@junyiacademy/ui-test 1.4.0 → 1.4.1
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/interfaces/index.d.ts +1 -2
- package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +1 -2
- package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +1 -1
- package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +1 -1
- package/dist/libs/ui/src/lib/menu-item/SelectMenuItem.js +4 -8
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +4 -6
- package/dist/libs/ui/src/lib/select/StandardSelect.js +5 -12
- package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +8 -5
- package/package.json +2 -2
- package/.storybook/main.js +0 -9
- package/.storybook/preview.js +0 -10
- package/.storybook/tsconfig.json +0 -14
- package/.storybook/webpack.config.js +0 -84
- package/src/index.ts +0 -7
- package/src/interfaces/index.tsx +0 -34
- package/src/lib/button/Button.stories.tsx +0 -50
- package/src/lib/button/Button.tsx +0 -85
- package/src/lib/button-group/ButtonGroup.stories.tsx +0 -59
- package/src/lib/button-group/ButtonGroup.tsx +0 -37
- package/src/lib/menu-item/SelectMenuItem.stories.tsx +0 -44
- package/src/lib/menu-item/SelectMenuItem.tsx +0 -48
- package/src/lib/radio/Radio.stories.tsx +0 -154
- package/src/lib/radio/Radio.tsx +0 -93
- package/src/lib/select/OutlinedSelect.tsx +0 -220
- package/src/lib/select/Select.stories.tsx +0 -306
- package/src/lib/select/Select.tsx +0 -13
- package/src/lib/select/StandardSelect.tsx +0 -178
- package/src/lib/text-field/TextField.stories.tsx +0 -160
- package/src/lib/text-field/TextField.tsx +0 -93
- package/src/lib/topic-filter/TopicFilter.stories.tsx +0 -83
- package/src/lib/topic-filter/TopicFilter.tsx +0 -209
- package/src/styles/theme.ts +0 -60
- package/src/utils/topicTree.ts +0 -197
|
@@ -1,306 +0,0 @@
|
|
|
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
|
-
variant: {
|
|
26
|
-
type: { name: 'string', required: false },
|
|
27
|
-
description: 'The variant to use.',
|
|
28
|
-
table: {
|
|
29
|
-
type: { summary: 'standard | outlined' },
|
|
30
|
-
defaultValue: { summary: 'standard' },
|
|
31
|
-
},
|
|
32
|
-
options: ['standard', 'outlined'],
|
|
33
|
-
control: { type: 'radio' },
|
|
34
|
-
},
|
|
35
|
-
size: {
|
|
36
|
-
type: { name: 'string', required: false },
|
|
37
|
-
description: `Adjust size`,
|
|
38
|
-
table: {
|
|
39
|
-
type: { summary: 'medium | small' },
|
|
40
|
-
defaultValue: { summary: 'small' },
|
|
41
|
-
},
|
|
42
|
-
options: ['small', 'medium'],
|
|
43
|
-
control: { type: 'radio' },
|
|
44
|
-
},
|
|
45
|
-
width: {
|
|
46
|
-
type: { name: 'number | string', required: false },
|
|
47
|
-
description: `Adjust width`,
|
|
48
|
-
table: {
|
|
49
|
-
type: { summary: 'number | string' },
|
|
50
|
-
defaultValue: { summary: 'auto' },
|
|
51
|
-
},
|
|
52
|
-
control: { type: 'number' },
|
|
53
|
-
},
|
|
54
|
-
selectMargin: {
|
|
55
|
-
type: { name: 'number | string', required: false },
|
|
56
|
-
description: `Adjust margin`,
|
|
57
|
-
table: {
|
|
58
|
-
type: { summary: 'number | string' },
|
|
59
|
-
defaultValue: { summary: '0' },
|
|
60
|
-
},
|
|
61
|
-
control: { type: 'number' },
|
|
62
|
-
},
|
|
63
|
-
paperMaxHeight: {
|
|
64
|
-
type: { name: 'number | string', required: false },
|
|
65
|
-
description: `Adjust select menu paper max height.`,
|
|
66
|
-
table: {
|
|
67
|
-
type: { summary: 'number | string' },
|
|
68
|
-
defaultValue: { summary: 'auto' },
|
|
69
|
-
},
|
|
70
|
-
control: { type: 'number' },
|
|
71
|
-
},
|
|
72
|
-
hasLabel: {
|
|
73
|
-
type: { name: 'boolean', required: false },
|
|
74
|
-
description:
|
|
75
|
-
'If true, the label is displayed. Always true on StandardSelect.',
|
|
76
|
-
table: {
|
|
77
|
-
type: { summary: 'boolean' },
|
|
78
|
-
defaultValue: { summary: true },
|
|
79
|
-
},
|
|
80
|
-
control: { type: 'boolean' },
|
|
81
|
-
},
|
|
82
|
-
hasShrink: {
|
|
83
|
-
type: { name: 'boolean', required: false },
|
|
84
|
-
description: 'If true, the label is displayed and shrunk.',
|
|
85
|
-
table: {
|
|
86
|
-
type: { summary: 'boolean' },
|
|
87
|
-
defaultValue: { summary: false },
|
|
88
|
-
},
|
|
89
|
-
control: { type: 'boolean' },
|
|
90
|
-
},
|
|
91
|
-
placeholder: {
|
|
92
|
-
type: { name: 'string', required: true },
|
|
93
|
-
description: `The label title`,
|
|
94
|
-
table: {
|
|
95
|
-
type: { summary: 'string' },
|
|
96
|
-
defaultValue: { summary: '請選擇' },
|
|
97
|
-
},
|
|
98
|
-
control: { type: 'text' },
|
|
99
|
-
},
|
|
100
|
-
value: {
|
|
101
|
-
type: { name: 'any', required: false },
|
|
102
|
-
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.
|
|
103
|
-
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.`,
|
|
104
|
-
table: {
|
|
105
|
-
type: { summary: 'any' },
|
|
106
|
-
defaultValue: { summary: '' },
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
disabled: {
|
|
110
|
-
type: { name: 'boolean', required: false },
|
|
111
|
-
description: 'If true, the input element will be disabled.',
|
|
112
|
-
table: {
|
|
113
|
-
type: { summary: 'boolean' },
|
|
114
|
-
defaultValue: { summary: false },
|
|
115
|
-
},
|
|
116
|
-
control: { type: 'boolean' },
|
|
117
|
-
},
|
|
118
|
-
error: {
|
|
119
|
-
type: { name: 'boolean', required: false },
|
|
120
|
-
description: 'If true, the label will be displayed in an error state.',
|
|
121
|
-
table: {
|
|
122
|
-
type: { summary: 'boolean' },
|
|
123
|
-
defaultValue: { summary: false },
|
|
124
|
-
},
|
|
125
|
-
control: { type: 'boolean' },
|
|
126
|
-
},
|
|
127
|
-
helperText: {
|
|
128
|
-
type: { name: 'string', required: true },
|
|
129
|
-
description: `Display the helper text.`,
|
|
130
|
-
table: {
|
|
131
|
-
type: { summary: 'string' },
|
|
132
|
-
defaultValue: { summary: '' },
|
|
133
|
-
},
|
|
134
|
-
control: { type: 'text' },
|
|
135
|
-
},
|
|
136
|
-
SelectProps: {
|
|
137
|
-
type: { name: 'any', required: false },
|
|
138
|
-
description: 'Attributes applied to inner Select element.',
|
|
139
|
-
table: {
|
|
140
|
-
type: { summary: 'any' },
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
CommonInputProps: {
|
|
144
|
-
type: { name: 'any', required: false },
|
|
145
|
-
description:
|
|
146
|
-
'Attributes applied to to inner OutlinedInput element on OutlinedSelect or Input element on StandardSelect.',
|
|
147
|
-
table: {
|
|
148
|
-
type: { summary: 'any' },
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
} as Meta
|
|
153
|
-
|
|
154
|
-
const PLACEHOLDER = 'Please select an option'
|
|
155
|
-
const ERROR_PLACEHOLDER = 'Please select an option'
|
|
156
|
-
const PREFIX = 'JuiSelect'
|
|
157
|
-
|
|
158
|
-
const classes = {
|
|
159
|
-
inputAdornmentRoot: `${PREFIX}-inputAdornmentRoot`,
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
interface StyledInputAdornmentProps {
|
|
163
|
-
disabled: boolean
|
|
164
|
-
theme?: Theme
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const StyledInputAdornment = styled(({ disabled: _disabled, ...props }) => (
|
|
168
|
-
<InputAdornment
|
|
169
|
-
classes={{
|
|
170
|
-
root: classes.inputAdornmentRoot,
|
|
171
|
-
}}
|
|
172
|
-
{...props}
|
|
173
|
-
/>
|
|
174
|
-
))(({ disabled, theme }: StyledInputAdornmentProps) => ({
|
|
175
|
-
height: '100%',
|
|
176
|
-
[`&.${classes.inputAdornmentRoot}`]: {
|
|
177
|
-
color: disabled
|
|
178
|
-
? theme.palette.action.disabled
|
|
179
|
-
: theme.palette.action.active,
|
|
180
|
-
},
|
|
181
|
-
}))
|
|
182
|
-
|
|
183
|
-
// Standard Select start with here.
|
|
184
|
-
const SelectWithMenu = (props: SelectProps) => {
|
|
185
|
-
const [item, setItem] = useState<string>('')
|
|
186
|
-
|
|
187
|
-
const handleChange = (event) => {
|
|
188
|
-
setItem(event.target.value)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return (
|
|
192
|
-
<Select
|
|
193
|
-
value={item}
|
|
194
|
-
SelectProps={{
|
|
195
|
-
onChange: (e) => {
|
|
196
|
-
handleChange(e)
|
|
197
|
-
},
|
|
198
|
-
}}
|
|
199
|
-
{...props}
|
|
200
|
-
>
|
|
201
|
-
<SelectMenuItem width={props.width} value='' disabled>
|
|
202
|
-
{PLACEHOLDER}
|
|
203
|
-
</SelectMenuItem>
|
|
204
|
-
<SelectMenuItem width={props.width} value='Option1'>
|
|
205
|
-
This is a select menu item
|
|
206
|
-
</SelectMenuItem>
|
|
207
|
-
<SelectMenuItem width={props.width} value='Option2'>
|
|
208
|
-
This is option 2
|
|
209
|
-
</SelectMenuItem>
|
|
210
|
-
</Select>
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const ValueOnlyStory: Story<SelectProps> = (args) => (
|
|
215
|
-
<SelectWithMenu {...args} />
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
export const ValueOnly = ValueOnlyStory.bind({})
|
|
219
|
-
|
|
220
|
-
ValueOnly.args = {
|
|
221
|
-
color: 'primary',
|
|
222
|
-
variant: 'standard',
|
|
223
|
-
size: 'small',
|
|
224
|
-
width: 300,
|
|
225
|
-
paperMaxHeight: 300,
|
|
226
|
-
hasShrink: false,
|
|
227
|
-
placeholder: PLACEHOLDER,
|
|
228
|
-
helperText: 'Pick your choice',
|
|
229
|
-
disabled: false,
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const SelectWithError = (props: SelectProps) => {
|
|
233
|
-
const [item, setItem] = useState<string>('')
|
|
234
|
-
|
|
235
|
-
const handleChange = (event) => {
|
|
236
|
-
setItem(event.target.value)
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return (
|
|
240
|
-
<Select
|
|
241
|
-
value={item}
|
|
242
|
-
SelectProps={{
|
|
243
|
-
onChange: (e) => {
|
|
244
|
-
handleChange(e)
|
|
245
|
-
},
|
|
246
|
-
}}
|
|
247
|
-
error={item === ''}
|
|
248
|
-
helperText={item === '' ? ERROR_PLACEHOLDER : ''}
|
|
249
|
-
{...props}
|
|
250
|
-
>
|
|
251
|
-
<SelectMenuItem width={props.width} value='' disabled>
|
|
252
|
-
{PLACEHOLDER}
|
|
253
|
-
</SelectMenuItem>
|
|
254
|
-
<SelectMenuItem width={props.width} value={'Test'}>
|
|
255
|
-
This is a select menu item, This is a select menu item
|
|
256
|
-
</SelectMenuItem>
|
|
257
|
-
<SelectMenuItem width={props.width} value={'Example'}>
|
|
258
|
-
Example
|
|
259
|
-
</SelectMenuItem>
|
|
260
|
-
</Select>
|
|
261
|
-
)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const WithErrorStory: Story<SelectProps> = (args) => (
|
|
265
|
-
<SelectWithError {...args} />
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
export const WithError = WithErrorStory.bind({})
|
|
269
|
-
|
|
270
|
-
WithError.args = {
|
|
271
|
-
color: 'primary',
|
|
272
|
-
variant: 'standard',
|
|
273
|
-
size: 'small',
|
|
274
|
-
width: 300,
|
|
275
|
-
paperMaxHeight: 300,
|
|
276
|
-
hasShrink: false,
|
|
277
|
-
placeholder: PLACEHOLDER,
|
|
278
|
-
disabled: false,
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const WithPrefixStory: Story<SelectProps> = (args) => (
|
|
282
|
-
<SelectWithMenu
|
|
283
|
-
InputProps={{
|
|
284
|
-
startAdornment: (
|
|
285
|
-
<StyledInputAdornment position='start' disabled={args.disabled}>
|
|
286
|
-
<Visibility />
|
|
287
|
-
</StyledInputAdornment>
|
|
288
|
-
),
|
|
289
|
-
}}
|
|
290
|
-
{...args}
|
|
291
|
-
/>
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
export const WithPrefix = WithPrefixStory.bind({})
|
|
295
|
-
|
|
296
|
-
WithPrefix.args = {
|
|
297
|
-
color: 'primary',
|
|
298
|
-
variant: 'standard',
|
|
299
|
-
size: 'small',
|
|
300
|
-
width: 300,
|
|
301
|
-
paperMaxHeight: 300,
|
|
302
|
-
hasShrink: false,
|
|
303
|
-
placeholder: PLACEHOLDER,
|
|
304
|
-
helperText: 'Pick your choice',
|
|
305
|
-
disabled: false,
|
|
306
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Theme, styled } from '@material-ui/core/styles'
|
|
3
|
-
import {
|
|
4
|
-
InputLabel,
|
|
5
|
-
FormControl,
|
|
6
|
-
Select,
|
|
7
|
-
Input,
|
|
8
|
-
FormHelperText,
|
|
9
|
-
} from '@material-ui/core'
|
|
10
|
-
import { SelectProps } from '../../interfaces'
|
|
11
|
-
|
|
12
|
-
// self-defined-components
|
|
13
|
-
const PREFIX = 'JuiStandardSelect'
|
|
14
|
-
|
|
15
|
-
const classes = {
|
|
16
|
-
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
17
|
-
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
18
|
-
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
19
|
-
inputFocused: `${PREFIX}-inputFocused`,
|
|
20
|
-
inputInput: `${PREFIX}-input`,
|
|
21
|
-
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
22
|
-
inputError: `${PREFIX}-inputError`,
|
|
23
|
-
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
24
|
-
inputAdornmentRoot: `${PREFIX}-inputAdornmentRoot`,
|
|
25
|
-
selectPaper: `${PREFIX}-menuPaper`,
|
|
26
|
-
selectDisabled: `${PREFIX}-selectDisabled`,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface StyledFormControlProps {
|
|
30
|
-
color: 'primary' | 'secondary'
|
|
31
|
-
width: number | string
|
|
32
|
-
selectMargin: number | string
|
|
33
|
-
theme?: Theme
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const StyledFormControl = styled(
|
|
37
|
-
({ width: _width, selectMargin: _selectMargin, ...props }) => (
|
|
38
|
-
<FormControl {...props} />
|
|
39
|
-
)
|
|
40
|
-
)(({ width, selectMargin, theme }: StyledFormControlProps) => ({
|
|
41
|
-
width,
|
|
42
|
-
margin: selectMargin,
|
|
43
|
-
}))
|
|
44
|
-
|
|
45
|
-
interface StyledInputLabelProps {
|
|
46
|
-
color: 'primary' | 'secondary'
|
|
47
|
-
theme?: Theme
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const StyledInputLabel = styled(({ color: _color, ...props }) => (
|
|
51
|
-
<InputLabel
|
|
52
|
-
classes={{
|
|
53
|
-
focused: classes.inputLabelFocused,
|
|
54
|
-
error: classes.inputLabelError,
|
|
55
|
-
}}
|
|
56
|
-
{...props}
|
|
57
|
-
/>
|
|
58
|
-
))(({ color, theme }: StyledInputLabelProps) => ({
|
|
59
|
-
color: theme.palette.text.disabled,
|
|
60
|
-
margin: theme.spacing(0, 10, 1.5, 0),
|
|
61
|
-
[`&.${classes.inputLabelFocused}`]: {
|
|
62
|
-
color: theme.palette[color].main,
|
|
63
|
-
},
|
|
64
|
-
[`&.${classes.inputLabelError}`]: {
|
|
65
|
-
color: theme.palette.error.main,
|
|
66
|
-
},
|
|
67
|
-
}))
|
|
68
|
-
|
|
69
|
-
interface StyledSelectProps {
|
|
70
|
-
paperMaxHeight: number | string
|
|
71
|
-
hasAdornment: boolean
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const StyledSelect = styled(
|
|
75
|
-
({
|
|
76
|
-
paperMaxHeight: _selectPaperHeight,
|
|
77
|
-
hasAdornment: _hasAdornment,
|
|
78
|
-
className,
|
|
79
|
-
...props
|
|
80
|
-
}) => (
|
|
81
|
-
<Select
|
|
82
|
-
MenuProps={{
|
|
83
|
-
classes: { paper: className },
|
|
84
|
-
transformOrigin: {
|
|
85
|
-
vertical: 'top',
|
|
86
|
-
horizontal: 'left',
|
|
87
|
-
},
|
|
88
|
-
getContentAnchorEl: null,
|
|
89
|
-
}}
|
|
90
|
-
{...props}
|
|
91
|
-
/>
|
|
92
|
-
)
|
|
93
|
-
)(({ hasAdornment, paperMaxHeight }: StyledSelectProps) => ({
|
|
94
|
-
'&&': {
|
|
95
|
-
maxHeight: paperMaxHeight,
|
|
96
|
-
left: hasAdornment ? '48px !important' : '70px',
|
|
97
|
-
},
|
|
98
|
-
}))
|
|
99
|
-
|
|
100
|
-
interface StyledInputProps {
|
|
101
|
-
color: 'primary' | 'secondary'
|
|
102
|
-
theme: Theme
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const StyledInput = styled(({ color: _color, ...props }) => (
|
|
106
|
-
<Input
|
|
107
|
-
classes={{
|
|
108
|
-
input: classes.inputInput,
|
|
109
|
-
disabled: classes.inputDisabled,
|
|
110
|
-
underline: classes.inputUnderline,
|
|
111
|
-
error: classes.inputError,
|
|
112
|
-
}}
|
|
113
|
-
{...props}
|
|
114
|
-
/>
|
|
115
|
-
))(({ color, theme }: StyledInputProps) => ({
|
|
116
|
-
color: theme.palette.text.primary,
|
|
117
|
-
[`& .${classes.inputInput}`]: {
|
|
118
|
-
['&:focus']: {
|
|
119
|
-
background: 'rgba(0,0,0,0)',
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
123
|
-
[`&:after,&:hover:before`]: {
|
|
124
|
-
borderBottomColor: theme.palette[color].main,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
[`&.${classes.inputUnderline}.${classes.inputError}:not(.${classes.inputDisabled})`]: {
|
|
128
|
-
[`&:after,&:hover:before`]: {
|
|
129
|
-
borderBottomColor: theme.palette.error.main,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
}))
|
|
133
|
-
|
|
134
|
-
export function StandardSelect({
|
|
135
|
-
placeholder,
|
|
136
|
-
helperText,
|
|
137
|
-
InputProps,
|
|
138
|
-
SelectProps,
|
|
139
|
-
children,
|
|
140
|
-
color = 'primary',
|
|
141
|
-
size = 'small',
|
|
142
|
-
width = 'auto',
|
|
143
|
-
selectMargin = '0',
|
|
144
|
-
paperMaxHeight = 'auto',
|
|
145
|
-
error = false,
|
|
146
|
-
hasShrink = false,
|
|
147
|
-
value = '',
|
|
148
|
-
disabled = false,
|
|
149
|
-
}: SelectProps) {
|
|
150
|
-
const hasAdornment = !!InputProps?.startAdornment
|
|
151
|
-
const hasHelperText = !!helperText
|
|
152
|
-
return (
|
|
153
|
-
<StyledFormControl
|
|
154
|
-
color={color}
|
|
155
|
-
size={size}
|
|
156
|
-
width={width}
|
|
157
|
-
selectMargin={selectMargin}
|
|
158
|
-
disabled={disabled}
|
|
159
|
-
error={error}
|
|
160
|
-
>
|
|
161
|
-
<StyledInputLabel color={color} shrink={hasShrink ? true : undefined}>
|
|
162
|
-
{placeholder}
|
|
163
|
-
</StyledInputLabel>
|
|
164
|
-
<StyledSelect
|
|
165
|
-
value={value}
|
|
166
|
-
paperMaxHeight={paperMaxHeight}
|
|
167
|
-
hasAdornment={hasAdornment}
|
|
168
|
-
input={<StyledInput color={color} {...InputProps} />}
|
|
169
|
-
{...SelectProps}
|
|
170
|
-
>
|
|
171
|
-
{children}
|
|
172
|
-
</StyledSelect>
|
|
173
|
-
{hasHelperText && <FormHelperText>{helperText}</FormHelperText>}
|
|
174
|
-
</StyledFormControl>
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export default StandardSelect
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
2
|
-
import { Story, Meta } from '@storybook/react'
|
|
3
|
-
import { InputAdornment, TextFieldProps } from '@material-ui/core'
|
|
4
|
-
import { Visibility } from '@material-ui/icons'
|
|
5
|
-
import { TextField } from './TextField'
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
component: TextField,
|
|
9
|
-
title: 'TextFiled',
|
|
10
|
-
argTypes: {
|
|
11
|
-
color: {
|
|
12
|
-
type: { name: 'string', required: false },
|
|
13
|
-
description:
|
|
14
|
-
'The color of the component. It supports those theme colors that make sense for this component.',
|
|
15
|
-
table: {
|
|
16
|
-
type: { summary: 'primary | secondary' },
|
|
17
|
-
defaultValue: { summary: 'primary' },
|
|
18
|
-
},
|
|
19
|
-
options: ['primary', 'secondary'],
|
|
20
|
-
control: { type: 'radio' },
|
|
21
|
-
},
|
|
22
|
-
variant: {
|
|
23
|
-
type: { name: 'string', required: false },
|
|
24
|
-
description: 'The variant to use.',
|
|
25
|
-
table: {
|
|
26
|
-
type: { summary: 'standard | filled | outlined' },
|
|
27
|
-
defaultValue: { summary: 'standard' },
|
|
28
|
-
},
|
|
29
|
-
options: ['standard', 'filled', 'outlined'],
|
|
30
|
-
control: { type: 'radio' },
|
|
31
|
-
},
|
|
32
|
-
size: {
|
|
33
|
-
type: { name: 'string', required: false },
|
|
34
|
-
description: 'The size of the text field.',
|
|
35
|
-
table: {
|
|
36
|
-
type: { summary: 'small | medium' },
|
|
37
|
-
defaultValue: { summary: 'small' },
|
|
38
|
-
},
|
|
39
|
-
options: ['small', 'medium'],
|
|
40
|
-
control: { type: 'radio' },
|
|
41
|
-
},
|
|
42
|
-
disabled: {
|
|
43
|
-
type: { name: 'boolean', required: false },
|
|
44
|
-
description: 'If true, the input element will be disabled.',
|
|
45
|
-
table: {
|
|
46
|
-
type: { summary: 'boolean' },
|
|
47
|
-
defaultValue: { summary: false },
|
|
48
|
-
},
|
|
49
|
-
control: { type: 'boolean' },
|
|
50
|
-
},
|
|
51
|
-
error: {
|
|
52
|
-
type: { name: 'boolean', required: false },
|
|
53
|
-
description: 'If true, the label will be displayed in an error state.',
|
|
54
|
-
table: {
|
|
55
|
-
type: { summary: 'boolean' },
|
|
56
|
-
defaultValue: { summary: false },
|
|
57
|
-
},
|
|
58
|
-
control: { type: 'boolean' },
|
|
59
|
-
},
|
|
60
|
-
label: {
|
|
61
|
-
type: { name: 'string', required: false },
|
|
62
|
-
description: 'The label content.',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
} as Meta
|
|
66
|
-
|
|
67
|
-
const ValueOnlyStory: Story<TextFieldProps> = (args) => <TextField {...args} />
|
|
68
|
-
|
|
69
|
-
export const ValueOnly = ValueOnlyStory.bind({})
|
|
70
|
-
|
|
71
|
-
ValueOnly.args = {
|
|
72
|
-
variant: 'standard',
|
|
73
|
-
color: 'primary',
|
|
74
|
-
disabled: false,
|
|
75
|
-
error: false,
|
|
76
|
-
size: 'small',
|
|
77
|
-
label: 'Which UI?',
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const TextFieldWithError = (props: TextFieldProps) => {
|
|
81
|
-
const [value, setValue] = React.useState('')
|
|
82
|
-
const [isError, setIsError] = React.useState(false)
|
|
83
|
-
|
|
84
|
-
const handleChange = (event) => {
|
|
85
|
-
setValue(event.target.value)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (value.length > 3) {
|
|
90
|
-
setIsError(true)
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
setIsError(false)
|
|
94
|
-
return
|
|
95
|
-
}, [value])
|
|
96
|
-
|
|
97
|
-
return <TextField error={isError} onChange={handleChange} {...props} />
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const WithErrorStory: Story<TextFieldProps> = (args) => (
|
|
101
|
-
<TextFieldWithError {...args} />
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
export const WithError = WithErrorStory.bind({})
|
|
105
|
-
|
|
106
|
-
WithError.args = {
|
|
107
|
-
variant: 'standard',
|
|
108
|
-
color: 'primary',
|
|
109
|
-
disabled: false,
|
|
110
|
-
size: 'small',
|
|
111
|
-
label: 'No more than 3 words',
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const WithSuffixStory: Story<TextFieldProps> = (args) => (
|
|
115
|
-
<TextField
|
|
116
|
-
{...args}
|
|
117
|
-
InputProps={{
|
|
118
|
-
endAdornment: (
|
|
119
|
-
<InputAdornment position='end'>
|
|
120
|
-
<Visibility />
|
|
121
|
-
</InputAdornment>
|
|
122
|
-
),
|
|
123
|
-
}}
|
|
124
|
-
/>
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
export const WithSuffix = WithSuffixStory.bind({})
|
|
128
|
-
|
|
129
|
-
WithSuffix.args = {
|
|
130
|
-
variant: 'standard',
|
|
131
|
-
color: 'primary',
|
|
132
|
-
disabled: false,
|
|
133
|
-
error: false,
|
|
134
|
-
size: 'small',
|
|
135
|
-
label: 'Which UI?',
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const WithPrefixStory: Story<TextFieldProps> = (args) => (
|
|
139
|
-
<TextField
|
|
140
|
-
{...args}
|
|
141
|
-
InputProps={{
|
|
142
|
-
startAdornment: (
|
|
143
|
-
<InputAdornment disableTypography position='start'>
|
|
144
|
-
Kg
|
|
145
|
-
</InputAdornment>
|
|
146
|
-
),
|
|
147
|
-
}}
|
|
148
|
-
/>
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
export const WithPrefix = WithPrefixStory.bind({})
|
|
152
|
-
|
|
153
|
-
WithPrefix.args = {
|
|
154
|
-
variant: 'standard',
|
|
155
|
-
color: 'primary',
|
|
156
|
-
disabled: false,
|
|
157
|
-
error: false,
|
|
158
|
-
size: 'small',
|
|
159
|
-
label: 'Which UI?',
|
|
160
|
-
}
|