Add search to mobile, fix light mode drawer background
This commit is contained in:
parent
3727a97973
commit
61e187199e
@ -5,7 +5,7 @@ import MenuIcon from '@mui/icons-material/Menu';
|
|||||||
import AppBar from '@mui/material/AppBar';
|
import AppBar from '@mui/material/AppBar';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled, useTheme } from '@mui/material/styles';
|
||||||
import Toolbar from '@mui/material/Toolbar';
|
import Toolbar from '@mui/material/Toolbar';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
@ -106,6 +106,7 @@ interface HeaderProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Header = ({ mode, docsGroups, searchablePages, toggleColorMode }: HeaderProps) => {
|
const Header = ({ mode, docsGroups, searchablePages, toggleColorMode }: HeaderProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
const [mobileOpen, setMobileOpen] = useState(false);
|
const [mobileOpen, setMobileOpen] = useState(false);
|
||||||
|
|
||||||
const handleDrawerToggle = useCallback(() => {
|
const handleDrawerToggle = useCallback(() => {
|
||||||
@ -151,10 +152,10 @@ const Header = ({ mode, docsGroups, searchablePages, toggleColorMode }: HeaderPr
|
|||||||
<MenuIcon fontSize="large" />
|
<MenuIcon fontSize="large" />
|
||||||
</StyledMenuButton>
|
</StyledMenuButton>
|
||||||
<Logo />
|
<Logo />
|
||||||
<Search searchablePages={searchablePages} />
|
|
||||||
<StyledIconsWrapper>
|
<StyledIconsWrapper>
|
||||||
|
<Search searchablePages={searchablePages} />
|
||||||
<IconButton
|
<IconButton
|
||||||
sx={{ ml: 1 }}
|
sx={{ [theme.breakpoints.up('lg')]: { ml: 1 } }}
|
||||||
onClick={toggleColorMode}
|
onClick={toggleColorMode}
|
||||||
color="inherit"
|
color="inherit"
|
||||||
title={mode === 'dark' ? 'Turn on the light' : 'Turn off the light'}
|
title={mode === 'dark' ? 'Turn on the light' : 'Turn off the light'}
|
||||||
|
@ -2,46 +2,19 @@ import { styled } from '@mui/material/styles';
|
|||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import transientOptions from '../../util/transientOptions';
|
const StyledImageLink = styled('a')`
|
||||||
|
|
||||||
interface StyledImageLinkProps {
|
|
||||||
$inDrawer: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const StyledImageLink = styled(
|
|
||||||
'a',
|
|
||||||
transientOptions,
|
|
||||||
)<StyledImageLinkProps>(
|
|
||||||
({ theme, $inDrawer }) => `
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
`;
|
||||||
${
|
|
||||||
!$inDrawer
|
|
||||||
? `
|
|
||||||
${theme.breakpoints.down('lg')} {
|
|
||||||
position: absolute;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, 0);
|
|
||||||
}
|
|
||||||
`
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const StyledImage = styled(Image)`
|
const StyledImage = styled(Image)`
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface LogoProps {
|
const Logo = () => {
|
||||||
inDrawer?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Logo = ({ inDrawer = false }: LogoProps) => {
|
|
||||||
return (
|
return (
|
||||||
<Link href="/">
|
<Link href="/">
|
||||||
<StyledImageLink $inDrawer={inDrawer}>
|
<StyledImageLink>
|
||||||
<StyledImage src="/static-cms-logo.svg" width={182} height={72} />
|
<StyledImage src="/static-cms-logo.svg" width={182} height={72} />
|
||||||
</StyledImageLink>
|
</StyledImageLink>
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -12,14 +12,19 @@ import type { MenuItem } from '../../../interface';
|
|||||||
const DRAWER_WIDTH = 300;
|
const DRAWER_WIDTH = 300;
|
||||||
|
|
||||||
const StyledDrawerContents = styled('div')`
|
const StyledDrawerContents = styled('div')`
|
||||||
padding-top: 16px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledLogoWrapper = styled('div')`
|
const StyledLogoWrapper = styled('div')(
|
||||||
|
({ theme }) => `
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
`;
|
padding: 16px 0;
|
||||||
|
background: ${
|
||||||
|
theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.background.paper
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
interface NavigationDrawerProps {
|
interface NavigationDrawerProps {
|
||||||
items: MenuItem[];
|
items: MenuItem[];
|
||||||
@ -39,9 +44,9 @@ const NavigationDrawer = ({ items, mobileOpen, onMobileOpenToggle }: NavigationD
|
|||||||
() => (
|
() => (
|
||||||
<StyledDrawerContents key="drawer-nav-contents" onClick={onMobileOpenToggle}>
|
<StyledDrawerContents key="drawer-nav-contents" onClick={onMobileOpenToggle}>
|
||||||
<StyledLogoWrapper key="drawer-nav-logo-wrapper">
|
<StyledLogoWrapper key="drawer-nav-logo-wrapper">
|
||||||
<Logo key="drawer-nav-logo" inDrawer />
|
<Logo key="drawer-nav-logo" />
|
||||||
</StyledLogoWrapper>
|
</StyledLogoWrapper>
|
||||||
<Divider key="drawer-nav-divider" sx={{ borderColor: 'rgba(255, 255, 255, 0.8)', pt: 2 }} />
|
<Divider key="drawer-nav-divider" sx={{ borderColor: 'rgba(255, 255, 255, 0.8)' }} />
|
||||||
<List key="drawer-nav-list">
|
<List key="drawer-nav-list">
|
||||||
{items.map(item => (
|
{items.map(item => (
|
||||||
<MobileNavItem key={`drawer-nav-item-${item.title}`} item={item} />
|
<MobileNavItem key={`drawer-nav-item-${item.title}`} item={item} />
|
||||||
@ -84,7 +89,7 @@ const NavigationDrawer = ({ items, mobileOpen, onMobileOpenToggle }: NavigationD
|
|||||||
boxSizing: 'border-box',
|
boxSizing: 'border-box',
|
||||||
width: '80%',
|
width: '80%',
|
||||||
maxWidth: DRAWER_WIDTH,
|
maxWidth: DRAWER_WIDTH,
|
||||||
background: '#2e3034',
|
background: theme.palette.background.paper,
|
||||||
},
|
},
|
||||||
'& .MuiListSubheader-root': {
|
'& .MuiListSubheader-root': {
|
||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
|
@ -3,6 +3,7 @@ import Button from '@mui/material/Button';
|
|||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
import IconButton from '@mui/material/IconButton';
|
||||||
|
|
||||||
import SearchModal from './SearchModal';
|
import SearchModal from './SearchModal';
|
||||||
|
|
||||||
@ -33,6 +34,14 @@ const StyledSearchPlaceholderBox = styled(Button)(
|
|||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const StyledIconButton = styled(IconButton)(
|
||||||
|
({ theme }) => `
|
||||||
|
${theme.breakpoints.up('lg')} {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
export interface SearchProps {
|
export interface SearchProps {
|
||||||
searchablePages: SearchablePage[];
|
searchablePages: SearchablePage[];
|
||||||
}
|
}
|
||||||
@ -65,6 +74,9 @@ const Search = ({ searchablePages }: SearchProps) => {
|
|||||||
Search the docs
|
Search the docs
|
||||||
</Typography>
|
</Typography>
|
||||||
</StyledSearchPlaceholderBox>
|
</StyledSearchPlaceholderBox>
|
||||||
|
<StyledIconButton onClick={handleOpen} color="inherit">
|
||||||
|
<SearchIcon />
|
||||||
|
</StyledIconButton>
|
||||||
<SearchModal open={open} onClose={handleClose} searchablePages={searchablePages} />
|
<SearchModal open={open} onClose={handleClose} searchablePages={searchablePages} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -13,10 +13,10 @@ const useCreateTheme = (mode: PaletteMode) => {
|
|||||||
? {
|
? {
|
||||||
mode,
|
mode,
|
||||||
primary: {
|
primary: {
|
||||||
main: '#3764be',
|
main: '#1b72de',
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
main: '#3764be',
|
main: '#1b72de',
|
||||||
},
|
},
|
||||||
background: {
|
background: {
|
||||||
default: '#f9f9f9',
|
default: '#f9f9f9',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user