@team-monolith/cds 1.99.3 → 1.99.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.
- package/dist/patterns/Dropdown/Dropdown.d.ts +1 -1
- package/dist/patterns/Dropdown/Dropdown.js +4 -2
- package/dist/patterns/Dropdown/DropdownItem/DropdownItem.d.ts +1 -1
- package/dist/patterns/Dropdown/DropdownItem/DropdownItem.js +5 -3
- package/dist/patterns/Dropdown/DropdownMenu/DropdownMenu.d.ts +6 -0
- package/dist/patterns/Dropdown/DropdownMenu/DropdownMenu.js +3 -3
- package/dist/patterns/SegmentedControl/SegmentedControlButton.js +4 -1
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ export interface DropdownProps {
|
|
|
29
29
|
/** 버튼 클릭 시 호출될 콜백 함수 */
|
|
30
30
|
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
31
31
|
/** 드롭다운 메뉴의 props */
|
|
32
|
-
menuProps?: Omit<DropdownMenuProps, "anchorEl" | "children" | "itemState" | "setItemState">;
|
|
32
|
+
menuProps?: Omit<DropdownMenuProps, "anchorEl" | "children" | "itemState" | "setItemState" | "dropdownMenuId">;
|
|
33
33
|
/** 드롭다운 메뉴의 children */
|
|
34
34
|
children: React.ReactNode;
|
|
35
35
|
/** 드롭다운 메뉴 아이템 클릭 시 메뉴가 닫히는지 여부 */
|
|
@@ -11,9 +11,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
13
13
|
/** @jsxImportSource @emotion/react */
|
|
14
|
-
import { forwardRef, useRef, useState } from "react";
|
|
14
|
+
import { forwardRef, useMemo, useRef, useState } from "react";
|
|
15
15
|
import { Button, ArrowDownSFillIcon, } from "../..";
|
|
16
16
|
import { DropdownMenu } from "./DropdownMenu";
|
|
17
|
+
import { uid } from "uid";
|
|
17
18
|
/**
|
|
18
19
|
* [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?type=design&node-id=203-95329&t=FwczLZ1IVvskUVbT-0)
|
|
19
20
|
*/
|
|
@@ -31,6 +32,7 @@ const Dropdown = forwardRef(function Dropdown(props, ref) {
|
|
|
31
32
|
const isControlled = menuProps.open !== undefined;
|
|
32
33
|
const [open, setOpen] = useState(false);
|
|
33
34
|
const [itemState, setItemState] = useState(new Map());
|
|
35
|
+
const uniqueId = useMemo(uid, []);
|
|
34
36
|
const handleClick = (e) => {
|
|
35
37
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
36
38
|
if (!isControlled)
|
|
@@ -53,6 +55,6 @@ const Dropdown = forwardRef(function Dropdown(props, ref) {
|
|
|
53
55
|
});
|
|
54
56
|
(_a = menuProps.onClose) === null || _a === void 0 ? void 0 : _a.call(menuProps, e);
|
|
55
57
|
};
|
|
56
|
-
return (_jsxs(Component, Object.assign({ className: className }, other, { ref: ref }, { children: [_jsx(Button, Object.assign({ css: buttonCss, ref: menuRef }, buttonProps, { onClick: handleClick, fullWidth: true, "aria-expanded": (
|
|
58
|
+
return (_jsxs(Component, Object.assign({ className: className }, other, { ref: ref }, { children: [_jsx(Button, Object.assign({ css: buttonCss, ref: menuRef }, buttonProps, { onClick: handleClick, fullWidth: true, "aria-expanded": (_a = menuProps.open) !== null && _a !== void 0 ? _a : open, "aria-controls": uniqueId })), _jsx(DropdownMenu, Object.assign({ dropdownMenuId: uniqueId }, menuProps, { open: isControlled ? menuProps.open : open, onClose: handleClose, anchorEl: menuRef.current, closeOnItemClick: closeOnItemClick, itemState: itemState, setItemState: setItemState }, { children: children }))] })));
|
|
57
59
|
});
|
|
58
60
|
export { Dropdown };
|
|
@@ -39,7 +39,7 @@ export interface DropdownItemProps {
|
|
|
39
39
|
/** 드롭다운 아이템 클릭 시 호출될 콜백 함수 */
|
|
40
40
|
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
41
41
|
/** 아이템이 가지는 드롭다운 메뉴 props.*/
|
|
42
|
-
subMenuProps?: Omit<DropdownMenuProps, "anchorEl" | "itemState" | "setItemState" | "children">;
|
|
42
|
+
subMenuProps?: Omit<DropdownMenuProps, "anchorEl" | "itemState" | "setItemState" | "children" | "dropdownMenuId">;
|
|
43
43
|
/** 아이템이 가지는 드롭다운 메뉴의 서브 아이템들. 주어지지 않으면 서브메뉴가 없습니다. */
|
|
44
44
|
children?: React.ReactNode;
|
|
45
45
|
}
|
|
@@ -15,10 +15,11 @@ import { css } from "@emotion/react";
|
|
|
15
15
|
import * as React from "react";
|
|
16
16
|
import styled from "@emotion/styled";
|
|
17
17
|
import { CheckboxInput, ArrowRightSLineIcon, HOVER, } from "../../..";
|
|
18
|
-
import { useContext, useRef } from "react";
|
|
18
|
+
import { useContext, useMemo, useRef } from "react";
|
|
19
19
|
import { DropdownMenu } from "../DropdownMenu";
|
|
20
20
|
import { DropdownContext } from "../DropdownContext";
|
|
21
21
|
import { getSelected, setSelected } from "./selected";
|
|
22
|
+
import { uid } from "uid";
|
|
22
23
|
const TYPE_TO_COLOR = (theme, type) => ({
|
|
23
24
|
default: theme.color.foreground.neutralBase,
|
|
24
25
|
danger: theme.color.foreground.danger,
|
|
@@ -30,6 +31,7 @@ const DropdownItem = React.forwardRef(function DropdownItem(props, ref) {
|
|
|
30
31
|
const { className, index, labelCss, component: Component = "div", type = "default", checkbox, checkboxProps = { checked: false }, startIcon, label, endIcon, preserveIconColor = false, disabled, active, onMouseEnter, onMouseLeave, onClick, subMenuProps, children } = props, other = __rest(props, ["className", "index", "labelCss", "component", "type", "checkbox", "checkboxProps", "startIcon", "label", "endIcon", "preserveIconColor", "disabled", "active", "onMouseEnter", "onMouseLeave", "onClick", "subMenuProps", "children"]);
|
|
31
32
|
const itemRef = useRef(null);
|
|
32
33
|
const { open, onCloseOnItemClick, nestedIndex, itemState, setItemState } = useContext(DropdownContext);
|
|
34
|
+
const uniqueId = useMemo(uid, []);
|
|
33
35
|
const absItemIndex = nestedIndex ? `${nestedIndex}-${index}` : `${index}`;
|
|
34
36
|
// 서브메뉴가 존재하는지 여부
|
|
35
37
|
const isSubMenuExist = Boolean(children);
|
|
@@ -49,7 +51,7 @@ const DropdownItem = React.forwardRef(function DropdownItem(props, ref) {
|
|
|
49
51
|
setSelected(setItemState, absItemIndex);
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
|
-
return (_jsxs(_Fragment, { children: [_jsx(Component, Object.assign({ className: className, ref: ref, tabIndex: disabled ? -1 : 0, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onClick: handleClick, "aria-disabled": disabled }, other, { "aria-expanded": isSubMenuExist ? isSubMenuShowed : undefined }, { children: _jsxs(Item, Object.assign({ ref: itemRef, disabled: disabled, selected: isSubMenuShowed || Boolean(active) }, { children: [_jsxs(LeftWrapper, { children: [checkbox && (_jsx(StyledCheckboxInput, Object.assign({}, checkboxProps, { disabled: disabled, onClick: (e) => {
|
|
54
|
+
return (_jsxs(_Fragment, { children: [_jsx(Component, Object.assign({ className: className, ref: ref, tabIndex: disabled ? -1 : 0, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onClick: handleClick, "aria-disabled": disabled }, other, { "aria-expanded": isSubMenuExist ? isSubMenuShowed : undefined, "aria-controls": isSubMenuExist ? uniqueId : undefined }, { children: _jsxs(Item, Object.assign({ ref: itemRef, disabled: disabled, selected: isSubMenuShowed || Boolean(active) }, { children: [_jsxs(LeftWrapper, { children: [checkbox && (_jsx(StyledCheckboxInput, Object.assign({}, checkboxProps, { disabled: disabled, onClick: (e) => {
|
|
53
55
|
e.stopPropagation();
|
|
54
56
|
} }))), startIcon && (_jsx(IconDiv, Object.assign({ type: type, preserveIconColor: preserveIconColor }, { children: startIcon }))), _jsx(LabelDiv, Object.assign({ css: labelCss, type: type }, { children: label }))] }), endIcon && (_jsx(IconDiv, Object.assign({ type: type, preserveIconColor: preserveIconColor }, { children: endIcon }))), !endIcon && isSubMenuExist && (_jsx(IconDiv, Object.assign({ type: type, preserveIconColor: preserveIconColor }, { children: _jsx(ArrowRightSLineIcon, {}) })))] })) })), isSubMenuExist && (_jsx(DropdownContext.Provider, Object.assign({ value: {
|
|
55
57
|
open,
|
|
@@ -57,7 +59,7 @@ const DropdownItem = React.forwardRef(function DropdownItem(props, ref) {
|
|
|
57
59
|
nestedIndex: absItemIndex,
|
|
58
60
|
itemState,
|
|
59
61
|
setItemState,
|
|
60
|
-
} }, { children: _jsx(DropdownMenu, Object.assign({}, subMenuProps, { open: isSubMenuShowed, anchorEl: itemRef.current, isNestedMenu: true, anchorOrigin: {
|
|
62
|
+
} }, { children: _jsx(DropdownMenu, Object.assign({ dropdownMenuId: uniqueId }, subMenuProps, { open: isSubMenuShowed, anchorEl: itemRef.current, isNestedMenu: true, anchorOrigin: {
|
|
61
63
|
vertical: "top",
|
|
62
64
|
horizontal: "right",
|
|
63
65
|
}, itemState: itemState, setItemState: setItemState }, { children: children })) })))] }));
|
|
@@ -30,6 +30,12 @@ export interface DropdownMenuProps {
|
|
|
30
30
|
/** 중첩 드롭다운 메뉴가 아닐 경우 주어주지 않아도 됩니다. */
|
|
31
31
|
itemState?: ItemState;
|
|
32
32
|
setItemState?: React.Dispatch<React.SetStateAction<ItemState>>;
|
|
33
|
+
/**
|
|
34
|
+
* 드롭다운 메뉴의 고유 id입니다.
|
|
35
|
+
* 이 id는 메뉴를 제어하는 버튼 등에서 aria-controls 속성을 통해 연결되어,
|
|
36
|
+
* 스크린 리더 등의 보조 기술이 메뉴를 올바르게 인식하도록 돕습니다.
|
|
37
|
+
*/
|
|
38
|
+
dropdownMenuId: string;
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
35
41
|
* [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?type=design&node-id=106-1921&t=FwczLZ1IVvskUVbT-0)
|
|
@@ -20,7 +20,7 @@ const DropdownMenu = React.forwardRef(function DropdownMenu(props, ref) {
|
|
|
20
20
|
}, transformOrigin = {
|
|
21
21
|
vertical: "top",
|
|
22
22
|
horizontal: "left",
|
|
23
|
-
}, closeOnItemClick, children, menuCss, itemState = EMPTY_MAP, setItemState = () => { }, } = props;
|
|
23
|
+
}, closeOnItemClick, children, menuCss, itemState = EMPTY_MAP, setItemState = () => { }, dropdownMenuId, } = props;
|
|
24
24
|
const { nestedIndex, onCloseOnItemClick } = useContext(DropdownContext);
|
|
25
25
|
// 드롭다운 메뉴 위치 조정
|
|
26
26
|
const menuStyle = css `
|
|
@@ -40,7 +40,7 @@ const DropdownMenu = React.forwardRef(function DropdownMenu(props, ref) {
|
|
|
40
40
|
nestedIndex,
|
|
41
41
|
itemState,
|
|
42
42
|
setItemState,
|
|
43
|
-
} }, { children: _jsx(Menu, Object.assign({ className: className, open: open, onClose: onClose, anchorEl: anchorEl, anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, ref: ref, css: menuStyle }, { children: children })) })));
|
|
43
|
+
} }, { children: _jsx(Menu, Object.assign({ id: dropdownMenuId, className: className, open: open, onClose: onClose, anchorEl: anchorEl, anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, ref: ref, css: menuStyle }, { children: children })) })));
|
|
44
44
|
}
|
|
45
45
|
// 중첩 드롭다운 메뉴
|
|
46
46
|
return (_jsx(DropdownContext.Provider, Object.assign({ value: {
|
|
@@ -50,7 +50,7 @@ const DropdownMenu = React.forwardRef(function DropdownMenu(props, ref) {
|
|
|
50
50
|
nestedIndex,
|
|
51
51
|
itemState,
|
|
52
52
|
setItemState,
|
|
53
|
-
} }, { children: _jsx(Menu, Object.assign({ className: className, open: open, onClose: onCloseOnItemClick, anchorEl: anchorEl, anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, ref: ref,
|
|
53
|
+
} }, { children: _jsx(Menu, Object.assign({ id: dropdownMenuId, className: className, open: open, onClose: onCloseOnItemClick, anchorEl: anchorEl, anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, ref: ref,
|
|
54
54
|
// 중첩된 드롭다운의 경우 상위 메뉴에 대한 마우스 호버, 클릭 이벤트가 동작하지 않는 문제 해결
|
|
55
55
|
// 실제 드롭다운 메뉴 영역에서만 포인터 이벤트를 감지하도록 처리
|
|
56
56
|
css: [
|
|
@@ -30,7 +30,10 @@ export const SegmentedControlButton = React.forwardRef(function SegmentedControl
|
|
|
30
30
|
const isActive = context.multiSelect
|
|
31
31
|
? context.value.includes(props.value)
|
|
32
32
|
: context.value === props.value;
|
|
33
|
-
|
|
33
|
+
const { label } = other;
|
|
34
|
+
return (_jsx(StyledButton, Object.assign({}, other, { ref: ref, startIcon: typeof startIcon === "function" ? startIcon(isActive) : startIcon, endIcon: typeof endIcon === "function" ? endIcon(isActive) : endIcon, isActive: isActive, color: isActive ? "white" : "textNeutral", size: context.size, onClick: handleClick, disabled: context.disabled || props.disabled, title: isActive
|
|
35
|
+
? `${typeof label === "string" ? label : ""} 선택됨`
|
|
36
|
+
: undefined })));
|
|
34
37
|
});
|
|
35
38
|
const StyledButton = styled(Button, {
|
|
36
39
|
shouldForwardProp: (prop) => prop !== "isActive",
|