sh-ui-cli 0.45.3 → 0.47.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/data/changelog/versions.json +26 -0
- package/data/registry/react/components/accordion/index.module.tsx +97 -0
- package/data/registry/react/components/accordion/styles.module.css +111 -0
- package/data/registry/react/components/avatar/index.module.tsx +73 -0
- package/data/registry/react/components/avatar/styles.module.css +36 -0
- package/data/registry/react/components/badge/index.module.tsx +40 -0
- package/data/registry/react/components/badge/styles.module.css +57 -0
- package/data/registry/react/components/breadcrumb/index.module.tsx +152 -0
- package/data/registry/react/components/breadcrumb/styles.module.css +82 -0
- package/data/registry/react/components/button/index.module.tsx +45 -0
- package/data/registry/react/components/button/styles.module.css +92 -0
- package/data/registry/react/components/calendar/index.module.tsx +806 -0
- package/data/registry/react/components/calendar/styles.module.css +213 -0
- package/data/registry/react/components/card/index.module.tsx +63 -0
- package/data/registry/react/components/card/styles.module.css +73 -0
- package/data/registry/react/components/carousel/index.module.tsx +430 -0
- package/data/registry/react/components/carousel/styles.module.css +155 -0
- package/data/registry/react/components/checkbox/index.module.tsx +96 -0
- package/data/registry/react/components/checkbox/styles.module.css +75 -0
- package/data/registry/react/components/code-editor/index.module.tsx +230 -0
- package/data/registry/react/components/code-editor/styles.module.css +76 -0
- package/data/registry/react/components/code-panel/index.module.tsx +191 -0
- package/data/registry/react/components/code-panel/styles.module.css +124 -0
- package/data/registry/react/components/color-picker/index.module.tsx +467 -0
- package/data/registry/react/components/color-picker/styles.module.css +166 -0
- package/data/registry/react/components/combobox/index.module.tsx +165 -0
- package/data/registry/react/components/combobox/styles.module.css +151 -0
- package/data/registry/react/components/context-menu/index.module.tsx +251 -0
- package/data/registry/react/components/context-menu/styles.module.css +140 -0
- package/data/registry/react/components/date-picker/index.module.tsx +520 -0
- package/data/registry/react/components/date-picker/styles.module.css +103 -0
- package/data/registry/react/components/dialog/index.module.tsx +95 -0
- package/data/registry/react/components/dialog/styles.module.css +127 -0
- package/data/registry/react/components/dropdown-menu/index.module.tsx +255 -0
- package/data/registry/react/components/dropdown-menu/styles.module.css +150 -0
- package/data/registry/react/components/file-upload/index.module.tsx +487 -0
- package/data/registry/react/components/file-upload/styles.module.css +170 -0
- package/data/registry/react/components/form/index.module.tsx +61 -0
- package/data/registry/react/components/form/styles.module.css +47 -0
- package/data/registry/react/components/header/index.module.tsx +805 -0
- package/data/registry/react/components/header/styles.module.css +350 -0
- package/data/registry/react/components/input/index.module.tsx +486 -0
- package/data/registry/react/components/input/styles.module.css +200 -0
- package/data/registry/react/components/label/index.module.tsx +52 -0
- package/data/registry/react/components/label/styles.module.css +90 -0
- package/data/registry/react/components/markdown-editor/index.module.tsx +119 -0
- package/data/registry/react/components/markdown-editor/styles.module.css +160 -0
- package/data/registry/react/components/menubar/index.module.tsx +32 -0
- package/data/registry/react/components/menubar/styles.module.css +45 -0
- package/data/registry/react/components/numeric-input/index.module.tsx +148 -0
- package/data/registry/react/components/numeric-input/styles.module.css +56 -0
- package/data/registry/react/components/page-toc/index.module.tsx +174 -0
- package/data/registry/react/components/page-toc/styles.module.css +82 -0
- package/data/registry/react/components/pagination/index.module.tsx +269 -0
- package/data/registry/react/components/pagination/styles.module.css +105 -0
- package/data/registry/react/components/popover/index.module.tsx +113 -0
- package/data/registry/react/components/popover/styles.module.css +65 -0
- package/data/registry/react/components/progress/index.module.tsx +54 -0
- package/data/registry/react/components/progress/styles.module.css +41 -0
- package/data/registry/react/components/radio/index.module.tsx +65 -0
- package/data/registry/react/components/radio/styles.module.css +80 -0
- package/data/registry/react/components/rich-text-editor/index.module.tsx +348 -0
- package/data/registry/react/components/rich-text-editor/styles.module.css +196 -0
- package/data/registry/react/components/select/index.module.tsx +234 -0
- package/data/registry/react/components/select/styles.module.css +193 -0
- package/data/registry/react/components/separator/index.module.tsx +46 -0
- package/data/registry/react/components/separator/styles.module.css +15 -0
- package/data/registry/react/components/sidebar/index.module.tsx +1067 -0
- package/data/registry/react/components/sidebar/styles.module.css +502 -0
- package/data/registry/react/components/skeleton/index.module.tsx +22 -0
- package/data/registry/react/components/skeleton/styles.module.css +24 -0
- package/data/registry/react/components/slider/index.module.tsx +298 -0
- package/data/registry/react/components/slider/styles.module.css +64 -0
- package/data/registry/react/components/spinner/index.module.tsx +38 -0
- package/data/registry/react/components/spinner/styles.module.css +37 -0
- package/data/registry/react/components/switch/index.module.tsx +39 -0
- package/data/registry/react/components/switch/styles.module.css +83 -0
- package/data/registry/react/components/tabs/index.module.tsx +91 -0
- package/data/registry/react/components/tabs/styles.module.css +148 -0
- package/data/registry/react/components/textarea/index.module.tsx +23 -0
- package/data/registry/react/components/textarea/styles.module.css +54 -0
- package/data/registry/react/components/toast/index.module.tsx +258 -0
- package/data/registry/react/components/toast/styles.module.css +290 -0
- package/data/registry/react/components/toggle/index.module.tsx +131 -0
- package/data/registry/react/components/toggle/styles.module.css +85 -0
- package/data/registry/react/components/tooltip/index.module.tsx +83 -0
- package/data/registry/react/components/tooltip/styles.module.css +44 -0
- package/data/registry/react/registry.json +604 -1
- package/data/tokens/build.mjs +4 -0
- package/package.json +1 -1
- package/src/add.mjs +12 -12
- package/src/api.d.ts +4 -3
- package/src/constants.js +4 -3
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@SH_UI_UTILS@";
|
|
5
|
+
import styles from "./styles.module.css";
|
|
6
|
+
|
|
7
|
+
export type HeadingLevel = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
8
|
+
|
|
9
|
+
export interface PageTOCProps {
|
|
10
|
+
/**
|
|
11
|
+
* 스캔할 컨테이너 selector. 기본 `"main"`.
|
|
12
|
+
*/
|
|
13
|
+
containerSelector?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 외부 신호로 TOC 재스캔. Next.js 사용 시 `usePathname()` 결과를 그대로 전달하면
|
|
16
|
+
* 라우트 변경 때마다 자동 갱신. 같은 페이지 안에서 헤딩이 동적으로 바뀌면 이 값을 갱신.
|
|
17
|
+
*/
|
|
18
|
+
routeKey?: string;
|
|
19
|
+
/**
|
|
20
|
+
* sticky 헤더 아래로 헤딩이 가려지지 않도록 띄울 거리(rem). `scroll-margin-top` 으로 적용.
|
|
21
|
+
* @default 5
|
|
22
|
+
*/
|
|
23
|
+
headerOffsetRem?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 라벨 텍스트.
|
|
26
|
+
* @default "On this page"
|
|
27
|
+
*/
|
|
28
|
+
label?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* 수집할 헤딩 레벨.
|
|
31
|
+
* @default ["h2", "h3"]
|
|
32
|
+
*/
|
|
33
|
+
levels?: HeadingLevel[];
|
|
34
|
+
/**
|
|
35
|
+
* 제외할 헤딩 selector. 컨테이너 안에서 이 selector 의 자손인 헤딩은 무시.
|
|
36
|
+
* 데모 미리보기·중첩 위젯 등을 TOC 에서 빼고 싶을 때 사용.
|
|
37
|
+
*/
|
|
38
|
+
excludeSelector?: string;
|
|
39
|
+
/** 추가 클래스. */
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const slugify = (text: string): string =>
|
|
44
|
+
text
|
|
45
|
+
.trim()
|
|
46
|
+
.toLowerCase()
|
|
47
|
+
.replace(/[^\w\s가-힣-]/g, "")
|
|
48
|
+
.replace(/\s+/g, "-");
|
|
49
|
+
|
|
50
|
+
interface TocItem {
|
|
51
|
+
id: string;
|
|
52
|
+
text: string;
|
|
53
|
+
level: HeadingLevel;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 페이지 내 자동 목차 (On this page).
|
|
59
|
+
*
|
|
60
|
+
* 컨테이너 안의 지정한 헤딩 레벨을 스캔해 자동 slugify · id 부여 · `IntersectionObserver` 로
|
|
61
|
+
* 현재 보이는 섹션을 active 표시 · 클릭 시 smooth scroll. 라우터 비종속 — `routeKey` 를
|
|
62
|
+
* 외부에서 갱신하면 재스캔된다.
|
|
63
|
+
*/
|
|
64
|
+
export function PageTOC({
|
|
65
|
+
containerSelector = "main",
|
|
66
|
+
routeKey,
|
|
67
|
+
headerOffsetRem = 5,
|
|
68
|
+
label = "On this page",
|
|
69
|
+
levels = ["h2", "h3"],
|
|
70
|
+
excludeSelector,
|
|
71
|
+
className,
|
|
72
|
+
}: PageTOCProps) {
|
|
73
|
+
const [items, setItems] = React.useState<TocItem[]>([]);
|
|
74
|
+
const [activeId, setActiveId] = React.useState<string | null>(null);
|
|
75
|
+
|
|
76
|
+
// levels 가 inline 배열(["h2", "h3"]) 로 전달되면 매 렌더마다 새 참조라 useEffect 가
|
|
77
|
+
// 무한 루프에 빠짐. 내용 기반 안정 키로 비교하고, 효과 안에서는 ref 로 최신 값 사용.
|
|
78
|
+
const levelsKey = levels.join(",");
|
|
79
|
+
const levelsRef = React.useRef(levels);
|
|
80
|
+
levelsRef.current = levels;
|
|
81
|
+
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
const container = document.querySelector(containerSelector);
|
|
84
|
+
if (!container) {
|
|
85
|
+
setItems([]);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const headingSelector = levelsRef.current.join(", ");
|
|
90
|
+
let headings = Array.from(
|
|
91
|
+
container.querySelectorAll<HTMLHeadingElement>(headingSelector),
|
|
92
|
+
);
|
|
93
|
+
if (excludeSelector) {
|
|
94
|
+
headings = headings.filter((h) => !h.closest(excludeSelector));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const usedIds = new Set<string>();
|
|
98
|
+
const collected: TocItem[] = headings.map((h) => {
|
|
99
|
+
const text = h.textContent?.trim() ?? "";
|
|
100
|
+
let id = h.id || slugify(text);
|
|
101
|
+
let suffix = 2;
|
|
102
|
+
const base = id;
|
|
103
|
+
while (!id || usedIds.has(id)) {
|
|
104
|
+
id = `${base}-${suffix++}`;
|
|
105
|
+
}
|
|
106
|
+
usedIds.add(id);
|
|
107
|
+
if (!h.id) h.id = id;
|
|
108
|
+
h.style.scrollMarginTop = `${headerOffsetRem}rem`;
|
|
109
|
+
const level = h.tagName.toLowerCase() as HeadingLevel;
|
|
110
|
+
return { id, text, level };
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
setItems(collected);
|
|
114
|
+
|
|
115
|
+
if (collected.length === 0) return;
|
|
116
|
+
|
|
117
|
+
const remInPx =
|
|
118
|
+
parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
119
|
+
const topOffsetPx = Math.round(headerOffsetRem * remInPx);
|
|
120
|
+
|
|
121
|
+
const observer = new IntersectionObserver(
|
|
122
|
+
(entries) => {
|
|
123
|
+
const visible = entries
|
|
124
|
+
.filter((e) => e.isIntersecting)
|
|
125
|
+
.sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top);
|
|
126
|
+
if (visible.length > 0) {
|
|
127
|
+
setActiveId(visible[0].target.id);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
rootMargin: `-${topOffsetPx}px 0px -70% 0px`,
|
|
132
|
+
threshold: 0,
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
headings.forEach((h) => observer.observe(h));
|
|
137
|
+
return () => observer.disconnect();
|
|
138
|
+
}, [containerSelector, headerOffsetRem, levelsKey, excludeSelector, routeKey]);
|
|
139
|
+
|
|
140
|
+
const handleClick = (event: React.MouseEvent<HTMLAnchorElement>, id: string) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
const el = document.getElementById(id);
|
|
143
|
+
if (!el) return;
|
|
144
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
145
|
+
history.replaceState(null, "", `#${id}`);
|
|
146
|
+
setActiveId(id);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (items.length === 0) return null;
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<nav
|
|
153
|
+
className={cn(styles["page-toc"], className)}
|
|
154
|
+
aria-label={typeof label === "string" ? label : "목차"}
|
|
155
|
+
>
|
|
156
|
+
<div className={styles["page-toc__label"]}>{label}</div>
|
|
157
|
+
<ul className={styles["page-toc__list"]}>
|
|
158
|
+
{items.map((item) => (
|
|
159
|
+
<li key={item.id} data-level={item.level.replace("h", "")}>
|
|
160
|
+
<a
|
|
161
|
+
href={`#${item.id}`}
|
|
162
|
+
onClick={(e) => handleClick(e, item.id)}
|
|
163
|
+
className={styles["page-toc__link"]}
|
|
164
|
+
data-active={activeId === item.id ? "true" : undefined}
|
|
165
|
+
aria-current={activeId === item.id ? "true" : undefined}
|
|
166
|
+
>
|
|
167
|
+
{item.text}
|
|
168
|
+
</a>
|
|
169
|
+
</li>
|
|
170
|
+
))}
|
|
171
|
+
</ul>
|
|
172
|
+
</nav>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* 페이지 내 목차 (On this page).
|
|
2
|
+
기본은 우측 고정 레일 — 좁은 뷰포트(<80rem)에서는 자동 숨김. 다른 배치(예: 본문 상단 inline)
|
|
3
|
+
가 필요하면 className override 또는 자체 wrapper 로 위치 재정의. */
|
|
4
|
+
.page-toc {
|
|
5
|
+
position: fixed;
|
|
6
|
+
top: 5rem;
|
|
7
|
+
right: 1.5rem;
|
|
8
|
+
width: 14rem;
|
|
9
|
+
max-height: calc(100vh - 7rem);
|
|
10
|
+
overflow-y: auto;
|
|
11
|
+
padding: 0.75rem 0.5rem 0.75rem 1rem;
|
|
12
|
+
border-left: 1px solid var(--border);
|
|
13
|
+
font-size: 0.8125rem;
|
|
14
|
+
z-index: 5;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.page-toc__label {
|
|
18
|
+
font-weight: 600;
|
|
19
|
+
font-size: 0.75rem;
|
|
20
|
+
color: var(--foreground-muted);
|
|
21
|
+
text-transform: uppercase;
|
|
22
|
+
letter-spacing: 0.04em;
|
|
23
|
+
margin-bottom: 0.5rem;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.page-toc__list {
|
|
27
|
+
list-style: none;
|
|
28
|
+
margin: 0;
|
|
29
|
+
padding: 0;
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
gap: 0.125rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.page-toc__list > li[data-level="3"] .page-toc__link,
|
|
36
|
+
.page-toc__list > li[data-level="4"] .page-toc__link {
|
|
37
|
+
padding-left: 1.25rem;
|
|
38
|
+
font-size: 0.8125em;
|
|
39
|
+
color: var(--foreground-subtle, var(--foreground-muted));
|
|
40
|
+
}
|
|
41
|
+
.page-toc__list > li[data-level="5"] .page-toc__link,
|
|
42
|
+
.page-toc__list > li[data-level="6"] .page-toc__link {
|
|
43
|
+
padding-left: 2rem;
|
|
44
|
+
font-size: 0.75em;
|
|
45
|
+
color: var(--foreground-subtle, var(--foreground-muted));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.page-toc__link {
|
|
49
|
+
display: block;
|
|
50
|
+
padding: 0.25rem 0.5rem;
|
|
51
|
+
border-radius: calc(var(--radius) - 4px);
|
|
52
|
+
color: var(--foreground-muted);
|
|
53
|
+
text-decoration: none;
|
|
54
|
+
line-height: 1.4;
|
|
55
|
+
transition: color var(--duration-fast), background-color var(--duration-fast);
|
|
56
|
+
}
|
|
57
|
+
.page-toc__link:hover {
|
|
58
|
+
color: var(--foreground);
|
|
59
|
+
background: var(--background-subtle);
|
|
60
|
+
}
|
|
61
|
+
.page-toc__link:focus-visible {
|
|
62
|
+
outline: var(--border-width-strong) solid var(--foreground);
|
|
63
|
+
outline-offset: 2px;
|
|
64
|
+
}
|
|
65
|
+
.page-toc__link[data-active="true"] {
|
|
66
|
+
color: var(--foreground);
|
|
67
|
+
font-weight: 600;
|
|
68
|
+
background: var(--background-subtle);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* 좁은 뷰포트에선 우측 레일 숨김 — 본문 너비를 침범하지 않도록 */
|
|
72
|
+
@media (max-width: 80rem) {
|
|
73
|
+
.page-toc {
|
|
74
|
+
display: none;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@media (prefers-reduced-motion: reduce) {
|
|
79
|
+
.page-toc__link {
|
|
80
|
+
transition: none;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import styles from "./styles.module.css";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { cn } from "@SH_UI_UTILS@";
|
|
6
|
+
/* ───────── Pagination (nav) ─────────
|
|
7
|
+
* 시맨틱: <nav aria-label="Pagination"><ul>...</ul></nav>.
|
|
8
|
+
* 현재 페이지 링크에 aria-current="page"를 부여해 스크린리더가 위치를 읽게 한다.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 페이지 분할 내비게이션의 시맨틱 컨테이너(`<nav aria-label="Pagination">`).
|
|
13
|
+
* 자식 구조: PaginationContent > PaginationItem × n > PaginationLink/Previous/Next/Ellipsis.
|
|
14
|
+
*/
|
|
15
|
+
export const Pagination = React.forwardRef<
|
|
16
|
+
HTMLElement,
|
|
17
|
+
React.HTMLAttributes<HTMLElement>
|
|
18
|
+
>(function Pagination({ className, ...props }, ref) {
|
|
19
|
+
return (
|
|
20
|
+
<nav
|
|
21
|
+
ref={ref}
|
|
22
|
+
aria-label="Pagination"
|
|
23
|
+
className={cn(styles.pagination, className)}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/* ───────── Content (ul) ───────── */
|
|
30
|
+
|
|
31
|
+
/** 페이지 항목들을 담는 정렬되지 않은 리스트(`<ul>`). */
|
|
32
|
+
export const PaginationContent = React.forwardRef<
|
|
33
|
+
HTMLUListElement,
|
|
34
|
+
React.HTMLAttributes<HTMLUListElement>
|
|
35
|
+
>(function PaginationContent({ className, ...props }, ref) {
|
|
36
|
+
return (
|
|
37
|
+
<ul
|
|
38
|
+
ref={ref}
|
|
39
|
+
className={cn(styles.pagination__content, className)}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/* ───────── Item (li) ───────── */
|
|
46
|
+
|
|
47
|
+
/** 한 페이지 슬롯(`<li>`). PaginationLink/Previous/Next/Ellipsis를 자식으로 둔다. */
|
|
48
|
+
export const PaginationItem = React.forwardRef<
|
|
49
|
+
HTMLLIElement,
|
|
50
|
+
React.LiHTMLAttributes<HTMLLIElement>
|
|
51
|
+
>(function PaginationItem({ className, ...props }, ref) {
|
|
52
|
+
return (
|
|
53
|
+
<li
|
|
54
|
+
ref={ref}
|
|
55
|
+
className={cn(styles.pagination__item, className)}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/* ───────── Link ─────────
|
|
62
|
+
* 숫자 페이지 링크. isActive일 때 aria-current="page" + 시각 강조.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
export interface PaginationLinkProps
|
|
66
|
+
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
67
|
+
/**
|
|
68
|
+
* 현재 페이지 표시. `true`면 `aria-current="page"`가 자동 부여되고 시각적으로 강조된다.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
isActive?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* 크기.
|
|
74
|
+
* - `sm` — 컴팩트
|
|
75
|
+
* - `md` — 일반 (기본)
|
|
76
|
+
*
|
|
77
|
+
* @default "md"
|
|
78
|
+
*/
|
|
79
|
+
size?: "sm" | "md";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 숫자 페이지 링크. `isActive`이면 `aria-current="page"`가 자동 부여되어
|
|
84
|
+
* 스크린리더가 현재 위치를 읽는다.
|
|
85
|
+
*/
|
|
86
|
+
export const PaginationLink = React.forwardRef<
|
|
87
|
+
HTMLAnchorElement,
|
|
88
|
+
PaginationLinkProps
|
|
89
|
+
>(function PaginationLink(
|
|
90
|
+
{ className, isActive, size = "md", ...props },
|
|
91
|
+
ref,
|
|
92
|
+
) {
|
|
93
|
+
return (
|
|
94
|
+
<a
|
|
95
|
+
ref={ref}
|
|
96
|
+
aria-current={isActive ? "page" : undefined}
|
|
97
|
+
data-active={isActive ? "" : undefined}
|
|
98
|
+
data-size={size}
|
|
99
|
+
className={cn(styles.pagination__link, className)}
|
|
100
|
+
{...props}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/* ───────── Previous / Next ─────────
|
|
106
|
+
* 아이콘 + 레이블. 레이블이 없는 아이콘 버튼에는 aria-label로 의미 전달.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/** "이전 페이지" 링크. 화살표 아이콘과 라벨이 함께 렌더되며 `aria-label`이 자동 부여된다. */
|
|
110
|
+
export const PaginationPrevious = React.forwardRef<
|
|
111
|
+
HTMLAnchorElement,
|
|
112
|
+
PaginationLinkProps
|
|
113
|
+
>(function PaginationPrevious({ className, children, ...props }, ref) {
|
|
114
|
+
return (
|
|
115
|
+
<PaginationLink
|
|
116
|
+
ref={ref}
|
|
117
|
+
aria-label="이전 페이지"
|
|
118
|
+
className={cn(styles.pagination__nav, className)}
|
|
119
|
+
{...props}
|
|
120
|
+
>
|
|
121
|
+
<ChevronLeftIcon />
|
|
122
|
+
{children ?? <span>이전</span>}
|
|
123
|
+
</PaginationLink>
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/** "다음 페이지" 링크. */
|
|
128
|
+
export const PaginationNext = React.forwardRef<
|
|
129
|
+
HTMLAnchorElement,
|
|
130
|
+
PaginationLinkProps
|
|
131
|
+
>(function PaginationNext({ className, children, ...props }, ref) {
|
|
132
|
+
return (
|
|
133
|
+
<PaginationLink
|
|
134
|
+
ref={ref}
|
|
135
|
+
aria-label="다음 페이지"
|
|
136
|
+
className={cn(styles.pagination__nav, className)}
|
|
137
|
+
{...props}
|
|
138
|
+
>
|
|
139
|
+
{children ?? <span>다음</span>}
|
|
140
|
+
<ChevronRightIcon />
|
|
141
|
+
</PaginationLink>
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/* ───────── Ellipsis — 생략 표시 ───────── */
|
|
146
|
+
|
|
147
|
+
/** 페이지 사이 생략을 표현하는 점 3개. 시각만 표현하고 스크린리더에는 무시된다. */
|
|
148
|
+
export const PaginationEllipsis = React.forwardRef<
|
|
149
|
+
HTMLSpanElement,
|
|
150
|
+
React.HTMLAttributes<HTMLSpanElement>
|
|
151
|
+
>(function PaginationEllipsis({ className, ...props }, ref) {
|
|
152
|
+
return (
|
|
153
|
+
<span
|
|
154
|
+
ref={ref}
|
|
155
|
+
role="presentation"
|
|
156
|
+
aria-hidden="true"
|
|
157
|
+
className={cn(styles.pagination__ellipsis, className)}
|
|
158
|
+
{...props}
|
|
159
|
+
>
|
|
160
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" aria-hidden>
|
|
161
|
+
<circle cx="3" cy="8" r="1.25" />
|
|
162
|
+
<circle cx="8" cy="8" r="1.25" />
|
|
163
|
+
<circle cx="13" cy="8" r="1.25" />
|
|
164
|
+
</svg>
|
|
165
|
+
<span className={styles.pagination__sr}>더 많은 페이지</span>
|
|
166
|
+
</span>
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/* ───────── 페이지 범위 유틸 ─────────
|
|
171
|
+
* 현재 페이지 주변 siblings개 + 양 끝 1개 + 필요한 곳에 "dots"를 넣어
|
|
172
|
+
* 렌더할 토큰 배열을 돌려준다.
|
|
173
|
+
*
|
|
174
|
+
* 예: page=5, totalPages=10, siblings=1 → [1, "dots", 4, 5, 6, "dots", 10]
|
|
175
|
+
*
|
|
176
|
+
* page·totalPages는 1-based를 가정한다.
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
export type PaginationToken = number | "dots";
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 1-based `page`/`totalPages`로부터 렌더할 토큰 배열을 만든다.
|
|
183
|
+
* 양 끝과 현재 주변 `siblings`개를 보여주고, 끊긴 구간엔 `"dots"`를 넣어준다.
|
|
184
|
+
*
|
|
185
|
+
* @param args.page - 1-based 현재 페이지.
|
|
186
|
+
* @param args.siblings - 현재 페이지 양옆에 보일 페이지 개수.
|
|
187
|
+
* @returns 렌더 토큰 배열. 숫자 또는 문자열 `"dots"`로 구성.
|
|
188
|
+
* @example
|
|
189
|
+
* getPaginationRange({ page: 5, totalPages: 10, siblings: 1 })
|
|
190
|
+
* // [1, "dots", 4, 5, 6, "dots", 10]
|
|
191
|
+
*/
|
|
192
|
+
export function getPaginationRange({
|
|
193
|
+
page,
|
|
194
|
+
totalPages,
|
|
195
|
+
siblings = 1,
|
|
196
|
+
}: {
|
|
197
|
+
/** 1-based 현재 페이지. */
|
|
198
|
+
page: number;
|
|
199
|
+
/** 전체 페이지 수. */
|
|
200
|
+
totalPages: number;
|
|
201
|
+
/**
|
|
202
|
+
* 현재 페이지 양옆에 보일 페이지 개수.
|
|
203
|
+
* @default 1
|
|
204
|
+
*/
|
|
205
|
+
siblings?: number;
|
|
206
|
+
}): PaginationToken[] {
|
|
207
|
+
if (totalPages <= 0) return [];
|
|
208
|
+
|
|
209
|
+
// 끝점 2개(첫/마지막) + 현재 주변 (2*siblings + 1) + dots 2개가 총 페이지 수보다 크거나 같으면
|
|
210
|
+
// 생략 없이 전부 보여준다.
|
|
211
|
+
const totalSlots = siblings * 2 + 5;
|
|
212
|
+
if (totalPages <= totalSlots) {
|
|
213
|
+
return range(1, totalPages);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const leftSibling = Math.max(page - siblings, 1);
|
|
217
|
+
const rightSibling = Math.min(page + siblings, totalPages);
|
|
218
|
+
|
|
219
|
+
const showLeftDots = leftSibling > 2;
|
|
220
|
+
const showRightDots = rightSibling < totalPages - 1;
|
|
221
|
+
|
|
222
|
+
// 왼쪽만 닫혀있음 → [1 ... right side]
|
|
223
|
+
if (!showLeftDots && showRightDots) {
|
|
224
|
+
const leftCount = 3 + 2 * siblings;
|
|
225
|
+
return [...range(1, leftCount), "dots", totalPages];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 오른쪽만 닫혀있음 → [1 ... left side]
|
|
229
|
+
if (showLeftDots && !showRightDots) {
|
|
230
|
+
const rightCount = 3 + 2 * siblings;
|
|
231
|
+
return [1, "dots", ...range(totalPages - rightCount + 1, totalPages)];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 양쪽 모두 생략
|
|
235
|
+
return [1, "dots", ...range(leftSibling, rightSibling), "dots", totalPages];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function range(start: number, end: number): number[] {
|
|
239
|
+
const length = end - start + 1;
|
|
240
|
+
return Array.from({ length }, (_, i) => start + i);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function ChevronLeftIcon() {
|
|
244
|
+
return (
|
|
245
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden>
|
|
246
|
+
<path
|
|
247
|
+
d="M10 4l-4 4 4 4"
|
|
248
|
+
stroke="currentColor"
|
|
249
|
+
strokeWidth="1.5"
|
|
250
|
+
strokeLinecap="round"
|
|
251
|
+
strokeLinejoin="round"
|
|
252
|
+
/>
|
|
253
|
+
</svg>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function ChevronRightIcon() {
|
|
258
|
+
return (
|
|
259
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden>
|
|
260
|
+
<path
|
|
261
|
+
d="M6 4l4 4-4 4"
|
|
262
|
+
stroke="currentColor"
|
|
263
|
+
strokeWidth="1.5"
|
|
264
|
+
strokeLinecap="round"
|
|
265
|
+
strokeLinejoin="round"
|
|
266
|
+
/>
|
|
267
|
+
</svg>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
.pagination {
|
|
2
|
+
display: flex;
|
|
3
|
+
justify-content: center;
|
|
4
|
+
font-size: var(--text-sm);
|
|
5
|
+
color: var(--foreground);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.pagination__content {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: 0.25rem;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 0;
|
|
15
|
+
list-style: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.pagination__item {
|
|
19
|
+
display: inline-flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.pagination__link {
|
|
24
|
+
display: inline-flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
gap: 0.375rem;
|
|
28
|
+
min-width: 2.25rem;
|
|
29
|
+
height: 2.25rem;
|
|
30
|
+
padding: 0 0.75rem;
|
|
31
|
+
border-radius: calc(var(--radius) - 2px);
|
|
32
|
+
border: var(--border-width) solid transparent;
|
|
33
|
+
background: transparent;
|
|
34
|
+
color: var(--foreground);
|
|
35
|
+
text-decoration: none;
|
|
36
|
+
transition:
|
|
37
|
+
background-color var(--duration-fast),
|
|
38
|
+
border-color var(--duration-fast),
|
|
39
|
+
color var(--duration-fast);
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
user-select: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.pagination__link[data-size="sm"] {
|
|
45
|
+
min-width: 2rem;
|
|
46
|
+
height: 2rem;
|
|
47
|
+
padding: 0 0.5rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.pagination__link:hover {
|
|
51
|
+
background: var(--background-muted);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.pagination__link:focus-visible {
|
|
55
|
+
outline: var(--border-width-strong) solid var(--foreground);
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.pagination__link[data-active] {
|
|
60
|
+
background: var(--foreground);
|
|
61
|
+
color: var(--background);
|
|
62
|
+
font-weight: var(--weight-medium);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.pagination__link[data-active]:hover {
|
|
66
|
+
background: var(--foreground);
|
|
67
|
+
opacity: 0.9;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.pagination__link[aria-disabled="true"],
|
|
71
|
+
.pagination__link[data-disabled] {
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
opacity: 0.45;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.pagination__nav {
|
|
77
|
+
padding: 0 0.625rem;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.pagination__ellipsis {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
width: 2.25rem;
|
|
85
|
+
height: 2.25rem;
|
|
86
|
+
color: var(--foreground-muted);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.pagination__sr {
|
|
90
|
+
position: absolute;
|
|
91
|
+
width: 1px;
|
|
92
|
+
height: 1px;
|
|
93
|
+
padding: 0;
|
|
94
|
+
margin: -1px;
|
|
95
|
+
overflow: hidden;
|
|
96
|
+
clip: rect(0, 0, 0, 0);
|
|
97
|
+
white-space: nowrap;
|
|
98
|
+
border: 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@media (prefers-reduced-motion: reduce) {
|
|
102
|
+
.pagination__link {
|
|
103
|
+
transition: none;
|
|
104
|
+
}
|
|
105
|
+
}
|