Set css flexbox styles in a .tsx react file - css

I'm changing some styles in a React Project. Some of this changes consist in set new alignments, change fonts or some colors of the UI. So, I am editing the titles of a form and I am unable to center the following text using flexbox.
I have tried to place the styles between the brackets like this but it doesn't works:
<Stack style={{ display: 'flex', flexDirection: 'column', justifyContent:'center', textAlign: 'center' }}>
<MDTypography variant="h4" fontWeight="bold">
Ingresa tus datos personales
<MDTypography>
</Stack>
But when I inspect the code in Chrome and set it manually, it works:
display: flex
flex-direction: column
justify-content: center

Related

How to change the size of a component with effect when another component is rendered inside of it?

I have a modal component that overlays my page with a form to make some data inputs.
a second component is rendered next to the form when a certain condition is met (try to fetch data, render if anything is found).
When this happens I would like the whole card containing the two items to expand with some effect (horizontally if on desktop, vertically if on mobile), reducing smoothly the width of the first box during the transion.
I have tried to achieve this using a simple combination of the MUI Grid Container and Grid items,
but with this approach the second item always go on a new line or shows on the right but never changing the modal card overall size.
this is the style applied to the modal card:
sx={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
display: 'flex',
flexDirection: 'column',
transitionDuration: '500ms',
minWidth: '30%'
}}
So I thought of wrapping the 2 brothers in some DIV and apply some custom CSS taking advantage of the transitionDuration to apply an effect. But I couldn't make it work.
here is the style applied to the DIV that wraps the 2 brothers:
<div style={{ display: 'flex', flexDirection: 'row', width: '100%' }}>
this is the div that contains the form grid container (1):
<div
style={{
flexGrow: 1,
minWidth: '30%',
transitionDuration: '500ms',
transitionTimingFunction: 'ease-out'
}}
>
and this is the div that contains the component to be shown when condition is met (2):
<div
style={{
paddingLeft: 10,
transitionDuration: '500ms',
transitionTimingFunction: 'ease-in',
whiteSpace: 'nowrap',
minWidth: condition ? '200px' : '0%',
width: '0%'
}}
>
can anybody point me in the right direction?
I'm new to CSS
Thanks
When you fetch the data you can add a class (.active or something similar)to the parent container as well and add the styles you want to change like
container.active > child{Blahblah styles}

React Material UI: Box not scroll-able in y-axis [duplicate]

This question already has answers here:
Use justify-content: flex-end and to have vertical scrollbar
(6 answers)
Closed 1 year ago.
I have been stuck at this problem for hours now and I need some help. I am trying to create a Chat component and I just want to be able to scroll it vertically. Here's a minimum reproducible example at Codesandbox: https://codesandbox.io/s/reverent-panini-lsbfg?file=/src/chat/ChatHistory.tsx
I have made the container's height fixed (600px) and added the overflow: "hidden" and overflowY: "scroll" styles, but it still does not work, and I have no idea why. Thanks in advance.
Welp, screw CSS. Apparently, it's a CSS bug.
Use justify-content: flex-end and to have vertical scrollbar
All I had to do was to remove justifyContent: "flex-end".
For MUI v5
<Box
sx={{
mb: 2,
display: "flex",
flexDirection: "column",
height: 700,
overflow: "hidden",
overflowY: "scroll",
// justifyContent="flex-end" # DO NOT USE THIS WITH 'scroll'
}}
>
For MUI v4
<Box
mb={2}
display="flex"
flexDirection="column"
// justifyContent="flex-end" # DO NOT USE THIS WITH 'scroll'
height="700px" // fixed the height
style={{
border: "2px solid black",
overflow: "hidden",
overflowY: "scroll" // added scroll
}}
>

Material-Ui How to adjust width to display items horizontally

I'm working on kanban/Trello clone app with Material-Ui,
I tried to display columns horizontally and keep columns the same width.
All columns are displayed horizontally in the same row.
If display area for columns requires to extend browser width, the display area width is automatically adjusted.
The issue is Material UI doesn't allow me to display columns with side scroll.
If I decided the display area directly, like width:2000. the all columns displayed horizontally,
but there is always redundant space.
Because the width is fixed, and we don't know how many columns users create.
What is the solution for this issue?
these are the code I tried.
1/wrapped child with Grid
<Grid container style={{margin: 0,width: "100%"}}>
{children}
</Grid>
2/set style like this
const useStyles = makeStyles({
root: {
display: "flex",
justifyContent: "flex-start",
alignContent: "center",
width: 20000,
overflowX: "auto"
}
3/use Container and Grid
<Container className={classes.container}>
<Grid container direction='row' justify='flex-start' alignItems='flex-start'>
{children}
</Container >
</Grid >
onst useStyles = makeStyles({
root: {
display: "flex",
justifyContent: "flex-start",
alignContent: "center"
// width: 20000,
// overflowX: "auto"
},
container: {
overflowY: "scroll",
whiteSpace: "nowrap"
}
});

Full height in React using flex

I can't find an answer for this, even though there are many flex themed questions.
I created a simple React app (npx create-react-app).
I then deleted App.css and set the contents of index.css to:
html, body, #root {
height: 100%;
margin: 0;
}
Next, in App.js I'm trying to have a full screen element using flex:
import React from 'react';
function App() {
return (
<div style={{ backgroundColor: 'blue', display: "flex", flex: 1 }}>
<div style={{ display: "flex", flexDirection: "column", flex: 1 }} />
</div>
);
}
But it just won't work. Why is the flex element not stretching?
The flex-grow works when there are other elements in the flex. It makes the element to grow x times in comparison to others.
wrt the solution you have implemented: inner div doesn't require display: flex and direction too. It will be inherited from the parent div.
To make the div take the full height. add height: 100vh to the parent div.
Let me know if this will solve the problem.
Thank you.
To achieve height of window you need to mention height: 100vh for parent tag like
class- .parent{height: 100vh}
object style - style={{height: '100vh'}}
import React from 'react'
function App() {
return (
<div style={{ backgroundColor: 'blue', display: "flex", height:'100vh' }}>
<div style={{ display: "flex", flexDirection: "column", flex: 1 }} >Hello world</div>
</div>
);
}

MUI Progress Indicator center align horizontally

Stack: Meteor + React + MUI
Here's my full code of my 'main' renderer components:
// Sorry for not giving material-UI CSS,
// cause it cannot be served as stand-alone CSS
render() {
return (
<div className = "container">
<AppBar title = "test" />
<Tabs /> // Tab contents goes here
<RefreshIndicator
left={70} // Required properties
top={0} // Required properties
status="loading"
style={{
display: 'inline-block',
position: 'relative',
margin: '0 auto' }} />
</div>
);
},
I want to make Refresh Indicator horizontally center aligned beneath of myTabs like this whirling circle in this picture :
In the document of MUI here, this indicator comes with following styles:
display: 'inline-block',
position: 'relative',
With this styles I cant align it center horizontally, and without this styles, I can`t even locate it where I wanted.
What I have tried :
margin: 0 auto --> failed
text-align: center --> failed
display: flex --> failed
combination of 1 & 2 --> failed
left={$(window).width/2-20} --> This works but I'd like to use CSS only
The solution below centres progress indicator without any hacky calculations that cause element to be offset:
<div style={{display: 'flex', justifyContent: 'center'}}>
<RefreshIndicator status="loading" />
</div>
Here is how I did to ensure it's horizontally centered. Works great for me.
Set the parent component style to position: 'relative'.
Set the refresh indicator style to marginLeft: '50%', and left={-20} (assuming the size is 40).
here is the code (I put it in a CardText component).
...
<CardText style={{position: 'relative'}}>
<RefreshIndicator
size={40}
left={-20}
top={10}
status={'loading'}
style={{marginLeft: '50%'}}
/>
</CardText>
...
In MUI v5, there is a Stack component which serves as a flexbox container. By default the direction is column, to center it horizontally you can set alignItems to center:
<Stack alignItems="center">
<CircularProgress />
</Stack>
Live Demo
circularprocess in material ui and text middle of page stackoverflow
<div style={{ alignItems: "center", display: "flex", justifyContent: "center", height: "100vh", width: "100vw" }}>
<CircularProgress />
<span style={{ justifyContent: "center", position: "fixed", top: "55%" }}>Loading...please wait</span>
</div>[![enter image description here][1]][1]
The Backdrop Component will place the progress indicator in the center and also can add a dimmed layer over your application. This component is available with MUI V5.
<Backdrop open={enabled} sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}><CircularProgress color="secondary" /></Backdrop>

Resources