@junyiacademy/ui-test 0.0.8 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/libs/ui/src/index.d.ts +8 -0
- package/declarations/libs/ui/src/interfaces/index.d.ts +26 -0
- package/declarations/libs/ui/src/lib/TopicFilter.d.ts +13 -0
- package/declarations/libs/ui/src/lib/button/Button.d.ts +6 -0
- package/declarations/libs/ui/src/lib/button-group/ButtonGroup.d.ts +3 -0
- package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +9 -0
- package/declarations/libs/ui/src/lib/radio/Radio.d.ts +10 -0
- package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +3 -0
- package/declarations/libs/ui/src/lib/select/Select.d.ts +3 -0
- package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +3 -0
- package/declarations/libs/ui/src/lib/text-field/TextField.d.ts +3 -0
- package/declarations/libs/ui/src/lib/topic-filter/TopicFilter.d.ts +13 -0
- package/dist/libs/ui/src/index.js +22 -0
- package/dist/libs/ui/src/interfaces/index.js +2 -0
- package/dist/libs/ui/src/lib/TopicFilter.js +120 -0
- package/dist/libs/ui/src/lib/button/Button.js +71 -0
- package/dist/libs/ui/src/lib/button-group/ButtonGroup.js +33 -0
- package/dist/libs/ui/src/lib/menu-item/SelectMenuItem.js +27 -0
- package/dist/libs/ui/src/lib/radio/Radio.js +43 -0
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +124 -0
- package/dist/libs/ui/src/lib/select/Select.js +16 -0
- package/dist/libs/ui/src/lib/select/StandardSelect.js +103 -0
- package/dist/libs/ui/src/lib/text-field/TextField.js +75 -0
- package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +120 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/interfaces/index.tsx +25 -0
- package/src/lib/select/OutlinedSelect.tsx +37 -44
- package/src/lib/select/Select.stories.tsx +421 -0
- package/src/lib/select/Select.tsx +13 -0
- package/src/lib/select/StandardSelect.tsx +24 -33
- package/src/lib/{TopicFilter.stories.tsx → topic-filter/TopicFilter.stories.tsx} +10 -7
- package/src/lib/{TopicFilter.tsx → topic-filter/TopicFilter.tsx} +5 -5
- package/src/lib/TopicFilter.spec.tsx +0 -10
- package/src/lib/menu-item/SelectMenuItem.spec.tsx +0 -10
- package/src/lib/select/OutlinedSelect.spec.tsx +0 -10
- package/src/lib/select/OutlinedSelect.stories.tsx +0 -245
- package/src/lib/select/StandardSelect.stories.tsx +0 -221
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { Story, Meta } from '@storybook/react'
|
|
3
|
+
import { Theme, styled } from '@material-ui/core/styles'
|
|
4
|
+
import { InputAdornment } from '@material-ui/core'
|
|
5
|
+
import { Visibility } from '@material-ui/icons'
|
|
6
|
+
import { Select } from './Select'
|
|
7
|
+
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
8
|
+
import { SelectProps } from '../../interfaces'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
component: Select,
|
|
12
|
+
title: 'Select',
|
|
13
|
+
argTypes: {
|
|
14
|
+
color: {
|
|
15
|
+
type: { name: 'string', required: false },
|
|
16
|
+
description:
|
|
17
|
+
'The color of the component. It supports those theme colors that make sense for this component.',
|
|
18
|
+
table: {
|
|
19
|
+
type: { summary: 'primary | secondary' },
|
|
20
|
+
defaultValue: { summary: 'primary' },
|
|
21
|
+
},
|
|
22
|
+
options: ['primary', 'secondary'],
|
|
23
|
+
control: { type: 'radio' },
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
type: { name: 'string', required: false },
|
|
27
|
+
description: `Adjust size`,
|
|
28
|
+
table: {
|
|
29
|
+
type: { summary: 'medium | small' },
|
|
30
|
+
defaultValue: { summary: 'medium' },
|
|
31
|
+
},
|
|
32
|
+
options: ['small', 'medium'],
|
|
33
|
+
control: { type: 'radio' },
|
|
34
|
+
},
|
|
35
|
+
width: {
|
|
36
|
+
type: { name: 'number', required: false },
|
|
37
|
+
description: `Adjust width`,
|
|
38
|
+
table: {
|
|
39
|
+
type: { summary: 'number' },
|
|
40
|
+
defaultValue: { summary: 'auto' },
|
|
41
|
+
},
|
|
42
|
+
control: { type: 'number' },
|
|
43
|
+
},
|
|
44
|
+
paperMaxHeight: {
|
|
45
|
+
type: { name: 'number', required: false },
|
|
46
|
+
description: `Adjust select menu paper max height.`,
|
|
47
|
+
table: {
|
|
48
|
+
type: { summary: 'number' },
|
|
49
|
+
defaultValue: { summary: 'auto' },
|
|
50
|
+
},
|
|
51
|
+
control: { type: 'number' },
|
|
52
|
+
},
|
|
53
|
+
hasLabel: {
|
|
54
|
+
type: { name: 'boolean', required: false },
|
|
55
|
+
description:
|
|
56
|
+
'If true, the label is displayed. Always true on StandardSelect.',
|
|
57
|
+
table: {
|
|
58
|
+
type: { summary: 'boolean' },
|
|
59
|
+
defaultValue: { summary: true },
|
|
60
|
+
},
|
|
61
|
+
control: { type: 'boolean' },
|
|
62
|
+
},
|
|
63
|
+
hasShrink: {
|
|
64
|
+
type: { name: 'boolean', required: false },
|
|
65
|
+
description: 'If true, the label is displayed and shrunk.',
|
|
66
|
+
table: {
|
|
67
|
+
type: { summary: 'boolean' },
|
|
68
|
+
defaultValue: { summary: false },
|
|
69
|
+
},
|
|
70
|
+
control: { type: 'boolean' },
|
|
71
|
+
},
|
|
72
|
+
placeholder: {
|
|
73
|
+
type: { name: 'string', required: true },
|
|
74
|
+
description: `The label title`,
|
|
75
|
+
table: {
|
|
76
|
+
type: { summary: 'string' },
|
|
77
|
+
defaultValue: { summary: '請選擇' },
|
|
78
|
+
},
|
|
79
|
+
control: { type: 'text' },
|
|
80
|
+
},
|
|
81
|
+
value: {
|
|
82
|
+
type: { name: 'any', required: false },
|
|
83
|
+
description: `The input value. Providing an empty string will select no options. This prop is required when the native prop is false (default). Set to an empty string '' if you don't want any of the available options to be selected.
|
|
84
|
+
If the value is an object it must have reference equality with the option in order to be selected. If the value is not an object, the string representation must match with the string representation of the option in order to be selected.`,
|
|
85
|
+
table: {
|
|
86
|
+
type: { summary: 'any' },
|
|
87
|
+
defaultValue: { summary: '' },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
disabled: {
|
|
91
|
+
type: { name: 'boolean', required: false },
|
|
92
|
+
description: 'If true, the input element will be disabled.',
|
|
93
|
+
table: {
|
|
94
|
+
type: { summary: 'boolean' },
|
|
95
|
+
defaultValue: { summary: false },
|
|
96
|
+
},
|
|
97
|
+
control: { type: 'boolean' },
|
|
98
|
+
},
|
|
99
|
+
error: {
|
|
100
|
+
type: { name: 'boolean', required: false },
|
|
101
|
+
description: 'If true, the label will be displayed in an error state.',
|
|
102
|
+
table: {
|
|
103
|
+
type: { summary: 'boolean' },
|
|
104
|
+
defaultValue: { summary: false },
|
|
105
|
+
},
|
|
106
|
+
control: { type: 'boolean' },
|
|
107
|
+
},
|
|
108
|
+
helperText: {
|
|
109
|
+
type: { name: 'string', required: true },
|
|
110
|
+
description: `Display the helper text.`,
|
|
111
|
+
table: {
|
|
112
|
+
type: { summary: 'string' },
|
|
113
|
+
defaultValue: { summary: '' },
|
|
114
|
+
},
|
|
115
|
+
control: { type: 'text' },
|
|
116
|
+
},
|
|
117
|
+
SelectProps: {
|
|
118
|
+
type: { name: 'any', required: false },
|
|
119
|
+
description: 'Attributes applied to inner Select element.',
|
|
120
|
+
table: {
|
|
121
|
+
type: { summary: 'any' },
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
CommonInputProps: {
|
|
125
|
+
type: { name: 'any', required: false },
|
|
126
|
+
description:
|
|
127
|
+
'Attributes applied to to inner OutlinedInput element on OutlinedSelect or Input element on StandardSelect.',
|
|
128
|
+
table: {
|
|
129
|
+
type: { summary: 'any' },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
} as Meta
|
|
134
|
+
|
|
135
|
+
const PLACEHOLDER = 'Please select an option'
|
|
136
|
+
const ERROR_PLACEHOLDER = 'Please select an option'
|
|
137
|
+
const PREFIX = 'JuiSelect'
|
|
138
|
+
|
|
139
|
+
const classes = {
|
|
140
|
+
inputAdornmentRoot: `${PREFIX}-inputAdornmentRoot`,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface StyledInputAdornmentProps {
|
|
144
|
+
disabled: boolean
|
|
145
|
+
theme?: Theme
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const StyledInputAdornment = styled(({ disabled: _disabled, ...props }) => (
|
|
149
|
+
<InputAdornment
|
|
150
|
+
classes={{
|
|
151
|
+
root: classes.inputAdornmentRoot,
|
|
152
|
+
}}
|
|
153
|
+
{...props}
|
|
154
|
+
/>
|
|
155
|
+
))(({ disabled, theme }: StyledInputAdornmentProps) => ({
|
|
156
|
+
height: '100%',
|
|
157
|
+
[`&.${classes.inputAdornmentRoot}`]: {
|
|
158
|
+
color: disabled
|
|
159
|
+
? theme.palette.action.disabled
|
|
160
|
+
: theme.palette.action.active,
|
|
161
|
+
},
|
|
162
|
+
}))
|
|
163
|
+
|
|
164
|
+
// Outlined Select start with here.
|
|
165
|
+
interface OutlinedSelectWithMenuProps {
|
|
166
|
+
startAdornment?: React.ReactNode
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const OutlinedSelectWithMenu = ({
|
|
170
|
+
startAdornment,
|
|
171
|
+
...props
|
|
172
|
+
}: SelectProps & OutlinedSelectWithMenuProps) => {
|
|
173
|
+
const [item, setItem] = useState<string>('')
|
|
174
|
+
|
|
175
|
+
const handleChange = (event) => {
|
|
176
|
+
setItem(event.target.value)
|
|
177
|
+
}
|
|
178
|
+
return (
|
|
179
|
+
<Select
|
|
180
|
+
variant='outlined'
|
|
181
|
+
InputProps={{
|
|
182
|
+
onChange: (e) => {
|
|
183
|
+
handleChange(e)
|
|
184
|
+
},
|
|
185
|
+
startAdornment,
|
|
186
|
+
}}
|
|
187
|
+
value={item}
|
|
188
|
+
{...props}
|
|
189
|
+
>
|
|
190
|
+
<SelectMenuItem width={props.width} value='' disabled>
|
|
191
|
+
{PLACEHOLDER}
|
|
192
|
+
</SelectMenuItem>
|
|
193
|
+
<SelectMenuItem width={props.width} value='Test'>
|
|
194
|
+
This is a select menu item
|
|
195
|
+
</SelectMenuItem>
|
|
196
|
+
<SelectMenuItem width={props.width} value='Example'>
|
|
197
|
+
Example
|
|
198
|
+
</SelectMenuItem>
|
|
199
|
+
</Select>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const OutlinedValueOnlyStory: Story<SelectProps> = (args) => (
|
|
204
|
+
<OutlinedSelectWithMenu {...args} />
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
export const OutlinedValueOnly = OutlinedValueOnlyStory.bind({})
|
|
208
|
+
|
|
209
|
+
OutlinedValueOnly.args = {
|
|
210
|
+
color: 'primary',
|
|
211
|
+
size: 'medium',
|
|
212
|
+
width: 220,
|
|
213
|
+
paperMaxHeight: 412,
|
|
214
|
+
hasLabel: true,
|
|
215
|
+
placeholder: PLACEHOLDER,
|
|
216
|
+
helperText: 'Pick your choice',
|
|
217
|
+
disabled: false,
|
|
218
|
+
SelectProps: {},
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const OutlinedSelectWithError = ({
|
|
222
|
+
startAdornment,
|
|
223
|
+
...props
|
|
224
|
+
}: SelectProps & OutlinedSelectWithMenuProps) => {
|
|
225
|
+
const [item, setItem] = useState<string>('')
|
|
226
|
+
|
|
227
|
+
const handleChange = (event) => {
|
|
228
|
+
setItem(event.target.value)
|
|
229
|
+
}
|
|
230
|
+
return (
|
|
231
|
+
<Select
|
|
232
|
+
variant='outlined'
|
|
233
|
+
InputProps={{
|
|
234
|
+
onChange: (e) => {
|
|
235
|
+
handleChange(e)
|
|
236
|
+
},
|
|
237
|
+
startAdornment,
|
|
238
|
+
}}
|
|
239
|
+
value={item}
|
|
240
|
+
error={item === ''}
|
|
241
|
+
helperText={item === '' ? ERROR_PLACEHOLDER : ''}
|
|
242
|
+
{...props}
|
|
243
|
+
>
|
|
244
|
+
<SelectMenuItem width={props.width} value='' disabled>
|
|
245
|
+
{PLACEHOLDER}
|
|
246
|
+
</SelectMenuItem>
|
|
247
|
+
<SelectMenuItem width={props.width} value='Option1'>
|
|
248
|
+
This is a select menu item
|
|
249
|
+
</SelectMenuItem>
|
|
250
|
+
<SelectMenuItem width={props.width} value='Option2'>
|
|
251
|
+
This is option 2
|
|
252
|
+
</SelectMenuItem>
|
|
253
|
+
</Select>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const OutlinedWithErrorStory: Story<SelectProps> = (args) => (
|
|
258
|
+
<OutlinedSelectWithError {...args} />
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
export const OutlinedWithError = OutlinedWithErrorStory.bind({})
|
|
262
|
+
|
|
263
|
+
OutlinedWithError.args = {
|
|
264
|
+
color: 'primary',
|
|
265
|
+
size: 'medium',
|
|
266
|
+
width: 220,
|
|
267
|
+
paperMaxHeight: 412,
|
|
268
|
+
hasLabel: true,
|
|
269
|
+
placeholder: PLACEHOLDER,
|
|
270
|
+
disabled: false,
|
|
271
|
+
SelectProps: {},
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const OutlinedWithPrefixStory: Story<SelectProps> = (args) => (
|
|
275
|
+
<OutlinedSelectWithMenu
|
|
276
|
+
startAdornment={
|
|
277
|
+
<StyledInputAdornment position='start' disabled={args.disabled}>
|
|
278
|
+
<Visibility />
|
|
279
|
+
</StyledInputAdornment>
|
|
280
|
+
}
|
|
281
|
+
{...args}
|
|
282
|
+
/>
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
export const OutlinedWithPrefix = OutlinedWithPrefixStory.bind({})
|
|
286
|
+
|
|
287
|
+
OutlinedWithPrefix.args = {
|
|
288
|
+
color: 'primary',
|
|
289
|
+
size: 'medium',
|
|
290
|
+
width: 220,
|
|
291
|
+
paperMaxHeight: 412,
|
|
292
|
+
hasLabel: true,
|
|
293
|
+
placeholder: PLACEHOLDER,
|
|
294
|
+
helperText: 'Pick your choice',
|
|
295
|
+
disabled: false,
|
|
296
|
+
SelectProps: {},
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Standard Select start with here.
|
|
300
|
+
const StandardSelectWithMenu = (props: SelectProps) => {
|
|
301
|
+
const [item, setItem] = useState<string>('')
|
|
302
|
+
|
|
303
|
+
const handleChange = (event) => {
|
|
304
|
+
setItem(event.target.value)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
<Select
|
|
309
|
+
variant='standard'
|
|
310
|
+
value={item}
|
|
311
|
+
SelectProps={{
|
|
312
|
+
onChange: (e) => {
|
|
313
|
+
handleChange(e)
|
|
314
|
+
},
|
|
315
|
+
}}
|
|
316
|
+
{...props}
|
|
317
|
+
>
|
|
318
|
+
<SelectMenuItem width={props.width} value='' disabled>
|
|
319
|
+
{PLACEHOLDER}
|
|
320
|
+
</SelectMenuItem>
|
|
321
|
+
<SelectMenuItem width={props.width} value='Option1'>
|
|
322
|
+
This is a select menu item
|
|
323
|
+
</SelectMenuItem>
|
|
324
|
+
<SelectMenuItem width={props.width} value='Option2'>
|
|
325
|
+
This is option 2
|
|
326
|
+
</SelectMenuItem>
|
|
327
|
+
</Select>
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const StandardValueOnlyStory: Story<SelectProps> = (args) => (
|
|
332
|
+
<StandardSelectWithMenu {...args} />
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
export const StandardValueOnly = StandardValueOnlyStory.bind({})
|
|
336
|
+
|
|
337
|
+
StandardValueOnly.args = {
|
|
338
|
+
color: 'primary',
|
|
339
|
+
size: 'medium',
|
|
340
|
+
width: 300,
|
|
341
|
+
paperMaxHeight: 300,
|
|
342
|
+
hasShrink: false,
|
|
343
|
+
placeholder: PLACEHOLDER,
|
|
344
|
+
helperText: 'Pick your choice',
|
|
345
|
+
disabled: false,
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const StandardSelectWithError = (props: SelectProps) => {
|
|
349
|
+
const [item, setItem] = useState<string>('')
|
|
350
|
+
|
|
351
|
+
const handleChange = (event) => {
|
|
352
|
+
setItem(event.target.value)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<Select
|
|
357
|
+
variant='standard'
|
|
358
|
+
value={item}
|
|
359
|
+
SelectProps={{
|
|
360
|
+
onChange: (e) => {
|
|
361
|
+
handleChange(e)
|
|
362
|
+
},
|
|
363
|
+
}}
|
|
364
|
+
error={item === ''}
|
|
365
|
+
helperText={item === '' ? ERROR_PLACEHOLDER : ''}
|
|
366
|
+
{...props}
|
|
367
|
+
>
|
|
368
|
+
<SelectMenuItem width={props.width} value='' disabled>
|
|
369
|
+
{PLACEHOLDER}
|
|
370
|
+
</SelectMenuItem>
|
|
371
|
+
<SelectMenuItem width={props.width} value={'Test'}>
|
|
372
|
+
This is a select menu item, This is a select menu item
|
|
373
|
+
</SelectMenuItem>
|
|
374
|
+
<SelectMenuItem width={props.width} value={'Example'}>
|
|
375
|
+
Example
|
|
376
|
+
</SelectMenuItem>
|
|
377
|
+
</Select>
|
|
378
|
+
)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const StandardWithErrorStory: Story<SelectProps> = (args) => (
|
|
382
|
+
<StandardSelectWithError {...args} />
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
export const StandardWithError = StandardWithErrorStory.bind({})
|
|
386
|
+
|
|
387
|
+
StandardWithError.args = {
|
|
388
|
+
color: 'primary',
|
|
389
|
+
size: 'medium',
|
|
390
|
+
width: 300,
|
|
391
|
+
paperMaxHeight: 300,
|
|
392
|
+
hasShrink: false,
|
|
393
|
+
placeholder: PLACEHOLDER,
|
|
394
|
+
disabled: false,
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const StandardWithPrefixStory: Story<SelectProps> = (args) => (
|
|
398
|
+
<StandardSelectWithMenu
|
|
399
|
+
InputProps={{
|
|
400
|
+
startAdornment: (
|
|
401
|
+
<StyledInputAdornment position='start' disabled={args.disabled}>
|
|
402
|
+
<Visibility />
|
|
403
|
+
</StyledInputAdornment>
|
|
404
|
+
),
|
|
405
|
+
}}
|
|
406
|
+
{...args}
|
|
407
|
+
/>
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
export const StandardWithPrefix = StandardWithPrefixStory.bind({})
|
|
411
|
+
|
|
412
|
+
StandardWithPrefix.args = {
|
|
413
|
+
color: 'primary',
|
|
414
|
+
size: 'medium',
|
|
415
|
+
width: 300,
|
|
416
|
+
paperMaxHeight: 300,
|
|
417
|
+
hasShrink: false,
|
|
418
|
+
placeholder: PLACEHOLDER,
|
|
419
|
+
helperText: 'Pick your choice',
|
|
420
|
+
disabled: false,
|
|
421
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { OutlinedSelect } from './OutlinedSelect'
|
|
3
|
+
import { StandardSelect } from './StandardSelect'
|
|
4
|
+
import { SelectProps } from '../../interfaces'
|
|
5
|
+
|
|
6
|
+
export function Select({ variant, ...props }: SelectProps) {
|
|
7
|
+
if (variant === 'outlined') {
|
|
8
|
+
return <OutlinedSelect {...props} />
|
|
9
|
+
}
|
|
10
|
+
return <StandardSelect {...props} />
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default Select
|
|
@@ -4,12 +4,10 @@ import {
|
|
|
4
4
|
InputLabel,
|
|
5
5
|
FormControl,
|
|
6
6
|
Select,
|
|
7
|
-
SelectProps,
|
|
8
7
|
Input,
|
|
9
|
-
InputProps,
|
|
10
8
|
FormHelperText,
|
|
11
|
-
InputAdornment,
|
|
12
9
|
} from '@material-ui/core'
|
|
10
|
+
import { SelectProps } from '../../interfaces'
|
|
13
11
|
|
|
14
12
|
// self-defined-components
|
|
15
13
|
const PREFIX = 'JuiStandardSelect'
|
|
@@ -18,6 +16,9 @@ const classes = {
|
|
|
18
16
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
19
17
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
20
18
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
19
|
+
inputRoot: `${PREFIX}-inputRoot`,
|
|
20
|
+
inputFocused: `${PREFIX}-inputFocused`,
|
|
21
|
+
inputInput: `${PREFIX}-input`,
|
|
21
22
|
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
22
23
|
inputError: `${PREFIX}-inputError`,
|
|
23
24
|
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
@@ -92,7 +93,6 @@ const StyledSelect = styled(
|
|
|
92
93
|
maxHeight: paperMaxHeight,
|
|
93
94
|
left: hasAdornment ? '48px !important' : '70px',
|
|
94
95
|
},
|
|
95
|
-
[`&.${classes.selectDisabled}`]: {},
|
|
96
96
|
}))
|
|
97
97
|
|
|
98
98
|
interface StyledInputProps {
|
|
@@ -103,6 +103,9 @@ interface StyledInputProps {
|
|
|
103
103
|
const StyledInput = styled(({ color: _color, ...props }) => (
|
|
104
104
|
<Input
|
|
105
105
|
classes={{
|
|
106
|
+
root: classes.inputRoot,
|
|
107
|
+
focused: classes.inputFocused,
|
|
108
|
+
input: classes.inputInput,
|
|
106
109
|
disabled: classes.inputDisabled,
|
|
107
110
|
underline: classes.inputUnderline,
|
|
108
111
|
error: classes.inputError,
|
|
@@ -111,6 +114,14 @@ const StyledInput = styled(({ color: _color, ...props }) => (
|
|
|
111
114
|
/>
|
|
112
115
|
))(({ color, theme }: StyledInputProps) => ({
|
|
113
116
|
color: theme.palette.text.primary,
|
|
117
|
+
[`&.${classes.inputRoot}.${classes.inputFocused}`]: {
|
|
118
|
+
backgroundColor: theme.palette.action.selected,
|
|
119
|
+
},
|
|
120
|
+
[`& .${classes.inputInput}`]: {
|
|
121
|
+
['&:focus']: {
|
|
122
|
+
background: 'rgba(0,0,0,0)',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
114
125
|
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
115
126
|
[`&:after,&:hover:before`]: {
|
|
116
127
|
borderBottomColor: theme.palette[color].main,
|
|
@@ -123,37 +134,21 @@ const StyledInput = styled(({ color: _color, ...props }) => (
|
|
|
123
134
|
},
|
|
124
135
|
}))
|
|
125
136
|
|
|
126
|
-
export interface StandardSelectProps {
|
|
127
|
-
color?: 'primary' | 'secondary'
|
|
128
|
-
size?: 'medium' | 'small'
|
|
129
|
-
width?: number | 'auto'
|
|
130
|
-
paperMaxHeight?: number | 'auto'
|
|
131
|
-
error?: boolean
|
|
132
|
-
hasShrink?: boolean
|
|
133
|
-
placeholder: string
|
|
134
|
-
helperText?: string
|
|
135
|
-
InputProps?: object & Partial<InputProps>
|
|
136
|
-
value?: unknown
|
|
137
|
-
disabled?: boolean
|
|
138
|
-
SelectProps?: object | Partial<SelectProps>
|
|
139
|
-
children?: React.ReactNode
|
|
140
|
-
}
|
|
141
|
-
|
|
142
137
|
export function StandardSelect({
|
|
138
|
+
placeholder,
|
|
139
|
+
helperText,
|
|
140
|
+
InputProps,
|
|
141
|
+
SelectProps,
|
|
142
|
+
children,
|
|
143
143
|
color = 'primary',
|
|
144
144
|
size = 'medium',
|
|
145
145
|
width = 'auto',
|
|
146
146
|
paperMaxHeight = 'auto',
|
|
147
147
|
error = false,
|
|
148
148
|
hasShrink = false,
|
|
149
|
-
placeholder,
|
|
150
|
-
helperText,
|
|
151
|
-
InputProps,
|
|
152
149
|
value = '',
|
|
153
|
-
SelectProps,
|
|
154
150
|
disabled = false,
|
|
155
|
-
|
|
156
|
-
}: StandardSelectProps) {
|
|
151
|
+
}: SelectProps) {
|
|
157
152
|
const hasAdornment = !!InputProps?.startAdornment
|
|
158
153
|
const hasHelperText = !!helperText
|
|
159
154
|
return (
|
|
@@ -164,13 +159,9 @@ export function StandardSelect({
|
|
|
164
159
|
disabled={disabled}
|
|
165
160
|
error={error}
|
|
166
161
|
>
|
|
167
|
-
{hasShrink ?
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
</StyledInputLabel>
|
|
171
|
-
) : (
|
|
172
|
-
<StyledInputLabel color={color}>{placeholder}</StyledInputLabel>
|
|
173
|
-
)}
|
|
162
|
+
<StyledInputLabel color={color} shrink={hasShrink ? true : undefined}>
|
|
163
|
+
{placeholder}
|
|
164
|
+
</StyledInputLabel>
|
|
174
165
|
<StyledSelect
|
|
175
166
|
value={value}
|
|
176
167
|
paperMaxHeight={paperMaxHeight}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { Story, Meta } from '@storybook/react'
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
TopicFilter as JuiTopicFilter,
|
|
5
|
+
TopicFilterProps as JuiTopicFilterProps,
|
|
6
|
+
} from './TopicFilter'
|
|
7
|
+
import { topicTree } from '../../utils/topicTree'
|
|
5
8
|
|
|
6
9
|
export default {
|
|
7
|
-
component:
|
|
10
|
+
component: JuiTopicFilter,
|
|
8
11
|
title: 'TopicFilter',
|
|
9
12
|
argTypes: {
|
|
10
13
|
topicTree: {
|
|
@@ -63,13 +66,13 @@ export default {
|
|
|
63
66
|
},
|
|
64
67
|
} as Meta
|
|
65
68
|
|
|
66
|
-
const
|
|
67
|
-
<
|
|
69
|
+
const TopicFilterStory: Story<JuiTopicFilterProps> = (args) => (
|
|
70
|
+
<JuiTopicFilter {...args} />
|
|
68
71
|
)
|
|
69
72
|
|
|
70
|
-
export const
|
|
73
|
+
export const TopicFilter = TopicFilterStory.bind({})
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
TopicFilter.args = {
|
|
73
76
|
topicTree: topicTree,
|
|
74
77
|
onTopicSelected: () => {},
|
|
75
78
|
isLastLayer: (selectedTopic) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
2
|
import { Theme, styled } from '@material-ui/core/styles'
|
|
3
3
|
import ArrowRightRoundedIcon from '@material-ui/icons/ArrowRightRounded'
|
|
4
|
-
import type { ITopicTreeNode } from '
|
|
5
|
-
import OutlinedSelect from '
|
|
6
|
-
import SelectMenuItem from '
|
|
4
|
+
import type { ITopicTreeNode } from '../../interfaces'
|
|
5
|
+
import OutlinedSelect from '../select/OutlinedSelect'
|
|
6
|
+
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
7
7
|
|
|
8
8
|
// self-defined-configs
|
|
9
9
|
const PLACEHOLDER = '請選擇'
|
|
@@ -45,7 +45,7 @@ export interface TopicFilterProps {
|
|
|
45
45
|
initSelectedTopicIds: string[]
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const TopicFilter = ({
|
|
48
|
+
export const TopicFilter = ({
|
|
49
49
|
topicTree,
|
|
50
50
|
onTopicSelected,
|
|
51
51
|
isLastLayer,
|
|
@@ -150,7 +150,7 @@ const TopicFilter = ({
|
|
|
150
150
|
SelectProps={{
|
|
151
151
|
'data-testid': `layered-topic-${layerNumber}`,
|
|
152
152
|
}}
|
|
153
|
-
|
|
153
|
+
InputProps={{
|
|
154
154
|
inputProps: {
|
|
155
155
|
'aria-label': `layered-topic-${layerNumber}`,
|
|
156
156
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/react'
|
|
2
|
-
|
|
3
|
-
import TopicFilter from './TopicFilter'
|
|
4
|
-
|
|
5
|
-
describe('TopicFilter', () => {
|
|
6
|
-
it('should render successfully', () => {
|
|
7
|
-
const { baseElement } = render(<TopicFilter />)
|
|
8
|
-
expect(baseElement).toBeTruthy()
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/react'
|
|
2
|
-
|
|
3
|
-
import SelectMenuItem from './SelectMenuItem'
|
|
4
|
-
|
|
5
|
-
describe('SelectMenuItem', () => {
|
|
6
|
-
it('should render successfully', () => {
|
|
7
|
-
const { baseElement } = render(<SelectMenuItem />)
|
|
8
|
-
expect(baseElement).toBeTruthy()
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/react'
|
|
2
|
-
|
|
3
|
-
import OutlinedSelect from './OutlinedSelect'
|
|
4
|
-
|
|
5
|
-
describe('OutlinedSelect', () => {
|
|
6
|
-
it('should render successfully', () => {
|
|
7
|
-
const { baseElement } = render(<OutlinedSelect />)
|
|
8
|
-
expect(baseElement).toBeTruthy()
|
|
9
|
-
})
|
|
10
|
-
})
|