// @flow import * as React from 'react'; import { VIEW_SIZE_TYPE } from '../constants'; import notes from './MediaQuery.stories.md'; import useMediaQuery from '../useMediaQuery'; import withMediaQuery from '../withMediaQuery'; export const CustomHook = () => { const { hover, isTouchDevice, pointer, size, viewWidth, viewHeight } = useMediaQuery(); return (

Hover: {` ${hover}`}

Pointer: {` ${pointer}`}

Is Touch Device: {` ${String(isTouchDevice)}`}

View Dimensions: {` ${viewWidth}px (w) x ${viewHeight}px (h)`}

{size === VIEW_SIZE_TYPE.small &&

This view is small

} {size === VIEW_SIZE_TYPE.medium &&

This view is medium

} {size === VIEW_SIZE_TYPE.large &&

This view is large

} {size === VIEW_SIZE_TYPE.xlarge &&

This view is xlarge

}
); }; type Props = { children?: any, hover: string, isTouchDevice: boolean, pointer: string, size: string, viewHeight: number, viewWidth: number, }; const DemoComponent = (props: Props) => { const { hover, isTouchDevice, pointer, size, viewWidth, viewHeight } = props; return (

Hover: {` ${hover}`}

Pointer: {` ${pointer}`}

Is Touch Device: {` ${String(isTouchDevice)}`}

View Dimensions: {` ${viewWidth}px (w) x ${viewHeight}px (h)`}

{size === 'small' &&

This view is small

} {size === 'medium' &&

This view is medium

} {size === 'large' &&

This view is large

} {size === 'x-large' &&

This view is xlarge

}
); }; export const HigherOrderComponent = withMediaQuery(DemoComponent); export default { title: 'Components/MediaQuery', component: useMediaQuery, parameters: { notes, viewport: { defaultViewport: 'tablet', }, }, };