@junyiacademy/ui-test 0.0.8 → 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.
@@ -0,0 +1,8 @@
1
+ export { default as TopicFilter } from './lib/TopicFilter';
2
+ export { default as SelectMenuItem } from './lib/menu-item/SelectMenuItem';
3
+ export { default as OutlinedSelect } from './lib/select/OutlinedSelect';
4
+ export { default as Button } from './lib/button/Button';
5
+ export { default as ButtonGroup } from './lib/button-group/ButtonGroup';
6
+ export { default as Radio } from './lib/radio/Radio';
7
+ export { default as TextField } from './lib/text-field/TextField';
8
+ export { default as StandardSelect } from './lib/select/StandardSelect';
@@ -0,0 +1,8 @@
1
+ export interface ITopicTreeNode {
2
+ childTopics: ITopicTreeNode[];
3
+ id: string;
4
+ isContentTopic: boolean;
5
+ key: string;
6
+ tags: string[];
7
+ title: string;
8
+ }
@@ -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
+ declare const TopicFilter: ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }: TopicFilterProps) => JSX.Element;
13
+ export default TopicFilter;
@@ -0,0 +1,6 @@
1
+ import { ButtonProps as MuiButtonProps } from '@material-ui/core';
2
+ export interface ButtonProps extends MuiButtonProps {
3
+ active?: boolean;
4
+ }
5
+ export declare const Button: ({ active, children, ...otherProps }: ButtonProps) => JSX.Element;
6
+ export default Button;
@@ -0,0 +1,3 @@
1
+ import { ButtonGroupProps as MuiButtonGroupProps } from '@material-ui/core';
2
+ export declare const ButtonGroup: ({ children, ...otherProps }: MuiButtonGroupProps) => JSX.Element;
3
+ export default ButtonGroup;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { MenuItemProps } from '@material-ui/core';
3
+ export interface SelectMenuItemProps extends MenuItemProps {
4
+ width: number | 'auto';
5
+ value?: any;
6
+ disabled?: boolean;
7
+ }
8
+ declare const SelectMenuItem: React.ForwardRefExoticComponent<Pick<React.PropsWithChildren<SelectMenuItemProps>, "button" | "slot" | "style" | "title" | "color" | "width" | "alignItems" | "translate" | "hidden" | "dense" | "disabled" | "classes" | "className" | "children" | "placeholder" | "value" | "innerRef" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "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" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "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" | "selected" | "ContainerComponent" | "ContainerProps" | "disableGutters" | "divider" | "focusVisibleClassName"> & React.RefAttributes<HTMLLIElement>>;
9
+ export default SelectMenuItem;
@@ -0,0 +1,10 @@
1
+ import { RadioProps as MuiRadioProps, FormControlLabelProps } from '@material-ui/core';
2
+ export interface RadioProps extends FormControlLabelProps {
3
+ color?: 'primary' | 'secondary' | 'default';
4
+ size?: 'medium' | 'small';
5
+ caption?: string;
6
+ formControlLabelProps?: Partial<FormControlLabelProps>;
7
+ radioProps?: Partial<MuiRadioProps>;
8
+ }
9
+ export declare const Radio: ({ checked, disabled, label, labelPlacement, value, formControlLabelProps, radioProps, color, size, caption, }: RadioProps) => JSX.Element;
10
+ export default Radio;
@@ -0,0 +1,22 @@
1
+ import React, { ChangeEvent } from 'react';
2
+ import { SelectProps, OutlinedInputProps } from '@material-ui/core';
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;
22
+ export default OutlinedSelect;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { SelectProps, InputProps } from '@material-ui/core';
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;
19
+ export default StandardSelect;
@@ -0,0 +1,3 @@
1
+ import { TextFieldProps } from '@material-ui/core';
2
+ export declare const TextField: (props: TextFieldProps) => JSX.Element;
3
+ export default TextField;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StandardSelect = exports.TextField = exports.Radio = exports.ButtonGroup = exports.Button = exports.OutlinedSelect = exports.SelectMenuItem = exports.TopicFilter = void 0;
7
+ var TopicFilter_1 = require("./lib/TopicFilter");
8
+ Object.defineProperty(exports, "TopicFilter", { enumerable: true, get: function () { return __importDefault(TopicFilter_1).default; } });
9
+ var SelectMenuItem_1 = require("./lib/menu-item/SelectMenuItem");
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
+ var Button_1 = require("./lib/button/Button");
14
+ Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return __importDefault(Button_1).default; } });
15
+ var ButtonGroup_1 = require("./lib/button-group/ButtonGroup");
16
+ Object.defineProperty(exports, "ButtonGroup", { enumerable: true, get: function () { return __importDefault(ButtonGroup_1).default; } });
17
+ var Radio_1 = require("./lib/radio/Radio");
18
+ Object.defineProperty(exports, "Radio", { enumerable: true, get: function () { return __importDefault(Radio_1).default; } });
19
+ var TextField_1 = require("./lib/text-field/TextField");
20
+ Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return __importDefault(TextField_1).default; } });
21
+ var StandardSelect_1 = require("./lib/select/StandardSelect");
22
+ Object.defineProperty(exports, "StandardSelect", { enumerable: true, get: function () { return __importDefault(StandardSelect_1).default; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const styles_1 = require("@material-ui/core/styles");
6
+ const ArrowRightRounded_1 = tslib_1.__importDefault(require("@material-ui/icons/ArrowRightRounded"));
7
+ const OutlinedSelect_1 = tslib_1.__importDefault(require("./select/OutlinedSelect"));
8
+ const SelectMenuItem_1 = tslib_1.__importDefault(require("./menu-item/SelectMenuItem"));
9
+ // self-defined-configs
10
+ const PLACEHOLDER = '請選擇';
11
+ // self-defined-components
12
+ const PREFIX = 'JuiTopicFilter';
13
+ const FiltersWrapper = styles_1.styled('div')({
14
+ display: 'flex',
15
+ alignItems: 'center',
16
+ flexWrap: 'wrap',
17
+ });
18
+ const SelectWrapper = styles_1.styled('div')({
19
+ display: 'flex',
20
+ alignItems: 'center',
21
+ });
22
+ const StyledArrowRightRoundedIcon = styles_1.styled(ArrowRightRounded_1.default)(({ theme }) => ({
23
+ margin: theme.spacing(-1, -1.5),
24
+ fontSize: theme.spacing(7),
25
+ color: '#444',
26
+ }));
27
+ const TopicFilter = ({ topicTree, onTopicSelected, isLastLayer, hasArrow, initSelectedTopicIds, }) => {
28
+ const [selectedTopicIds, setSelectedTopicIds] = react_1.useState([]);
29
+ const [layeredTopicList, setLayeredTopicList] = react_1.useState([]);
30
+ const [isFocusedList, setIsFocusedList] = react_1.useState([]);
31
+ const initSelectedLayers = () => {
32
+ const newLayeredTopicList = initSelectedTopicIds.reduce((topicListAccumulator, topicId, index) => {
33
+ var _a, _b;
34
+ 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);
35
+ if (!selectedTopic) {
36
+ return topicListAccumulator;
37
+ }
38
+ if (isLastLayer(selectedTopic)) {
39
+ return topicListAccumulator;
40
+ }
41
+ return [...topicListAccumulator, selectedTopic];
42
+ }, [topicTree]);
43
+ setLayeredTopicList(newLayeredTopicList);
44
+ setSelectedTopicIds(initSelectedTopicIds.slice(0, newLayeredTopicList.length));
45
+ setIsFocusedList(Array(newLayeredTopicList.length).fill(false));
46
+ };
47
+ const handleChange = (e, layerNumber, layeredTopic) => {
48
+ const selectedTopic = layeredTopic.childTopics.find((childTopic) => childTopic.id === e.target.value);
49
+ const newSelectedTopicIds = [
50
+ ...selectedTopicIds.slice(0, layerNumber),
51
+ selectedTopic.id,
52
+ ];
53
+ setSelectedTopicIds(newSelectedTopicIds);
54
+ onTopicSelected(selectedTopic, {
55
+ layerNumber,
56
+ selectedTopicIds: newSelectedTopicIds,
57
+ });
58
+ if (isLastLayer(selectedTopic)) {
59
+ setLayeredTopicList((prevTopicList) => prevTopicList.slice(0, layerNumber + 1));
60
+ setIsFocusedList((prevList) => prevList.slice(0, layerNumber + 1));
61
+ }
62
+ else {
63
+ setLayeredTopicList((prevTopicList) => [
64
+ ...prevTopicList.slice(0, layerNumber + 1),
65
+ selectedTopic,
66
+ ]);
67
+ setIsFocusedList((prevList) => [
68
+ ...prevList.slice(0, layerNumber + 1),
69
+ false,
70
+ ]);
71
+ }
72
+ };
73
+ react_1.useEffect(() => {
74
+ if (!topicTree || Object.keys(topicTree).length === 0) {
75
+ return;
76
+ }
77
+ if (initSelectedTopicIds.length !== 0) {
78
+ initSelectedLayers();
79
+ return;
80
+ }
81
+ setLayeredTopicList([topicTree]);
82
+ }, [topicTree]);
83
+ if (layeredTopicList.length === 0) {
84
+ return (react_1.default.createElement(OutlinedSelect_1.default, { size: 'small', width: 220, placeholder: '\u8F09\u5165\u8CC7\u6599\u4E2D...', disabled: true }));
85
+ }
86
+ return (react_1.default.createElement(FiltersWrapper, null, layeredTopicList.map((layeredTopic, layerNumber) => {
87
+ const hasLabel = isFocusedList[layerNumber] || !selectedTopicIds[layerNumber];
88
+ return (react_1.default.createElement(SelectWrapper, { key: layeredTopic.id },
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
+ 'data-testid': `layered-topic-${layerNumber}`,
91
+ }, OutlinedInputProps: {
92
+ inputProps: {
93
+ 'aria-label': `layered-topic-${layerNumber}`,
94
+ },
95
+ onChange: (e) => {
96
+ handleChange(e, layerNumber, layeredTopic);
97
+ },
98
+ onFocus: () => {
99
+ setIsFocusedList((prevList) => {
100
+ const newList = [...prevList];
101
+ newList[layerNumber] = true;
102
+ return newList;
103
+ });
104
+ },
105
+ onBlur: () => {
106
+ setIsFocusedList((prevList) => {
107
+ const newList = [...prevList];
108
+ newList[layerNumber] = false;
109
+ return newList;
110
+ });
111
+ },
112
+ } },
113
+ react_1.default.createElement(SelectMenuItem_1.default, { width: 220, disabled: true }, PLACEHOLDER),
114
+ 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)))),
115
+ hasArrow && layerNumber !== layeredTopicList.length - 1 && (react_1.default.createElement(StyledArrowRightRoundedIcon, { fontSize: 'large', "data-testid": 'topic-filter-arrow' }))));
116
+ })));
117
+ };
118
+ exports.default = TopicFilter;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Button = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const styles_1 = require("@material-ui/core/styles");
7
+ const core_1 = require("@material-ui/core");
8
+ // self-defined-components
9
+ const PREFIX = 'JuiButton';
10
+ const classes = {
11
+ outlinedPrimary: `${PREFIX}-outlinedPrimary`,
12
+ outlinedSecondary: `${PREFIX}-outlinedSecondary`,
13
+ textPrimary: `${PREFIX}-textPrimary`,
14
+ textSecondary: `${PREFIX}-textSecondary`,
15
+ disabled: `${PREFIX}-disabled`,
16
+ };
17
+ const StyledButton = styles_1.styled((_a) => {
18
+ var { active: _active } = _a, other = tslib_1.__rest(_a, ["active"]);
19
+ return (react_1.default.createElement(core_1.Button, Object.assign({ classes: classes }, other)));
20
+ })(({ active, theme }) => ({
21
+ [`&.${classes.outlinedPrimary}`]: {
22
+ backgroundColor: active
23
+ ? theme.palette.primary.main
24
+ : theme.palette.common.white,
25
+ color: active ? theme.palette.common.white : theme.palette.primary.main,
26
+ borderColor: theme.palette.primary.main,
27
+ '&:hover': {
28
+ backgroundColor: active
29
+ ? theme.palette.primary.main
30
+ : styles_1.fade(theme.palette.primary.main, 0.1),
31
+ },
32
+ [`&.${classes.disabled}`]: {
33
+ backgroundColor: theme.palette.common.white,
34
+ borderColor: theme.palette.action.disabledBackground,
35
+ color: theme.palette.action.disabled,
36
+ },
37
+ },
38
+ [`&.${classes.outlinedSecondary}`]: {
39
+ backgroundColor: active
40
+ ? theme.palette.secondary.main
41
+ : theme.palette.common.white,
42
+ color: active ? theme.palette.common.white : theme.palette.secondary.main,
43
+ borderColor: theme.palette.secondary.main,
44
+ '&:hover': {
45
+ backgroundColor: active
46
+ ? theme.palette.secondary.main
47
+ : styles_1.fade(theme.palette.secondary.main, 0.1),
48
+ },
49
+ [`&.${classes.disabled}`]: {
50
+ backgroundColor: theme.palette.common.white,
51
+ borderColor: theme.palette.action.disabledBackground,
52
+ color: theme.palette.action.disabled,
53
+ },
54
+ },
55
+ [`&.${classes.textPrimary}`]: {
56
+ '&:hover': {
57
+ backgroundColor: styles_1.fade(theme.palette.primary.main, 0.1),
58
+ },
59
+ },
60
+ [`&.${classes.textSecondary}`]: {
61
+ '&:hover': {
62
+ backgroundColor: styles_1.fade(theme.palette.secondary.main, 0.1),
63
+ },
64
+ },
65
+ }));
66
+ const Button = (_a) => {
67
+ var { active, children } = _a, otherProps = tslib_1.__rest(_a, ["active", "children"]);
68
+ return (react_1.default.createElement(StyledButton, Object.assign({ active: active }, otherProps), children));
69
+ };
70
+ exports.Button = Button;
71
+ exports.default = exports.Button;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ButtonGroup = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const styles_1 = require("@material-ui/core/styles");
7
+ const core_1 = require("@material-ui/core");
8
+ const PREFIX = 'JuiButtonGroup';
9
+ const classes = {
10
+ grouped: `${PREFIX}-grouped`,
11
+ groupedOutlinedPrimary: `${PREFIX}-groupedOutlinedPrimary`,
12
+ groupedOutlinedSecondary: `${PREFIX}-groupedOutlinedSecondary`,
13
+ disabled: `${PREFIX}-disabled`,
14
+ };
15
+ const StyledButtonGroup = styles_1.styled((_a) => {
16
+ var props = tslib_1.__rest(_a, []);
17
+ return (react_1.default.createElement(core_1.ButtonGroup, Object.assign({ classes: classes }, props)));
18
+ })(({ theme }) => ({
19
+ [`& .${classes.groupedOutlinedPrimary}.${classes.grouped}.${classes.disabled}`]: {
20
+ borderColor: styles_1.fade(theme.palette.primary.main, 0.5),
21
+ color: styles_1.fade(theme.palette.primary.main, 0.5),
22
+ },
23
+ [`& .${classes.groupedOutlinedSecondary}.${classes.grouped}.${classes.disabled}`]: {
24
+ borderColor: styles_1.fade(theme.palette.secondary.main, 0.5),
25
+ color: styles_1.fade(theme.palette.secondary.main, 0.5),
26
+ },
27
+ }));
28
+ const ButtonGroup = (_a) => {
29
+ var { children } = _a, otherProps = tslib_1.__rest(_a, ["children"]);
30
+ return (react_1.default.createElement(StyledButtonGroup, Object.assign({}, otherProps), children));
31
+ };
32
+ exports.ButtonGroup = ButtonGroup;
33
+ exports.default = exports.ButtonGroup;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importDefault(require("react"));
5
+ const styles_1 = require("@material-ui/core/styles");
6
+ const core_1 = require("@material-ui/core");
7
+ // self-defined-components
8
+ const PREFIX = 'JuiSelectMenuItem';
9
+ const classes = {
10
+ menuItemSelected: `${PREFIX}-menuItemSelected`,
11
+ };
12
+ const StyledMenuItem = styles_1.styled((_a) => {
13
+ var { width: _width } = _a, props = tslib_1.__rest(_a, ["width"]);
14
+ return (react_1.default.createElement(core_1.MenuItem, Object.assign({ classes: { selected: classes.menuItemSelected } }, props)));
15
+ })(({ width, theme }) => ({
16
+ width: width,
17
+ whiteSpace: 'unset',
18
+ color: theme.palette.text.primary,
19
+ [`& .${classes.menuItemSelected}`]: {
20
+ backgroundColor: theme.palette.grey[300],
21
+ },
22
+ }));
23
+ const SelectMenuItem = react_1.default.forwardRef((_a, ref) => {
24
+ var { width, children, value = '' } = _a, otherProps = tslib_1.__rest(_a, ["width", "children", "value"]);
25
+ return (react_1.default.createElement(StyledMenuItem, Object.assign({ width: width, innerRef: ref, value: value }, otherProps), children));
26
+ });
27
+ exports.default = SelectMenuItem;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Radio = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const styles_1 = require("@material-ui/core/styles");
7
+ const core_1 = require("@material-ui/core");
8
+ const PREFIX = 'JuiRadio';
9
+ const classes = {
10
+ formControlLabel: `${PREFIX}-formControl-label`,
11
+ formControlDisabled: `${PREFIX}-formControl-disabled`,
12
+ radioChecked: `${PREFIX}-radio-checked`,
13
+ };
14
+ const StyledFormControlLabel = styles_1.styled((props) => (react_1.default.createElement(core_1.FormControlLabel, Object.assign({ classes: {
15
+ label: classes.formControlLabel,
16
+ disabled: classes.formControlDisabled,
17
+ } }, props))))(({ theme }) => ({
18
+ [`& .${classes.formControlLabel}`]: {
19
+ color: theme.palette.text.secondary,
20
+ [`&.${classes.formControlDisabled}`]: {
21
+ color: theme.palette.text.disabled,
22
+ },
23
+ },
24
+ [`& .${classes.radioChecked} + .${classes.formControlLabel}`]: {
25
+ color: theme.palette.text.primary,
26
+ },
27
+ }));
28
+ const StyledRadio = styles_1.styled((props) => (react_1.default.createElement(core_1.Radio, Object.assign({ classes: {
29
+ checked: classes.radioChecked,
30
+ } }, props))))(({ theme }) => ({
31
+ color: theme.palette.text.primary,
32
+ }));
33
+ const StyledTypography = styles_1.styled(core_1.Typography)(({ theme }) => ({
34
+ color: theme.palette.text.disabled,
35
+ margin: '0 0 0 30px',
36
+ }));
37
+ const Radio = ({ checked, disabled, label, labelPlacement, value, formControlLabelProps, radioProps, color = 'secondary', size = 'medium', caption = '', }) => {
38
+ return (react_1.default.createElement(react_1.default.Fragment, null,
39
+ react_1.default.createElement(StyledFormControlLabel, Object.assign({ control: react_1.default.createElement(StyledRadio, Object.assign({ color: color, size: size }, radioProps)), checked: checked, disabled: disabled, label: label, labelPlacement: labelPlacement, value: value }, formControlLabelProps)),
40
+ caption && (react_1.default.createElement(StyledTypography, { variant: 'body2' }, caption))));
41
+ };
42
+ exports.Radio = Radio;
43
+ exports.default = exports.Radio;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importDefault(require("react"));
5
+ const styles_1 = require("@material-ui/core/styles");
6
+ const core_1 = require("@material-ui/core");
7
+ // self-defined-components
8
+ const PREFIX = 'JuiOutlinedSelect';
9
+ const classes = {
10
+ inputLabelFocused: `${PREFIX}-inputLabelFocused`,
11
+ inputLabelOutlined: `${PREFIX}-inputLabelOutlined`,
12
+ inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
13
+ inputLabelShrink: `${PREFIX}-inputLabelShrink`,
14
+ inputLabelError: `${PREFIX}-inputLabelError`,
15
+ inputLabelDisabled: `${PREFIX}-inputLabelDisabled`,
16
+ outlineInputInput: `${PREFIX}-input`,
17
+ outlineInputInputMarginDense: `${PREFIX}-inputMarginDense`,
18
+ outlineInputNotchedOutline: `${PREFIX}-notchedOutline`,
19
+ outlineInputDisabled: `${PREFIX}-inputDisabled`,
20
+ outlineInputError: `${PREFIX}-outlinedInputError`,
21
+ selectPaper: `${PREFIX}-menuPaper`,
22
+ };
23
+ 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
+ margin: theme.spacing(1),
28
+ width: width,
29
+ backgroundColor: 'white',
30
+ '&:hover': {
31
+ [`& :not(.${classes.outlineInputDisabled}):not(.${classes.outlineInputError}) .${classes.outlineInputNotchedOutline}`]: {
32
+ borderColor: theme.palette[color].main,
33
+ },
34
+ },
35
+ }));
36
+ const StyledInputLabel = styles_1.styled((_a) => {
37
+ var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
38
+ return (react_1.default.createElement(core_1.InputLabel, Object.assign({ classes: {
39
+ outlined: classes.inputLabelOutlined,
40
+ marginDense: classes.inputLabelMarginDense,
41
+ shrink: classes.inputLabelShrink,
42
+ focused: classes.inputLabelFocused,
43
+ disabled: classes.inputLabelDisabled,
44
+ error: classes.inputLabelError,
45
+ } }, props)));
46
+ })(({ color, theme }) => ({
47
+ color: theme.palette.text.secondary,
48
+ [`&.${classes.inputLabelOutlined}`]: {
49
+ [`&:not(.${classes.inputLabelDisabled}) .${classes.inputLabelFocused}`]: {
50
+ color: theme.palette.action.active,
51
+ },
52
+ [`&.${classes.inputLabelMarginDense}:not(.${classes.inputLabelShrink})`]: {
53
+ transform: 'translate(12px, 16px) scale(1)',
54
+ },
55
+ },
56
+ [`&.${classes.inputLabelShrink}:not(.${classes.inputLabelError}):not(.${classes.inputLabelDisabled}).${classes.inputLabelFocused}`]: {
57
+ color: theme.palette[color].main,
58
+ },
59
+ [`&.${classes.inputLabelShrink}`]: {
60
+ backgroundColor: '#ffffff',
61
+ padding: '0 2px',
62
+ },
63
+ }));
64
+ const StyledOutlinedInput = styles_1.styled((props) => (react_1.default.createElement(core_1.OutlinedInput, Object.assign({ classes: {
65
+ input: classes.outlineInputInput,
66
+ inputMarginDense: classes.outlineInputInputMarginDense,
67
+ notchedOutline: classes.outlineInputNotchedOutline,
68
+ disabled: classes.outlineInputDisabled,
69
+ error: classes.outlineInputError,
70
+ } }, props))))(({ theme }) => ({
71
+ [`& .${classes.outlineInputInput}`]: {
72
+ color: theme.palette.text.primary,
73
+ },
74
+ [`& .${classes.outlineInputInputMarginDense}`]: {
75
+ padding: '14.5px 15px 14.5px 12px',
76
+ },
77
+ }));
78
+ const StyledSelect = styles_1.styled((_a) => {
79
+ var { paperMaxHeight: _paperMaxHeight, hasAdornment: _hasAdornment, className } = _a, props = tslib_1.__rest(_a, ["paperMaxHeight", "hasAdornment", "className"]);
80
+ return (react_1.default.createElement(core_1.Select, Object.assign({ MenuProps: {
81
+ disableAutoFocusItem: true,
82
+ anchorOrigin: {
83
+ vertical: 2,
84
+ horizontal: 'left',
85
+ },
86
+ transformOrigin: {
87
+ vertical: 'top',
88
+ horizontal: 'left',
89
+ },
90
+ getContentAnchorEl: null,
91
+ classes: { paper: className },
92
+ } }, props)));
93
+ })(({ hasAdornment, paperMaxHeight }) => ({
94
+ '&&': {
95
+ maxHeight: paperMaxHeight,
96
+ left: hasAdornment ? '24px !important' : '70px',
97
+ },
98
+ }));
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, }) => {
100
+ const hasAdornment = !!(OutlinedInputProps === null || OutlinedInputProps === void 0 ? void 0 : OutlinedInputProps.startAdornment);
101
+ const hasHelperText = !!helperText;
102
+ return (react_1.default.createElement(StyledFormControl, { size: size, width: width, disabled: disabled, error: error, color: color },
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),
105
+ hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
106
+ };
107
+ exports.default = OutlinedSelect;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StandardSelect = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const styles_1 = require("@material-ui/core/styles");
7
+ const core_1 = require("@material-ui/core");
8
+ // self-defined-components
9
+ const PREFIX = 'JuiStandardSelect';
10
+ const classes = {
11
+ inputLabelFocused: `${PREFIX}-inputLabelFocused`,
12
+ inputLabelMarginDense: `${PREFIX}-inputLabelMarginDense`,
13
+ inputLabelError: `${PREFIX}-inputLabelError`,
14
+ inputUnderline: `${PREFIX}-inputUnderline`,
15
+ inputError: `${PREFIX}-inputError`,
16
+ inputDisabled: `${PREFIX}-inputDisabled`,
17
+ inputAdornmentRoot: `${PREFIX}-inputAdornmentRoot`,
18
+ selectPaper: `${PREFIX}-menuPaper`,
19
+ selectDisabled: `${PREFIX}-selectDisabled`,
20
+ };
21
+ const StyledFormControl = styles_1.styled((_a) => {
22
+ var { width: _width } = _a, props = tslib_1.__rest(_a, ["width"]);
23
+ return (react_1.default.createElement(core_1.FormControl, Object.assign({}, props)));
24
+ })(({ width, theme }) => ({
25
+ width,
26
+ margin: theme.spacing(0, 4, 4, 4),
27
+ }));
28
+ const StyledInputLabel = styles_1.styled((_a) => {
29
+ var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
30
+ return (react_1.default.createElement(core_1.InputLabel, Object.assign({ classes: {
31
+ focused: classes.inputLabelFocused,
32
+ error: classes.inputLabelError,
33
+ } }, props)));
34
+ })(({ color, theme }) => ({
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,
42
+ },
43
+ }));
44
+ const StyledSelect = styles_1.styled((_a) => {
45
+ var { paperMaxHeight: _selectPaperHeight, hasAdornment: _hasAdornment, className } = _a, props = tslib_1.__rest(_a, ["paperMaxHeight", "hasAdornment", "className"]);
46
+ return (react_1.default.createElement(core_1.Select, Object.assign({ MenuProps: {
47
+ classes: { paper: className },
48
+ transformOrigin: {
49
+ vertical: 'top',
50
+ horizontal: 'left',
51
+ },
52
+ getContentAnchorEl: null,
53
+ } }, props)));
54
+ })(({ hasAdornment, paperMaxHeight }) => ({
55
+ '&&': {
56
+ maxHeight: paperMaxHeight,
57
+ left: hasAdornment ? '48px !important' : '70px',
58
+ },
59
+ [`&.${classes.selectDisabled}`]: {},
60
+ }));
61
+ const StyledInput = styles_1.styled((_a) => {
62
+ var { color: _color } = _a, props = tslib_1.__rest(_a, ["color"]);
63
+ return (react_1.default.createElement(core_1.Input, Object.assign({ classes: {
64
+ disabled: classes.inputDisabled,
65
+ underline: classes.inputUnderline,
66
+ error: classes.inputError,
67
+ } }, props)));
68
+ })(({ color, theme }) => ({
69
+ color: theme.palette.text.primary,
70
+ [`&.${classes.inputUnderline}:not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
71
+ [`&:after,&:hover:before`]: {
72
+ borderBottomColor: theme.palette[color].main,
73
+ },
74
+ },
75
+ [`&.${classes.inputUnderline}.${classes.inputError}:not(.${classes.inputDisabled})`]: {
76
+ [`&:after,&:hover:before`]: {
77
+ borderBottomColor: theme.palette.error.main,
78
+ },
79
+ },
80
+ }));
81
+ function StandardSelect({ color = 'primary', size = 'medium', width = 'auto', paperMaxHeight = 'auto', error = false, hasShrink = false, placeholder, helperText, InputProps, value = '', SelectProps, disabled = false, children, }) {
82
+ const hasAdornment = !!(InputProps === null || InputProps === void 0 ? void 0 : InputProps.startAdornment);
83
+ const hasHelperText = !!helperText;
84
+ return (react_1.default.createElement(StyledFormControl, { color: color, size: size, width: width, disabled: disabled, error: error },
85
+ hasShrink ? (react_1.default.createElement(StyledInputLabel, { color: color, shrink: true }, placeholder)) : (react_1.default.createElement(StyledInputLabel, { color: color }, placeholder)),
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),
87
+ hasHelperText && react_1.default.createElement(core_1.FormHelperText, null, helperText)));
88
+ }
89
+ exports.StandardSelect = StandardSelect;
90
+ exports.default = StandardSelect;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextField = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const styles_1 = require("@material-ui/core/styles");
7
+ const core_1 = require("@material-ui/core");
8
+ // self-defined-components
9
+ const PREFIX = 'JuiTextField';
10
+ const classes = {
11
+ inputLabelError: `${PREFIX}-inputLabel-error`,
12
+ inputLabelDisabled: `${PREFIX}-inputLabel-disabled`,
13
+ inputLabelShrink: `${PREFIX}-inputLabel-shrink`,
14
+ inputLabelFocused: `${PREFIX}-inputLabel-focused`,
15
+ inputNotchedOutline: `${PREFIX}-input-notchedOutline`,
16
+ inputUnderline: `${PREFIX}-input-underline`,
17
+ inputColorSecondary: `${PREFIX}-input-colorSecondary`,
18
+ inputDisabled: `${PREFIX}-input-disabled`,
19
+ inputError: `${PREFIX}-input-error`,
20
+ inputFocused: `${PREFIX}-input-focused`,
21
+ };
22
+ const StyledTextField = styles_1.styled((_a) => {
23
+ var { hasEndAdornment, InputLabelProps, InputProps } = _a, otherProps = tslib_1.__rest(_a, ["hasEndAdornment", "InputLabelProps", "InputProps"]);
24
+ return (react_1.default.createElement(core_1.TextField, Object.assign({ InputLabelProps: Object.assign(Object.assign({}, InputLabelProps), { classes: {
25
+ error: classes.inputLabelError,
26
+ disabled: classes.inputLabelDisabled,
27
+ shrink: classes.inputLabelShrink,
28
+ focused: classes.inputLabelFocused,
29
+ }, shrink: hasEndAdornment ? true : undefined }), InputProps: Object.assign(Object.assign({}, InputProps), { classes: Object.assign({ colorSecondary: classes.inputColorSecondary, disabled: classes.inputDisabled, error: classes.inputError, focused: classes.inputFocused }, ((otherProps === null || otherProps === void 0 ? void 0 : otherProps.variant) === 'outlined'
30
+ ? { notchedOutline: classes.inputNotchedOutline }
31
+ : { underline: classes.inputUnderline })) }) }, otherProps)));
32
+ })(({ theme }) => ({
33
+ [`& .${classes.inputLabelError}`]: {
34
+ [`&:not(.${classes.inputLabelShrink})`]: {
35
+ color: theme.palette.text.secondary,
36
+ },
37
+ [`&.${classes.inputLabelDisabled}`]: {
38
+ color: theme.palette.text.disabled,
39
+ },
40
+ },
41
+ [`& .${classes.inputLabelError}.${classes.inputLabelFocused}`]: {
42
+ color: theme.palette.error.main,
43
+ },
44
+ // For variant: standard | filled
45
+ [`& .${classes.inputUnderline}:not(.${classes.inputDisabled})`]: {
46
+ [`&:hover:before`]: {
47
+ borderColor: theme.palette.primary.main,
48
+ },
49
+ [`&.${classes.inputColorSecondary}:hover:before`]: {
50
+ borderColor: theme.palette.secondary.main,
51
+ },
52
+ },
53
+ // For variant: outlined
54
+ [`& .${classes.inputDisabled} .${classes.inputNotchedOutline}`]: {
55
+ borderStyle: 'dotted',
56
+ },
57
+ [`& .${classes.inputError}.${classes.inputFocused} .${classes.inputNotchedOutline}`]: {
58
+ borderColor: theme.palette.error.main,
59
+ },
60
+ [`& :not(.${classes.inputDisabled}):not(.${classes.inputError})`]: {
61
+ [`&:hover .${classes.inputNotchedOutline}`]: {
62
+ borderColor: theme.palette.primary.main,
63
+ },
64
+ [`&.${classes.inputColorSecondary}:hover .${classes.inputNotchedOutline}`]: {
65
+ borderColor: theme.palette.secondary.main,
66
+ },
67
+ },
68
+ }));
69
+ const TextField = (props) => {
70
+ var _a;
71
+ const hasEndAdornment = !!((_a = props === null || props === void 0 ? void 0 : props.InputProps) === null || _a === void 0 ? void 0 : _a.endAdornment);
72
+ return react_1.default.createElement(StyledTextField, Object.assign({ hasEndAdornment: hasEndAdornment }, props));
73
+ };
74
+ exports.TextField = TextField;
75
+ exports.default = exports.TextField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junyiacademy/ui-test",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
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",