gpt4 book ai didi

reactjs - 使用 Material-UI Drawer 添加可折叠功能

转载 作者:行者123 更新时间:2023-12-05 04:06:02 32 4
gpt4 key购买 nike

我能够在我的应用程序中设置抽屉。我发现默认设置中缺少的一项功能是可折叠选项,其中的部分是嵌套的。一个例子是 Mail,它有 inbox, sent, outbox, etc.

我希望它看起来像这样:

邮件
收件箱
发送
发件箱

我该怎么做?此文件在所有演示中共享。

import React from 'react';
import { ListItem, ListItemIcon, ListItemText } from 'material-ui/List';
import InboxIcon from '@material-ui/icons/MoveToInbox';
import DraftsIcon from '@material-ui/icons/Drafts';
import StarIcon from '@material-ui/icons/Star';
import SendIcon from '@material-ui/icons/Send';
import MailIcon from '@material-ui/icons/Mail';
import DeleteIcon from '@material-ui/icons/Delete';
import ReportIcon from '@material-ui/icons/Report';

export const mailFolderListItems = (
<div>
<ListItem button>
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText primary="Inbox" />
</ListItem>
<ListItem button>
<ListItemIcon>
<StarIcon />
</ListItemIcon>
<ListItemText primary="Starred" />
</ListItem>
<ListItem button>
<ListItemIcon>
<SendIcon />
</ListItemIcon>
<ListItemText primary="Send mail" />
</ListItem>
<ListItem button>
<ListItemIcon>
<DraftsIcon />
</ListItemIcon>
<ListItemText primary="Drafts" />
</ListItem>
</div>
);

export const otherMailFolderListItems = (
<div>
<ListItem button>
<ListItemIcon>
<MailIcon />
</ListItemIcon>
<ListItemText primary="All mail" />
</ListItem>
<ListItem button>
<ListItemIcon>
<DeleteIcon />
</ListItemIcon>
<ListItemText primary="Trash" />
</ListItem>
<ListItem button>
<ListItemIcon>
<ReportIcon />
</ListItemIcon>
<ListItemText primary="Spam" />
</ListItem>
</div>
);

//

最佳答案

查看“嵌套列表”演示:https://material-ui.com/demos/lists/#nested-list

// ...
import Collapse from '@material-ui/core/Collapse';
// ...

class NestedList extends React.Component {
state = { open: true };

handleClick = () => {
this.setState({ open: !this.state.open });
};

render() {
const { classes } = this.props;

return (
<div className={classes.root}>
<List
component="nav"
subheader={<ListSubheader component="div">Nested List Items</ListSubheader>}
>
{/* ... */}
<ListItem button onClick={this.handleClick}>
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText inset primary="Inbox" />
{this.state.open ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={this.state.open} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
<ListItem button className={classes.nested}>
<ListItemIcon>
<StarBorder />
</ListItemIcon>
<ListItemText inset primary="Starred" />
</ListItem>
</List>
</Collapse>
</List>
</div>
);
}
}

关于reactjs - 使用 Material-UI Drawer 添加可折叠功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50425921/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com