@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.
- package/LICENSE +21 -0
- package/dist/Accordion.d.ts +66 -0
- package/dist/Accordion.js +127 -0
- package/dist/Alert.d.ts +32 -0
- package/dist/Alert.js +47 -0
- package/dist/AlertDialog.d.ts +8 -0
- package/dist/AlertDialog.js +18 -0
- package/dist/Avatar.d.ts +27 -0
- package/dist/Avatar.js +44 -0
- package/dist/Badge.d.ts +32 -0
- package/dist/Badge.js +28 -0
- package/dist/Breadcrumb.d.ts +26 -0
- package/dist/Breadcrumb.js +53 -0
- package/dist/Button.d.ts +42 -0
- package/dist/Button.js +76 -0
- package/dist/Card.d.ts +13 -0
- package/dist/Card.js +18 -0
- package/dist/Checkbox.d.ts +30 -0
- package/dist/Checkbox.js +74 -0
- package/dist/CheckboxGroup.d.ts +19 -0
- package/dist/CheckboxGroup.js +45 -0
- package/dist/Combobox.d.ts +59 -0
- package/dist/Combobox.js +206 -0
- package/dist/Dialog.d.ts +70 -0
- package/dist/Dialog.js +255 -0
- package/dist/Field.d.ts +33 -0
- package/dist/Field.js +74 -0
- package/dist/IconButton.d.ts +42 -0
- package/dist/IconButton.js +63 -0
- package/dist/Input.d.ts +16 -0
- package/dist/Input.js +29 -0
- package/dist/Link.d.ts +20 -0
- package/dist/Link.js +21 -0
- package/dist/Menu.d.ts +72 -0
- package/dist/Menu.js +226 -0
- package/dist/Pagination.d.ts +46 -0
- package/dist/Pagination.js +79 -0
- package/dist/Popover.d.ts +43 -0
- package/dist/Popover.js +147 -0
- package/dist/Progress.d.ts +32 -0
- package/dist/Progress.js +40 -0
- package/dist/Radio.d.ts +27 -0
- package/dist/Radio.js +67 -0
- package/dist/RadioGroup.d.ts +28 -0
- package/dist/RadioGroup.js +50 -0
- package/dist/Select.d.ts +62 -0
- package/dist/Select.js +169 -0
- package/dist/Separator.d.ts +18 -0
- package/dist/Separator.js +24 -0
- package/dist/Skeleton.d.ts +24 -0
- package/dist/Skeleton.js +29 -0
- package/dist/Spinner.d.ts +20 -0
- package/dist/Spinner.js +35 -0
- package/dist/Switch.d.ts +30 -0
- package/dist/Switch.js +65 -0
- package/dist/Table.d.ts +31 -0
- package/dist/Table.js +53 -0
- package/dist/Tabs.d.ts +66 -0
- package/dist/Tabs.js +159 -0
- package/dist/Tag.d.ts +48 -0
- package/dist/Tag.js +102 -0
- package/dist/Textarea.d.ts +19 -0
- package/dist/Textarea.js +36 -0
- package/dist/Toast.d.ts +71 -0
- package/dist/Toast.js +191 -0
- package/dist/Tooltip.d.ts +53 -0
- package/dist/Tooltip.js +129 -0
- package/dist/Typography.d.ts +36 -0
- package/dist/Typography.js +50 -0
- package/dist/VisuallyHidden.d.ts +4 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/alert-style.js +45 -0
- package/dist/choice-group.js +34 -0
- package/dist/choice-style.d.ts +2 -0
- package/dist/choice-style.js +16 -0
- package/dist/cn.d.ts +6 -0
- package/dist/cn.js +15 -0
- package/dist/field-context.js +26 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +38 -0
- package/dist/input-style.d.ts +3 -0
- package/dist/input-style.js +11 -0
- package/dist/list-collection.d.ts +23 -0
- package/dist/list-collection.js +99 -0
- package/dist/list-style.js +46 -0
- package/dist/listbox.d.ts +15 -0
- package/dist/listbox.js +90 -0
- package/dist/overlay-style.js +84 -0
- package/dist/overlay.d.ts +7 -0
- package/dist/overlay.js +130 -0
- package/dist/pressable.js +70 -0
- package/dist/render.js +55 -0
- package/dist/styles.css +5 -0
- package/dist/types.d.ts +9 -0
- package/package.json +57 -4
- package/README.md +0 -3
package/dist/Dialog.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
import { IconButton } from "./IconButton.js";
|
|
5
|
+
import { OverlayPortal, useOverlayPresence, useOverlayTheme } from "./overlay.js";
|
|
6
|
+
import { backdropMotionClass, dialogMotionClass, dialogSurfaceClass } from "./overlay-style.js";
|
|
7
|
+
import { renderElement } from "./render.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { createContext, createElement, use, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
10
|
+
import { XIcon } from "@tide-design/icons";
|
|
11
|
+
import { mergeProps, mergeRefs, useDialog, useFocusManager, useModalOverlay, useOverlayTrigger, usePress } from "react-aria";
|
|
12
|
+
import { useOverlayTriggerState } from "react-stately";
|
|
13
|
+
|
|
14
|
+
// src/Dialog.tsx
|
|
15
|
+
const DialogContext = createContext(null);
|
|
16
|
+
function useDialogContext(part) {
|
|
17
|
+
const context = use(DialogContext);
|
|
18
|
+
if (!context) throw new Error(`${part}는 Dialog나 AlertDialog 안에 둔다.`);
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
const DialogPartsContext = createContext(null);
|
|
22
|
+
function useDialogPartsContext(part) {
|
|
23
|
+
const context = use(DialogPartsContext);
|
|
24
|
+
if (!context) throw new Error(`${part}는 DialogContent 안에 둔다.`);
|
|
25
|
+
return context;
|
|
26
|
+
}
|
|
27
|
+
/** Dialog·AlertDialog가 같이 쓰는 열림 상태. 공개 API가 아니다(AlertDialog.tsx가 쓴다). */
|
|
28
|
+
function DialogRoot({ open, defaultOpen, onOpenChange, alert, children }) {
|
|
29
|
+
const state = useOverlayTriggerState({
|
|
30
|
+
isOpen: open,
|
|
31
|
+
defaultOpen,
|
|
32
|
+
onOpenChange
|
|
33
|
+
});
|
|
34
|
+
const triggerRef = useRef(null);
|
|
35
|
+
const { triggerProps, overlayProps } = useOverlayTrigger({ type: "dialog" }, state, triggerRef);
|
|
36
|
+
const [triggerId, setTriggerId] = useState(null);
|
|
37
|
+
const value = useMemo(() => ({
|
|
38
|
+
state,
|
|
39
|
+
triggerRef,
|
|
40
|
+
triggerProps,
|
|
41
|
+
contentId: overlayProps.id,
|
|
42
|
+
triggerId,
|
|
43
|
+
setTriggerId,
|
|
44
|
+
alert
|
|
45
|
+
}), [
|
|
46
|
+
state,
|
|
47
|
+
triggerProps,
|
|
48
|
+
overlayProps.id,
|
|
49
|
+
triggerId,
|
|
50
|
+
alert
|
|
51
|
+
]);
|
|
52
|
+
return /* @__PURE__ */ jsx(DialogContext, {
|
|
53
|
+
value,
|
|
54
|
+
children
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 트리거와 내용을 잇는 열림 상태. DOM 요소를 만들지 않는다.
|
|
59
|
+
* 안에 `DialogTrigger`(없어도 된다. `open`으로 제어해 Menu 항목 등에서 열 수 있다)와 `DialogContent`를 둔다.
|
|
60
|
+
*/
|
|
61
|
+
function Dialog(props) {
|
|
62
|
+
return /* @__PURE__ */ jsx(DialogRoot, {
|
|
63
|
+
...props,
|
|
64
|
+
alert: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Dialog를 여는 버튼. 누르면(마우스, 터치, Enter, Space) 연다. 열린 동안은 바깥이 inert라 다시 누를 수 없다.
|
|
69
|
+
* `aria-haspopup="dialog"`, `aria-expanded`, 열렸을 때 `aria-controls`와 `data-open`이 붙는다.
|
|
70
|
+
*/
|
|
71
|
+
function DialogTrigger({ render, ref, id, className, ...props }) {
|
|
72
|
+
const { state, triggerRef, triggerProps, setTriggerId } = useDialogContext("DialogTrigger");
|
|
73
|
+
const { onPress, ...ariaProps } = triggerProps;
|
|
74
|
+
const { pressProps } = usePress({
|
|
75
|
+
onPress,
|
|
76
|
+
ref: triggerRef
|
|
77
|
+
});
|
|
78
|
+
const mergedRef = useMemo(() => mergeRefs(ref, triggerRef), [ref, triggerRef]);
|
|
79
|
+
const generatedId = useId();
|
|
80
|
+
const resolvedId = id ?? generatedId;
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
setTriggerId(resolvedId);
|
|
83
|
+
return () => setTriggerId(null);
|
|
84
|
+
}, [resolvedId, setTriggerId]);
|
|
85
|
+
const merged = {
|
|
86
|
+
...mergeProps(props, ariaProps, pressProps),
|
|
87
|
+
id: resolvedId,
|
|
88
|
+
ref: mergedRef,
|
|
89
|
+
"data-open": state.isOpen ? "" : void 0
|
|
90
|
+
};
|
|
91
|
+
if (!render) return createElement("button", {
|
|
92
|
+
type: "button",
|
|
93
|
+
...merged,
|
|
94
|
+
className
|
|
95
|
+
});
|
|
96
|
+
return renderElement({
|
|
97
|
+
defaultElement: "button",
|
|
98
|
+
render,
|
|
99
|
+
baseClassName: "",
|
|
100
|
+
props: {
|
|
101
|
+
...merged,
|
|
102
|
+
className
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const backdropClass = `fixed inset-0 isolate z-modal flex items-center justify-center bg-overlay p-4 ${backdropMotionClass}`;
|
|
107
|
+
const contentClass = `relative flex max-h-full w-full flex-col gap-4 overflow-y-auto p-6 text-body-md outline-none ${dialogSurfaceClass} ${dialogMotionClass}`;
|
|
108
|
+
const sizeClass = {
|
|
109
|
+
sm: "max-w-96",
|
|
110
|
+
md: "max-w-128",
|
|
111
|
+
lg: "max-w-160"
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* 화면 가운데 뜨는 모달 내용(`role="dialog"`, AlertDialog 안에서는 `role="alertdialog"`).
|
|
115
|
+
* 열릴 때만 `document.body`에 portal하고, 반투명 막(`bg-overlay`)과 함께 `z-modal`로 쌓는다.
|
|
116
|
+
* 등장은 opacity + scale 0.96 → 1(`normal`), 퇴장은 opacity + scale 0.98(`fast`)이다. 움직임 줄이기에서는 opacity만 바뀐다.
|
|
117
|
+
* Dialog에는 끝 위쪽에 닫기 버튼(IconButton)이 있고 바깥 막을 누르면 닫힌다. AlertDialog는 둘 다 없다(Esc는 닫는다).
|
|
118
|
+
*/
|
|
119
|
+
function DialogContent(props) {
|
|
120
|
+
const context = useDialogContext("DialogContent");
|
|
121
|
+
const backdropRef = useRef(null);
|
|
122
|
+
if (!useOverlayPresence(context.state.isOpen, backdropRef)) return null;
|
|
123
|
+
return /* @__PURE__ */ jsx(OverlayPortal, {
|
|
124
|
+
isExiting: !context.state.isOpen,
|
|
125
|
+
children: /* @__PURE__ */ jsx(DialogContentInner, {
|
|
126
|
+
...props,
|
|
127
|
+
context,
|
|
128
|
+
backdropRef
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** DOM에 있는 동안만 portal 안에서 렌더한다. React Aria 오버레이 hook은 요소가 있다고 보고 동작한다. */
|
|
133
|
+
function DialogContentInner({ context, backdropRef, size = "md", closeLabel = "닫기", ref, className, children, ...props }) {
|
|
134
|
+
const { state, triggerRef, contentId, triggerId, alert } = context;
|
|
135
|
+
const dialogRef = useRef(null);
|
|
136
|
+
const [titleId, setTitleId] = useState(null);
|
|
137
|
+
const [descriptionId, setDescriptionId] = useState(null);
|
|
138
|
+
useOverlayTheme(triggerRef, backdropRef);
|
|
139
|
+
const { modalProps, underlayProps } = useModalOverlay({ isDismissable: !alert }, state, dialogRef);
|
|
140
|
+
const labelledBy = props["aria-labelledby"] ?? (props["aria-label"] ? void 0 : titleId ?? triggerId ?? void 0);
|
|
141
|
+
const describedBy = props["aria-describedby"] ?? descriptionId ?? void 0;
|
|
142
|
+
const { dialogProps } = useDialog({
|
|
143
|
+
role: alert ? "alertdialog" : "dialog",
|
|
144
|
+
"aria-label": props["aria-label"],
|
|
145
|
+
"aria-labelledby": labelledBy,
|
|
146
|
+
"aria-describedby": describedBy
|
|
147
|
+
}, dialogRef);
|
|
148
|
+
const focusManager = useFocusManager();
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (alert && document.activeElement === dialogRef.current) focusManager?.focusFirst({ tabbable: true });
|
|
151
|
+
}, []);
|
|
152
|
+
const mergedRef = useMemo(() => mergeRefs(ref, dialogRef), [ref]);
|
|
153
|
+
const parts = useMemo(() => ({
|
|
154
|
+
alert,
|
|
155
|
+
setTitleId,
|
|
156
|
+
setDescriptionId
|
|
157
|
+
}), [alert]);
|
|
158
|
+
const open = state.isOpen ? "" : void 0;
|
|
159
|
+
return /* @__PURE__ */ jsx("div", {
|
|
160
|
+
...underlayProps,
|
|
161
|
+
ref: backdropRef,
|
|
162
|
+
"data-open": open,
|
|
163
|
+
className: backdropClass,
|
|
164
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
165
|
+
...mergeProps(props, modalProps, dialogProps),
|
|
166
|
+
id: contentId,
|
|
167
|
+
ref: mergedRef,
|
|
168
|
+
"data-open": open,
|
|
169
|
+
className: cn(contentClass, sizeClass[size], className),
|
|
170
|
+
children: [/* @__PURE__ */ jsx(DialogPartsContext, {
|
|
171
|
+
value: parts,
|
|
172
|
+
children
|
|
173
|
+
}), !alert && /* @__PURE__ */ jsx(IconButton, {
|
|
174
|
+
"aria-label": closeLabel,
|
|
175
|
+
variant: "ghost",
|
|
176
|
+
color: "neutral",
|
|
177
|
+
size: "sm",
|
|
178
|
+
onClick: state.close,
|
|
179
|
+
className: "absolute end-5 top-5",
|
|
180
|
+
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
181
|
+
})]
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** 부분 요소의 id를 정하고 열린 동안 dialog에 알린다. */
|
|
186
|
+
function usePartId(id, register) {
|
|
187
|
+
const generated = useId();
|
|
188
|
+
const resolved = id ?? generated;
|
|
189
|
+
useLayoutEffect(() => {
|
|
190
|
+
register(resolved);
|
|
191
|
+
return () => register(null);
|
|
192
|
+
}, [resolved, register]);
|
|
193
|
+
return resolved;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Dialog 제목(`<h2>`, `text-heading-sm`). 있으면 dialog의 `aria-labelledby`가 가리켜 이름이 된다.
|
|
197
|
+
* Dialog에서는 끝쪽 닫기 버튼과 겹치지 않게 끝 여백(36px)을 둔다.
|
|
198
|
+
*/
|
|
199
|
+
function DialogTitle({ id, className, ...props }) {
|
|
200
|
+
const { alert, setTitleId } = useDialogPartsContext("DialogTitle");
|
|
201
|
+
const resolvedId = usePartId(id, setTitleId);
|
|
202
|
+
return /* @__PURE__ */ jsx("h2", {
|
|
203
|
+
...props,
|
|
204
|
+
id: resolvedId,
|
|
205
|
+
className: cn("text-heading-sm text-default", !alert && "pe-9", className)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Dialog 설명(`<p>`, `text-muted`). 있으면 dialog의 `aria-describedby`가 가리킨다. AlertDialog에서는 알릴 내용을 여기에 쓴다.
|
|
210
|
+
* 목록·여러 문단처럼 구조가 있는 내용은 한 줄로 읽히므로 이 요소 밖에 둔다(APG Dialog).
|
|
211
|
+
*/
|
|
212
|
+
function DialogDescription({ id, className, ...props }) {
|
|
213
|
+
const { setDescriptionId } = useDialogPartsContext("DialogDescription");
|
|
214
|
+
const resolvedId = usePartId(id, setDescriptionId);
|
|
215
|
+
return /* @__PURE__ */ jsx("p", {
|
|
216
|
+
...props,
|
|
217
|
+
id: resolvedId,
|
|
218
|
+
className: cn("text-body-md text-muted", className)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/** 동작 버튼 줄. 끝쪽에 맞추고 버튼 사이는 8px이다. 앞에 덜 위험한 동작(취소)을, 끝에 주 동작을 둔다. */
|
|
222
|
+
function DialogFooter({ className, ...props }) {
|
|
223
|
+
return /* @__PURE__ */ jsx("div", {
|
|
224
|
+
...props,
|
|
225
|
+
className: cn("mt-2 flex flex-wrap justify-end gap-2", className)
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 누르면 Dialog를 닫는 버튼. `onClick`을 먼저 부르고, 그 안에서 `event.preventDefault()`를 부르면 닫지 않는다.
|
|
230
|
+
* 닫히면 포커스는 열기 전 요소로 돌아간다.
|
|
231
|
+
*/
|
|
232
|
+
function DialogClose({ render, onClick, className, ...props }) {
|
|
233
|
+
const { state } = useDialogContext("DialogClose");
|
|
234
|
+
const handleClick = (event) => {
|
|
235
|
+
onClick?.(event);
|
|
236
|
+
if (!event.defaultPrevented) state.close();
|
|
237
|
+
};
|
|
238
|
+
const merged = {
|
|
239
|
+
...props,
|
|
240
|
+
onClick: handleClick,
|
|
241
|
+
className
|
|
242
|
+
};
|
|
243
|
+
if (!render) return createElement("button", {
|
|
244
|
+
type: "button",
|
|
245
|
+
...merged
|
|
246
|
+
});
|
|
247
|
+
return renderElement({
|
|
248
|
+
defaultElement: "button",
|
|
249
|
+
render,
|
|
250
|
+
baseClassName: "",
|
|
251
|
+
props: merged
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogRoot, DialogTitle, DialogTrigger };
|
package/dist/Field.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
2
|
+
export interface FieldProps extends ComponentProps<"div"> {
|
|
3
|
+
/** 입력창의 이름이 되는 label. 화면에 보인다. */
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
/** 입력창 아래에 보이는 설명. 입력창의 `aria-describedby`로 연결된다. */
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
/** 오류 메시지. 오류 상태일 때만 보이고 입력창의 `aria-describedby`로 연결된다. */
|
|
8
|
+
error?: ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* 오류 상태. 기본값은 `error`가 있으면 `true`다.
|
|
11
|
+
* 입력창에 `aria-invalid="true"`와 `data-invalid`가 붙는다. `false`를 주면 `error`가 있어도 숨긴다.
|
|
12
|
+
*/
|
|
13
|
+
invalid?: boolean;
|
|
14
|
+
/** 필수 입력. 입력창에 네이티브 `required`가 붙고 label 뒤에 `*`가 보인다(스크린리더는 `required`로 읽는다). */
|
|
15
|
+
required?: boolean;
|
|
16
|
+
/** 비활성. 입력창에 네이티브 `disabled`가 붙는다. */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** label이 가리킬 입력창 id. 주지 않으면 자동으로 만든다. 오류 요약에서 `#id`로 링크할 때 쓴다. `group`이면 묶음의 id다. */
|
|
19
|
+
htmlFor?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 안에 둔 것이 묶음(`CheckboxGroup`, `RadioGroup`)일 때 `true`로 준다. 기본값은 `false`다.
|
|
22
|
+
* label이 `<label for>` 대신 `for` 없는 요소가 되고, 묶음이 `aria-labelledby`로 이 label을 이름으로 쓴다.
|
|
23
|
+
*/
|
|
24
|
+
group?: boolean;
|
|
25
|
+
/** 입력 Component 하나(Input, Textarea, CheckboxGroup, RadioGroup 등) */
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 입력 Component에 label, 설명, 오류 메시지를 붙인다. 안의 Input·Textarea에 `id`, `aria-describedby`,
|
|
30
|
+
* `aria-invalid`, `required`, `disabled`가 자동으로 연결된다. 묶음(CheckboxGroup·RadioGroup)은 `group`과 함께 쓴다.
|
|
31
|
+
* 서버 컴포넌트로 쓸 수 있다.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Field({ label, description, error, invalid, required, disabled, htmlFor, group, className, children, ...props }: FieldProps): ReactElement;
|
package/dist/Field.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { cn } from "./cn.js";
|
|
2
|
+
import { FieldContext } from "./field-context.js";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { CircleExclamationPointIcon } from "@tide-design/icons";
|
|
6
|
+
|
|
7
|
+
// src/Field.tsx
|
|
8
|
+
/** 값이 화면에 그릴 내용인지(null·undefined·false·빈 문자열이 아닌지) */
|
|
9
|
+
const hasContent = (node) => node !== void 0 && node !== null && node !== false && node !== "";
|
|
10
|
+
/**
|
|
11
|
+
* 입력 Component에 label, 설명, 오류 메시지를 붙인다. 안의 Input·Textarea에 `id`, `aria-describedby`,
|
|
12
|
+
* `aria-invalid`, `required`, `disabled`가 자동으로 연결된다. 묶음(CheckboxGroup·RadioGroup)은 `group`과 함께 쓴다.
|
|
13
|
+
* 서버 컴포넌트로 쓸 수 있다.
|
|
14
|
+
*/
|
|
15
|
+
function Field({ label, description, error, invalid, required = false, disabled = false, htmlFor, group = false, className, children, ...props }) {
|
|
16
|
+
const baseId = useId();
|
|
17
|
+
const controlId = htmlFor ?? `${baseId}-control`;
|
|
18
|
+
const labelId = `${baseId}-label`;
|
|
19
|
+
const descriptionId = `${baseId}-description`;
|
|
20
|
+
const errorId = `${baseId}-error`;
|
|
21
|
+
const isInvalid = invalid ?? hasContent(error);
|
|
22
|
+
const showDescription = hasContent(description);
|
|
23
|
+
const showError = isInvalid && hasContent(error);
|
|
24
|
+
const value = {
|
|
25
|
+
controlId,
|
|
26
|
+
labelId,
|
|
27
|
+
describedBy: [showDescription ? descriptionId : void 0, showError ? errorId : void 0].filter(Boolean).join(" ") || void 0,
|
|
28
|
+
invalid: isInvalid,
|
|
29
|
+
disabled,
|
|
30
|
+
required
|
|
31
|
+
};
|
|
32
|
+
const labelContent = /* @__PURE__ */ jsxs(Fragment, { children: [label, required ? /* @__PURE__ */ jsx("span", {
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
className: "ms-0.5 text-danger",
|
|
35
|
+
children: "*"
|
|
36
|
+
}) : null] });
|
|
37
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
38
|
+
...props,
|
|
39
|
+
"data-invalid": isInvalid ? "" : void 0,
|
|
40
|
+
"data-disabled": disabled ? "" : void 0,
|
|
41
|
+
className: cn("flex flex-col gap-1.5", className),
|
|
42
|
+
children: [
|
|
43
|
+
group ? /* @__PURE__ */ jsx("span", {
|
|
44
|
+
id: labelId,
|
|
45
|
+
className: "text-label-md text-default",
|
|
46
|
+
children: labelContent
|
|
47
|
+
}) : /* @__PURE__ */ jsx("label", {
|
|
48
|
+
id: labelId,
|
|
49
|
+
htmlFor: controlId,
|
|
50
|
+
className: "text-label-md text-default",
|
|
51
|
+
children: labelContent
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx(FieldContext, {
|
|
54
|
+
value,
|
|
55
|
+
children
|
|
56
|
+
}),
|
|
57
|
+
showDescription ? /* @__PURE__ */ jsx("p", {
|
|
58
|
+
id: descriptionId,
|
|
59
|
+
className: "text-body-sm text-muted",
|
|
60
|
+
children: description
|
|
61
|
+
}) : null,
|
|
62
|
+
showError ? /* @__PURE__ */ jsxs("p", {
|
|
63
|
+
id: errorId,
|
|
64
|
+
className: "flex items-start gap-1 text-body-sm text-danger",
|
|
65
|
+
children: [/* @__PURE__ */ jsx(CircleExclamationPointIcon, {
|
|
66
|
+
size: 16,
|
|
67
|
+
className: "mt-0.5 shrink-0"
|
|
68
|
+
}), /* @__PURE__ */ jsx("span", { children: error })]
|
|
69
|
+
}) : null
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Field };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FillVariant, Role, Size } from "./types.js";
|
|
2
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
3
|
+
/** IconButton의 채움 방식. Button과 같은 4개를 받는다. */
|
|
4
|
+
type IconButtonVariant = Extract<FillVariant, "solid" | "subtle" | "outline" | "ghost">;
|
|
5
|
+
/** IconButton의 size. 공통 size 4개를 모두 받는다. 가장 작은 `xs`도 24×24px다. */
|
|
6
|
+
type IconButtonSize = Extract<Size, "xs" | "sm" | "md" | "lg">;
|
|
7
|
+
export interface IconButtonProps extends Omit<ComponentProps<"button">, "color" | "aria-label" | "children"> {
|
|
8
|
+
/** 버튼 이름. 아이콘만 보이므로 반드시 적는다(예: `"설정"`). 스크린 리더가 읽는다. */
|
|
9
|
+
"aria-label": string;
|
|
10
|
+
/** 아이콘. 장식용으로 숨겨지고 size에 맞는 크기가 된다. 다른 라이브러리의 아이콘도 받는다. */
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/** 채움 방식. 기본값은 Button과 같은 `solid`다. 툴바·닫기 버튼처럼 약한 동작은 `ghost`를 쓴다. */
|
|
13
|
+
variant?: IconButtonVariant;
|
|
14
|
+
/**
|
|
15
|
+
* Role. Tide Role 6개와 앱이 `RoleRegistry`에 더한 Role을 받는다. 기본값은 `primary`다.
|
|
16
|
+
* 색 계열 이름(`blue` 등)은 받지 않는다. 행동의 뜻을 색으로 전하기 때문이다(ADR 0016).
|
|
17
|
+
* 루트에 `data-color`로 붙어 accent 색을 정한다. 바깥 요소의 색을 물려받지 않는다.
|
|
18
|
+
*/
|
|
19
|
+
color?: Role;
|
|
20
|
+
/** 정사각형 크기 `xs` 24px, `sm` 32px, `md` 40px, `lg` 48px. 아이콘은 16/16/20/24px다. 기본값은 `md`다. */
|
|
21
|
+
size?: IconButtonSize;
|
|
22
|
+
/**
|
|
23
|
+
* 로딩 중. 아이콘 자리에 Spinner를 보이고 클릭을 막는다.
|
|
24
|
+
* 포커스는 유지하고 `aria-disabled="true"`와 `data-loading`을 붙인다.
|
|
25
|
+
*/
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
/** 로딩 중에 `aria-label` 뒤에 붙는 텍스트. 기본값은 `"로딩 중"`이다. */
|
|
28
|
+
loadingLabel?: string;
|
|
29
|
+
/** 누를 때 줄어드는 반응(scale 0.96)을 끈다. 움직임 줄이기 설정에서는 이 값과 관계없이 줄어들지 않는다. */
|
|
30
|
+
noPressScale?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 다른 요소로 렌더한다. 예: `render={<Link href="/x" />}`.
|
|
33
|
+
* props, ref, className을 그 요소에 병합한다. `button`이 아닌 요소의 `disabled`는 `aria-disabled`로 바뀐다.
|
|
34
|
+
*/
|
|
35
|
+
render?: ReactElement;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 아이콘만 있는 버튼. `aria-label`이 필수라 이름이 빠지지 않는다.
|
|
39
|
+
* Button과 같은 채움 방식(`variant`) × Role(`color`) × `size` 축을 쓴다.
|
|
40
|
+
*/
|
|
41
|
+
export declare function IconButton({ variant, color, size, loading, loadingLabel, noPressScale, render, disabled, type, children, onClick, "aria-label": ariaLabel, ...props }: IconButtonProps): ReactElement;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { jsx } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
// src/IconButton.tsx
|
|
9
|
+
/** 정사각형 크기(spec size 표의 높이). padding은 없고 아이콘을 가운데 둔다. 24×24px 밑으로 내려가지 않는다. */
|
|
10
|
+
const sizeClass = {
|
|
11
|
+
xs: "size-6",
|
|
12
|
+
sm: "size-8",
|
|
13
|
+
md: "size-10",
|
|
14
|
+
lg: "size-12"
|
|
15
|
+
};
|
|
16
|
+
/** 아이콘 크기(spec 아이콘 크기 규칙 「IconButton 아이콘」 열). 감싼 span과 Spinner에 쓴다. */
|
|
17
|
+
const iconSizeClass = {
|
|
18
|
+
xs: "size-4",
|
|
19
|
+
sm: "size-4",
|
|
20
|
+
md: "size-5",
|
|
21
|
+
lg: "size-6"
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 아이콘만 있는 버튼. `aria-label`이 필수라 이름이 빠지지 않는다.
|
|
25
|
+
* Button과 같은 채움 방식(`variant`) × Role(`color`) × `size` 축을 쓴다.
|
|
26
|
+
*/
|
|
27
|
+
function IconButton({ variant = "solid", color = "primary", size = "md", loading = false, loadingLabel = "로딩 중", noPressScale = false, render, disabled = false, type, children, onClick, "aria-label": ariaLabel, ...props }) {
|
|
28
|
+
const state = pressableState({
|
|
29
|
+
variant,
|
|
30
|
+
color,
|
|
31
|
+
disabled,
|
|
32
|
+
loading,
|
|
33
|
+
noPressScale,
|
|
34
|
+
render,
|
|
35
|
+
type,
|
|
36
|
+
onClick,
|
|
37
|
+
ariaDisabled: props["aria-disabled"]
|
|
38
|
+
});
|
|
39
|
+
const { showSpinner } = state;
|
|
40
|
+
const icon = children ?? (render?.props)?.children;
|
|
41
|
+
const rootProps = {
|
|
42
|
+
...props,
|
|
43
|
+
...state.rootProps,
|
|
44
|
+
"aria-label": showSpinner ? `${ariaLabel} ${loadingLabel}` : ariaLabel,
|
|
45
|
+
children: showSpinner ? /* @__PURE__ */ jsx(Spinner, {
|
|
46
|
+
size,
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
className: iconSizeClass[size]
|
|
49
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
50
|
+
"aria-hidden": "true",
|
|
51
|
+
className: `inline-flex shrink-0 items-center justify-center *:size-full ${iconSizeClass[size]}`,
|
|
52
|
+
children: icon
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
return renderElement({
|
|
56
|
+
defaultElement: "button",
|
|
57
|
+
render,
|
|
58
|
+
baseClassName: `${pressableBaseClass} p-0 ${sizeClass[size]} ${state.className}`,
|
|
59
|
+
props: rootProps
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { IconButton };
|
package/dist/Input.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InputSize } from "./input-style.js";
|
|
2
|
+
import { ComponentProps, ReactElement } from "react";
|
|
3
|
+
export interface InputProps extends Omit<ComponentProps<"input">, "size"> {
|
|
4
|
+
/** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Button과 높이가 같다. 기본값은 `md`다. */
|
|
5
|
+
size?: InputSize;
|
|
6
|
+
/**
|
|
7
|
+
* 오류 상태. `aria-invalid="true"`와 `data-invalid`가 붙고 경계가 danger 색이 된다.
|
|
8
|
+
* Field 안에서는 Field의 값을 따르고, 여기에 준 값이 이긴다.
|
|
9
|
+
*/
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 한 줄 텍스트를 입력하는 네이티브 `<input>`. `type`(`email`, `password`, `date` 등)을 그대로 받는다.
|
|
14
|
+
* Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Input({ size, invalid, id, disabled, required, className, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: InputProps): ReactElement;
|
package/dist/Input.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
import { useFieldControl } from "./field-context.js";
|
|
5
|
+
import { inputBaseClass, inputSizeClass } from "./input-style.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
// src/Input.tsx
|
|
9
|
+
/**
|
|
10
|
+
* 한 줄 텍스트를 입력하는 네이티브 `<input>`. `type`(`email`, `password`, `date` 등)을 그대로 받는다.
|
|
11
|
+
* Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
12
|
+
*/
|
|
13
|
+
function Input({ size = "md", invalid, id, disabled, required, className, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }) {
|
|
14
|
+
const control = useFieldControl({
|
|
15
|
+
id,
|
|
16
|
+
invalid,
|
|
17
|
+
disabled,
|
|
18
|
+
required,
|
|
19
|
+
"aria-describedby": ariaDescribedBy,
|
|
20
|
+
"aria-invalid": ariaInvalid
|
|
21
|
+
});
|
|
22
|
+
return /* @__PURE__ */ jsx("input", {
|
|
23
|
+
...props,
|
|
24
|
+
...control,
|
|
25
|
+
className: cn(inputSizeClass[size], inputBaseClass, className)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Input };
|
package/dist/Link.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Role } from "./types.js";
|
|
2
|
+
import { ComponentProps, ReactElement } from "react";
|
|
3
|
+
export interface LinkProps extends Omit<ComponentProps<"a">, "color"> {
|
|
4
|
+
/**
|
|
5
|
+
* Role. Tide Role 6개와 앱이 `RoleRegistry`에 더한 Role을 받는다. 기본값은 `primary`다.
|
|
6
|
+
* 색 계열 이름(`blue` 등)은 받지 않는다. 행동의 뜻을 색으로 전하기 때문이다(ADR 0016).
|
|
7
|
+
* 루트에 `data-color`로 붙어 글자색(`text-accent`)을 정한다. 바깥 요소의 색을 물려받지 않는다.
|
|
8
|
+
*/
|
|
9
|
+
color?: Role;
|
|
10
|
+
/**
|
|
11
|
+
* 다른 요소로 렌더한다. 예: `render={<NextLink href="/x" />}`.
|
|
12
|
+
* props, ref, className을 그 요소에 병합한다.
|
|
13
|
+
*/
|
|
14
|
+
render?: ReactElement;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 문장 안에서 다른 페이지나 위치로 이동하는 텍스트 링크.
|
|
18
|
+
* Next.js에서는 `render={<NextLink href="/x" />}`로 클라이언트 이동을 쓴다.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Link({ color, render, ...props }: LinkProps): ReactElement;
|
package/dist/Link.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { renderElement } from "./render.js";
|
|
2
|
+
|
|
3
|
+
// src/Link.tsx
|
|
4
|
+
const baseClass = "cursor-pointer rounded-sm text-accent underline decoration-1 underline-offset-2 hover:decoration-2 focus-visible:focus-ring";
|
|
5
|
+
/**
|
|
6
|
+
* 문장 안에서 다른 페이지나 위치로 이동하는 텍스트 링크.
|
|
7
|
+
* Next.js에서는 `render={<NextLink href="/x" />}`로 클라이언트 이동을 쓴다.
|
|
8
|
+
*/
|
|
9
|
+
function Link({ color = "primary", render, ...props }) {
|
|
10
|
+
return renderElement({
|
|
11
|
+
defaultElement: "a",
|
|
12
|
+
render,
|
|
13
|
+
baseClassName: baseClass,
|
|
14
|
+
props: {
|
|
15
|
+
...props,
|
|
16
|
+
"data-color": color
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { Link };
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CollectionItemProps, CollectionSectionProps } from "./list-collection.js";
|
|
2
|
+
import { OverlayPlacement } from "./overlay.js";
|
|
3
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
4
|
+
/** Menu 목록의 위치. 앞은 트리거의 어느 쪽, 뒤는 그 변에서 맞출 끝이다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
|
|
5
|
+
export type MenuPlacement = OverlayPlacement;
|
|
6
|
+
export interface MenuProps {
|
|
7
|
+
/** 열림 상태(제어). 주면 `onOpenChange`로 바꾼다. */
|
|
8
|
+
open?: boolean;
|
|
9
|
+
/** 처음 열림 상태(비제어). 기본값은 `false`다. */
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/** 열림 상태가 바뀌려 할 때 새 값으로 부른다. 항목을 실행해 닫힐 때도 부른다. */
|
|
12
|
+
onOpenChange?: (open: boolean) => void;
|
|
13
|
+
/** `MenuTrigger`와 `MenuContent` */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 트리거와 동작 목록을 잇는 열림 상태. DOM 요소를 만들지 않는다.
|
|
18
|
+
* 안에 `MenuTrigger` 하나와 `MenuContent` 하나를 둔다.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Menu({ open, defaultOpen, onOpenChange, children }: MenuProps): ReactElement;
|
|
21
|
+
export interface MenuTriggerProps extends ComponentProps<"button"> {
|
|
22
|
+
/**
|
|
23
|
+
* 다른 요소로 렌더한다. 예: `render={<Button variant="outline" />}`, `render={<IconButton aria-label="더보기" />}`.
|
|
24
|
+
* props, ref, className, 이벤트 핸들러를 그 요소에 병합한다. 기본은 class 없는 `<button type="button">`이다.
|
|
25
|
+
*/
|
|
26
|
+
render?: ReactElement;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Menu를 여는 버튼. 마우스는 누르는 순간 열고, 키보드는 Enter·Space·↓로 열어 첫 항목에, ↑로 열어 마지막 항목에
|
|
30
|
+
* 위치한다. `aria-haspopup`, `aria-expanded`, 열렸을 때 `aria-controls`와 `data-open`이 붙는다.
|
|
31
|
+
*/
|
|
32
|
+
export declare function MenuTrigger({ render, ref, id, className, ...props }: MenuTriggerProps): ReactElement;
|
|
33
|
+
export interface MenuContentProps extends Omit<ComponentProps<"div">, "id" | "role"> {
|
|
34
|
+
/** 트리거 기준 위치. 기본값은 `bottom start`(아래, 시작 끝 맞춤)다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
|
|
35
|
+
placement?: MenuPlacement;
|
|
36
|
+
/** 트리거와의 간격(px). 기본값은 `4`다. */
|
|
37
|
+
offset?: number;
|
|
38
|
+
/** `MenuItem`과 `MenuSection`. 이 요소들을 바로 아래(또는 Fragment·배열 안)에 둔다. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 트리거 옆에 뜨는 동작 목록(`role="menu"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-popover`로 쌓는다.
|
|
43
|
+
* 바로 나타나고, 닫히면 opacity만 `fast`(150ms)로 사라진다.
|
|
44
|
+
* 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
|
|
45
|
+
*/
|
|
46
|
+
export declare function MenuContent(props: MenuContentProps): ReactElement | null;
|
|
47
|
+
export interface MenuItemProps extends Omit<ComponentProps<"div">, "role" | "children">, CollectionItemProps {
|
|
48
|
+
/** 항목 내용. 아이콘(장식용)과 글자를 함께 둘 수 있다. */
|
|
49
|
+
children?: ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* 항목을 실행할 때 부른다. 마우스·터치 누름뿐 아니라 Enter·Space도 click으로 실행한다(네이티브 버튼과 같다).
|
|
52
|
+
* 실행하면 메뉴가 닫힌다. `disabled`면 부르지 않는다.
|
|
53
|
+
*/
|
|
54
|
+
onClick?: ComponentProps<"div">["onClick"];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Menu의 동작 항목(`role="menuitem"`). `MenuContent`나 `MenuSection` 바로 안에 둔다.
|
|
58
|
+
* 키보드 위치와 마우스를 올린 항목은 highlight(primary subtle 배경, primary 글자)로 바로 바뀐다.
|
|
59
|
+
* 상태는 `data-highlighted`(키보드 위치·hover), `data-disabled`(비활성)로 노출한다.
|
|
60
|
+
*/
|
|
61
|
+
export declare function MenuItem(_props: MenuItemProps): null;
|
|
62
|
+
export interface MenuSectionProps extends CollectionSectionProps {
|
|
63
|
+
/** 묶음 감싸개(`<div role="presentation">`)에 붙는 class */
|
|
64
|
+
className?: string;
|
|
65
|
+
/** `MenuItem`. 바로 아래(또는 Fragment·배열 안)에 둔다. */
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 항목 묶음(`role="group"`). `heading`이 화면에 보이는 제목이자 묶음의 이름이고, 없으면 `aria-label`이 이름이다.
|
|
70
|
+
* 앞뒤 다른 항목·묶음과의 사이에 구분선(`role="separator"`)이 그려진다.
|
|
71
|
+
*/
|
|
72
|
+
export declare function MenuSection(_props: MenuSectionProps): null;
|