@zonsh/ui 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
4
|
+
import { Dialog as BaseDialog } from "@base-ui/react/dialog";
|
|
5
|
+
import { ChevronLeftIcon, ChevronRightIcon, DownloadIcon, XIcon, ZoomInIcon, ZoomOutIcon, } from "lucide-react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { cn, sx } from "../lib/cn.js";
|
|
8
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
9
|
+
import { usePopupDir } from "./_overlay.js";
|
|
10
|
+
import { Button } from "./button.js";
|
|
11
|
+
import { useMessages } from "./locale.js";
|
|
12
|
+
import { Spinner } from "./spinner.js";
|
|
13
|
+
const defaultMessages = {
|
|
14
|
+
title: "Image viewer",
|
|
15
|
+
close: "Close",
|
|
16
|
+
previous: "Previous image",
|
|
17
|
+
next: "Next image",
|
|
18
|
+
zoomIn: "Zoom in",
|
|
19
|
+
zoomOut: "Zoom out",
|
|
20
|
+
download: "Download",
|
|
21
|
+
loading: "Loading image",
|
|
22
|
+
position: (index, count) => `Image ${index} of ${count}`,
|
|
23
|
+
};
|
|
24
|
+
const LightboxContext = React.createContext(null);
|
|
25
|
+
function useLightboxContext(part) {
|
|
26
|
+
const context = React.useContext(LightboxContext);
|
|
27
|
+
if (!context)
|
|
28
|
+
throw new Error(`${part} must be used within a <Lightbox />`);
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lightbox — images opened large over the page, one at a time: the photos of a listing, the
|
|
33
|
+
* figures of an article, the attachments of a report.
|
|
34
|
+
*
|
|
35
|
+
* Thumbnails (`LightboxGrid`, or `LightboxTrigger`s around your own) open a full-screen viewer on
|
|
36
|
+
* a black ground in either theme, with a mono "03 / 12" counter, previous and next buttons, the
|
|
37
|
+
* arrow keys and a swipe, zoom by double click or tap, wheel or pinch with a drag to pan, a
|
|
38
|
+
* caption and an optional download. It is a modal Dialog: focus stays inside, Escape closes it,
|
|
39
|
+
* and focus returns to the thumbnail of the image last shown.
|
|
40
|
+
*
|
|
41
|
+
* The rule people break: an empty `alt`. Every image is named, in the grid and in the viewer.
|
|
42
|
+
*/
|
|
43
|
+
export function Lightbox({ images, index: indexProp, defaultIndex = 0, onIndexChange, open: openProp, defaultOpen = false, onOpenChange, loop = false, download = false, imageClassName, labels, children, }) {
|
|
44
|
+
const text = useMessages("lightbox", defaultMessages, labels);
|
|
45
|
+
const [ownIndex, setOwnIndex] = React.useState(defaultIndex);
|
|
46
|
+
const [ownOpen, setOwnOpen] = React.useState(defaultOpen);
|
|
47
|
+
const count = images.length;
|
|
48
|
+
const raw = indexProp ?? ownIndex;
|
|
49
|
+
const index = count ? Math.min(Math.max(Math.floor(raw) || 0, 0), count - 1) : 0;
|
|
50
|
+
const open = (openProp ?? ownOpen) && count > 0;
|
|
51
|
+
const triggers = React.useRef(new Map());
|
|
52
|
+
/** Whatever opened the viewer, if it was not one of the thumbnails. */
|
|
53
|
+
const opener = React.useRef(null);
|
|
54
|
+
const setIndex = React.useCallback((next) => {
|
|
55
|
+
if (indexProp === undefined)
|
|
56
|
+
setOwnIndex(next);
|
|
57
|
+
onIndexChange?.(next);
|
|
58
|
+
}, [indexProp, onIndexChange]);
|
|
59
|
+
const setOpen = React.useCallback((next) => {
|
|
60
|
+
if (openProp === undefined)
|
|
61
|
+
setOwnOpen(next);
|
|
62
|
+
onOpenChange?.(next);
|
|
63
|
+
}, [openProp, onOpenChange]);
|
|
64
|
+
const context = {
|
|
65
|
+
images,
|
|
66
|
+
index,
|
|
67
|
+
open,
|
|
68
|
+
loop,
|
|
69
|
+
download,
|
|
70
|
+
imageClassName,
|
|
71
|
+
text,
|
|
72
|
+
setIndex,
|
|
73
|
+
openAt: (at, from) => {
|
|
74
|
+
opener.current = from ?? document.activeElement;
|
|
75
|
+
if (at !== index)
|
|
76
|
+
setIndex(at);
|
|
77
|
+
setOpen(true);
|
|
78
|
+
},
|
|
79
|
+
close: () => setOpen(false),
|
|
80
|
+
registerTrigger: (at, el) => {
|
|
81
|
+
if (el)
|
|
82
|
+
triggers.current.set(at, el);
|
|
83
|
+
return () => {
|
|
84
|
+
if (triggers.current.get(at) === el)
|
|
85
|
+
triggers.current.delete(at);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
triggerFor: (at) => {
|
|
89
|
+
const el = triggers.current.get(at);
|
|
90
|
+
return el?.isConnected ? el : opener.current?.isConnected ? opener.current : null;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return (_jsx(LightboxContext.Provider, { value: context, children: _jsxs(BaseDialog.Root, { open: open, onOpenChange: (next) => setOpen(next), children: [children, _jsx(LightboxViewer, {})] }) }));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Opens the viewer at one image. Put the thumbnail inside, with its `alt`: it names the button.
|
|
97
|
+
* Compose with `render` to draw it as something else.
|
|
98
|
+
*/
|
|
99
|
+
export function LightboxTrigger({ index, className, onClick, ref, ...props }) {
|
|
100
|
+
const context = useLightboxContext("LightboxTrigger");
|
|
101
|
+
const own = React.useRef(null);
|
|
102
|
+
const { registerTrigger } = context;
|
|
103
|
+
React.useLayoutEffect(() => registerTrigger(index, own.current), [registerTrigger, index]);
|
|
104
|
+
const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
|
|
105
|
+
return (_jsx(BaseButton, { ref: refs, "data-slot": "lightbox-trigger", "aria-haspopup": "dialog", onClick: (event) => {
|
|
106
|
+
onClick?.(event);
|
|
107
|
+
if (!event.defaultPrevented)
|
|
108
|
+
context.openAt(index, event.currentTarget);
|
|
109
|
+
}, className: sx("cursor-zoom-in focus-ring", className), ...props }));
|
|
110
|
+
}
|
|
111
|
+
const gridColumns = {
|
|
112
|
+
2: "grid-cols-2",
|
|
113
|
+
3: "grid-cols-2 sm:grid-cols-3",
|
|
114
|
+
4: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4",
|
|
115
|
+
5: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5",
|
|
116
|
+
6: "grid-cols-3 sm:grid-cols-4 md:grid-cols-6",
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The thumbnails of every image as a grid of square buttons, each cropped to fill its square and
|
|
120
|
+
* edged with a `--field-edge` hairline at 12px.
|
|
121
|
+
*/
|
|
122
|
+
export function LightboxGrid({ columns = 4, className, ...props }) {
|
|
123
|
+
const { images } = useLightboxContext("LightboxGrid");
|
|
124
|
+
return (_jsx("ul", { "data-slot": "lightbox-grid", className: cn("m-0 grid w-full list-none gap-2 p-0", gridColumns[columns], className), ...props, children: images.map((image, i) => (_jsx("li", { className: "min-w-0", children: _jsx(LightboxTrigger, { index: i, className: "group/thumb block w-full overflow-hidden rounded-button border border-field-edge bg-control-surface p-0", children: _jsx("img", { src: image.thumbnail ?? image.src, alt: image.alt, loading: "lazy", decoding: "async", draggable: false, className: "aspect-square w-full object-cover transition-[scale] duration-[calc(var(--duration)*2)] ease-(--ease) group-hover/thumb:scale-[1.03]" }) }) }, `${image.src}-${i}`))) }));
|
|
125
|
+
}
|
|
126
|
+
/* ── The viewer ────────────────────────────────────────────────────────────── */
|
|
127
|
+
/** The furthest zoom, and the one a double click goes to when the image is no larger than its place. */
|
|
128
|
+
const MAX_ZOOM = 4;
|
|
129
|
+
const STEP_ZOOM = 2;
|
|
130
|
+
/** A swipe that goes further than this, or flicks faster (px/ms, over at least 20px), turns the page. */
|
|
131
|
+
const SWIPE = 60;
|
|
132
|
+
const FLICK = 0.11;
|
|
133
|
+
/** A wheel or trackpad pinch counts as one gesture until this long (ms) after its last event. */
|
|
134
|
+
const WHEEL_SETTLE = 120;
|
|
135
|
+
/** Two taps this close in time and place are a double tap. */
|
|
136
|
+
const DOUBLE_TAP = 300;
|
|
137
|
+
const REST = { scale: 1, x: 0, y: 0 };
|
|
138
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
139
|
+
function LightboxViewer() {
|
|
140
|
+
const context = useLightboxContext("LightboxViewer");
|
|
141
|
+
const { images, index, open, loop, text, setIndex, close } = context;
|
|
142
|
+
const count = images.length;
|
|
143
|
+
const image = images[index];
|
|
144
|
+
const dir = usePopupDir();
|
|
145
|
+
const popupRef = React.useRef(null);
|
|
146
|
+
const frameRef = React.useRef(null);
|
|
147
|
+
const imgRef = React.useRef(null);
|
|
148
|
+
const [view, setViewState] = React.useState(REST);
|
|
149
|
+
const viewRef = React.useRef(view);
|
|
150
|
+
const setView = (next) => {
|
|
151
|
+
viewRef.current = next;
|
|
152
|
+
setViewState(next);
|
|
153
|
+
};
|
|
154
|
+
const [swipe, setSwipe] = React.useState(0);
|
|
155
|
+
const [gesturing, setGesturing] = React.useState(false);
|
|
156
|
+
// While the wheel or a trackpad pinch is moving, the image follows each event at once: a
|
|
157
|
+
// transition retargeted on every event would trail behind the fingers.
|
|
158
|
+
const [wheeling, setWheeling] = React.useState(false);
|
|
159
|
+
const wheelTimer = React.useRef(undefined);
|
|
160
|
+
const [loaded, setLoaded] = React.useState(false);
|
|
161
|
+
const canPrev = loop ? count > 1 : index > 0;
|
|
162
|
+
const canNext = loop ? count > 1 : index < count - 1;
|
|
163
|
+
const zoomed = view.scale > 1.01;
|
|
164
|
+
const go = (delta) => {
|
|
165
|
+
if (count < 2)
|
|
166
|
+
return;
|
|
167
|
+
let next = index + delta;
|
|
168
|
+
if (loop)
|
|
169
|
+
next = (next + count) % count;
|
|
170
|
+
else
|
|
171
|
+
next = Math.min(Math.max(next, 0), count - 1);
|
|
172
|
+
if (next !== index)
|
|
173
|
+
setIndex(next);
|
|
174
|
+
};
|
|
175
|
+
// A new image starts at rest; it is shown once it has loaded (at once from the cache).
|
|
176
|
+
React.useLayoutEffect(() => {
|
|
177
|
+
setView(REST);
|
|
178
|
+
setSwipe(0);
|
|
179
|
+
const img = imgRef.current;
|
|
180
|
+
setLoaded(!!img && img.complete && img.naturalWidth > 0);
|
|
181
|
+
}, [index, open]);
|
|
182
|
+
// The neighbours load in the background, so previous and next show at once.
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (!open)
|
|
185
|
+
return;
|
|
186
|
+
for (const at of [index - 1, index + 1]) {
|
|
187
|
+
const neighbour = images[loop ? (at + count) % count : at];
|
|
188
|
+
if (neighbour) {
|
|
189
|
+
const pre = new Image();
|
|
190
|
+
if (neighbour.srcSet)
|
|
191
|
+
pre.srcset = neighbour.srcSet;
|
|
192
|
+
if (neighbour.sizes)
|
|
193
|
+
pre.sizes = neighbour.sizes;
|
|
194
|
+
pre.src = neighbour.src;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}, [open, index, images, loop, count]);
|
|
198
|
+
/** Keep a zoomed image over its place: no gap opens at an edge while there is more of it beyond. */
|
|
199
|
+
const clamp = (next) => {
|
|
200
|
+
const img = imgRef.current;
|
|
201
|
+
const frame = frameRef.current;
|
|
202
|
+
const scale = Math.min(Math.max(next.scale, 1), MAX_ZOOM);
|
|
203
|
+
if (!img || !frame || scale <= 1.01)
|
|
204
|
+
return REST;
|
|
205
|
+
const maxX = Math.max(0, (img.offsetWidth * scale - frame.clientWidth) / 2);
|
|
206
|
+
const maxY = Math.max(0, (img.offsetHeight * scale - frame.clientHeight) / 2);
|
|
207
|
+
return {
|
|
208
|
+
scale,
|
|
209
|
+
x: Math.min(Math.max(next.x, -maxX), maxX),
|
|
210
|
+
y: Math.min(Math.max(next.y, -maxY), maxY),
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
/** Zoom to `scale`, keeping the point under (clientX, clientY) — the middle by default — in place. */
|
|
214
|
+
const zoomTo = (scale, point, from = viewRef.current) => {
|
|
215
|
+
const frame = frameRef.current;
|
|
216
|
+
if (!frame)
|
|
217
|
+
return;
|
|
218
|
+
const rect = frame.getBoundingClientRect();
|
|
219
|
+
const cx = rect.left + rect.width / 2;
|
|
220
|
+
const cy = rect.top + rect.height / 2;
|
|
221
|
+
const dx = (point?.x ?? cx) - cx;
|
|
222
|
+
const dy = (point?.y ?? cy) - cy;
|
|
223
|
+
const next = Math.min(Math.max(scale, 1), MAX_ZOOM);
|
|
224
|
+
const k = next / from.scale;
|
|
225
|
+
setView(clamp({ scale: next, x: dx - k * (dx - from.x), y: dy - k * (dy - from.y) }));
|
|
226
|
+
};
|
|
227
|
+
/** A double click or tap: in to the image's own pixels (at least twice), or back out. */
|
|
228
|
+
const toggleZoom = (point) => {
|
|
229
|
+
if (viewRef.current.scale > 1.01)
|
|
230
|
+
return setView(REST);
|
|
231
|
+
const img = imgRef.current;
|
|
232
|
+
const natural = img && img.offsetWidth ? img.naturalWidth / img.offsetWidth : 1;
|
|
233
|
+
zoomTo(Math.min(Math.max(natural, STEP_ZOOM), MAX_ZOOM), point);
|
|
234
|
+
};
|
|
235
|
+
/* Gestures: one pointer pans a zoomed image or swipes to the next; two pinch. */
|
|
236
|
+
const pointers = React.useRef(new Map());
|
|
237
|
+
const gesture = React.useRef(null);
|
|
238
|
+
const lastTap = React.useRef(null);
|
|
239
|
+
const lastPointerType = React.useRef("mouse");
|
|
240
|
+
/** Whether the press began on the image, or on the black around it. */
|
|
241
|
+
const pressedImage = React.useRef(false);
|
|
242
|
+
/** A tap on the black closes the viewer on the click that follows it (see `onPointerUp`). */
|
|
243
|
+
const tapClose = React.useRef(false);
|
|
244
|
+
const rtl = () => (popupRef.current ? getComputedStyle(popupRef.current).direction === "rtl" : false);
|
|
245
|
+
const beginGesture = () => {
|
|
246
|
+
const points = [...pointers.current.values()];
|
|
247
|
+
const from = viewRef.current;
|
|
248
|
+
if (points.length >= 2) {
|
|
249
|
+
const [a, b] = points;
|
|
250
|
+
gesture.current = {
|
|
251
|
+
kind: "pinch",
|
|
252
|
+
startX: 0,
|
|
253
|
+
startY: 0,
|
|
254
|
+
time: performance.now(),
|
|
255
|
+
from,
|
|
256
|
+
distance: Math.hypot(a.x - b.x, a.y - b.y) || 1,
|
|
257
|
+
mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
|
|
258
|
+
moved: true,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
else if (points.length === 1) {
|
|
262
|
+
const [p] = points;
|
|
263
|
+
gesture.current = {
|
|
264
|
+
kind: from.scale > 1.01 ? "pan" : "swipe",
|
|
265
|
+
startX: p.x,
|
|
266
|
+
startY: p.y,
|
|
267
|
+
time: performance.now(),
|
|
268
|
+
from,
|
|
269
|
+
distance: 0,
|
|
270
|
+
mid: p,
|
|
271
|
+
moved: gesture.current?.moved ?? false,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const onPointerDown = (event) => {
|
|
276
|
+
lastPointerType.current = event.pointerType;
|
|
277
|
+
if (event.pointerType === "mouse" && event.button !== 0)
|
|
278
|
+
return;
|
|
279
|
+
if (event.target.closest("button, a"))
|
|
280
|
+
return;
|
|
281
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
282
|
+
pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
283
|
+
if (pointers.current.size === 1) {
|
|
284
|
+
gesture.current = null;
|
|
285
|
+
pressedImage.current = event.target === imgRef.current;
|
|
286
|
+
tapClose.current = false;
|
|
287
|
+
}
|
|
288
|
+
beginGesture();
|
|
289
|
+
setGesturing(true);
|
|
290
|
+
};
|
|
291
|
+
const onPointerMove = (event) => {
|
|
292
|
+
if (!pointers.current.has(event.pointerId))
|
|
293
|
+
return;
|
|
294
|
+
pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
295
|
+
const g = gesture.current;
|
|
296
|
+
if (!g)
|
|
297
|
+
return;
|
|
298
|
+
if (g.kind === "pinch") {
|
|
299
|
+
const [a, b] = [...pointers.current.values()];
|
|
300
|
+
if (!a || !b)
|
|
301
|
+
return;
|
|
302
|
+
const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
303
|
+
const scale = g.from.scale * (Math.hypot(a.x - b.x, a.y - b.y) / g.distance);
|
|
304
|
+
// Zoom about where the fingers started, then follow them as they move together.
|
|
305
|
+
const moved = { ...g.from, x: g.from.x + mid.x - g.mid.x, y: g.from.y + mid.y - g.mid.y };
|
|
306
|
+
zoomTo(scale, mid, moved);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const dx = event.clientX - g.startX;
|
|
310
|
+
const dy = event.clientY - g.startY;
|
|
311
|
+
if (Math.hypot(dx, dy) > 6)
|
|
312
|
+
g.moved = true;
|
|
313
|
+
if (g.kind === "pan") {
|
|
314
|
+
setView(clamp({ scale: g.from.scale, x: g.from.x + dx, y: g.from.y + dy }));
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
// Past the first or last image the picture gives a little, and springs back.
|
|
318
|
+
const forward = rtl() ? dx > 0 : dx < 0;
|
|
319
|
+
setSwipe((forward ? canNext : canPrev) ? dx : dx * 0.3);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const onPointerUp = (event) => {
|
|
323
|
+
if (!pointers.current.has(event.pointerId))
|
|
324
|
+
return;
|
|
325
|
+
pointers.current.delete(event.pointerId);
|
|
326
|
+
const g = gesture.current;
|
|
327
|
+
if (pointers.current.size > 0) {
|
|
328
|
+
// One finger of a pinch lifted: the other pans on from here.
|
|
329
|
+
beginGesture();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
gesture.current = null;
|
|
333
|
+
setGesturing(false);
|
|
334
|
+
if (!g || event.type === "pointercancel") {
|
|
335
|
+
setSwipe(0);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (g.kind === "swipe") {
|
|
339
|
+
const dx = event.clientX - g.startX;
|
|
340
|
+
const speed = Math.abs(dx) / Math.max(performance.now() - g.time, 1);
|
|
341
|
+
setSwipe(0);
|
|
342
|
+
if (Math.abs(dx) > SWIPE || (Math.abs(dx) > 20 && speed > FLICK)) {
|
|
343
|
+
const forward = rtl() ? dx > 0 : dx < 0;
|
|
344
|
+
if (forward ? canNext : canPrev)
|
|
345
|
+
go(forward ? 1 : -1);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (g.moved)
|
|
350
|
+
return;
|
|
351
|
+
const point = { x: event.clientX, y: event.clientY };
|
|
352
|
+
if (event.pointerType === "touch") {
|
|
353
|
+
const tap = lastTap.current;
|
|
354
|
+
if (tap &&
|
|
355
|
+
event.timeStamp - tap.time < DOUBLE_TAP &&
|
|
356
|
+
Math.hypot(tap.x - point.x, tap.y - point.y) < 30) {
|
|
357
|
+
lastTap.current = null;
|
|
358
|
+
toggleZoom(point);
|
|
359
|
+
}
|
|
360
|
+
else if (!pressedImage.current && viewRef.current.scale <= 1.01) {
|
|
361
|
+
// A tap on the black closes the viewer, as a click there does: at once, since a double
|
|
362
|
+
// tap zooms only on the image (or out of a zoomed one). It closes on the click the tap
|
|
363
|
+
// makes, not here, so that click lands on the viewer and not on what is under it.
|
|
364
|
+
lastTap.current = null;
|
|
365
|
+
tapClose.current = true;
|
|
366
|
+
}
|
|
367
|
+
else
|
|
368
|
+
lastTap.current = { time: event.timeStamp, ...point };
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
// A click on the black around the image closes the viewer, as a click outside a dialog would.
|
|
372
|
+
if (!pressedImage.current && viewRef.current.scale <= 1.01)
|
|
373
|
+
close();
|
|
374
|
+
};
|
|
375
|
+
// Wheel and trackpad pinch zoom (a pinch arrives as a wheel with Ctrl). Not passive: the page
|
|
376
|
+
// must not scroll or zoom under the viewer.
|
|
377
|
+
React.useEffect(() => {
|
|
378
|
+
const frame = frameRef.current;
|
|
379
|
+
if (!open || !frame)
|
|
380
|
+
return;
|
|
381
|
+
const onWheel = (event) => {
|
|
382
|
+
event.preventDefault();
|
|
383
|
+
if (wheelTimer.current === undefined)
|
|
384
|
+
setWheeling(true);
|
|
385
|
+
clearTimeout(wheelTimer.current);
|
|
386
|
+
wheelTimer.current = setTimeout(() => {
|
|
387
|
+
wheelTimer.current = undefined;
|
|
388
|
+
setWheeling(false);
|
|
389
|
+
}, WHEEL_SETTLE);
|
|
390
|
+
const factor = Math.exp(-event.deltaY * (event.ctrlKey ? 0.01 : 0.002));
|
|
391
|
+
zoomTo(viewRef.current.scale * factor, { x: event.clientX, y: event.clientY });
|
|
392
|
+
};
|
|
393
|
+
frame.addEventListener("wheel", onWheel, { passive: false });
|
|
394
|
+
return () => {
|
|
395
|
+
frame.removeEventListener("wheel", onWheel);
|
|
396
|
+
clearTimeout(wheelTimer.current);
|
|
397
|
+
wheelTimer.current = undefined;
|
|
398
|
+
setWheeling(false);
|
|
399
|
+
};
|
|
400
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
401
|
+
}, [open, index]);
|
|
402
|
+
const onKeyDown = (event) => {
|
|
403
|
+
if (event.altKey || event.ctrlKey || event.metaKey)
|
|
404
|
+
return;
|
|
405
|
+
const back = rtl() ? "ArrowRight" : "ArrowLeft";
|
|
406
|
+
const forward = rtl() ? "ArrowLeft" : "ArrowRight";
|
|
407
|
+
switch (event.key) {
|
|
408
|
+
case back:
|
|
409
|
+
go(-1);
|
|
410
|
+
break;
|
|
411
|
+
case forward:
|
|
412
|
+
go(1);
|
|
413
|
+
break;
|
|
414
|
+
case "Home":
|
|
415
|
+
if (index !== 0)
|
|
416
|
+
setIndex(0);
|
|
417
|
+
break;
|
|
418
|
+
case "End":
|
|
419
|
+
if (index !== count - 1)
|
|
420
|
+
setIndex(count - 1);
|
|
421
|
+
break;
|
|
422
|
+
case "+":
|
|
423
|
+
case "=":
|
|
424
|
+
zoomTo(viewRef.current.scale * 1.5);
|
|
425
|
+
break;
|
|
426
|
+
case "-":
|
|
427
|
+
zoomTo(viewRef.current.scale / 1.5);
|
|
428
|
+
break;
|
|
429
|
+
case "0":
|
|
430
|
+
setView(REST);
|
|
431
|
+
break;
|
|
432
|
+
default:
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
event.preventDefault();
|
|
436
|
+
};
|
|
437
|
+
if (!image)
|
|
438
|
+
return null;
|
|
439
|
+
const downloadHref = context.download && image.download !== false ? (image.download ?? image.src) : null;
|
|
440
|
+
const fileName = downloadHref
|
|
441
|
+
? decodeURIComponent(downloadHref.split(/[?#]/)[0].split("/").pop() || "")
|
|
442
|
+
: "";
|
|
443
|
+
return (_jsxs(BaseDialog.Portal, { children: [_jsx(BaseDialog.Backdrop, { "data-slot": "lightbox-backdrop", className: "fixed inset-0 z-50 min-h-dvh bg-black transition-opacity duration-(--duration) ease-(--ease) data-ending-style:opacity-0 data-starting-style:opacity-0" }), _jsxs(BaseDialog.Popup, { ref: popupRef, "data-slot": "lightbox-content", dir: dir, initialFocus: popupRef, finalFocus: () => context.triggerFor(index) ?? true, onKeyDown: onKeyDown, className: cn(
|
|
444
|
+
// Dark tokens in either theme: the controls sit on the black ground like a video's.
|
|
445
|
+
"theme-dark fixed inset-0 z-50 flex flex-col bg-transparent font-body text-foreground outline-none",
|
|
446
|
+
// The controls and the image stay clear of the notch, the status bar and the home
|
|
447
|
+
// indicator; the black ground behind still fills the screen.
|
|
448
|
+
"pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)] pb-[env(safe-area-inset-bottom,0px)] pl-[env(safe-area-inset-left,0px)]", "transition-opacity duration-(--duration) ease-(--ease) data-ending-style:opacity-0 data-starting-style:opacity-0"), children: [_jsx(BaseDialog.Title, { className: "sr-only", children: text.title }), _jsxs("div", { "data-slot": "lightbox-header", className: "relative z-10 flex shrink-0 items-center gap-1 px-3 pt-3 sm:px-5 sm:pt-4", children: [_jsxs("div", { "data-slot": "lightbox-counter", dir: "ltr", "aria-hidden": true, className: "ps-2 font-mono text-[13px] leading-none text-muted-foreground tabular-nums", children: [_jsx("span", { className: "text-foreground", children: pad(index + 1) }), " / ", pad(count)] }), _jsxs("div", { className: "ms-auto flex items-center gap-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "lightbox-zoom", "aria-label": zoomed ? text.zoomOut : text.zoomIn, disabled: !loaded, onClick: () => (zoomed ? setView(REST) : toggleZoom()), children: zoomed ? _jsx(ZoomOutIcon, {}) : _jsx(ZoomInIcon, {}) }), downloadHref && (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "lightbox-download", "aria-label": text.download, nativeButton: false, render: _jsx("a", { href: downloadHref, download: fileName || true }), children: _jsx(DownloadIcon, {}) })), _jsx(BaseDialog.Close, { "data-slot": "lightbox-close", "aria-label": text.close, render: _jsx(Button, { variant: "ghost", size: "icon" }), children: _jsx(XIcon, {}) })] })] }), _jsxs("div", { ref: frameRef, "data-slot": "lightbox-stage", "data-zoomed": zoomed ? "" : undefined, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: onPointerUp, onClick: () => {
|
|
449
|
+
if (!tapClose.current)
|
|
450
|
+
return;
|
|
451
|
+
tapClose.current = false;
|
|
452
|
+
close();
|
|
453
|
+
}, onDoubleClick: (event) => {
|
|
454
|
+
if (lastPointerType.current !== "touch")
|
|
455
|
+
toggleZoom({ x: event.clientX, y: event.clientY });
|
|
456
|
+
}, className: cn("relative flex min-h-0 flex-1 touch-none items-center justify-center overflow-hidden px-4 py-3 select-none sm:px-20", zoomed && (gesturing ? "cursor-grabbing" : "cursor-grab")), children: [!loaded && (_jsx(Spinner, { label: text.loading, className: "absolute top-1/2 left-1/2 -translate-1/2 text-muted-foreground" })), _jsx("img", { ref: imgRef, "data-slot": "lightbox-image", src: image.src, srcSet: image.srcSet, sizes: image.sizes, alt: image.alt, draggable: false, onLoad: () => setLoaded(true), onError: () => setLoaded(true), style: { transform: `translate(${view.x + swipe}px, ${view.y}px) scale(${view.scale})` }, className: cn("max-h-full max-w-full object-contain", !zoomed && "cursor-zoom-in", "transition-[opacity,transform] duration-(--duration) ease-(--ease) will-change-transform", (gesturing || wheeling) && "transition-none", loaded ? "opacity-100" : "opacity-0", context.imageClassName) }, index), count > 1 && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "secondary", size: "icon", "data-slot": "lightbox-previous", "aria-label": text.previous, disabled: !canPrev, focusableWhenDisabled: true, onClick: () => go(-1), className: "absolute start-3 top-1/2 z-10 -translate-y-1/2 sm:start-5", children: _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }) }), _jsx(Button, { variant: "secondary", size: "icon", "data-slot": "lightbox-next", "aria-label": text.next, disabled: !canNext, focusableWhenDisabled: true, onClick: () => go(1), className: "absolute end-3 top-1/2 z-10 -translate-y-1/2 sm:end-5", children: _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }) })] }))] }), _jsx("div", { "data-slot": "lightbox-caption", className: "relative z-10 mx-auto min-h-14 w-full max-w-2xl shrink-0 px-6 pt-2 pb-5 text-center text-[15px] leading-relaxed text-pretty text-foreground-soft", children: image.caption }), _jsx("div", { "data-slot": "lightbox-status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: open ? `${text.position(index + 1, count)}${image.alt ? `: ${image.alt}` : ""}` : "" })] })] }));
|
|
457
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Every component's interface text, by component. Each component adds its own entry next to its
|
|
4
|
+
* code (declaration merging), with its English defaults there too:
|
|
5
|
+
*
|
|
6
|
+
* declare module "./locale" {
|
|
7
|
+
* interface Messages { pagination: PaginationMessages }
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* so `LocaleProvider messages` is typed for every component in the library.
|
|
11
|
+
*/
|
|
12
|
+
export interface Messages {
|
|
13
|
+
}
|
|
14
|
+
/** Messages for some components, and some strings of each: what is left out stays English. */
|
|
15
|
+
export type PartialMessages = {
|
|
16
|
+
[K in keyof Messages]?: Partial<Messages[K]>;
|
|
17
|
+
};
|
|
18
|
+
export interface LocaleProviderProps {
|
|
19
|
+
/**
|
|
20
|
+
* A BCP 47 language tag ("de-DE", "ar-EG"). Numbers, dates, times and sizes inside are
|
|
21
|
+
* formatted for it; without one, components use the browser's language.
|
|
22
|
+
*/
|
|
23
|
+
locale?: string;
|
|
24
|
+
/** The interface text to replace, by component; nested providers merge into the outer one. */
|
|
25
|
+
messages?: PartialMessages;
|
|
26
|
+
children?: React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* LocaleProvider — the language of every component inside it: the interface text people read
|
|
30
|
+
* and hear ("Previous page", "Copied", "No results") and the locale numbers and dates are
|
|
31
|
+
* formatted in.
|
|
32
|
+
*
|
|
33
|
+
* Wrap the app once. A component's own `labels` prop still wins over the provider, for the one
|
|
34
|
+
* place that needs other words. The rule people break: translating the visible text and leaving
|
|
35
|
+
* the accessible names English — they come from here too, so pass the whole message set.
|
|
36
|
+
*/
|
|
37
|
+
export declare function LocaleProvider({ locale, messages, children }: LocaleProviderProps): React.JSX.Element;
|
|
38
|
+
/** The locale set by the nearest LocaleProvider, or undefined for the browser's own. */
|
|
39
|
+
export declare function useLocale(): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* A component's interface text: its English `defaults`, then what a LocaleProvider sets for it,
|
|
42
|
+
* then the component's own `labels` prop.
|
|
43
|
+
*/
|
|
44
|
+
export declare function useMessages<K extends keyof Messages>(key: K, defaults: Messages[K], labels?: Partial<Messages[K]>): Messages[K];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
const LocaleContext = React.createContext({ locale: undefined, messages: {} });
|
|
5
|
+
/**
|
|
6
|
+
* LocaleProvider — the language of every component inside it: the interface text people read
|
|
7
|
+
* and hear ("Previous page", "Copied", "No results") and the locale numbers and dates are
|
|
8
|
+
* formatted in.
|
|
9
|
+
*
|
|
10
|
+
* Wrap the app once. A component's own `labels` prop still wins over the provider, for the one
|
|
11
|
+
* place that needs other words. The rule people break: translating the visible text and leaving
|
|
12
|
+
* the accessible names English — they come from here too, so pass the whole message set.
|
|
13
|
+
*/
|
|
14
|
+
export function LocaleProvider({ locale, messages, children }) {
|
|
15
|
+
const outer = React.useContext(LocaleContext);
|
|
16
|
+
const value = React.useMemo(() => {
|
|
17
|
+
if (!messages)
|
|
18
|
+
return { locale: locale ?? outer.locale, messages: outer.messages };
|
|
19
|
+
const merged = { ...outer.messages };
|
|
20
|
+
for (const [key, entry] of Object.entries(messages))
|
|
21
|
+
merged[key] = { ...merged[key], ...entry };
|
|
22
|
+
return { locale: locale ?? outer.locale, messages: merged };
|
|
23
|
+
}, [locale, messages, outer]);
|
|
24
|
+
return _jsx(LocaleContext.Provider, { value: value, children: children });
|
|
25
|
+
}
|
|
26
|
+
/** The locale set by the nearest LocaleProvider, or undefined for the browser's own. */
|
|
27
|
+
export function useLocale() {
|
|
28
|
+
return React.useContext(LocaleContext).locale;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A component's interface text: its English `defaults`, then what a LocaleProvider sets for it,
|
|
32
|
+
* then the component's own `labels` prop.
|
|
33
|
+
*/
|
|
34
|
+
export function useMessages(key, defaults, labels) {
|
|
35
|
+
const fromProvider = React.useContext(LocaleContext).messages[key];
|
|
36
|
+
return React.useMemo(() => (fromProvider || labels ? { ...defaults, ...fromProvider, ...labels } : defaults), [defaults, fromProvider, labels]);
|
|
37
|
+
}
|
package/dist/components/logo.js
CHANGED
|
@@ -63,7 +63,7 @@ export function LogoRight({ size = 24, ...props }) {
|
|
|
63
63
|
export function Logo({ variant = "default", size = 20, product, open = false, render, ref, className, style, ...props }) {
|
|
64
64
|
const compact = variant === "compact";
|
|
65
65
|
const vars = { "--logo-gap": `${px(size * GAP)}px`, ...style };
|
|
66
|
-
const reveal = "duration-(--duration
|
|
66
|
+
const reveal = "duration-[calc(var(--duration)*1.6)] ease-(--ease) motion-reduce:transition-none";
|
|
67
67
|
const children = (_jsxs(_Fragment, { children: [_jsx(LogoMark, { size: size }), _jsx("span", { "data-slot": "logo-wordmark-track", className: cn("grid", compact
|
|
68
68
|
? [
|
|
69
69
|
"grid-cols-[0fr] transition-[grid-template-columns,padding]",
|
package/dist/components/menu.js
CHANGED
|
@@ -8,6 +8,7 @@ import { mergeRefs } from "../lib/merge-refs.js";
|
|
|
8
8
|
import { formatShortcut, useShortcutKeys } from "../lib/platform.js";
|
|
9
9
|
import { TriggerRoomContext, useTriggerRoom } from "../lib/room.js";
|
|
10
10
|
import { MenuFrame } from "./_overlay.js";
|
|
11
|
+
import { useKeyNames } from "./kbd.js";
|
|
11
12
|
/**
|
|
12
13
|
* Menu — a list of actions opened from a button: "Rename", "Duplicate", "Delete project".
|
|
13
14
|
* Menu material at 12px, items at 7px and 38px tall, the highlighted item raised like `SelectItem`.
|
|
@@ -116,11 +117,12 @@ export function MenuSeparator({ className, ...props }) {
|
|
|
116
117
|
}
|
|
117
118
|
export function MenuShortcut({ keys, className, children, ...props }) {
|
|
118
119
|
const { mod, hasKeyboard } = useShortcutKeys();
|
|
120
|
+
const names = useKeyNames();
|
|
119
121
|
if (keys && !hasKeyboard)
|
|
120
122
|
return null;
|
|
121
123
|
return (_jsx("span", { "data-slot": "menu-shortcut", "aria-hidden": true, className: cn(
|
|
122
124
|
// Its own text decides its direction: ⌘D stays ⌘D in a right-to-left menu.
|
|
123
|
-
"ms-auto ps-4 font-mono text-xs tracking-normal whitespace-nowrap text-muted-foreground [unicode-bidi:plaintext]", className), ...props, children: keys ? formatShortcut(keys, mod) : children }));
|
|
125
|
+
"ms-auto ps-4 font-mono text-xs tracking-normal whitespace-nowrap text-muted-foreground [unicode-bidi:plaintext]", className), ...props, children: keys ? formatShortcut(keys, mod, names) : children }));
|
|
124
126
|
}
|
|
125
127
|
/* ── Submenus ──────────────────────────────────────────────────────────────── */
|
|
126
128
|
/** A nested menu. Holds a `MenuSubTrigger` and a `MenuSubContent`. */
|