useScreenType replaced with useMobile; hide breadcrumbs on mobile
This commit is contained in:
1 parent
822f1a0535
commit
471d8f4714
4 files changed
+12
-20
No files matched your search
@@ -10,6 +10,7 @@ import { Breadcrumbs } from '../Breadcrumbs'
|
|||||||
import { IBreadcumbsPart } from 'src/types'
|
import { IBreadcumbsPart } from 'src/types'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { route } from 'next/dist/next-server/server/router'
|
import { route } from 'next/dist/next-server/server/router'
|
||||||
|
import { useMobile } from 'src/hooks/useMobile'
|
||||||
|
|
||||||
const Navigation = dynamic(() => import('../Navigation').then(mod => mod.Navigation), {
|
const Navigation = dynamic(() => import('../Navigation').then(mod => mod.Navigation), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -23,6 +24,7 @@ export interface IAppProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const App: React.FC<IAppProps> = props => {
|
export const App: React.FC<IAppProps> = props => {
|
||||||
|
const hideBreadcrumbs = useMobile()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const wide = props.wide ?? false
|
const wide = props.wide ?? false
|
||||||
const blockStyle = {
|
const blockStyle = {
|
||||||
@@ -35,8 +37,8 @@ export const App: React.FC<IAppProps> = props => {
|
|||||||
header={(
|
header={(
|
||||||
<header>
|
<header>
|
||||||
<Navigation />
|
<Navigation />
|
||||||
{!props.breadcrumbs ? null : (
|
{hideBreadcrumbs || !props.breadcrumbs ? null : (
|
||||||
<Block direction={'vertical'} style={blockStyle}>
|
<Block direction={'horizontal'} style={blockStyle}>
|
||||||
<Content wide={wide}>
|
<Content wide={wide}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={props.breadcrumbs}
|
items={props.breadcrumbs}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { MenuToggle } from '../MenuToggle'
|
import { MenuToggle } from '../MenuToggle'
|
||||||
import { useScreenType } from 'src/hooks/useScreenType'
|
import { useMobile } from 'src/hooks/useMobile'
|
||||||
import { Menu } from '../Menu'
|
import { Menu } from '../Menu'
|
||||||
import { Overlay } from '../Overlay'
|
import { Overlay } from '../Overlay'
|
||||||
import { useState, useCallback, useContext } from 'react'
|
import { useState, useCallback, useContext } from 'react'
|
||||||
@@ -10,7 +10,7 @@ export interface INavigationProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Navigation: React.FC<INavigationProps> = props => {
|
export const Navigation: React.FC<INavigationProps> = props => {
|
||||||
const isMobile = useScreenType(['phone', 'tablet'])
|
const collapseMenu = useMobile()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const onClick = useCallback(
|
const onClick = useCallback(
|
||||||
() => {
|
() => {
|
||||||
@@ -34,7 +34,7 @@ export const Navigation: React.FC<INavigationProps> = props => {
|
|||||||
}
|
}
|
||||||
`}</style>
|
`}</style>
|
||||||
|
|
||||||
{isMobile ? (
|
{collapseMenu ? (
|
||||||
<MenuToggle
|
<MenuToggle
|
||||||
open={open}
|
open={open}
|
||||||
position={'right'}
|
position={'right'}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import useMedia from 'use-media'
|
||||||
|
|
||||||
|
export function useMobile(): boolean {
|
||||||
|
return useMedia('(max-width: 31.25em)', false)
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import * as React from 'react'
|
|
||||||
import useMedia from 'use-media'
|
|
||||||
|
|
||||||
export type Type = 'phone' | 'tablet' | 'laptop' | 'desktop'
|
|
||||||
|
|
||||||
export function useScreenType(types: Type[]): boolean {
|
|
||||||
const isPhone = useMedia('(max-width: 31.25em)')
|
|
||||||
const [match, setMatch] = React.useState(false)
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
setMatch(isPhone && types.includes('phone'))
|
|
||||||
}, [isPhone])
|
|
||||||
|
|
||||||
return match
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user