@mui/icons-material#Menu TypeScript Examples
The following examples show how to use
@mui/icons-material#Menu.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Layout.tsx From your_spotify with GNU General Public License v3.0 | 6 votes |
export default function Layout({ children }: LayoutProps) {
const [open, setOpen] = useState(false);
const showSider = !useMediaQuery('(max-width: 900px)');
const publicToken = useSelector(selectPublicToken);
const drawer = useCallback(() => {
setOpen((old) => !old);
}, []);
return (
<div className={s.root}>
{!showSider && (
<Drawer open={open} anchor="left" onClose={() => setOpen(false)}>
<Sider />
</Drawer>
)}
<section className={s.sider}>{showSider && <Sider />}</section>
<section
className={clsx({
[s.content]: true,
[s.contentdrawer]: showSider,
})}>
{publicToken && (
<div className={s.publictoken}>
<Text>You are viewing as guest</Text>
</div>
)}
{!showSider && (
<IconButton onClick={drawer} className={s.drawerbutton}>
<Menu />
</IconButton>
)}
{children}
</section>
</div>
);
}
Example #2
Source File: searchInput.tsx From Search-Next with GNU General Public License v3.0 | 6 votes |
function SearchInput() {
return (
<Paper
component="form"
sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}
>
<IconButton sx={{ p: '10px' }} aria-label="menu">
<Menu />
</IconButton>
<InputBase
sx={{ ml: 1, flex: 1 }}
placeholder="Search Google Maps"
inputProps={{ 'aria-label': 'search google maps' }}
/>
<IconButton type="submit" sx={{ p: '10px' }} aria-label="search">
<Search />
</IconButton>
</Paper>
);
}
Example #3
Source File: App.tsx From NekoMaid with MIT License | 4 votes |
App: React.FC<{ darkMode: boolean, setDarkMode: (a: boolean) => void }> = React.memo(({ darkMode, setDarkMode }) => {
const loc = useLocation()
const his = useHistory()
const pluginRef = useRef<Plugin | null>(null)
const [mobileOpen, setMobileOpen] = useState(false)
const [globalItemsOpen, setGlobalItemsOpen] = useState(false)
const [globalData, setGlobalData] = useState<GlobalInfo>({ } as any)
const [drawerWidth, setDrawerWidth] = useState(240)
const updateF = useState(0)[1]
const create = useMemo(() => {
const io = socketIO(origin!, { path: pathname!, auth: { token } })
const map: Record<string, Plugin> = { }
const fn = (window as any).__NekoMaidAPICreate = (name: string) => map[name] || (map[name] = new Plugin(io, name))
const nekoMaid = pluginRef.current = fn('NekoMaid')
io.on('globalData', (data: GlobalInfo) => {
const his: ServerRecord[] = JSON.parse(localStorage.getItem('NekoMaid:servers') || '[]')
const curAddress = address!.replace('http://', '') + '?' + token
let cur = his.find(it => it.address === curAddress)
if (!cur) his.push((cur = { address: curAddress, time: 0 }))
cur.time = Date.now()
cur.icon = data.icon
const arr = loc.pathname.split('/')
if (!sent && arr.length > 2) io.emit('switchPage', arr[1], arr[2])
sent = true
localStorage.setItem('NekoMaid:servers', JSON.stringify(his))
new Set(Object.values(data.plugins).flat()).forEach(loadPlugin)
setGlobalData(data)
pages = { }
initPages(nekoMaid)
onGlobalDataReceived(nekoMaid, data)
update(Math.random())
if (process.env.NODE_ENV !== 'development' && data.pluginVersion !== version) toast(lang.pluginUpdate, 'warning')
}).on('!', () => {
io.close()
dialog({ content: lang.wrongToken, cancelButton: false })
// eslint-disable-next-line no-return-assign
.then(() => (location.search = location.pathname = location.hash = ''))
}).on('reconnect', () => {
toast(lang.reconnect)
setTimeout(() => location.reload(), 5000)
}).on('disconnect', () => failed(lang.disconnected)).on('connect_error', () => failed(lang.failedToConnect))
return fn
}, [])
useEffect(() => { if (!loc.pathname || loc.pathname === '/') his.replace('/NekoMaid/dashboard') }, [loc.pathname])
useEffect(() => {
update = updateF
return () => { update = undefined as any }
}, [])
const handleDrawerToggle = () => {
setDrawerWidth(240)
setMobileOpen(!mobileOpen)
}
const isExpand = drawerWidth === 240
const routes: JSX.Element[] = []
const mapToItem = (name: string, it: Page) => {
const path = Array.isArray(it.path) ? it.path[0] : it.path
const key = '/' + name + '/' + path
routes.push(<pluginCtx.Provider key={key} value={create(name)}>
<Route
path={Array.isArray(it.path) ? it.path.map(it => '/' + name + '/' + it) : key}
component={it.component}
strict={it.strict}
exact={it.exact}
sensitive={it.sensitive}
/>
</pluginCtx.Provider>)
const icon = <ListItemIcon><pluginCtx.Provider value={create(name)}>
{(typeof it.icon === 'function' ? <it.icon /> : it.icon) || <Build />}
</pluginCtx.Provider></ListItemIcon>
return it.title
? <NavLink key={key} to={'/' + name + '/' + (it.url || path)} activeClassName='actived'>
<ListItem button>
{isExpand ? icon : <Tooltip title={it.title} placement='right'>{icon}</Tooltip>}
{isExpand && <ListItemText primary={it.title} />}
</ListItem>
</NavLink>
: undefined
}
const singlePages: JSX.Element[] = []
const multiPagesPages: Array<JSX.Element | JSX.Element[]> = []
let index = 0
for (const name in pages) {
if (pages[name].length === 1) {
const elm = mapToItem(name, pages[name][0])
if (elm) singlePages.push(elm)
} else {
if (multiPagesPages.length) multiPagesPages.push(<Divider key={index++} />)
multiPagesPages.push(pages[name].map(it => mapToItem(name, it)!).filter(Boolean))
}
}
if (singlePages.length) multiPagesPages.push(<Divider key={index++} />, singlePages)
const drawer = <Box sx={{ overflowX: 'hidden' }}>
<Toolbar />
<Divider sx={{ display: { sm: 'none', xs: 'block' } }} />
<List sx={{
'& a': {
color: 'inherit',
textDecoration: 'inherit'
},
'& .actived > div': {
fontWeight: 'bold',
color: theme => theme.palette.primary.main,
backgroundColor: theme => alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity) + '!important',
'& svg': { color: theme => theme.palette.primary.main + '!important' }
}
}}>{multiPagesPages.flat()}</List>
</Box>
return <Box sx={{ display: 'flex' }}>
<CssBaseline />
<AppBar position='fixed' sx={{ zIndex: theme => theme.zIndex.drawer + 1 }}>
<Toolbar>
<IconButton
color='inherit'
edge='start'
onClick={() => setDrawerWidth(isExpand ? 57 : 240)}
sx={{ mr: 1, display: { sm: 'inline-flex', xs: 'none' } }}
><ChevronLeft sx={{ transition: '.3s', transform: isExpand ? undefined : 'rotate(-180deg)' }} /></IconButton>
<IconButton color='inherit' edge='start' onClick={handleDrawerToggle} sx={{ mr: 2, display: { sm: 'none' } }}><Menu /></IconButton>
<Typography variant='h3' noWrap component='div' sx={{ flexGrow: 1 }}>NekoMaid</Typography>
{globalData.hasNBTAPI && <IconButton
color='inherit'
onClick={() => setGlobalItemsOpen(!globalItemsOpen)}
onDragOver={() => setGlobalItemsOpen(true)}
><Backpack /></IconButton>}
<LanguageSwitch />
<IconButton color='inherit' edge='end' onClick={() => setDarkMode(!darkMode)}>
{darkMode ? <Brightness7 /> : <Brightness4 />}
</IconButton>
</Toolbar>
</AppBar>
<globalCtx.Provider value={globalData}>
<Box component='nav' sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }}>
<Drawer
variant='temporary'
open={mobileOpen}
onClose={handleDrawerToggle}
ModalProps={{ keepMounted: true }}
sx={{
display: { xs: 'block', sm: 'none' },
'& .MuiDrawer-paper': {
boxSizing: 'border-box',
width: drawerWidth,
backgroundImage: theme => theme.palette.mode === 'dark'
? 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))'
: undefined
}
}}
>
{drawer}
</Drawer>
<Drawer
open
variant='permanent'
sx={{
display: { xs: 'none', sm: 'block' },
'& .MuiDrawer-paper': {
boxSizing: 'border-box',
width: drawerWidth,
transition: 'width .3s',
backgroundImage: theme => theme.palette.mode === 'dark' ? 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))' : undefined
}
}}
>
{drawer}
</Drawer>
</Box>
<Box component='main' sx={{ flexGrow: 1, width: '100vw' }}>
<drawerWidthCtx.Provider value={drawerWidth}>{routes}</drawerWidthCtx.Provider>
{globalData.hasNBTAPI && <pluginCtx.Provider value={pluginRef.current}>
<GlobalItems open={globalItemsOpen} onClose={() => setGlobalItemsOpen(false)} />
</pluginCtx.Provider>}
</Box>
</globalCtx.Provider>
</Box>
})
Example #4
Source File: AppNavBar.tsx From frontend with MIT License | 4 votes |
export default function AppNavBar({ navMenuToggle }: AppBarDeckProps) {
const { locale } = useRouter()
const { status } = useSession()
const shrink = useScrollTrigger()
return (
<AppBar
position="fixed"
className={clsx({ shrink })}
sx={(theme) => ({
overflow: 'hidden',
transition: 'height .5s, background-color .5s ease 0s',
height: theme.spacing(14),
lineHeight: theme.spacing(14),
[theme.breakpoints.down('md')]: {
height: theme.spacing(10),
},
'&.shrink': {
height: theme.spacing(10),
lineHeight: theme.spacing(10),
backgroundColor: 'hsla(0,0%,100%,0.85)',
backdropFilter: 'saturate(180%) blur(5px)',
},
backgroundColor: theme.palette.common.white,
})}>
<Toolbar
sx={{
height: '100%',
display: 'flex',
justifyContent: 'space-between',
}}>
<Link href={routes.index} passHref>
<ButtonBase
component="a"
className={clsx({ shrink })}
sx={(theme) => ({
transition: 'height .5s',
height: theme.spacing(7.5),
minWidth: theme.spacing(15),
marginLeft: theme.spacing(5),
[theme.breakpoints.up('lg')]: {
marginLeft: theme.spacing(10),
},
[theme.breakpoints.down('md')]: {
marginLeft: 0,
width: '100%',
height: '50%',
},
'&.shrink': {
height: '50%',
},
'& > svg': {
display: 'block',
height: '100%',
},
})}>
<PodkrepiLogo locale={locale} variant="adaptive" />
</ButtonBase>
</Link>
<Hidden mdDown>
<Grid
container
wrap="nowrap"
direction="row"
justifyContent="flex-end"
sx={(theme) => ({
marginLeft: theme.spacing(2),
marginRight: theme.spacing(5),
[theme.breakpoints.up('lg')]: {
marginRight: theme.spacing(10),
},
})}>
<Grid item>
<MainNavMenu>
{status === 'authenticated' ? <PrivateMenu /> : <PublicMenu />}
<Grid item>
<LocaleButton />
</Grid>
</MainNavMenu>
</Grid>
</Grid>
</Hidden>
<Hidden mdUp>
<IconButton
size="small"
edge="end"
onClick={navMenuToggle}
aria-labelledby="navigation menu">
<Menu fontSize="large" />
</IconButton>
</Hidden>
</Toolbar>
</AppBar>
)
}