@senvenli/react 0.3.3 → 0.3.4
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/action/fab.d.ts +7 -0
- package/dist/action/fab.js +22 -3
- package/dist/action/fab.js.map +1 -1
- package/dist/collection/data-table.d.ts +1 -1
- package/dist/collection/data-table.js +2 -2
- package/dist/collection/data-table.js.map +1 -1
- package/dist/collection/table.d.ts +7 -2
- package/dist/collection/table.js +17 -7
- package/dist/collection/table.js.map +1 -1
- package/dist/i18n.d.ts +8 -0
- package/dist/i18n.js +18 -1
- package/dist/i18n.js.map +1 -1
- package/dist/navigation/index.d.ts +2 -2
- package/dist/navigation/index.js +1 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/sidebar.d.ts +18 -0
- package/dist/navigation/sidebar.js +26 -2
- package/dist/navigation/sidebar.js.map +1 -1
- package/dist/overlay/floating.js +4 -1
- package/dist/overlay/floating.js.map +1 -1
- package/dist/overlay/index.d.ts +2 -0
- package/dist/overlay/index.js +2 -1
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/tour.d.ts +88 -0
- package/dist/overlay/tour.js +302 -0
- package/dist/overlay/tour.js.map +1 -0
- package/package.json +2 -2
- package/dist/action/files.d.ts +0 -70
- package/dist/action/files.js +0 -156
- package/dist/action/files.js.map +0 -1
- package/dist/action/theme-toggle.d.ts +0 -43
- package/dist/action/theme-toggle.js +0 -259
- package/dist/action/theme-toggle.js.map +0 -1
- package/dist/display/image-crop.d.ts +0 -106
- package/dist/display/image-crop.js +0 -117
- package/dist/display/image-crop.js.map +0 -1
- package/dist/display/image-cropper.d.ts +0 -68
- package/dist/display/image-cropper.js +0 -284
- package/dist/display/image-cropper.js.map +0 -1
- package/dist/display/lozenge.d.ts +0 -30
- package/dist/display/lozenge.js +0 -55
- package/dist/display/lozenge.js.map +0 -1
- package/dist/display/scroll-area.d.ts +0 -29
- package/dist/display/scroll-area.js +0 -95
- package/dist/display/scroll-area.js.map +0 -1
- package/dist/feedback/cooldown.d.ts +0 -17
- package/dist/feedback/cooldown.js +0 -59
- package/dist/feedback/cooldown.js.map +0 -1
- package/dist/feedback/status-dot.d.ts +0 -23
- package/dist/feedback/status-dot.js +0 -37
- package/dist/feedback/status-dot.js.map +0 -1
- package/dist/form/input-otp.d.ts +0 -35
- package/dist/form/input-otp.js +0 -83
- package/dist/form/input-otp.js.map +0 -1
- package/dist/layout/auth-form-layout.d.ts +0 -71
- package/dist/layout/auth-form-layout.js +0 -61
- package/dist/layout/auth-form-layout.js.map +0 -1
- package/dist/layout/auth-layout.d.ts +0 -59
- package/dist/layout/auth-layout.js +0 -26
- package/dist/layout/auth-layout.js.map +0 -1
- package/dist/layout/pressable.d.ts +0 -40
- package/dist/layout/pressable.js +0 -65
- package/dist/layout/pressable.js.map +0 -1
- package/dist/layout/reset-sent-card.d.ts +0 -39
- package/dist/layout/reset-sent-card.js +0 -22
- package/dist/layout/reset-sent-card.js.map +0 -1
- package/dist/navigation/dock.d.ts +0 -27
- package/dist/navigation/dock.js +0 -47
- package/dist/navigation/dock.js.map +0 -1
- package/dist/navigation/footer.d.ts +0 -43
- package/dist/navigation/footer.js +0 -43
- package/dist/navigation/footer.js.map +0 -1
- package/dist/navigation/language-names.d.ts +0 -19
- package/dist/navigation/language-names.js +0 -79
- package/dist/navigation/language-names.js.map +0 -1
- package/dist/navigation/language-switcher.d.ts +0 -55
- package/dist/navigation/language-switcher.js +0 -53
- package/dist/navigation/language-switcher.js.map +0 -1
- package/dist/navigation/panel-header.d.ts +0 -37
- package/dist/navigation/panel-header.js +0 -50
- package/dist/navigation/panel-header.js.map +0 -1
- package/dist/navigation/toolbar.d.ts +0 -37
- package/dist/navigation/toolbar.js +0 -334
- package/dist/navigation/toolbar.js.map +0 -1
- package/dist/overlay/command-palette.d.ts +0 -53
- package/dist/overlay/command-palette.js +0 -130
- package/dist/overlay/command-palette.js.map +0 -1
- package/dist/overlay/overlay.d.ts +0 -299
- package/dist/overlay/overlay.js +0 -558
- package/dist/overlay/overlay.js.map +0 -1
- package/dist/selection/radio-card.d.ts +0 -31
- package/dist/selection/radio-card.js +0 -29
- package/dist/selection/radio-card.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type WithMotion } from "../defaults.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a step points at: a CSS selector (the first visible match, e.g. `[data-tour-id="orders"]`), a ref, or a
|
|
5
|
+
* function that returns the element. Left out, the step is a centred panel with nothing highlighted.
|
|
6
|
+
*/
|
|
7
|
+
export type TourTarget = string | React.RefObject<Element | null> | (() => Element | null);
|
|
8
|
+
/** The side of the target the panel prefers; `start` and `end` follow the reading direction. */
|
|
9
|
+
export type TourPlacement = "top" | "bottom" | "start" | "end";
|
|
10
|
+
export type TourStep = {
|
|
11
|
+
/** A stable name for the step, for the app's own bookkeeping (analytics, "seen" flags). */
|
|
12
|
+
id?: string;
|
|
13
|
+
target?: TourTarget;
|
|
14
|
+
/** A few words: the panel's heading and its accessible name. */
|
|
15
|
+
title: React.ReactNode;
|
|
16
|
+
/** One or two sentences on what the highlighted part does. */
|
|
17
|
+
description?: React.ReactNode;
|
|
18
|
+
/** This step's side of the target; the tour's `placement` otherwise. */
|
|
19
|
+
placement?: TourPlacement;
|
|
20
|
+
};
|
|
21
|
+
export type TourProps = {
|
|
22
|
+
steps: readonly TourStep[];
|
|
23
|
+
isOpen?: boolean;
|
|
24
|
+
defaultOpen?: boolean;
|
|
25
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
26
|
+
/** The current step's index (0-based), controlled. */
|
|
27
|
+
step?: number;
|
|
28
|
+
/** The step an uncontrolled tour starts at each time it opens; default 0. */
|
|
29
|
+
defaultStep?: number;
|
|
30
|
+
onStepChange?: (step: number) => void;
|
|
31
|
+
/** Done on the last step. The tour then closes. */
|
|
32
|
+
onFinish?: () => void;
|
|
33
|
+
/** Skip, the close button or Esc. The tour then closes. Kept apart from `onFinish` so an app can tell them apart. */
|
|
34
|
+
onSkip?: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* `true` (default): the page is dimmed except the target, which cannot be pressed, and focus stays in the panel
|
|
37
|
+
* (a modal dialog). `false`: no dimming, the page stays usable and the panel is a non-modal dialog.
|
|
38
|
+
*/
|
|
39
|
+
mask?: boolean;
|
|
40
|
+
/** Room between the target and the edge of the lit area, in px; default 6. */
|
|
41
|
+
spotlightPadding?: number;
|
|
42
|
+
/** The side of the target the panel prefers; default `bottom`. It flips when that side has no room. */
|
|
43
|
+
placement?: TourPlacement;
|
|
44
|
+
/** "Step 2 of 5" above the title; default true. */
|
|
45
|
+
showProgress?: boolean;
|
|
46
|
+
/** Scroll a target that is out of view to the middle of the screen; default true. */
|
|
47
|
+
scrollIntoView?: boolean;
|
|
48
|
+
/** How long to wait for a target that is not on the page yet (a route still loading), in ms; default 3000. */
|
|
49
|
+
targetTimeout?: number;
|
|
50
|
+
/** When a target never appears: `center` (default) shows the step as a centred panel; `skip` moves on in the direction of travel. */
|
|
51
|
+
missingTarget?: "center" | "skip";
|
|
52
|
+
/** Turn off the arrow keys moving between steps. Esc still skips. */
|
|
53
|
+
isKeyboardNavigationDisabled?: boolean;
|
|
54
|
+
};
|
|
55
|
+
type Rect = {
|
|
56
|
+
top: number;
|
|
57
|
+
left: number;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
bottom: number;
|
|
61
|
+
right: number;
|
|
62
|
+
};
|
|
63
|
+
type Side = "top" | "bottom" | "left" | "right";
|
|
64
|
+
type Position = {
|
|
65
|
+
top: number;
|
|
66
|
+
left: number;
|
|
67
|
+
side: Side;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* Where the panel goes: the preferred side, else the opposite one, else either of the other two; the cross axis is
|
|
71
|
+
* kept on screen. `null` when no side has room (a target taller than a phone's screen): the panel is then centred.
|
|
72
|
+
*/
|
|
73
|
+
export declare function placePanel(target: Rect, panel: {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}, preferred: Side, viewport: {
|
|
77
|
+
width: number;
|
|
78
|
+
height: number;
|
|
79
|
+
}): Position;
|
|
80
|
+
/**
|
|
81
|
+
* A guided tour: a short sequence of steps, each pointing at a part of the page with a title, a sentence and
|
|
82
|
+
* Back / Next / Done, plus Skip. By default the page is dimmed except the step's target, which cannot be pressed,
|
|
83
|
+
* and focus stays in the panel; `mask={false}` keeps the page usable. Arrow keys move between steps (mirrored
|
|
84
|
+
* right to left), Esc skips. A target can be a selector, a ref or a function; one that is not on the page yet is
|
|
85
|
+
* waited for, then shown centred or skipped.
|
|
86
|
+
*/
|
|
87
|
+
export declare function Tour({ motion, ...props }: TourProps & WithMotion): React.JSX.Element;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { Dialog as AriaDialog, Heading, Modal, ModalOverlay, useLocale } from "react-aria-components";
|
|
6
|
+
import { cn } from "../utils.js";
|
|
7
|
+
import { MotionScope, useMotionAttribute, useReducedMotion } from "../defaults.js";
|
|
8
|
+
import { Button } from "../action/button.js";
|
|
9
|
+
import { CloseButton } from "../action/close-button.js";
|
|
10
|
+
import { stepOfLabel, tourBackLabel, tourFinishLabel, tourNextLabel, tourSkipLabel } from "../i18n.js";
|
|
11
|
+
import { OverlayContents } from "./overlay-base.js";
|
|
12
|
+
const GAP = 12;
|
|
13
|
+
const MARGIN = 16;
|
|
14
|
+
function isVisible(element) {
|
|
15
|
+
const rect = element.getBoundingClientRect();
|
|
16
|
+
return rect.width > 0 && rect.height > 0 && getComputedStyle(element).visibility !== "hidden";
|
|
17
|
+
}
|
|
18
|
+
function resolveTarget(target) {
|
|
19
|
+
if (!target)
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof target === "function")
|
|
22
|
+
return target();
|
|
23
|
+
if (typeof target !== "string")
|
|
24
|
+
return target.current;
|
|
25
|
+
let matches;
|
|
26
|
+
try {
|
|
27
|
+
matches = document.querySelectorAll(target);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
if (process.env.NODE_ENV !== "production")
|
|
31
|
+
console.warn(`Tour: "${target}" is not a valid CSS selector.`);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
for (const element of matches)
|
|
35
|
+
if (isVisible(element))
|
|
36
|
+
return element;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/** The step's element: found at once, or polled for until `timeout`, as a route may still be rendering it. */
|
|
40
|
+
function useTarget(target, active, stepKey, timeout) {
|
|
41
|
+
const [state, setState] = React.useState({ status: "none", element: null, key: -1 });
|
|
42
|
+
const targetRef = React.useRef(target);
|
|
43
|
+
targetRef.current = target;
|
|
44
|
+
React.useLayoutEffect(() => {
|
|
45
|
+
if (!active)
|
|
46
|
+
return;
|
|
47
|
+
const wanted = targetRef.current;
|
|
48
|
+
if (!wanted) {
|
|
49
|
+
setState({ status: "none", element: null, key: stepKey });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const found = resolveTarget(wanted);
|
|
53
|
+
if (found) {
|
|
54
|
+
setState({ status: "found", element: found, key: stepKey });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setState({ status: "pending", element: null, key: stepKey });
|
|
58
|
+
const started = Date.now();
|
|
59
|
+
const timer = window.setInterval(() => {
|
|
60
|
+
const element = resolveTarget(targetRef.current);
|
|
61
|
+
if (element) {
|
|
62
|
+
window.clearInterval(timer);
|
|
63
|
+
setState({ status: "found", element, key: stepKey });
|
|
64
|
+
}
|
|
65
|
+
else if (Date.now() - started >= timeout) {
|
|
66
|
+
window.clearInterval(timer);
|
|
67
|
+
setState({ status: "missing", element: null, key: stepKey });
|
|
68
|
+
}
|
|
69
|
+
}, 100);
|
|
70
|
+
return () => window.clearInterval(timer);
|
|
71
|
+
}, [active, stepKey, timeout]);
|
|
72
|
+
if (!active)
|
|
73
|
+
return { status: "none", element: null };
|
|
74
|
+
// Until this step's own lookup has run, the last step's answer ("missing") must not act on this one.
|
|
75
|
+
return state.key === stepKey ? state : { status: "pending", element: null };
|
|
76
|
+
}
|
|
77
|
+
function toRect(rect) {
|
|
78
|
+
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height, bottom: rect.bottom, right: rect.right };
|
|
79
|
+
}
|
|
80
|
+
/** The target's box in the viewport, kept current through scrolling, resizing and the target's own size changes. */
|
|
81
|
+
function useTargetRect(element) {
|
|
82
|
+
const [rect, setRect] = React.useState(null);
|
|
83
|
+
React.useLayoutEffect(() => {
|
|
84
|
+
if (!element) {
|
|
85
|
+
setRect(null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let frame = 0;
|
|
89
|
+
const measure = () => {
|
|
90
|
+
cancelAnimationFrame(frame);
|
|
91
|
+
frame = requestAnimationFrame(() => setRect(toRect(element.getBoundingClientRect())));
|
|
92
|
+
};
|
|
93
|
+
setRect(toRect(element.getBoundingClientRect()));
|
|
94
|
+
window.addEventListener("scroll", measure, true);
|
|
95
|
+
window.addEventListener("resize", measure);
|
|
96
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
|
97
|
+
observer?.observe(element);
|
|
98
|
+
return () => {
|
|
99
|
+
cancelAnimationFrame(frame);
|
|
100
|
+
window.removeEventListener("scroll", measure, true);
|
|
101
|
+
window.removeEventListener("resize", measure);
|
|
102
|
+
observer?.disconnect();
|
|
103
|
+
};
|
|
104
|
+
}, [element]);
|
|
105
|
+
return rect;
|
|
106
|
+
}
|
|
107
|
+
function physical(placement, rtl) {
|
|
108
|
+
if (placement === "start")
|
|
109
|
+
return rtl ? "right" : "left";
|
|
110
|
+
if (placement === "end")
|
|
111
|
+
return rtl ? "left" : "right";
|
|
112
|
+
return placement;
|
|
113
|
+
}
|
|
114
|
+
const OPPOSITE = { top: "bottom", bottom: "top", left: "right", right: "left" };
|
|
115
|
+
/**
|
|
116
|
+
* Where the panel goes: the preferred side, else the opposite one, else either of the other two; the cross axis is
|
|
117
|
+
* kept on screen. `null` when no side has room (a target taller than a phone's screen): the panel is then centred.
|
|
118
|
+
*/
|
|
119
|
+
export function placePanel(target, panel, preferred, viewport) {
|
|
120
|
+
const clamp = (value, size, limit) => Math.min(Math.max(value, MARGIN), Math.max(MARGIN, limit - size - MARGIN));
|
|
121
|
+
const others = ["bottom", "top", "right", "left"].filter((side) => side !== preferred && side !== OPPOSITE[preferred]);
|
|
122
|
+
for (const side of [preferred, OPPOSITE[preferred], ...others]) {
|
|
123
|
+
if (side === "bottom" || side === "top") {
|
|
124
|
+
const top = side === "bottom" ? target.bottom + GAP : target.top - GAP - panel.height;
|
|
125
|
+
if (top < MARGIN || top + panel.height > viewport.height - MARGIN)
|
|
126
|
+
continue;
|
|
127
|
+
return { side, top, left: clamp(target.left + target.width / 2 - panel.width / 2, panel.width, viewport.width) };
|
|
128
|
+
}
|
|
129
|
+
const left = side === "right" ? target.right + GAP : target.left - GAP - panel.width;
|
|
130
|
+
if (left < MARGIN || left + panel.width > viewport.width - MARGIN)
|
|
131
|
+
continue;
|
|
132
|
+
return { side, left, top: clamp(target.top + target.height / 2 - panel.height / 2, panel.height, viewport.height) };
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function isEditable(element) {
|
|
137
|
+
if (!(element instanceof HTMLElement))
|
|
138
|
+
return false;
|
|
139
|
+
return element.isContentEditable || element.tagName === "INPUT" || element.tagName === "TEXTAREA" || element.tagName === "SELECT";
|
|
140
|
+
}
|
|
141
|
+
const PANEL = "fixed flex w-80 max-w-[calc(100vw-2rem)] max-h-[calc(100dvh-2rem)] flex-col overflow-auto rounded-ds-large [--ds-surface-radius:var(--ds-radius-large)] " +
|
|
142
|
+
"bg-ds-surface-overlay p-ds-200 text-ds-text shadow-ds-overlay outline-hidden " +
|
|
143
|
+
"transition-[top,left,opacity] duration-(--ds-duration-medium) ease-ds-enter motion-reduce:transition-none";
|
|
144
|
+
/** The lit area: a rounded box whose huge shadow is the dimming, so the target shows through it untouched. */
|
|
145
|
+
const SPOTLIGHT = "pointer-events-none fixed rounded-ds-medium shadow-[0_0_0_100vmax_var(--ds-blanket)] " +
|
|
146
|
+
"transition-[top,left,width,height] duration-(--ds-duration-medium) ease-ds-enter motion-reduce:transition-none";
|
|
147
|
+
function TourRoot({ steps, isOpen: isOpenProp, defaultOpen, onOpenChange, step: stepProp, defaultStep = 0, onStepChange, onFinish, onSkip, mask = true, spotlightPadding = 6, placement = "bottom", showProgress = true, scrollIntoView = true, targetTimeout = 3000, missingTarget = "center", isKeyboardNavigationDisabled = false, }) {
|
|
148
|
+
const { locale, direction } = useLocale();
|
|
149
|
+
const rtl = direction === "rtl";
|
|
150
|
+
const reduced = useReducedMotion();
|
|
151
|
+
const motion = useMotionAttribute();
|
|
152
|
+
const [ownOpen, setOwnOpen] = React.useState(defaultOpen ?? false);
|
|
153
|
+
const isOpen = isOpenProp ?? ownOpen;
|
|
154
|
+
const [ownStep, setOwnStep] = React.useState(defaultStep);
|
|
155
|
+
const total = steps.length;
|
|
156
|
+
const index = Math.min(Math.max(stepProp ?? ownStep, 0), Math.max(total - 1, 0));
|
|
157
|
+
const current = steps[index];
|
|
158
|
+
const travel = React.useRef(1);
|
|
159
|
+
const panelRef = React.useRef(null);
|
|
160
|
+
const titleRef = React.useRef(null);
|
|
161
|
+
const returnTo = React.useRef(null);
|
|
162
|
+
const descriptionId = React.useId();
|
|
163
|
+
const [position, setPosition] = React.useState(null);
|
|
164
|
+
const [placed, setPlaced] = React.useState(false);
|
|
165
|
+
// An uncontrolled tour starts from `defaultStep` each time it opens; the element focused before is where focus returns.
|
|
166
|
+
const wasOpen = React.useRef(false);
|
|
167
|
+
if (isOpen && !wasOpen.current && typeof document !== "undefined") {
|
|
168
|
+
returnTo.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
169
|
+
}
|
|
170
|
+
React.useEffect(() => {
|
|
171
|
+
if (isOpen && !wasOpen.current && stepProp === undefined)
|
|
172
|
+
setOwnStep(defaultStep);
|
|
173
|
+
wasOpen.current = isOpen;
|
|
174
|
+
}, [isOpen, stepProp, defaultStep]);
|
|
175
|
+
const setOpen = (next) => {
|
|
176
|
+
if (isOpenProp === undefined)
|
|
177
|
+
setOwnOpen(next);
|
|
178
|
+
onOpenChange?.(next);
|
|
179
|
+
// Non-modal, nothing restores focus for us; the modal's own focus scope does it otherwise.
|
|
180
|
+
if (!next && !mask)
|
|
181
|
+
returnTo.current?.focus?.({ preventScroll: true });
|
|
182
|
+
};
|
|
183
|
+
const goTo = (next) => {
|
|
184
|
+
if (next < 0 || next >= total || next === index)
|
|
185
|
+
return;
|
|
186
|
+
travel.current = next < index ? -1 : 1;
|
|
187
|
+
if (stepProp === undefined)
|
|
188
|
+
setOwnStep(next);
|
|
189
|
+
onStepChange?.(next);
|
|
190
|
+
};
|
|
191
|
+
const finish = () => {
|
|
192
|
+
onFinish?.();
|
|
193
|
+
setOpen(false);
|
|
194
|
+
};
|
|
195
|
+
const skip = () => {
|
|
196
|
+
onSkip?.();
|
|
197
|
+
setOpen(false);
|
|
198
|
+
};
|
|
199
|
+
const next = () => (index >= total - 1 ? finish() : goTo(index + 1));
|
|
200
|
+
const back = () => goTo(index - 1);
|
|
201
|
+
const target = useTarget(current?.target, isOpen && !!current, index, targetTimeout);
|
|
202
|
+
const rect = useTargetRect(target.element);
|
|
203
|
+
const centered = target.status === "none" || (target.status === "missing" && missingTarget === "center");
|
|
204
|
+
// A target that never came: move on in the direction of travel (ending the tour past the last step).
|
|
205
|
+
React.useEffect(() => {
|
|
206
|
+
if (target.status !== "missing" || missingTarget !== "skip")
|
|
207
|
+
return;
|
|
208
|
+
if (travel.current === -1 && index > 0)
|
|
209
|
+
back();
|
|
210
|
+
else
|
|
211
|
+
next();
|
|
212
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
213
|
+
}, [target.status, index]);
|
|
214
|
+
// Bring an off-screen target to the middle of the screen; the rect follows through the scroll events.
|
|
215
|
+
React.useEffect(() => {
|
|
216
|
+
const element = target.element;
|
|
217
|
+
if (!scrollIntoView || !element)
|
|
218
|
+
return;
|
|
219
|
+
const box = element.getBoundingClientRect();
|
|
220
|
+
const inView = box.top >= 0 && box.left >= 0 && box.bottom <= window.innerHeight && box.right <= window.innerWidth;
|
|
221
|
+
if (!inView)
|
|
222
|
+
element.scrollIntoView?.({ block: "center", inline: "nearest", behavior: reduced ? "auto" : "smooth" });
|
|
223
|
+
}, [target.element, scrollIntoView, reduced]);
|
|
224
|
+
// Place the panel against the target once both sizes are known; hidden until then, so it never jumps.
|
|
225
|
+
React.useLayoutEffect(() => {
|
|
226
|
+
if (!isOpen || target.status === "pending" || (target.status === "missing" && missingTarget === "skip")) {
|
|
227
|
+
setPlaced(false);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (centered || !rect) {
|
|
231
|
+
setPosition(null);
|
|
232
|
+
setPlaced(true);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const panel = panelRef.current;
|
|
236
|
+
if (!panel)
|
|
237
|
+
return;
|
|
238
|
+
const pad = spotlightPadding;
|
|
239
|
+
const lit = { top: rect.top - pad, left: rect.left - pad, width: rect.width + pad * 2, height: rect.height + pad * 2, bottom: rect.bottom + pad, right: rect.right + pad };
|
|
240
|
+
const side = physical(current?.placement ?? placement, rtl);
|
|
241
|
+
setPosition(placePanel(lit, { width: panel.offsetWidth, height: panel.offsetHeight }, side, { width: window.innerWidth, height: window.innerHeight }));
|
|
242
|
+
setPlaced(true);
|
|
243
|
+
}, [isOpen, rect, centered, target.status, missingTarget, spotlightPadding, current?.placement, placement, rtl, index]);
|
|
244
|
+
// Each step's heading takes focus, so a screen reader reads where the tour went; the status line says how far.
|
|
245
|
+
React.useEffect(() => {
|
|
246
|
+
if (isOpen && placed)
|
|
247
|
+
titleRef.current?.focus({ preventScroll: true });
|
|
248
|
+
}, [isOpen, placed, index]);
|
|
249
|
+
if (!isOpen || !current)
|
|
250
|
+
return null;
|
|
251
|
+
const onKeyDown = (event) => {
|
|
252
|
+
if (!mask && event.key === "Escape") {
|
|
253
|
+
event.stopPropagation();
|
|
254
|
+
skip();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (isKeyboardNavigationDisabled || isEditable(event.target))
|
|
258
|
+
return;
|
|
259
|
+
const forward = rtl ? "ArrowLeft" : "ArrowRight";
|
|
260
|
+
const backward = rtl ? "ArrowRight" : "ArrowLeft";
|
|
261
|
+
if (event.key === forward) {
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
next();
|
|
264
|
+
}
|
|
265
|
+
else if (event.key === backward) {
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
back();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const last = index === total - 1;
|
|
271
|
+
const progress = stepOfLabel(locale, index + 1, total);
|
|
272
|
+
const style = position ? { top: position.top, left: position.left } : { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
|
|
273
|
+
const spot = !centered && target.status === "found" ? rect : null;
|
|
274
|
+
const panel = (_jsx(AriaDialog, { ref: panelRef, "aria-describedby": current.description ? descriptionId : undefined, "data-slot": "tour", "data-side": position?.side ?? "center", "data-step": index, style: style, className: cn(PANEL, !placed && "invisible opacity-0", !mask && "z-50"), children: _jsx(OverlayContents, { children: _jsxs("div", { onKeyDown: onKeyDown, className: "flex flex-col gap-ds-150", children: [_jsxs("div", { className: "flex items-start justify-between gap-ds-100", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-ds-050", children: [showProgress && total > 1 && (_jsx("span", { "data-slot": "tour-progress", className: "text-body-small text-ds-text-subtle", children: progress })), _jsx(Heading, { ref: titleRef, slot: "title", tabIndex: -1, "data-slot": "tour-title", className: "m-0 -mx-ds-050 px-ds-050 text-heading-small outline-hidden focus-visible:rounded-ds-small focus-visible:inset-ring-2 focus-visible:inset-ring-ds-border-focused", children: current.title })] }), _jsx("span", { "data-slot": "tour-close-wrap", className: "-me-ds-100 -mt-ds-050 flex shrink-0", children: _jsx(CloseButton, { "data-slot": "tour-close", onPress: skip }) })] }), current.description && (_jsx("div", { id: descriptionId, "data-slot": "tour-description", className: "text-body text-ds-text-subtle", children: current.description })), _jsxs("div", { "data-slot": "tour-footer", className: "flex flex-wrap items-center gap-ds-100", children: [_jsx("span", { className: "-ms-ds-100 flex", children: _jsx(Button, { "data-slot": "tour-skip", variant: "subtle", size: "small", onPress: skip, children: tourSkipLabel(locale) }) }), _jsxs("div", { className: "ms-auto flex gap-ds-100", children: [index > 0 && (_jsx(Button, { "data-slot": "tour-back", variant: "default", size: "small", onPress: back, children: tourBackLabel(locale) })), _jsx(Button, { "data-slot": "tour-next", variant: "primary", size: "small", onPress: next, children: last ? tourFinishLabel(locale) : tourNextLabel(locale) })] })] }), _jsx("span", { role: "status", "data-slot": "tour-status", className: "sr-only", children: placed && total > 1 ? progress : "" })] }) }) }));
|
|
275
|
+
if (!mask) {
|
|
276
|
+
if (typeof document === "undefined")
|
|
277
|
+
return null;
|
|
278
|
+
return createPortal(_jsx("div", { ...motion, "data-slot": "tour-layer", style: { display: "contents" }, children: panel }), document.body);
|
|
279
|
+
}
|
|
280
|
+
return (_jsxs(ModalOverlay, { ...motion, isOpen: true,
|
|
281
|
+
// Outside presses (the dimmed page, the target) do nothing; Esc skips.
|
|
282
|
+
isDismissable: false, onOpenChange: (open) => {
|
|
283
|
+
if (!open)
|
|
284
|
+
skip();
|
|
285
|
+
}, "data-slot": "tour-overlay", className: cn("fixed inset-0 z-50", !spot && "bg-ds-blanket"), children: [spot && (_jsx("div", { "aria-hidden": true, "data-slot": "tour-spotlight", className: SPOTLIGHT, style: {
|
|
286
|
+
top: spot.top - spotlightPadding,
|
|
287
|
+
left: spot.left - spotlightPadding,
|
|
288
|
+
width: spot.width + spotlightPadding * 2,
|
|
289
|
+
height: spot.height + spotlightPadding * 2,
|
|
290
|
+
} })), _jsx(Modal, { "data-slot": "tour-modal", className: "outline-hidden", children: panel })] }));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* A guided tour: a short sequence of steps, each pointing at a part of the page with a title, a sentence and
|
|
294
|
+
* Back / Next / Done, plus Skip. By default the page is dimmed except the step's target, which cannot be pressed,
|
|
295
|
+
* and focus stays in the panel; `mask={false}` keeps the page usable. Arrow keys move between steps (mirrored
|
|
296
|
+
* right to left), Esc skips. A target can be a selector, a ref or a function; one that is not on the page yet is
|
|
297
|
+
* waited for, then shown centred or skipped.
|
|
298
|
+
*/
|
|
299
|
+
export function Tour({ motion, ...props }) {
|
|
300
|
+
return (_jsx(MotionScope, { motion: motion, children: _jsx(TourRoot, { ...props }) }));
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=tour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tour.js","sourceRoot":"","sources":["../../src/overlay/tour.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACtG,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAmB,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,gB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,oBAAoB,EAAE,CAAC,IAAI,IAAI,eAAe,CAAC,aAE5D,IAAI,IAAI,CACP,gDAEY,gBAAgB,EAC1B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE;oBACL,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,gBAAgB;oBAChC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,gBAAgB;oBAClC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,gBAAgB,GAAG,CAAC;oBACxC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,gBAAgB,GAAG,CAAC;iBAC3C,GACD,CACH,EACD,KAAC,KAAK,iBAAW,YAAY,EAAC,SAAS,EAAC,gBAAgB,YACrD,KAAK,GACA,IACK,CAChB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAA0B;IAC/D,OAAO,CACL,KAAC,WAAW,IAAC,MAAM,EAAE,MAAM,YACzB,KAAC,QAAQ,OAAK,KAAK,GAAI,GACX,CACf,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Dialog as AriaDialog, Heading, Modal, ModalOverlay, useLocale } from \"react-aria-components\";\nimport { cn } from \"../utils\";\nimport { MotionScope, type WithMotion, useMotionAttribute, useReducedMotion } from \"../defaults\";\nimport { Button } from \"../action/button\";\nimport { CloseButton } from \"../action/close-button\";\nimport { stepOfLabel, tourBackLabel, tourFinishLabel, tourNextLabel, tourSkipLabel } from \"../i18n\";\nimport { OverlayContents } from \"./overlay-base\";\n\n/**\n * What a step points at: a CSS selector (the first visible match, e.g. `[data-tour-id=\"orders\"]`), a ref, or a\n * function that returns the element. Left out, the step is a centred panel with nothing highlighted.\n */\nexport type TourTarget = string | React.RefObject<Element | null> | (() => Element | null);\n\n/** The side of the target the panel prefers; `start` and `end` follow the reading direction. */\nexport type TourPlacement = \"top\" | \"bottom\" | \"start\" | \"end\";\n\nexport type TourStep = {\n /** A stable name for the step, for the app's own bookkeeping (analytics, \"seen\" flags). */\n id?: string;\n target?: TourTarget;\n /** A few words: the panel's heading and its accessible name. */\n title: React.ReactNode;\n /** One or two sentences on what the highlighted part does. */\n description?: React.ReactNode;\n /** This step's side of the target; the tour's `placement` otherwise. */\n placement?: TourPlacement;\n};\n\nexport type TourProps = {\n steps: readonly TourStep[];\n isOpen?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (isOpen: boolean) => void;\n /** The current step's index (0-based), controlled. */\n step?: number;\n /** The step an uncontrolled tour starts at each time it opens; default 0. */\n defaultStep?: number;\n onStepChange?: (step: number) => void;\n /** Done on the last step. The tour then closes. */\n onFinish?: () => void;\n /** Skip, the close button or Esc. The tour then closes. Kept apart from `onFinish` so an app can tell them apart. */\n onSkip?: () => void;\n /**\n * `true` (default): the page is dimmed except the target, which cannot be pressed, and focus stays in the panel\n * (a modal dialog). `false`: no dimming, the page stays usable and the panel is a non-modal dialog.\n */\n mask?: boolean;\n /** Room between the target and the edge of the lit area, in px; default 6. */\n spotlightPadding?: number;\n /** The side of the target the panel prefers; default `bottom`. It flips when that side has no room. */\n placement?: TourPlacement;\n /** \"Step 2 of 5\" above the title; default true. */\n showProgress?: boolean;\n /** Scroll a target that is out of view to the middle of the screen; default true. */\n scrollIntoView?: boolean;\n /** How long to wait for a target that is not on the page yet (a route still loading), in ms; default 3000. */\n targetTimeout?: number;\n /** When a target never appears: `center` (default) shows the step as a centred panel; `skip` moves on in the direction of travel. */\n missingTarget?: \"center\" | \"skip\";\n /** Turn off the arrow keys moving between steps. Esc still skips. */\n isKeyboardNavigationDisabled?: boolean;\n};\n\nconst GAP = 12;\nconst MARGIN = 16;\n\ntype Rect = { top: number; left: number; width: number; height: number; bottom: number; right: number };\ntype Side = \"top\" | \"bottom\" | \"left\" | \"right\";\ntype Position = { top: number; left: number; side: Side } | null;\ntype TargetState = { status: \"none\" | \"pending\" | \"found\" | \"missing\"; element: Element | null };\ntype KeyedTarget = TargetState & { key: number };\n\nfunction isVisible(element: Element): boolean {\n const rect = element.getBoundingClientRect();\n return rect.width > 0 && rect.height > 0 && getComputedStyle(element).visibility !== \"hidden\";\n}\n\nfunction resolveTarget(target: TourTarget | undefined): Element | null {\n if (!target) return null;\n if (typeof target === \"function\") return target();\n if (typeof target !== \"string\") return target.current;\n let matches: NodeListOf<Element>;\n try {\n matches = document.querySelectorAll(target);\n } catch {\n if (process.env.NODE_ENV !== \"production\") console.warn(`Tour: \"${target}\" is not a valid CSS selector.`);\n return null;\n }\n for (const element of matches) if (isVisible(element)) return element;\n return null;\n}\n\n/** The step's element: found at once, or polled for until `timeout`, as a route may still be rendering it. */\nfunction useTarget(target: TourTarget | undefined, active: boolean, stepKey: number, timeout: number): TargetState {\n const [state, setState] = React.useState<KeyedTarget>({ status: \"none\", element: null, key: -1 });\n const targetRef = React.useRef(target);\n targetRef.current = target;\n React.useLayoutEffect(() => {\n if (!active) return;\n const wanted = targetRef.current;\n if (!wanted) {\n setState({ status: \"none\", element: null, key: stepKey });\n return;\n }\n const found = resolveTarget(wanted);\n if (found) {\n setState({ status: \"found\", element: found, key: stepKey });\n return;\n }\n setState({ status: \"pending\", element: null, key: stepKey });\n const started = Date.now();\n const timer = window.setInterval(() => {\n const element = resolveTarget(targetRef.current);\n if (element) {\n window.clearInterval(timer);\n setState({ status: \"found\", element, key: stepKey });\n } else if (Date.now() - started >= timeout) {\n window.clearInterval(timer);\n setState({ status: \"missing\", element: null, key: stepKey });\n }\n }, 100);\n return () => window.clearInterval(timer);\n }, [active, stepKey, timeout]);\n if (!active) return { status: \"none\", element: null };\n // Until this step's own lookup has run, the last step's answer (\"missing\") must not act on this one.\n return state.key === stepKey ? state : { status: \"pending\", element: null };\n}\n\nfunction toRect(rect: DOMRect): Rect {\n return { top: rect.top, left: rect.left, width: rect.width, height: rect.height, bottom: rect.bottom, right: rect.right };\n}\n\n/** The target's box in the viewport, kept current through scrolling, resizing and the target's own size changes. */\nfunction useTargetRect(element: Element | null): Rect | null {\n const [rect, setRect] = React.useState<Rect | null>(null);\n React.useLayoutEffect(() => {\n if (!element) {\n setRect(null);\n return;\n }\n let frame = 0;\n const measure = () => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => setRect(toRect(element.getBoundingClientRect())));\n };\n setRect(toRect(element.getBoundingClientRect()));\n window.addEventListener(\"scroll\", measure, true);\n window.addEventListener(\"resize\", measure);\n const observer = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(measure);\n observer?.observe(element);\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener(\"scroll\", measure, true);\n window.removeEventListener(\"resize\", measure);\n observer?.disconnect();\n };\n }, [element]);\n return rect;\n}\n\nfunction physical(placement: TourPlacement, rtl: boolean): Side {\n if (placement === \"start\") return rtl ? \"right\" : \"left\";\n if (placement === \"end\") return rtl ? \"left\" : \"right\";\n return placement;\n}\n\nconst OPPOSITE: Record<Side, Side> = { top: \"bottom\", bottom: \"top\", left: \"right\", right: \"left\" };\n\n/**\n * Where the panel goes: the preferred side, else the opposite one, else either of the other two; the cross axis is\n * kept on screen. `null` when no side has room (a target taller than a phone's screen): the panel is then centred.\n */\nexport function placePanel(\n target: Rect,\n panel: { width: number; height: number },\n preferred: Side,\n viewport: { width: number; height: number },\n): Position {\n const clamp = (value: number, size: number, limit: number) => Math.min(Math.max(value, MARGIN), Math.max(MARGIN, limit - size - MARGIN));\n const others = ([\"bottom\", \"top\", \"right\", \"left\"] as Side[]).filter((side) => side !== preferred && side !== OPPOSITE[preferred]);\n for (const side of [preferred, OPPOSITE[preferred], ...others]) {\n if (side === \"bottom\" || side === \"top\") {\n const top = side === \"bottom\" ? target.bottom + GAP : target.top - GAP - panel.height;\n if (top < MARGIN || top + panel.height > viewport.height - MARGIN) continue;\n return { side, top, left: clamp(target.left + target.width / 2 - panel.width / 2, panel.width, viewport.width) };\n }\n const left = side === \"right\" ? target.right + GAP : target.left - GAP - panel.width;\n if (left < MARGIN || left + panel.width > viewport.width - MARGIN) continue;\n return { side, left, top: clamp(target.top + target.height / 2 - panel.height / 2, panel.height, viewport.height) };\n }\n return null;\n}\n\nfunction isEditable(element: EventTarget | null): boolean {\n if (!(element instanceof HTMLElement)) return false;\n return element.isContentEditable || element.tagName === \"INPUT\" || element.tagName === \"TEXTAREA\" || element.tagName === \"SELECT\";\n}\n\nconst PANEL =\n \"fixed flex w-80 max-w-[calc(100vw-2rem)] max-h-[calc(100dvh-2rem)] flex-col overflow-auto rounded-ds-large [--ds-surface-radius:var(--ds-radius-large)] \" +\n \"bg-ds-surface-overlay p-ds-200 text-ds-text shadow-ds-overlay outline-hidden \" +\n \"transition-[top,left,opacity] duration-(--ds-duration-medium) ease-ds-enter motion-reduce:transition-none\";\n\n/** The lit area: a rounded box whose huge shadow is the dimming, so the target shows through it untouched. */\nconst SPOTLIGHT =\n \"pointer-events-none fixed rounded-ds-medium shadow-[0_0_0_100vmax_var(--ds-blanket)] \" +\n \"transition-[top,left,width,height] duration-(--ds-duration-medium) ease-ds-enter motion-reduce:transition-none\";\n\nfunction TourRoot({\n steps,\n isOpen: isOpenProp,\n defaultOpen,\n onOpenChange,\n step: stepProp,\n defaultStep = 0,\n onStepChange,\n onFinish,\n onSkip,\n mask = true,\n spotlightPadding = 6,\n placement = \"bottom\",\n showProgress = true,\n scrollIntoView = true,\n targetTimeout = 3000,\n missingTarget = \"center\",\n isKeyboardNavigationDisabled = false,\n}: TourProps) {\n const { locale, direction } = useLocale();\n const rtl = direction === \"rtl\";\n const reduced = useReducedMotion();\n const motion = useMotionAttribute();\n const [ownOpen, setOwnOpen] = React.useState(defaultOpen ?? false);\n const isOpen = isOpenProp ?? ownOpen;\n const [ownStep, setOwnStep] = React.useState(defaultStep);\n const total = steps.length;\n const index = Math.min(Math.max(stepProp ?? ownStep, 0), Math.max(total - 1, 0));\n const current = steps[index];\n const travel = React.useRef<1 | -1>(1);\n const panelRef = React.useRef<HTMLElement>(null);\n const titleRef = React.useRef<HTMLHeadingElement>(null);\n const returnTo = React.useRef<HTMLElement | null>(null);\n const descriptionId = React.useId();\n const [position, setPosition] = React.useState<Position>(null);\n const [placed, setPlaced] = React.useState(false);\n\n // An uncontrolled tour starts from `defaultStep` each time it opens; the element focused before is where focus returns.\n const wasOpen = React.useRef(false);\n if (isOpen && !wasOpen.current && typeof document !== \"undefined\") {\n returnTo.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;\n }\n React.useEffect(() => {\n if (isOpen && !wasOpen.current && stepProp === undefined) setOwnStep(defaultStep);\n wasOpen.current = isOpen;\n }, [isOpen, stepProp, defaultStep]);\n\n const setOpen = (next: boolean) => {\n if (isOpenProp === undefined) setOwnOpen(next);\n onOpenChange?.(next);\n // Non-modal, nothing restores focus for us; the modal's own focus scope does it otherwise.\n if (!next && !mask) returnTo.current?.focus?.({ preventScroll: true });\n };\n const goTo = (next: number) => {\n if (next < 0 || next >= total || next === index) return;\n travel.current = next < index ? -1 : 1;\n if (stepProp === undefined) setOwnStep(next);\n onStepChange?.(next);\n };\n const finish = () => {\n onFinish?.();\n setOpen(false);\n };\n const skip = () => {\n onSkip?.();\n setOpen(false);\n };\n const next = () => (index >= total - 1 ? finish() : goTo(index + 1));\n const back = () => goTo(index - 1);\n\n const target = useTarget(current?.target, isOpen && !!current, index, targetTimeout);\n const rect = useTargetRect(target.element);\n const centered = target.status === \"none\" || (target.status === \"missing\" && missingTarget === \"center\");\n\n // A target that never came: move on in the direction of travel (ending the tour past the last step).\n React.useEffect(() => {\n if (target.status !== \"missing\" || missingTarget !== \"skip\") return;\n if (travel.current === -1 && index > 0) back();\n else next();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [target.status, index]);\n\n // Bring an off-screen target to the middle of the screen; the rect follows through the scroll events.\n React.useEffect(() => {\n const element = target.element;\n if (!scrollIntoView || !element) return;\n const box = element.getBoundingClientRect();\n const inView = box.top >= 0 && box.left >= 0 && box.bottom <= window.innerHeight && box.right <= window.innerWidth;\n if (!inView) element.scrollIntoView?.({ block: \"center\", inline: \"nearest\", behavior: reduced ? \"auto\" : \"smooth\" });\n }, [target.element, scrollIntoView, reduced]);\n\n // Place the panel against the target once both sizes are known; hidden until then, so it never jumps.\n React.useLayoutEffect(() => {\n if (!isOpen || target.status === \"pending\" || (target.status === \"missing\" && missingTarget === \"skip\")) {\n setPlaced(false);\n return;\n }\n if (centered || !rect) {\n setPosition(null);\n setPlaced(true);\n return;\n }\n const panel = panelRef.current;\n if (!panel) return;\n const pad = spotlightPadding;\n const lit = { top: rect.top - pad, left: rect.left - pad, width: rect.width + pad * 2, height: rect.height + pad * 2, bottom: rect.bottom + pad, right: rect.right + pad };\n const side = physical(current?.placement ?? placement, rtl);\n setPosition(placePanel(lit, { width: panel.offsetWidth, height: panel.offsetHeight }, side, { width: window.innerWidth, height: window.innerHeight }));\n setPlaced(true);\n }, [isOpen, rect, centered, target.status, missingTarget, spotlightPadding, current?.placement, placement, rtl, index]);\n\n // Each step's heading takes focus, so a screen reader reads where the tour went; the status line says how far.\n React.useEffect(() => {\n if (isOpen && placed) titleRef.current?.focus({ preventScroll: true });\n }, [isOpen, placed, index]);\n\n if (!isOpen || !current) return null;\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n if (!mask && event.key === \"Escape\") {\n event.stopPropagation();\n skip();\n return;\n }\n if (isKeyboardNavigationDisabled || isEditable(event.target)) return;\n const forward = rtl ? \"ArrowLeft\" : \"ArrowRight\";\n const backward = rtl ? \"ArrowRight\" : \"ArrowLeft\";\n if (event.key === forward) {\n event.preventDefault();\n next();\n } else if (event.key === backward) {\n event.preventDefault();\n back();\n }\n };\n\n const last = index === total - 1;\n const progress = stepOfLabel(locale, index + 1, total);\n const style: React.CSSProperties = position ? { top: position.top, left: position.left } : { top: \"50%\", left: \"50%\", transform: \"translate(-50%, -50%)\" };\n const spot = !centered && target.status === \"found\" ? rect : null;\n\n const panel = (\n <AriaDialog\n ref={panelRef as React.Ref<HTMLElement>}\n aria-describedby={current.description ? descriptionId : undefined}\n data-slot=\"tour\"\n data-side={position?.side ?? \"center\"}\n data-step={index}\n style={style}\n className={cn(PANEL, !placed && \"invisible opacity-0\", !mask && \"z-50\")}\n >\n <OverlayContents>\n {/* Keys from anything focused in the panel (the heading, a button) bubble here. */}\n <div onKeyDown={onKeyDown} className=\"flex flex-col gap-ds-150\">\n <div className=\"flex items-start justify-between gap-ds-100\">\n <div className=\"flex min-w-0 flex-col gap-ds-050\">\n {showProgress && total > 1 && (\n <span data-slot=\"tour-progress\" className=\"text-body-small text-ds-text-subtle\">\n {progress}\n </span>\n )}\n <Heading\n ref={titleRef}\n slot=\"title\"\n tabIndex={-1}\n data-slot=\"tour-title\"\n className=\"m-0 -mx-ds-050 px-ds-050 text-heading-small outline-hidden focus-visible:rounded-ds-small focus-visible:inset-ring-2 focus-visible:inset-ring-ds-border-focused\"\n >\n {current.title}\n </Heading>\n </div>\n {/* Pulled into the corner so its icon lines up with the padding, as Dialog's. */}\n <span data-slot=\"tour-close-wrap\" className=\"-me-ds-100 -mt-ds-050 flex shrink-0\">\n <CloseButton data-slot=\"tour-close\" onPress={skip} />\n </span>\n </div>\n {current.description && (\n <div id={descriptionId} data-slot=\"tour-description\" className=\"text-body text-ds-text-subtle\">\n {current.description}\n </div>\n )}\n <div data-slot=\"tour-footer\" className=\"flex flex-wrap items-center gap-ds-100\">\n <span className=\"-ms-ds-100 flex\">\n <Button data-slot=\"tour-skip\" variant=\"subtle\" size=\"small\" onPress={skip}>\n {tourSkipLabel(locale)}\n </Button>\n </span>\n <div className=\"ms-auto flex gap-ds-100\">\n {index > 0 && (\n <Button data-slot=\"tour-back\" variant=\"default\" size=\"small\" onPress={back}>\n {tourBackLabel(locale)}\n </Button>\n )}\n <Button data-slot=\"tour-next\" variant=\"primary\" size=\"small\" onPress={next}>\n {last ? tourFinishLabel(locale) : tourNextLabel(locale)}\n </Button>\n </div>\n </div>\n <span role=\"status\" data-slot=\"tour-status\" className=\"sr-only\">\n {placed && total > 1 ? progress : \"\"}\n </span>\n </div>\n </OverlayContents>\n </AriaDialog>\n );\n\n if (!mask) {\n if (typeof document === \"undefined\") return null;\n return createPortal(\n <div {...motion} data-slot=\"tour-layer\" style={{ display: \"contents\" }}>\n {panel}\n </div>,\n document.body,\n );\n }\n\n return (\n <ModalOverlay\n {...motion}\n isOpen\n // Outside presses (the dimmed page, the target) do nothing; Esc skips.\n isDismissable={false}\n onOpenChange={(open) => {\n if (!open) skip();\n }}\n data-slot=\"tour-overlay\"\n className={cn(\"fixed inset-0 z-50\", !spot && \"bg-ds-blanket\")}\n >\n {spot && (\n <div\n aria-hidden\n data-slot=\"tour-spotlight\"\n className={SPOTLIGHT}\n style={{\n top: spot.top - spotlightPadding,\n left: spot.left - spotlightPadding,\n width: spot.width + spotlightPadding * 2,\n height: spot.height + spotlightPadding * 2,\n }}\n />\n )}\n <Modal data-slot=\"tour-modal\" className=\"outline-hidden\">\n {panel}\n </Modal>\n </ModalOverlay>\n );\n}\n\n/**\n * A guided tour: a short sequence of steps, each pointing at a part of the page with a title, a sentence and\n * Back / Next / Done, plus Skip. By default the page is dimmed except the step's target, which cannot be pressed,\n * and focus stays in the panel; `mask={false}` keeps the page usable. Arrow keys move between steps (mirrored\n * right to left), Esc skips. A target can be a selector, a ref or a function; one that is not on the page yet is\n * waited for, then shown centred or skipped.\n */\nexport function Tour({ motion, ...props }: TourProps & WithMotion) {\n return (\n <MotionScope motion={motion}>\n <TourRoot {...props} />\n </MotionScope>\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senvenli/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Senvenli UI web components (React Aria Components + Tailwind v4).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Senvenli",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"clsx": "^2.1.1",
|
|
95
95
|
"recharts": "^3.11.0",
|
|
96
96
|
"tailwind-merge": "^3.5.0",
|
|
97
|
-
"@senvenli/tokens": "^0.3.
|
|
97
|
+
"@senvenli/tokens": "^0.3.4"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"lucide-react": "^1.34.0",
|
package/dist/action/files.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { type DropItem, type FileTriggerProps as AriaFileTriggerProps } from "react-aria-components";
|
|
3
|
-
/** Bytes as the locale writes them: "2.4 MB", "980 kB". */
|
|
4
|
-
export declare function formatFileSize(bytes: number, locale: string): string;
|
|
5
|
-
export type FileRules = {
|
|
6
|
-
/** MIME types or extensions: "image/jpeg", "image/*", ".heic", "application/pdf". */
|
|
7
|
-
acceptedFileTypes?: readonly string[];
|
|
8
|
-
/** Bytes. */
|
|
9
|
-
maxSize?: number;
|
|
10
|
-
};
|
|
11
|
-
export type RejectedFile = {
|
|
12
|
-
file: File;
|
|
13
|
-
reason: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Checks each file on its own: a wrong type or a file over `maxSize` is
|
|
17
|
-
* rejected with the reason, and the others are kept (design rule).
|
|
18
|
-
*/
|
|
19
|
-
export declare function validateFiles(files: readonly File[], rules: FileRules, locale: string): {
|
|
20
|
-
accepted: File[];
|
|
21
|
-
rejected: RejectedFile[];
|
|
22
|
-
};
|
|
23
|
-
export type FileTriggerProps = Omit<AriaFileTriggerProps, "onSelect" | "acceptedFileTypes"> & FileRules & {
|
|
24
|
-
/** Files that passed the rules. */
|
|
25
|
-
onSelect?: (files: File[]) => void;
|
|
26
|
-
/** Files that did not, each with its reason. */
|
|
27
|
-
onReject?: (rejected: RejectedFile[]) => void;
|
|
28
|
-
/** The control that opens the picker: a DS Button or Link. */
|
|
29
|
-
children: React.ReactElement;
|
|
30
|
-
};
|
|
31
|
-
/** Opens the system file picker from any button. */
|
|
32
|
-
export declare function FileTrigger({ onSelect, onReject, acceptedFileTypes, maxSize, children, ...rest }: FileTriggerProps): React.JSX.Element;
|
|
33
|
-
export type DropZoneProps = FileRules & {
|
|
34
|
-
/** What to drop, as a call to action: "Drag your photos here". */
|
|
35
|
-
label: string;
|
|
36
|
-
/** The accepted types as people read them ("JPG, PNG, HEIC"); the size limit is added. */
|
|
37
|
-
typesLabel?: string;
|
|
38
|
-
allowsMultiple?: boolean;
|
|
39
|
-
onSelect?: (files: File[]) => void;
|
|
40
|
-
onReject?: (rejected: RejectedFile[]) => void;
|
|
41
|
-
isDisabled?: boolean;
|
|
42
|
-
};
|
|
43
|
-
/** The files among dropped items; folders, text and files the browser cannot read are skipped. */
|
|
44
|
-
export declare function filesFrom(items: readonly DropItem[]): Promise<File[]>;
|
|
45
|
-
/**
|
|
46
|
-
* A drop target with the picker inside: states the accepted types and the
|
|
47
|
-
* size limit before the user picks; while a file is over it the zone takes
|
|
48
|
-
* the selected fill and border.
|
|
49
|
-
*/
|
|
50
|
-
export declare function DropZone({ label, typesLabel, allowsMultiple, acceptedFileTypes, maxSize, onSelect, onReject, isDisabled }: DropZoneProps): React.JSX.Element;
|
|
51
|
-
export type FileRowProps = {
|
|
52
|
-
/** The picked file; photos get a thumbnail at once, before upload ends. */
|
|
53
|
-
file?: File;
|
|
54
|
-
/** Shown name and size when there is no File object (a stored document). */
|
|
55
|
-
name?: string;
|
|
56
|
-
size?: number;
|
|
57
|
-
/** 0–1 while uploading; omit when done. */
|
|
58
|
-
progress?: number;
|
|
59
|
-
error?: string;
|
|
60
|
-
onCancel?: () => void;
|
|
61
|
-
onRemove?: () => void;
|
|
62
|
-
onReplace?: () => void;
|
|
63
|
-
};
|
|
64
|
-
/** One picked or stored file: thumbnail, name, progress or size, per-file error, one trailing action. */
|
|
65
|
-
export declare function FileRow({ file, name, size, progress, error, onCancel, onRemove, onReplace }: FileRowProps): React.JSX.Element;
|
|
66
|
-
/** The list of picked or stored files. */
|
|
67
|
-
export declare function FileUploadList({ children, "aria-label": ariaLabel }: {
|
|
68
|
-
children: React.ReactNode;
|
|
69
|
-
"aria-label"?: string;
|
|
70
|
-
}): React.JSX.Element;
|