@tide-design/components 0.0.0-placeholder → 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 -4
  96. package/README.md +0 -3
package/dist/Menu.js ADDED
@@ -0,0 +1,226 @@
1
+ "use client";
2
+
3
+ import { cn } from "./cn.js";
4
+ import { asCollectionComponent, itemCollectionNode, resolveCollectionChildren, sectionCollectionNode } from "./list-collection.js";
5
+ import { listHeadingClass, listItemClass, listPopupClass, listSeparatorClass } from "./list-style.js";
6
+ import { OverlayPortal, useCloseOnTab, useOverlayPresence, useOverlayTheme, usePopoverOverlay } from "./overlay.js";
7
+ import { renderElement } from "./render.js";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { createContext, createElement, use, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
10
+ import { mergeProps, mergeRefs, useMenu, useMenuItem, useMenuSection, useMenuTrigger, usePress } from "react-aria";
11
+ import { useMenuTriggerState, useTreeState } from "react-stately";
12
+
13
+ // src/Menu.tsx
14
+ const MenuContext = createContext(null);
15
+ function useMenuContext(part) {
16
+ const context = use(MenuContext);
17
+ if (!context) throw new Error(`${part}는 Menu 안에 둔다.`);
18
+ return context;
19
+ }
20
+ /**
21
+ * 트리거와 동작 목록을 잇는 열림 상태. DOM 요소를 만들지 않는다.
22
+ * 안에 `MenuTrigger` 하나와 `MenuContent` 하나를 둔다.
23
+ */
24
+ function Menu({ open, defaultOpen, onOpenChange, children }) {
25
+ const state = useMenuTriggerState({
26
+ isOpen: open,
27
+ defaultOpen,
28
+ onOpenChange
29
+ });
30
+ const triggerRef = useRef(null);
31
+ const { menuTriggerProps, menuProps } = useMenuTrigger({}, state, triggerRef);
32
+ const generatedTriggerId = useId();
33
+ const [triggerId, setTriggerId] = useState(generatedTriggerId);
34
+ const value = useMemo(() => ({
35
+ state,
36
+ triggerRef,
37
+ menuTriggerProps,
38
+ menuProps,
39
+ triggerId,
40
+ setTriggerId
41
+ }), [
42
+ state,
43
+ menuTriggerProps,
44
+ menuProps,
45
+ triggerId
46
+ ]);
47
+ return /* @__PURE__ */ jsx(MenuContext, {
48
+ value,
49
+ children
50
+ });
51
+ }
52
+ /**
53
+ * Menu를 여는 버튼. 마우스는 누르는 순간 열고, 키보드는 Enter·Space·↓로 열어 첫 항목에, ↑로 열어 마지막 항목에
54
+ * 위치한다. `aria-haspopup`, `aria-expanded`, 열렸을 때 `aria-controls`와 `data-open`이 붙는다.
55
+ */
56
+ function MenuTrigger({ render, ref, id, className, ...props }) {
57
+ const { state, triggerRef, menuTriggerProps, triggerId, setTriggerId } = useMenuContext("MenuTrigger");
58
+ const { onPressStart, onPress, preventFocusOnPress, id: _ariaId, isDisabled: _isDisabled, ...ariaProps } = menuTriggerProps;
59
+ const { pressProps } = usePress({
60
+ onPressStart,
61
+ onPress,
62
+ preventFocusOnPress,
63
+ ref: triggerRef
64
+ });
65
+ const mergedRef = useMemo(() => mergeRefs(ref, triggerRef), [ref, triggerRef]);
66
+ const resolvedId = id ?? triggerId;
67
+ useLayoutEffect(() => {
68
+ if (resolvedId !== triggerId) setTriggerId(resolvedId);
69
+ }, [
70
+ resolvedId,
71
+ triggerId,
72
+ setTriggerId
73
+ ]);
74
+ const merged = {
75
+ ...mergeProps(props, ariaProps, pressProps),
76
+ id: resolvedId,
77
+ ref: mergedRef,
78
+ "data-open": state.isOpen ? "" : void 0
79
+ };
80
+ if (!render) return createElement("button", {
81
+ type: "button",
82
+ ...merged,
83
+ className
84
+ });
85
+ return renderElement({
86
+ defaultElement: "button",
87
+ render,
88
+ baseClassName: "",
89
+ props: {
90
+ ...merged,
91
+ className
92
+ }
93
+ });
94
+ }
95
+ /**
96
+ * 트리거 옆에 뜨는 동작 목록(`role="menu"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-popover`로 쌓는다.
97
+ * 바로 나타나고, 닫히면 opacity만 `fast`(150ms)로 사라진다.
98
+ * 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
99
+ */
100
+ function MenuContent(props) {
101
+ const context = useMenuContext("MenuContent");
102
+ const popoverRef = useRef(null);
103
+ if (!useOverlayPresence(context.state.isOpen, popoverRef)) return null;
104
+ return /* @__PURE__ */ jsx(OverlayPortal, {
105
+ isExiting: !context.state.isOpen,
106
+ children: /* @__PURE__ */ jsx(MenuContentInner, {
107
+ ...props,
108
+ context,
109
+ popoverRef
110
+ })
111
+ });
112
+ }
113
+ /** DOM에 있는 동안만 portal 안에서 렌더한다. React Aria 오버레이·목록 hook은 요소가 있다고 보고 동작한다. */
114
+ function MenuContentInner({ context, popoverRef, placement = "bottom start", offset = 4, ref, className, children, ...props }) {
115
+ const { state, triggerRef, menuProps, triggerId } = context;
116
+ useOverlayTheme(triggerRef, popoverRef);
117
+ const { overlayProps } = usePopoverOverlay({
118
+ triggerRef,
119
+ popoverRef,
120
+ placement,
121
+ offset
122
+ }, state);
123
+ const items = useMemo(() => resolveCollectionChildren(children), [children]);
124
+ const tree = useTreeState({ children: items });
125
+ const labelledBy = props["aria-labelledby"] ?? (props["aria-label"] ? void 0 : triggerId);
126
+ const { menuProps: ariaMenuProps } = useMenu({
127
+ ...menuProps,
128
+ "aria-label": props["aria-label"],
129
+ "aria-labelledby": labelledBy
130
+ }, tree, popoverRef);
131
+ const mergedRef = useMemo(() => mergeRefs(ref, popoverRef), [ref, popoverRef]);
132
+ useCloseOnTab(popoverRef, state.close);
133
+ const { style: _style, ...rest } = mergeProps(props, overlayProps, ariaMenuProps);
134
+ const nodes = [...tree.collection];
135
+ return /* @__PURE__ */ jsx("div", {
136
+ ...rest,
137
+ ref: mergedRef,
138
+ "data-open": state.isOpen ? "" : void 0,
139
+ className: cn(listPopupClass, className),
140
+ style: {
141
+ ...overlayProps.style,
142
+ ...props.style
143
+ },
144
+ children: nodes.map((node, index) => {
145
+ const previous = nodes[index - 1];
146
+ const separator = previous !== void 0 && (node.type === "section" || previous.type === "section");
147
+ const element = node.type === "section" ? /* @__PURE__ */ jsx(MenuSectionView, {
148
+ node,
149
+ tree
150
+ }, node.key) : /* @__PURE__ */ jsx(MenuItemView, {
151
+ node,
152
+ tree
153
+ }, node.key);
154
+ if (!separator) return element;
155
+ return [/* @__PURE__ */ jsx("div", {
156
+ role: "separator",
157
+ className: listSeparatorClass
158
+ }, `${String(node.key)}-separator`), element];
159
+ })
160
+ });
161
+ }
162
+ /**
163
+ * Menu의 동작 항목(`role="menuitem"`). `MenuContent`나 `MenuSection` 바로 안에 둔다.
164
+ * 키보드 위치와 마우스를 올린 항목은 highlight(primary subtle 배경, primary 글자)로 바로 바뀐다.
165
+ * 상태는 `data-highlighted`(키보드 위치·hover), `data-disabled`(비활성)로 노출한다.
166
+ */
167
+ function MenuItem(_props) {
168
+ return null;
169
+ }
170
+ asCollectionComponent(MenuItem, itemCollectionNode);
171
+ /**
172
+ * 항목 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
173
+ * 앞뒤 다른 항목·묶음과의 사이에 구분선(`role="separator"`)이 그려진다.
174
+ */
175
+ function MenuSection(_props) {
176
+ return null;
177
+ }
178
+ asCollectionComponent(MenuSection, sectionCollectionNode);
179
+ /** 항목 하나를 그린다. node.props는 앱이 MenuItem에 준 props(와 컬렉션이 더한 isDisabled)다. */
180
+ function MenuItemView({ node, tree }) {
181
+ const itemRef = useRef(null);
182
+ const { ref, className, onClick, disabled: _disabled, textValue: _textValue, isDisabled: _isDisabled, children: _children, id, ...props } = node.props;
183
+ const { menuItemProps, isFocused, isDisabled } = useMenuItem({
184
+ key: node.key,
185
+ id,
186
+ onClick,
187
+ "aria-label": props["aria-label"]
188
+ }, tree, itemRef);
189
+ const mergedRef = useMemo(() => mergeRefs(ref, itemRef), [ref, itemRef]);
190
+ const merged = mergeProps(props, menuItemProps);
191
+ return /* @__PURE__ */ jsx("div", {
192
+ ...merged,
193
+ ref: mergedRef,
194
+ "aria-labelledby": props["aria-labelledby"],
195
+ "aria-describedby": props["aria-describedby"],
196
+ "data-highlighted": isFocused ? "" : void 0,
197
+ "data-disabled": isDisabled ? "" : void 0,
198
+ className: cn(listItemClass, className),
199
+ children: node.rendered
200
+ });
201
+ }
202
+ /** 묶음 하나를 그린다. 제목은 보조기술에서 숨기고(`presentation`) 묶음의 이름으로만 쓴다(useMenuSection). */
203
+ function MenuSectionView({ node, tree }) {
204
+ const { className } = node.props;
205
+ const { itemProps, headingProps, groupProps } = useMenuSection({
206
+ heading: node.rendered,
207
+ "aria-label": node["aria-label"]
208
+ });
209
+ return /* @__PURE__ */ jsxs("div", {
210
+ ...itemProps,
211
+ className,
212
+ children: [node.rendered != null && /* @__PURE__ */ jsx("div", {
213
+ ...headingProps,
214
+ className: "px-2 pt-1.5 pb-1 text-label-sm text-muted select-none",
215
+ children: node.rendered
216
+ }), /* @__PURE__ */ jsx("div", {
217
+ ...groupProps,
218
+ children: [...node.childNodes].map((child) => /* @__PURE__ */ jsx(MenuItemView, {
219
+ node: child,
220
+ tree
221
+ }, child.key))
222
+ })]
223
+ });
224
+ }
225
+
226
+ export { Menu, MenuContent, MenuItem, MenuSection, MenuTrigger };
@@ -0,0 +1,46 @@
1
+ import { IconButtonProps } from "./IconButton.js";
2
+ import { ComponentProps, ReactElement, ReactNode } from "react";
3
+ export interface PaginationProps extends ComponentProps<"nav"> {
4
+ /** 탐색 영역 이름. 기본값은 `"페이지 이동"`이다. 한 화면에 목록이 여럿이면 `"댓글 페이지"`처럼 구분한다. */
5
+ "aria-label"?: string;
6
+ }
7
+ export interface PaginationItemProps extends ComponentProps<"li"> {}
8
+ export interface PaginationLinkProps extends Omit<ComponentProps<"a">, "color"> {
9
+ /** 현재 페이지인지. `aria-current="page"`를 붙이고 subtle 채움으로 보인다. 기본값은 `false`다. */
10
+ current?: boolean;
11
+ /**
12
+ * 다른 요소로 렌더한다. 예: `render={<NextLink href="?page=2" />}`.
13
+ * 상태로 페이지를 바꾸면 `render={<button type="button" onClick={...} />}`를 쓴다. props, ref, className을 병합한다.
14
+ */
15
+ render?: ReactElement;
16
+ }
17
+ /** 이전/다음 항목 props. IconButton의 props에서 모양(variant·color·size)과 아이콘·로딩을 고정했다. */
18
+ export interface PaginationArrowProps extends Omit<IconButtonProps, "aria-label" | "children" | "variant" | "color" | "size" | "loading" | "loadingLabel"> {
19
+ /** 버튼 이름. 기본값은 이전 `"이전 페이지"`, 다음 `"다음 페이지"`다. */
20
+ "aria-label"?: string;
21
+ }
22
+ export interface PaginationPreviousProps extends PaginationArrowProps {}
23
+ export interface PaginationNextProps extends PaginationArrowProps {}
24
+ export interface PaginationEllipsisProps extends Omit<ComponentProps<"span">, "children"> {
25
+ /** 스크린리더가 읽는 텍스트. 화면에는 「…」 아이콘만 보인다. 기본값은 `"페이지 생략"`이다. */
26
+ children?: ReactNode;
27
+ }
28
+ /**
29
+ * 페이지 이동 탐색 영역. `<nav>` 안의 `<ul>`이다.
30
+ * 자식은 `PaginationItem`이고, 그 안에 `PaginationPrevious`·`PaginationLink`·`PaginationEllipsis`·`PaginationNext`를 둔다.
31
+ * `ref`·`className`은 `<nav>`에 붙는다.
32
+ */
33
+ export declare function Pagination({ "aria-label": ariaLabel, children, ...props }: PaginationProps): ReactElement;
34
+ /** 목록의 한 항목 `<li>`. 기본 class가 없다. */
35
+ export declare function PaginationItem(props: PaginationItemProps): ReactElement;
36
+ /**
37
+ * 페이지 번호 링크. 기본은 `<a>`이고 Button(ghost, 32px) 모양이다. 현재 페이지는 `current`를 준다.
38
+ * Next.js에서는 `render={<NextLink href="?page=2" />}`를 쓴다.
39
+ */
40
+ export declare function PaginationLink({ current, render, className, ...props }: PaginationLinkProps): ReactElement;
41
+ /** 이전 페이지로 가는 IconButton(ghost, 32px, ‹). 첫 페이지에서는 `disabled`를 준다. */
42
+ export declare function PaginationPrevious({ "aria-label": ariaLabel, ...props }: PaginationPreviousProps): ReactElement;
43
+ /** 다음 페이지로 가는 IconButton(ghost, 32px, ›). 마지막 페이지에서는 `disabled`를 준다. */
44
+ export declare function PaginationNext({ "aria-label": ariaLabel, ...props }: PaginationNextProps): ReactElement;
45
+ /** 생략된 번호 자리 `<span>`. 화면에는 「…」 아이콘, 스크린리더에는 텍스트(기본 `"페이지 생략"`)를 보인다. */
46
+ export declare function PaginationEllipsis({ className, children, ...props }: PaginationEllipsisProps): ReactElement;
@@ -0,0 +1,79 @@
1
+ import { Button } from "./Button.js";
2
+ import { cn } from "./cn.js";
3
+ import { IconButton } from "./IconButton.js";
4
+ import { VisuallyHidden } from "./VisuallyHidden.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { ChevronLeftIcon, ChevronRightIcon, EllipsisIcon } from "@tide-design/icons";
7
+
8
+ // src/Pagination.tsx
9
+ /** 페이지 번호·이전/다음 항목의 고정 size. 둘 다 32×32px다(24×24 이상). */
10
+ const itemSize = "sm";
11
+ const listClass = "flex flex-wrap items-center gap-1";
12
+ const linkClass = "min-w-8 px-2 tabular-nums";
13
+ const ellipsisClass = "inline-flex size-8 items-center justify-center text-muted";
14
+ /**
15
+ * 페이지 이동 탐색 영역. `<nav>` 안의 `<ul>`이다.
16
+ * 자식은 `PaginationItem`이고, 그 안에 `PaginationPrevious`·`PaginationLink`·`PaginationEllipsis`·`PaginationNext`를 둔다.
17
+ * `ref`·`className`은 `<nav>`에 붙는다.
18
+ */
19
+ function Pagination({ "aria-label": ariaLabel = "페이지 이동", children, ...props }) {
20
+ return /* @__PURE__ */ jsx("nav", {
21
+ ...props,
22
+ "aria-label": ariaLabel,
23
+ children: /* @__PURE__ */ jsx("ul", {
24
+ className: listClass,
25
+ children
26
+ })
27
+ });
28
+ }
29
+ /** 목록의 한 항목 `<li>`. 기본 class가 없다. */
30
+ function PaginationItem(props) {
31
+ return /* @__PURE__ */ jsx("li", { ...props });
32
+ }
33
+ /**
34
+ * 페이지 번호 링크. 기본은 `<a>`이고 Button(ghost, 32px) 모양이다. 현재 페이지는 `current`를 준다.
35
+ * Next.js에서는 `render={<NextLink href="?page=2" />}`를 쓴다.
36
+ */
37
+ function PaginationLink({ current = false, render, className, ...props }) {
38
+ return /* @__PURE__ */ jsx(Button, {
39
+ ...props,
40
+ render: render ?? /* @__PURE__ */ jsx("a", {}),
41
+ variant: current ? "subtle" : "ghost",
42
+ color: current ? "primary" : "neutral",
43
+ size: itemSize,
44
+ "aria-current": current ? "page" : props["aria-current"],
45
+ className: cn(linkClass, className)
46
+ });
47
+ }
48
+ /** 이전 페이지로 가는 IconButton(ghost, 32px, ‹). 첫 페이지에서는 `disabled`를 준다. */
49
+ function PaginationPrevious({ "aria-label": ariaLabel = "이전 페이지", ...props }) {
50
+ return /* @__PURE__ */ jsx(IconButton, {
51
+ ...props,
52
+ "aria-label": ariaLabel,
53
+ variant: "ghost",
54
+ color: "neutral",
55
+ size: itemSize,
56
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
57
+ });
58
+ }
59
+ /** 다음 페이지로 가는 IconButton(ghost, 32px, ›). 마지막 페이지에서는 `disabled`를 준다. */
60
+ function PaginationNext({ "aria-label": ariaLabel = "다음 페이지", ...props }) {
61
+ return /* @__PURE__ */ jsx(IconButton, {
62
+ ...props,
63
+ "aria-label": ariaLabel,
64
+ variant: "ghost",
65
+ color: "neutral",
66
+ size: itemSize,
67
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, {})
68
+ });
69
+ }
70
+ /** 생략된 번호 자리 `<span>`. 화면에는 「…」 아이콘, 스크린리더에는 텍스트(기본 `"페이지 생략"`)를 보인다. */
71
+ function PaginationEllipsis({ className, children = "페이지 생략", ...props }) {
72
+ return /* @__PURE__ */ jsxs("span", {
73
+ ...props,
74
+ className: cn(ellipsisClass, className),
75
+ children: [/* @__PURE__ */ jsx(EllipsisIcon, {}), /* @__PURE__ */ jsx(VisuallyHidden, { children })]
76
+ });
77
+ }
78
+
79
+ export { Pagination, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious };
@@ -0,0 +1,43 @@
1
+ import { OverlayPlacement } from "./overlay.js";
2
+ import { ComponentProps, ReactElement, ReactNode } from "react";
3
+ /** Popover 내용의 위치. 앞은 트리거의 어느 쪽, 뒤는 그 변에서 맞출 끝이다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
4
+ export type PopoverPlacement = OverlayPlacement;
5
+ export interface PopoverProps {
6
+ /** 열림 상태(제어). 주면 `onOpenChange`로 바꾼다. */
7
+ open?: boolean;
8
+ /** 처음 열림 상태(비제어). 기본값은 `false`다. */
9
+ defaultOpen?: boolean;
10
+ /** 열림 상태가 바뀌려 할 때 새 값으로 부른다. */
11
+ onOpenChange?: (open: boolean) => void;
12
+ /** `PopoverTrigger`와 `PopoverContent` */
13
+ children: ReactNode;
14
+ }
15
+ /**
16
+ * 트리거와 내용을 잇는 열림 상태. DOM 요소를 만들지 않는다.
17
+ * 안에 `PopoverTrigger` 하나와 `PopoverContent` 하나를 둔다.
18
+ */
19
+ export declare function Popover({ open, defaultOpen, onOpenChange, children }: PopoverProps): ReactElement;
20
+ export interface PopoverTriggerProps extends ComponentProps<"button"> {
21
+ /**
22
+ * 다른 요소로 렌더한다. 예: `render={<Button variant="outline" />}`, `render={<IconButton aria-label="설정" />}`.
23
+ * props, ref, className, 이벤트 핸들러를 그 요소에 병합한다. 기본은 class 없는 `<button type="button">`이다.
24
+ */
25
+ render?: ReactElement;
26
+ }
27
+ /**
28
+ * Popover를 여닫는 버튼. 누르면(마우스, 터치, Enter, Space) 열림 상태를 뒤집는다.
29
+ * `aria-expanded`, 열렸을 때 `aria-controls`, 열렸을 때 `data-open`이 붙는다.
30
+ */
31
+ export declare function PopoverTrigger({ render, ref, id, className, ...props }: PopoverTriggerProps): ReactElement;
32
+ export interface PopoverContentProps extends Omit<ComponentProps<"div">, "id" | "role"> {
33
+ /** 트리거 기준 위치. 기본값은 `bottom`(아래, 가운데 맞춤)이다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
34
+ placement?: PopoverPlacement;
35
+ /** 트리거와의 간격(px). 기본값은 `8`이다. */
36
+ offset?: number;
37
+ }
38
+ /**
39
+ * 트리거 옆에 뜨는 내용(`role="dialog"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-popover`로 쌓는다.
40
+ * 등장은 opacity + blur 4px + 4px 이동(`normal`), 퇴장은 그 절반(`fast`)이다. 움직임 줄이기에서는 opacity만 바뀐다.
41
+ * 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
42
+ */
43
+ export declare function PopoverContent(props: PopoverContentProps): ReactElement | null;
@@ -0,0 +1,147 @@
1
+ "use client";
2
+
3
+ import { cn } from "./cn.js";
4
+ import { OverlayPortal, useOverlayPresence, useOverlayTheme, usePopoverOverlay } from "./overlay.js";
5
+ import { overlaySurfaceClass, popoverMotionClass } from "./overlay-style.js";
6
+ import { renderElement } from "./render.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { createContext, createElement, use, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
9
+ import { DismissButton, mergeProps, mergeRefs, useDialog, useOverlayTrigger, usePress } from "react-aria";
10
+ import { useOverlayTriggerState } from "react-stately";
11
+
12
+ // src/Popover.tsx
13
+ const PopoverContext = createContext(null);
14
+ function usePopoverContext(part) {
15
+ const context = use(PopoverContext);
16
+ if (!context) throw new Error(`${part}는 Popover 안에 둔다.`);
17
+ return context;
18
+ }
19
+ /**
20
+ * 트리거와 내용을 잇는 열림 상태. DOM 요소를 만들지 않는다.
21
+ * 안에 `PopoverTrigger` 하나와 `PopoverContent` 하나를 둔다.
22
+ */
23
+ function Popover({ open, defaultOpen, onOpenChange, children }) {
24
+ const state = useOverlayTriggerState({
25
+ isOpen: open,
26
+ defaultOpen,
27
+ onOpenChange
28
+ });
29
+ const triggerRef = useRef(null);
30
+ const { triggerProps, overlayProps } = useOverlayTrigger({ type: "dialog" }, state, triggerRef);
31
+ const generatedTriggerId = useId();
32
+ const [triggerId, setTriggerId] = useState(generatedTriggerId);
33
+ const value = useMemo(() => ({
34
+ state,
35
+ triggerRef,
36
+ triggerProps,
37
+ contentId: overlayProps.id,
38
+ triggerId,
39
+ setTriggerId
40
+ }), [
41
+ state,
42
+ triggerProps,
43
+ overlayProps.id,
44
+ triggerId
45
+ ]);
46
+ return /* @__PURE__ */ jsx(PopoverContext, {
47
+ value,
48
+ children
49
+ });
50
+ }
51
+ /**
52
+ * Popover를 여닫는 버튼. 누르면(마우스, 터치, Enter, Space) 열림 상태를 뒤집는다.
53
+ * `aria-expanded`, 열렸을 때 `aria-controls`, 열렸을 때 `data-open`이 붙는다.
54
+ */
55
+ function PopoverTrigger({ render, ref, id, className, ...props }) {
56
+ const { state, triggerRef, triggerProps, triggerId, setTriggerId } = usePopoverContext("PopoverTrigger");
57
+ const { onPress, ...ariaProps } = triggerProps;
58
+ const { pressProps } = usePress({
59
+ onPress,
60
+ ref: triggerRef
61
+ });
62
+ const mergedRef = useMemo(() => mergeRefs(ref, triggerRef), [ref, triggerRef]);
63
+ const resolvedId = id ?? triggerId;
64
+ useLayoutEffect(() => {
65
+ if (resolvedId !== triggerId) setTriggerId(resolvedId);
66
+ }, [
67
+ resolvedId,
68
+ triggerId,
69
+ setTriggerId
70
+ ]);
71
+ const merged = {
72
+ ...mergeProps(props, ariaProps, pressProps),
73
+ id: resolvedId,
74
+ ref: mergedRef,
75
+ "data-open": state.isOpen ? "" : void 0
76
+ };
77
+ if (!render) return createElement("button", {
78
+ type: "button",
79
+ ...merged,
80
+ className
81
+ });
82
+ return renderElement({
83
+ defaultElement: "button",
84
+ render,
85
+ baseClassName: "",
86
+ props: {
87
+ ...merged,
88
+ className
89
+ }
90
+ });
91
+ }
92
+ const contentClass = `isolate z-popover max-w-80 overflow-auto p-4 text-body-md outline-none ${overlaySurfaceClass} ${popoverMotionClass}`;
93
+ /**
94
+ * 트리거 옆에 뜨는 내용(`role="dialog"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-popover`로 쌓는다.
95
+ * 등장은 opacity + blur 4px + 4px 이동(`normal`), 퇴장은 그 절반(`fast`)이다. 움직임 줄이기에서는 opacity만 바뀐다.
96
+ * 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
97
+ */
98
+ function PopoverContent(props) {
99
+ const context = usePopoverContext("PopoverContent");
100
+ const popoverRef = useRef(null);
101
+ if (!useOverlayPresence(context.state.isOpen, popoverRef)) return null;
102
+ return /* @__PURE__ */ jsx(OverlayPortal, {
103
+ isExiting: !context.state.isOpen,
104
+ children: /* @__PURE__ */ jsx(PopoverContentInner, {
105
+ ...props,
106
+ context,
107
+ popoverRef
108
+ })
109
+ });
110
+ }
111
+ /** DOM에 있는 동안만 portal 안에서 렌더한다. React Aria 오버레이 hook은 요소가 있다고 보고 동작한다. */
112
+ function PopoverContentInner({ context, popoverRef, placement = "bottom", offset = 8, ref, className, children, ...props }) {
113
+ const { state, triggerRef, contentId, triggerId } = context;
114
+ useOverlayTheme(triggerRef, popoverRef);
115
+ const { overlayProps } = usePopoverOverlay({
116
+ triggerRef,
117
+ popoverRef,
118
+ placement,
119
+ offset
120
+ }, state);
121
+ const { dialogProps } = useDialog({
122
+ "aria-label": props["aria-label"],
123
+ "aria-labelledby": props["aria-labelledby"]
124
+ }, popoverRef);
125
+ const labelledBy = dialogProps["aria-labelledby"] ?? (props["aria-label"] ? void 0 : triggerId);
126
+ const mergedRef = useMemo(() => mergeRefs(ref, popoverRef), [ref, popoverRef]);
127
+ const { style: _style, ...rest } = mergeProps(props, overlayProps, dialogProps);
128
+ return /* @__PURE__ */ jsxs("div", {
129
+ ...rest,
130
+ id: contentId,
131
+ ref: mergedRef,
132
+ "aria-labelledby": labelledBy,
133
+ "data-open": state.isOpen ? "" : void 0,
134
+ className: cn(contentClass, className),
135
+ style: {
136
+ ...overlayProps.style,
137
+ ...props.style
138
+ },
139
+ children: [
140
+ /* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close }),
141
+ children,
142
+ /* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close })
143
+ ]
144
+ });
145
+ }
146
+
147
+ export { Popover, PopoverContent, PopoverTrigger };
@@ -0,0 +1,32 @@
1
+ import { Role, Size } from "./types.js";
2
+ import { ComponentProps, ReactElement } from "react";
3
+ /** Progress의 size. 막대 굵기다. */
4
+ type ProgressSize = Extract<Size, "sm" | "md">;
5
+ /** 접근 가능한 이름. `aria-label`이나 `aria-labelledby` 중 하나는 꼭 준다(WAI-ARIA progressbar는 이름이 필요하다). */
6
+ type ProgressName = {
7
+ "aria-label": string;
8
+ "aria-labelledby"?: string;
9
+ } | {
10
+ "aria-label"?: string;
11
+ "aria-labelledby": string;
12
+ };
13
+ interface ProgressOwnProps extends Omit<ComponentProps<"div">, "color" | "children" | "role" | "aria-label" | "aria-labelledby" | "aria-valuenow" | "aria-valuemin" | "aria-valuemax"> {
14
+ /** 현재 값. 0 이상 `max` 이하로 잘라서 쓴다. 값을 모르는 진행은 Progress가 아니라 Spinner로 보여 준다. */
15
+ value: number;
16
+ /** 끝 값. 기본값은 `100`이다. 시작 값은 항상 0이다. */
17
+ max?: number;
18
+ /** 막대 굵기. `sm` 4px, `md` 8px. 기본값은 `md`다. */
19
+ size?: ProgressSize;
20
+ /**
21
+ * 막대 색. 진행 상태는 뜻이 있는 표시라 Role만 받는다(Tide Role 6개와 앱이 `RoleRegistry`에 더한 Role, ADR 0016).
22
+ * 기본값은 `primary`다. 루트에 `data-color`로 붙고 바깥 요소의 색을 물려받지 않는다.
23
+ */
24
+ color?: Role;
25
+ }
26
+ export type ProgressProps = ProgressOwnProps & ProgressName;
27
+ /**
28
+ * 작업이 얼마나 진행됐는지 막대로 보여 준다. 역할은 `progressbar`이고 값은 `aria-valuenow`로 나간다.
29
+ * 움직임 줄이기에서도 진행 표시는 그대로다. 서버 컴포넌트로 쓸 수 있다.
30
+ */
31
+ export declare function Progress({ value, max, size, color, className, ...props }: ProgressProps): ReactElement;
32
+ export {};
@@ -0,0 +1,40 @@
1
+ import { cn } from "./cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ // src/Progress.tsx
5
+ const sizeClass = {
6
+ sm: "h-1",
7
+ md: "h-2"
8
+ };
9
+ const trackClass = "relative block w-full overflow-hidden rounded-full bg-accent-subtle forced-colors:forced-color-adjust-none forced-colors:border forced-colors:border-[CanvasText] forced-colors:bg-[Canvas]";
10
+ const barClass = "block h-full rounded-full bg-current text-accent motion-safe:transition-[width] forced-colors:text-[Highlight]";
11
+ /** 0 이상 max 이하로 자른다. max가 0 이하이거나 숫자가 아니면 0으로 본다. */
12
+ function clamp(value, max) {
13
+ if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) return 0;
14
+ return Math.min(Math.max(value, 0), max);
15
+ }
16
+ /**
17
+ * 작업이 얼마나 진행됐는지 막대로 보여 준다. 역할은 `progressbar`이고 값은 `aria-valuenow`로 나간다.
18
+ * 움직임 줄이기에서도 진행 표시는 그대로다. 서버 컴포넌트로 쓸 수 있다.
19
+ */
20
+ function Progress({ value, max = 100, size = "md", color = "primary", className, ...props }) {
21
+ const safeMax = Number.isFinite(max) && max > 0 ? max : 100;
22
+ const now = clamp(value, safeMax);
23
+ const percent = now / safeMax * 100;
24
+ return /* @__PURE__ */ jsx("div", {
25
+ ...props,
26
+ role: "progressbar",
27
+ "aria-valuenow": now,
28
+ "aria-valuemin": 0,
29
+ "aria-valuemax": safeMax,
30
+ "data-color": color,
31
+ className: cn(trackClass, sizeClass[size], className),
32
+ children: /* @__PURE__ */ jsx("span", {
33
+ "aria-hidden": "true",
34
+ className: barClass,
35
+ style: { width: `${percent}%` }
36
+ })
37
+ });
38
+ }
39
+
40
+ export { Progress };
@@ -0,0 +1,27 @@
1
+ import { ChoiceSize } from "./choice-style.js";
2
+ import { Role } from "./types.js";
3
+ import { CSSProperties, ComponentProps, ReactElement, ReactNode } from "react";
4
+ export interface RadioProps extends Omit<ComponentProps<"input">, "type" | "size" | "color" | "children" | "className" | "style" | "value"> {
5
+ /** 이 라디오의 값. RadioGroup의 `value`·`onValueChange`가 이 값을 쓰고, form에 제출된다. */
6
+ value: string;
7
+ /** 원 옆에 보이는 label. 라디오의 이름이 된다. 없으면 `aria-label`을 준다. */
8
+ children?: ReactNode;
9
+ /** 원 16px·글자 14px(`sm`) 또는 원 20px·글자 16px(`md`). 누르는 영역은 둘 다 24×24px이다. 기본값은 `md`다. */
10
+ size?: ChoiceSize;
11
+ /** 선택했을 때 원 색(Role). 루트에 `data-color`로 붙는다. 기본값은 `primary`다. */
12
+ color?: Role;
13
+ /**
14
+ * 오류 상태. input에 `aria-invalid="true"`와 `data-invalid`가 붙고 경계가 danger 색이 된다.
15
+ * Field·RadioGroup 안에서는 그 값을 따르고, 여기에 준 값이 이긴다.
16
+ */
17
+ invalid?: boolean;
18
+ /** 루트 label의 class. 사용자 class가 기본 class를 이긴다. 상자 모양은 바꾸지 않는다(`size`·`color`가 맡는다). */
19
+ className?: string;
20
+ /** 루트 label의 style */
21
+ style?: CSSProperties;
22
+ }
23
+ /**
24
+ * 네이티브 라디오 버튼. 보통 `RadioGroup` 안에 두고, 묶음이 `name`과 선택 값을 정한다.
25
+ * 묶음 밖에서는 `name`·`checked`/`defaultChecked`·`onChange`를 직접 준다.
26
+ */
27
+ export declare function Radio({ value, children, size, color, invalid, id, disabled, required, name, checked, defaultChecked, onChange, className, style, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: RadioProps): ReactElement;