-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathBAIDeleteConfirmModal.stories.tsx
More file actions
315 lines (302 loc) · 8.41 KB
/
BAIDeleteConfirmModal.stories.tsx
File metadata and controls
315 lines (302 loc) · 8.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
'use memo';
import BAIButton from './BAIButton';
import BAIDeleteConfirmModal from './BAIDeleteConfirmModal';
import BAIFlex from './BAIFlex';
import { DeleteFilled, FolderOutlined } from '@ant-design/icons';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Checkbox, Space, Tag } from 'antd';
import { useState } from 'react';
const meta: Meta<typeof BAIDeleteConfirmModal> = {
title: 'Modal/BAIDeleteConfirmModal',
component: BAIDeleteConfirmModal,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component: `
**BAIDeleteConfirmModal** is a unified delete confirmation modal for table row deletion.
## Behavior
- **Single item**: Simple confirm dialog. OK button is immediately enabled.
- **Single item + \`requireConfirmInput\`**: Requires typing the item name. Item list is hidden — the name already appears in the description.
- **Multiple items (2+)**: Shows scrollable item list followed by a confirmation input requiring "Delete" to be typed.
## Key Features
- Accepts \`React.ReactNode\` for item labels (icons, tags, custom rendering)
- Scrollable item list for multi-item selections
- \`target\` prop produces a resource-type-aware default description ("Are you sure you want to permanently delete {target}?")
- \`extraContent\` slot for domain-specific additions (checkboxes, warnings)
- Built on \`BAIModal\`
`,
},
},
},
};
export default meta;
type Story = StoryObj<typeof BAIDeleteConfirmModal>;
export const SingleItem: Story = {
parameters: {
docs: {
description: {
story:
'Single item deletion with simple confirm. No text input required.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete Item
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={[{ key: '1', label: 'my-important-resource' }]}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const SingleItemWithInput: Story = {
parameters: {
docs: {
description: {
story:
'Single item with `requireConfirmInput={true}`. Item list is hidden (name already appears in description). User must type the item name into the confirmation input to enable the Delete button.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete (Confirm Required)
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={[{ key: '1', label: 'production-database' }]}
requireConfirmInput
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const WithTarget: Story = {
parameters: {
docs: {
description: {
story:
'Resource-typed deletion using the `target` prop. The default description becomes "Are you sure you want to permanently delete {target}?", surfacing the resource type (e.g. "Resource Preset", "Resource Policy") in the dialog copy. Typically paired with `requireConfirmInput` for irreversible deletes.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
const itemName = 'gpu-large-preset';
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete Resource Preset
</BAIButton>
<BAIDeleteConfirmModal
open={open}
title="Delete Resource Preset"
target="Resource Preset"
items={[{ key: itemName, label: itemName }]}
confirmText={itemName}
requireConfirmInput
inputProps={{ placeholder: itemName }}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const MultipleItems: Story = {
parameters: {
docs: {
description: {
story:
'Multiple items require typing "Delete" to confirm. Shows scrollable item list above the confirmation input.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
const items = [
{ key: '1', label: 'project-alpha' },
{ key: '2', label: 'project-beta' },
{ key: '3', label: 'project-gamma' },
{ key: '4', label: 'project-delta' },
{ key: '5', label: 'project-epsilon' },
];
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete 5 Items
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={items}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const ManyItems: Story = {
parameters: {
docs: {
description: {
story:
'Large selection (50 items) demonstrating scroll behavior within the item list.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
const items = Array.from({ length: 50 }, (_, i) => ({
key: String(i),
label: `resource-${String(i + 1).padStart(3, '0')}`,
}));
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete 50 Items
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={items}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const CustomRenderedItems: Story = {
parameters: {
docs: {
description: {
story:
'Items with ReactNode labels — icons, tags, and custom components.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
const items = [
{
key: '1',
label: (
<Space>
<FolderOutlined />
<span>shared-dataset</span>
<Tag color="blue">Public</Tag>
</Space>
),
},
{
key: '2',
label: (
<Space>
<FolderOutlined />
<span>model-weights-v2</span>
<Tag color="red">Private</Tag>
</Space>
),
},
{
key: '3',
label: (
<Space>
<FolderOutlined />
<span>training-logs</span>
<Tag color="green">Archived</Tag>
</Space>
),
},
];
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete Folders
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={items}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const WithExtraContent: Story = {
parameters: {
docs: {
description: {
story:
'Extra content slot with checkboxes, similar to PurgeUsersModal pattern.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
const items = [
{ key: '1', label: 'user-john@example.com' },
{ key: '2', label: 'user-jane@example.com' },
];
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Purge Users
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={items}
extraContent={
<BAIFlex direction="column" align="start">
<Checkbox>Also delete shared folders</Checkbox>
<Checkbox>Terminate running sessions</Checkbox>
</BAIFlex>
}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};
export const EmptyItems: Story = {
parameters: {
docs: {
description: {
story: 'Edge case: empty items array. OK button is disabled.',
},
},
},
render: () => {
const [open, setOpen] = useState(false);
return (
<>
<BAIButton danger icon={<DeleteFilled />} onClick={() => setOpen(true)}>
Delete (No Selection)
</BAIButton>
<BAIDeleteConfirmModal
open={open}
items={[]}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
/>
</>
);
},
};