@tide-design/components 0.0.0-stage → 0.11.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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Accordion.d.ts +66 -0
  3. package/dist/Accordion.js +127 -0
  4. package/dist/Alert.d.ts +32 -0
  5. package/dist/Alert.js +47 -0
  6. package/dist/AlertDialog.d.ts +8 -0
  7. package/dist/AlertDialog.js +18 -0
  8. package/dist/Avatar.d.ts +27 -0
  9. package/dist/Avatar.js +44 -0
  10. package/dist/Badge.d.ts +32 -0
  11. package/dist/Badge.js +28 -0
  12. package/dist/Breadcrumb.d.ts +26 -0
  13. package/dist/Breadcrumb.js +53 -0
  14. package/dist/Button.d.ts +42 -0
  15. package/dist/Button.js +76 -0
  16. package/dist/Card.d.ts +13 -0
  17. package/dist/Card.js +18 -0
  18. package/dist/Checkbox.d.ts +30 -0
  19. package/dist/Checkbox.js +74 -0
  20. package/dist/CheckboxGroup.d.ts +19 -0
  21. package/dist/CheckboxGroup.js +45 -0
  22. package/dist/Combobox.d.ts +59 -0
  23. package/dist/Combobox.js +206 -0
  24. package/dist/Dialog.d.ts +70 -0
  25. package/dist/Dialog.js +255 -0
  26. package/dist/Field.d.ts +33 -0
  27. package/dist/Field.js +74 -0
  28. package/dist/IconButton.d.ts +42 -0
  29. package/dist/IconButton.js +63 -0
  30. package/dist/Input.d.ts +16 -0
  31. package/dist/Input.js +29 -0
  32. package/dist/Link.d.ts +20 -0
  33. package/dist/Link.js +21 -0
  34. package/dist/Menu.d.ts +72 -0
  35. package/dist/Menu.js +226 -0
  36. package/dist/Pagination.d.ts +46 -0
  37. package/dist/Pagination.js +79 -0
  38. package/dist/Popover.d.ts +43 -0
  39. package/dist/Popover.js +147 -0
  40. package/dist/Progress.d.ts +32 -0
  41. package/dist/Progress.js +40 -0
  42. package/dist/Radio.d.ts +27 -0
  43. package/dist/Radio.js +67 -0
  44. package/dist/RadioGroup.d.ts +28 -0
  45. package/dist/RadioGroup.js +50 -0
  46. package/dist/Select.d.ts +62 -0
  47. package/dist/Select.js +169 -0
  48. package/dist/Separator.d.ts +18 -0
  49. package/dist/Separator.js +24 -0
  50. package/dist/Skeleton.d.ts +24 -0
  51. package/dist/Skeleton.js +29 -0
  52. package/dist/Spinner.d.ts +20 -0
  53. package/dist/Spinner.js +35 -0
  54. package/dist/Switch.d.ts +30 -0
  55. package/dist/Switch.js +65 -0
  56. package/dist/Table.d.ts +31 -0
  57. package/dist/Table.js +53 -0
  58. package/dist/Tabs.d.ts +66 -0
  59. package/dist/Tabs.js +159 -0
  60. package/dist/Tag.d.ts +48 -0
  61. package/dist/Tag.js +102 -0
  62. package/dist/Textarea.d.ts +19 -0
  63. package/dist/Textarea.js +36 -0
  64. package/dist/Toast.d.ts +71 -0
  65. package/dist/Toast.js +191 -0
  66. package/dist/Tooltip.d.ts +53 -0
  67. package/dist/Tooltip.js +129 -0
  68. package/dist/Typography.d.ts +36 -0
  69. package/dist/Typography.js +50 -0
  70. package/dist/VisuallyHidden.d.ts +4 -0
  71. package/dist/VisuallyHidden.js +13 -0
  72. package/dist/alert-style.js +45 -0
  73. package/dist/choice-group.js +34 -0
  74. package/dist/choice-style.d.ts +2 -0
  75. package/dist/choice-style.js +16 -0
  76. package/dist/cn.d.ts +6 -0
  77. package/dist/cn.js +15 -0
  78. package/dist/field-context.js +26 -0
  79. package/dist/index.d.ts +38 -0
  80. package/dist/index.js +38 -0
  81. package/dist/input-style.d.ts +3 -0
  82. package/dist/input-style.js +11 -0
  83. package/dist/list-collection.d.ts +23 -0
  84. package/dist/list-collection.js +99 -0
  85. package/dist/list-style.js +46 -0
  86. package/dist/listbox.d.ts +15 -0
  87. package/dist/listbox.js +90 -0
  88. package/dist/overlay-style.js +84 -0
  89. package/dist/overlay.d.ts +7 -0
  90. package/dist/overlay.js +130 -0
  91. package/dist/pressable.js +70 -0
  92. package/dist/render.js +55 -0
  93. package/dist/styles.css +5 -0
  94. package/dist/types.d.ts +9 -0
  95. package/package.json +57 -3
  96. package/README.md +0 -3
package/dist/Button.js ADDED
@@ -0,0 +1,76 @@
1
+ "use client";
2
+
3
+ import { pressableBaseClass, pressableState } from "./pressable.js";
4
+ import { renderElement } from "./render.js";
5
+ import { Spinner } from "./Spinner.js";
6
+ import { VisuallyHidden } from "./VisuallyHidden.js";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+
9
+ // src/Button.tsx
10
+ /** 높이, 좌우 padding, 아이콘과 텍스트 사이 간격, 텍스트 스타일(spec size 표). radius는 모든 size에서 `md`다. */
11
+ const sizeClass = {
12
+ xs: "h-6 gap-1 px-2 text-label-sm",
13
+ sm: "h-8 gap-1.5 px-3 text-label-md",
14
+ md: "h-10 gap-2 px-4 text-label-md",
15
+ lg: "h-12 gap-2 px-5 text-label-lg"
16
+ };
17
+ /** 텍스트 옆 아이콘 크기(spec 아이콘 크기 규칙). 감싼 span의 크기이고 안의 요소가 꽉 채운다. */
18
+ const iconSizeClass = {
19
+ xs: "size-3.5",
20
+ sm: "size-3.5",
21
+ md: "size-4",
22
+ lg: "size-5"
23
+ };
24
+ function Icon({ size, children }) {
25
+ return /* @__PURE__ */ jsx("span", {
26
+ "aria-hidden": "true",
27
+ className: `inline-flex shrink-0 items-center justify-center *:size-full ${iconSizeClass[size]}`,
28
+ children
29
+ });
30
+ }
31
+ /**
32
+ * 누르면 동작을 실행하는 버튼. 채움 방식(`variant`) × Role(`color`) × `size`로 모양을 고른다.
33
+ * 링크로 렌더해야 하면 `render={<Link href="/x" />}`를 쓴다.
34
+ */
35
+ function Button({ variant = "solid", color = "primary", size = "md", startIcon, endIcon, loading = false, loadingLabel = "로딩 중", noPressScale = false, render, disabled = false, type, children, onClick, ...props }) {
36
+ const state = pressableState({
37
+ variant,
38
+ color,
39
+ disabled,
40
+ loading,
41
+ noPressScale,
42
+ render,
43
+ type,
44
+ onClick,
45
+ ariaDisabled: props["aria-disabled"]
46
+ });
47
+ const { showSpinner } = state;
48
+ const label = children ?? (render?.props)?.children;
49
+ const rootProps = {
50
+ ...props,
51
+ ...state.rootProps,
52
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [
53
+ showSpinner ? /* @__PURE__ */ jsx(Spinner, {
54
+ size,
55
+ "aria-hidden": "true"
56
+ }) : startIcon != null ? /* @__PURE__ */ jsx(Icon, {
57
+ size,
58
+ children: startIcon
59
+ }) : null,
60
+ label,
61
+ endIcon != null ? /* @__PURE__ */ jsx(Icon, {
62
+ size,
63
+ children: endIcon
64
+ }) : null,
65
+ showSpinner ? /* @__PURE__ */ jsx(VisuallyHidden, { children: loadingLabel }) : null
66
+ ] })
67
+ };
68
+ return renderElement({
69
+ defaultElement: "button",
70
+ render,
71
+ baseClassName: `${pressableBaseClass} ${sizeClass[size]} ${state.className}`,
72
+ props: rootProps
73
+ });
74
+ }
75
+
76
+ export { Button };
package/dist/Card.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ComponentProps, ReactElement } from "react";
2
+ export interface CardProps extends ComponentProps<"div"> {
3
+ /**
4
+ * 다른 요소로 렌더한다. 예: `render={<article />}`, `render={<li />}`.
5
+ * 묶음의 뜻이 있으면 그 요소를 고른다. props, ref, className을 그 요소에 병합한다.
6
+ */
7
+ render?: ReactElement;
8
+ }
9
+ /**
10
+ * 관련 내용을 한 덩어리로 묶는 surface 표면 컨테이너. 경계만 있고 그림자는 없다.
11
+ * 기본 요소는 `div`이고, `render`로 `article`·`section`·`li` 등을 쓴다. 서버 컴포넌트로 쓸 수 있다.
12
+ */
13
+ export declare function Card({ render, ...props }: CardProps): ReactElement;
package/dist/Card.js ADDED
@@ -0,0 +1,18 @@
1
+ import { renderElement } from "./render.js";
2
+
3
+ // src/Card.tsx
4
+ const baseClass = "rounded-lg border border-default bg-surface p-4 text-default";
5
+ /**
6
+ * 관련 내용을 한 덩어리로 묶는 surface 표면 컨테이너. 경계만 있고 그림자는 없다.
7
+ * 기본 요소는 `div`이고, `render`로 `article`·`section`·`li` 등을 쓴다. 서버 컴포넌트로 쓸 수 있다.
8
+ */
9
+ function Card({ render, ...props }) {
10
+ return renderElement({
11
+ defaultElement: "div",
12
+ render,
13
+ baseClassName: baseClass,
14
+ props
15
+ });
16
+ }
17
+
18
+ export { Card };
@@ -0,0 +1,30 @@
1
+ import { ChoiceSize } from "./choice-style.js";
2
+ import { Role } from "./types.js";
3
+ import { CSSProperties, ComponentProps, ReactElement, ReactNode } from "react";
4
+ export interface CheckboxProps extends Omit<ComponentProps<"input">, "type" | "size" | "color" | "children" | "className" | "style"> {
5
+ /** 상자 옆에 보이는 label. 체크박스의 이름이 된다. 없으면 `aria-label`을 준다. */
6
+ children?: ReactNode;
7
+ /** 상자 16px·글자 14px(`sm`) 또는 상자 20px·글자 16px(`md`). 누르는 영역은 둘 다 24×24px이다. 기본값은 `md`다. */
8
+ size?: ChoiceSize;
9
+ /** 체크했을 때 상자 색(Role). 루트에 `data-color`로 붙는다. 기본값은 `primary`다. */
10
+ color?: Role;
11
+ /**
12
+ * 일부만 선택된 상태(「전체 선택」 등). 체크 대신 가로줄이 보이고 보조 기술은 「일부 선택」으로 읽는다.
13
+ * 누르면 브라우저가 이 상태를 지우므로, 앱이 다시 계산해 넘긴다.
14
+ */
15
+ indeterminate?: boolean;
16
+ /**
17
+ * 오류 상태. input에 `aria-invalid="true"`와 `data-invalid`가 붙고 경계가 danger 색이 된다.
18
+ * Field·CheckboxGroup 안에서는 그 값을 따르고, 여기에 준 값이 이긴다.
19
+ */
20
+ invalid?: boolean;
21
+ /** 루트 label의 class. 사용자 class가 기본 class를 이긴다. 상자 모양은 바꾸지 않는다(`size`·`color`가 맡는다). */
22
+ className?: string;
23
+ /** 루트 label의 style */
24
+ style?: CSSProperties;
25
+ }
26
+ /**
27
+ * 네이티브 체크박스. `checked`/`defaultChecked`/`onChange`를 그대로 받고 form에 그대로 제출된다.
28
+ * 여러 개를 묶어 이름·설명·오류를 붙이려면 `Field group` 안의 `CheckboxGroup`에 둔다.
29
+ */
30
+ export declare function Checkbox({ children, size, color, indeterminate, invalid, id, disabled, required, className, style, ref, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: CheckboxProps): ReactElement;
@@ -0,0 +1,74 @@
1
+ "use client";
2
+
3
+ import { CheckboxGroupContext } from "./choice-group.js";
4
+ import { choiceAreaClass, choiceInputClass, choiceMarkClass, choiceRootClass, choiceTextClass } from "./choice-style.js";
5
+ import { cn } from "./cn.js";
6
+ import { useFieldControl } from "./field-context.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { use, useImperativeHandle, useLayoutEffect, useRef } from "react";
9
+ import { CheckIcon, MinusIcon } from "@tide-design/icons";
10
+
11
+ // src/Checkbox.tsx
12
+ /** 상자 크기와 모서리. 체크박스는 radius `sm`(4px)이다. */
13
+ const boxClass = {
14
+ sm: "size-4 rounded-sm",
15
+ md: "size-5 rounded-sm"
16
+ };
17
+ /** 상자 안 아이콘 크기(px) */
18
+ const iconSize = {
19
+ sm: 12,
20
+ md: 16
21
+ };
22
+ /**
23
+ * 네이티브 체크박스. `checked`/`defaultChecked`/`onChange`를 그대로 받고 form에 그대로 제출된다.
24
+ * 여러 개를 묶어 이름·설명·오류를 붙이려면 `Field group` 안의 `CheckboxGroup`에 둔다.
25
+ */
26
+ function Checkbox({ children, size = "md", color = "primary", indeterminate = false, invalid, id, disabled, required, className, style, ref, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }) {
27
+ const group = use(CheckboxGroupContext);
28
+ const control = useFieldControl({
29
+ id,
30
+ invalid: invalid ?? group?.invalid,
31
+ disabled: disabled ?? group?.disabled,
32
+ required,
33
+ "aria-describedby": ariaDescribedBy,
34
+ "aria-invalid": ariaInvalid
35
+ });
36
+ const inputRef = useRef(null);
37
+ useImperativeHandle(ref, () => inputRef.current, []);
38
+ useLayoutEffect(() => {
39
+ if (inputRef.current) inputRef.current.indeterminate = indeterminate;
40
+ });
41
+ return /* @__PURE__ */ jsxs("label", {
42
+ "data-color": color,
43
+ "data-disabled": control.disabled ? "" : void 0,
44
+ "data-invalid": control["data-invalid"],
45
+ style,
46
+ className: cn(choiceRootClass, choiceTextClass[size], className),
47
+ children: [/* @__PURE__ */ jsxs("span", {
48
+ className: choiceAreaClass,
49
+ children: [
50
+ /* @__PURE__ */ jsx("input", {
51
+ ...props,
52
+ ...control,
53
+ ref: inputRef,
54
+ type: "checkbox",
55
+ className: cn(boxClass[size], choiceInputClass)
56
+ }),
57
+ /* @__PURE__ */ jsx(CheckIcon, {
58
+ size: iconSize[size],
59
+ strokeWidth: 3,
60
+ "data-mark": "check",
61
+ className: cn(choiceMarkClass, "peer-checked:block peer-indeterminate:hidden")
62
+ }),
63
+ /* @__PURE__ */ jsx(MinusIcon, {
64
+ size: iconSize[size],
65
+ strokeWidth: 3,
66
+ "data-mark": "indeterminate",
67
+ className: cn(choiceMarkClass, "peer-indeterminate:block")
68
+ })
69
+ ]
70
+ }), children === void 0 || children === null ? null : /* @__PURE__ */ jsx("span", { children })]
71
+ });
72
+ }
73
+
74
+ export { Checkbox };
@@ -0,0 +1,19 @@
1
+ import { ComponentProps, ReactElement } from "react";
2
+ /** 항목을 쌓는 방향 */
3
+ export type ChoiceOrientation = "vertical" | "horizontal";
4
+ export interface CheckboxGroupProps extends ComponentProps<"div"> {
5
+ /** 항목을 세로(`vertical`)로 쌓거나 가로(`horizontal`)로 늘어놓는다. 기본값은 `vertical`이다. */
6
+ orientation?: ChoiceOrientation;
7
+ /**
8
+ * 오류 상태. 안의 Checkbox마다 `aria-invalid="true"`가 붙고, 묶음에 `data-invalid`가 붙는다.
9
+ * Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
10
+ */
11
+ invalid?: boolean;
12
+ /** 안의 Checkbox를 모두 비활성으로 만든다. Field 안에서는 Field의 값을 따른다. */
13
+ disabled?: boolean;
14
+ }
15
+ /**
16
+ * Checkbox 여러 개를 하나의 이름으로 묶는다. `<Field label group>` 안에 두면 label이 묶음의 이름, 설명·오류가
17
+ * 묶음의 설명이 된다. Field 밖에서는 `aria-label`이나 `aria-labelledby`를 준다.
18
+ */
19
+ export declare function CheckboxGroup({ orientation, invalid, disabled, id, className, children, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }: CheckboxGroupProps): ReactElement;
@@ -0,0 +1,45 @@
1
+ "use client";
2
+
3
+ import { CheckboxGroupContext, useChoiceGroup } from "./choice-group.js";
4
+ import { cn } from "./cn.js";
5
+ import { FieldContext } from "./field-context.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+
8
+ // src/CheckboxGroup.tsx
9
+ /** 방향별 배치. 가로는 줄이 넘치면 다음 줄로 간다. */
10
+ const orientationClass = {
11
+ vertical: "flex flex-col gap-2",
12
+ horizontal: "flex flex-row flex-wrap gap-x-6 gap-y-2"
13
+ };
14
+ /**
15
+ * Checkbox 여러 개를 하나의 이름으로 묶는다. `<Field label group>` 안에 두면 label이 묶음의 이름, 설명·오류가
16
+ * 묶음의 설명이 된다. Field 밖에서는 `aria-label`이나 `aria-labelledby`를 준다.
17
+ */
18
+ function CheckboxGroup({ orientation = "vertical", invalid, disabled, id, className, children, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }) {
19
+ const connection = useChoiceGroup({
20
+ id,
21
+ invalid,
22
+ disabled,
23
+ "aria-labelledby": ariaLabelledBy,
24
+ "aria-describedby": ariaDescribedBy
25
+ });
26
+ const state = {
27
+ invalid: connection.invalid,
28
+ disabled: connection.disabled
29
+ };
30
+ return /* @__PURE__ */ jsx("div", {
31
+ role: "group",
32
+ ...props,
33
+ ...connection.rootProps,
34
+ className: cn(orientationClass[orientation], className),
35
+ children: /* @__PURE__ */ jsx(FieldContext, {
36
+ value: null,
37
+ children: /* @__PURE__ */ jsx(CheckboxGroupContext, {
38
+ value: state,
39
+ children
40
+ })
41
+ })
42
+ });
43
+ }
44
+
45
+ export { CheckboxGroup, orientationClass };
@@ -0,0 +1,59 @@
1
+ import { InputSize } from "./input-style.js";
2
+ import { ListBoxOptionProps, ListBoxSectionProps } from "./listbox.js";
3
+ import { ComponentProps, ReactElement, ReactNode } from "react";
4
+ export interface ComboboxProps extends Omit<ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "type" | "size" | "children" | "name" | "form" | "list"> {
5
+ /** 고른 값(제어). 고른 옵션의 `value`다. `null`이면 아무것도 고르지 않은 상태다. 주면 `onValueChange`로 바꾼다. */
6
+ value?: string | null;
7
+ /** 처음 고른 값(비제어). 입력에 그 옵션의 글자가 보인다. 폼을 reset하면 이 값으로 돌아간다. */
8
+ defaultValue?: string;
9
+ /**
10
+ * 고른 값이 바뀌면 부른다. 옵션을 고르면 그 `value`로, 사용자가 입력을 모두 지우면 `null`로 부른다.
11
+ */
12
+ onValueChange?: (value: string | null) => void;
13
+ /** 목록이 열리거나 닫힐 때 새 상태로 부른다. 열림 상태는 입력이 정하므로 제어할 수 없다. */
14
+ onOpenChange?: (open: boolean) => void;
15
+ /** 거른 결과가 없을 때 목록에 보이는 글자. 기본값은 `"결과가 없습니다"`다. */
16
+ emptyMessage?: ReactNode;
17
+ /** 폼 제출 이름. 숨은 input에 붙어 고른 옵션의 `value`가 이 이름으로 제출된다(입력한 글자는 제출되지 않는다). */
18
+ name?: string;
19
+ /** 숨은 input이 속할 `<form>`의 id. 폼 밖에 둘 때 쓴다. */
20
+ form?: string;
21
+ /** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Input·Select·Button과 높이가 같다. 기본값은 `md`다. */
22
+ size?: InputSize;
23
+ /**
24
+ * 오류 상태. 입력에 `aria-invalid="true"`와 `data-invalid`가 붙고 경계가 danger 색이 된다.
25
+ * Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
26
+ */
27
+ invalid?: boolean;
28
+ /**
29
+ * 필수. 비어 있으면 폼 제출이 막히고 입력으로 포커스가 오며 오류 상태가 된다(브라우저 오류 말풍선은 없다).
30
+ * 메시지는 Field의 `error`로 앱이 보여 준다. Field 안에서는 Field의 값을 따른다.
31
+ */
32
+ required?: boolean;
33
+ /** `ComboboxItem`과 `ComboboxSection`. 이 요소들을 바로 아래(또는 Fragment·배열 안)에 둔다. */
34
+ children?: ReactNode;
35
+ }
36
+ /**
37
+ * 글자를 쳐서 옵션을 거르고 하나를 고르는 입력. 치면 목록이 열리고 옵션 글자에 친 글자가 들어 있는 옵션만 남는다
38
+ * (대소문자·악센트 무시, 현재 locale 기준). ↓·↑로 목록을 열고 옵션을 옮겨 Enter로 고르며, chevron 버튼을 누르면 거르지
39
+ * 않은 전체 목록이 열린다. 고르면 닫히고 입력에 그 옵션의 글자가 들어간다. Esc는 닫고 입력을 고른 옵션의 글자로 되돌린다.
40
+ * 포커스가 나가면 고르지 않은 글자는 지워진다(자유 입력 없음). 거른 결과가 없으면 목록에 `emptyMessage`가 보인다.
41
+ * Field 안에 두면 label·설명·오류가 자동으로 연결되고, `name`을 주면 고른 옵션의 `value`가 폼에 제출된다.
42
+ * 상태는 `data-open`·`data-invalid`·네이티브 `:disabled`(입력), `data-open`(목록),
43
+ * `data-highlighted`·`data-selected`·`data-disabled`(옵션)로 노출한다.
44
+ */
45
+ export declare function Combobox({ value, defaultValue, onValueChange, onOpenChange, emptyMessage, name, form, size, invalid, disabled, required, readOnly, id, ref, className, children, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }: ComboboxProps): ReactElement;
46
+ export interface ComboboxItemProps extends ListBoxOptionProps {}
47
+ /**
48
+ * Combobox의 옵션(`role="option"`). `Combobox`나 `ComboboxSection` 바로 안에 둔다. `value`가 고른 값이고 폼에
49
+ * 제출된다. 거르기와 고른 뒤 입력에 들어가는 글자는 `textValue`(기본은 내용의 글자)다. 키보드 위치와 마우스를 올린
50
+ * 옵션은 highlight, 고른 옵션은 neutral subtle-active 배경과 끝의 체크 아이콘이다(Select 옵션과 같다).
51
+ * 상태는 `data-highlighted`, `data-selected`, `data-disabled`로 노출한다.
52
+ */
53
+ export declare function ComboboxItem(_props: ComboboxItemProps): null;
54
+ export interface ComboboxSectionProps extends ListBoxSectionProps {}
55
+ /**
56
+ * 옵션 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
57
+ * 거른 결과 묶음 안에 남은 옵션이 없으면 묶음도 빠진다.
58
+ */
59
+ export declare function ComboboxSection(_props: ComboboxSectionProps): null;
@@ -0,0 +1,206 @@
1
+ "use client";
2
+
3
+ import { cn } from "./cn.js";
4
+ import { FieldContext, useFieldControl } from "./field-context.js";
5
+ import { inputBaseClass, inputSizeClass } from "./input-style.js";
6
+ import { asCollectionComponent, resolveCollectionChildren, sectionCollectionNode, valueItemCollectionNode } from "./list-collection.js";
7
+ import { listPopupClass } from "./list-style.js";
8
+ import { ListBoxNodes } from "./listbox.js";
9
+ import { OverlayPortal, useOverlayPresence, useOverlayTheme, usePopoverOverlay } from "./overlay.js";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { use, useLayoutEffect, useMemo, useRef } from "react";
12
+ import { ChevronDownIcon } from "@tide-design/icons";
13
+ import { mergeProps, mergeRefs, useButton, useComboBox, useFilter, useListBox } from "react-aria";
14
+ import { useComboBoxState } from "react-stately";
15
+
16
+ // src/Combobox.tsx
17
+ const wrapperClass = "flex w-full";
18
+ const inputEndClass = {
19
+ sm: "pe-[34px]",
20
+ md: "pe-9",
21
+ lg: "pe-10"
22
+ };
23
+ const buttonSizeClass = {
24
+ sm: "-ms-[35px] w-[35px] pe-[11px]",
25
+ md: "-ms-[37px] w-[37px] pe-[13px]",
26
+ lg: "-ms-[41px] w-[41px] pe-[17px]"
27
+ };
28
+ const buttonClass = "inline-flex shrink-0 cursor-pointer items-center justify-end text-muted outline-none disabled:cursor-not-allowed disabled:text-disabled";
29
+ /**
30
+ * 거른 결과가 없을 때의 글자. 옵션과 같은 여백·글자 크기라 목록 높이가 옵션 하나와 같다. `text-muted`.
31
+ * listbox 밖(같은 목록 표면 안)에 둔다. listbox 자식은 option·group만 될 수 있어서다. 결과 개수(0개)는 React Aria가
32
+ * live region으로 알린다.
33
+ */
34
+ const emptyClass = "px-2 py-1.5 text-body-sm text-muted select-none";
35
+ /**
36
+ * 한글 IME 조합 중의 keydown인지. 조합 중 Enter·화살표·Esc는 IME가 쓰므로 목록 동작에 쓰지 않는다.
37
+ * Chromium·Firefox는 `isComposing`이 `true`다. Safari는 조합을 끝내는 Enter의 keydown이 compositionend 뒤에
38
+ * `isComposing: false`로 오지만 `keyCode`가 229다(조합 처리 중인 키). 그래서 둘 다 본다.
39
+ */
40
+ const isComposingKey = (event) => event.nativeEvent.isComposing || event.keyCode === 229;
41
+ /**
42
+ * 글자를 쳐서 옵션을 거르고 하나를 고르는 입력. 치면 목록이 열리고 옵션 글자에 친 글자가 들어 있는 옵션만 남는다
43
+ * (대소문자·악센트 무시, 현재 locale 기준). ↓·↑로 목록을 열고 옵션을 옮겨 Enter로 고르며, chevron 버튼을 누르면 거르지
44
+ * 않은 전체 목록이 열린다. 고르면 닫히고 입력에 그 옵션의 글자가 들어간다. Esc는 닫고 입력을 고른 옵션의 글자로 되돌린다.
45
+ * 포커스가 나가면 고르지 않은 글자는 지워진다(자유 입력 없음). 거른 결과가 없으면 목록에 `emptyMessage`가 보인다.
46
+ * Field 안에 두면 label·설명·오류가 자동으로 연결되고, `name`을 주면 고른 옵션의 `value`가 폼에 제출된다.
47
+ * 상태는 `data-open`·`data-invalid`·네이티브 `:disabled`(입력), `data-open`(목록),
48
+ * `data-highlighted`·`data-selected`·`data-disabled`(옵션)로 노출한다.
49
+ */
50
+ function Combobox({ value, defaultValue, onValueChange, onOpenChange, emptyMessage = "결과가 없습니다", name, form, size = "md", invalid, disabled, required, readOnly, id, ref, className, children, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }) {
51
+ const field = use(FieldContext);
52
+ const control = useFieldControl({
53
+ id,
54
+ invalid,
55
+ disabled,
56
+ required,
57
+ "aria-describedby": ariaDescribedBy,
58
+ "aria-invalid": ariaInvalid
59
+ });
60
+ const isDisabled = control.disabled ?? false;
61
+ const isRequired = control.required ?? false;
62
+ const items = useMemo(() => resolveCollectionChildren(children), [children]);
63
+ const { contains } = useFilter({ sensitivity: "base" });
64
+ const state = useComboBoxState({
65
+ children: items,
66
+ defaultFilter: contains,
67
+ value,
68
+ defaultValue,
69
+ onChange: (key) => onValueChange?.(key == null ? null : String(key)),
70
+ onOpenChange: (open) => onOpenChange?.(open),
71
+ allowsEmptyCollection: true,
72
+ isDisabled,
73
+ isReadOnly: readOnly,
74
+ isRequired,
75
+ validationBehavior: "native"
76
+ });
77
+ const inputRef = useRef(null);
78
+ const buttonRef = useRef(null);
79
+ const popoverRef = useRef(null);
80
+ const listBoxRef = useRef(null);
81
+ const { inputProps, buttonProps, listBoxProps, isInvalid } = useComboBox({
82
+ inputRef,
83
+ buttonRef,
84
+ popoverRef,
85
+ listBoxRef,
86
+ id: control.id,
87
+ "aria-label": ariaLabel,
88
+ "aria-labelledby": ariaLabelledBy ?? field?.labelId,
89
+ isDisabled,
90
+ isReadOnly: readOnly,
91
+ isRequired,
92
+ validationBehavior: "native"
93
+ }, state);
94
+ const { buttonProps: chevronProps } = useButton(buttonProps, buttonRef);
95
+ const mergedRef = useMemo(() => mergeRefs(ref, inputRef), [ref, inputRef]);
96
+ const showInvalid = control["data-invalid"] === "" || isInvalid;
97
+ const { onKeyDown: ariaKeyDown, ...ariaInputProps } = inputProps;
98
+ return /* @__PURE__ */ jsxs("div", {
99
+ className: wrapperClass,
100
+ children: [
101
+ /* @__PURE__ */ jsx("input", {
102
+ ...mergeProps(props, ariaInputProps),
103
+ ref: mergedRef,
104
+ onKeyDown: (event) => {
105
+ props.onKeyDown?.(event);
106
+ if (!isComposingKey(event)) ariaKeyDown?.(event);
107
+ },
108
+ "aria-describedby": control["aria-describedby"],
109
+ "aria-invalid": showInvalid ? true : control["aria-invalid"],
110
+ "data-invalid": showInvalid ? "" : void 0,
111
+ "data-open": state.isOpen ? "" : void 0,
112
+ className: cn(inputSizeClass[size], inputBaseClass, inputEndClass[size], className)
113
+ }),
114
+ /* @__PURE__ */ jsx("button", {
115
+ ...chevronProps,
116
+ ref: buttonRef,
117
+ className: cn(buttonClass, buttonSizeClass[size]),
118
+ children: /* @__PURE__ */ jsx(ChevronDownIcon, { size: 16 })
119
+ }),
120
+ name !== void 0 && /* @__PURE__ */ jsx("input", {
121
+ type: "hidden",
122
+ name,
123
+ form,
124
+ value: state.selectedKey == null ? "" : String(state.selectedKey),
125
+ disabled: isDisabled
126
+ }),
127
+ /* @__PURE__ */ jsx(ComboboxPopover, {
128
+ state,
129
+ inputRef,
130
+ popoverRef,
131
+ listBoxRef,
132
+ listBoxProps,
133
+ emptyMessage
134
+ })
135
+ ]
136
+ });
137
+ }
138
+ /**
139
+ * 목록을 DOM에 둘지 정하고 portal한다. 닫혀도 퇴장 전환이 끝날 때까지 남긴다(ADR 0018).
140
+ * 포커스는 입력에 머물므로 FocusScope로 감싸지 않는다(`focusManagement={false}`). 감싸면 바깥 빈 곳을 눌러 포커스가
141
+ * body로 간 뒤 목록이 빠질 때 FocusScope가 입력으로 포커스를 되돌린다(react-aria 3.53.1 FocusScope restoreFocus).
142
+ */
143
+ function ComboboxPopover(props) {
144
+ if (!useOverlayPresence(props.state.isOpen, props.popoverRef)) return null;
145
+ return /* @__PURE__ */ jsx(OverlayPortal, {
146
+ isExiting: !props.state.isOpen,
147
+ focusManagement: false,
148
+ children: /* @__PURE__ */ jsx(ComboboxPopoverInner, { ...props })
149
+ });
150
+ }
151
+ /**
152
+ * 목록 표면(`listPopupClass`)과 그 안의 `role="listbox"`. 입력 아래 시작 끝에 4px 떨어져 붙고(Select와 같다),
153
+ * 폭은 입력보다 좁지 않다. 거른 결과가 없으면 listbox 뒤에 `emptyMessage`를 보인다.
154
+ */
155
+ function ComboboxPopoverInner({ state, inputRef, popoverRef, listBoxRef, listBoxProps, emptyMessage }) {
156
+ useOverlayTheme(inputRef, popoverRef);
157
+ useLayoutEffect(() => {
158
+ const popover = popoverRef.current;
159
+ const width = inputRef.current?.offsetWidth;
160
+ if (popover && width) popover.style.minWidth = `min(${width}px, 100vw - 24px)`;
161
+ }, [inputRef, popoverRef]);
162
+ const { overlayProps } = usePopoverOverlay({
163
+ triggerRef: inputRef,
164
+ popoverRef,
165
+ placement: "bottom start",
166
+ offset: 4,
167
+ nonModal: true
168
+ }, state);
169
+ const { listBoxProps: listProps } = useListBox(listBoxProps, state, listBoxRef);
170
+ const empty = state.collection.size === 0;
171
+ return /* @__PURE__ */ jsxs("div", {
172
+ ...overlayProps,
173
+ ref: popoverRef,
174
+ "data-open": state.isOpen ? "" : void 0,
175
+ className: listPopupClass,
176
+ children: [/* @__PURE__ */ jsx("div", {
177
+ ...listProps,
178
+ ref: listBoxRef,
179
+ className: "outline-none",
180
+ children: /* @__PURE__ */ jsx(ListBoxNodes, { state })
181
+ }), empty && /* @__PURE__ */ jsx("div", {
182
+ className: emptyClass,
183
+ children: emptyMessage
184
+ })]
185
+ });
186
+ }
187
+ /**
188
+ * Combobox의 옵션(`role="option"`). `Combobox`나 `ComboboxSection` 바로 안에 둔다. `value`가 고른 값이고 폼에
189
+ * 제출된다. 거르기와 고른 뒤 입력에 들어가는 글자는 `textValue`(기본은 내용의 글자)다. 키보드 위치와 마우스를 올린
190
+ * 옵션은 highlight, 고른 옵션은 neutral subtle-active 배경과 끝의 체크 아이콘이다(Select 옵션과 같다).
191
+ * 상태는 `data-highlighted`, `data-selected`, `data-disabled`로 노출한다.
192
+ */
193
+ function ComboboxItem(_props) {
194
+ return null;
195
+ }
196
+ asCollectionComponent(ComboboxItem, valueItemCollectionNode);
197
+ /**
198
+ * 옵션 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
199
+ * 거른 결과 묶음 안에 남은 옵션이 없으면 묶음도 빠진다.
200
+ */
201
+ function ComboboxSection(_props) {
202
+ return null;
203
+ }
204
+ asCollectionComponent(ComboboxSection, sectionCollectionNode);
205
+
206
+ export { Combobox, ComboboxItem, ComboboxSection };
@@ -0,0 +1,70 @@
1
+ import { ComponentProps, ReactElement, ReactNode } from "react";
2
+ export interface DialogProps {
3
+ /** 열림 상태(제어). 주면 `onOpenChange`로 바꾼다. */
4
+ open?: boolean;
5
+ /** 처음 열림 상태(비제어). 기본값은 `false`다. */
6
+ defaultOpen?: boolean;
7
+ /** 열림 상태가 바뀌려 할 때 새 값으로 부른다. */
8
+ onOpenChange?: (open: boolean) => void;
9
+ /** `DialogTrigger`와 `DialogContent` */
10
+ children: ReactNode;
11
+ }
12
+ /**
13
+ * 트리거와 내용을 잇는 열림 상태. DOM 요소를 만들지 않는다.
14
+ * 안에 `DialogTrigger`(없어도 된다. `open`으로 제어해 Menu 항목 등에서 열 수 있다)와 `DialogContent`를 둔다.
15
+ */
16
+ export declare function Dialog(props: DialogProps): ReactElement;
17
+ export interface DialogTriggerProps extends ComponentProps<"button"> {
18
+ /**
19
+ * 다른 요소로 렌더한다. 예: `render={<Button variant="outline" />}`, `render={<IconButton aria-label="삭제" />}`.
20
+ * props, ref, className, 이벤트 핸들러를 그 요소에 병합한다. 기본은 class 없는 `<button type="button">`이다.
21
+ */
22
+ render?: ReactElement;
23
+ }
24
+ /**
25
+ * Dialog를 여는 버튼. 누르면(마우스, 터치, Enter, Space) 연다. 열린 동안은 바깥이 inert라 다시 누를 수 없다.
26
+ * `aria-haspopup="dialog"`, `aria-expanded`, 열렸을 때 `aria-controls`와 `data-open`이 붙는다.
27
+ */
28
+ export declare function DialogTrigger({ render, ref, id, className, ...props }: DialogTriggerProps): ReactElement;
29
+ /** Dialog 최대 폭. `sm` 24rem(384px), `md` 32rem(512px), `lg` 40rem(640px)이다. */
30
+ export type DialogSize = "sm" | "md" | "lg";
31
+ export interface DialogContentProps extends Omit<ComponentProps<"div">, "id" | "role"> {
32
+ /** 최대 폭. 기본값은 `md`(32rem)다. 화면이 좁으면 화면 폭 − 32px까지 줄어든다. */
33
+ size?: DialogSize;
34
+ /** 닫기 버튼(IconButton)의 이름. 기본값은 `"닫기"`다. AlertDialog에는 닫기 버튼이 없어 쓰지 않는다. */
35
+ closeLabel?: string;
36
+ }
37
+ /**
38
+ * 화면 가운데 뜨는 모달 내용(`role="dialog"`, AlertDialog 안에서는 `role="alertdialog"`).
39
+ * 열릴 때만 `document.body`에 portal하고, 반투명 막(`bg-overlay`)과 함께 `z-modal`로 쌓는다.
40
+ * 등장은 opacity + scale 0.96 → 1(`normal`), 퇴장은 opacity + scale 0.98(`fast`)이다. 움직임 줄이기에서는 opacity만 바뀐다.
41
+ * Dialog에는 끝 위쪽에 닫기 버튼(IconButton)이 있고 바깥 막을 누르면 닫힌다. AlertDialog는 둘 다 없다(Esc는 닫는다).
42
+ */
43
+ export declare function DialogContent(props: DialogContentProps): ReactElement | null;
44
+ export type DialogTitleProps = ComponentProps<"h2">;
45
+ /**
46
+ * Dialog 제목(`<h2>`, `text-heading-sm`). 있으면 dialog의 `aria-labelledby`가 가리켜 이름이 된다.
47
+ * Dialog에서는 끝쪽 닫기 버튼과 겹치지 않게 끝 여백(36px)을 둔다.
48
+ */
49
+ export declare function DialogTitle({ id, className, ...props }: DialogTitleProps): ReactElement;
50
+ export type DialogDescriptionProps = ComponentProps<"p">;
51
+ /**
52
+ * Dialog 설명(`<p>`, `text-muted`). 있으면 dialog의 `aria-describedby`가 가리킨다. AlertDialog에서는 알릴 내용을 여기에 쓴다.
53
+ * 목록·여러 문단처럼 구조가 있는 내용은 한 줄로 읽히므로 이 요소 밖에 둔다(APG Dialog).
54
+ */
55
+ export declare function DialogDescription({ id, className, ...props }: DialogDescriptionProps): ReactElement;
56
+ export type DialogFooterProps = ComponentProps<"div">;
57
+ /** 동작 버튼 줄. 끝쪽에 맞추고 버튼 사이는 8px이다. 앞에 덜 위험한 동작(취소)을, 끝에 주 동작을 둔다. */
58
+ export declare function DialogFooter({ className, ...props }: DialogFooterProps): ReactElement;
59
+ export interface DialogCloseProps extends ComponentProps<"button"> {
60
+ /**
61
+ * 다른 요소로 렌더한다. 예: `render={<Button variant="ghost" color="neutral" />}`.
62
+ * 기본은 class 없는 `<button type="button">`이다.
63
+ */
64
+ render?: ReactElement;
65
+ }
66
+ /**
67
+ * 누르면 Dialog를 닫는 버튼. `onClick`을 먼저 부르고, 그 안에서 `event.preventDefault()`를 부르면 닫지 않는다.
68
+ * 닫히면 포커스는 열기 전 요소로 돌아간다.
69
+ */
70
+ export declare function DialogClose({ render, onClick, className, ...props }: DialogCloseProps): ReactElement;