Not able to add css in react - html

**Hii all I am trying to add css in react but not getting any changes in app home page and I also need wants to know how to add this pseudo selector using mui styled **
This is the css file:
lines {
display: 'flex';
flex-direction: row;
}
lines:before, lines:after{
content: "";
flex: 1 1;
border-bottom: 1px solid;
margin: auto;
}
lines:before {
margin-right: 10px
}
lines:after {
margin-left: 10px
}
And this is the home.js file :
import { styled } from '#mui/system';
import styles from './Style.css';
const MyComponent = styled('div')({
backgroundImage : "url('https://images.pexels.com/photos/841130/pexels-photo-841130.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1')",
height:'30vh',**strong text**
backgroundPosition: "center",
marginTop:'-80px',
fontSize:'50px',
backgroundSize: 'cover',
marginRight : '-10px',
marginLeft : '-10px',
backgroundRepeat: 'no-repeat',
textAlign : 'center',
padding: 200,
top: 200,
});
const HomeComp = () => {
return (
<>
<MyComponent> </MyComponent>
<h4 className={styles.lines}> Home Page</h4>
</>
)
}
export default HomeComp;

Try importing your CSS this way
import './Style.css';
and use it by calling the class name directly
<h4 className="lines"> Home Page</h4>

Your imports are correct, but coming to CSS, as they are classes, you have to add a . in front of them
.lines {
display: 'flex';
flex-direction: row;
}
.lines::before,
.lines::after {
content: "";
flex: 1 1;
border-bottom: 1px solid;
margin: auto;
}
.lines::before {
margin-right: 10px
}
.lines::after {
margin-left: 10px
}

Related

How can I disable my submit button when a text area is left blank?

I am trying to make a submit button that is disabled when a text area is left blank, but alas I am not seeing results. If any advice could be spared it would be greatly appreciated. Here is the code that pertains to this problem. This submit button works as if it were not disabled, so I'm guessing there must be something wrong in my typescript or the way that I am constructing the disable in the first place, but I am getting to the point where I am running out of Ideas. If anyone has any questions feel free to ask.
<template>
<div id="editEntryDiv">
<div id="mainContent" v-if="loaded">
<PartsForm v-model="localPartEntry" />
</div>
<Teleport to="#mainContent">
<div class="actionBar">
<!-- Empty Div Required for formatting -->
<div>
<button id="deleteButton" #click="deleteItem(parseInt(id))">
<i class="fas fa-trash"></i>
<span>Delete</span>
</button>
</div>
<!-- Empty Div Required for formatting -->
<div>
<button
id="submitButton"
:class="{ disabled: localPartEntry.partNumber == undefined }"
:disabled="localPartEntry.partNumber == undefined"
#click="submitItem"
>
<i class="fas fa-paper-plane"></i>
<span>Submit</span>
</button>
</div>
</div>
</Teleport>
</div>
</template>
here is the typescript:
<script lang="ts">
import { defineComponent } from "vue";
import { usePartStore } from "../stores/part-store";
import PartsForm from "../components/PartsForm.vue";
import { PartDefinition } from "../types/PartDefinition";
import { mapStores } from 'pinia'
export default defineComponent({
components: {
PartsForm,
},
data() {
return {
loaded: false,
localPartEntry: {} as PartDefinition,
};
},
watch: {
localPartEntry: {
handler() {
if (!this.loaded) return
sessionStorage.setItem("unsavedPart", JSON.stringify(this.localPartEntry))
},
deep: true
}
},
computed: {
...mapStores(usePartStore),
id(): string {
return this.$route.params.id.toString();
},
},
methods: {
async submitItem(): Promise<void> {
this.localPartEntry.id = parseInt(this.id);
if (await this.partStore.editPartDefinition(this.localPartEntry))
if (await this.partStore.getParts())
this.$router.push({
path: `/`,
});
},
async deleteItem(id: number) {
if (confirm("Are you sure you want to delete this entry?"))
if (await this.partStore.deletePartDefinition(id))
if (await this.partStore.getParts())
this.$router.push({
path: `/`,
});
},
},
mounted() {
for (let element of this.partStore.partEntries as PartDefinition[]) {
if (element.id == parseInt(this.$route.params.id.toString())) {
this.localPartEntry.id = element.id;
this.localPartEntry.partNumber = element.partNumber;
this.localPartEntry.variant = element.variant;
this.localPartEntry.revision = element.revision;
this.localPartEntry.description = element.description;
this.localPartEntry.supplier = element.supplier;
this.localPartEntry.previewImagePath = element.previewImagePath;
this.localPartEntry.previewImageDateTime = element.previewImageDateTime;
this.localPartEntry.obsolete = element.obsolete;
this.localPartEntry.internalOnly = element.internalOnly;
this.loaded = true;
break;
}
}
},
});
</script>
And finally, the css:
<style lang="sass" scoped>
#editEntryDiv
width: 100%
height: 100%
background: $primary-background
display: flex
flex-direction: column
overflow-y: auto
-ms-overflow-style: none // for Internet Explorer, Edge */
scrollbar-width: none // for Firefox */
&::-webkit-scrollbar
display: none // for Chrome, Safari, and Opera */
#mainContent
margin-top: 1rem
margin-bottom: 5rem
flex-grow: 1
#submitButton
border: 1px solid $primary-accent-color
font-size: 1.5rem
border-radius: .25rem
cursor: pointer
padding: .25rem .75rem
transition: background .3s, color .3s
color: $primary-accent-color
background: transparent
display: flex
flex-direction: row
justify-content: center
align-items: center
gap: .5rem
&:hover
color: $tertiary-background
background: $primary-accent-color
.disabled
background: grey !important
#deleteButton
border: 1px solid $primary-accent-color
font-size: 1.5rem
border-radius: .25rem
cursor: pointer
padding: .25rem .75rem
transition: background .3s, color .3s
color: $primary-accent-color
background: transparent
display: flex
flex-direction: row
justify-content: center
align-items: center
gap: .5rem
&:hover
color: $tertiary-background
background: $primary-accent-color
.actionBar
width: 100%
min-height: 4rem !important
background: $secondary-background
display: flex
justify-content: space-between
position: fixed
bottom: 0px
right: 0px
&>div
display: flex
flex-direction: row
align-items: center
gap: 1rem
margin: 0 1rem
</style>
You can just check with Logical NOT (!) operator which takes truth to falsity and vice versa. Hence, If there will be no value in the textarea it will return false else true.
Working Demo :
new Vue({
el: '#app',
data: {
content: ''
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
Textarea content: {{ content }}
<br><br>
<textarea v-model="content"></textarea>
<button id="submitButton" :disabled="!content.trim()">
<span>Submit</span>
</button>
</div>
I just added an example to show you how to achieve. You can made the changes in your original code.

How to fix unwanted behavior with CSS transition & flex wrap?

I am building a React webpage.
I have a number Cards in a flex row, which expand when hovered over with the mouse. The way I am making them expand is by increasing max-width & by adding a transition clause regarding max-width in the CSS.
At certain screen sizes this works well, but at others the Card that is expanding will wrap around to the next row, which makes the mouse not hover it anymore, which in turn makes it contract & move back up to the initial row, restarting this process. It looks like the page went nuts.
What is a good approach to fixing this unwanted behaviour?
Card:
// this makes the cards expand/contract
const onHover = () => {
cardRef.current.style.maxWidth = '370px';
}
const onExitHover = () => {
cardRef.current.style.maxWidth = '250px';
}
CSS:
.parent {
padding: 20px;
margin: 10px;
border-radius: 20px;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: center;
flex-wrap: wrap;
}
.card {
max-width: 250px;
min-width: 250px;
transition: max-width 0.5s;
/* plus the following from react */
/* display:'flex', */
/* flexDirection:'row', */
/* width:'100%', */
/* position: 'relative' */
}
EDIT:
Adding more code for Context
HTML of Parent
<div className="App-content">
<p className="Section-header" style={{color:'red'}}> PROJECTS </p>
<div className="parent">
<NewCard title="Project 1" ...
/>
<NewCard title="Project 2" ...
/>
...
</div>
</div>
Css Of Parent
.App-content {
background-color: white;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.parent {
/* background-color: #ffffff33; */
padding: 20px;
margin: 10px;
border-radius: 20px;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: center;
flex-wrap: wrap;
}
React Card Component:
import React, {useState, useRef, useEffect} from 'react';
import { makeStyles } from '#material-ui/core/styles';
import Card from '#material-ui/core/Card';
import CardContent from '#material-ui/core/CardContent';
import Typography from '#material-ui/core/Typography';
import { DynamicTag } from './Tag';
import './NewCard.css';
const useStyles = makeStyles({
root: {
margin: 10,
},
title: {
marginBottom: 12,
}
});
export default function NewCard(props) {
const classes = useStyles();
const { title } = props;
const containerRef = useRef();
const onHover = () => {
containerRef.current.style.maxWidth = '370px';
}
const onExitHover = () => {
containerRef.current.style.maxWidth = '250px';
}
return (
<Card onMouseEnter={onHover} onMouseLeave={onExitHover} className={classes.root}>
<div ref={containerRef}
className=".card"
style={{
display:'flex',
flexDirection:'row',
width:'100%',
position: 'relative'}}>
<div style={{minWidth:'250px'}}>
<CardContent>
<Typography className={classes.title}>
{title}
</Typography>
// some content here
</CardContent>
</div>
<div className='Card-image-container'>
<img src={image} className='Card-image'/>
</div>
</div>
</Card>
);
}
Card CSS
.card {
max-width: 250px;
min-width: 250px;
transition: max-width 0.5s;
}

How to enable scroll on background component even if a Modal is Open?

I have a problem with Angular and Material for Angular, I have an application with many modals, they all lock background scrolling when they're open, but I have a notification modal, this notification modal isn't intended to block background scrolling.
I don't have any .noScroll class in this modal, but the background page in relation to the modal still won't scroll, I want to the user to be able to scroll the page even with the notification modal open.
The notification modal is a DialogRef from Material for Angular.
I tried using overflow: visible and auto, also tried to modify the backdrop to enable scroll, but no success :(
How do I make the backdrop of this particular modal to enable scrolling and possible override other configurations of the code?
Edit: Here is part of the code >
ModalService:
{
constructor(private matDialog: MatDialog) {
}
openNotificationsModal(topOffset, rightOffset): MatDialogRef<NotificationsModalComponent> {
return this.notificationsModal(topOffset, rightOffset);
}
private notificationsModal(topOffset, rightOffset, clazz?: string): MatDialogRef<NotificationsModalComponent> {
const config = {
panelClass: clazz ? clazz : 'notifications-modal',
backdropClass: 'cdk-overlay-transparent-backdrop',
data: {
topOffset,
rightOffset,
}
};
return this.matDialog.open(NotificationsModalComponent, config);
}
}
this is my modal component:
import { Component } from '#angular/core';
import { MatDialogRef } from '#angular/material';
#Component({
selector: 'aa-notifications-modal',
templateUrl: './notifications-modal.component.html',
styles: []
})
export class NotificationsModalComponent {
constructor(private dialogRef: MatDialogRef<NotificationsModalComponent>) {}
async ngOnInit() {
this.dialogRef.updatePosition({
top: '2.5rem'
});
}
output() {
this.dialogRef.close();
}
}
this is the scss of this modal:
aa-notifications-modal {
width: 100%;
}
.notifications-modal {
width: 100%;
max-width: 100% !important;
pointer-events: none !important;
.mat-dialog-container {
display: flex;
justify-content: flex-end;
background: transparent;
width: 100%;
box-shadow: none;
}
.align-triangle {
display: flex;
justify-content: flex-end;
padding: 0;
.triangle {
margin-right: 4rem;
width: 0;
height: 0;
border-left: 25px solid transparent;
border-right: 25px solid transparent;
border-bottom: 25px solid #fff;
}
}
.space {
padding: 0;
}
.content-modal {
display: flex;
justify-content: flex-end;
margin-right: 8rem;
aa-notifications-list {
width: 427px;
pointer-events: auto;
border-radius: 5px;
}
}
}
As I can understand you need to find out where overflow: hidden; likely it will be on body tag, a simple solution you can try to set overflow: auto !important;
But more elegant will be to provide Scroll strategy into your Dialog

the table border-bottom disappear?

I try to implement a table with large size of data. then due to the performance issue, I just want to render the data in the body window.
But the new render element border disappear.
HTML:
<script src="//unpkg.com/vue#2.5.15/dist/vue.js"></script>
<script type="text/x-template" id="list-template">
<div class='table-body' ref="body" #scroll="handleScroll">
<div class="list-view">
<div
class="list-view-phantom"
:style="{
height: contentHeight
}">
</div>
<div class="list-view-colgroup">
<div class="list-view-item-col-g" v-for='count in 5'>
</div>
</div>
<div
ref="content"
class="list-view-content">
<ul
class="list-view-item"
:style="{
height: itemHeight + 'px'
}"
v-for="item in visibleData" :key='item.value'>
<li class="list-view-item-col" v-for='count in 5'>
{{item.value+count}}
</li>
</ul>
</div>
</div>
</div>
</script>
<div id="app">
<template>
<list-view :data="data"></list-view>
</template>
</div>
JS:
const ListView = {
name: 'ListView',
template: '#list-template',
props: {
data: {
type: Array,
required: true
},
itemHeight: {
type: Number,
default: 30
}
},
computed: {
contentHeight() {
return this.data.length * this.itemHeight + 'px';
}
},
mounted() {
this.updateVisibleData();
},
data() {
return {
visibleData: []
};
},
methods: {
updateVisibleData(scrollTop) {
scrollTop = scrollTop || 0;
const visibleCount = Math.ceil(this.$el.clientHeight / this.itemHeight);
const start = Math.floor(scrollTop / this.itemHeight);
const end = start + visibleCount;
this.visibleData = this.data.slice(start, end);
this.$refs.content.style.transform = `translate3d(0, ${ start * this.itemHeight }px, 0)`;
},
handleScroll() {
const scrollTop = this.$refs.body.scrollTop;
this.updateVisibleData(scrollTop);
}
}
};
new Vue({
components: {
ListView
},
data() {
const data = [];
for (let i = 0; i < 1000; i++) {
data.push({ value: i });
}
return {
data
};
}
}).$mount('#app')
code example:
https://jsfiddle.net/441701328/hq1ej6bx/6/
you can see only the data render in the first time can have border.
could anyone help?
thanks all!!!
table-row-group does not work with divs you can change the whole layout and use tables or instead you can do it like this.
.list-view-item {
padding: 5px;
color: #666;
display: table;
line-height: 30px;
box-sizing: border-box;
border-bottom: 1px solid red;
min-width: 100vw;
}
.list-view-item-col {
display: table-cell;
min-width: 50px;
}
jsfiddle for table-row-group
Hope it helps.
Use display :flex for list-view-item class, Try with following code.Hope it will work fine for you.
.list-view-item {
padding: 5px;
color: #666;
display: flex;
flex-basis: 100%;
flex-direction: row;
line-height: 30px;
box-sizing: border-box;
border-bottom: 1px solid red;
}
Try with this CSS. I hope it will works for you.
.list-view-item {
padding: 5px;
color: #666;
display:table;
line-height: 30px;
box-sizing: border-box;
border-bottom: 1px solid green;
}
I try to change the js code :
this.$refs.content.style.transform = `translateY(0, ${ start * this.itemHeight }px, 0)`;
to :
this.$refs.content.style.transform = `translateY(${ start * this.itemHeight }px)`;
and add a css to div class is list-view:
transform:translateY(0)px;
then the border showed.
don't understand why this action work!
.list-view-item {
padding: 5px;
color: #666;
display: flex;
flex-basis: 100%;
flex-direction: row;
line-height: 30px;
box-sizing: border-box;
border-bottom: 1px solid red;
}

circular border-radius artifacts in css

I am using react and have a circle component that I want to map on the screen. The problem is at certain view sizes I get small artifacts in the circles. Flat ends and only on certain rows of circles.
Circles have flat sides at view width 980px
ball hitbox
container hitbox
.ballholder{
display:flex;
flex-wrap: wrap;
justify-content: space-evenly;
background-color:rgb(206,35,212);
padding:0.5vw;
border-radius: 5%;
border:2px solid black;
}
.aball{
background-image: linear-gradient(to bottom right, white, whitesmoke, rgb(150,150,150));
color:black;
border-radius:50%;
display:flex;
justify-content:center;
align-items:center;
width:2vw;
height:2vw;
padding:0.05vw;
margin:0.20vw;
font-size:1.3vw;
}
Here's the parent component:
import React, { Component } from "react";
import { Switch, Route, Redirect, Link } from "react-router-dom";
import Ball from "./Ball";
import "../App.css";
export default class Ballswitch90 extends Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
const balls = this.state.balls.map((a, i) =>
a ? (
<Ball p={{ num: i + 1, clicked: false }} />
) : (
<Ball p={{ num: i + 1, clicked: true }} />
)
);
return <div className="ballholder">{balls}</div>;
}
}
Ball component:
import React, { Component } from 'react';
import { Switch, Route, Redirect, Link } from "react-router-dom"
import '../App.css'
export default class Ball extends Component {
constructor(props) {
super(props)
this.state = {
num:props.p.num,
clicked:props.p.clicked
}
}
render() {
return (
<div>
{this.state.clicked
?
<div className="aball">{this.state.num}</div>
:
<div className="aballred">{this.state.num}</div>
}
</div>
)
}
}
I've tried adding a padding and margin but that only changed the size at which the flats show up.
Probably the css rules with height and width make some problems.
You can see this snippet that works well:
https://codesandbox.io/embed/n6jrm1k2l
aball {
border-radius: 50%;
background-color: white;
border: 1px solid darkred;
padding: 1em;
/* Center the text contents */
display: inline-flex;
align-items: center;
justify-content: center;
color: black;
}
.aball:after {
content: "";
display: block;
/* Ensure the element is a square */
height: 0;
width: 100%;
padding-bottom: 100%;
}
.aball__value {
/* Set the height to 0 and overflow to visible to not interfere with the square styles */
overflow: visible;
height: 0;
/* Vertically center text since we set its height to 0 */
margin-top: -1em;
}