@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/Radio.js ADDED
@@ -0,0 +1,67 @@
1
+ "use client";
2
+
3
+ import { RadioGroupContext } 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 } from "react";
9
+ import { CircleIcon } from "@tide-design/icons";
10
+
11
+ // src/Radio.tsx
12
+ const boxClass = {
13
+ sm: "size-4 rounded-full",
14
+ md: "size-5 rounded-full"
15
+ };
16
+ /** 가운데 점 크기(px). 원 아이콘을 채워 그리고 선 두께 2px이 더해진다. */
17
+ const dotSize = {
18
+ sm: 6,
19
+ md: 8
20
+ };
21
+ /**
22
+ * 네이티브 라디오 버튼. 보통 `RadioGroup` 안에 두고, 묶음이 `name`과 선택 값을 정한다.
23
+ * 묶음 밖에서는 `name`·`checked`/`defaultChecked`·`onChange`를 직접 준다.
24
+ */
25
+ function Radio({ value, children, size = "md", color = "primary", invalid, id, disabled, required, name, checked, defaultChecked, onChange, className, style, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }) {
26
+ const group = use(RadioGroupContext);
27
+ const control = useFieldControl({
28
+ id,
29
+ invalid: invalid ?? group?.invalid,
30
+ disabled: disabled ?? group?.disabled,
31
+ required: required ?? (group?.required || void 0),
32
+ "aria-describedby": ariaDescribedBy,
33
+ "aria-invalid": ariaInvalid
34
+ });
35
+ const selection = group?.value !== void 0 ? { checked: group.value === value } : group?.defaultValue !== void 0 ? { defaultChecked: group.defaultValue === value } : checked !== void 0 ? { checked } : { defaultChecked };
36
+ const handleChange = (event) => {
37
+ onChange?.(event);
38
+ if (event.target.checked) group?.onValueChange?.(value);
39
+ };
40
+ return /* @__PURE__ */ jsxs("label", {
41
+ "data-color": color,
42
+ "data-disabled": control.disabled ? "" : void 0,
43
+ "data-invalid": control["data-invalid"],
44
+ style,
45
+ className: cn(choiceRootClass, choiceTextClass[size], className),
46
+ children: [/* @__PURE__ */ jsxs("span", {
47
+ className: choiceAreaClass,
48
+ children: [/* @__PURE__ */ jsx("input", {
49
+ ...props,
50
+ ...control,
51
+ ...selection,
52
+ type: "radio",
53
+ name: name ?? group?.name,
54
+ value,
55
+ onChange: handleChange,
56
+ className: cn(boxClass[size], choiceInputClass)
57
+ }), /* @__PURE__ */ jsx(CircleIcon, {
58
+ size: dotSize[size],
59
+ fill: "currentColor",
60
+ "data-mark": "dot",
61
+ className: cn(choiceMarkClass, "peer-checked:block")
62
+ })]
63
+ }), children === void 0 || children === null ? null : /* @__PURE__ */ jsx("span", { children })]
64
+ });
65
+ }
66
+
67
+ export { Radio };
@@ -0,0 +1,28 @@
1
+ import { ChoiceOrientation } from "./CheckboxGroup.js";
2
+ import { ComponentProps, ReactElement } from "react";
3
+ export interface RadioGroupProps extends Omit<ComponentProps<"div">, "defaultValue"> {
4
+ /** 안의 Radio가 함께 쓰는 `name`. form에 이 이름으로 제출된다. 주지 않으면 자동으로 만든다. */
5
+ name?: string;
6
+ /** 선택된 Radio의 값(제어). `onValueChange`와 함께 쓴다. */
7
+ value?: string;
8
+ /** 처음 선택된 Radio의 값(비제어). */
9
+ defaultValue?: string;
10
+ /** 선택이 바뀌면 새 값 하나로 불린다. */
11
+ onValueChange?: (value: string) => void;
12
+ /** 항목을 세로(`vertical`)로 쌓거나 가로(`horizontal`)로 늘어놓는다. 기본값은 `vertical`이다. 화살표 키는 둘 다 동작한다. */
13
+ orientation?: ChoiceOrientation;
14
+ /**
15
+ * 오류 상태. 안의 Radio마다 `aria-invalid="true"`가 붙고, 묶음에 `data-invalid`가 붙는다.
16
+ * Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
17
+ */
18
+ invalid?: boolean;
19
+ /** 안의 Radio를 모두 비활성으로 만든다. Field 안에서는 Field의 값을 따른다. */
20
+ disabled?: boolean;
21
+ /** 하나를 꼭 골라야 한다. 안의 Radio에 네이티브 `required`가 붙고 묶음에 `aria-required`가 붙는다. */
22
+ required?: boolean;
23
+ }
24
+ /**
25
+ * Radio 여러 개를 하나의 이름과 선택 값으로 묶는다. `<Field label group>` 안에 두면 label이 묶음의 이름,
26
+ * 설명·오류가 묶음의 설명이 된다. Field 밖에서는 `aria-label`이나 `aria-labelledby`를 준다.
27
+ */
28
+ export declare function RadioGroup({ name, value, defaultValue, onValueChange, orientation, invalid, disabled, required, id, className, children, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }: RadioGroupProps): ReactElement;
@@ -0,0 +1,50 @@
1
+ "use client";
2
+
3
+ import { orientationClass } from "./CheckboxGroup.js";
4
+ import { RadioGroupContext, useChoiceGroup } from "./choice-group.js";
5
+ import { cn } from "./cn.js";
6
+ import { FieldContext } from "./field-context.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { useId } from "react";
9
+
10
+ // src/RadioGroup.tsx
11
+ /**
12
+ * Radio 여러 개를 하나의 이름과 선택 값으로 묶는다. `<Field label group>` 안에 두면 label이 묶음의 이름,
13
+ * 설명·오류가 묶음의 설명이 된다. Field 밖에서는 `aria-label`이나 `aria-labelledby`를 준다.
14
+ */
15
+ function RadioGroup({ name, value, defaultValue, onValueChange, orientation = "vertical", invalid, disabled, required, id, className, children, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }) {
16
+ const autoName = useId();
17
+ const connection = useChoiceGroup({
18
+ id,
19
+ invalid,
20
+ disabled,
21
+ required,
22
+ "aria-labelledby": ariaLabelledBy,
23
+ "aria-describedby": ariaDescribedBy
24
+ });
25
+ const state = {
26
+ name: name ?? autoName,
27
+ value,
28
+ defaultValue,
29
+ onValueChange,
30
+ invalid: connection.invalid,
31
+ disabled: connection.disabled,
32
+ required: connection.required
33
+ };
34
+ return /* @__PURE__ */ jsx("div", {
35
+ role: "radiogroup",
36
+ "aria-required": connection.required || void 0,
37
+ ...props,
38
+ ...connection.rootProps,
39
+ className: cn(orientationClass[orientation], className),
40
+ children: /* @__PURE__ */ jsx(FieldContext, {
41
+ value: null,
42
+ children: /* @__PURE__ */ jsx(RadioGroupContext, {
43
+ value: state,
44
+ children
45
+ })
46
+ })
47
+ });
48
+ }
49
+
50
+ export { RadioGroup };
@@ -0,0 +1,62 @@
1
+ import { InputSize } from "./input-style.js";
2
+ import { ListBoxOptionProps, ListBoxSectionProps } from "./listbox.js";
3
+ import { ComponentProps, ReactElement, ReactNode } from "react";
4
+ export interface SelectProps extends Omit<ComponentProps<"button">, "value" | "defaultValue" | "onChange" | "type" | "size" | "children" | "name" | "form"> {
5
+ /** 고른 값(제어). 고른 옵션의 `value`다. `null`이면 아무것도 고르지 않은 상태다. 주면 `onValueChange`로 바꾼다. */
6
+ value?: string | null;
7
+ /** 처음 고른 값(비제어). 주지 않으면 아무것도 고르지 않은 상태로 시작한다. 폼을 reset하면 이 값으로 돌아간다. */
8
+ defaultValue?: string;
9
+ /** 사용자가 다른 옵션을 고르면 그 옵션의 `value`로 부른다. */
10
+ onValueChange?: (value: string) => void;
11
+ /** 목록 열림 상태(제어). 주면 `onOpenChange`로 바꾼다. */
12
+ open?: boolean;
13
+ /** 처음 목록 열림 상태(비제어). 기본값은 `false`다. */
14
+ defaultOpen?: boolean;
15
+ /** 목록 열림 상태가 바뀌려 할 때 새 값으로 부른다. 옵션을 골라 닫힐 때도 부른다. */
16
+ onOpenChange?: (open: boolean) => void;
17
+ /** 폼 제출 이름. 숨은 `<select>`에 붙어 고른 값이 이 이름으로 제출된다(트리거 버튼에는 붙지 않는다). */
18
+ name?: string;
19
+ /** 숨은 `<select>`가 속할 `<form>`의 id. 폼 밖에 둘 때 쓴다. */
20
+ form?: string;
21
+ /** 브라우저 자동 완성 힌트. 숨은 `<select>`에 붙는다. */
22
+ autoComplete?: string;
23
+ /** 아무것도 고르지 않았을 때 트리거에 보이는 글자. 기본값은 `"선택하세요"`다. */
24
+ placeholder?: string;
25
+ /** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Input·Button과 높이가 같다. 기본값은 `md`다. */
26
+ size?: InputSize;
27
+ /**
28
+ * 오류 상태. 트리거에 `aria-invalid="true"`와 `data-invalid`가 붙고 경계가 danger 색이 된다.
29
+ * Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
30
+ */
31
+ invalid?: boolean;
32
+ /**
33
+ * 필수. 고르지 않고 폼을 제출하면 제출이 막히고 트리거로 포커스가 오며 오류 상태가 된다(브라우저 오류 말풍선은
34
+ * 없다). 메시지는 Field의 `error`로 앱이 보여 준다. Field 안에서는 Field의 값을 따른다.
35
+ */
36
+ required?: boolean;
37
+ /** `SelectItem`과 `SelectSection`. 이 요소들을 바로 아래(또는 Fragment·배열 안)에 둔다. */
38
+ children?: ReactNode;
39
+ }
40
+ /**
41
+ * 값 하나를 고르는 입력. 트리거를 누르거나(마우스는 누르는 순간) Enter·Space·↓·↑로 목록을 열고, 화살표·Home/End·
42
+ * 영문 글자로 옵션을 옮겨 Enter·Space·누름으로 고른다. 닫힌 채로 글자를 치면 바로 그 옵션을 고른다.
43
+ * 고르면 닫히고 포커스는 트리거로 돌아온다. Esc·바깥 누름·Tab으로도 닫힌다.
44
+ * Field 안에 두면 label·설명·오류가 자동으로 연결되고, `name`을 주면 고른 값이 폼에 제출된다.
45
+ * 상태는 `data-open`(트리거·목록), `data-invalid`(트리거), 네이티브 `:disabled`(트리거),
46
+ * `data-highlighted`·`data-selected`·`data-disabled`(옵션)로 노출한다.
47
+ */
48
+ export declare function Select({ value, defaultValue, onValueChange, open, defaultOpen, onOpenChange, name, form, autoComplete, placeholder, size, invalid, disabled, required, id, ref, className, children, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }: SelectProps): ReactElement;
49
+ export interface SelectItemProps extends ListBoxOptionProps {}
50
+ /**
51
+ * Select의 옵션(`role="option"`). `Select`나 `SelectSection` 바로 안에 둔다. `value`가 고른 값이고 폼에 제출된다.
52
+ * 내용(아이콘과 글자)은 고르면 트리거에도 보인다. 키보드 위치와 마우스를 올린 옵션은 highlight(primary subtle 배경,
53
+ * primary 글자), 고른 옵션은 neutral subtle-active 배경과 끝의 체크 아이콘이다.
54
+ * 상태는 `data-highlighted`, `data-selected`, `data-disabled`로 노출한다.
55
+ */
56
+ export declare function SelectItem(_props: SelectItemProps): null;
57
+ export interface SelectSectionProps extends ListBoxSectionProps {}
58
+ /**
59
+ * 옵션 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
60
+ * 앞뒤 다른 옵션·묶음과의 사이에 구분선이 그려진다.
61
+ */
62
+ export declare function SelectSection(_props: SelectSectionProps): null;
package/dist/Select.js ADDED
@@ -0,0 +1,169 @@
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, useCloseOnTab, useOverlayPresence, useOverlayTheme, usePopoverOverlay } from "./overlay.js";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ import { use, useLayoutEffect, useMemo, useRef } from "react";
12
+ import { ChevronDownIcon } from "@tide-design/icons";
13
+ import { DismissButton, HiddenSelect, mergeProps, mergeRefs, useButton, useListBox, useSelect } from "react-aria";
14
+ import { useSelectState } from "react-stately";
15
+
16
+ // src/Select.tsx
17
+ const triggerClass = "group inline-flex items-center justify-between gap-2 text-start";
18
+ const valueClass = "min-w-0 flex-1 truncate [&>svg]:me-2 [&>svg]:inline-block [&>svg]:size-4 [&>svg]:align-[-0.125em]";
19
+ const placeholderClass = "text-muted group-disabled:text-disabled";
20
+ const chevronClass = "shrink-0 text-muted group-disabled:text-disabled";
21
+ /**
22
+ * 값 하나를 고르는 입력. 트리거를 누르거나(마우스는 누르는 순간) Enter·Space·↓·↑로 목록을 열고, 화살표·Home/End·
23
+ * 영문 글자로 옵션을 옮겨 Enter·Space·누름으로 고른다. 닫힌 채로 글자를 치면 바로 그 옵션을 고른다.
24
+ * 고르면 닫히고 포커스는 트리거로 돌아온다. Esc·바깥 누름·Tab으로도 닫힌다.
25
+ * Field 안에 두면 label·설명·오류가 자동으로 연결되고, `name`을 주면 고른 값이 폼에 제출된다.
26
+ * 상태는 `data-open`(트리거·목록), `data-invalid`(트리거), 네이티브 `:disabled`(트리거),
27
+ * `data-highlighted`·`data-selected`·`data-disabled`(옵션)로 노출한다.
28
+ */
29
+ function Select({ value, defaultValue, onValueChange, open, defaultOpen, onOpenChange, name, form, autoComplete, placeholder = "선택하세요", size = "md", invalid, disabled, required, id, ref, className, children, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }) {
30
+ const field = use(FieldContext);
31
+ const control = useFieldControl({
32
+ id,
33
+ invalid,
34
+ disabled,
35
+ required,
36
+ "aria-describedby": ariaDescribedBy,
37
+ "aria-invalid": ariaInvalid
38
+ });
39
+ const isDisabled = control.disabled ?? false;
40
+ const isRequired = control.required ?? false;
41
+ const items = useMemo(() => resolveCollectionChildren(children), [children]);
42
+ const state = useSelectState({
43
+ children: items,
44
+ value,
45
+ defaultValue,
46
+ onChange: (key) => {
47
+ if (key != null) onValueChange?.(String(key));
48
+ },
49
+ isOpen: open,
50
+ defaultOpen,
51
+ onOpenChange,
52
+ isDisabled,
53
+ isRequired,
54
+ validationBehavior: "native"
55
+ });
56
+ const triggerRef = useRef(null);
57
+ const { triggerProps, valueProps, menuProps, hiddenSelectProps, isInvalid } = useSelect({
58
+ id: control.id,
59
+ "aria-label": ariaLabel,
60
+ "aria-labelledby": ariaLabelledBy ?? field?.labelId,
61
+ isDisabled,
62
+ isRequired,
63
+ validationBehavior: "native",
64
+ name,
65
+ form,
66
+ autoComplete
67
+ }, state, triggerRef);
68
+ const { buttonProps } = useButton(triggerProps, triggerRef);
69
+ const mergedRef = useMemo(() => mergeRefs(ref, triggerRef), [ref, triggerRef]);
70
+ const showInvalid = control["data-invalid"] === "" || isInvalid;
71
+ const selected = state.selectedItem;
72
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
73
+ /* @__PURE__ */ jsxs("button", {
74
+ ...mergeProps(props, buttonProps),
75
+ ref: mergedRef,
76
+ "aria-describedby": control["aria-describedby"],
77
+ "aria-invalid": showInvalid ? true : control["aria-invalid"],
78
+ "data-invalid": showInvalid ? "" : void 0,
79
+ "data-open": state.isOpen ? "" : void 0,
80
+ className: cn(inputSizeClass[size], inputBaseClass, triggerClass, className),
81
+ children: [/* @__PURE__ */ jsx("span", {
82
+ ...valueProps,
83
+ className: cn(valueClass, !selected && placeholderClass),
84
+ children: selected ? selected.rendered : placeholder
85
+ }), /* @__PURE__ */ jsx(ChevronDownIcon, {
86
+ size: 16,
87
+ className: chevronClass
88
+ })]
89
+ }),
90
+ /* @__PURE__ */ jsx(HiddenSelect, {
91
+ ...hiddenSelectProps,
92
+ autoComplete
93
+ }),
94
+ /* @__PURE__ */ jsx(SelectPopover, {
95
+ state,
96
+ triggerRef,
97
+ menuProps
98
+ })
99
+ ] });
100
+ }
101
+ /** 목록을 DOM에 둘지 정하고 portal한다. 닫혀도 퇴장 전환이 끝날 때까지 남긴다(ADR 0018). */
102
+ function SelectPopover(props) {
103
+ const popoverRef = useRef(null);
104
+ if (!useOverlayPresence(props.state.isOpen, popoverRef)) return null;
105
+ return /* @__PURE__ */ jsx(OverlayPortal, {
106
+ isExiting: !props.state.isOpen,
107
+ children: /* @__PURE__ */ jsx(SelectPopoverInner, {
108
+ ...props,
109
+ popoverRef
110
+ })
111
+ });
112
+ }
113
+ /**
114
+ * 목록 표면(`listPopupClass`)과 그 안의 `role="listbox"`. 트리거 아래 시작 끝에 4px 떨어져 붙고(Menu와 같다),
115
+ * 폭은 트리거보다 좁지 않다.
116
+ */
117
+ function SelectPopoverInner({ state, triggerRef, menuProps, popoverRef }) {
118
+ const listRef = useRef(null);
119
+ useOverlayTheme(triggerRef, popoverRef);
120
+ useLayoutEffect(() => {
121
+ const popover = popoverRef.current;
122
+ const width = triggerRef.current?.offsetWidth;
123
+ if (popover && width) popover.style.minWidth = `${width}px`;
124
+ }, [triggerRef, popoverRef]);
125
+ const { overlayProps } = usePopoverOverlay({
126
+ triggerRef,
127
+ popoverRef,
128
+ placement: "bottom start",
129
+ offset: 4
130
+ }, state);
131
+ const { listBoxProps } = useListBox(menuProps, state, listRef);
132
+ useCloseOnTab(popoverRef, state.close);
133
+ return /* @__PURE__ */ jsxs("div", {
134
+ ...overlayProps,
135
+ ref: popoverRef,
136
+ "data-open": state.isOpen ? "" : void 0,
137
+ className: listPopupClass,
138
+ children: [
139
+ /* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close }),
140
+ /* @__PURE__ */ jsx("div", {
141
+ ...listBoxProps,
142
+ ref: listRef,
143
+ className: "outline-none",
144
+ children: /* @__PURE__ */ jsx(ListBoxNodes, { state })
145
+ }),
146
+ /* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close })
147
+ ]
148
+ });
149
+ }
150
+ /**
151
+ * Select의 옵션(`role="option"`). `Select`나 `SelectSection` 바로 안에 둔다. `value`가 고른 값이고 폼에 제출된다.
152
+ * 내용(아이콘과 글자)은 고르면 트리거에도 보인다. 키보드 위치와 마우스를 올린 옵션은 highlight(primary subtle 배경,
153
+ * primary 글자), 고른 옵션은 neutral subtle-active 배경과 끝의 체크 아이콘이다.
154
+ * 상태는 `data-highlighted`, `data-selected`, `data-disabled`로 노출한다.
155
+ */
156
+ function SelectItem(_props) {
157
+ return null;
158
+ }
159
+ asCollectionComponent(SelectItem, valueItemCollectionNode);
160
+ /**
161
+ * 옵션 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
162
+ * 앞뒤 다른 옵션·묶음과의 사이에 구분선이 그려진다.
163
+ */
164
+ function SelectSection(_props) {
165
+ return null;
166
+ }
167
+ asCollectionComponent(SelectSection, sectionCollectionNode);
168
+
169
+ export { Select, SelectItem, SelectSection };
@@ -0,0 +1,18 @@
1
+ import { ComponentProps, ReactElement } from "react";
2
+ /** Separator의 방향 */
3
+ type SeparatorOrientation = "horizontal" | "vertical";
4
+ export interface SeparatorProps extends Omit<ComponentProps<"hr">, "children" | "role"> {
5
+ /** `horizontal`(기본값)은 위아래 내용을, `vertical`은 한 줄 안의 양옆 내용을 나눈다. */
6
+ orientation?: SeparatorOrientation;
7
+ /**
8
+ * 보기만 나누는 선이면 `true`. `role="none"`이 붙어 보조 기술에서 빠진다. 기본값은 `false`(separator 역할)다.
9
+ * 내용의 주제가 바뀌는 곳이면 `false`로 둔다.
10
+ */
11
+ decorative?: boolean;
12
+ }
13
+ /**
14
+ * 내용 묶음 사이를 선으로 나눈다. 기본은 의미 구분(separator 역할)이고, `decorative`면 보조 기술에서 빠진다.
15
+ * 서버 컴포넌트로 쓸 수 있다.
16
+ */
17
+ export declare function Separator({ orientation, decorative, className, ...props }: SeparatorProps): ReactElement;
18
+ export {};
@@ -0,0 +1,24 @@
1
+ import { cn } from "./cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ // src/Separator.tsx
5
+ const orientationClass = {
6
+ horizontal: "h-0 w-full border-t",
7
+ vertical: "h-auto w-0 self-stretch border-s"
8
+ };
9
+ const baseClass = "m-0 shrink-0 border-0 border-default";
10
+ /**
11
+ * 내용 묶음 사이를 선으로 나눈다. 기본은 의미 구분(separator 역할)이고, `decorative`면 보조 기술에서 빠진다.
12
+ * 서버 컴포넌트로 쓸 수 있다.
13
+ */
14
+ function Separator({ orientation = "horizontal", decorative = false, className, ...props }) {
15
+ return /* @__PURE__ */ jsx("hr", {
16
+ ...props,
17
+ role: decorative ? "none" : void 0,
18
+ "aria-orientation": !decorative && orientation === "vertical" ? "vertical" : void 0,
19
+ "data-orientation": orientation,
20
+ className: cn(baseClass, orientationClass[orientation], className)
21
+ });
22
+ }
23
+
24
+ export { Separator };
@@ -0,0 +1,24 @@
1
+ import { Size } from "./types.js";
2
+ import { ComponentProps, ReactElement } from "react";
3
+ /** 원의 size. Avatar size와 같은 24·32·40·48px다(Avatar 자리를 그대로 채운다). */
4
+ type SkeletonCircleSize = Extract<Size, "xs" | "sm" | "md" | "lg">;
5
+ interface SkeletonBaseProps extends Omit<ComponentProps<"div">, "children" | "aria-hidden"> {}
6
+ /** `variant`에 따라 받는 props가 다르다. `size`는 원(`circle`)에만 있다. */
7
+ export type SkeletonProps = SkeletonBaseProps & ({
8
+ /**
9
+ * 모양. `text`는 글 한 줄(높이 1em, 너비 100%), `rect`는 사각형 영역(너비 100%, 높이는 `className`으로 준다),
10
+ * `circle`은 원(크기는 `size`). 기본값은 `text`다.
11
+ */
12
+ variant?: "text" | "rect";
13
+ size?: never;
14
+ } | {
15
+ variant: "circle";
16
+ /** 원 크기. `xs` 24px, `sm` 32px, `md` 40px, `lg` 48px(Avatar와 같다). 기본값은 `md`다. */
17
+ size?: SkeletonCircleSize;
18
+ });
19
+ /**
20
+ * 내용이 오기 전 자리를 표시한다. 스크린 리더에는 읽히지 않는다(`aria-hidden`).
21
+ * 불러오는 중이라는 사실은 앱이 영역의 `aria-busy`나 보이는 문구로 알린다. 서버 컴포넌트로 쓸 수 있다.
22
+ */
23
+ export declare function Skeleton({ variant, size, className, ...props }: SkeletonProps): ReactElement;
24
+ export {};
@@ -0,0 +1,29 @@
1
+ import { cn } from "./cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ // src/Skeleton.tsx
5
+ const variantClass = {
6
+ text: "h-[1em] w-full rounded-sm",
7
+ rect: "w-full rounded-md",
8
+ circle: "shrink-0 rounded-full"
9
+ };
10
+ const circleSizeClass = {
11
+ xs: "size-6",
12
+ sm: "size-8",
13
+ md: "size-10",
14
+ lg: "size-12"
15
+ };
16
+ const baseClass = "block border border-transparent bg-neutral-subtle-active motion-safe:animate-pulse";
17
+ /**
18
+ * 내용이 오기 전 자리를 표시한다. 스크린 리더에는 읽히지 않는다(`aria-hidden`).
19
+ * 불러오는 중이라는 사실은 앱이 영역의 `aria-busy`나 보이는 문구로 알린다. 서버 컴포넌트로 쓸 수 있다.
20
+ */
21
+ function Skeleton({ variant = "text", size, className, ...props }) {
22
+ return /* @__PURE__ */ jsx("div", {
23
+ ...props,
24
+ "aria-hidden": "true",
25
+ className: cn(baseClass, variantClass[variant], variant === "circle" ? circleSizeClass[size ?? "md"] : void 0, className)
26
+ });
27
+ }
28
+
29
+ export { Skeleton };
@@ -0,0 +1,20 @@
1
+ import { Size } from "./types.js";
2
+ import { ComponentProps, ReactElement } from "react";
3
+ /** Spinner의 size. 공통 size 4개를 모두 받는다. */
4
+ type SpinnerSize = Extract<Size, "xs" | "sm" | "md" | "lg">;
5
+ export interface SpinnerProps extends Omit<ComponentProps<"svg">, "children"> {
6
+ /**
7
+ * 같은 size의 Component(Button 등) 안 텍스트 옆 아이콘과 같은 크기다.
8
+ * `xs`·`sm` 14px, `md` 16px, `lg` 20px. 기본값은 `md`다.
9
+ */
10
+ size?: SpinnerSize;
11
+ /** 접근 가능한 이름. 기본값은 `"로딩 중"`이다. 무엇을 불러오는지 적으면 더 좋다. */
12
+ "aria-label"?: string;
13
+ }
14
+ /**
15
+ * 로딩 중임을 알리는 회전 표시. 역할은 `status`이고 접근 가능한 이름이 기본으로 붙는다.
16
+ * 회전은 keyframe(`animate-spin`)이고 움직임 줄이기에서도 멈추지 않는다(로딩 여부 자체가 정보다).
17
+ * 색은 `currentColor`라 주변 글자색을 따른다. 서버 컴포넌트로 쓸 수 있다.
18
+ */
19
+ export declare function Spinner({ size, className, "aria-label": ariaLabel, ...props }: SpinnerProps): ReactElement;
20
+ export {};
@@ -0,0 +1,35 @@
1
+ import { cn } from "./cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ // src/Spinner.tsx
5
+ const sizeClass = {
6
+ xs: "size-3.5",
7
+ sm: "size-3.5",
8
+ md: "size-4",
9
+ lg: "size-5"
10
+ };
11
+ /**
12
+ * 로딩 중임을 알리는 회전 표시. 역할은 `status`이고 접근 가능한 이름이 기본으로 붙는다.
13
+ * 회전은 keyframe(`animate-spin`)이고 움직임 줄이기에서도 멈추지 않는다(로딩 여부 자체가 정보다).
14
+ * 색은 `currentColor`라 주변 글자색을 따른다. 서버 컴포넌트로 쓸 수 있다.
15
+ */
16
+ function Spinner({ size = "md", className, "aria-label": ariaLabel = "로딩 중", ...props }) {
17
+ return /* @__PURE__ */ jsx("svg", {
18
+ role: "status",
19
+ "aria-label": ariaLabel,
20
+ viewBox: "0 0 24 24",
21
+ fill: "none",
22
+ focusable: "false",
23
+ ...props,
24
+ className: cn("shrink-0 animate-spin", sizeClass[size], className),
25
+ children: /* @__PURE__ */ jsx("path", {
26
+ d: "M12 3a9 9 0 1 1-9 9",
27
+ stroke: "currentColor",
28
+ strokeWidth: 2,
29
+ strokeLinecap: "round",
30
+ vectorEffect: "non-scaling-stroke"
31
+ })
32
+ });
33
+ }
34
+
35
+ export { Spinner };
@@ -0,0 +1,30 @@
1
+ import { Role, Size } from "./types.js";
2
+ import { CSSProperties, ComponentProps, ReactElement, ReactNode } from "react";
3
+ /** Switch의 size. `xs`는 track이 너무 작아 받지 않는다. */
4
+ type SwitchSize = Extract<Size, "sm" | "md" | "lg">;
5
+ export interface SwitchProps extends Omit<ComponentProps<"input">, "type" | "size" | "color" | "role" | "children"> {
6
+ /** 스위치 옆에 보이는 label. 스위치의 이름이 된다. Field 안에서는 Field의 `label`을 쓰고 비워 둔다. */
7
+ children?: ReactNode;
8
+ /** track 크기 `sm` 28×16px, `md` 36×20px, `lg` 44×24px. label 텍스트 스타일(Checkbox·Radio와 같은 `body-sm`/`body-md`/`body-lg`)도 함께 바뀐다. 기본값은 `md`다. */
9
+ size?: SwitchSize;
10
+ /**
11
+ * 켜졌을 때 track 색. Role(Tide Role 6개와 앱이 `RoleRegistry`에 더한 Role)을 받는다. 기본값은 `primary`다.
12
+ * 루트에 `data-color`로 붙어 accent 색을 정한다. 바깥 요소의 색을 물려받지 않는다.
13
+ */
14
+ color?: Role;
15
+ /**
16
+ * 오류 상태. `aria-invalid="true"`와 `data-invalid`가 붙고 꺼진 track 경계가 danger 색이 된다.
17
+ * Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
18
+ */
19
+ invalid?: boolean;
20
+ /** 루트 `<label>`의 class. 기본 class를 이긴다. track과 thumb 모양은 바꾸지 않는다. */
21
+ className?: string;
22
+ /** 루트 `<label>`의 style */
23
+ style?: CSSProperties;
24
+ }
25
+ /**
26
+ * 켜고 끄는 설정을 바꾸는 스위치. 네이티브 체크박스라 form 제출이 그대로 되고, 스크린리더는 「스위치」로 읽는다.
27
+ * `children`이 label이 된다. Field 안에 두면 Field의 label·설명·오류가 연결된다.
28
+ */
29
+ export declare function Switch({ children, size, color, invalid, id, disabled, required, className, style, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: SwitchProps): ReactElement;
30
+ export {};
package/dist/Switch.js ADDED
@@ -0,0 +1,65 @@
1
+ "use client";
2
+
3
+ import { cn } from "./cn.js";
4
+ import { useFieldControl } from "./field-context.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+
7
+ // src/Switch.tsx
8
+ /** 루트 높이는 최소 24px라 track이 작아도 누르는 영역이 24×24px 이상이다. */
9
+ const rootSizeClass = {
10
+ sm: "gap-1.5 text-body-sm",
11
+ md: "gap-2 text-body-md",
12
+ lg: "gap-2.5 text-body-lg"
13
+ };
14
+ /** track 크기(border 1px 포함). thumb은 track 안쪽에서 2px 떨어진다. */
15
+ const trackSizeClass = {
16
+ sm: "h-4 w-7",
17
+ md: "h-5 w-9",
18
+ lg: "h-6 w-11"
19
+ };
20
+ /** thumb 크기와 켜졌을 때 이동 거리(track 폭 - border 2px - 여백 4px - thumb 크기). RTL에서는 반대로 움직인다. */
21
+ const thumbSizeClass = {
22
+ sm: "size-2.5 peer-checked:translate-x-3 rtl:peer-checked:-translate-x-3",
23
+ md: "size-3.5 peer-checked:translate-x-4 rtl:peer-checked:-translate-x-4",
24
+ lg: "size-4.5 peer-checked:translate-x-5 rtl:peer-checked:-translate-x-5"
25
+ };
26
+ const trackClass = "peer m-0 shrink-0 cursor-pointer appearance-none rounded-full border border-strong bg-transparent transition-colors aria-invalid:border-danger focus-visible:focus-ring checked:enabled:border-accent checked:enabled:bg-accent-solid group-hover/switch:checked:enabled:bg-accent-solid-hover group-active/switch:checked:enabled:bg-accent-solid-active group-hover/switch:not-checked:enabled:bg-accent-subtle group-active/switch:not-checked:enabled:bg-accent-subtle-active disabled:cursor-not-allowed disabled:border-default disabled:bg-disabled";
27
+ const thumbClass = "pointer-events-none absolute start-0.75 top-0.75 rounded-full bg-current text-muted shadow-sm transition-colors motion-safe:transition-[color,background-color,translate] peer-checked:peer-enabled:text-accent-on-solid group-hover/switch:peer-enabled:peer-not-checked:text-accent group-active/switch:peer-enabled:peer-not-checked:text-accent peer-disabled:text-disabled";
28
+ const trackForcedClass = "forced-colors:forced-color-adjust-none forced-colors:[--tide-border-strong:CanvasText] forced-colors:[--tide-border-danger:CanvasText] forced-colors:[--tide-accent-border:Highlight] forced-colors:[--tide-accent-solid:Highlight] forced-colors:[--tide-accent-solid-hover:Highlight] forced-colors:[--tide-accent-solid-active:Highlight] forced-colors:[--tide-accent-subtle:Canvas] forced-colors:[--tide-accent-subtle-active:Canvas] forced-colors:[--tide-border-default:GrayText] forced-colors:[--tide-bg-disabled:Canvas] forced-colors:[--tide-outline-focus:Highlight]";
29
+ const thumbForcedClass = "forced-colors:forced-color-adjust-none forced-colors:[--tide-text-muted:CanvasText] forced-colors:[--tide-accent-text:CanvasText] forced-colors:[--tide-accent-on-solid:HighlightText] forced-colors:[--tide-text-disabled:GrayText]";
30
+ /**
31
+ * 켜고 끄는 설정을 바꾸는 스위치. 네이티브 체크박스라 form 제출이 그대로 되고, 스크린리더는 「스위치」로 읽는다.
32
+ * `children`이 label이 된다. Field 안에 두면 Field의 label·설명·오류가 연결된다.
33
+ */
34
+ function Switch({ children, size = "md", color = "primary", invalid, id, disabled, required, className, style, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }) {
35
+ const control = useFieldControl({
36
+ id,
37
+ invalid,
38
+ disabled,
39
+ required,
40
+ "aria-describedby": ariaDescribedBy,
41
+ "aria-invalid": ariaInvalid
42
+ });
43
+ return /* @__PURE__ */ jsxs("label", {
44
+ "data-color": color,
45
+ "data-disabled": control.disabled ? "" : void 0,
46
+ "data-invalid": control["data-invalid"],
47
+ style,
48
+ className: cn("group/switch inline-flex min-h-6 cursor-pointer items-center text-default select-none has-disabled:cursor-not-allowed has-disabled:text-disabled", rootSizeClass[size], className),
49
+ children: [/* @__PURE__ */ jsxs("span", {
50
+ className: "relative inline-flex shrink-0",
51
+ children: [/* @__PURE__ */ jsx("input", {
52
+ ...props,
53
+ ...control,
54
+ type: "checkbox",
55
+ role: "switch",
56
+ className: cn(trackSizeClass[size], trackClass, trackForcedClass)
57
+ }), /* @__PURE__ */ jsx("span", {
58
+ "aria-hidden": "true",
59
+ className: cn(thumbSizeClass[size], thumbClass, thumbForcedClass)
60
+ })]
61
+ }), children != null && children !== false ? /* @__PURE__ */ jsx("span", { children }) : null]
62
+ });
63
+ }
64
+
65
+ export { Switch };