@junyiacademy/ui-test 0.0.14 → 1.5.0

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