@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.
- package/declarations/libs/ui/src/index.d.ts +2 -3
- package/declarations/libs/ui/src/interfaces/index.d.ts +18 -0
- package/declarations/libs/ui/src/lib/TopicFilter.d.ts +1 -1
- package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +1 -1
- package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +2 -21
- package/declarations/libs/ui/src/lib/select/Select.d.ts +3 -0
- package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +2 -18
- package/declarations/libs/ui/src/lib/topic-filter/TopicFilter.d.ts +13 -0
- package/dist/libs/ui/src/index.js +4 -6
- package/dist/libs/ui/src/lib/TopicFilter.js +3 -1
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +24 -7
- package/dist/libs/ui/src/lib/select/Select.js +16 -0
- package/dist/libs/ui/src/lib/select/StandardSelect.js +16 -3
- package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +120 -0
- package/package.json +1 -1
- package/src/index.ts +2 -3
- package/src/interfaces/index.tsx +25 -0
- package/src/lib/select/OutlinedSelect.tsx +37 -44
- package/src/lib/select/Select.stories.tsx +421 -0
- package/src/lib/select/Select.tsx +13 -0
- package/src/lib/select/StandardSelect.tsx +24 -33
- package/src/lib/{TopicFilter.stories.tsx → topic-filter/TopicFilter.stories.tsx} +10 -7
- package/src/lib/{TopicFilter.tsx → topic-filter/TopicFilter.tsx} +5 -5
- package/src/lib/TopicFilter.spec.tsx +0 -10
- package/src/lib/menu-item/SelectMenuItem.spec.tsx +0 -10
- package/src/lib/select/OutlinedSelect.spec.tsx +0 -10
- package/src/lib/select/OutlinedSelect.stories.tsx +0 -245
- package/src/lib/select/StandardSelect.stories.tsx +0 -221
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export { default as TopicFilter } from './lib/TopicFilter';
|
|
1
|
+
export { default as TopicFilter } from './lib/topic-filter/TopicFilter';
|
|
2
2
|
export { default as SelectMenuItem } from './lib/menu-item/SelectMenuItem';
|
|
3
|
-
export { default as OutlinedSelect } from './lib/select/OutlinedSelect';
|
|
4
3
|
export { default as Button } from './lib/button/Button';
|
|
5
4
|
export { default as ButtonGroup } from './lib/button-group/ButtonGroup';
|
|
6
5
|
export { default as Radio } from './lib/radio/Radio';
|
|
7
6
|
export { default as TextField } from './lib/text-field/TextField';
|
|
8
|
-
export { default as
|
|
7
|
+
export { default as Select } from './lib/select/Select';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { SelectProps as MuiSelectProp, InputProps as MuiInputProps, OutlinedInputProps } from '@material-ui/core';
|
|
1
3
|
export interface ITopicTreeNode {
|
|
2
4
|
childTopics: ITopicTreeNode[];
|
|
3
5
|
id: string;
|
|
@@ -6,3 +8,19 @@ export interface ITopicTreeNode {
|
|
|
6
8
|
tags: string[];
|
|
7
9
|
title: string;
|
|
8
10
|
}
|
|
11
|
+
export interface SelectProps extends MuiSelectProp {
|
|
12
|
+
placeholder: string;
|
|
13
|
+
helperText?: string;
|
|
14
|
+
InputProps?: (Partial<OutlinedInputProps> & {
|
|
15
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
16
|
+
}) | (object & Partial<MuiInputProps>);
|
|
17
|
+
SelectProps?: object | Partial<MuiSelectProp>;
|
|
18
|
+
color?: 'primary' | 'secondary';
|
|
19
|
+
size?: 'medium' | 'small';
|
|
20
|
+
width?: number | 'auto';
|
|
21
|
+
paperMaxHeight?: number | 'auto';
|
|
22
|
+
error?: boolean;
|
|
23
|
+
hasLabel?: boolean;
|
|
24
|
+
hasShrink?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}
|
|
@@ -9,5 +9,5 @@ export interface TopicFilterProps {
|
|
|
9
9
|
hasArrow: boolean;
|
|
10
10
|
initSelectedTopicIds: string[];
|
|
11
11
|
}
|
|
12
|
-
declare const TopicFilter: ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }: TopicFilterProps) => JSX.Element;
|
|
12
|
+
export declare const TopicFilter: ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }: TopicFilterProps) => JSX.Element;
|
|
13
13
|
export default TopicFilter;
|
|
@@ -5,5 +5,5 @@ export interface SelectMenuItemProps extends MenuItemProps {
|
|
|
5
5
|
value?: any;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare const SelectMenuItem: React.ForwardRefExoticComponent<Pick<React.PropsWithChildren<SelectMenuItemProps>, "
|
|
8
|
+
declare const SelectMenuItem: React.ForwardRefExoticComponent<Pick<React.PropsWithChildren<SelectMenuItemProps>, "classes" | "disabled" | "value" | "onChange" | "children" | "onKeyUp" | "onKeyDown" | "onBlur" | "onFocus" | "defaultValue" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "innerRef" | "button" | "width" | "alignItems" | "dense" | "key" | "selected" | "ContainerComponent" | "ContainerProps" | "disableGutters" | "divider" | "focusVisibleClassName"> & React.RefAttributes<HTMLLIElement>>;
|
|
9
9
|
export default SelectMenuItem;
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export interface OutlinedSelectProps {
|
|
4
|
-
color?: 'primary' | 'secondary';
|
|
5
|
-
size?: 'medium' | 'small';
|
|
6
|
-
width?: number | 'auto';
|
|
7
|
-
paperMaxHeight?: number | 'auto';
|
|
8
|
-
error?: boolean;
|
|
9
|
-
hasLabel?: boolean;
|
|
10
|
-
hasShrink?: boolean;
|
|
11
|
-
placeholder: string;
|
|
12
|
-
helperText?: string;
|
|
13
|
-
value?: unknown;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
SelectProps?: object | Partial<SelectProps>;
|
|
16
|
-
OutlinedInputProps?: Partial<OutlinedInputProps> & {
|
|
17
|
-
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
-
};
|
|
19
|
-
children?: React.ReactNode;
|
|
20
|
-
}
|
|
21
|
-
declare const OutlinedSelect: ({ color, size, width, paperMaxHeight, error, hasLabel, hasShrink, placeholder, helperText, value, disabled, SelectProps, OutlinedInputProps, children, }: OutlinedSelectProps) => JSX.Element;
|
|
1
|
+
import { SelectProps } from '../../interfaces';
|
|
2
|
+
export declare const OutlinedSelect: ({ placeholder, helperText, InputProps, SelectProps, children, color, size, width, paperMaxHeight, error, hasLabel, hasShrink, value, disabled, }: SelectProps) => JSX.Element;
|
|
22
3
|
export default OutlinedSelect;
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export interface StandardSelectProps {
|
|
4
|
-
color?: 'primary' | 'secondary';
|
|
5
|
-
size?: 'medium' | 'small';
|
|
6
|
-
width?: number | 'auto';
|
|
7
|
-
paperMaxHeight?: number | 'auto';
|
|
8
|
-
error?: boolean;
|
|
9
|
-
hasShrink?: boolean;
|
|
10
|
-
placeholder: string;
|
|
11
|
-
helperText?: string;
|
|
12
|
-
InputProps?: object & Partial<InputProps>;
|
|
13
|
-
value?: unknown;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
SelectProps?: object | Partial<SelectProps>;
|
|
16
|
-
children?: React.ReactNode;
|
|
17
|
-
}
|
|
18
|
-
export declare function StandardSelect({ color, size, width, paperMaxHeight, error, hasShrink, placeholder, helperText, InputProps, value, SelectProps, disabled, children, }: StandardSelectProps): JSX.Element;
|
|
1
|
+
import { SelectProps } from '../../interfaces';
|
|
2
|
+
export declare function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color, size, width, paperMaxHeight, error, hasShrink, value, disabled, }: SelectProps): JSX.Element;
|
|
19
3
|
export default StandardSelect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ITopicTreeNode } from '../../interfaces';
|
|
2
|
+
export interface TopicFilterProps {
|
|
3
|
+
topicTree: ITopicTreeNode;
|
|
4
|
+
onTopicSelected: (topic: ITopicTreeNode, selectedInfo: {
|
|
5
|
+
layerNumber: number;
|
|
6
|
+
selectedTopicIds: string[];
|
|
7
|
+
}) => void;
|
|
8
|
+
isLastLayer: (topic: ITopicTreeNode) => boolean;
|
|
9
|
+
hasArrow: boolean;
|
|
10
|
+
initSelectedTopicIds: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const TopicFilter: ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }: TopicFilterProps) => JSX.Element;
|
|
13
|
+
export default TopicFilter;
|
|
@@ -3,13 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var TopicFilter_1 = require("./lib/TopicFilter");
|
|
6
|
+
exports.Select = exports.TextField = exports.Radio = exports.ButtonGroup = exports.Button = exports.SelectMenuItem = exports.TopicFilter = void 0;
|
|
7
|
+
var TopicFilter_1 = require("./lib/topic-filter/TopicFilter");
|
|
8
8
|
Object.defineProperty(exports, "TopicFilter", { enumerable: true, get: function () { return __importDefault(TopicFilter_1).default; } });
|
|
9
9
|
var SelectMenuItem_1 = require("./lib/menu-item/SelectMenuItem");
|
|
10
10
|
Object.defineProperty(exports, "SelectMenuItem", { enumerable: true, get: function () { return __importDefault(SelectMenuItem_1).default; } });
|
|
11
|
-
var OutlinedSelect_1 = require("./lib/select/OutlinedSelect");
|
|
12
|
-
Object.defineProperty(exports, "OutlinedSelect", { enumerable: true, get: function () { return __importDefault(OutlinedSelect_1).default; } });
|
|
13
11
|
var Button_1 = require("./lib/button/Button");
|
|
14
12
|
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return __importDefault(Button_1).default; } });
|
|
15
13
|
var ButtonGroup_1 = require("./lib/button-group/ButtonGroup");
|
|
@@ -18,5 +16,5 @@ var Radio_1 = require("./lib/radio/Radio");
|
|
|
18
16
|
Object.defineProperty(exports, "Radio", { enumerable: true, get: function () { return __importDefault(Radio_1).default; } });
|
|
19
17
|
var TextField_1 = require("./lib/text-field/TextField");
|
|
20
18
|
Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return __importDefault(TextField_1).default; } });
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "
|
|
19
|
+
var Select_1 = require("./lib/select/Select");
|
|
20
|
+
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return __importDefault(Select_1).default; } });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopicFilter = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
6
|
const styles_1 = require("@material-ui/core/styles");
|
|
@@ -115,4 +116,5 @@ const TopicFilter = ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSe
|
|
|
115
116
|
hasArrow && layerNumber !== layeredTopicList.length - 1 && (react_1.default.createElement(StyledArrowRightRoundedIcon, { fontSize: 'large', "data-testid": 'topic-filter-arrow' }))));
|
|
116
117
|
})));
|
|
117
118
|
};
|
|
118
|
-
exports.
|
|
119
|
+
exports.TopicFilter = TopicFilter;
|
|
120
|
+
exports.default = exports.TopicFilter;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutlinedSelect = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
6
|
const styles_1 = require("@material-ui/core/styles");
|
|
@@ -14,10 +15,12 @@ const classes = {
|
|
|
14
15
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
15
16
|
inputLabelDisabled: `${PREFIX}-inputLabelDisabled`,
|
|
16
17
|
outlineInputInput: `${PREFIX}-input`,
|
|
18
|
+
outlineInputRoot: `${PREFIX}-inputRoot`,
|
|
17
19
|
outlineInputInputMarginDense: `${PREFIX}-inputMarginDense`,
|
|
18
20
|
outlineInputNotchedOutline: `${PREFIX}-notchedOutline`,
|
|
19
21
|
outlineInputDisabled: `${PREFIX}-inputDisabled`,
|
|
20
22
|
outlineInputError: `${PREFIX}-outlinedInputError`,
|
|
23
|
+
outlineInputFocused: `${PREFIX}-focused`,
|
|
21
24
|
selectPaper: `${PREFIX}-menuPaper`,
|
|
22
25
|
};
|
|
23
26
|
const StyledFormControl = styles_1.styled((_a) => {
|
|
@@ -32,6 +35,9 @@ const StyledFormControl = styles_1.styled((_a) => {
|
|
|
32
35
|
borderColor: theme.palette[color].main,
|
|
33
36
|
},
|
|
34
37
|
},
|
|
38
|
+
[`& .${classes.outlineInputError}.${classes.outlineInputFocused} .${classes.outlineInputNotchedOutline}`]: {
|
|
39
|
+
borderColor: `${theme.palette.error.main}`,
|
|
40
|
+
},
|
|
35
41
|
}));
|
|
36
42
|
const StyledInputLabel = styles_1.styled((_a) => {
|
|
37
43
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
@@ -62,14 +68,22 @@ const StyledInputLabel = styles_1.styled((_a) => {
|
|
|
62
68
|
},
|
|
63
69
|
}));
|
|
64
70
|
const StyledOutlinedInput = styles_1.styled((props) => (react_1.default.createElement(core_1.OutlinedInput, Object.assign({ classes: {
|
|
71
|
+
root: classes.outlineInputRoot,
|
|
72
|
+
focused: classes.outlineInputFocused,
|
|
65
73
|
input: classes.outlineInputInput,
|
|
66
74
|
inputMarginDense: classes.outlineInputInputMarginDense,
|
|
67
75
|
notchedOutline: classes.outlineInputNotchedOutline,
|
|
68
76
|
disabled: classes.outlineInputDisabled,
|
|
69
77
|
error: classes.outlineInputError,
|
|
70
78
|
} }, props))))(({ theme }) => ({
|
|
79
|
+
[`&.${classes.outlineInputRoot}.${classes.outlineInputFocused}`]: {
|
|
80
|
+
backgroundColor: theme.palette.action.selected,
|
|
81
|
+
},
|
|
71
82
|
[`& .${classes.outlineInputInput}`]: {
|
|
72
83
|
color: theme.palette.text.primary,
|
|
84
|
+
['&:focus']: {
|
|
85
|
+
background: 'rgba(0,0,0,0)',
|
|
86
|
+
},
|
|
73
87
|
},
|
|
74
88
|
[`& .${classes.outlineInputInputMarginDense}`]: {
|
|
75
89
|
padding: '14.5px 15px 14.5px 12px',
|
|
@@ -88,20 +102,23 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
88
102
|
horizontal: 'left',
|
|
89
103
|
},
|
|
90
104
|
getContentAnchorEl: null,
|
|
91
|
-
classes: {
|
|
105
|
+
classes: {
|
|
106
|
+
paper: className,
|
|
107
|
+
},
|
|
92
108
|
} }, props)));
|
|
93
109
|
})(({ hasAdornment, paperMaxHeight }) => ({
|
|
94
|
-
'
|
|
110
|
+
'&': {
|
|
95
111
|
maxHeight: paperMaxHeight,
|
|
96
112
|
left: hasAdornment ? '24px !important' : '70px',
|
|
97
113
|
},
|
|
98
114
|
}));
|
|
99
|
-
const OutlinedSelect = ({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasLabel = true, hasShrink = false,
|
|
100
|
-
const hasAdornment = !!(
|
|
115
|
+
const OutlinedSelect = ({ placeholder, helperText, InputProps, SelectProps, children, color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasLabel = true, hasShrink = false, value = '', disabled = false, }) => {
|
|
116
|
+
const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
|
|
101
117
|
const hasHelperText = !!helperText;
|
|
102
118
|
return (react_1.default.createElement(StyledFormControl, { size: size, width: width, disabled: disabled, error: error, color: color },
|
|
103
|
-
hasLabel
|
|
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 },
|
|
119
|
+
hasLabel && (react_1.default.createElement(StyledInputLabel, { color: color, variant: 'outlined', shrink: hasShrink ? true : undefined }, placeholder)),
|
|
120
|
+
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 }, InputProps)) }, SelectProps), children),
|
|
105
121
|
hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
|
|
106
122
|
};
|
|
107
|
-
exports.
|
|
123
|
+
exports.OutlinedSelect = OutlinedSelect;
|
|
124
|
+
exports.default = exports.OutlinedSelect;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Select = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const OutlinedSelect_1 = require("./OutlinedSelect");
|
|
7
|
+
const StandardSelect_1 = require("./StandardSelect");
|
|
8
|
+
function Select(_a) {
|
|
9
|
+
var { variant } = _a, props = tslib_1.__rest(_a, ["variant"]);
|
|
10
|
+
if (variant === 'outlined') {
|
|
11
|
+
return react_1.default.createElement(OutlinedSelect_1.OutlinedSelect, Object.assign({}, props));
|
|
12
|
+
}
|
|
13
|
+
return react_1.default.createElement(StandardSelect_1.StandardSelect, Object.assign({}, props));
|
|
14
|
+
}
|
|
15
|
+
exports.Select = Select;
|
|
16
|
+
exports.default = Select;
|
|
@@ -11,6 +11,9 @@ const classes = {
|
|
|
11
11
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
12
12
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
13
13
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
14
|
+
inputRoot: `${PREFIX}-inputRoot`,
|
|
15
|
+
inputFocused: `${PREFIX}-inputFocused`,
|
|
16
|
+
inputInput: `${PREFIX}-input`,
|
|
14
17
|
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
15
18
|
inputError: `${PREFIX}-inputError`,
|
|
16
19
|
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
@@ -56,17 +59,27 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
56
59
|
maxHeight: paperMaxHeight,
|
|
57
60
|
left: hasAdornment ? '48px !important' : '70px',
|
|
58
61
|
},
|
|
59
|
-
[`&.${classes.selectDisabled}`]: {},
|
|
60
62
|
}));
|
|
61
63
|
const StyledInput = styles_1.styled((_a) => {
|
|
62
64
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
63
65
|
return (react_1.default.createElement(core_1.Input, Object.assign({ classes: {
|
|
66
|
+
root: classes.inputRoot,
|
|
67
|
+
focused: classes.inputFocused,
|
|
68
|
+
input: classes.inputInput,
|
|
64
69
|
disabled: classes.inputDisabled,
|
|
65
70
|
underline: classes.inputUnderline,
|
|
66
71
|
error: classes.inputError,
|
|
67
72
|
} }, props)));
|
|
68
73
|
})(({ color, theme }) => ({
|
|
69
74
|
color: theme.palette.text.primary,
|
|
75
|
+
[`&.${classes.inputRoot}.${classes.inputFocused}`]: {
|
|
76
|
+
backgroundColor: theme.palette.action.selected,
|
|
77
|
+
},
|
|
78
|
+
[`& .${classes.inputInput}`]: {
|
|
79
|
+
['&:focus']: {
|
|
80
|
+
background: 'rgba(0,0,0,0)',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
70
83
|
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
71
84
|
[`&:after,&:hover:before`]: {
|
|
72
85
|
borderBottomColor: theme.palette[color].main,
|
|
@@ -78,11 +91,11 @@ const StyledInput = styles_1.styled((_a) => {
|
|
|
78
91
|
},
|
|
79
92
|
},
|
|
80
93
|
}));
|
|
81
|
-
function StandardSelect({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasShrink = false,
|
|
94
|
+
function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasShrink = false, value = '', disabled = false, }) {
|
|
82
95
|
const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
|
|
83
96
|
const hasHelperText = !!helperText;
|
|
84
97
|
return (react_1.default.createElement(StyledFormControl, { color: color, size: size, width: width, disabled: disabled, error: error },
|
|
85
|
-
|
|
98
|
+
react_1.default.createElement(StyledInputLabel, { color: color, shrink: hasShrink ? true : undefined }, placeholder),
|
|
86
99
|
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),
|
|
87
100
|
hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
|
|
88
101
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopicFilter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const styles_1 = require("@material-ui/core/styles");
|
|
7
|
+
const ArrowRightRounded_1 = tslib_1.__importDefault(require("@material-ui/icons/ArrowRightRounded"));
|
|
8
|
+
const OutlinedSelect_1 = tslib_1.__importDefault(require("../select/OutlinedSelect"));
|
|
9
|
+
const SelectMenuItem_1 = tslib_1.__importDefault(require("../menu-item/SelectMenuItem"));
|
|
10
|
+
// self-defined-configs
|
|
11
|
+
const PLACEHOLDER = '請選擇';
|
|
12
|
+
// self-defined-components
|
|
13
|
+
const PREFIX = 'JuiTopicFilter';
|
|
14
|
+
const FiltersWrapper = styles_1.styled('div')({
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
flexWrap: 'wrap',
|
|
18
|
+
});
|
|
19
|
+
const SelectWrapper = styles_1.styled('div')({
|
|
20
|
+
display: 'flex',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
});
|
|
23
|
+
const StyledArrowRightRoundedIcon = styles_1.styled(ArrowRightRounded_1.default)(({ theme }) => ({
|
|
24
|
+
margin: theme.spacing(-1, -1.5),
|
|
25
|
+
fontSize: theme.spacing(7),
|
|
26
|
+
color: '#444',
|
|
27
|
+
}));
|
|
28
|
+
const TopicFilter = ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }) => {
|
|
29
|
+
const [selectedTopicIds, setSelectedTopicIds] = react_1.useState([]);
|
|
30
|
+
const [layeredTopicList, setLayeredTopicList] = react_1.useState([]);
|
|
31
|
+
const [isFocusedList, setIsFocusedList] = react_1.useState([]);
|
|
32
|
+
const initSelectedLayers = () => {
|
|
33
|
+
const newLayeredTopicList = initSelectedTopicIds.reduce((topicListAccumulator, topicId, index) => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const selectedTopic = (_b = (_a = topicListAccumulator[index]) === null || _a === void 0 ? void 0 : _a.childTopics) === null || _b === void 0 ? void 0 : _b.find((childTopic) => childTopic.id === topicId);
|
|
36
|
+
if (!selectedTopic) {
|
|
37
|
+
return topicListAccumulator;
|
|
38
|
+
}
|
|
39
|
+
if (isLastLayer(selectedTopic)) {
|
|
40
|
+
return topicListAccumulator;
|
|
41
|
+
}
|
|
42
|
+
return [...topicListAccumulator, selectedTopic];
|
|
43
|
+
}, [topicTree]);
|
|
44
|
+
setLayeredTopicList(newLayeredTopicList);
|
|
45
|
+
setSelectedTopicIds(initSelectedTopicIds.slice(0, newLayeredTopicList.length));
|
|
46
|
+
setIsFocusedList(Array(newLayeredTopicList.length).fill(false));
|
|
47
|
+
};
|
|
48
|
+
const handleChange = (e, layerNumber, layeredTopic) => {
|
|
49
|
+
const selectedTopic = layeredTopic.childTopics.find((childTopic) => childTopic.id === e.target.value);
|
|
50
|
+
const newSelectedTopicIds = [
|
|
51
|
+
...selectedTopicIds.slice(0, layerNumber),
|
|
52
|
+
selectedTopic.id,
|
|
53
|
+
];
|
|
54
|
+
setSelectedTopicIds(newSelectedTopicIds);
|
|
55
|
+
onTopicSelected(selectedTopic, {
|
|
56
|
+
layerNumber,
|
|
57
|
+
selectedTopicIds: newSelectedTopicIds,
|
|
58
|
+
});
|
|
59
|
+
if (isLastLayer(selectedTopic)) {
|
|
60
|
+
setLayeredTopicList((prevTopicList) => prevTopicList.slice(0, layerNumber + 1));
|
|
61
|
+
setIsFocusedList((prevList) => prevList.slice(0, layerNumber + 1));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
setLayeredTopicList((prevTopicList) => [
|
|
65
|
+
...prevTopicList.slice(0, layerNumber + 1),
|
|
66
|
+
selectedTopic,
|
|
67
|
+
]);
|
|
68
|
+
setIsFocusedList((prevList) => [
|
|
69
|
+
...prevList.slice(0, layerNumber + 1),
|
|
70
|
+
false,
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
react_1.useEffect(() => {
|
|
75
|
+
if (!topicTree || Object.keys(topicTree).length === 0) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (initSelectedTopicIds.length !== 0) {
|
|
79
|
+
initSelectedLayers();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setLayeredTopicList([topicTree]);
|
|
83
|
+
}, [topicTree]);
|
|
84
|
+
if (layeredTopicList.length === 0) {
|
|
85
|
+
return (react_1.default.createElement(OutlinedSelect_1.default, { size: 'small', width: 220, placeholder: '\u8F09\u5165\u8CC7\u6599\u4E2D...', disabled: true }));
|
|
86
|
+
}
|
|
87
|
+
return (react_1.default.createElement(FiltersWrapper, null, layeredTopicList.map((layeredTopic, layerNumber) => {
|
|
88
|
+
const hasLabel = isFocusedList[layerNumber] || !selectedTopicIds[layerNumber];
|
|
89
|
+
return (react_1.default.createElement(SelectWrapper, { key: layeredTopic.id },
|
|
90
|
+
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: {
|
|
91
|
+
'data-testid': `layered-topic-${layerNumber}`,
|
|
92
|
+
}, InputProps: {
|
|
93
|
+
inputProps: {
|
|
94
|
+
'aria-label': `layered-topic-${layerNumber}`,
|
|
95
|
+
},
|
|
96
|
+
onChange: (e) => {
|
|
97
|
+
handleChange(e, layerNumber, layeredTopic);
|
|
98
|
+
},
|
|
99
|
+
onFocus: () => {
|
|
100
|
+
setIsFocusedList((prevList) => {
|
|
101
|
+
const newList = [...prevList];
|
|
102
|
+
newList[layerNumber] = true;
|
|
103
|
+
return newList;
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
onBlur: () => {
|
|
107
|
+
setIsFocusedList((prevList) => {
|
|
108
|
+
const newList = [...prevList];
|
|
109
|
+
newList[layerNumber] = false;
|
|
110
|
+
return newList;
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
} },
|
|
114
|
+
react_1.default.createElement(SelectMenuItem_1.default, { width: 220, disabled: true }, PLACEHOLDER),
|
|
115
|
+
layeredTopic.childTopics.map((childTopic) => (react_1.default.createElement(SelectMenuItem_1.default, { width: 220, key: childTopic.id, value: childTopic.id, "data-testid": `layered-menuitem-${layerNumber}`, "data-is-content-topic": childTopic.isContentTopic }, childTopic.title)))),
|
|
116
|
+
hasArrow && layerNumber !== layeredTopicList.length - 1 && (react_1.default.createElement(StyledArrowRightRoundedIcon, { fontSize: 'large', "data-testid": 'topic-filter-arrow' }))));
|
|
117
|
+
})));
|
|
118
|
+
};
|
|
119
|
+
exports.TopicFilter = TopicFilter;
|
|
120
|
+
exports.default = exports.TopicFilter;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export { default as TopicFilter } from './lib/TopicFilter'
|
|
1
|
+
export { default as TopicFilter } from './lib/topic-filter/TopicFilter'
|
|
2
2
|
export { default as SelectMenuItem } from './lib/menu-item/SelectMenuItem'
|
|
3
|
-
export { default as OutlinedSelect } from './lib/select/OutlinedSelect'
|
|
4
3
|
export { default as Button } from './lib/button/Button'
|
|
5
4
|
export { default as ButtonGroup } from './lib/button-group/ButtonGroup'
|
|
6
5
|
export { default as Radio } from './lib/radio/Radio'
|
|
7
6
|
export { default as TextField } from './lib/text-field/TextField'
|
|
8
|
-
export { default as
|
|
7
|
+
export { default as Select } from './lib/select/Select'
|
package/src/interfaces/index.tsx
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
SelectProps as MuiSelectProp,
|
|
4
|
+
InputProps as MuiInputProps,
|
|
5
|
+
OutlinedInputProps,
|
|
6
|
+
} from '@material-ui/core'
|
|
7
|
+
|
|
1
8
|
export interface ITopicTreeNode {
|
|
2
9
|
childTopics: ITopicTreeNode[]
|
|
3
10
|
id: string
|
|
@@ -6,3 +13,21 @@ export interface ITopicTreeNode {
|
|
|
6
13
|
tags: string[]
|
|
7
14
|
title: string
|
|
8
15
|
}
|
|
16
|
+
export interface SelectProps extends MuiSelectProp {
|
|
17
|
+
placeholder: string
|
|
18
|
+
helperText?: string
|
|
19
|
+
InputProps?:
|
|
20
|
+
| (Partial<OutlinedInputProps> & {
|
|
21
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void
|
|
22
|
+
})
|
|
23
|
+
| (object & Partial<MuiInputProps>)
|
|
24
|
+
SelectProps?: object | Partial<MuiSelectProp>
|
|
25
|
+
color?: 'primary' | 'secondary'
|
|
26
|
+
size?: 'medium' | 'small'
|
|
27
|
+
width?: number | 'auto'
|
|
28
|
+
paperMaxHeight?: number | 'auto'
|
|
29
|
+
error?: boolean
|
|
30
|
+
hasLabel?: boolean
|
|
31
|
+
hasShrink?: boolean
|
|
32
|
+
disabled?: boolean
|
|
33
|
+
}
|