@x-plat/design-system 0.15.6 → 0.16.1
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/dist/components/Tour/index.cjs +338 -0
- package/dist/components/Tour/index.css +117 -0
- package/dist/components/Tour/index.d.cts +79 -0
- package/dist/components/Tour/index.d.ts +79 -0
- package/dist/components/Tour/index.js +301 -0
- package/dist/components/index.cjs +213 -53
- package/dist/components/index.css +116 -0
- package/dist/components/index.d.cts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +212 -53
- package/dist/index.cjs +237 -77
- package/dist/index.css +116 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +236 -77
- package/guidelines/Guidelines.md +1 -0
- package/guidelines/components/tour.md +93 -0
- package/package.json +1 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// src/components/Tour/Tour.tsx
|
|
2
|
+
import React3 from "react";
|
|
3
|
+
|
|
4
|
+
// src/tokens/hooks/Portal.tsx
|
|
5
|
+
import ReactDOM from "react-dom";
|
|
6
|
+
var Portal = ({ children, container }) => {
|
|
7
|
+
if (typeof document === "undefined") return null;
|
|
8
|
+
return ReactDOM.createPortal(children, container ?? document.body);
|
|
9
|
+
};
|
|
10
|
+
Portal.displayName = "Portal";
|
|
11
|
+
var Portal_default = Portal;
|
|
12
|
+
|
|
13
|
+
// src/tokens/hooks/useAutoPosition.ts
|
|
14
|
+
import React from "react";
|
|
15
|
+
var TRIGGER_GAP = 8;
|
|
16
|
+
var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
17
|
+
const roomBelow = clip.bottom - triggerRect.bottom - TRIGGER_GAP;
|
|
18
|
+
const roomAbove = triggerRect.top - clip.top - TRIGGER_GAP;
|
|
19
|
+
let direction;
|
|
20
|
+
let top;
|
|
21
|
+
let maxHeight = null;
|
|
22
|
+
if (popH <= roomBelow) {
|
|
23
|
+
direction = "bottom";
|
|
24
|
+
top = triggerRect.bottom + TRIGGER_GAP;
|
|
25
|
+
} else if (popH <= roomAbove) {
|
|
26
|
+
direction = "top";
|
|
27
|
+
top = triggerRect.top - TRIGGER_GAP - popH;
|
|
28
|
+
} else {
|
|
29
|
+
const room = Math.max(roomBelow, roomAbove, 0);
|
|
30
|
+
if (roomBelow >= roomAbove) {
|
|
31
|
+
direction = "bottom";
|
|
32
|
+
top = triggerRect.bottom + TRIGGER_GAP;
|
|
33
|
+
} else {
|
|
34
|
+
direction = "top";
|
|
35
|
+
top = triggerRect.top - TRIGGER_GAP - room;
|
|
36
|
+
}
|
|
37
|
+
maxHeight = room;
|
|
38
|
+
}
|
|
39
|
+
let left = triggerRect.left;
|
|
40
|
+
if (left + popW > clip.right - 8) {
|
|
41
|
+
left = triggerRect.right - popW;
|
|
42
|
+
}
|
|
43
|
+
if (left < clip.left + 8) left = clip.left + 8;
|
|
44
|
+
return {
|
|
45
|
+
direction,
|
|
46
|
+
top,
|
|
47
|
+
left,
|
|
48
|
+
maxHeight
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/tokens/hooks/useOverlayKeyboard.ts
|
|
53
|
+
import React2 from "react";
|
|
54
|
+
var FOCUSABLE = [
|
|
55
|
+
"a[href]",
|
|
56
|
+
"button:not([disabled])",
|
|
57
|
+
"input:not([disabled]):not([type='hidden'])",
|
|
58
|
+
"select:not([disabled])",
|
|
59
|
+
"textarea:not([disabled])",
|
|
60
|
+
"[tabindex]:not([tabindex='-1'])"
|
|
61
|
+
].join(",");
|
|
62
|
+
var focusableIn = (el) => Array.from(el.querySelectorAll(FOCUSABLE)).filter(
|
|
63
|
+
// 화면에 없는 것은 제외 (display:none 등)
|
|
64
|
+
(n) => n.offsetWidth > 0 || n.offsetHeight > 0 || n === document.activeElement
|
|
65
|
+
);
|
|
66
|
+
var useEscapeKey = (enabled, onEscape) => {
|
|
67
|
+
React2.useEffect(() => {
|
|
68
|
+
if (!enabled) return;
|
|
69
|
+
const onKey = (e) => {
|
|
70
|
+
if (e.key !== "Escape") return;
|
|
71
|
+
if (e.defaultPrevented) return;
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
onEscape();
|
|
74
|
+
};
|
|
75
|
+
document.addEventListener("keydown", onKey);
|
|
76
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
77
|
+
}, [enabled, onEscape]);
|
|
78
|
+
};
|
|
79
|
+
var useFocusTrap = (containerRef, enabled, options = {}) => {
|
|
80
|
+
const { trap = false, initialFocus } = options;
|
|
81
|
+
const restoreRef = React2.useRef(null);
|
|
82
|
+
React2.useEffect(() => {
|
|
83
|
+
if (!enabled) return;
|
|
84
|
+
restoreRef.current = document.activeElement;
|
|
85
|
+
const raf = requestAnimationFrame(() => {
|
|
86
|
+
const el = containerRef.current;
|
|
87
|
+
if (!el) return;
|
|
88
|
+
const target = initialFocus?.current ?? focusableIn(el)[0] ?? el;
|
|
89
|
+
if (!target.hasAttribute("tabindex") && !focusableIn(el).includes(target)) {
|
|
90
|
+
target.setAttribute("tabindex", "-1");
|
|
91
|
+
}
|
|
92
|
+
target.focus({ preventScroll: true });
|
|
93
|
+
});
|
|
94
|
+
return () => {
|
|
95
|
+
cancelAnimationFrame(raf);
|
|
96
|
+
const prev = restoreRef.current;
|
|
97
|
+
if (prev && document.contains(prev)) prev.focus({ preventScroll: true });
|
|
98
|
+
};
|
|
99
|
+
}, [enabled, containerRef, initialFocus]);
|
|
100
|
+
React2.useEffect(() => {
|
|
101
|
+
if (!enabled || !trap) return;
|
|
102
|
+
const onKey = (e) => {
|
|
103
|
+
if (e.key !== "Tab") return;
|
|
104
|
+
const el = containerRef.current;
|
|
105
|
+
if (!el) return;
|
|
106
|
+
const items = focusableIn(el);
|
|
107
|
+
if (items.length === 0) {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const first = items[0];
|
|
112
|
+
const last = items[items.length - 1];
|
|
113
|
+
const active = document.activeElement;
|
|
114
|
+
if (e.shiftKey && (active === first || !el.contains(active))) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
last.focus();
|
|
117
|
+
} else if (!e.shiftKey && (active === last || !el.contains(active))) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
first.focus();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
document.addEventListener("keydown", onKey);
|
|
123
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
124
|
+
}, [enabled, trap, containerRef]);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/clsx/dist/clsx.mjs
|
|
128
|
+
function r(e) {
|
|
129
|
+
var t, f, n = "";
|
|
130
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
131
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
132
|
+
var o = e.length;
|
|
133
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
134
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
135
|
+
return n;
|
|
136
|
+
}
|
|
137
|
+
function clsx() {
|
|
138
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
139
|
+
return n;
|
|
140
|
+
}
|
|
141
|
+
var clsx_default = clsx;
|
|
142
|
+
|
|
143
|
+
// src/components/Tour/Tour.tsx
|
|
144
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
145
|
+
var VIEWPORT_MARGIN = 16;
|
|
146
|
+
var DEFAULT_PADDING = 8;
|
|
147
|
+
var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
|
|
148
|
+
var resolve = (target) => {
|
|
149
|
+
if (typeof target === "string") return document.querySelector(target);
|
|
150
|
+
return target.current;
|
|
151
|
+
};
|
|
152
|
+
var Tour = (props) => {
|
|
153
|
+
const {
|
|
154
|
+
open,
|
|
155
|
+
steps,
|
|
156
|
+
onClose,
|
|
157
|
+
current,
|
|
158
|
+
onStepChange,
|
|
159
|
+
nextLabel = "\uB2E4\uC74C",
|
|
160
|
+
prevLabel = "\uC774\uC804",
|
|
161
|
+
skipLabel = "\uAC74\uB108\uB6F0\uAE30",
|
|
162
|
+
doneLabel = "\uB2E4 \uBD24\uC5B4\uC694"
|
|
163
|
+
} = props;
|
|
164
|
+
const [uncontrolled, setUncontrolled] = React3.useState(0);
|
|
165
|
+
const index = current ?? uncontrolled;
|
|
166
|
+
const step = steps[index];
|
|
167
|
+
const isLast = index === steps.length - 1;
|
|
168
|
+
const spotRef = React3.useRef(null);
|
|
169
|
+
const cardRef = React3.useRef(null);
|
|
170
|
+
const [targetFound, setTargetFound] = React3.useState(true);
|
|
171
|
+
const goTo = React3.useCallback(
|
|
172
|
+
(next) => {
|
|
173
|
+
if (current === void 0) setUncontrolled(next);
|
|
174
|
+
onStepChange?.(next);
|
|
175
|
+
},
|
|
176
|
+
[current, onStepChange]
|
|
177
|
+
);
|
|
178
|
+
useEscapeKey(open, () => onClose("skip"));
|
|
179
|
+
useFocusTrap(cardRef, open, { trap: true });
|
|
180
|
+
React3.useEffect(() => {
|
|
181
|
+
if (!open || !step) return;
|
|
182
|
+
const el = resolve(step.target);
|
|
183
|
+
setTargetFound(!!el);
|
|
184
|
+
el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
|
|
185
|
+
}, [open, step]);
|
|
186
|
+
const place = React3.useCallback(() => {
|
|
187
|
+
const spot = spotRef.current;
|
|
188
|
+
const card = cardRef.current;
|
|
189
|
+
if (!spot || !card || !step) return;
|
|
190
|
+
const el = resolve(step.target);
|
|
191
|
+
const pad = step.padding ?? DEFAULT_PADDING;
|
|
192
|
+
let hole;
|
|
193
|
+
if (el) {
|
|
194
|
+
const r2 = el.getBoundingClientRect();
|
|
195
|
+
hole = {
|
|
196
|
+
top: r2.top - pad,
|
|
197
|
+
left: r2.left - pad,
|
|
198
|
+
width: r2.width + pad * 2,
|
|
199
|
+
height: r2.height + pad * 2
|
|
200
|
+
};
|
|
201
|
+
spot.style.visibility = "visible";
|
|
202
|
+
} else {
|
|
203
|
+
hole = { top: window.innerHeight / 2, left: window.innerWidth / 2, width: 0, height: 0 };
|
|
204
|
+
spot.style.visibility = "hidden";
|
|
205
|
+
}
|
|
206
|
+
spot.style.top = `${hole.top}px`;
|
|
207
|
+
spot.style.left = `${hole.left}px`;
|
|
208
|
+
spot.style.width = `${hole.width}px`;
|
|
209
|
+
spot.style.height = `${hole.height}px`;
|
|
210
|
+
const placed = computePlacement(
|
|
211
|
+
{
|
|
212
|
+
top: hole.top,
|
|
213
|
+
bottom: hole.top + hole.height,
|
|
214
|
+
left: hole.left,
|
|
215
|
+
right: hole.left + hole.width
|
|
216
|
+
},
|
|
217
|
+
card.offsetWidth,
|
|
218
|
+
Math.max(card.offsetHeight, card.scrollHeight),
|
|
219
|
+
{
|
|
220
|
+
top: VIEWPORT_MARGIN,
|
|
221
|
+
bottom: window.innerHeight - VIEWPORT_MARGIN,
|
|
222
|
+
left: VIEWPORT_MARGIN,
|
|
223
|
+
right: window.innerWidth - VIEWPORT_MARGIN
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
|
|
227
|
+
const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
|
|
228
|
+
const cardW = card.offsetWidth;
|
|
229
|
+
card.style.maxHeight = `${cardH}px`;
|
|
230
|
+
card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
|
|
231
|
+
card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
|
|
232
|
+
}, [step]);
|
|
233
|
+
React3.useLayoutEffect(() => {
|
|
234
|
+
if (!open) return;
|
|
235
|
+
place();
|
|
236
|
+
const t = setTimeout(place, 400);
|
|
237
|
+
return () => clearTimeout(t);
|
|
238
|
+
}, [open, place]);
|
|
239
|
+
React3.useEffect(() => {
|
|
240
|
+
if (!open) return;
|
|
241
|
+
const onMove = () => place();
|
|
242
|
+
window.addEventListener("scroll", onMove, { passive: true, capture: true });
|
|
243
|
+
window.addEventListener("resize", onMove, { passive: true });
|
|
244
|
+
return () => {
|
|
245
|
+
window.removeEventListener("scroll", onMove, true);
|
|
246
|
+
window.removeEventListener("resize", onMove);
|
|
247
|
+
};
|
|
248
|
+
}, [open, place]);
|
|
249
|
+
if (!open || !step) return null;
|
|
250
|
+
return /* @__PURE__ */ jsx(Portal_default, { children: /* @__PURE__ */ jsxs("div", { className: "lib-xplat-tour", role: "presentation", children: [
|
|
251
|
+
!targetFound && /* @__PURE__ */ jsx("div", { className: "lib-xplat-tour-dim" }),
|
|
252
|
+
/* @__PURE__ */ jsx("div", { ref: spotRef, className: "lib-xplat-tour-spotlight", "aria-hidden": true }),
|
|
253
|
+
/* @__PURE__ */ jsxs(
|
|
254
|
+
"div",
|
|
255
|
+
{
|
|
256
|
+
ref: cardRef,
|
|
257
|
+
className: "lib-xplat-tour-card",
|
|
258
|
+
role: "dialog",
|
|
259
|
+
"aria-modal": "true",
|
|
260
|
+
"aria-label": typeof step.title === "string" ? step.title : "\uD654\uBA74 \uC548\uB0B4",
|
|
261
|
+
children: [
|
|
262
|
+
/* @__PURE__ */ jsxs("div", { className: "tour-card-progress", "aria-hidden": true, children: [
|
|
263
|
+
index + 1,
|
|
264
|
+
" / ",
|
|
265
|
+
steps.length
|
|
266
|
+
] }),
|
|
267
|
+
step.title && /* @__PURE__ */ jsx("div", { className: "tour-card-title", children: step.title }),
|
|
268
|
+
step.description && /* @__PURE__ */ jsx("div", { className: "tour-card-description", children: step.description }),
|
|
269
|
+
/* @__PURE__ */ jsxs("div", { className: "tour-card-actions", children: [
|
|
270
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tour-skip", onClick: () => onClose("skip"), children: skipLabel }),
|
|
271
|
+
/* @__PURE__ */ jsxs("div", { className: "tour-card-nav", children: [
|
|
272
|
+
index > 0 && /* @__PURE__ */ jsx(
|
|
273
|
+
"button",
|
|
274
|
+
{
|
|
275
|
+
type: "button",
|
|
276
|
+
className: clsx_default("tour-nav", "secondary"),
|
|
277
|
+
onClick: () => goTo(index - 1),
|
|
278
|
+
children: prevLabel
|
|
279
|
+
}
|
|
280
|
+
),
|
|
281
|
+
/* @__PURE__ */ jsx(
|
|
282
|
+
"button",
|
|
283
|
+
{
|
|
284
|
+
type: "button",
|
|
285
|
+
className: clsx_default("tour-nav", "primary"),
|
|
286
|
+
onClick: () => isLast ? onClose("done") : goTo(index + 1),
|
|
287
|
+
children: isLast ? doneLabel : nextLabel
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
] })
|
|
291
|
+
] })
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
] }) });
|
|
296
|
+
};
|
|
297
|
+
Tour.displayName = "Tour";
|
|
298
|
+
var Tour_default = Tour;
|
|
299
|
+
export {
|
|
300
|
+
Tour_default as Tour
|
|
301
|
+
};
|