import React from 'react'; import {storiesOf} from '@storybook/react'; import {action} from '@storybook/addon-actions'; import {breakpoints} from 'moda-themes'; import {Breakpoint} from 'display-library/Responsive'; const DebugBreakpoint: React.FC<{ name: string; width: string; mode: string; }> = ({name, width, mode}) => { React.useEffect(() => { action(`mount ${mode} ${name}`)(); return (): void => action(`unmount ${mode} ${name}`)(); }, [mode, name]); return (
{mode}: {name} @{width}
); }; const DisplayBreakpoint: React.FC<{width: string}> = ({width}) => { return (
{width}
); }; const Watcher: React.FC<{from: string}> = ({from}) => { React.useEffect(() => { console.log(' mounted', {from}); }, [from]); return ( <> {console.log(' rendered', {from})}
The watcher watches
); }; storiesOf('Responsive', module) .add('Breakpoint', () => ( <> {Object.values(breakpoints).map(width => ( ))} {Object.entries(breakpoints).map(([name, width]: [string, string]) => { return ( <> ); })} )) .add('Breakpoint simple example', () => ( <> {Object.values(breakpoints).map(width => ( ))} Only displays on small screens Only displays on large screens )) .add('Breakpoint with mount events', () => ( <> Only displays on smaller screens Only displays on large screens )) .add('Breakpoint render props', () => ( {({matches}): React.ReactNode => matches ? 'Only displays on smaller screens' : 'Displays on large screens' } ));