@team-monolith/cds 1.38.4 → 1.38.5

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.
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
13
  /** @jsxImportSource @emotion/react */
3
14
  import { forwardRef, useRef, useState } from "react";
@@ -7,7 +18,7 @@ import { DropdownMenu } from "./DropdownMenu";
7
18
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?type=design&node-id=203-95329&t=FwczLZ1IVvskUVbT-0)
8
19
  */
9
20
  const Dropdown = forwardRef((props, ref) => {
10
- const { className, component: Component = "div", disabled, color = "primary", size = "medium", bold, startIcon, endIcon = _jsx(ArrowDropDownFillIcon, {}), buttonCss, label, onClick, menuProps = {}, children, closeOnItemClick, } = props;
21
+ const { className, component: Component = "div", disabled, color = "primary", size = "medium", bold, startIcon, endIcon = _jsx(ArrowDropDownFillIcon, {}), buttonCss, label, onClick, menuProps = {}, children, closeOnItemClick } = props, other = __rest(props, ["className", "component", "disabled", "color", "size", "bold", "startIcon", "endIcon", "buttonCss", "label", "onClick", "menuProps", "children", "closeOnItemClick"]);
11
22
  const buttonProps = {
12
23
  disabled,
13
24
  color,
@@ -16,16 +27,19 @@ const Dropdown = forwardRef((props, ref) => {
16
27
  endIcon,
17
28
  };
18
29
  const menuRef = useRef(null);
30
+ const isControlled = menuProps.open !== undefined;
19
31
  const [open, setOpen] = useState(false);
20
32
  const [itemState, setItemState] = useState(new Map());
21
33
  const handleClick = (e) => {
22
34
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
23
- setOpen(true);
35
+ if (!isControlled)
36
+ setOpen(true);
24
37
  };
25
38
  const handleClose = (e) => {
26
39
  var _a;
27
40
  e.stopPropagation();
28
- setOpen(false);
41
+ if (!isControlled)
42
+ setOpen(false);
29
43
  setItemState((prevState) => {
30
44
  const newState = new Map(prevState);
31
45
  newState.forEach((value, key) => {
@@ -38,6 +52,6 @@ const Dropdown = forwardRef((props, ref) => {
38
52
  });
39
53
  (_a = menuProps === null || menuProps === void 0 ? void 0 : menuProps.onClose) === null || _a === void 0 ? void 0 : _a.call(menuProps, e);
40
54
  };
41
- return (_jsxs(Component, Object.assign({ className: className, ref: ref }, { children: [_jsx(Button, Object.assign({ css: buttonCss, ref: menuRef }, buttonProps, { label: label, bold: bold, onClick: handleClick, fullWidth: true })), _jsx(DropdownMenu, Object.assign({}, menuProps, { open: open, onClose: handleClose, anchorEl: menuRef.current, closeOnItemClick: closeOnItemClick, itemState: itemState, setItemState: setItemState }, { children: children }))] })));
55
+ return (_jsxs(Component, Object.assign({ className: className }, other, { ref: ref }, { children: [_jsx(Button, Object.assign({ css: buttonCss, ref: menuRef }, buttonProps, { label: label, bold: bold, onClick: handleClick, fullWidth: true })), _jsx(DropdownMenu, Object.assign({}, menuProps, { open: isControlled ? menuProps.open : open, onClose: handleClose, anchorEl: menuRef.current, closeOnItemClick: closeOnItemClick, itemState: itemState, setItemState: setItemState }, { children: children }))] })));
42
56
  });
43
57
  export { Dropdown };
@@ -31,6 +31,7 @@ export default function TextInput(props) {
31
31
  color: ${theme.color.foreground.danger};
32
32
  &::placeholder {
33
33
  // inputComponent의 placeholder 스타일을 덮어쓰기 위해 부득이하게 !important 사용
34
+ // TODO: static classname을 사용하여 !important 제거
34
35
  color: ${theme.color.foreground.dangerDisabled} !important;
35
36
  }
36
37
  `
@@ -1,10 +1,13 @@
1
1
  import React from "react";
2
2
  import { ImageProps } from "../ProblemSelectNode";
3
+ export type SelectBoxType = "primary" | "success" | "danger";
3
4
  /** 비지니스 로직과 무관한 SelectBox를 그리는 공통 컴포넌트입니다. */
4
5
  export declare function SelectBoxComponent(props: {
5
6
  className?: string;
6
7
  indexClassName?: string;
7
8
  contentClassName?: string;
9
+ /** SelectBox의 스타일 타입. 전달하지 않으면 기본 스타일이 적용됩니다. */
10
+ type?: SelectBoxType;
8
11
  /** 문제 번호 박스 내부를 그립니다. */
9
12
  index: React.ReactNode;
10
13
  image?: ImageProps | null;
@@ -1,11 +1,46 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { css } from "@emotion/react";
3
+ import { css, useTheme } from "@emotion/react";
4
4
  import styled from "@emotion/styled";
5
+ const TYPE_TO_CONTAINER_STYLE = (theme, type) => ({
6
+ primary: css `
7
+ background: ${theme.color.container.primaryContainer};
8
+ border: 1px solid ${theme.color.foreground.primary};
9
+ color: ${theme.color.container.primaryOnContainer};
10
+ `,
11
+ success: css `
12
+ background: ${theme.color.container.successContainer};
13
+ border: 1px solid ${theme.color.background.successActive};
14
+ color: ${theme.color.container.successOnContainer};
15
+ `,
16
+ danger: css `
17
+ background: ${theme.color.container.dangerContainer};
18
+ border: 1px solid ${theme.color.background.dangerActive};
19
+ color: ${theme.color.container.dangerOnContainer};
20
+ `,
21
+ })[type];
22
+ const TYPE_TO_INDEX_STYLE = (theme, type) => ({
23
+ primary: css `
24
+ background: ${theme.color.background.primary};
25
+ border: 1px solid ${theme.color.background.primary};
26
+ color: ${theme.color.foreground.neutralAlt};
27
+ `,
28
+ success: css `
29
+ background: ${theme.color.background.successActive};
30
+ border: 1px solid ${theme.color.background.successActive};
31
+ color: ${theme.color.foreground.neutralAlt};
32
+ `,
33
+ danger: css `
34
+ background: ${theme.color.background.dangerActive};
35
+ border: 1px solid ${theme.color.background.dangerActive};
36
+ color: ${theme.color.foreground.neutralAlt};
37
+ `,
38
+ })[type];
5
39
  /** 비지니스 로직과 무관한 SelectBox를 그리는 공통 컴포넌트입니다. */
6
40
  export function SelectBoxComponent(props) {
7
- const { className, indexClassName, contentClassName, index, image, text, endIcon, onClick, } = props;
8
- return (_jsxs(Container, Object.assign({ className: className, onClick: onClick }, { children: [_jsx(Index, Object.assign({ className: indexClassName }, { children: index })), _jsxs(Content, Object.assign({ className: contentClassName }, { children: [image && (_jsx("img", { src: image.src, alt: image.altText, css: css `
41
+ const { className, indexClassName, contentClassName, type, index, image, text, endIcon, onClick, } = props;
42
+ const theme = useTheme();
43
+ return (_jsxs(Container, Object.assign({ className: className, css: type ? TYPE_TO_CONTAINER_STYLE(theme, type) : undefined, onClick: onClick }, { children: [_jsx(Index, Object.assign({ className: indexClassName, css: type ? TYPE_TO_INDEX_STYLE(theme, type) : undefined }, { children: index })), _jsxs(Content, Object.assign({ className: contentClassName }, { children: [image && (_jsx("img", { src: image.src, alt: image.altText, css: css `
9
44
  height: auto;
10
45
  // 이미지로 인해 좌우로 스크롤이 생기는 것을 방지
11
46
  max-width: 100%;
@@ -1,97 +1,35 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { css, useTheme } from "@emotion/react";
4
- import { css as cssToClassName } from "@emotion/css";
3
+ import { css } from "@emotion/react";
5
4
  import { CheckboxCircleFillIcon, CheckFillIcon, CloseCircleFillIcon, } from "../../../../../icons";
6
5
  import { SelectBoxComponent } from "./SelectBoxComponent";
7
6
  import Tag from "../../../../../components/Tag";
8
- const getBoxStyle = (theme, isSelected, isAnswer) => {
9
- if (isSelected) {
10
- // 선택 박스
11
- if (isAnswer === undefined) {
12
- return css `
13
- background: ${theme.color.container.primaryContainer};
14
- border: 1px solid ${theme.color.foreground.primary};
15
- color: ${theme.color.container.primaryOnContainer};
16
- `;
17
- }
18
- // 정답 박스
19
- if (isAnswer) {
20
- return css `
21
- background: ${theme.color.container.successContainer};
22
- border: 1px solid ${theme.color.background.successActive};
23
- color: ${theme.color.container.successOnContainer};
24
- `;
25
- }
26
- // 오답 박스
27
- return css `
28
- background: ${theme.color.container.dangerContainer};
29
- border: 1px solid ${theme.color.background.dangerActive};
30
- color: ${theme.color.container.dangerOnContainer};
31
- `;
32
- }
33
- return undefined;
34
- };
35
- const getIndexClassName = (theme, isSelected, isAnswer) => {
36
- if (isSelected) {
37
- // 선택 박스
38
- if (isAnswer === undefined) {
39
- return cssToClassName `
40
- background: ${theme.color.background.primary};
41
- border: 1px solid ${theme.color.background.primary};
42
- color: ${theme.color.foreground.neutralAlt};
43
- `;
44
- }
45
- // 정답 박스
46
- if (isAnswer) {
47
- return cssToClassName `
48
- background: ${theme.color.background.successActive};
49
- border: 1px solid ${theme.color.background.successActive};
50
- color: ${theme.color.foreground.neutralAlt};
51
- `;
52
- }
53
- // 오답 박스
54
- return cssToClassName `
55
- background: ${theme.color.background.dangerActive};
56
- border: 1px solid ${theme.color.background.dangerActive};
57
- color: ${theme.color.foreground.neutralAlt};
58
- `;
59
- }
60
- return undefined;
61
- };
62
- const getIndexComponent = (index, isSelected, isAnswer) => {
63
- if (isSelected) {
64
- // 선택 박스
65
- if (isAnswer === undefined) {
66
- return (_jsx(CheckFillIcon, { css: css `
67
- width: 12px;
68
- height: 12px;
69
- ` }));
70
- }
71
- // 정답 박스
72
- if (isAnswer) {
73
- return (_jsx(CheckboxCircleFillIcon, { css: css `
74
- width: 12px;
75
- height: 12px;
76
- ` }));
77
- }
78
- // 오답 박스
79
- return (_jsx(CloseCircleFillIcon, { css: css `
7
+ const TYPE_TO_INDEX_ICON = (type) => ({
8
+ primary: (_jsx(CheckFillIcon, { css: css `
80
9
  width: 12px;
81
10
  height: 12px;
82
- ` }));
83
- }
84
- return index;
85
- };
11
+ ` })),
12
+ success: (_jsx(CheckboxCircleFillIcon, { css: css `
13
+ width: 12px;
14
+ height: 12px;
15
+ ` })),
16
+ danger: (_jsx(CloseCircleFillIcon, { css: css `
17
+ width: 12px;
18
+ height: 12px;
19
+ ` })),
20
+ })[type];
86
21
  export function SelectBoxView(props) {
87
22
  const { index, isSelected, isAnswer, image, text, onClick } = props;
88
- const theme = useTheme();
89
- return (_jsx(SelectBoxComponent, { css: [
90
- css `
91
- width: 100%;
92
- `,
93
- getBoxStyle(theme, isSelected, isAnswer),
94
- ], indexClassName: getIndexClassName(theme, isSelected, isAnswer), index: getIndexComponent(index, isSelected, isAnswer), image: image, text: text,
23
+ const selectBoxType = isSelected
24
+ ? isAnswer === undefined
25
+ ? "primary"
26
+ : isAnswer
27
+ ? "success"
28
+ : "danger"
29
+ : undefined;
30
+ return (_jsx(SelectBoxComponent, { css: css `
31
+ width: 100%;
32
+ `, type: selectBoxType, index: selectBoxType ? TYPE_TO_INDEX_ICON(selectBoxType) : index, image: image, text: text,
95
33
  // isAnswer가 존재하면 채점 후의 상태이므로 unclickable을 위해 onClick을 전달하지 않음
96
34
  onClick: isAnswer === undefined ? onClick : undefined,
97
35
  // 선택되지 않았으나 정답일 때 정답 태그를 표시
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.38.4",
3
+ "version": "1.38.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,