@junyiacademy/ui-test 0.0.11 → 1.4.0
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 +19 -0
- package/declarations/libs/ui/src/lib/menu-item/SelectMenuItem.d.ts +2 -2
- package/declarations/libs/ui/src/lib/select/OutlinedSelect.d.ts +2 -19
- package/declarations/libs/ui/src/lib/select/Select.d.ts +3 -0
- package/declarations/libs/ui/src/lib/select/StandardSelect.d.ts +2 -15
- 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/menu-item/SelectMenuItem.js +4 -1
- package/dist/libs/ui/src/lib/select/OutlinedSelect.js +30 -14
- package/dist/libs/ui/src/lib/select/Select.js +16 -0
- package/dist/libs/ui/src/lib/select/StandardSelect.js +13 -5
- package/dist/libs/ui/src/lib/topic-filter/TopicFilter.js +121 -0
- package/package.json +2 -2
- package/src/index.ts +2 -3
- package/src/interfaces/index.tsx +26 -0
- package/src/lib/menu-item/SelectMenuItem.tsx +6 -3
- package/src/lib/select/OutlinedSelect.tsx +38 -37
- package/src/lib/select/{StandardSelect.stories.tsx → Select.stories.tsx} +119 -34
- package/src/lib/select/Select.tsx +13 -0
- package/src/lib/select/StandardSelect.tsx +22 -25
- package/src/lib/{TopicFilter.stories.tsx → topic-filter/TopicFilter.stories.tsx} +1 -1
- package/src/lib/{TopicFilter.tsx → topic-filter/TopicFilter.tsx} +14 -9
- 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/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 -238
|
@@ -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,20 @@ 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 | string;
|
|
21
|
+
selectMargin?: number | string;
|
|
22
|
+
paperMaxHeight?: number | string;
|
|
23
|
+
error?: boolean;
|
|
24
|
+
hasLabel?: boolean;
|
|
25
|
+
hasShrink?: boolean;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MenuItemProps } from '@material-ui/core';
|
|
3
3
|
export interface SelectMenuItemProps extends MenuItemProps {
|
|
4
|
-
width: number |
|
|
4
|
+
width: number | string;
|
|
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,20 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface OutlinedSelectProps extends SelectProps {
|
|
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
|
-
disabled?: boolean;
|
|
14
|
-
SelectProps?: object | Partial<SelectProps>;
|
|
15
|
-
OutlinedInputProps?: Partial<OutlinedInputProps> & {
|
|
16
|
-
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
declare const OutlinedSelect: ({ placeholder, SelectProps, OutlinedInputProps, children, color, size, width, paperMaxHeight, error, hasLabel, hasShrink, helperText, value, disabled, }: OutlinedSelectProps) => JSX.Element;
|
|
1
|
+
import { SelectProps } from '../../interfaces';
|
|
2
|
+
export declare const OutlinedSelect: ({ placeholder, helperText, InputProps, SelectProps, children, color, size, width, selectMargin, paperMaxHeight, error, hasLabel, hasShrink, value, disabled, }: SelectProps) => JSX.Element;
|
|
20
3
|
export default OutlinedSelect;
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { SelectProps
|
|
2
|
-
export
|
|
3
|
-
color?: 'primary' | 'secondary';
|
|
4
|
-
size?: 'medium' | 'small';
|
|
5
|
-
width?: number | 'auto';
|
|
6
|
-
paperMaxHeight?: number | 'auto';
|
|
7
|
-
error?: boolean;
|
|
8
|
-
hasShrink?: boolean;
|
|
9
|
-
placeholder: string;
|
|
10
|
-
helperText?: string;
|
|
11
|
-
InputProps?: object & Partial<InputProps>;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
SelectProps?: object | Partial<SelectProps>;
|
|
14
|
-
}
|
|
15
|
-
export declare function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color, size, width, paperMaxHeight, error, hasShrink, value, disabled, }: StandardSelectProps): JSX.Element;
|
|
1
|
+
import { SelectProps } from '../../interfaces';
|
|
2
|
+
export declare function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color, size, width, selectMargin, paperMaxHeight, error, hasShrink, value, disabled, }: SelectProps): JSX.Element;
|
|
16
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; } });
|
|
@@ -16,8 +16,11 @@ const StyledMenuItem = styles_1.styled((_a) => {
|
|
|
16
16
|
width: width,
|
|
17
17
|
whiteSpace: 'unset',
|
|
18
18
|
color: theme.palette.text.primary,
|
|
19
|
-
[
|
|
19
|
+
[`&.${classes.menuItemSelected}`]: {
|
|
20
20
|
backgroundColor: theme.palette.grey[300],
|
|
21
|
+
['&:hover']: {
|
|
22
|
+
backgroundColor: theme.palette.grey[200],
|
|
23
|
+
},
|
|
21
24
|
},
|
|
22
25
|
}));
|
|
23
26
|
const SelectMenuItem = react_1.default.forwardRef((_a, ref) => {
|
|
@@ -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,18 +15,20 @@ 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) => {
|
|
24
|
-
var { color: _color, width: _width } = _a, props = tslib_1.__rest(_a, ["color", "width"]);
|
|
25
|
-
return react_1.default.createElement(core_1.FormControl, Object.assign({}, props));
|
|
26
|
-
})(({ color, width, theme }) => ({
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var { color: _color, width: _width, selectMargin: _selectMargin } = _a, props = tslib_1.__rest(_a, ["color", "width", "selectMargin"]);
|
|
28
|
+
return (react_1.default.createElement(core_1.FormControl, Object.assign({}, props)));
|
|
29
|
+
})(({ color, width, selectMargin, theme }) => ({
|
|
30
|
+
width,
|
|
31
|
+
margin: selectMargin,
|
|
29
32
|
backgroundColor: 'white',
|
|
30
33
|
'&:hover': {
|
|
31
34
|
[`& :not(.${classes.outlineInputDisabled}):not(.${classes.outlineInputError}) .${classes.outlineInputNotchedOutline}`]: {
|
|
@@ -62,17 +65,27 @@ const StyledInputLabel = styles_1.styled((_a) => {
|
|
|
62
65
|
},
|
|
63
66
|
}));
|
|
64
67
|
const StyledOutlinedInput = styles_1.styled((props) => (react_1.default.createElement(core_1.OutlinedInput, Object.assign({ classes: {
|
|
68
|
+
root: classes.outlineInputRoot,
|
|
65
69
|
input: classes.outlineInputInput,
|
|
70
|
+
focused: classes.outlineInputFocused,
|
|
66
71
|
inputMarginDense: classes.outlineInputInputMarginDense,
|
|
67
72
|
notchedOutline: classes.outlineInputNotchedOutline,
|
|
68
73
|
disabled: classes.outlineInputDisabled,
|
|
69
74
|
error: classes.outlineInputError,
|
|
70
75
|
} }, props))))(({ theme }) => ({
|
|
76
|
+
[`&.${classes.outlineInputRoot}`]: {
|
|
77
|
+
[`&.${classes.outlineInputError}.${classes.outlineInputFocused} .${classes.outlineInputNotchedOutline}`]: {
|
|
78
|
+
borderColor: `${theme.palette.error.main}`,
|
|
79
|
+
},
|
|
80
|
+
[`& .${classes.outlineInputInputMarginDense}`]: {
|
|
81
|
+
padding: '14.5px 15px 14.5px 12px',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
71
84
|
[`& .${classes.outlineInputInput}`]: {
|
|
72
85
|
color: theme.palette.text.primary,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
['&:focus']: {
|
|
87
|
+
background: 'rgba(0,0,0,0)',
|
|
88
|
+
},
|
|
76
89
|
},
|
|
77
90
|
}));
|
|
78
91
|
const StyledSelect = styles_1.styled((_a) => {
|
|
@@ -88,7 +101,9 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
88
101
|
horizontal: 'left',
|
|
89
102
|
},
|
|
90
103
|
getContentAnchorEl: null,
|
|
91
|
-
classes: {
|
|
104
|
+
classes: {
|
|
105
|
+
paper: className,
|
|
106
|
+
},
|
|
92
107
|
} }, props)));
|
|
93
108
|
})(({ hasAdornment, paperMaxHeight }) => ({
|
|
94
109
|
'&': {
|
|
@@ -96,12 +111,13 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
96
111
|
left: hasAdornment ? '24px !important' : '70px',
|
|
97
112
|
},
|
|
98
113
|
}));
|
|
99
|
-
const OutlinedSelect = ({ placeholder,
|
|
100
|
-
const hasAdornment = !!(
|
|
114
|
+
const OutlinedSelect = ({ placeholder, helperText, InputProps, SelectProps, children, color = 'primary', size = 'small', width = 'auto', selectMargin = 0, paperMaxHeight = 'auto', error = false, hasLabel = true, hasShrink = false, value = '', disabled = false, }) => {
|
|
115
|
+
const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
|
|
101
116
|
const hasHelperText = !!helperText;
|
|
102
|
-
return (react_1.default.createElement(StyledFormControl, { size: size, width: width, disabled: disabled, error: error, color: color },
|
|
117
|
+
return (react_1.default.createElement(StyledFormControl, { size: size, width: width, selectMargin: selectMargin, disabled: disabled, error: error, color: color },
|
|
103
118
|
hasLabel && (react_1.default.createElement(StyledInputLabel, { color: color, variant: 'outlined', shrink: hasShrink ? true : undefined }, placeholder)),
|
|
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
|
+
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
120
|
hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
|
|
106
121
|
};
|
|
107
|
-
exports.
|
|
122
|
+
exports.OutlinedSelect = OutlinedSelect;
|
|
123
|
+
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,8 @@ const classes = {
|
|
|
11
11
|
inputLabelFocused: `${PREFIX}-inputLabelFocused`,
|
|
12
12
|
inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
|
|
13
13
|
inputLabelError: `${PREFIX}-inputLabelError`,
|
|
14
|
+
inputFocused: `${PREFIX}-inputFocused`,
|
|
15
|
+
inputInput: `${PREFIX}-input`,
|
|
14
16
|
inputUnderline: `${PREFIX}-inputUnderline`,
|
|
15
17
|
inputError: `${PREFIX}-inputError`,
|
|
16
18
|
inputDisabled: `${PREFIX}-inputDisabled`,
|
|
@@ -19,11 +21,11 @@ const classes = {
|
|
|
19
21
|
selectDisabled: `${PREFIX}-selectDisabled`,
|
|
20
22
|
};
|
|
21
23
|
const StyledFormControl = styles_1.styled((_a) => {
|
|
22
|
-
var { width: _width } = _a, props = tslib_1.__rest(_a, ["width"]);
|
|
24
|
+
var { width: _width, selectMargin: _selectMargin } = _a, props = tslib_1.__rest(_a, ["width", "selectMargin"]);
|
|
23
25
|
return (react_1.default.createElement(core_1.FormControl, Object.assign({}, props)));
|
|
24
|
-
})(({ width, theme }) => ({
|
|
26
|
+
})(({ width, selectMargin, theme }) => ({
|
|
25
27
|
width,
|
|
26
|
-
margin:
|
|
28
|
+
margin: selectMargin,
|
|
27
29
|
}));
|
|
28
30
|
const StyledInputLabel = styles_1.styled((_a) => {
|
|
29
31
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
@@ -60,12 +62,18 @@ const StyledSelect = styles_1.styled((_a) => {
|
|
|
60
62
|
const StyledInput = styles_1.styled((_a) => {
|
|
61
63
|
var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
|
|
62
64
|
return (react_1.default.createElement(core_1.Input, Object.assign({ classes: {
|
|
65
|
+
input: classes.inputInput,
|
|
63
66
|
disabled: classes.inputDisabled,
|
|
64
67
|
underline: classes.inputUnderline,
|
|
65
68
|
error: classes.inputError,
|
|
66
69
|
} }, props)));
|
|
67
70
|
})(({ color, theme }) => ({
|
|
68
71
|
color: theme.palette.text.primary,
|
|
72
|
+
[`& .${classes.inputInput}`]: {
|
|
73
|
+
['&:focus']: {
|
|
74
|
+
background: 'rgba(0,0,0,0)',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
69
77
|
[`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
|
|
70
78
|
[`&:after,&:hover:before`]: {
|
|
71
79
|
borderBottomColor: theme.palette[color].main,
|
|
@@ -77,10 +85,10 @@ const StyledInput = styles_1.styled((_a) => {
|
|
|
77
85
|
},
|
|
78
86
|
},
|
|
79
87
|
}));
|
|
80
|
-
function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color = 'primary', size = '
|
|
88
|
+
function StandardSelect({ placeholder, helperText, InputProps, SelectProps, children, color = 'primary', size = 'small', width = 'auto', selectMargin = '0', paperMaxHeight = 'auto', error = false, hasShrink = false, value = '', disabled = false, }) {
|
|
81
89
|
const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
|
|
82
90
|
const hasHelperText = !!helperText;
|
|
83
|
-
return (react_1.default.createElement(StyledFormControl, { color: color, size: size, width: width, disabled: disabled, error: error },
|
|
91
|
+
return (react_1.default.createElement(StyledFormControl, { color: color, size: size, width: width, selectMargin: selectMargin, disabled: disabled, error: error },
|
|
84
92
|
react_1.default.createElement(StyledInputLabel, { color: color, shrink: hasShrink ? true : undefined }, placeholder),
|
|
85
93
|
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),
|
|
86
94
|
hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
|
|
@@ -0,0 +1,121 @@
|
|
|
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 Select_1 = tslib_1.__importDefault(require("../select/Select"));
|
|
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 theme = styles_1.useTheme();
|
|
30
|
+
const [selectedTopicIds, setSelectedTopicIds] = react_1.useState([]);
|
|
31
|
+
const [layeredTopicList, setLayeredTopicList] = react_1.useState([]);
|
|
32
|
+
const [isFocusedList, setIsFocusedList] = react_1.useState([]);
|
|
33
|
+
const initSelectedLayers = () => {
|
|
34
|
+
const newLayeredTopicList = initSelectedTopicIds.reduce((topicListAccumulator, topicId, index) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
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);
|
|
37
|
+
if (!selectedTopic) {
|
|
38
|
+
return topicListAccumulator;
|
|
39
|
+
}
|
|
40
|
+
if (isLastLayer(selectedTopic)) {
|
|
41
|
+
return topicListAccumulator;
|
|
42
|
+
}
|
|
43
|
+
return [...topicListAccumulator, selectedTopic];
|
|
44
|
+
}, [topicTree]);
|
|
45
|
+
setLayeredTopicList(newLayeredTopicList);
|
|
46
|
+
setSelectedTopicIds(initSelectedTopicIds.slice(0, newLayeredTopicList.length));
|
|
47
|
+
setIsFocusedList(Array(newLayeredTopicList.length).fill(false));
|
|
48
|
+
};
|
|
49
|
+
const handleChange = (e, layerNumber, layeredTopic) => {
|
|
50
|
+
const selectedTopic = layeredTopic.childTopics.find((childTopic) => childTopic.id === e.target.value);
|
|
51
|
+
const newSelectedTopicIds = [
|
|
52
|
+
...selectedTopicIds.slice(0, layerNumber),
|
|
53
|
+
selectedTopic.id,
|
|
54
|
+
];
|
|
55
|
+
setSelectedTopicIds(newSelectedTopicIds);
|
|
56
|
+
onTopicSelected(selectedTopic, {
|
|
57
|
+
layerNumber,
|
|
58
|
+
selectedTopicIds: newSelectedTopicIds,
|
|
59
|
+
});
|
|
60
|
+
if (isLastLayer(selectedTopic)) {
|
|
61
|
+
setLayeredTopicList((prevTopicList) => prevTopicList.slice(0, layerNumber + 1));
|
|
62
|
+
setIsFocusedList((prevList) => prevList.slice(0, layerNumber + 1));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
setLayeredTopicList((prevTopicList) => [
|
|
66
|
+
...prevTopicList.slice(0, layerNumber + 1),
|
|
67
|
+
selectedTopic,
|
|
68
|
+
]);
|
|
69
|
+
setIsFocusedList((prevList) => [
|
|
70
|
+
...prevList.slice(0, layerNumber + 1),
|
|
71
|
+
false,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
react_1.useEffect(() => {
|
|
76
|
+
if (!topicTree || Object.keys(topicTree).length === 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (initSelectedTopicIds.length !== 0) {
|
|
80
|
+
initSelectedLayers();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
setLayeredTopicList([topicTree]);
|
|
84
|
+
}, [topicTree]);
|
|
85
|
+
if (layeredTopicList.length === 0) {
|
|
86
|
+
return (react_1.default.createElement(Select_1.default, { variant: 'outlined', size: 'small', width: 220, selectMargin: theme.spacing(1), placeholder: '\u8F09\u5165\u8CC7\u6599\u4E2D...', disabled: true }));
|
|
87
|
+
}
|
|
88
|
+
return (react_1.default.createElement(FiltersWrapper, null, layeredTopicList.map((layeredTopic, layerNumber) => {
|
|
89
|
+
const hasLabel = isFocusedList[layerNumber] || !selectedTopicIds[layerNumber];
|
|
90
|
+
return (react_1.default.createElement(SelectWrapper, { key: layeredTopic.id },
|
|
91
|
+
react_1.default.createElement(Select_1.default, { variant: 'outlined', size: 'small', width: 220, selectMargin: theme.spacing(1), paperMaxHeight: 412, hasLabel: hasLabel, placeholder: PLACEHOLDER, value: (selectedTopicIds === null || selectedTopicIds === void 0 ? void 0 : selectedTopicIds[layerNumber]) || '', SelectProps: {
|
|
92
|
+
'data-testid': `layered-topic-${layerNumber}`,
|
|
93
|
+
}, InputProps: {
|
|
94
|
+
inputProps: {
|
|
95
|
+
'aria-label': `layered-topic-${layerNumber}`,
|
|
96
|
+
},
|
|
97
|
+
onChange: (e) => {
|
|
98
|
+
handleChange(e, layerNumber, layeredTopic);
|
|
99
|
+
},
|
|
100
|
+
onFocus: () => {
|
|
101
|
+
setIsFocusedList((prevList) => {
|
|
102
|
+
const newList = [...prevList];
|
|
103
|
+
newList[layerNumber] = true;
|
|
104
|
+
return newList;
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
onBlur: () => {
|
|
108
|
+
setIsFocusedList((prevList) => {
|
|
109
|
+
const newList = [...prevList];
|
|
110
|
+
newList[layerNumber] = false;
|
|
111
|
+
return newList;
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
} },
|
|
115
|
+
react_1.default.createElement(SelectMenuItem_1.default, { width: 220, disabled: true }, PLACEHOLDER),
|
|
116
|
+
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)))),
|
|
117
|
+
hasArrow && layerNumber !== layeredTopicList.length - 1 && (react_1.default.createElement(StyledArrowRightRoundedIcon, { fontSize: 'large', "data-testid": 'topic-filter-arrow' }))));
|
|
118
|
+
})));
|
|
119
|
+
};
|
|
120
|
+
exports.TopicFilter = TopicFilter;
|
|
121
|
+
exports.default = exports.TopicFilter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junyiacademy/ui-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "junyiacademy ui library",
|
|
5
5
|
"main": "./dist/libs/ui/src/index.js",
|
|
6
6
|
"typings": "./declarations/libs/ui/src/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@material-ui/core": "4.9.10",
|
|
21
21
|
"@material-ui/icons": "4.9.1",
|
|
22
|
-
"react": "
|
|
22
|
+
"react": "17.0.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "~4.1.4"
|
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,22 @@ 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 | string
|
|
28
|
+
selectMargin?: number | string
|
|
29
|
+
paperMaxHeight?: number | string
|
|
30
|
+
error?: boolean
|
|
31
|
+
hasLabel?: boolean
|
|
32
|
+
hasShrink?: boolean
|
|
33
|
+
disabled?: boolean
|
|
34
|
+
}
|
|
@@ -10,7 +10,7 @@ const classes = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface StyledMenuItemProps {
|
|
13
|
-
width: number |
|
|
13
|
+
width: number | string
|
|
14
14
|
theme?: Theme
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -20,13 +20,16 @@ const StyledMenuItem = styled(({ width: _width, ...props }) => (
|
|
|
20
20
|
width: width,
|
|
21
21
|
whiteSpace: 'unset',
|
|
22
22
|
color: theme.palette.text.primary,
|
|
23
|
-
[
|
|
23
|
+
[`&.${classes.menuItemSelected}`]: {
|
|
24
24
|
backgroundColor: theme.palette.grey[300],
|
|
25
|
+
['&:hover']: {
|
|
26
|
+
backgroundColor: theme.palette.grey[200],
|
|
27
|
+
},
|
|
25
28
|
},
|
|
26
29
|
}))
|
|
27
30
|
|
|
28
31
|
export interface SelectMenuItemProps extends MenuItemProps {
|
|
29
|
-
width: number |
|
|
32
|
+
width: number | string
|
|
30
33
|
value?: any
|
|
31
34
|
disabled?: boolean
|
|
32
35
|
}
|