@junyiacademy/ui-test 0.0.9 → 0.0.13

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 (28) hide show
  1. package/declarations/libs/ui/src/index.d.ts +2 -3
  2. package/declarations/libs/ui/src/interfaces/index.d.ts +18 -0
  3. package/declarations/libs/ui/src/lib/TopicFilter.d.ts +1 -1
  4. package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +1 -1
  5. package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +2 -21
  6. package/declarations/libs/ui/src/lib/select/Select.d.ts +3 -0
  7. package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +2 -18
  8. package/declarations/libs/ui/src/lib/topic-filter/TopicFilter.d.ts +13 -0
  9. package/dist/libs/ui/src/index.js +4 -6
  10. package/dist/libs/ui/src/lib/TopicFilter.js +3 -1
  11. package/dist/libs/ui/src/lib/select/OutlinedSelect.js +24 -7
  12. package/dist/libs/ui/src/lib/select/Select.js +16 -0
  13. package/dist/libs/ui/src/lib/select/StandardSelect.js +16 -3
  14. package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +120 -0
  15. package/package.json +1 -1
  16. package/src/index.ts +2 -3
  17. package/src/interfaces/index.tsx +25 -0
  18. package/src/lib/select/OutlinedSelect.tsx +37 -44
  19. package/src/lib/select/Select.stories.tsx +421 -0
  20. package/src/lib/select/Select.tsx +13 -0
  21. package/src/lib/select/StandardSelect.tsx +24 -33
  22. package/src/lib/{TopicFilter.stories.tsx → topic-filter/TopicFilter.stories.tsx} +10 -7
  23. package/src/lib/{TopicFilter.tsx → topic-filter/TopicFilter.tsx} +5 -5
  24. package/src/lib/TopicFilter.spec.tsx +0 -10
  25. package/src/lib/menu-item/SelectMenuItem.spec.tsx +0 -10
  26. package/src/lib/select/OutlinedSelect.spec.tsx +0 -10
  27. package/src/lib/select/OutlinedSelect.stories.tsx +0 -245
  28. package/src/lib/select/StandardSelect.stories.tsx +0 -221
@@ -1,10 +1,13 @@
1
1
  import React from 'react'
2
2
  import { Story, Meta } from '@storybook/react'
3
- import TopicFilter, { TopicFilterProps } from './TopicFilter'
4
- import { topicTree } from '../utils/topicTree'
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: TopicFilter,
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 OutlinedSelectStory: Story<TopicFilterProps> = (args) => (
67
- <TopicFilter {...args} />
69
+ const TopicFilterStory: Story<JuiTopicFilterProps> = (args) => (
70
+ <JuiTopicFilter {...args} />
68
71
  )
69
72
 
70
- export const OutlinedSelect = OutlinedSelectStory.bind({})
73
+ export const TopicFilter = TopicFilterStory.bind({})
71
74
 
72
- OutlinedSelect.args = {
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 '../interfaces'
5
- import OutlinedSelect from './select/OutlinedSelect'
6
- import SelectMenuItem from './menu-item/SelectMenuItem'
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
- OutlinedInputProps={{
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
- })
@@ -1,245 +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 OutlinedSelect, { OutlinedSelectProps } from './OutlinedSelect'
7
- import SelectMenuItem from '../menu-item/SelectMenuItem'
8
-
9
- const PLACEHOLDER = '請選擇'
10
-
11
- export default {
12
- component: OutlinedSelect,
13
- title: 'OutlinedSelect',
14
- argTypes: {
15
- color: {
16
- type: { name: 'string', required: false },
17
- description:
18
- 'The color of the component. It supports those theme colors that make sense for this component.',
19
- table: {
20
- type: { summary: 'primary | secondary' },
21
- defaultValue: { summary: 'primary' },
22
- },
23
- options: ['primary', 'secondary'],
24
- control: { type: 'radio' },
25
- },
26
- size: {
27
- type: { name: 'string', required: false },
28
- description: `Adjust size`,
29
- table: {
30
- type: { summary: 'medium | small' },
31
- defaultValue: { summary: 'medium' },
32
- },
33
- options: ['small', 'medium'],
34
- control: { type: 'radio' },
35
- },
36
- width: {
37
- type: { name: 'number', required: false },
38
- description: `Adjust width`,
39
- table: {
40
- type: { summary: 'number' },
41
- defaultValue: { summary: 'auto' },
42
- },
43
- control: { type: 'number' },
44
- },
45
- paperMaxHeight: {
46
- type: { name: 'number', required: false },
47
- description: `Adjust select menu paper max height.`,
48
- table: {
49
- type: { summary: 'number' },
50
- defaultValue: { summary: 'auto' },
51
- },
52
- control: { type: 'number' },
53
- },
54
- hasInputLabel: {
55
- type: { name: 'boolean', required: false },
56
- description: 'If true, the label is displayed.',
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
- OutlinedInputProps: {
125
- type: { name: 'any', required: false },
126
- description: 'Attributes applied to to inner OutlinedInput element.',
127
- table: {
128
- type: { summary: 'any' },
129
- },
130
- },
131
- },
132
- } as Meta
133
-
134
- const PREFIX = 'JuiOutlinedSelect'
135
-
136
- const classes = {
137
- outlineInputAdornmentRoot: `${PREFIX}-outlineInputAdornmentRoot`,
138
- }
139
-
140
- interface StyledInputAdornmentProps {
141
- disabled: boolean
142
- theme?: Theme
143
- }
144
-
145
- const StyledInputAdornment = styled(({ disabled: _disabled, ...props }) => (
146
- <InputAdornment
147
- classes={{
148
- root: classes.outlineInputAdornmentRoot,
149
- }}
150
- {...props}
151
- />
152
- ))(({ disabled, theme }: StyledInputAdornmentProps) => ({
153
- [`&.${classes.outlineInputAdornmentRoot}`]: {
154
- color: disabled
155
- ? theme.palette.action.disabled
156
- : theme.palette.action.active,
157
- },
158
- }))
159
-
160
- const OutlinedSelectWithMenu = (props: OutlinedSelectProps) => {
161
- return (
162
- <OutlinedSelect {...props}>
163
- <SelectMenuItem width={220} value='' disabled>
164
- {PLACEHOLDER}
165
- </SelectMenuItem>
166
- <SelectMenuItem width={220} value='Test'>
167
- This is a select menu item
168
- </SelectMenuItem>
169
- <SelectMenuItem width={220} value='Example'>
170
- Example
171
- </SelectMenuItem>
172
- </OutlinedSelect>
173
- )
174
- }
175
-
176
- const ValueOnlyStory: Story<OutlinedSelectProps> = (args) => {
177
- const [item, setItem] = useState<string>('')
178
-
179
- const handleChange = (event) => {
180
- setItem(event.target.value)
181
- }
182
- return (
183
- <OutlinedSelectWithMenu
184
- OutlinedInputProps={{
185
- onChange: (e) => {
186
- handleChange(e)
187
- },
188
- }}
189
- value={item}
190
- {...args}
191
- />
192
- )
193
- }
194
-
195
- export const ValueOnly = ValueOnlyStory.bind({})
196
-
197
- ValueOnly.args = {
198
- color: 'primary',
199
- size: 'medium',
200
- width: 220,
201
- paperMaxHeight: 412,
202
- hasInputLabel: true,
203
- placeholder: PLACEHOLDER,
204
- helperText: 'test',
205
- disabled: false,
206
- SelectProps: {},
207
- }
208
-
209
- const WithPrefixStory: Story<OutlinedSelectProps> = (args) => {
210
- const [item, setItem] = useState<string>('')
211
-
212
- const handleChange = (event) => {
213
- setItem(event.target.value)
214
- }
215
- return (
216
- <OutlinedSelectWithMenu
217
- OutlinedInputProps={{
218
- onChange: (e) => {
219
- handleChange(e)
220
- },
221
- startAdornment: (
222
- <StyledInputAdornment position='start' disabled={args.disabled}>
223
- <Visibility />
224
- </StyledInputAdornment>
225
- ),
226
- }}
227
- value={item}
228
- {...args}
229
- />
230
- )
231
- }
232
-
233
- export const WithPrefix = WithPrefixStory.bind({})
234
-
235
- WithPrefix.args = {
236
- color: 'primary',
237
- size: 'medium',
238
- width: 220,
239
- paperMaxHeight: 412,
240
- hasInputLabel: true,
241
- placeholder: PLACEHOLDER,
242
- helperText: 'test',
243
- disabled: false,
244
- SelectProps: {},
245
- }
@@ -1,221 +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 { StandardSelect, StandardSelectProps } from './StandardSelect'
7
- import SelectMenuItem from '../menu-item/SelectMenuItem'
8
-
9
- const PLACEHOLDER = '請選擇'
10
-
11
- export default {
12
- component: StandardSelect,
13
- title: 'StandardSelect',
14
- argTypes: {
15
- color: {
16
- type: { name: 'string', required: false },
17
- description:
18
- 'The color of the component. It supports those theme colors that make sense for this component.',
19
- table: {
20
- type: { summary: 'primary | secondary' },
21
- defaultValue: { summary: 'primary' },
22
- },
23
- options: ['primary', 'secondary'],
24
- control: { type: 'radio' },
25
- },
26
- size: {
27
- type: { name: 'string', required: false },
28
- description: `Adjust size`,
29
- table: {
30
- type: { summary: 'medium | small' },
31
- defaultValue: { summary: 'medium' },
32
- },
33
- options: ['small', 'medium'],
34
- control: { type: 'radio' },
35
- },
36
- width: {
37
- type: { name: 'number', required: false },
38
- description: `Adjust width`,
39
- table: {
40
- type: { summary: 'number' },
41
- defaultValue: { summary: 'auto' },
42
- },
43
- control: { type: 'number' },
44
- },
45
- paperMaxHeight: {
46
- type: { name: 'number', required: false },
47
- description: `Adjust select menu paper max height.`,
48
- table: {
49
- type: { summary: 'number' },
50
- defaultValue: { summary: 'auto' },
51
- },
52
- control: { type: 'number' },
53
- },
54
- hasShrink: {
55
- type: { name: 'boolean', required: false },
56
- description: 'If true, the label is displayed and shrunk.',
57
- table: {
58
- type: { summary: 'boolean' },
59
- defaultValue: { summary: true },
60
- },
61
- control: { type: 'boolean' },
62
- },
63
- placeholder: {
64
- type: { name: 'string', required: true },
65
- description: `The label title`,
66
- table: {
67
- type: { summary: 'string' },
68
- defaultValue: { summary: '請選擇' },
69
- },
70
- control: { type: 'text' },
71
- },
72
- value: {
73
- type: { name: 'any', required: false },
74
- 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.
75
- 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.`,
76
- table: {
77
- type: { summary: 'any' },
78
- defaultValue: { summary: '' },
79
- },
80
- },
81
- disabled: {
82
- type: { name: 'boolean', required: false },
83
- description: 'If true, the input element will be disabled.',
84
- table: {
85
- type: { summary: 'boolean' },
86
- defaultValue: { summary: false },
87
- },
88
- control: { type: 'boolean' },
89
- },
90
- error: {
91
- type: { name: 'boolean', required: false },
92
- description: 'If true, the label will be displayed in an error state.',
93
- table: {
94
- type: { summary: 'boolean' },
95
- defaultValue: { summary: false },
96
- },
97
- control: { type: 'boolean' },
98
- },
99
- helperText: {
100
- type: { name: 'string', required: true },
101
- description: `Display the helper text.`,
102
- table: {
103
- type: { summary: 'string' },
104
- defaultValue: { summary: '' },
105
- },
106
- control: { type: 'text' },
107
- },
108
- InputProps: {
109
- type: { name: 'any', required: false },
110
- description: 'Attributes applied to inner Input element.',
111
- table: {
112
- type: { summary: 'any' },
113
- },
114
- },
115
- SelectProps: {
116
- type: { name: 'any', required: false },
117
- description: 'Attributes applied to inner Select element.',
118
- table: {
119
- type: { summary: 'any' },
120
- },
121
- },
122
- },
123
- } as Meta
124
-
125
- const PREFIX = 'JuiStandardSelect'
126
-
127
- const classes = {
128
- inputAdornmentRoot: `${PREFIX}-inputAdornmentRoot`,
129
- }
130
- interface StyledInputAdornmentProps {
131
- theme: Theme
132
- disabled: boolean
133
- }
134
-
135
- const StyledInputAdornment = styled(({ disabled: _disabled, ...props }) => (
136
- <InputAdornment
137
- classes={{
138
- root: classes.inputAdornmentRoot,
139
- }}
140
- {...props}
141
- />
142
- ))(({ disabled, theme }: StyledInputAdornmentProps) => ({
143
- [`&.${classes.inputAdornmentRoot}`]: {
144
- color: disabled
145
- ? theme.palette.action.disabled
146
- : theme.palette.action.active,
147
- },
148
- }))
149
-
150
- const StandardSelectWithMenu = (props: StandardSelectProps) => {
151
- const [item, setItem] = useState<string>('')
152
-
153
- const handleChange = (event) => {
154
- setItem(event.target.value)
155
- }
156
-
157
- return (
158
- <StandardSelect
159
- value={item}
160
- SelectProps={{
161
- onChange: (e) => {
162
- handleChange(e)
163
- },
164
- }}
165
- {...props}
166
- >
167
- <SelectMenuItem width={300} value='' disabled>
168
- {PLACEHOLDER}
169
- </SelectMenuItem>
170
- <SelectMenuItem width={300} value={'Test'}>
171
- This is a select menu item, This is a select menu item
172
- </SelectMenuItem>
173
- <SelectMenuItem width={300} value={'Example'}>
174
- Example
175
- </SelectMenuItem>
176
- </StandardSelect>
177
- )
178
- }
179
-
180
- const ValueOnlyStory: Story<StandardSelectProps> = (args) => (
181
- <StandardSelectWithMenu {...args} />
182
- )
183
-
184
- export const ValueOnly = ValueOnlyStory.bind({})
185
-
186
- ValueOnly.args = {
187
- color: 'primary',
188
- size: 'medium',
189
- width: 220,
190
- paperMaxHeight: 300,
191
- hasShrink: false,
192
- placeholder: PLACEHOLDER,
193
- helperText: 'test',
194
- disabled: false,
195
- }
196
-
197
- const WithPrefixStory: Story<StandardSelectProps> = (args) => (
198
- <StandardSelectWithMenu
199
- InputProps={{
200
- startAdornment: (
201
- <StyledInputAdornment position='start' disabled={args.disabled}>
202
- <Visibility />
203
- </StyledInputAdornment>
204
- ),
205
- }}
206
- {...args}
207
- />
208
- )
209
-
210
- export const WithPrefix = WithPrefixStory.bind({})
211
-
212
- WithPrefix.args = {
213
- color: 'primary',
214
- size: 'medium',
215
- width: 300,
216
- paperMaxHeight: 300,
217
- hasShrink: false,
218
- placeholder: PLACEHOLDER,
219
- helperText: 'test',
220
- disabled: false,
221
- }