@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.
Files changed (33) hide show
  1. package/declarations/libs/ui/src/interfaces/index.d.ts +1 -2
  2. package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +1 -2
  3. package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +1 -1
  4. package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +1 -1
  5. package/dist/libs/ui/src/lib/menu-item/SelectMenuItem.js +4 -8
  6. package/dist/libs/ui/src/lib/select/OutlinedSelect.js +4 -6
  7. package/dist/libs/ui/src/lib/select/StandardSelect.js +5 -12
  8. package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +8 -5
  9. package/package.json +2 -2
  10. package/.storybook/main.js +0 -9
  11. package/.storybook/preview.js +0 -10
  12. package/.storybook/tsconfig.json +0 -14
  13. package/.storybook/webpack.config.js +0 -84
  14. package/src/index.ts +0 -7
  15. package/src/interfaces/index.tsx +0 -34
  16. package/src/lib/button/Button.stories.tsx +0 -50
  17. package/src/lib/button/Button.tsx +0 -85
  18. package/src/lib/button-group/ButtonGroup.stories.tsx +0 -59
  19. package/src/lib/button-group/ButtonGroup.tsx +0 -37
  20. package/src/lib/menu-item/SelectMenuItem.stories.tsx +0 -44
  21. package/src/lib/menu-item/SelectMenuItem.tsx +0 -48
  22. package/src/lib/radio/Radio.stories.tsx +0 -154
  23. package/src/lib/radio/Radio.tsx +0 -93
  24. package/src/lib/select/OutlinedSelect.tsx +0 -220
  25. package/src/lib/select/Select.stories.tsx +0 -306
  26. package/src/lib/select/Select.tsx +0 -13
  27. package/src/lib/select/StandardSelect.tsx +0 -178
  28. package/src/lib/text-field/TextField.stories.tsx +0 -160
  29. package/src/lib/text-field/TextField.tsx +0 -93
  30. package/src/lib/topic-filter/TopicFilter.stories.tsx +0 -83
  31. package/src/lib/topic-filter/TopicFilter.tsx +0 -209
  32. package/src/styles/theme.ts +0 -60
  33. package/src/utils/topicTree.ts +0 -197
@@ -1,44 +0,0 @@
1
- import React from 'react'
2
- import { Story, Meta } from '@storybook/react'
3
- import { Menu } from '@material-ui/core'
4
- import SelectMenuItem, { SelectMenuItemProps } from './SelectMenuItem'
5
-
6
- export default {
7
- component: SelectMenuItem,
8
- title: 'SelectMenuItem',
9
- argTypes: {
10
- value: {
11
- type: { name: 'any', required: false },
12
- 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.
13
- 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.`,
14
- table: {
15
- type: { summary: 'any' },
16
- defaultValue: { summary: '' },
17
- },
18
- },
19
- disabled: {
20
- type: { name: 'boolean', required: false },
21
- description: 'Control the disabled display state.',
22
- table: {
23
- type: { summary: 'boolean' },
24
- defaultValue: { summary: true },
25
- },
26
- control: { type: 'boolean' },
27
- defaultValue: true,
28
- },
29
- },
30
- } as Meta
31
-
32
- const Template: Story<SelectMenuItemProps> = (args) => (
33
- <Menu open={true}>
34
- <SelectMenuItem {...args}>Test</SelectMenuItem>
35
- <SelectMenuItem {...args}>Example</SelectMenuItem>
36
- </Menu>
37
- )
38
-
39
- export const Primary = Template.bind({})
40
-
41
- Primary.args = {
42
- value: '',
43
- disabled: false,
44
- }
@@ -1,48 +0,0 @@
1
- import React, { PropsWithChildren } from 'react'
2
- import { Theme, styled } from '@material-ui/core/styles'
3
- import { MenuItem, MenuItemProps } from '@material-ui/core'
4
-
5
- // self-defined-components
6
- const PREFIX = 'JuiSelectMenuItem'
7
-
8
- const classes = {
9
- menuItemSelected: `${PREFIX}-menuItemSelected`,
10
- }
11
-
12
- interface StyledMenuItemProps {
13
- width: number | string
14
- theme?: Theme
15
- }
16
-
17
- const StyledMenuItem = styled(({ width: _width, ...props }) => (
18
- <MenuItem classes={{ selected: classes.menuItemSelected }} {...props} />
19
- ))(({ width, theme }: StyledMenuItemProps) => ({
20
- width: width,
21
- whiteSpace: 'unset',
22
- color: theme.palette.text.primary,
23
- [`&.${classes.menuItemSelected}`]: {
24
- backgroundColor: theme.palette.grey[300],
25
- ['&:hover']: {
26
- backgroundColor: theme.palette.grey[200],
27
- },
28
- },
29
- }))
30
-
31
- export interface SelectMenuItemProps extends MenuItemProps {
32
- width: number | string
33
- value?: any
34
- disabled?: boolean
35
- }
36
-
37
- const SelectMenuItem = React.forwardRef<
38
- HTMLLIElement,
39
- PropsWithChildren<SelectMenuItemProps>
40
- >(({ width, children, value = '', ...otherProps }, ref) => {
41
- return (
42
- <StyledMenuItem width={width} innerRef={ref} value={value} {...otherProps}>
43
- {children}
44
- </StyledMenuItem>
45
- )
46
- })
47
-
48
- export default SelectMenuItem
@@ -1,154 +0,0 @@
1
- import React, { useEffect } from 'react'
2
- import { Story, Meta } from '@storybook/react'
3
- import {
4
- FormControl,
5
- FormLabel,
6
- FormHelperText,
7
- RadioGroup,
8
- } from '@material-ui/core'
9
- import { Radio, RadioProps } from './Radio'
10
-
11
- export default {
12
- component: Radio,
13
- title: 'Radio',
14
- argTypes: {
15
- disabled: {
16
- type: { name: 'boolean', required: false },
17
- description: 'If true, the radio will be disabled.',
18
- table: {
19
- type: { summary: 'boolean' },
20
- defaultValue: { summary: false },
21
- },
22
- control: { type: 'boolean' },
23
- },
24
- labelPlacement: {
25
- type: { name: 'string', required: false },
26
- description: 'The position of the label.',
27
- table: {
28
- type: { summary: 'end' },
29
- defaultValue: { summary: 'end' },
30
- category: 'not comparable with caption',
31
- },
32
- options: ['end'],
33
- control: { type: 'radio' },
34
- },
35
- color: {
36
- type: { name: 'string', required: false },
37
- description:
38
- 'The color of the component. It supports those theme colors that make sense for this component.',
39
- table: {
40
- type: { summary: 'primary | secondary | default' },
41
- defaultValue: { summary: 'secondary' },
42
- },
43
- options: ['primary', 'secondary', 'default'],
44
- control: { type: 'radio' },
45
- },
46
- size: {
47
- type: { name: 'string', required: false },
48
- description:
49
- 'The size of the radio. small is equivalent to the dense radio styling.',
50
- table: {
51
- type: { summary: 'medium | small' },
52
- defaultValue: { summary: 'medium' },
53
- },
54
- options: ['medium', 'small'],
55
- control: { type: 'radio' },
56
- },
57
- },
58
- } as Meta
59
-
60
- const WithLabelStory: Story<RadioProps> = (args) => <Radio {...args} />
61
-
62
- export const WithLabel = WithLabelStory.bind({})
63
-
64
- WithLabel.args = {
65
- disabled: false,
66
- labelPlacement: 'end',
67
- color: 'secondary',
68
- size: 'medium',
69
- value: 'JUI',
70
- label: 'JUI',
71
- }
72
-
73
- const RadioWithCaption = (props: RadioProps) => {
74
- const [value, setValue] = React.useState('')
75
-
76
- const handleRadioChange = (event) => {
77
- setValue(event.target.value)
78
- }
79
-
80
- return (
81
- <RadioGroup value={value} onChange={handleRadioChange}>
82
- <Radio caption={value && 'caption'} {...props} />
83
- </RadioGroup>
84
- )
85
- }
86
-
87
- const WithCaptionStory: Story<RadioProps> = (args) => (
88
- <RadioWithCaption {...args} />
89
- )
90
-
91
- export const WithCaption = WithCaptionStory.bind({})
92
-
93
- WithCaption.args = {
94
- disabled: false,
95
- labelPlacement: 'end',
96
- color: 'secondary',
97
- size: 'medium',
98
- value: 'JUI',
99
- label: 'JUI',
100
- }
101
-
102
- const RadioWithFormGroup = (props: RadioProps) => {
103
- const options = ['JUI', 'MUI', 'MUIX']
104
- const [value, setValue] = React.useState('')
105
- const [error, setError] = React.useState(false)
106
- const [helperText, setHelperText] = React.useState('Choose wisely')
107
-
108
- const handleRadioChange = (event) => {
109
- setValue(event.target.value)
110
- setHelperText('')
111
- setError(false)
112
- }
113
-
114
- useEffect(() => {
115
- if (!value) {
116
- return
117
- }
118
-
119
- if (value === 'JUI') {
120
- setHelperText('You got it!')
121
- setError(false)
122
- } else {
123
- setHelperText("I'm sorry to hear that.")
124
- setError(true)
125
- }
126
- }, [value])
127
-
128
- return (
129
- <FormControl component='fieldset' error={error}>
130
- <FormLabel component='legend'>
131
- Choose the UI made by Junyiacademy
132
- </FormLabel>
133
- <RadioGroup name='ui' value={value} onChange={handleRadioChange}>
134
- {options.map((option) => (
135
- <Radio key={option} label={option} value={option} {...props} />
136
- ))}
137
- </RadioGroup>
138
- <FormHelperText>{helperText}</FormHelperText>
139
- </FormControl>
140
- )
141
- }
142
-
143
- const WithFormGroupStory: Story<RadioProps> = (args) => (
144
- <RadioWithFormGroup {...args} />
145
- )
146
-
147
- export const WithFormGroup = WithFormGroupStory.bind({})
148
-
149
- WithFormGroup.args = {
150
- disabled: false,
151
- labelPlacement: 'end',
152
- color: 'secondary',
153
- size: 'medium',
154
- }
@@ -1,93 +0,0 @@
1
- import React from 'react'
2
- import { styled } from '@material-ui/core/styles'
3
- import {
4
- Radio as MuiRadio,
5
- RadioProps as MuiRadioProps,
6
- FormControlLabel,
7
- FormControlLabelProps,
8
- Typography,
9
- } from '@material-ui/core'
10
-
11
- const PREFIX = 'JuiRadio'
12
-
13
- const classes = {
14
- formControlLabel: `${PREFIX}-formControl-label`,
15
- formControlDisabled: `${PREFIX}-formControl-disabled`,
16
- radioChecked: `${PREFIX}-radio-checked`,
17
- }
18
-
19
- const StyledFormControlLabel = styled((props) => (
20
- <FormControlLabel
21
- classes={{
22
- label: classes.formControlLabel,
23
- disabled: classes.formControlDisabled,
24
- }}
25
- {...props}
26
- />
27
- ))(({ theme }) => ({
28
- [`& .${classes.formControlLabel}`]: {
29
- color: theme.palette.text.secondary,
30
- [`&.${classes.formControlDisabled}`]: {
31
- color: theme.palette.text.disabled,
32
- },
33
- },
34
- [`& .${classes.radioChecked} + .${classes.formControlLabel}`]: {
35
- color: theme.palette.text.primary,
36
- },
37
- }))
38
-
39
- const StyledRadio = styled((props) => (
40
- <MuiRadio
41
- classes={{
42
- checked: classes.radioChecked,
43
- }}
44
- {...props}
45
- />
46
- ))(({ theme }) => ({
47
- color: theme.palette.text.primary,
48
- }))
49
-
50
- const StyledTypography = styled(Typography)(({ theme }) => ({
51
- color: theme.palette.text.disabled,
52
- margin: '0 0 0 30px',
53
- }))
54
-
55
- export interface RadioProps extends FormControlLabelProps {
56
- color?: 'primary' | 'secondary' | 'default'
57
- size?: 'medium' | 'small'
58
- caption?: string
59
- formControlLabelProps?: Partial<FormControlLabelProps>
60
- radioProps?: Partial<MuiRadioProps>
61
- }
62
-
63
- export const Radio = ({
64
- checked,
65
- disabled,
66
- label,
67
- labelPlacement,
68
- value,
69
- formControlLabelProps,
70
- radioProps,
71
- color = 'secondary',
72
- size = 'medium',
73
- caption = '',
74
- }: RadioProps) => {
75
- return (
76
- <>
77
- <StyledFormControlLabel
78
- control={<StyledRadio color={color} size={size} {...radioProps} />}
79
- checked={checked}
80
- disabled={disabled}
81
- label={label}
82
- labelPlacement={labelPlacement}
83
- value={value}
84
- {...formControlLabelProps}
85
- />
86
- {caption && (
87
- <StyledTypography variant='body2'>{caption}</StyledTypography>
88
- )}
89
- </>
90
- )
91
- }
92
-
93
- export default Radio
@@ -1,220 +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
- OutlinedInput,
8
- FormHelperText,
9
- } from '@material-ui/core'
10
- import { SelectProps } from '../../interfaces'
11
-
12
- // self-defined-components
13
- const PREFIX = 'JuiOutlinedSelect'
14
-
15
- const classes = {
16
- inputLabelFocused: `${PREFIX}-inputLabelFocused`,
17
- inputLabelOutlined: `${PREFIX}-inputLabelOutlined`,
18
- inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
19
- inputLabelShrink: `${PREFIX}-inputLabelShrink`,
20
- inputLabelError: `${PREFIX}-inputLabelError`,
21
- inputLabelDisabled: `${PREFIX}-inputLabelDisabled`,
22
- outlineInputInput: `${PREFIX}-input`,
23
- outlineInputRoot: `${PREFIX}-inputRoot`,
24
- outlineInputInputMarginDense: `${PREFIX}-inputMarginDense`,
25
- outlineInputNotchedOutline: `${PREFIX}-notchedOutline`,
26
- outlineInputDisabled: `${PREFIX}-inputDisabled`,
27
- outlineInputError: `${PREFIX}-outlinedInputError`,
28
- outlineInputFocused: `${PREFIX}-focused`,
29
- selectPaper: `${PREFIX}-menuPaper`,
30
- }
31
-
32
- interface StyledFormControlProps {
33
- color: 'primary' | 'secondary'
34
- width: number | string
35
- selectMargin: number | string
36
- theme?: Theme
37
- }
38
-
39
- const StyledFormControl = styled(
40
- ({ color: _color, width: _width, selectMargin: _selectMargin, ...props }) => (
41
- <FormControl {...props} />
42
- )
43
- )(({ color, width, selectMargin, theme }: StyledFormControlProps) => ({
44
- width,
45
- margin: selectMargin,
46
- backgroundColor: 'white',
47
- '&:hover': {
48
- [`& :not(.${classes.outlineInputDisabled}):not(.${classes.outlineInputError}) .${classes.outlineInputNotchedOutline}`]: {
49
- borderColor: theme.palette[color].main,
50
- },
51
- },
52
- }))
53
-
54
- interface StyledInputLabelProps {
55
- color: 'primary' | 'secondary'
56
- theme?: Theme
57
- }
58
-
59
- const StyledInputLabel = styled(({ color: _color, ...props }) => (
60
- <InputLabel
61
- classes={{
62
- outlined: classes.inputLabelOutlined,
63
- marginDense: classes.inputLabelMarginDense,
64
- shrink: classes.inputLabelShrink,
65
- focused: classes.inputLabelFocused,
66
- disabled: classes.inputLabelDisabled,
67
- error: classes.inputLabelError,
68
- }}
69
- {...props}
70
- />
71
- ))(({ color, theme }: StyledInputLabelProps) => ({
72
- color: theme.palette.text.secondary,
73
- [`&.${classes.inputLabelOutlined}`]: {
74
- [`&:not(.${classes.inputLabelDisabled}) .${classes.inputLabelFocused}`]: {
75
- color: theme.palette.action.active,
76
- },
77
- [`&.${classes.inputLabelMarginDense}:not(.${classes.inputLabelShrink})`]: {
78
- transform: 'translate(12px, 16px) scale(1)',
79
- },
80
- },
81
- [`&.${classes.inputLabelShrink}:not(.${classes.inputLabelError}):not(.${classes.inputLabelDisabled}).${classes.inputLabelFocused}`]: {
82
- color: theme.palette[color].main,
83
- },
84
- [`&.${classes.inputLabelShrink}`]: {
85
- backgroundColor: '#ffffff',
86
- padding: '0 2px',
87
- },
88
- }))
89
-
90
- interface StyledOutlinedInputProps {
91
- theme?: Theme
92
- }
93
-
94
- const StyledOutlinedInput = styled((props) => (
95
- <OutlinedInput
96
- classes={{
97
- root: classes.outlineInputRoot,
98
- input: classes.outlineInputInput,
99
- focused: classes.outlineInputFocused,
100
- inputMarginDense: classes.outlineInputInputMarginDense,
101
- notchedOutline: classes.outlineInputNotchedOutline,
102
- disabled: classes.outlineInputDisabled,
103
- error: classes.outlineInputError,
104
- }}
105
- {...props}
106
- />
107
- ))(({ theme }: StyledOutlinedInputProps) => ({
108
- [`&.${classes.outlineInputRoot}`]: {
109
- [`&.${classes.outlineInputError}.${classes.outlineInputFocused} .${classes.outlineInputNotchedOutline}`]: {
110
- borderColor: `${theme.palette.error.main}`,
111
- },
112
- [`& .${classes.outlineInputInputMarginDense}`]: {
113
- padding: '14.5px 15px 14.5px 12px',
114
- },
115
- },
116
- [`& .${classes.outlineInputInput}`]: {
117
- color: theme.palette.text.primary,
118
- ['&:focus']: {
119
- background: 'rgba(0,0,0,0)',
120
- },
121
- },
122
- }))
123
-
124
- interface StyledSelectProps {
125
- paperMaxHeight: number | string
126
- hasAdornment: boolean
127
- }
128
-
129
- const StyledSelect = styled(
130
- ({
131
- paperMaxHeight: _paperMaxHeight,
132
- hasAdornment: _hasAdornment,
133
- className,
134
- ...props
135
- }) => (
136
- <Select
137
- MenuProps={{
138
- disableAutoFocusItem: true,
139
- anchorOrigin: {
140
- vertical: 2,
141
- horizontal: 'left',
142
- },
143
- transformOrigin: {
144
- vertical: 'top',
145
- horizontal: 'left',
146
- },
147
- getContentAnchorEl: null,
148
- classes: {
149
- paper: className,
150
- },
151
- }}
152
- {...props}
153
- />
154
- )
155
- )(({ hasAdornment, paperMaxHeight }: StyledSelectProps) => ({
156
- '&': {
157
- maxHeight: paperMaxHeight,
158
- left: hasAdornment ? '24px !important' : '70px',
159
- },
160
- }))
161
-
162
- export const OutlinedSelect = ({
163
- placeholder,
164
- helperText,
165
- InputProps,
166
- SelectProps,
167
- children,
168
- color = 'primary',
169
- size = 'small',
170
- width = 'auto',
171
- selectMargin = 0,
172
- paperMaxHeight = 'auto',
173
- error = false,
174
- hasLabel = true,
175
- hasShrink = false,
176
- value = '',
177
- disabled = false,
178
- }: SelectProps) => {
179
- const hasAdornment = !!InputProps?.startAdornment
180
- const hasHelperText = !!helperText
181
- return (
182
- <StyledFormControl
183
- size={size}
184
- width={width}
185
- selectMargin={selectMargin}
186
- disabled={disabled}
187
- error={error}
188
- color={color}
189
- >
190
- {hasLabel && (
191
- <StyledInputLabel
192
- color={color}
193
- variant='outlined'
194
- shrink={hasShrink ? true : undefined}
195
- >
196
- {placeholder}
197
- </StyledInputLabel>
198
- )}
199
- <StyledSelect
200
- value={value}
201
- paperMaxHeight={paperMaxHeight}
202
- hasAdornment={hasAdornment}
203
- input={
204
- <StyledOutlinedInput
205
- color={color}
206
- label={hasLabel ? placeholder : undefined}
207
- disabled={disabled}
208
- {...InputProps}
209
- />
210
- }
211
- {...SelectProps}
212
- >
213
- {children}
214
- </StyledSelect>
215
- {hasHelperText && <FormHelperText>{helperText}</FormHelperText>}
216
- </StyledFormControl>
217
- )
218
- }
219
-
220
- export default OutlinedSelect