|
| 1 | +import BAIFlex from './BAIFlex'; |
| 2 | +import BAIListAlert from './BAIListAlert'; |
| 3 | +import type { Meta, StoryObj } from '@storybook/react-vite'; |
| 4 | +import * as _ from 'lodash-es'; |
| 5 | + |
| 6 | +const meta: Meta<typeof BAIListAlert> = { |
| 7 | + title: 'Alert/BAIListAlert', |
| 8 | + component: BAIListAlert, |
| 9 | + tags: ['autodocs'], |
| 10 | + parameters: { |
| 11 | + layout: 'padded', |
| 12 | + docs: { |
| 13 | + description: { |
| 14 | + component: ` |
| 15 | +**BAIListAlert** extends **BAIAlert** (and therefore [Ant Design Alert](https://ant.design/components/alert)). |
| 16 | +
|
| 17 | +It renders a standardized \`ul\` list inside the alert description — used to |
| 18 | +summarize a list of items (e.g. selected resources) inside a modal. The list |
| 19 | +scrolls vertically once it exceeds \`maxHeight\`, so the modal never grows |
| 20 | +unbounded. Item count indication belongs in the consumer-provided \`title\` |
| 21 | +prop (i18n \`count\` interpolation). |
| 22 | +
|
| 23 | +## BAI-Specific Props |
| 24 | +| Prop | Type | Default | Description | |
| 25 | +|------|------|---------|-------------| |
| 26 | +| \`items\` | \`Array<{ key?: React.Key; content: ReactNode }>\` | — | List entries rendered as \`li\` elements. \`key\` falls back to the array index | |
| 27 | +| \`maxHeight\` | \`CSSProperties['maxHeight']\` | \`165\` | Maximum height of the list before it scrolls vertically | |
| 28 | +
|
| 29 | +For all other props, refer to **BAIAlert** and [Ant Design Alert](https://ant.design/components/alert). |
| 30 | + `, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + argTypes: { |
| 35 | + items: { |
| 36 | + control: false, |
| 37 | + description: |
| 38 | + 'List entries rendered as li elements; key falls back to the array index', |
| 39 | + table: { |
| 40 | + type: { summary: 'Array<{ key?: React.Key; content: ReactNode }>' }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + maxHeight: { |
| 44 | + control: { type: 'number' }, |
| 45 | + description: 'Maximum height of the list before it scrolls vertically', |
| 46 | + table: { |
| 47 | + type: { summary: "CSSProperties['maxHeight']" }, |
| 48 | + defaultValue: { summary: '165' }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + // Hide Ant Design props used in args |
| 52 | + type: { table: { disable: true } }, |
| 53 | + title: { table: { disable: true } }, |
| 54 | + showIcon: { table: { disable: true } }, |
| 55 | + }, |
| 56 | +}; |
| 57 | + |
| 58 | +export default meta; |
| 59 | +type Story = StoryObj<typeof BAIListAlert>; |
| 60 | + |
| 61 | +// Default story: Use args for interactive Controls |
| 62 | +export const Default: Story = { |
| 63 | + name: 'Basic', |
| 64 | + args: { |
| 65 | + type: 'info', |
| 66 | + title: 'The following projects will be updated', |
| 67 | + showIcon: true, |
| 68 | + items: [ |
| 69 | + { key: 'a', content: 'project-alpha' }, |
| 70 | + { key: 'b', content: 'project-beta' }, |
| 71 | + { key: 'c', content: 'project-gamma' }, |
| 72 | + ], |
| 73 | + }, |
| 74 | + parameters: { |
| 75 | + docs: { |
| 76 | + description: { |
| 77 | + story: 'Basic list summary inside an info alert.', |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | +}; |
| 82 | + |
| 83 | +export const LongListWithScroll: Story = { |
| 84 | + args: { |
| 85 | + type: 'warning', |
| 86 | + title: 'The following 30 users will be updated', |
| 87 | + showIcon: true, |
| 88 | + items: _.map(_.range(30), (i) => ({ |
| 89 | + key: i, |
| 90 | + content: `user-${i + 1}@example.com`, |
| 91 | + })), |
| 92 | + }, |
| 93 | + parameters: { |
| 94 | + docs: { |
| 95 | + description: { |
| 96 | + story: |
| 97 | + 'A long list is capped at the default maxHeight (165px) and scrolls vertically, keeping the surrounding modal compact.', |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | +}; |
| 102 | + |
| 103 | +export const CustomMaxHeight: Story = { |
| 104 | + args: { |
| 105 | + type: 'warning', |
| 106 | + title: 'Custom maxHeight of 80px', |
| 107 | + showIcon: true, |
| 108 | + maxHeight: 80, |
| 109 | + items: _.map(_.range(10), (i) => ({ |
| 110 | + key: i, |
| 111 | + content: `item-${i + 1}`, |
| 112 | + })), |
| 113 | + }, |
| 114 | + parameters: { |
| 115 | + docs: { |
| 116 | + description: { |
| 117 | + story: 'The scroll cap can be adjusted via the maxHeight prop.', |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | +}; |
| 122 | + |
| 123 | +export const AlertTypes: Story = { |
| 124 | + render: () => ( |
| 125 | + <BAIFlex direction="column" gap="md" align="stretch"> |
| 126 | + <BAIListAlert |
| 127 | + type="warning" |
| 128 | + showIcon |
| 129 | + title="Warning: these users will be updated" |
| 130 | + items={[ |
| 131 | + { key: 1, content: 'admin@example.com' }, |
| 132 | + { key: 2, content: 'user@example.com' }, |
| 133 | + ]} |
| 134 | + /> |
| 135 | + <BAIListAlert |
| 136 | + type="info" |
| 137 | + showIcon |
| 138 | + ghostInfoBg={false} |
| 139 | + title="Info: these projects will be updated" |
| 140 | + items={[ |
| 141 | + { key: 1, content: 'project-alpha' }, |
| 142 | + { key: 2, content: 'project-beta' }, |
| 143 | + ]} |
| 144 | + /> |
| 145 | + </BAIFlex> |
| 146 | + ), |
| 147 | + parameters: { |
| 148 | + docs: { |
| 149 | + description: { |
| 150 | + story: |
| 151 | + 'Side-by-side comparison of warning and info (ghostInfoBg disabled) variants, matching the modal call sites.', |
| 152 | + }, |
| 153 | + }, |
| 154 | + }, |
| 155 | +}; |
| 156 | + |
| 157 | +export const TitleWithCount: Story = { |
| 158 | + args: { |
| 159 | + type: 'info', |
| 160 | + showIcon: true, |
| 161 | + ghostInfoBg: false, |
| 162 | + title: '3 folders are excluded because they cannot be deleted', |
| 163 | + items: [ |
| 164 | + { key: 'f1', content: 'shared-folder' }, |
| 165 | + { key: 'f2', content: 'model-store' }, |
| 166 | + { key: 'f3', content: 'pipeline-data' }, |
| 167 | + ], |
| 168 | + }, |
| 169 | + parameters: { |
| 170 | + docs: { |
| 171 | + description: { |
| 172 | + story: |
| 173 | + 'Item count indication stays in the consumer-provided title (i18n count interpolation) — the component does not render counts itself.', |
| 174 | + }, |
| 175 | + }, |
| 176 | + }, |
| 177 | +}; |
0 commit comments