@junyiacademy/ui-test 0.0.13 → 1.4.2
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 +2 -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/.DS_Store +0 -0
- package/dist/libs/ui/.DS_Store +0 -0
- package/dist/libs/ui/src/.DS_Store +0 -0
- package/dist/libs/ui/src/lib/menu-item/SelectMenuItem.js +7 -8
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +13 -16
- package/dist/libs/ui/src/lib/select/StandardSelect.js +5 -18
- package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +9 -5
- package/package.json +2 -2
- package/.eslintrc.json +0 -24
- 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/declarations/libs/ui/src/lib/alert/Alert.d.ts +0 -13
- package/declarations/libs/ui/src/lib/selection-item/SelectionItem.d.ts +0 -10
- package/dist/libs/ui/src/lib/alert/Alert.js +0 -72
- package/dist/libs/ui/src/lib/selection-item/SelectionItem.js +0 -16
- package/jest.config.js +0 -9
- package/src/index.ts +0 -7
- package/src/interfaces/index.tsx +0 -33
- 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 -45
- package/src/lib/radio/Radio.stories.tsx +0 -154
- package/src/lib/radio/Radio.tsx +0 -93
- package/src/lib/select/OutlinedSelect.tsx +0 -216
- package/src/lib/select/Select.stories.tsx +0 -421
- package/src/lib/select/Select.tsx +0 -13
- package/src/lib/select/StandardSelect.tsx +0 -179
- 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 -204
- package/src/styles/theme.ts +0 -60
- package/src/utils/topicTree.ts +0 -197
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -22
- package/tsconfig.spec.json +0 -15
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Story, Meta } from '@storybook/react'
|
|
3
|
-
import { Button, ButtonProps } from './Button'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
component: Button,
|
|
7
|
-
title: 'Button',
|
|
8
|
-
argTypes: {
|
|
9
|
-
active: {
|
|
10
|
-
description: 'The Button is active or not.',
|
|
11
|
-
table: {
|
|
12
|
-
defaultValue: { summary: false },
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
variant: {
|
|
16
|
-
table: {
|
|
17
|
-
defaultValue: { summary: 'contained' },
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
color: {
|
|
21
|
-
table: {
|
|
22
|
-
defaultValue: { summary: 'default' },
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
disabled: {
|
|
26
|
-
table: {
|
|
27
|
-
defaultValue: { summary: false },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
size: {
|
|
31
|
-
table: {
|
|
32
|
-
defaultValue: { summary: 'medium' },
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
} as Meta
|
|
37
|
-
|
|
38
|
-
const Template: Story<ButtonProps> = (args) => (
|
|
39
|
-
<Button {...args}>I'm a Button</Button>
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
export const TextOnly = Template.bind({})
|
|
43
|
-
|
|
44
|
-
TextOnly.args = {
|
|
45
|
-
active: false,
|
|
46
|
-
variant: 'contained',
|
|
47
|
-
color: 'default',
|
|
48
|
-
disabled: false,
|
|
49
|
-
size: 'medium',
|
|
50
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { styled, fade, Theme } from '@material-ui/core/styles'
|
|
3
|
-
import {
|
|
4
|
-
Button as MuiButton,
|
|
5
|
-
ButtonProps as MuiButtonProps,
|
|
6
|
-
} from '@material-ui/core'
|
|
7
|
-
|
|
8
|
-
// self-defined-components
|
|
9
|
-
const PREFIX = 'JuiButton'
|
|
10
|
-
|
|
11
|
-
const classes = {
|
|
12
|
-
outlinedPrimary: `${PREFIX}-outlinedPrimary`,
|
|
13
|
-
outlinedSecondary: `${PREFIX}-outlinedSecondary`,
|
|
14
|
-
textPrimary: `${PREFIX}-textPrimary`,
|
|
15
|
-
textSecondary: `${PREFIX}-textSecondary`,
|
|
16
|
-
disabled: `${PREFIX}-disabled`,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface StyleFuncProps {
|
|
20
|
-
active?: boolean
|
|
21
|
-
theme?: Theme
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const StyledButton = styled(({ active: _active, ...other }) => (
|
|
25
|
-
<MuiButton classes={classes} {...other} />
|
|
26
|
-
))(({ active, theme }: StyleFuncProps) => ({
|
|
27
|
-
[`&.${classes.outlinedPrimary}`]: {
|
|
28
|
-
backgroundColor: active
|
|
29
|
-
? theme.palette.primary.main
|
|
30
|
-
: theme.palette.common.white,
|
|
31
|
-
color: active ? theme.palette.common.white : theme.palette.primary.main,
|
|
32
|
-
borderColor: theme.palette.primary.main,
|
|
33
|
-
'&:hover': {
|
|
34
|
-
backgroundColor: active
|
|
35
|
-
? theme.palette.primary.main
|
|
36
|
-
: fade(theme.palette.primary.main, 0.1),
|
|
37
|
-
},
|
|
38
|
-
[`&.${classes.disabled}`]: {
|
|
39
|
-
backgroundColor: theme.palette.common.white,
|
|
40
|
-
borderColor: theme.palette.action.disabledBackground,
|
|
41
|
-
color: theme.palette.action.disabled,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
[`&.${classes.outlinedSecondary}`]: {
|
|
45
|
-
backgroundColor: active
|
|
46
|
-
? theme.palette.secondary.main
|
|
47
|
-
: theme.palette.common.white,
|
|
48
|
-
color: active ? theme.palette.common.white : theme.palette.secondary.main,
|
|
49
|
-
borderColor: theme.palette.secondary.main,
|
|
50
|
-
'&:hover': {
|
|
51
|
-
backgroundColor: active
|
|
52
|
-
? theme.palette.secondary.main
|
|
53
|
-
: fade(theme.palette.secondary.main, 0.1),
|
|
54
|
-
},
|
|
55
|
-
[`&.${classes.disabled}`]: {
|
|
56
|
-
backgroundColor: theme.palette.common.white,
|
|
57
|
-
borderColor: theme.palette.action.disabledBackground,
|
|
58
|
-
color: theme.palette.action.disabled,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
[`&.${classes.textPrimary}`]: {
|
|
62
|
-
'&:hover': {
|
|
63
|
-
backgroundColor: fade(theme.palette.primary.main, 0.1),
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
[`&.${classes.textSecondary}`]: {
|
|
67
|
-
'&:hover': {
|
|
68
|
-
backgroundColor: fade(theme.palette.secondary.main, 0.1),
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}))
|
|
72
|
-
|
|
73
|
-
export interface ButtonProps extends MuiButtonProps {
|
|
74
|
-
active?: boolean
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const Button = ({ active, children, ...otherProps }: ButtonProps) => {
|
|
78
|
-
return (
|
|
79
|
-
<StyledButton active={active} {...otherProps}>
|
|
80
|
-
{children}
|
|
81
|
-
</StyledButton>
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export default Button
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { Story, Meta } from '@storybook/react'
|
|
3
|
-
import { ButtonGroupProps as MuiButtonGroupProps } from '@material-ui/core'
|
|
4
|
-
import { ButtonGroup } from './ButtonGroup'
|
|
5
|
-
import { Button } from '../button/Button'
|
|
6
|
-
|
|
7
|
-
const ButtonGroupWithState = (props: MuiButtonGroupProps) => {
|
|
8
|
-
const [activeId, setActiveId] = useState(null)
|
|
9
|
-
|
|
10
|
-
const buttons = ['JUI', 'MUI', 'Unstyled UI']
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<ButtonGroup {...props}>
|
|
14
|
-
{buttons.map((id) => (
|
|
15
|
-
<Button
|
|
16
|
-
key={id}
|
|
17
|
-
onClick={() => setActiveId(id)}
|
|
18
|
-
active={id === activeId}
|
|
19
|
-
>
|
|
20
|
-
{id}
|
|
21
|
-
</Button>
|
|
22
|
-
))}
|
|
23
|
-
</ButtonGroup>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default {
|
|
28
|
-
component: ButtonGroup,
|
|
29
|
-
title: 'ButtonGroup',
|
|
30
|
-
argTypes: {
|
|
31
|
-
variant: {
|
|
32
|
-
table: {
|
|
33
|
-
defaultValue: { summary: 'contained' },
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
color: {
|
|
37
|
-
table: {
|
|
38
|
-
defaultValue: { summary: 'default' },
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
disabled: {
|
|
42
|
-
table: {
|
|
43
|
-
defaultValue: { summary: false },
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
} as Meta
|
|
48
|
-
|
|
49
|
-
const Template: Story<MuiButtonGroupProps> = (args) => (
|
|
50
|
-
<ButtonGroupWithState {...args} />
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
export const Basic = Template.bind({})
|
|
54
|
-
|
|
55
|
-
Basic.args = {
|
|
56
|
-
variant: 'contained',
|
|
57
|
-
color: 'default',
|
|
58
|
-
disabled: false,
|
|
59
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { styled, fade } from '@material-ui/core/styles'
|
|
3
|
-
import {
|
|
4
|
-
ButtonGroup as MuiButtonGroup,
|
|
5
|
-
ButtonGroupProps as MuiButtonGroupProps,
|
|
6
|
-
} from '@material-ui/core'
|
|
7
|
-
|
|
8
|
-
const PREFIX = 'JuiButtonGroup'
|
|
9
|
-
|
|
10
|
-
const classes = {
|
|
11
|
-
grouped: `${PREFIX}-grouped`,
|
|
12
|
-
groupedOutlinedPrimary: `${PREFIX}-groupedOutlinedPrimary`,
|
|
13
|
-
groupedOutlinedSecondary: `${PREFIX}-groupedOutlinedSecondary`,
|
|
14
|
-
disabled: `${PREFIX}-disabled`,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const StyledButtonGroup = styled(({ ...props }) => (
|
|
18
|
-
<MuiButtonGroup classes={classes} {...props} />
|
|
19
|
-
))(({ theme }) => ({
|
|
20
|
-
[`& .${classes.groupedOutlinedPrimary}.${classes.grouped}.${classes.disabled}`]: {
|
|
21
|
-
borderColor: fade(theme.palette.primary.main, 0.5),
|
|
22
|
-
color: fade(theme.palette.primary.main, 0.5),
|
|
23
|
-
},
|
|
24
|
-
[`& .${classes.groupedOutlinedSecondary}.${classes.grouped}.${classes.disabled}`]: {
|
|
25
|
-
borderColor: fade(theme.palette.secondary.main, 0.5),
|
|
26
|
-
color: fade(theme.palette.secondary.main, 0.5),
|
|
27
|
-
},
|
|
28
|
-
}))
|
|
29
|
-
|
|
30
|
-
export const ButtonGroup = ({
|
|
31
|
-
children,
|
|
32
|
-
...otherProps
|
|
33
|
-
}: MuiButtonGroupProps) => (
|
|
34
|
-
<StyledButtonGroup {...otherProps}>{children}</StyledButtonGroup>
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
export default ButtonGroup
|
|
@@ -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,45 +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 | 'auto'
|
|
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
|
-
},
|
|
26
|
-
}))
|
|
27
|
-
|
|
28
|
-
export interface SelectMenuItemProps extends MenuItemProps {
|
|
29
|
-
width: number | 'auto'
|
|
30
|
-
value?: any
|
|
31
|
-
disabled?: boolean
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const SelectMenuItem = React.forwardRef<
|
|
35
|
-
HTMLLIElement,
|
|
36
|
-
PropsWithChildren<SelectMenuItemProps>
|
|
37
|
-
>(({ width, children, value = '', ...otherProps }, ref) => {
|
|
38
|
-
return (
|
|
39
|
-
<StyledMenuItem width={width} innerRef={ref} value={value} {...otherProps}>
|
|
40
|
-
{children}
|
|
41
|
-
</StyledMenuItem>
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
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
|
-
}
|
package/src/lib/radio/Radio.tsx
DELETED
|
@@ -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
|