-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathPowerSearchMobile.stories.tsx
More file actions
318 lines (301 loc) · 7.87 KB
/
Copy pathPowerSearchMobile.stories.tsx
File metadata and controls
318 lines (301 loc) · 7.87 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
316
317
318
// Copyright (c) Meta Platforms, Inc. and affiliates.
import React, {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {PowerSearch, PowerSearchMobile} from '@astryxdesign/core/PowerSearch';
import type {
PowerSearchConfig,
PowerSearchFilter,
} from '@astryxdesign/core/PowerSearch';
import {useMediaQuery} from '@astryxdesign/core/hooks';
import {Text} from '@astryxdesign/core/Text';
import {VStack} from '@astryxdesign/core/Stack';
// =============================================================================
// Sample data
// =============================================================================
const statusValues = [
{value: 'open', label: 'Open'},
{value: 'in_progress', label: 'In Progress'},
{value: 'review', label: 'In Review'},
{value: 'closed', label: 'Closed'},
];
const tagValues = [
{value: 'bug', label: 'Bug'},
{value: 'feature', label: 'Feature'},
{value: 'docs', label: 'Documentation'},
{value: 'perf', label: 'Performance'},
{value: 'security', label: 'Security'},
];
const issueConfig: PowerSearchConfig = {
name: 'IssueSearch',
fields: [
{
key: 'status',
label: 'Status',
description: 'Where the issue sits in the workflow',
operators: [
{
key: 'is',
i18nKey: '@astryx.powersearch.operator.is',
value: {type: 'enum', values: statusValues},
},
{
key: 'isNot',
i18nKey: '@astryx.powersearch.operator.isNot',
value: {type: 'enum', values: statusValues},
},
],
},
{
key: 'title',
label: 'Title',
description: 'Free text anywhere in the issue title',
operators: [
{
key: 'contains',
i18nKey: '@astryx.powersearch.operator.contains',
value: {type: 'string'},
},
],
},
{
key: 'tags',
label: 'Tags',
group: 'Metadata',
operators: [
{
key: 'isAnyOf',
i18nKey: '@astryx.powersearch.operator.isAnyOf',
value: {type: 'enum_list', values: tagValues},
},
],
},
{
key: 'points',
label: 'Story points',
group: 'Metadata',
operators: [
{
key: 'greaterThan',
i18nKey: '@astryx.powersearch.operator.greaterThan',
value: {type: 'integer', minValue: 0, maxValue: 21},
},
],
},
{
key: 'created',
label: 'Created',
group: 'Dates',
operators: [
{
key: 'before',
i18nKey: '@astryx.powersearch.operator.before',
value: {type: 'date_absolute', isDateOnly: true},
},
{
key: 'after',
i18nKey: '@astryx.powersearch.operator.after',
value: {type: 'date_absolute', isDateOnly: true},
},
],
},
{
key: 'unassigned',
label: 'Unassigned',
description: 'Nobody has picked it up yet',
group: 'Metadata',
operators: [
{
key: 'isTrue',
i18nKey: '@astryx.powersearch.operator.isTrue',
value: {type: 'empty'},
},
],
},
],
};
// A config long enough that the sheet offers a search box over the field list.
const wideConfig: PowerSearchConfig = {
name: 'WideSearch',
fields: [
...issueConfig.fields,
...[
'Assignee',
'Reporter',
'Component',
'Milestone',
'Sprint',
'Resolution',
].map(label => ({
key: label.toLowerCase(),
label,
group: 'People and planning',
operators: [
{
key: 'is',
i18nKey: '@astryx.powersearch.operator.is',
value: {type: 'string'} as const,
},
],
})),
],
};
// =============================================================================
// Meta
// =============================================================================
const meta: Meta<typeof PowerSearchMobile> = {
title: 'Core/PowerSearchMobile',
component: PowerSearchMobile,
tags: ['autodocs'],
decorators: [
Story => (
<div style={{width: 390, maxWidth: '100%'}}>
<Story />
</div>
),
],
argTypes: {
placeholder: {control: 'text'},
isDisabled: {control: 'boolean'},
isReadOnly: {control: 'boolean'},
hasClear: {control: 'boolean'},
maxTokenLength: {control: 'number'},
popoverSaveButtonLabel: {control: 'text'},
size: {control: 'radio', options: ['sm', 'md', 'lg']},
},
};
export default meta;
type Story = StoryObj<typeof PowerSearchMobile>;
// =============================================================================
// Stories
// =============================================================================
export const Default: Story = {
render: args => {
const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>(
[],
);
return (
<PowerSearchMobile
{...args}
config={issueConfig}
filters={filters}
onChange={setFilters}
/>
);
},
};
export const WithFilters: Story = {
render: args => {
const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>([
{field: 'status', operator: 'is', value: {type: 'enum', value: 'open'}},
{
field: 'tags',
operator: 'isAnyOf',
value: {type: 'enum_list', value: ['bug', 'perf']},
},
]);
return (
<PowerSearchMobile
{...args}
config={issueConfig}
filters={filters}
onChange={setFilters}
resultCount={filters.length === 0 ? 248 : 31}
/>
);
},
};
/**
* Past seven or so fields the sheet adds a search box above the list, pinned
* under the title while the list scrolls.
*/
export const SearchableFieldList: Story = {
render: args => {
const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>(
[],
);
return (
<PowerSearchMobile
{...args}
config={wideConfig}
filters={filters}
onChange={setFilters}
/>
);
},
};
export const ReadOnly: Story = {
args: {isReadOnly: true, isLabelHidden: false, label: 'Applied filters'},
render: args => (
<PowerSearchMobile
{...args}
config={issueConfig}
filters={[
{field: 'status', operator: 'is', value: {type: 'enum', value: 'open'}},
]}
onChange={() => {}}
/>
),
};
export const Disabled: Story = {
args: {
isDisabled: true,
isLabelHidden: false,
label: 'Filters',
disabledMessage: 'Pick a project before filtering',
},
render: args => (
<PowerSearchMobile
{...args}
config={issueConfig}
filters={[]}
onChange={() => {}}
/>
),
};
export const WithStatus: Story = {
args: {
isLabelHidden: false,
label: 'Filters',
status: {type: 'error', message: 'Add at least one filter'},
},
render: args => {
const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>(
[],
);
return (
<PowerSearchMobile
{...args}
config={issueConfig}
filters={filters}
onChange={setFilters}
/>
);
},
};
/**
* The intended production shape: one call site, one viewport check, both
* variants fed the same props. Resize the preview across 768px to swap.
*/
export const Responsive: Story = {
parameters: {controls: {disable: true}},
render: () => {
const isTouch = useMediaQuery('(max-width: 768px)');
const Search = isTouch ? PowerSearchMobile : PowerSearch;
const [filters, setFilters] = useState<ReadonlyArray<PowerSearchFilter>>(
[],
);
return (
<VStack gap={2}>
<Text type="supporting" color="secondary">
Rendering {isTouch ? 'PowerSearchMobile' : 'PowerSearch'}
</Text>
<Search
config={issueConfig}
filters={filters}
onChange={setFilters}
resultCount={filters.length === 0 ? 248 : 31}
/>
</VStack>
);
},
};