@junyiacademy/ui-test 0.0.5 → 0.0.9
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/lib/select/OutlinedSelect.d.ts +2 -3
- package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +1 -2
- package/declarations/libs/ui/src/lib/selection-item/SelectionItem.d.ts +10 -0
- package/dist/libs/ui/src/lib/TopicFilter.js +1 -1
- package/dist/libs/ui/src/lib/menu-item/SelectMenuItem.js +5 -8
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +11 -22
- package/dist/libs/ui/src/lib/select/StandardSelect.js +10 -17
- package/dist/libs/ui/src/lib/selection-item/SelectionItem.js +16 -0
- package/package.json +1 -1
- package/src/lib/TopicFilter.tsx +1 -1
- package/src/lib/menu-item/SelectMenuItem.tsx +5 -11
- package/src/lib/radio/Radio.stories.tsx +3 -2
- package/src/lib/select/OutlinedSelect.stories.tsx +11 -29
- package/src/lib/select/OutlinedSelect.tsx +27 -34
- package/src/lib/select/StandardSelect.stories.tsx +5 -22
- package/src/lib/select/StandardSelect.tsx +9 -18
- package/src/lib/text-field/TextField.stories.tsx +35 -1
|
@@ -4,12 +4,11 @@ export interface OutlinedSelectProps {
|
|
|
4
4
|
color?: 'primary' | 'secondary';
|
|
5
5
|
size?: 'medium' | 'small';
|
|
6
6
|
width?: number | 'auto';
|
|
7
|
-
|
|
7
|
+
paperMaxHeight?: number | 'auto';
|
|
8
8
|
error?: boolean;
|
|
9
9
|
hasLabel?: boolean;
|
|
10
10
|
hasShrink?: boolean;
|
|
11
11
|
placeholder: string;
|
|
12
|
-
hasHelperText?: boolean;
|
|
13
12
|
helperText?: string;
|
|
14
13
|
value?: unknown;
|
|
15
14
|
disabled?: boolean;
|
|
@@ -19,5 +18,5 @@ export interface OutlinedSelectProps {
|
|
|
19
18
|
};
|
|
20
19
|
children?: React.ReactNode;
|
|
21
20
|
}
|
|
22
|
-
declare const OutlinedSelect: ({ color, size, width,
|
|
21
|
+
declare const OutlinedSelect: ({ color, size, width, paperMaxHeight, error, hasLabel, hasShrink, placeholder, helperText, value, disabled, SelectProps, OutlinedInputProps, children, }: OutlinedSelectProps) => JSX.Element;
|
|
23
22
|
export default OutlinedSelect;
|
|
@@ -8,7 +8,6 @@ export interface StandardSelectProps {
|
|
|
8
8
|
error?: boolean;
|
|
9
9
|
hasShrink?: boolean;
|
|
10
10
|
placeholder: string;
|
|
11
|
-
hasHelperText?: boolean;
|
|
12
11
|
helperText?: string;
|
|
13
12
|
InputProps?: object & Partial<InputProps>;
|
|
14
13
|
value?: unknown;
|
|
@@ -16,5 +15,5 @@ export interface StandardSelectProps {
|
|
|
16
15
|
SelectProps?: object | Partial<SelectProps>;
|
|
17
16
|
children?: React.ReactNode;
|
|
18
17
|
}
|
|
19
|
-
export declare function StandardSelect({ color, size, width, paperMaxHeight, error, hasShrink, placeholder,
|
|
18
|
+
export declare function StandardSelect({ color, size, width, paperMaxHeight, error, hasShrink, placeholder, helperText, InputProps, value, SelectProps, disabled, children, }: StandardSelectProps): JSX.Element;
|
|
20
19
|
export default StandardSelect;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface SelectionItemProps {
|
|
2
|
+
handleInput: () => {};
|
|
3
|
+
label1: string;
|
|
4
|
+
value1: string;
|
|
5
|
+
label2: string;
|
|
6
|
+
value2: string;
|
|
7
|
+
isError: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function SelectionItem({ handleInput, label1, value1, label2, value2, isError, }: SelectionItemProps): JSX.Element;
|
|
10
|
+
export default SelectionItem;
|
|
@@ -86,7 +86,7 @@ const TopicFilter = ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSe
|
|
|
86
86
|
return (react_1.default.createElement(FiltersWrapper, null, layeredTopicList.map((layeredTopic, layerNumber) => {
|
|
87
87
|
const hasLabel = isFocusedList[layerNumber] || !selectedTopicIds[layerNumber];
|
|
88
88
|
return (react_1.default.createElement(SelectWrapper, { key: layeredTopic.id },
|
|
89
|
-
react_1.default.createElement(OutlinedSelect_1.default, { size: 'small', width: 220,
|
|
89
|
+
react_1.default.createElement(OutlinedSelect_1.default, { size: 'small', width: 220, paperMaxHeight: 412, hasLabel: hasLabel, placeholder: PLACEHOLDER, value: (selectedTopicIds === null || selectedTopicIds === void 0 ? void 0 : selectedTopicIds[layerNumber]) || '', SelectProps: {
|
|
90
90
|
'data-testid': `layered-topic-${layerNumber}`,
|
|
91
91
|
}, OutlinedInputProps: {
|
|
92
92
|
inputProps: {
|
|
@@ -7,20 +7,17 @@ const core_1 = require("@material-ui/core");
|
|
|
7
7
|
// self-defined-components
|
|
8
8
|
const PREFIX = 'JuiSelectMenuItem';
|
|
9
9
|
const classes = {
|
|
10
|
-
menuItemRoot: `${PREFIX}-menuItem`,
|
|
11
10
|
menuItemSelected: `${PREFIX}-menuItemSelected`,
|
|
12
11
|
};
|
|
13
12
|
const StyledMenuItem = styles_1.styled((_a) => {
|
|
14
13
|
var { width: _width } = _a, props = tslib_1.__rest(_a, ["width"]);
|
|
15
|
-
return (react_1.default.createElement(core_1.MenuItem, Object.assign({ classes: {
|
|
14
|
+
return (react_1.default.createElement(core_1.MenuItem, Object.assign({ classes: { selected: classes.menuItemSelected } }, props)));
|
|
16
15
|
})(({ width, theme }) => ({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
color: theme.palette.text.primary,
|
|
21
|
-
},
|
|
16
|
+
width: width,
|
|
17
|
+
whiteSpace: 'unset',
|
|
18
|
+
color: theme.palette.text.primary,
|
|
22
19
|
[`& .${classes.menuItemSelected}`]: {
|
|
23
|
-
backgroundColor:
|
|
20
|
+
backgroundColor: theme.palette.grey[300],
|
|
24
21
|
},
|
|
25
22
|
}));
|
|
26
23
|
const SelectMenuItem = react_1.default.forwardRef((_a, ref) => {
|
|
@@ -7,14 +7,12 @@ const core_1 = require("@material-ui/core");
|
|
|
7
7
|
// self-defined-components
|
|
8
8
|
const PREFIX = 'JuiOutlinedSelect';
|
|
9
9
|
const classes = {
|
|
10
|
-
inputLabelRoot: `${PREFIX}-inputLabel`,
|
|
11
10
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
12
11
|
inputLabelOutlined: `${PREFIX}-inputLabelOutlined`,
|
|
13
12
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
14
13
|
inputLabelShrink: `${PREFIX}-inputLabelShrink`,
|
|
15
14
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
16
15
|
inputLabelDisabled: `${PREFIX}-inputLabelDisabled`,
|
|
17
|
-
outlineInputRoot: `${PREFIX}-outlineInput`,
|
|
18
16
|
outlineInputInput: `${PREFIX}-input`,
|
|
19
17
|
outlineInputInputMarginDense: `${PREFIX}-inputMarginDense`,
|
|
20
18
|
outlineInputNotchedOutline: `${PREFIX}-notchedOutline`,
|
|
@@ -38,7 +36,6 @@ const StyledFormControl = styles_1.styled((_a) => {
|
|
|
38
36
|
const StyledInputLabel = styles_1.styled((_a) => {
|
|
39
37
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
40
38
|
return (react_1.default.createElement(core_1.InputLabel, Object.assign({ classes: {
|
|
41
|
-
root: classes.inputLabelRoot,
|
|
42
39
|
outlined: classes.inputLabelOutlined,
|
|
43
40
|
marginDense: classes.inputLabelMarginDense,
|
|
44
41
|
shrink: classes.inputLabelShrink,
|
|
@@ -47,9 +44,7 @@ const StyledInputLabel = styles_1.styled((_a) => {
|
|
|
47
44
|
error: classes.inputLabelError,
|
|
48
45
|
} }, props)));
|
|
49
46
|
})(({ color, theme }) => ({
|
|
50
|
-
|
|
51
|
-
color: theme.palette.text.secondary,
|
|
52
|
-
},
|
|
47
|
+
color: theme.palette.text.secondary,
|
|
53
48
|
[`&.${classes.inputLabelOutlined}`]: {
|
|
54
49
|
[`&:not(.${classes.inputLabelDisabled}) .${classes.inputLabelFocused}`]: {
|
|
55
50
|
color: theme.palette.action.active,
|
|
@@ -61,10 +56,6 @@ const StyledInputLabel = styles_1.styled((_a) => {
|
|
|
61
56
|
[`&.${classes.inputLabelShrink}:not(.${classes.inputLabelError}):not(.${classes.inputLabelDisabled}).${classes.inputLabelFocused}`]: {
|
|
62
57
|
color: theme.palette[color].main,
|
|
63
58
|
},
|
|
64
|
-
[`&.${classes.inputLabelShrink}.${classes.inputLabelError}:not(.${classes.inputLabelDisabled})`]: {
|
|
65
|
-
color: theme.palette.error.main,
|
|
66
|
-
},
|
|
67
|
-
[`&.${classes.inputLabelMarginDense}`]: {},
|
|
68
59
|
[`&.${classes.inputLabelShrink}`]: {
|
|
69
60
|
backgroundColor: '#ffffff',
|
|
70
61
|
padding: '0 2px',
|
|
@@ -76,18 +67,16 @@ const StyledOutlinedInput = styles_1.styled((props) => (react_1.default.createEl
|
|
|
76
67
|
notchedOutline: classes.outlineInputNotchedOutline,
|
|
77
68
|
disabled: classes.outlineInputDisabled,
|
|
78
69
|
error: classes.outlineInputError,
|
|
79
|
-
} }, props))))({
|
|
70
|
+
} }, props))))(({ theme }) => ({
|
|
80
71
|
[`& .${classes.outlineInputInput}`]: {
|
|
81
|
-
color:
|
|
72
|
+
color: theme.palette.text.primary,
|
|
82
73
|
},
|
|
83
74
|
[`& .${classes.outlineInputInputMarginDense}`]: {
|
|
84
75
|
padding: '14.5px 15px 14.5px 12px',
|
|
85
76
|
},
|
|
86
|
-
|
|
87
|
-
[`&.${classes.outlineInputDisabled}`]: {},
|
|
88
|
-
});
|
|
77
|
+
}));
|
|
89
78
|
const StyledSelect = styles_1.styled((_a) => {
|
|
90
|
-
var {
|
|
79
|
+
var { paperMaxHeight: _paperMaxHeight, hasAdornment: _hasAdornment, className } = _a, props = tslib_1.__rest(_a, ["paperMaxHeight", "hasAdornment", "className"]);
|
|
91
80
|
return (react_1.default.createElement(core_1.Select, Object.assign({ MenuProps: {
|
|
92
81
|
disableAutoFocusItem: true,
|
|
93
82
|
anchorOrigin: {
|
|
@@ -101,18 +90,18 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
101
90
|
getContentAnchorEl: null,
|
|
102
91
|
classes: { paper: className },
|
|
103
92
|
} }, props)));
|
|
104
|
-
})(({ hasAdornment,
|
|
93
|
+
})(({ hasAdornment, paperMaxHeight }) => ({
|
|
105
94
|
'&&': {
|
|
106
|
-
maxHeight:
|
|
95
|
+
maxHeight: paperMaxHeight,
|
|
107
96
|
left: hasAdornment ? '24px !important' : '70px',
|
|
108
97
|
},
|
|
109
98
|
}));
|
|
110
|
-
const OutlinedSelect = ({ color = 'primary', size = 'medium', width = 'auto',
|
|
99
|
+
const OutlinedSelect = ({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasLabel = true, hasShrink = false, placeholder, helperText = '', value = '', disabled = false, SelectProps, OutlinedInputProps, children, }) => {
|
|
111
100
|
const hasAdornment = !!(OutlinedInputProps === null || OutlinedInputProps === void 0 ? void 0 : OutlinedInputProps.startAdornment);
|
|
101
|
+
const hasHelperText = !!helperText;
|
|
112
102
|
return (react_1.default.createElement(StyledFormControl, { size: size, width: width, disabled: disabled, error: error, color: color },
|
|
113
|
-
hasShrink
|
|
114
|
-
|
|
115
|
-
react_1.default.createElement(StyledSelect, Object.assign({ value: value, selectPaperMaxHeight: selectPaperMaxHeight, hasAdornment: hasAdornment, input: react_1.default.createElement(StyledOutlinedInput, Object.assign({ color: color, label: hasLabel ? placeholder : undefined, disabled: disabled }, OutlinedInputProps)) }, SelectProps), children),
|
|
103
|
+
hasLabel ? (hasShrink ? (react_1.default.createElement(StyledInputLabel, { color: color, variant: 'outlined', shrink: true }, placeholder)) : (react_1.default.createElement(StyledInputLabel, { color: color, variant: 'outlined' }, placeholder))) : null,
|
|
104
|
+
react_1.default.createElement(StyledSelect, Object.assign({ value: value, paperMaxHeight: paperMaxHeight, hasAdornment: hasAdornment, input: react_1.default.createElement(StyledOutlinedInput, Object.assign({ color: color, label: hasLabel ? placeholder : undefined, disabled: disabled }, OutlinedInputProps)) }, SelectProps), children),
|
|
116
105
|
hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
|
|
117
106
|
};
|
|
118
107
|
exports.default = OutlinedSelect;
|
|
@@ -8,11 +8,9 @@ const core_1 = require("@material-ui/core");
|
|
|
8
8
|
// self-defined-components
|
|
9
9
|
const PREFIX = 'JuiStandardSelect';
|
|
10
10
|
const classes = {
|
|
11
|
-
inputLabelRoot: `${PREFIX}-inputLabel`,
|
|
12
11
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
13
12
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
14
13
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
15
|
-
inputRoot: `${PREFIX}-inputRoot`,
|
|
16
14
|
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
17
15
|
inputError: `${PREFIX}-inputError`,
|
|
18
16
|
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
@@ -30,20 +28,17 @@ const StyledFormControl = styles_1.styled((_a) => {
|
|
|
30
28
|
const StyledInputLabel = styles_1.styled((_a) => {
|
|
31
29
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
32
30
|
return (react_1.default.createElement(core_1.InputLabel, Object.assign({ classes: {
|
|
33
|
-
root: classes.inputLabelRoot,
|
|
34
31
|
focused: classes.inputLabelFocused,
|
|
35
32
|
error: classes.inputLabelError,
|
|
36
33
|
} }, props)));
|
|
37
34
|
})(({ color, theme }) => ({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
[
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
color: theme.palette.error.main,
|
|
46
|
-
},
|
|
35
|
+
color: theme.palette.text.disabled,
|
|
36
|
+
margin: theme.spacing(0, 10, 1.5, 0),
|
|
37
|
+
[`&.${classes.inputLabelFocused}`]: {
|
|
38
|
+
color: theme.palette[color].main,
|
|
39
|
+
},
|
|
40
|
+
[`&.${classes.inputLabelError}`]: {
|
|
41
|
+
color: theme.palette.error.main,
|
|
47
42
|
},
|
|
48
43
|
}));
|
|
49
44
|
const StyledSelect = styles_1.styled((_a) => {
|
|
@@ -67,14 +62,11 @@ const StyledInput = styles_1.styled((_a) => {
|
|
|
67
62
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
68
63
|
return (react_1.default.createElement(core_1.Input, Object.assign({ classes: {
|
|
69
64
|
disabled: classes.inputDisabled,
|
|
70
|
-
root: classes.inputRoot,
|
|
71
65
|
underline: classes.inputUnderline,
|
|
72
66
|
error: classes.inputError,
|
|
73
67
|
} }, props)));
|
|
74
68
|
})(({ color, theme }) => ({
|
|
75
|
-
|
|
76
|
-
color: theme.palette.text.primary,
|
|
77
|
-
},
|
|
69
|
+
color: theme.palette.text.primary,
|
|
78
70
|
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
79
71
|
[`&:after,&:hover:before`]: {
|
|
80
72
|
borderBottomColor: theme.palette[color].main,
|
|
@@ -86,8 +78,9 @@ const StyledInput = styles_1.styled((_a) => {
|
|
|
86
78
|
},
|
|
87
79
|
},
|
|
88
80
|
}));
|
|
89
|
-
function StandardSelect({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasShrink = false, placeholder,
|
|
81
|
+
function StandardSelect({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasShrink = false, placeholder, helperText, InputProps, value = '', SelectProps, disabled = false, children, }) {
|
|
90
82
|
const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
|
|
83
|
+
const hasHelperText = !!helperText;
|
|
91
84
|
return (react_1.default.createElement(StyledFormControl, { color: color, size: size, width: width, disabled: disabled, error: error },
|
|
92
85
|
hasShrink ? (react_1.default.createElement(StyledInputLabel, { color: color, shrink: true }, placeholder)) : (react_1.default.createElement(StyledInputLabel, { color: color }, placeholder)),
|
|
93
86
|
react_1.default.createElement(StyledSelect, Object.assign({ value: value, paperMaxHeight: paperMaxHeight, hasAdornment: hasAdornment, input: react_1.default.createElement(StyledInput, Object.assign({ color: color }, InputProps)) }, SelectProps), children),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectionItem = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const core_1 = require("@material-ui/core");
|
|
7
|
+
const Radio_1 = require("../radio/Radio");
|
|
8
|
+
function SelectionItem({ handleInput, label1, value1, label2, value2, isError, }) {
|
|
9
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
10
|
+
react_1.default.createElement(core_1.RadioGroup, { onChange: handleInput },
|
|
11
|
+
react_1.default.createElement(Radio_1.Radio, { label: label1, value: value1 }),
|
|
12
|
+
react_1.default.createElement(Radio_1.Radio, { label: label2, value: value2 })),
|
|
13
|
+
isError && react_1.default.createElement(core_1.FormHelperText, null, "\u8ACB\u9078\u64C7")));
|
|
14
|
+
}
|
|
15
|
+
exports.SelectionItem = SelectionItem;
|
|
16
|
+
exports.default = SelectionItem;
|
package/package.json
CHANGED
package/src/lib/TopicFilter.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import { MenuItem, MenuItemProps } from '@material-ui/core'
|
|
|
6
6
|
const PREFIX = 'JuiSelectMenuItem'
|
|
7
7
|
|
|
8
8
|
const classes = {
|
|
9
|
-
menuItemRoot: `${PREFIX}-menuItem`,
|
|
10
9
|
menuItemSelected: `${PREFIX}-menuItemSelected`,
|
|
11
10
|
}
|
|
12
11
|
|
|
@@ -16,18 +15,13 @@ interface StyledMenuItemProps {
|
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
const StyledMenuItem = styled(({ width: _width, ...props }) => (
|
|
19
|
-
<MenuItem
|
|
20
|
-
classes={{ root: classes.menuItemRoot, selected: classes.menuItemSelected }}
|
|
21
|
-
{...props}
|
|
22
|
-
/>
|
|
18
|
+
<MenuItem classes={{ selected: classes.menuItemSelected }} {...props} />
|
|
23
19
|
))(({ width, theme }: StyledMenuItemProps) => ({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
color: theme.palette.text.primary,
|
|
28
|
-
},
|
|
20
|
+
width: width,
|
|
21
|
+
whiteSpace: 'unset',
|
|
22
|
+
color: theme.palette.text.primary,
|
|
29
23
|
[`& .${classes.menuItemSelected}`]: {
|
|
30
|
-
backgroundColor:
|
|
24
|
+
backgroundColor: theme.palette.grey[300],
|
|
31
25
|
},
|
|
32
26
|
}))
|
|
33
27
|
|
|
@@ -25,10 +25,11 @@ export default {
|
|
|
25
25
|
type: { name: 'string', required: false },
|
|
26
26
|
description: 'The position of the label.',
|
|
27
27
|
table: {
|
|
28
|
-
type: { summary: '
|
|
28
|
+
type: { summary: 'end' },
|
|
29
29
|
defaultValue: { summary: 'end' },
|
|
30
|
+
category: 'not comparable with caption',
|
|
30
31
|
},
|
|
31
|
-
options: ['
|
|
32
|
+
options: ['end'],
|
|
32
33
|
control: { type: 'radio' },
|
|
33
34
|
},
|
|
34
35
|
color: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
2
|
import { Story, Meta } from '@storybook/react'
|
|
3
3
|
import { Theme, styled } from '@material-ui/core/styles'
|
|
4
|
-
import OutlinedSelect, { OutlinedSelectProps } from './OutlinedSelect'
|
|
5
|
-
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
6
4
|
import { InputAdornment } from '@material-ui/core'
|
|
7
5
|
import { Visibility } from '@material-ui/icons'
|
|
6
|
+
import OutlinedSelect, { OutlinedSelectProps } from './OutlinedSelect'
|
|
7
|
+
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
8
8
|
|
|
9
9
|
const PLACEHOLDER = '請選擇'
|
|
10
10
|
|
|
@@ -32,7 +32,6 @@ export default {
|
|
|
32
32
|
},
|
|
33
33
|
options: ['small', 'medium'],
|
|
34
34
|
control: { type: 'radio' },
|
|
35
|
-
defaultValue: 'medium',
|
|
36
35
|
},
|
|
37
36
|
width: {
|
|
38
37
|
type: { name: 'number', required: false },
|
|
@@ -42,7 +41,6 @@ export default {
|
|
|
42
41
|
defaultValue: { summary: 'auto' },
|
|
43
42
|
},
|
|
44
43
|
control: { type: 'number' },
|
|
45
|
-
defaultValue: '220',
|
|
46
44
|
},
|
|
47
45
|
paperMaxHeight: {
|
|
48
46
|
type: { name: 'number', required: false },
|
|
@@ -52,27 +50,24 @@ export default {
|
|
|
52
50
|
defaultValue: { summary: 'auto' },
|
|
53
51
|
},
|
|
54
52
|
control: { type: 'number' },
|
|
55
|
-
defaultValue: '412',
|
|
56
53
|
},
|
|
57
|
-
|
|
54
|
+
hasInputLabel: {
|
|
58
55
|
type: { name: 'boolean', required: false },
|
|
59
|
-
description: '
|
|
56
|
+
description: 'If true, the label is displayed.',
|
|
60
57
|
table: {
|
|
61
58
|
type: { summary: 'boolean' },
|
|
62
59
|
defaultValue: { summary: true },
|
|
63
60
|
},
|
|
64
61
|
control: { type: 'boolean' },
|
|
65
|
-
defaultValue: true,
|
|
66
62
|
},
|
|
67
63
|
hasShrink: {
|
|
68
64
|
type: { name: 'boolean', required: false },
|
|
69
|
-
description: '
|
|
65
|
+
description: 'If true, the label is displayed and shrunk.',
|
|
70
66
|
table: {
|
|
71
67
|
type: { summary: 'boolean' },
|
|
72
68
|
defaultValue: { summary: false },
|
|
73
69
|
},
|
|
74
70
|
control: { type: 'boolean' },
|
|
75
|
-
defaultValue: false,
|
|
76
71
|
},
|
|
77
72
|
placeholder: {
|
|
78
73
|
type: { name: 'string', required: true },
|
|
@@ -82,7 +77,6 @@ export default {
|
|
|
82
77
|
defaultValue: { summary: '請選擇' },
|
|
83
78
|
},
|
|
84
79
|
control: { type: 'text' },
|
|
85
|
-
defaultValue: '請選擇',
|
|
86
80
|
},
|
|
87
81
|
value: {
|
|
88
82
|
type: { name: 'any', required: false },
|
|
@@ -111,24 +105,14 @@ export default {
|
|
|
111
105
|
},
|
|
112
106
|
control: { type: 'boolean' },
|
|
113
107
|
},
|
|
114
|
-
hasHelperText: {
|
|
115
|
-
type: { name: 'boolean', required: false },
|
|
116
|
-
description: 'If true, the helper text will be displayed.',
|
|
117
|
-
table: {
|
|
118
|
-
type: { summary: 'boolean' },
|
|
119
|
-
defaultValue: { summary: false },
|
|
120
|
-
},
|
|
121
|
-
control: { type: 'boolean' },
|
|
122
|
-
},
|
|
123
108
|
helperText: {
|
|
124
109
|
type: { name: 'string', required: true },
|
|
125
|
-
description: `
|
|
110
|
+
description: `Display the helper text.`,
|
|
126
111
|
table: {
|
|
127
112
|
type: { summary: 'string' },
|
|
128
|
-
defaultValue: { summary: '
|
|
113
|
+
defaultValue: { summary: '' },
|
|
129
114
|
},
|
|
130
115
|
control: { type: 'text' },
|
|
131
|
-
defaultValue: 'Helper text.',
|
|
132
116
|
},
|
|
133
117
|
SelectProps: {
|
|
134
118
|
type: { name: 'any', required: false },
|
|
@@ -179,10 +163,10 @@ const OutlinedSelectWithMenu = (props: OutlinedSelectProps) => {
|
|
|
179
163
|
<SelectMenuItem width={220} value='' disabled>
|
|
180
164
|
{PLACEHOLDER}
|
|
181
165
|
</SelectMenuItem>
|
|
182
|
-
<SelectMenuItem width={220} value=
|
|
166
|
+
<SelectMenuItem width={220} value='Test'>
|
|
183
167
|
This is a select menu item
|
|
184
168
|
</SelectMenuItem>
|
|
185
|
-
<SelectMenuItem width={220} value=
|
|
169
|
+
<SelectMenuItem width={220} value='Example'>
|
|
186
170
|
Example
|
|
187
171
|
</SelectMenuItem>
|
|
188
172
|
</OutlinedSelect>
|
|
@@ -215,9 +199,8 @@ ValueOnly.args = {
|
|
|
215
199
|
size: 'medium',
|
|
216
200
|
width: 220,
|
|
217
201
|
paperMaxHeight: 412,
|
|
218
|
-
|
|
202
|
+
hasInputLabel: true,
|
|
219
203
|
placeholder: PLACEHOLDER,
|
|
220
|
-
hasHelperText: false,
|
|
221
204
|
helperText: 'test',
|
|
222
205
|
disabled: false,
|
|
223
206
|
SelectProps: {},
|
|
@@ -254,9 +237,8 @@ WithPrefix.args = {
|
|
|
254
237
|
size: 'medium',
|
|
255
238
|
width: 220,
|
|
256
239
|
paperMaxHeight: 412,
|
|
257
|
-
|
|
240
|
+
hasInputLabel: true,
|
|
258
241
|
placeholder: PLACEHOLDER,
|
|
259
|
-
hasHelperText: false,
|
|
260
242
|
helperText: 'test',
|
|
261
243
|
disabled: false,
|
|
262
244
|
SelectProps: {},
|
|
@@ -14,14 +14,12 @@ import {
|
|
|
14
14
|
const PREFIX = 'JuiOutlinedSelect'
|
|
15
15
|
|
|
16
16
|
const classes = {
|
|
17
|
-
inputLabelRoot: `${PREFIX}-inputLabel`,
|
|
18
17
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
19
18
|
inputLabelOutlined: `${PREFIX}-inputLabelOutlined`,
|
|
20
19
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
21
20
|
inputLabelShrink: `${PREFIX}-inputLabelShrink`,
|
|
22
21
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
23
22
|
inputLabelDisabled: `${PREFIX}-inputLabelDisabled`,
|
|
24
|
-
outlineInputRoot: `${PREFIX}-outlineInput`,
|
|
25
23
|
outlineInputInput: `${PREFIX}-input`,
|
|
26
24
|
outlineInputInputMarginDense: `${PREFIX}-inputMarginDense`,
|
|
27
25
|
outlineInputNotchedOutline: `${PREFIX}-notchedOutline`,
|
|
@@ -57,7 +55,6 @@ interface StyledInputLabelProps {
|
|
|
57
55
|
const StyledInputLabel = styled(({ color: _color, ...props }) => (
|
|
58
56
|
<InputLabel
|
|
59
57
|
classes={{
|
|
60
|
-
root: classes.inputLabelRoot,
|
|
61
58
|
outlined: classes.inputLabelOutlined,
|
|
62
59
|
marginDense: classes.inputLabelMarginDense,
|
|
63
60
|
shrink: classes.inputLabelShrink,
|
|
@@ -68,9 +65,7 @@ const StyledInputLabel = styled(({ color: _color, ...props }) => (
|
|
|
68
65
|
{...props}
|
|
69
66
|
/>
|
|
70
67
|
))(({ color, theme }: StyledInputLabelProps) => ({
|
|
71
|
-
|
|
72
|
-
color: theme.palette.text.secondary,
|
|
73
|
-
},
|
|
68
|
+
color: theme.palette.text.secondary,
|
|
74
69
|
[`&.${classes.inputLabelOutlined}`]: {
|
|
75
70
|
[`&:not(.${classes.inputLabelDisabled}) .${classes.inputLabelFocused}`]: {
|
|
76
71
|
color: theme.palette.action.active,
|
|
@@ -82,16 +77,16 @@ const StyledInputLabel = styled(({ color: _color, ...props }) => (
|
|
|
82
77
|
[`&.${classes.inputLabelShrink}:not(.${classes.inputLabelError}):not(.${classes.inputLabelDisabled}).${classes.inputLabelFocused}`]: {
|
|
83
78
|
color: theme.palette[color].main,
|
|
84
79
|
},
|
|
85
|
-
[`&.${classes.inputLabelShrink}.${classes.inputLabelError}:not(.${classes.inputLabelDisabled})`]: {
|
|
86
|
-
color: theme.palette.error.main,
|
|
87
|
-
},
|
|
88
|
-
[`&.${classes.inputLabelMarginDense}`]: {},
|
|
89
80
|
[`&.${classes.inputLabelShrink}`]: {
|
|
90
81
|
backgroundColor: '#ffffff',
|
|
91
82
|
padding: '0 2px',
|
|
92
83
|
},
|
|
93
84
|
}))
|
|
94
85
|
|
|
86
|
+
interface StyledOutlinedInputProps {
|
|
87
|
+
theme?: Theme
|
|
88
|
+
}
|
|
89
|
+
|
|
95
90
|
const StyledOutlinedInput = styled((props) => (
|
|
96
91
|
<OutlinedInput
|
|
97
92
|
classes={{
|
|
@@ -103,25 +98,23 @@ const StyledOutlinedInput = styled((props) => (
|
|
|
103
98
|
}}
|
|
104
99
|
{...props}
|
|
105
100
|
/>
|
|
106
|
-
))({
|
|
101
|
+
))(({ theme }: StyledOutlinedInputProps) => ({
|
|
107
102
|
[`& .${classes.outlineInputInput}`]: {
|
|
108
|
-
color:
|
|
103
|
+
color: theme.palette.text.primary,
|
|
109
104
|
},
|
|
110
105
|
[`& .${classes.outlineInputInputMarginDense}`]: {
|
|
111
106
|
padding: '14.5px 15px 14.5px 12px',
|
|
112
107
|
},
|
|
113
|
-
|
|
114
|
-
[`&.${classes.outlineInputDisabled}`]: {},
|
|
115
|
-
})
|
|
108
|
+
}))
|
|
116
109
|
|
|
117
110
|
interface StyledSelectProps {
|
|
118
|
-
|
|
111
|
+
paperMaxHeight: number | 'auto'
|
|
119
112
|
hasAdornment: boolean
|
|
120
113
|
}
|
|
121
114
|
|
|
122
115
|
const StyledSelect = styled(
|
|
123
116
|
({
|
|
124
|
-
|
|
117
|
+
paperMaxHeight: _paperMaxHeight,
|
|
125
118
|
hasAdornment: _hasAdornment,
|
|
126
119
|
className,
|
|
127
120
|
...props
|
|
@@ -143,9 +136,9 @@ const StyledSelect = styled(
|
|
|
143
136
|
{...props}
|
|
144
137
|
/>
|
|
145
138
|
)
|
|
146
|
-
)(({ hasAdornment,
|
|
139
|
+
)(({ hasAdornment, paperMaxHeight }: StyledSelectProps) => ({
|
|
147
140
|
'&&': {
|
|
148
|
-
maxHeight:
|
|
141
|
+
maxHeight: paperMaxHeight,
|
|
149
142
|
left: hasAdornment ? '24px !important' : '70px',
|
|
150
143
|
},
|
|
151
144
|
}))
|
|
@@ -154,12 +147,11 @@ export interface OutlinedSelectProps {
|
|
|
154
147
|
color?: 'primary' | 'secondary'
|
|
155
148
|
size?: 'medium' | 'small'
|
|
156
149
|
width?: number | 'auto'
|
|
157
|
-
|
|
150
|
+
paperMaxHeight?: number | 'auto'
|
|
158
151
|
error?: boolean
|
|
159
152
|
hasLabel?: boolean
|
|
160
153
|
hasShrink?: boolean
|
|
161
154
|
placeholder: string
|
|
162
|
-
hasHelperText?: boolean
|
|
163
155
|
helperText?: string
|
|
164
156
|
value?: unknown
|
|
165
157
|
disabled?: boolean
|
|
@@ -174,12 +166,11 @@ const OutlinedSelect = ({
|
|
|
174
166
|
color = 'primary',
|
|
175
167
|
size = 'medium',
|
|
176
168
|
width = 'auto',
|
|
177
|
-
|
|
169
|
+
paperMaxHeight = 'auto',
|
|
178
170
|
error = false,
|
|
179
171
|
hasLabel = true,
|
|
180
172
|
hasShrink = false,
|
|
181
173
|
placeholder,
|
|
182
|
-
hasHelperText = false,
|
|
183
174
|
helperText = '',
|
|
184
175
|
value = '',
|
|
185
176
|
disabled = false,
|
|
@@ -188,6 +179,7 @@ const OutlinedSelect = ({
|
|
|
188
179
|
children,
|
|
189
180
|
}: OutlinedSelectProps) => {
|
|
190
181
|
const hasAdornment = !!OutlinedInputProps?.startAdornment
|
|
182
|
+
const hasHelperText = !!helperText
|
|
191
183
|
return (
|
|
192
184
|
<StyledFormControl
|
|
193
185
|
size={size}
|
|
@@ -196,19 +188,20 @@ const OutlinedSelect = ({
|
|
|
196
188
|
error={error}
|
|
197
189
|
color={color}
|
|
198
190
|
>
|
|
199
|
-
{
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
191
|
+
{hasLabel ? (
|
|
192
|
+
hasShrink ? (
|
|
193
|
+
<StyledInputLabel color={color} variant='outlined' shrink>
|
|
194
|
+
{placeholder}
|
|
195
|
+
</StyledInputLabel>
|
|
196
|
+
) : (
|
|
197
|
+
<StyledInputLabel color={color} variant='outlined'>
|
|
198
|
+
{placeholder}
|
|
199
|
+
</StyledInputLabel>
|
|
200
|
+
)
|
|
201
|
+
) : null}
|
|
209
202
|
<StyledSelect
|
|
210
203
|
value={value}
|
|
211
|
-
|
|
204
|
+
paperMaxHeight={paperMaxHeight}
|
|
212
205
|
hasAdornment={hasAdornment}
|
|
213
206
|
input={
|
|
214
207
|
<StyledOutlinedInput
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
2
|
import { Story, Meta } from '@storybook/react'
|
|
3
3
|
import { Theme, styled } from '@material-ui/core/styles'
|
|
4
|
-
import { StandardSelect, StandardSelectProps } from './StandardSelect'
|
|
5
|
-
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
6
4
|
import { InputAdornment } from '@material-ui/core'
|
|
7
5
|
import { Visibility } from '@material-ui/icons'
|
|
6
|
+
import { StandardSelect, StandardSelectProps } from './StandardSelect'
|
|
7
|
+
import SelectMenuItem from '../menu-item/SelectMenuItem'
|
|
8
8
|
|
|
9
9
|
const PLACEHOLDER = '請選擇'
|
|
10
10
|
|
|
@@ -32,7 +32,6 @@ export default {
|
|
|
32
32
|
},
|
|
33
33
|
options: ['small', 'medium'],
|
|
34
34
|
control: { type: 'radio' },
|
|
35
|
-
defaultValue: 'medium',
|
|
36
35
|
},
|
|
37
36
|
width: {
|
|
38
37
|
type: { name: 'number', required: false },
|
|
@@ -42,7 +41,6 @@ export default {
|
|
|
42
41
|
defaultValue: { summary: 'auto' },
|
|
43
42
|
},
|
|
44
43
|
control: { type: 'number' },
|
|
45
|
-
defaultValue: '220',
|
|
46
44
|
},
|
|
47
45
|
paperMaxHeight: {
|
|
48
46
|
type: { name: 'number', required: false },
|
|
@@ -52,17 +50,15 @@ export default {
|
|
|
52
50
|
defaultValue: { summary: 'auto' },
|
|
53
51
|
},
|
|
54
52
|
control: { type: 'number' },
|
|
55
|
-
defaultValue: '412',
|
|
56
53
|
},
|
|
57
54
|
hasShrink: {
|
|
58
55
|
type: { name: 'boolean', required: false },
|
|
59
|
-
description: '
|
|
56
|
+
description: 'If true, the label is displayed and shrunk.',
|
|
60
57
|
table: {
|
|
61
58
|
type: { summary: 'boolean' },
|
|
62
59
|
defaultValue: { summary: true },
|
|
63
60
|
},
|
|
64
61
|
control: { type: 'boolean' },
|
|
65
|
-
defaultValue: true,
|
|
66
62
|
},
|
|
67
63
|
placeholder: {
|
|
68
64
|
type: { name: 'string', required: true },
|
|
@@ -72,7 +68,6 @@ export default {
|
|
|
72
68
|
defaultValue: { summary: '請選擇' },
|
|
73
69
|
},
|
|
74
70
|
control: { type: 'text' },
|
|
75
|
-
defaultValue: '請選擇',
|
|
76
71
|
},
|
|
77
72
|
value: {
|
|
78
73
|
type: { name: 'any', required: false },
|
|
@@ -101,24 +96,14 @@ export default {
|
|
|
101
96
|
},
|
|
102
97
|
control: { type: 'boolean' },
|
|
103
98
|
},
|
|
104
|
-
hasHelperText: {
|
|
105
|
-
type: { name: 'boolean', required: false },
|
|
106
|
-
description: 'If true, the helper text will be displayed.',
|
|
107
|
-
table: {
|
|
108
|
-
type: { summary: 'boolean' },
|
|
109
|
-
defaultValue: { summary: false },
|
|
110
|
-
},
|
|
111
|
-
control: { type: 'boolean' },
|
|
112
|
-
},
|
|
113
99
|
helperText: {
|
|
114
100
|
type: { name: 'string', required: true },
|
|
115
|
-
description: `
|
|
101
|
+
description: `Display the helper text.`,
|
|
116
102
|
table: {
|
|
117
103
|
type: { summary: 'string' },
|
|
118
|
-
defaultValue: { summary: '
|
|
104
|
+
defaultValue: { summary: '' },
|
|
119
105
|
},
|
|
120
106
|
control: { type: 'text' },
|
|
121
|
-
defaultValue: 'Helper text.',
|
|
122
107
|
},
|
|
123
108
|
InputProps: {
|
|
124
109
|
type: { name: 'any', required: false },
|
|
@@ -205,7 +190,6 @@ ValueOnly.args = {
|
|
|
205
190
|
paperMaxHeight: 300,
|
|
206
191
|
hasShrink: false,
|
|
207
192
|
placeholder: PLACEHOLDER,
|
|
208
|
-
hasHelperText: false,
|
|
209
193
|
helperText: 'test',
|
|
210
194
|
disabled: false,
|
|
211
195
|
}
|
|
@@ -232,7 +216,6 @@ WithPrefix.args = {
|
|
|
232
216
|
paperMaxHeight: 300,
|
|
233
217
|
hasShrink: false,
|
|
234
218
|
placeholder: PLACEHOLDER,
|
|
235
|
-
hasHelperText: false,
|
|
236
219
|
helperText: 'test',
|
|
237
220
|
disabled: false,
|
|
238
221
|
}
|
|
@@ -15,11 +15,9 @@ import {
|
|
|
15
15
|
const PREFIX = 'JuiStandardSelect'
|
|
16
16
|
|
|
17
17
|
const classes = {
|
|
18
|
-
inputLabelRoot: `${PREFIX}-inputLabel`,
|
|
19
18
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
20
19
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
21
20
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
22
|
-
inputRoot: `${PREFIX}-inputRoot`,
|
|
23
21
|
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
24
22
|
inputError: `${PREFIX}-inputError`,
|
|
25
23
|
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
@@ -49,22 +47,19 @@ interface StyledInputLabelProps {
|
|
|
49
47
|
const StyledInputLabel = styled(({ color: _color, ...props }) => (
|
|
50
48
|
<InputLabel
|
|
51
49
|
classes={{
|
|
52
|
-
root: classes.inputLabelRoot,
|
|
53
50
|
focused: classes.inputLabelFocused,
|
|
54
51
|
error: classes.inputLabelError,
|
|
55
52
|
}}
|
|
56
53
|
{...props}
|
|
57
54
|
/>
|
|
58
55
|
))(({ color, theme }: StyledInputLabelProps) => ({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
[
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
color: theme.palette.error.main,
|
|
67
|
-
},
|
|
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,
|
|
68
63
|
},
|
|
69
64
|
}))
|
|
70
65
|
|
|
@@ -109,16 +104,13 @@ const StyledInput = styled(({ color: _color, ...props }) => (
|
|
|
109
104
|
<Input
|
|
110
105
|
classes={{
|
|
111
106
|
disabled: classes.inputDisabled,
|
|
112
|
-
root: classes.inputRoot,
|
|
113
107
|
underline: classes.inputUnderline,
|
|
114
108
|
error: classes.inputError,
|
|
115
109
|
}}
|
|
116
110
|
{...props}
|
|
117
111
|
/>
|
|
118
112
|
))(({ color, theme }: StyledInputProps) => ({
|
|
119
|
-
|
|
120
|
-
color: theme.palette.text.primary,
|
|
121
|
-
},
|
|
113
|
+
color: theme.palette.text.primary,
|
|
122
114
|
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
123
115
|
[`&:after,&:hover:before`]: {
|
|
124
116
|
borderBottomColor: theme.palette[color].main,
|
|
@@ -139,7 +131,6 @@ export interface StandardSelectProps {
|
|
|
139
131
|
error?: boolean
|
|
140
132
|
hasShrink?: boolean
|
|
141
133
|
placeholder: string
|
|
142
|
-
hasHelperText?: boolean
|
|
143
134
|
helperText?: string
|
|
144
135
|
InputProps?: object & Partial<InputProps>
|
|
145
136
|
value?: unknown
|
|
@@ -156,7 +147,6 @@ export function StandardSelect({
|
|
|
156
147
|
error = false,
|
|
157
148
|
hasShrink = false,
|
|
158
149
|
placeholder,
|
|
159
|
-
hasHelperText = false,
|
|
160
150
|
helperText,
|
|
161
151
|
InputProps,
|
|
162
152
|
value = '',
|
|
@@ -165,6 +155,7 @@ export function StandardSelect({
|
|
|
165
155
|
children,
|
|
166
156
|
}: StandardSelectProps) {
|
|
167
157
|
const hasAdornment = !!InputProps?.startAdornment
|
|
158
|
+
const hasHelperText = !!helperText
|
|
168
159
|
return (
|
|
169
160
|
<StyledFormControl
|
|
170
161
|
color={color}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
2
|
import { Story, Meta } from '@storybook/react'
|
|
3
3
|
import { InputAdornment, TextFieldProps } from '@material-ui/core'
|
|
4
4
|
import { Visibility } from '@material-ui/icons'
|
|
@@ -77,6 +77,40 @@ ValueOnly.args = {
|
|
|
77
77
|
label: 'Which UI?',
|
|
78
78
|
}
|
|
79
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
|
+
|
|
80
114
|
const WithSuffixStory: Story<TextFieldProps> = (args) => (
|
|
81
115
|
<TextField
|
|
82
116
|
{...args}
|