I have a project to monitor employees and I have a sidebar in this project.
As is evident in the first two pictures, there is a sidebar, and inside it there is a button. Then I press the button, then the dialog appears in the "bottom left" of the page, and I want to do the same idea.
And the thing that I did is in the third picture,
I create a button within the sidebar, and when I click on this button, a dialog appears, but the dialog appears in the middle of the page and not at the bottom left of the page.
How can I solve this problem?
const useStyles = makeStyles((theme: Theme) =>
createStyles({
dialogPaper: {
maxWidth: '36rem',
height: '33rem',
},
border: {
borderBottom: '10rem'
}, paper: {
// padding: theme.spacing(2),
// textAlign: 'center',
// color: theme.palette.text.secondary,
},
dividerColor: {
backgroundColor: '#000000',
},
resize: {
fontSize: 24,
color: '#BDBDBD'
},
oneEdgeShadow: {
background: '#384047',
boxShadow: '0 0 0 4px #384047, 0 4px 4px black',
}
})
);
export default function FormDialog() {
const classes = useStyles();
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const navigation = useNavigate();
const onMySettings=() =>{
console.log('Clicked on My settings');
navigation('/dashboard/workspace-sidebar/settings');
}
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open form dialog
</Button>
<Dialog classes={{paper: classes.dialogPaper}} open={open} onClose={handleClose}
aria-labelledby="form-dialog-title">
<Grid container xs={12}>
<Grid item xs={2}>
<List component="nav" aria-label="main mailbox folders"
style={{paddingLeft: '1rem', fontSize: '14px', color: '#BDBDBD',
lineHeight: 1}}>
<ListItem button style={{
fontWeight: 500,
fontSize: '11px',
lineHeight: 1,
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
color: '#BDBDBD'
}}>
<ListItemAvatar>
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg"/>
</ListItemAvatar>
</ListItem>
</List>
</Grid>
<Divider classes={{root: classes.dividerColor}} orientation="vertical" flexItem/>
<Grid item xs={5}>
<List component="nav" aria-label="main mailbox folders"
style={{paddingLeft: '1rem', fontSize: '10px', color: '#BDBDBD',
lineHeight: 1}}>
<ListItem button style={{
paddingBottom: '1rem',
fontWeight: 500,
fontSize: '10px',
lineHeight: 1,
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
color: '#BDBDBD'
}}>
<ListItemAvatar>
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg"/>
</ListItemAvatar>
<ListItemText>Ali Baba {/*Workspaces*/}</ListItemText>
</ListItem>
<ListItem button>
<ListItemText primary="Settings"/>
</ListItem>
<ListItem button>
<ListItemText primary="Import/Export"/>
</ListItem>
<ListItem button>
<ListItemText primary="People"/>
<Button onClick={handleClose} startIcon={<PersonAddIcon />} style={{
borderRadius: 2,background: '#7b68ee'}} variant="contained">
Invite
</Button>
</ListItem>
<ListItem button>
<ListItemText primary="Spaces"/>
</ListItem>
<ListItem button>
<ListItemText primary="Integrations"/>
</ListItem>
<ListItem button>
<ListItemText primary="Template Center"/>
</ListItem>
<ListItem button>
<ListItemText primary="Trash"/>
</ListItem>
<ListItem button>
<ListItemText primary="Security & Permissions"/>
</ListItem>
</List>
</Grid>
<Divider classes={{root: classes.dividerColor}} orientation="vertical" flexItem/>
<Grid item xs>
<List component="nav" aria-label="main mailbox folders"
style={{paddingLeft: '1rem', fontSize: '14px', color: '#BDBDBD',
lineHeight: 1}}>
<ListItem button style={{paddingBottom: '1rem'}}>
<ListItemAvatar>
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg"/>
</ListItemAvatar>
<ListItemText>Ali Baba</ListItemText>
</ListItem>
<ListItem button onClick={onMySettings}>
<ListItemText primary="My Settings"/>
</ListItem>
<ListItem button>
<ListItemText primary="Notifications"/>
</ListItem>
<ListItem button>
<ListItemText primary="Layout size & style"/>
</ListItem>
<ListItem button>
<ListItemText primary="Rewards"/>
</ListItem>
</List>
<List component="nav" aria-label="main mailbox folders"
style={{paddingLeft: '1rem', fontSize: '14px', color: '#BDBDBD',
lineHeight: 1}}>
<ListItem button>
<ListItemText primary="Log out"/>
</ListItem>
<Divider classes={{root: classes.dividerColor}} variant="middle" />
<ListItem button>
<ListItemText primary="Help"/>
</ListItem>
<ListItem button>
<ListItemText primary="Hotkeys"/>
</ListItem>
<ListItem button>
<ListItemText primary="Dark mode"/>
</ListItem>
</List>
</Grid>
</Grid>
</Dialog>
</div>
);
}
You need to modify the paper style of the Dialog component.
First create your desirable style and position by makeStyles as below:
const useStyles = makeStyles({
paper: {
position: "absolute",
left: 0,
bottom: 0
}
});
and then pass it to the Dialog component:
<Dialog
classes={{ paper: classes.paper }}
onClose={handleClose}
aria-labelledby="simple-dialog-title"
open={open}
>
working example in sandbox
Related
How I can collapse only the click item?, I am using customize in material ui Customization
what I want is to show only the list of item in the select item this code will show all the list item not the list of the clicked item. I am only following the customization in the nested list in material ui and also I use the nested list it will show also the same output.
const [open, setOpen] = React.useState(false)
const handleToggle = () => {
setOpen((toggleOpen) => !toggleOpen)
}
const drawer = (
<Paper elevation={0} sx={{maxWidth: 256}}>
<StyledNav component="nav" disablePadding>
<ListItemButton component="a" href="/app/profile">
{loading ? (
<Typography>loading...</Typography>
) : data ? (
<Fragment>
<ListItemIcon
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
minHeight: 'fit-content',
padding: theme.spacing(0.5),
}}
>
<Avatar sx={useStyles.avatar} alt="User">
{getinitials(`${data.me?.lastname} ${data.me?.firstname}`)}
</Avatar>
</ListItemIcon>
<Stack>
<ListItemText
sx={{my: 0}}
primary={`${data.me?.lastname} ${data.me?.firstname}`}
primaryTypographyProps={{
fontSize: 20,
fontWeight: 'medium',
letterSpacing: 0,
}}
/>
<ListItemText
sx={{my: -1}}
primary={`${data.me?.username}`}
primaryTypographyProps={{
fontSize: 15,
fontWeight: 'medium',
letterSpacing: 0,
}}
/>
</Stack>
</Fragment>
) : null}
</ListItemButton>
<Divider />
{!loadingGetUserPagesAccess &&
dataGetUserPagesAccess &&
dataGetUserPagesAccess.userPagesAccess.map((pagegroup) => {
return (
<Fragment key={pagegroup.name}>
<List
sx={{
width: '100%',
maxWidth: 360,
bgcolor: open ? 'rgba(71, 98, 130, 0.2)' : null,
}}
subheader={<ListSubheader>{pagegroup.name}</ListSubheader>}
>
{pagegroup.pages?.map((page) => {
return (
<Fragment key={page.name}>
<ListItemButton
alignItems="flex-start"
onClick={handleToggle}
sx={{
px: 3,
pt: 2.5,
pb: open ? 0 : 2.5,
'&:hover, &:focus': {
'& svg': {opacity: open ? 1 : 0},
},
}}
disableGutters
>
<ListItemText
primary={page.name}
primaryTypographyProps={{
fontSize: 15,
fontWeight: 'medium',
lineHeight: '20px',
mb: '2px',
}}
secondaryTypographyProps={{
noWrap: true,
fontSize: 12,
lineHeight: '16px',
color: open
? 'rgba(0,0,0,0)'
: 'rgba(255,255,255,0.5)',
}}
sx={{my: 0}}
/>
<KeyboardArrowDown
sx={{
mr: -1,
opacity: 100,
transform: open ? 'rotate(-180deg)' : 'rotate(0)',
transition: '0.2s',
}}
/>
</ListItemButton>
{open &&
page.subpages &&
page.subpages.map((subpage) => {
return (
<ListItemButton
sx={{
py: 0,
minHeight: 32,
}}
>
<ListItemText
primary={subpage.name}
primaryTypographyProps={{
fontSize: 14,
fontWeight: 'medium',
}}
onClick={() => {
navigate(`/app/services${subpage.url}`)
}}
/>
</ListItemButton>
)
})}
</Fragment>
)
})}
</List>
</Fragment>
)
})}
</StyledNav>
</Paper>)
what should I do thank you..
I have a navbar component that looks like
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton edge="start" color="inherit" aria-label="menu" onClick={toggleDrawer(true)}>
<MenuIcon />
</IconButton>
<Link href="#" color="primary" underline="none" variant="h5" className={classes.brand}>
{brand}
</Link>
<Button variant="contained" color="secondary" className={classes.primaryAction}>{content['primary-action']}</Button>
</Toolbar>
However the <Button variant="contained> is placed before the Link, how can I place the button all the way to the end of the x axis?
This is the styles
const useStyles = makeStyles((theme: Theme) => ({
toolbar: {
minHeight: 200
},
brand: {
lineHeight: 1,
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)'
},
primaryAction: {
justifySelf: 'end'
},
iconWrapper: {
minWidth: 40,
},
}));
Try to apply flexGrow: 1 on the link and align it right:
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton edge="start" color="inherit" aria-label="menu" onClick={toggleDrawer(true)}>
<MenuIcon />
</IconButton>
<Link href="#" color="primary" underline="none" variant="h5" sx={{ flexGrow: 1, textAlign: 'right' }}>
{brand}
</Link>
<Button variant="contained" color="secondary" className={classes.primaryAction}>{content['primary-action']}</Button>
</Toolbar>
Try using CSS flex to place the buttons and link inside the toolbar.
Here's a working CodeSandbox. (Note that if you want the Link to come after the Button, just move the component below the Button in the code as per the comment I left).
Here's the JSX:
<AppBar position="static" color="inherit">
<Toolbar className={classes.toolbar}>
<IconButton
edge="start"
color="inherit"
aria-label="menu"
onClick={toggleDrawer(true)}
>
<MenuIcon />
</IconButton>
<div className={classes.verticalCenter}>
{/* Just move this link to come after the Button below to change the order */}
<Link
href="#"
color="primary"
underline="none"
variant="h5"
className={classes.brand}
>
{brand}
</Link>
<Button
variant="contained"
color="secondary"
className={classes.primaryAction}
>
{content["primary-action"]}
</Button>
</div>
</Toolbar>
</AppBar>
And the CSS:
const useStyles = makeStyles((theme) => ({
toolbar: {
minHeight: 200,
display: "flex",
justifyContent: "space-between"
},
brand: {
lineHeight: 1,
padding: 16
},
primaryAction: {
justifySelf: "flex-end"
},
iconWrapper: {
minWidth: 40
},
verticalCenter: {
display: "flex",
alignItems: "center"
}
}));
i have the same names in my data and I want to use unique id which i have .
However . i can not find right place for "key={id}"
<AutoCompleteComp
data={data}
setInputValue={setInputValue}
inputValue={inputValue}
setCurrentEvent={setCurrentEvent}
goToPage={goToPage}
/>
{currentEvent?.name === inputValue && (
<Box sx={{ width: "100%" }}>
{listArray.map((text, index) => (
<ListItem
// selected
onClick={() => addUrlHandler(index, text)}
button
key={text}
sx={{
"& .MuiListItemText-root": {
color: index === currentIndex ? "#6AE05F" : "",
},
"&:hover": {
backgroundColor: "rgba(36, 82, 32, 0.5)",
},
}}>
<ListItemIcon sx={{ color: "#6AE05F" }}>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText sx={{ color: "white" }} primary={text} />
</ListItem>
))}
It's fine to use index as key when you can't find an id.
This is from the doc:
When you don’t have stable IDs for rendered items, you may use the
item index as a key as a last resort:
<AutoCompleteComp
data={data}
setInputValue={setInputValue}
inputValue={inputValue}
setCurrentEvent={setCurrentEvent}
goToPage={goToPage}
/>
{currentEvent?.name === inputValue && (
<Box sx={{ width: "100%" }}>
{listArray.map((text, index) => (
<ListItem
// selected
onClick={() => addUrlHandler(index, text)}
button
key={index}
sx={{
"& .MuiListItemText-root": {
color: index === currentIndex ? "#6AE05F" : "",
},
"&:hover": {
backgroundColor: "rgba(36, 82, 32, 0.5)",
},
}}>
<ListItemIcon sx={{ color: "#6AE05F" }}>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText sx={{ color: "white" }} primary={text} />
</ListItem>
))}
I have this piece of code here that will make a list of reviews in react, is there a way to add more text into ListItemText because most online tutorials only go up to secondary but I want to add a tertiary text if possible
<Paper>
<List sx={{ width: '100%', maxWidth: 360, bgcolor: 'background.paper' }}>
{this.state.bookReviews.map((review =>
<>
<ListItem alignItems="flex-start" key={review.id}>
<ListItemAvatar>
<Avatar alt="Cindy Baker" />
</ListItemAvatar>
<ListItemText
primary={review.heading}
secondary={
<React.Fragment>
<Typography
sx={{ display: 'inline' }}
component="span"
variant="body2"
color="text.primary"
>
</Typography>
{review.reviewText}
</React.Fragment>
}
/>
</ListItem>
<Divider variant="inset" component="li"/>
</>
))}
</List>
</Paper>
I am using Material UI to create a list. My code below needs to reduce the height of the list element. I am not sure if it is padding or what. I tried setting <List dense={dense}> but it is still too spaced out.
<ListItem
button
onClick={() => {
board.current.setPosition(fenHistory[index + 1]);
plyViewed = index + 1;
}}
>
<ListItemText
classes={{ primary: classes.listItemText }}
primary={game.history()[index]}
/>
</ListItem>
The output current looks like the image below, but I want to reduce the height between the lines. Any ideas how?
Edit: Using the styling recommended in a reply, it is a little tighter now:
You can override default styles like this:
<ListItem button style={{ paddingTop: 0, paddingBottom: 0, margin: 0 }}>
<ListItemText primary={"sss"} style={{ lineHeight: 1, margin: 0 }} />
<ListItemText primary={"sss"} style={{ lineHeight: 1, margin: 0 }} />
<ListItemText primary={"sss"} style={{ lineHeight: 1, margin: 0 }} />
<ListItemText primary={"sss"} style={{ lineHeight: 1, margin: 0 }} />
</ListItem>