|
| 1 | +import type {Meta, StoryFn} from '@storybook/react-vite' |
| 2 | +import type React from 'react' |
| 3 | +import {Hidden} from './Hidden' |
| 4 | + |
| 5 | +const meta: Meta = { |
| 6 | + title: 'Experimental/Components/Hidden/Responsive Tests', |
| 7 | + parameters: { |
| 8 | + layout: 'padded', |
| 9 | + controls: {expanded: true}, |
| 10 | + }, |
| 11 | +} |
| 12 | + |
| 13 | +export default meta |
| 14 | + |
| 15 | +const Box = ({children}: {children: React.ReactNode}) => ( |
| 16 | + <div |
| 17 | + style={{ |
| 18 | + padding: '16px', |
| 19 | + backgroundColor: '#0969da', |
| 20 | + color: 'white', |
| 21 | + borderRadius: '6px', |
| 22 | + marginBottom: '8px', |
| 23 | + }} |
| 24 | + > |
| 25 | + {children} |
| 26 | + </div> |
| 27 | +) |
| 28 | + |
| 29 | +/** |
| 30 | + * Test hiding content on narrow viewports only. |
| 31 | + * Resize the viewport to see the content hide on narrow and show on regular/wide. |
| 32 | + */ |
| 33 | +export const HiddenOnNarrow: StoryFn = () => ( |
| 34 | + <> |
| 35 | + <p>This box is hidden on narrow viewports, visible on regular and wide:</p> |
| 36 | + <Hidden when="narrow"> |
| 37 | + <Box>Hidden on narrow ({'<'}768px) → Visible on regular and wide (≥768px)</Box> |
| 38 | + </Hidden> |
| 39 | + </> |
| 40 | +) |
| 41 | + |
| 42 | +HiddenOnNarrow.parameters = { |
| 43 | + docs: { |
| 44 | + description: { |
| 45 | + story: 'Content is **hidden** on narrow viewports and **visible** on regular and wide viewports.', |
| 46 | + }, |
| 47 | + }, |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * Test hiding content on regular viewports only. |
| 52 | + * Resize the viewport to see the content show/hide at different breakpoints. |
| 53 | + */ |
| 54 | +export const HiddenOnRegular: StoryFn = () => ( |
| 55 | + <> |
| 56 | + <p>This box is hidden on regular viewports, visible on narrow and wide:</p> |
| 57 | + <Hidden when="regular"> |
| 58 | + <Box>Visible on narrow ({'<'}768px) → Hidden on regular (768-1399px) → Visible on wide (≥1400px)</Box> |
| 59 | + </Hidden> |
| 60 | + </> |
| 61 | +) |
| 62 | + |
| 63 | +HiddenOnRegular.parameters = { |
| 64 | + docs: { |
| 65 | + description: { |
| 66 | + story: 'Content is **visible** on narrow and wide viewports, **hidden** on regular viewports.', |
| 67 | + }, |
| 68 | + }, |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * Test hiding content on wide viewports only. |
| 73 | + * Resize the viewport to see the content hide on wide and show on narrow/regular. |
| 74 | + */ |
| 75 | +export const HiddenOnWide: StoryFn = () => ( |
| 76 | + <> |
| 77 | + <p>This box is hidden on wide viewports, visible on narrow and regular:</p> |
| 78 | + <Hidden when="wide"> |
| 79 | + <Box>Visible on narrow and regular ({'<'}1400px) → Hidden on wide (≥1400px)</Box> |
| 80 | + </Hidden> |
| 81 | + </> |
| 82 | +) |
| 83 | + |
| 84 | +HiddenOnWide.parameters = { |
| 85 | + docs: { |
| 86 | + description: { |
| 87 | + story: 'Content is **visible** on narrow and regular viewports, **hidden** on wide viewports.', |
| 88 | + }, |
| 89 | + }, |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * Test hiding content on multiple viewports (narrow and wide). |
| 94 | + * Only visible on regular viewports. |
| 95 | + */ |
| 96 | +export const HiddenOnNarrowAndWide: StoryFn = () => ( |
| 97 | + <> |
| 98 | + <p>This box is only visible on regular viewports:</p> |
| 99 | + <Hidden when={['narrow', 'wide']}> |
| 100 | + <Box>Hidden on narrow ({'<'}768px) → Visible on regular (768-1399px) → Hidden on wide (≥1400px)</Box> |
| 101 | + </Hidden> |
| 102 | + </> |
| 103 | +) |
| 104 | + |
| 105 | +HiddenOnNarrowAndWide.parameters = { |
| 106 | + docs: { |
| 107 | + description: { |
| 108 | + story: 'Content is **hidden** on narrow and wide viewports, only **visible** on regular viewports.', |
| 109 | + }, |
| 110 | + }, |
| 111 | +} |
| 112 | + |
| 113 | +/** |
| 114 | + * Test hiding content on multiple viewports (regular and wide). |
| 115 | + * Only visible on narrow viewports. |
| 116 | + */ |
| 117 | +export const HiddenOnRegularAndWide: StoryFn = () => ( |
| 118 | + <> |
| 119 | + <p>This box is only visible on narrow viewports:</p> |
| 120 | + <Hidden when={['regular', 'wide']}> |
| 121 | + <Box>Visible on narrow ({'<'}768px) → Hidden on regular and wide (≥768px)</Box> |
| 122 | + </Hidden> |
| 123 | + </> |
| 124 | +) |
| 125 | + |
| 126 | +HiddenOnRegularAndWide.parameters = { |
| 127 | + docs: { |
| 128 | + description: { |
| 129 | + story: 'Content is **visible** on narrow viewports, **hidden** on regular and wide viewports.', |
| 130 | + }, |
| 131 | + }, |
| 132 | +} |
0 commit comments