How to show background in styled-components? - css

In my react-app I cannot see the background/border style. What am I doing wrong?
This is what is looks like:
<Flex>
<Box
bg="blue"
css={{
borderRadius: "4px"
}}
/>
</Flex>
codesandbox

There isn't the content in box.
When you add any content, you will see the border radius and background color.
If you change like below, then you will see the background.
<Flex>
<Box
bg="blue"
css={{
borderRadius: "4px"
}}
>
lorem texts
</Box>
</Flex>
and you can specify
width={1}
to make box will have full width.

Related

Dynamic Image List from MUI do not respect max height of the React container

I am trying to create a dynamic image list where I can change the number of images that are being displayed, where the images have to occupy the max space in the component without change the image ratio and also without make the component scrollable. The following images show the result that is expected:
Although what really happens now is, in the first case, with only 2 images, it overflows the parent component due to the spacing added between the flexbox elements.
For the 6 images example, it goes worst:
It overflows the parent even more because it ignores the component's max height and always tries to occupy the max width possible.
To reach the correct behaviour, I'm hard coding the flex-basis of the image list for each case because it is a flex item, and only that way does it not grow more than it should. Although, that is not desirable because I want to make the images grow as much as possible without depending on the screen size.
I do not understand why they ignore the parent's max height.
I do not understand why they do ignore the max height of the parent.
Main component:
<>
<Grid
container
direction="column"
wrap="nowrap"
rowSpacing={1}
sx={{ alignSelf: 'flex-end', margin: 0, height: '100%', justifyContent: 'flex-end' }}
>
<Grid
container
wrap="nowrap"
item
sx={{
alignSelf: 'flex-start',
flex: '1 0 auto',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<CustomImageList ref={ref} />
</Grid>
<Grid item>
<CustomPagination onClick={keyMap.move} />
</Grid>
<Grid width="100%" item>
<Stack
spacing={1}
direction="row"
sx={{
overflowX: 'auto',
justifyContent: 'space-between',
'& .MuiFormControl-root': { marginTop: '1px' },
}}
divider={<Divider orientation="vertical" flexItem />}
>
{Buttons.map((button) => (
<Stack spacing={1} flex={1} key={button.buttonId}>
<Stack direction="row" spacing={1}>
{button.text ? (
<ButtonText button={button} />
) : (
<Button />
)}
</Stack>
<Stack spacing={1} direction="row">
<ButtonBox button={button} />
</Stack>
</Stack>
))}
</Stack>
</Grid>
</Grid>
</>
The component CustomImageList is sketch like the next code:
<>
<Stack justifyContent="center">
<IconButton
ref={leftArrowRef}
size="large"
onClick={(e) => {
e.preventDefault();
handleClick({
key: 'ArrowLeft',
keyCode: 37,
});
}}
>
<ArrowBackIosNewIcon />
</IconButton>
</Stack>
<ImageList
sx={{
height: '100%',
alignContent: 'center'
}}
cols={imageColumnCount}
>
{images.map((image, index) =>
createOrdinaryListItem(image, index)
)}
</ImageList>
<Stack justifyContent="center">
<IconButton
onClick={(e) => {
e.preventDefault();
handleClick({
key: 'ArrowRight',
keyCode: 39,
});
}}
ref={rightArrowRef}
size="large"
>
<ArrowForwardIosIcon />
</IconButton>
</Stack>
</>
The ImageList component is a MUI ImageList
What would be the best approach to create the scenario shown in the first and second figures? I have already tried to create my component. It was a flexbox where I used the breakpoint from the grid to distribute the columns across the images. I had the same behaviour that I presented here.
Sorry about the verbose post and kinda "hard to understand" question, but I was not capable of creating a runnable script to show what is aforementioned

Material-ui , remove paper border

How to remove the top border in material-ui Paper component. I've tried the following but it seems that it does not work.
<Paper
sx={{
border: 0,
borderTop: 0,
borderRadius: 0,
}}
>
<Box className="main">
<Typography variant="h4">O_x</Typography>
<InvoiceFormCmp />
</Box>
</Paper>
image
Probably, you haven't noticed that the Paper component is not using any border. You are seeing that line because of the box-shadow CSS property used by the Paper component. You can set it to none with:
<Paper sx={{ boxShadow: "none" }}>
<Box className="main">
<Typography variant="h4">0_x</Typography>
</Box>
</Paper>
Check the sandbox here
<Paper sx={{ border: 'none' }}>

Not getting the space and lines in my text modal

I think because I am using p tag.
<DialogContent>
<Grid
style={{ marginTop: "8px" }}
container
spacing={0}
></Grid>
<p>
{this.state.eulaEncText ? this.state.eulaEncText : null}
</p>
</DialogContent>
here I am not able to see the lines and tabs as in the original text.
You can achieve this using css using the white-space attribute with the value pre-wrap on the p tag as follow:
<DialogContent>
<Grid
style={{ marginTop: "8px" }}
container
spacing={0}
></Grid>
<p style={{ whiteSpace: "pre-wrap" }}>
{this.state.eulaEncText ? this.state.eulaEncText : null}
</p>
</DialogContent>
According to the documentation, the value pre-wrap does the following:
Sequences of white space are preserved. Lines are broken at newline characters, at , and as necessary to fill line boxes.

Material UI how to justify content inside FormControlLabel

I'm trying to align the label and the radio button inside a FormControlLabel component so that the label consumes the same width regardless of the text inside of it. Here's what it currently looks like:
Here's the code I have:
<RadioGroup row>
<FormControl>
<FormControlLabel
value={first_column_day}
control={
<Radio
value={first_column_day}
/>
}
label={<Typography variant={"subtitle2"}>{first_column_day}</Typography>}
labelPlacement="start"
/>
</FormControl>
<FormControl>
<FormControlLabel
value={second_column_day}
control={
<Radio
value={second_column_day}
/>
}
label={<Typography variant={"subtitle2"}>{second_column_day}</Typography>}
labelPlacement="start"
/>
</FormControl>
</RadioGroup>
I tried adding justifyContent for FormControl:
<FormControl style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
I also tried wrapping Typography in a div:
<div><Typography variant={"subtitle2"}>{first_column_day}</Typography></div>
But those didn't work. So far the only thing that worked is adding a fixed width to the Typography like so:
<Typography style={{ width: 75 }} variant={"subtitle2"}>{first_column_day}</Typography>
But I don't really like doing that because it's not responsive. Setting the width to 100% doesn't work either.
You can add min-width to FormControlLabel component if you need alignment like below without losing responsiveness -
Working Sandbox here - https://codesandbox.io/s/material-demo-3u8i2?file=/demo.js

React - vertically align text and icon

I have tried all things to align vertically an icon and a text, Code:
<Danger color="secondary" style={{ flex:1,justifyContent: "center",alignItems: "center" }}>
<ErrorOutline
className={classes.warning}
/>
<text numberOfLines={1} style={{ textAlignVertical: "center" }}>
The last job was canceled
</text>
</Danger>
Things that I've tried : display, justifyContent, alignItems, flex, flexDirection, etc.
Any advice? Thanks!
Try out this inside render of react code
<div style={{display: 'flex', lineHeight: '40px'}}>
<img src="https://png.icons8.com/ios/50/000000/user-male-circle-filled.png" height="40"/>
<div>Welcome User!!!</div>
</div>
And for clear understanding you can find the entire React code for this particular example in this link: https://jsfiddle.net/r6yLmu8t/
You need to give lineHeight for the div tag in which the image/icon and text are there. And make sure that the icon/image height is equal to the lineHeight given to the div.
Hope this will achieve your need of text and icon to be on the same line and text to be at centre of icon/image
<Button light>
<View style={{flexGrow: 1, justifyContent:'center', alignItems: 'center'}}>
<Icon name='arrow-back' />
<Text>Back</Text>
</View>
</Button>

Resources