@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/Toast.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { alertCloseClass, alertContentClass, alertDescriptionClass, alertIconClass, alertLayoutClass, alertStatusIcon, alertTitleClass } from "./alert-style.js";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
5
|
+
import { cn } from "./cn.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { OverlayPortal, useOverlayPresence } from "./overlay.js";
|
|
8
|
+
import { overlaySurfaceClass, popoverMotionClass } from "./overlay-style.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
|
+
import { XIcon } from "@tide-design/icons";
|
|
12
|
+
import { mergeProps, mergeRefs, useToast, useToastRegion } from "react-aria";
|
|
13
|
+
import { ToastQueue, useToastQueue } from "react-stately";
|
|
14
|
+
|
|
15
|
+
// src/Toast.tsx
|
|
16
|
+
/** 자동으로 닫히는 Toast가 보이는 가장 짧은 시간(ms). React Aria 문서가 권하는 최소값과 같다. */
|
|
17
|
+
const minTimeout = 5e3;
|
|
18
|
+
const statelyQueues = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
/** 자동 닫힘 시간. `undefined`면 자동으로 닫지 않는다. */
|
|
20
|
+
function resolveTimeout(options) {
|
|
21
|
+
if (options.action !== void 0 || options.color === "danger") return void 0;
|
|
22
|
+
const timeout = options.timeout === void 0 ? minTimeout : options.timeout;
|
|
23
|
+
if (timeout === null || !Number.isFinite(timeout)) return void 0;
|
|
24
|
+
return Math.max(timeout, minTimeout);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Toast 큐. React 밖(모듈)에서 만들어 `ToastRegion`에 넘기고, 어디서든 `add`로 띄운다.
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* export const toasts = new ToastQueue();
|
|
31
|
+
* toasts.add({ title: "저장했습니다" });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
var ToastQueue$1 = class {
|
|
35
|
+
constructor({ maxVisible = 3 } = {}) {
|
|
36
|
+
statelyQueues.set(this, new ToastQueue({ maxVisibleToasts: maxVisible }));
|
|
37
|
+
}
|
|
38
|
+
/** Toast를 띄우고 key를 돌려준다. 새 Toast가 맨 앞(영역의 아래)에 온다. */
|
|
39
|
+
add(options) {
|
|
40
|
+
const { timeout: _timeout, onClose, ...content } = options;
|
|
41
|
+
return queueOf(this).add(content, {
|
|
42
|
+
timeout: resolveTimeout(options),
|
|
43
|
+
onClose
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** key의 Toast를 닫는다. */
|
|
47
|
+
close(key) {
|
|
48
|
+
queueOf(this).close(key);
|
|
49
|
+
}
|
|
50
|
+
/** 모든 Toast를 닫는다. 기다리던 Toast도 빠진다. `onClose`는 부르지 않는다. */
|
|
51
|
+
clear() {
|
|
52
|
+
queueOf(this).clear();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function queueOf(queue) {
|
|
56
|
+
const stately = statelyQueues.get(queue);
|
|
57
|
+
if (!stately) throw new Error("ToastRegion의 queue에는 new ToastQueue()로 만든 큐를 넘긴다.");
|
|
58
|
+
return stately;
|
|
59
|
+
}
|
|
60
|
+
const regionClass = "fixed end-4 bottom-4 isolate z-toast flex w-[calc(100%-2rem)] max-w-96 flex-col-reverse gap-2 rounded-lg outline-none focus-visible:focus-ring";
|
|
61
|
+
const toastClass = `${alertLayoutClass} ${overlaySurfaceClass} ${popoverMotionClass} outline-none focus-visible:focus-ring`;
|
|
62
|
+
/** 보이는 Toast 목록에 퇴장 중인 Toast를 원래 자리에 끼워 넣는다. */
|
|
63
|
+
function mergeEntries(previous, visible) {
|
|
64
|
+
const visibleKeys = new Set(visible.map((toast) => toast.key));
|
|
65
|
+
const next = visible.map((toast) => ({
|
|
66
|
+
toast,
|
|
67
|
+
open: true
|
|
68
|
+
}));
|
|
69
|
+
previous.forEach((entry, index) => {
|
|
70
|
+
if (visibleKeys.has(entry.toast.key)) return;
|
|
71
|
+
next.splice(Math.min(index, next.length), 0, {
|
|
72
|
+
toast: entry.toast,
|
|
73
|
+
open: false
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return next;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `ToastQueue`의 Toast를 그리는 영역. 앱에 하나 둔다(보통 레이아웃의 client Component 안).
|
|
80
|
+
* Toast가 있을 때만 `document.body`에 portal하고, 없으면 아무것도 그리지 않는다.
|
|
81
|
+
*/
|
|
82
|
+
function ToastRegion({ queue, ...props }) {
|
|
83
|
+
const state = useToastQueue(queueOf(queue));
|
|
84
|
+
const [entries, setEntries] = useState(() => state.visibleToasts.map((toast) => ({
|
|
85
|
+
toast,
|
|
86
|
+
open: true
|
|
87
|
+
})));
|
|
88
|
+
const [visible, setVisible] = useState(state.visibleToasts);
|
|
89
|
+
if (visible !== state.visibleToasts) {
|
|
90
|
+
setVisible(state.visibleToasts);
|
|
91
|
+
setEntries(mergeEntries(entries, state.visibleToasts));
|
|
92
|
+
}
|
|
93
|
+
const onExited = useCallback((key) => {
|
|
94
|
+
setEntries((current) => current.filter((entry) => entry.open || entry.toast.key !== key));
|
|
95
|
+
}, []);
|
|
96
|
+
if (entries.length === 0) return null;
|
|
97
|
+
return /* @__PURE__ */ jsx(OverlayPortal, {
|
|
98
|
+
isExiting: false,
|
|
99
|
+
focusManagement: false,
|
|
100
|
+
children: /* @__PURE__ */ jsx(Region, {
|
|
101
|
+
...props,
|
|
102
|
+
state,
|
|
103
|
+
entries,
|
|
104
|
+
onExited
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function Region({ state, entries, onExited, ref, className, "aria-label": ariaLabel, ...props }) {
|
|
109
|
+
const regionRef = useRef(null);
|
|
110
|
+
const mergedRef = useMemo(() => mergeRefs(ref, regionRef), [ref]);
|
|
111
|
+
const { regionProps } = useToastRegion({ "aria-label": ariaLabel }, state, regionRef);
|
|
112
|
+
return /* @__PURE__ */ jsx("div", {
|
|
113
|
+
...mergeProps(props, regionProps),
|
|
114
|
+
ref: mergedRef,
|
|
115
|
+
className: cn(regionClass, className),
|
|
116
|
+
children: entries.map((entry) => /* @__PURE__ */ jsx(ToastItem, {
|
|
117
|
+
toast: entry.toast,
|
|
118
|
+
open: entry.open,
|
|
119
|
+
state,
|
|
120
|
+
onExited
|
|
121
|
+
}, entry.toast.key))
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function ToastItem({ toast, open, state, onExited }) {
|
|
125
|
+
const ref = useRef(null);
|
|
126
|
+
const present = useOverlayPresence(open, ref);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (!present) onExited(toast.key);
|
|
129
|
+
}, [
|
|
130
|
+
present,
|
|
131
|
+
onExited,
|
|
132
|
+
toast.key
|
|
133
|
+
]);
|
|
134
|
+
const { toastProps, contentProps, titleProps, descriptionProps } = useToast({ toast }, state, ref);
|
|
135
|
+
const { title, description, color = "info", action, closeLabel = "닫기" } = toast.content;
|
|
136
|
+
const StatusIcon = alertStatusIcon(color);
|
|
137
|
+
const close = () => state.close(toast.key);
|
|
138
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
139
|
+
...open ? toastProps : {},
|
|
140
|
+
ref,
|
|
141
|
+
"data-color": color,
|
|
142
|
+
"data-open": open ? "" : void 0,
|
|
143
|
+
inert: !open,
|
|
144
|
+
"data-placement": "top",
|
|
145
|
+
className: toastClass,
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ jsx(StatusIcon, {
|
|
148
|
+
size: 20,
|
|
149
|
+
"aria-hidden": "true",
|
|
150
|
+
className: `${alertIconClass} text-accent`
|
|
151
|
+
}),
|
|
152
|
+
/* @__PURE__ */ jsxs("div", {
|
|
153
|
+
className: "flex min-w-0 flex-1 flex-col gap-3",
|
|
154
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
155
|
+
...open ? contentProps : {},
|
|
156
|
+
className: alertContentClass,
|
|
157
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
158
|
+
...titleProps,
|
|
159
|
+
className: alertTitleClass,
|
|
160
|
+
children: title
|
|
161
|
+
}), description !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
162
|
+
...descriptionProps,
|
|
163
|
+
className: "text-body-sm",
|
|
164
|
+
children: description
|
|
165
|
+
})]
|
|
166
|
+
}), action !== void 0 && /* @__PURE__ */ jsx(Button, {
|
|
167
|
+
variant: "outline",
|
|
168
|
+
color: "neutral",
|
|
169
|
+
size: "sm",
|
|
170
|
+
className: "self-start",
|
|
171
|
+
onClick: (event) => {
|
|
172
|
+
action.onClick?.(event);
|
|
173
|
+
if (!event.defaultPrevented) close();
|
|
174
|
+
},
|
|
175
|
+
children: action.label
|
|
176
|
+
})]
|
|
177
|
+
}),
|
|
178
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
179
|
+
"aria-label": closeLabel,
|
|
180
|
+
variant: "ghost",
|
|
181
|
+
color: "neutral",
|
|
182
|
+
size: "xs",
|
|
183
|
+
onClick: close,
|
|
184
|
+
className: alertCloseClass,
|
|
185
|
+
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { ToastQueue$1 as ToastQueue, ToastRegion };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OverlayPlacement } from "./overlay.js";
|
|
2
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
3
|
+
/** Tooltip 설명의 위치. 앞은 트리거의 어느 쪽, 뒤는 그 변에서 맞출 끝이다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
|
|
4
|
+
export type TooltipPlacement = OverlayPlacement;
|
|
5
|
+
export interface TooltipProps {
|
|
6
|
+
/** 열림 상태(제어). 주면 `onOpenChange`로 바꾼다. */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** 처음 열림 상태(비제어). 기본값은 `false`다. */
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
/** 열림 상태가 바뀌려 할 때 새 값으로 부른다. */
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
/**
|
|
13
|
+
* 마우스를 올린 뒤 열릴 때까지 기다리는 시간(ms). 기본값은 `500`이다. 키보드 포커스는 기다리지 않는다.
|
|
14
|
+
* 한 Tooltip이 열린 뒤 잠깐(0.5초) 안에 다른 트리거로 옮기면 기다리지 않고 바로 연다.
|
|
15
|
+
*/
|
|
16
|
+
delay?: number;
|
|
17
|
+
/** 포인터가 트리거·설명을 떠난 뒤 닫힐 때까지 기다리는 시간(ms). 기본값은 `300`이다. 설명으로 옮겨 갈 틈이다. */
|
|
18
|
+
closeDelay?: number;
|
|
19
|
+
/** `true`면 열리지 않는다. 트리거는 그대로 동작한다. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** `TooltipTrigger`와 `TooltipContent` */
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 트리거와 설명을 잇는 열림 상태. DOM 요소를 만들지 않는다.
|
|
26
|
+
* 안에 `TooltipTrigger` 하나와 `TooltipContent` 하나를 둔다.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Tooltip({ open, defaultOpen, onOpenChange, delay, closeDelay, disabled, children }: TooltipProps): ReactElement;
|
|
29
|
+
export interface TooltipTriggerProps extends ComponentProps<"button"> {
|
|
30
|
+
/**
|
|
31
|
+
* 다른 요소로 렌더한다. 예: `render={<IconButton aria-label="복사" />}`, `render={<Button variant="ghost" />}`.
|
|
32
|
+
* props, ref, className, 이벤트 핸들러를 그 요소에 병합한다. 기본은 class 없는 `<button type="button">`이다.
|
|
33
|
+
* 포커스를 받을 수 있는 요소여야 키보드 사용자도 설명을 본다.
|
|
34
|
+
*/
|
|
35
|
+
render?: ReactElement;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tooltip을 여는 요소. 마우스를 올리면 `delay` 뒤에, 키보드로 포커스하면 바로 열린다.
|
|
39
|
+
* 누르면(마우스, 터치, 키) 닫힌다. 열린 동안 `aria-describedby`에 설명 id가 더해진다.
|
|
40
|
+
*/
|
|
41
|
+
export declare function TooltipTrigger({ render, ref, className, "aria-describedby": describedBy, ...props }: TooltipTriggerProps): ReactElement;
|
|
42
|
+
export interface TooltipContentProps extends Omit<ComponentProps<"div">, "id" | "role"> {
|
|
43
|
+
/** 트리거 기준 위치. 기본값은 `top`(위, 가운데 맞춤)이다. 공간이 모자라면 반대쪽으로 뒤집힌다. */
|
|
44
|
+
placement?: TooltipPlacement;
|
|
45
|
+
/** 트리거와의 간격(px). 기본값은 `4`다. */
|
|
46
|
+
offset?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 트리거에 붙는 설명(`role="tooltip"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-tooltip`으로 쌓는다.
|
|
50
|
+
* 바로 나타나고, 닫히면 opacity만 `fast`(150ms)로 사라진다. 조작 요소(버튼, 링크)는 넣지 않는다.
|
|
51
|
+
* 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
|
|
52
|
+
*/
|
|
53
|
+
export declare function TooltipContent(props: TooltipContentProps): ReactElement | null;
|
package/dist/Tooltip.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
import { OverlayPortal, overlayPositionProps, useOverlayPresence, useOverlayTheme } from "./overlay.js";
|
|
5
|
+
import { frequentMotionClass, overlaySurfaceClass } from "./overlay-style.js";
|
|
6
|
+
import { renderElement } from "./render.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { createContext, createElement, use, useMemo, useRef } from "react";
|
|
9
|
+
import { mergeProps, mergeRefs, useOverlayPosition, useTooltip, useTooltipTrigger } from "react-aria";
|
|
10
|
+
import { useTooltipTriggerState } from "react-stately";
|
|
11
|
+
|
|
12
|
+
// src/Tooltip.tsx
|
|
13
|
+
const TooltipContext = createContext(null);
|
|
14
|
+
function useTooltipContext(part) {
|
|
15
|
+
const context = use(TooltipContext);
|
|
16
|
+
if (!context) throw new Error(`${part}는 Tooltip 안에 둔다.`);
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 트리거와 설명을 잇는 열림 상태. DOM 요소를 만들지 않는다.
|
|
21
|
+
* 안에 `TooltipTrigger` 하나와 `TooltipContent` 하나를 둔다.
|
|
22
|
+
*/
|
|
23
|
+
function Tooltip({ open, defaultOpen, onOpenChange, delay = 500, closeDelay = 300, disabled, children }) {
|
|
24
|
+
const options = {
|
|
25
|
+
isOpen: open,
|
|
26
|
+
defaultOpen,
|
|
27
|
+
onOpenChange,
|
|
28
|
+
delay,
|
|
29
|
+
closeDelay,
|
|
30
|
+
isDisabled: disabled
|
|
31
|
+
};
|
|
32
|
+
const state = useTooltipTriggerState(options);
|
|
33
|
+
const triggerRef = useRef(null);
|
|
34
|
+
const { triggerProps, tooltipProps } = useTooltipTrigger(options, state, triggerRef);
|
|
35
|
+
const value = useMemo(() => ({
|
|
36
|
+
state,
|
|
37
|
+
triggerRef,
|
|
38
|
+
triggerProps,
|
|
39
|
+
tooltipId: tooltipProps.id
|
|
40
|
+
}), [
|
|
41
|
+
state,
|
|
42
|
+
triggerProps,
|
|
43
|
+
tooltipProps.id
|
|
44
|
+
]);
|
|
45
|
+
return /* @__PURE__ */ jsx(TooltipContext, {
|
|
46
|
+
value,
|
|
47
|
+
children
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Tooltip을 여는 요소. 마우스를 올리면 `delay` 뒤에, 키보드로 포커스하면 바로 열린다.
|
|
52
|
+
* 누르면(마우스, 터치, 키) 닫힌다. 열린 동안 `aria-describedby`에 설명 id가 더해진다.
|
|
53
|
+
*/
|
|
54
|
+
function TooltipTrigger({ render, ref, className, "aria-describedby": describedBy, ...props }) {
|
|
55
|
+
const { triggerRef, triggerProps } = useTooltipContext("TooltipTrigger");
|
|
56
|
+
const { tabIndex: _tabIndex, "aria-describedby": tooltipDescribedBy, ...ariaProps } = triggerProps;
|
|
57
|
+
const mergedRef = useMemo(() => mergeRefs(ref, triggerRef), [ref, triggerRef]);
|
|
58
|
+
const merged = {
|
|
59
|
+
...mergeProps(props, ariaProps),
|
|
60
|
+
"aria-describedby": [describedBy, tooltipDescribedBy].filter(Boolean).join(" ") || void 0,
|
|
61
|
+
ref: mergedRef
|
|
62
|
+
};
|
|
63
|
+
if (!render) return createElement("button", {
|
|
64
|
+
type: "button",
|
|
65
|
+
...merged,
|
|
66
|
+
className
|
|
67
|
+
});
|
|
68
|
+
return renderElement({
|
|
69
|
+
defaultElement: "button",
|
|
70
|
+
render,
|
|
71
|
+
baseClassName: "",
|
|
72
|
+
props: {
|
|
73
|
+
...merged,
|
|
74
|
+
className
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const contentClass = `isolate z-tooltip max-w-60 px-2 py-1 text-body-sm ${overlaySurfaceClass} ${frequentMotionClass}`;
|
|
79
|
+
/**
|
|
80
|
+
* 트리거에 붙는 설명(`role="tooltip"`). 열릴 때만 `document.body`에 portal로 렌더하고 `z-tooltip`으로 쌓는다.
|
|
81
|
+
* 바로 나타나고, 닫히면 opacity만 `fast`(150ms)로 사라진다. 조작 요소(버튼, 링크)는 넣지 않는다.
|
|
82
|
+
* 열려 있으면 `data-open`이, 트리거 기준 방향이 `data-placement`(`top`/`bottom`/`left`/`right`)로 붙는다.
|
|
83
|
+
*/
|
|
84
|
+
function TooltipContent(props) {
|
|
85
|
+
const context = useTooltipContext("TooltipContent");
|
|
86
|
+
const tooltipRef = useRef(null);
|
|
87
|
+
if (!useOverlayPresence(context.state.isOpen, tooltipRef)) return null;
|
|
88
|
+
return /* @__PURE__ */ jsx(OverlayPortal, {
|
|
89
|
+
isExiting: !context.state.isOpen,
|
|
90
|
+
focusManagement: false,
|
|
91
|
+
children: /* @__PURE__ */ jsx(TooltipContentInner, {
|
|
92
|
+
...props,
|
|
93
|
+
context,
|
|
94
|
+
tooltipRef
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** DOM에 있는 동안만 portal 안에서 렌더한다. 위치 hook은 요소가 있다고 보고 동작한다. */
|
|
99
|
+
function TooltipContentInner({ context, tooltipRef, placement = "top", offset = 4, ref, className, children, ...props }) {
|
|
100
|
+
const { state, triggerRef, tooltipId } = context;
|
|
101
|
+
useOverlayTheme(triggerRef, tooltipRef);
|
|
102
|
+
const position = useOverlayPosition({
|
|
103
|
+
targetRef: triggerRef,
|
|
104
|
+
overlayRef: tooltipRef,
|
|
105
|
+
placement,
|
|
106
|
+
offset,
|
|
107
|
+
isOpen: state.isOpen,
|
|
108
|
+
onClose: () => state.close(true)
|
|
109
|
+
});
|
|
110
|
+
const overlayProps = overlayPositionProps(position.overlayProps, position.placement, placement);
|
|
111
|
+
const { tooltipProps } = useTooltip({}, state);
|
|
112
|
+
const mergedRef = useMemo(() => mergeRefs(ref, tooltipRef), [ref, tooltipRef]);
|
|
113
|
+
const { style: _style, ...rest } = mergeProps(props, overlayProps, tooltipProps);
|
|
114
|
+
return /* @__PURE__ */ jsx("div", {
|
|
115
|
+
...rest,
|
|
116
|
+
id: tooltipId,
|
|
117
|
+
ref: mergedRef,
|
|
118
|
+
"data-open": state.isOpen ? "" : void 0,
|
|
119
|
+
"data-react-aria-top-layer": "",
|
|
120
|
+
className: cn(contentClass, !state.isOpen && state.shouldSkipAnimation && "transition-none", className),
|
|
121
|
+
style: {
|
|
122
|
+
...overlayProps.style,
|
|
123
|
+
...props.style
|
|
124
|
+
},
|
|
125
|
+
children
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { Tooltip, TooltipContent, TooltipTrigger };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactElement, Ref } from "react";
|
|
2
|
+
import { TextStyleName } from "@tide-design/foundation";
|
|
3
|
+
/** heading·display 텍스트 스타일. 항상 `<h*>`로 렌더되고 `level`을 받는다. */
|
|
4
|
+
type HeadingVariant = Extract<TextStyleName, `display-${string}` | `heading-${string}`>;
|
|
5
|
+
/** heading·display가 아닌 텍스트 스타일 */
|
|
6
|
+
type TextVariant = Exclude<TextStyleName, HeadingVariant>;
|
|
7
|
+
/** 제목 단계 */
|
|
8
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
9
|
+
interface TypographyBaseProps extends HTMLAttributes<HTMLElement> {
|
|
10
|
+
/** 루트 DOM 요소에 연결한다. */
|
|
11
|
+
ref?: Ref<HTMLElement>;
|
|
12
|
+
/**
|
|
13
|
+
* 다른 요소로 렌더한다. 예: `render={<label htmlFor="name" />}`.
|
|
14
|
+
* props, ref, className을 그 요소에 병합하고 `level`과 기본 요소는 무시한다.
|
|
15
|
+
*/
|
|
16
|
+
render?: ReactElement;
|
|
17
|
+
}
|
|
18
|
+
interface TypographyHeadingProps extends TypographyBaseProps {
|
|
19
|
+
/** 텍스트 스타일 이름 */
|
|
20
|
+
variant: HeadingVariant;
|
|
21
|
+
/** 제목 단계. 주지 않으면 텍스트 스타일의 기본 단계를 쓴다. */
|
|
22
|
+
level?: HeadingLevel;
|
|
23
|
+
}
|
|
24
|
+
interface TypographyTextProps extends TypographyBaseProps {
|
|
25
|
+
/** 텍스트 스타일 이름. 기본값은 `body-md`다. */
|
|
26
|
+
variant?: TextVariant;
|
|
27
|
+
/** heading·display 텍스트 스타일에만 있다. */
|
|
28
|
+
level?: never;
|
|
29
|
+
}
|
|
30
|
+
export type TypographyProps = TypographyHeadingProps | TypographyTextProps;
|
|
31
|
+
/**
|
|
32
|
+
* 텍스트 스타일 하나로 크기, 행간, 굵기를 정하고 알맞은 시맨틱 요소로 렌더한다.
|
|
33
|
+
* heading·display는 항상 `<h*>`다. 다른 요소가 필요하면 `render`를 쓴다. 서버 컴포넌트로 쓸 수 있다.
|
|
34
|
+
*/
|
|
35
|
+
export declare function Typography({ variant, level, render, ...props }: TypographyProps): ReactElement;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { renderElement } from "./render.js";
|
|
2
|
+
|
|
3
|
+
// src/Typography.tsx
|
|
4
|
+
const variantClass = {
|
|
5
|
+
"display-lg": "text-display-lg",
|
|
6
|
+
"display-md": "text-display-md",
|
|
7
|
+
"heading-xl": "text-heading-xl",
|
|
8
|
+
"heading-lg": "text-heading-lg",
|
|
9
|
+
"heading-md": "text-heading-md",
|
|
10
|
+
"heading-sm": "text-heading-sm",
|
|
11
|
+
"heading-xs": "text-heading-xs",
|
|
12
|
+
"body-lg": "text-body-lg",
|
|
13
|
+
"body-md": "text-body-md",
|
|
14
|
+
"body-sm": "text-body-sm",
|
|
15
|
+
"label-lg": "text-label-lg",
|
|
16
|
+
"label-md": "text-label-md",
|
|
17
|
+
"label-sm": "text-label-sm",
|
|
18
|
+
caption: "text-caption"
|
|
19
|
+
};
|
|
20
|
+
const elementByVariant = {
|
|
21
|
+
"display-lg": 1,
|
|
22
|
+
"display-md": 1,
|
|
23
|
+
"heading-xl": 1,
|
|
24
|
+
"heading-lg": 2,
|
|
25
|
+
"heading-md": 3,
|
|
26
|
+
"heading-sm": 4,
|
|
27
|
+
"heading-xs": 5,
|
|
28
|
+
"body-lg": "p",
|
|
29
|
+
"body-md": "p",
|
|
30
|
+
"body-sm": "p",
|
|
31
|
+
"label-lg": "span",
|
|
32
|
+
"label-md": "span",
|
|
33
|
+
"label-sm": "span",
|
|
34
|
+
caption: "p"
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 텍스트 스타일 하나로 크기, 행간, 굵기를 정하고 알맞은 시맨틱 요소로 렌더한다.
|
|
38
|
+
* heading·display는 항상 `<h*>`다. 다른 요소가 필요하면 `render`를 쓴다. 서버 컴포넌트로 쓸 수 있다.
|
|
39
|
+
*/
|
|
40
|
+
function Typography({ variant = "body-md", level, render, ...props }) {
|
|
41
|
+
const element = elementByVariant[variant];
|
|
42
|
+
return renderElement({
|
|
43
|
+
defaultElement: typeof element === "number" ? `h${level ?? element}` : element,
|
|
44
|
+
render,
|
|
45
|
+
baseClassName: variantClass[variant],
|
|
46
|
+
props
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { Typography };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cn } from "./cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
// src/VisuallyHidden.tsx
|
|
5
|
+
/** 화면에는 보이지 않고 보조 기술에는 읽히는 텍스트. 서버 컴포넌트로 쓸 수 있다. */
|
|
6
|
+
function VisuallyHidden({ className, ...props }) {
|
|
7
|
+
return /* @__PURE__ */ jsx("span", {
|
|
8
|
+
...props,
|
|
9
|
+
className: cn("sr-only", className)
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { VisuallyHidden };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CircleCheckIcon, InfoIcon, OctagonExclamationPointIcon, TriangleExclamationPointIcon } from "@tide-design/icons";
|
|
2
|
+
|
|
3
|
+
// src/alert-style.ts
|
|
4
|
+
/**
|
|
5
|
+
* 배치. 아이콘·내용·닫기 버튼을 한 줄로 놓고 위에 맞춘다. 여백은 16px, radius는 담는 요소의 lg다(spec radius 「쓰는 곳」).
|
|
6
|
+
* border 1px는 항상 둔다. forced-colors에서 브라우저가 경계를 CanvasText로 덮어 배경 없이도 영역이 남는다.
|
|
7
|
+
*/
|
|
8
|
+
const alertLayoutClass = "flex items-start gap-3 rounded-lg border p-4";
|
|
9
|
+
/**
|
|
10
|
+
* Alert의 subtle 표면(ADR 0022 §1).
|
|
11
|
+
* - 글자·아이콘: text-accent-on-subtle × bg-accent-subtle 4.5:1(Role `text-<role>-on-subtle` × `bg-<role>-subtle`, neutral은
|
|
12
|
+
* text-default × bg-neutral-subtle, 앱 Role은 색 이름 규칙 on-subtle × subtle)
|
|
13
|
+
* - 경계: 파스텔 테두리 border-accent-subtle. 바탕과 글자만으로 알아볼 수 있어 꾸밈이고 대비 검사에서 뺐다.
|
|
14
|
+
*/
|
|
15
|
+
const alertSurfaceClass = "border-accent-subtle bg-accent-subtle text-accent-on-subtle";
|
|
16
|
+
/** 상태 아이콘 자리. 글자 첫 줄 높이(body-sm 20px)와 같은 20px라 첫 줄 가운데에 맞는다. */
|
|
17
|
+
const alertIconClass = "size-5 shrink-0";
|
|
18
|
+
/** 제목과 본문을 세로로 쌓는다. 긴 단어가 닫기 버튼을 밀어내지 않게 min-w-0을 둔다. */
|
|
19
|
+
const alertContentClass = "flex min-w-0 flex-1 flex-col gap-1";
|
|
20
|
+
/** 제목. 본문과 같은 크기에 굵기만 올린다. 제목 수준(h1~h6)은 화면마다 다르므로 heading 요소를 쓰지 않는다. */
|
|
21
|
+
const alertTitleClass = "text-body-sm font-semibold";
|
|
22
|
+
/** 본문 */
|
|
23
|
+
const alertDescriptionClass = "text-body-sm";
|
|
24
|
+
/** 닫기 버튼(IconButton xs, 24px). 위아래 2px를 겹쳐 첫 줄 높이(20px)를 늘리지 않고, 끝쪽 4px를 여백에 겹친다. */
|
|
25
|
+
const alertCloseClass = "-my-0.5 -me-1";
|
|
26
|
+
/**
|
|
27
|
+
* Alert(subtle 표면) 안 닫기 버튼의 색. ghost의 기본(text-accent, bg-hover·bg-active)을 덮어쓴다.
|
|
28
|
+
* subtle 바탕 위라 글자는 on-subtle이고, hover·누름은 같은 색의 subtle-hover·subtle-active다
|
|
29
|
+
* (on-subtle × subtle 4.5:1, × subtle-hover·subtle-active 4:1 등록, ADR 0022·0023).
|
|
30
|
+
*/
|
|
31
|
+
const alertSubtleCloseClass = "text-accent-on-subtle hover:bg-accent-subtle-hover active:bg-accent-subtle-active";
|
|
32
|
+
const statusIcons = {
|
|
33
|
+
neutral: InfoIcon,
|
|
34
|
+
primary: InfoIcon,
|
|
35
|
+
info: InfoIcon,
|
|
36
|
+
success: CircleCheckIcon,
|
|
37
|
+
warning: TriangleExclamationPointIcon,
|
|
38
|
+
danger: OctagonExclamationPointIcon
|
|
39
|
+
};
|
|
40
|
+
/** Role의 상태 아이콘. 앱이 더한 Role(예: `brand`)은 일반 알림으로 보고 i 아이콘을 쓴다. */
|
|
41
|
+
function alertStatusIcon(color) {
|
|
42
|
+
return Object.hasOwn(statusIcons, color) ? statusIcons[color] : InfoIcon;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { alertCloseClass, alertContentClass, alertDescriptionClass, alertIconClass, alertLayoutClass, alertStatusIcon, alertSubtleCloseClass, alertSurfaceClass, alertTitleClass };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { FieldContext } from "./field-context.js";
|
|
4
|
+
import { createContext, use } from "react";
|
|
5
|
+
|
|
6
|
+
// src/choice-group.ts
|
|
7
|
+
/** CheckboxGroup 안에서만 값이 있다. */
|
|
8
|
+
const CheckboxGroupContext = createContext(null);
|
|
9
|
+
/** RadioGroup 안에서만 값이 있다. */
|
|
10
|
+
const RadioGroupContext = createContext(null);
|
|
11
|
+
/**
|
|
12
|
+
* Field 연결 정보와 묶음 자신의 props를 합친다. 묶음에 직접 준 값이 Field 값을 이긴다(useFieldControl과 같은 규칙).
|
|
13
|
+
* `aria-labelledby`를 직접 주면 Field label 대신 그것을 쓴다. `aria-describedby`는 Field 것 뒤에 이어 붙인다.
|
|
14
|
+
*/
|
|
15
|
+
function useChoiceGroup(props) {
|
|
16
|
+
const field = use(FieldContext);
|
|
17
|
+
const invalid = props.invalid ?? field?.invalid ?? false;
|
|
18
|
+
const disabled = props.disabled ?? field?.disabled ?? false;
|
|
19
|
+
const required = props.required ?? field?.required ?? false;
|
|
20
|
+
return {
|
|
21
|
+
rootProps: {
|
|
22
|
+
id: props.id ?? field?.controlId,
|
|
23
|
+
"aria-labelledby": props["aria-labelledby"] ?? field?.labelId,
|
|
24
|
+
"aria-describedby": [field?.describedBy, props["aria-describedby"]].filter(Boolean).join(" ") || void 0,
|
|
25
|
+
"data-invalid": invalid ? "" : void 0,
|
|
26
|
+
"data-disabled": disabled ? "" : void 0
|
|
27
|
+
},
|
|
28
|
+
invalid,
|
|
29
|
+
disabled,
|
|
30
|
+
required
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { CheckboxGroupContext, RadioGroupContext, useChoiceGroup };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/choice-style.ts
|
|
2
|
+
/** 루트 label. 글자 크기 class와 사용자 className은 뒤에 붙인다. */
|
|
3
|
+
const choiceRootClass = "group/choice inline-flex items-start gap-2 align-top text-default cursor-pointer has-disabled:cursor-not-allowed has-disabled:text-disabled";
|
|
4
|
+
/** 상자와 아이콘을 겹쳐 두는 24×24 조작 영역 */
|
|
5
|
+
const choiceAreaClass = "grid size-6 shrink-0 place-items-center";
|
|
6
|
+
/** 네이티브 input을 상자로 그린다. 모양(rounded)과 크기 class는 Component가 앞에 붙인다. */
|
|
7
|
+
const choiceInputClass = "peer col-start-1 row-start-1 m-0 appearance-none border border-strong bg-canvas cursor-pointer transition-colors checked:border-accent checked:bg-accent-solid enabled:not-checked:not-indeterminate:group-hover/choice:bg-accent-subtle enabled:checked:group-hover/choice:bg-accent-solid-hover indeterminate:border-accent indeterminate:bg-accent-solid enabled:indeterminate:group-hover/choice:bg-accent-solid-hover enabled:not-checked:not-indeterminate:group-active/choice:bg-accent-subtle-active enabled:checked:group-active/choice:bg-accent-solid-active enabled:indeterminate:group-active/choice:bg-accent-solid-active aria-invalid:border-danger focus-visible:focus-ring disabled:cursor-not-allowed disabled:border-default disabled:bg-disabled forced-colors:forced-color-adjust-none forced-colors:[--tide-bg-canvas:Canvas] 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]";
|
|
8
|
+
/** 상자 위에 겹치는 표시 아이콘. 누름은 input이 받는다. 보이는 조건 class는 Component가 붙인다. */
|
|
9
|
+
const choiceMarkClass = "pointer-events-none col-start-1 row-start-1 hidden text-accent-on-solid peer-disabled:text-disabled forced-colors:forced-color-adjust-none forced-colors:[--tide-accent-on-solid:HighlightText] forced-colors:[--tide-text-disabled:GrayText]";
|
|
10
|
+
/** 글자 스타일. md 행간 24px은 조작 영역과 같고, sm 행간 20px은 위아래 2px을 둬 첫 줄을 상자 가운데에 맞춘다. */
|
|
11
|
+
const choiceTextClass = {
|
|
12
|
+
sm: "py-0.5 text-body-sm",
|
|
13
|
+
md: "text-body-md"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { choiceAreaClass, choiceInputClass, choiceMarkClass, choiceRootClass, choiceTextClass };
|
package/dist/cn.d.ts
ADDED
package/dist/cn.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { tailwindMergeConfig } from "@tide-design/foundation/tailwind-merge";
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { extendTailwindMerge } from "tailwind-merge";
|
|
4
|
+
|
|
5
|
+
// src/cn.ts
|
|
6
|
+
const twMerge = extendTailwindMerge(tailwindMergeConfig);
|
|
7
|
+
/**
|
|
8
|
+
* class를 합치고 충돌을 푼다. 뒤에 온 class가 이긴다.
|
|
9
|
+
* Component는 사용자 `className`을 항상 마지막 인자로 넘긴다.
|
|
10
|
+
*/
|
|
11
|
+
function cn(...inputs) {
|
|
12
|
+
return twMerge(clsx(inputs));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { cn };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, use } from "react";
|
|
4
|
+
|
|
5
|
+
// src/field-context.ts
|
|
6
|
+
/** Field 밖에서는 `null`이다. */
|
|
7
|
+
const FieldContext = createContext(null);
|
|
8
|
+
/**
|
|
9
|
+
* Field 연결 정보와 입력 Component 자신의 props를 합친다.
|
|
10
|
+
* 입력 Component에 직접 준 값(id, disabled 등)이 Field 값보다 이긴다. `aria-describedby`는 Field 것 뒤에 이어 붙인다.
|
|
11
|
+
*/
|
|
12
|
+
function useFieldControl(props) {
|
|
13
|
+
const field = use(FieldContext);
|
|
14
|
+
const invalid = props.invalid ?? field?.invalid ?? false;
|
|
15
|
+
const describedBy = [field?.describedBy, props["aria-describedby"]].filter(Boolean).join(" ") || void 0;
|
|
16
|
+
return {
|
|
17
|
+
id: props.id ?? field?.controlId,
|
|
18
|
+
"aria-describedby": describedBy,
|
|
19
|
+
"aria-invalid": invalid ? true : props["aria-invalid"],
|
|
20
|
+
"data-invalid": invalid ? "" : void 0,
|
|
21
|
+
disabled: (props.disabled ?? field?.disabled) || void 0,
|
|
22
|
+
required: (props.required ?? field?.required) || void 0
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { FieldContext, useFieldControl };
|