@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
|
@@ -8,8 +8,10 @@ import * as React from "react";
|
|
|
8
8
|
import { cn, sx } from "../lib/cn.js";
|
|
9
9
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
10
10
|
import { cssDuration } from "../lib/motion.js";
|
|
11
|
+
import { useMessages } from "./locale.js";
|
|
12
|
+
const defaultMessages = { showPassword: "Show password", clear: "Clear" };
|
|
11
13
|
const groupSizes = {
|
|
12
|
-
sm: "min-h-(--control-h-sm) text-[13px]",
|
|
14
|
+
sm: "min-h-(--control-h-sm) text-[13px] pointer-coarse:text-base",
|
|
13
15
|
default: "min-h-(--control-h) text-base sm:text-[15px]",
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
@@ -97,11 +99,13 @@ const buttonVariants = {
|
|
|
97
99
|
primary: "material-primary",
|
|
98
100
|
};
|
|
99
101
|
const buttonSizes = {
|
|
102
|
+
// `leading-none` after the size: a font size given later would drop it, and a 1.5 line would
|
|
103
|
+
// keep the button from fitting a theme with smaller controls.
|
|
100
104
|
/** 24px — fits the dense group, or a quiet action in the default one. */
|
|
101
|
-
sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs",
|
|
105
|
+
sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs leading-none",
|
|
102
106
|
/** 30px — fits the 38px group with a 3px inset, like a segment. */
|
|
103
|
-
default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px]",
|
|
104
|
-
"icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-
|
|
107
|
+
default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px] leading-none",
|
|
108
|
+
"icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-[min(14px,calc(var(--control-inset-sm)-4px))]",
|
|
105
109
|
icon: "size-(--control-inset) rounded-full p-0",
|
|
106
110
|
};
|
|
107
111
|
/**
|
|
@@ -128,7 +132,10 @@ export function InputGroupButton({ variant = "secondary", size = "default", clas
|
|
|
128
132
|
* a day never means waiting. Only a press of the toggle plays it; reduced motion skips it.
|
|
129
133
|
*/
|
|
130
134
|
let measurer = null;
|
|
131
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Where the field's text runs, in the input's own pixels: from its start padding to its end — the
|
|
137
|
+
* left one, or the right one in a right-to-left field.
|
|
138
|
+
*/
|
|
132
139
|
function textSpan(input) {
|
|
133
140
|
const style = getComputedStyle(input);
|
|
134
141
|
measurer ??= document.createElement("canvas").getContext("2d");
|
|
@@ -139,25 +146,36 @@ function textSpan(input) {
|
|
|
139
146
|
measurer.letterSpacing = style.letterSpacing;
|
|
140
147
|
width = measurer.measureText(text).width;
|
|
141
148
|
}
|
|
149
|
+
const rtl = style.direction === "rtl";
|
|
150
|
+
if (rtl) {
|
|
151
|
+
const right = input.clientWidth - parseFloat(style.paddingRight) - input.scrollLeft;
|
|
152
|
+
return { left: Math.max(0, right - width), right, width: input.clientWidth, rtl };
|
|
153
|
+
}
|
|
142
154
|
const left = parseFloat(style.paddingLeft) - input.scrollLeft;
|
|
143
|
-
return { left, right: Math.min(input.clientWidth, left + width), width: input.clientWidth };
|
|
155
|
+
return { left, right: Math.min(input.clientWidth, left + width), width: input.clientWidth, rtl };
|
|
144
156
|
}
|
|
145
157
|
/**
|
|
146
158
|
* A mask twice the field's width with a soft edge at its middle, slid so the edge travels from
|
|
147
159
|
* just before the text's start to just past its end — or back, to erase it (`out`).
|
|
148
160
|
*/
|
|
149
161
|
function sweepFrames(input, out = false) {
|
|
150
|
-
const { left, right, width } = textSpan(input);
|
|
162
|
+
const { left, right, width, rtl } = textSpan(input);
|
|
151
163
|
const soft = 16;
|
|
152
164
|
const mask = {
|
|
153
|
-
|
|
165
|
+
// Right to left, the shown half is the right one and the edge travels from the text's right.
|
|
166
|
+
maskImage: `linear-gradient(${rtl ? 270 : 90}deg, #000 calc(50% - ${soft}px), transparent calc(50% + ${soft}px))`,
|
|
154
167
|
maskSize: `${width * 2}px 100%`,
|
|
155
168
|
maskRepeat: "no-repeat",
|
|
156
169
|
};
|
|
157
|
-
const frames =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
170
|
+
const frames = rtl
|
|
171
|
+
? [
|
|
172
|
+
{ ...mask, maskPosition: `${right + soft - width}px 0` },
|
|
173
|
+
{ ...mask, maskPosition: `${left - soft - width}px 0` },
|
|
174
|
+
]
|
|
175
|
+
: [
|
|
176
|
+
{ ...mask, maskPosition: `${left - soft - width}px 0` },
|
|
177
|
+
{ ...mask, maskPosition: `${right + soft - width}px 0` },
|
|
178
|
+
];
|
|
161
179
|
return out ? frames.reverse() : frames;
|
|
162
180
|
}
|
|
163
181
|
/** The input this part shares an InputGroup with. */
|
|
@@ -173,6 +191,7 @@ const groupInput = (el) => el
|
|
|
173
191
|
* Switch the input's `type` with `visible`.
|
|
174
192
|
*/
|
|
175
193
|
export function InputGroupPasswordToggle({ visible, onVisibleChange, label, labels, ref, onClick, ...props }) {
|
|
194
|
+
const text = useMessages("inputGroup", defaultMessages);
|
|
176
195
|
const own = React.useRef(null);
|
|
177
196
|
const pressed = React.useRef(false);
|
|
178
197
|
const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
|
|
@@ -185,12 +204,12 @@ export function InputGroupPasswordToggle({ visible, onVisibleChange, label, labe
|
|
|
185
204
|
const input = groupInput(own.current);
|
|
186
205
|
if (!input)
|
|
187
206
|
return;
|
|
188
|
-
const duration = cssDuration(input) * 2
|
|
207
|
+
const duration = cssDuration(input) * 2;
|
|
189
208
|
if (!duration)
|
|
190
209
|
return;
|
|
191
210
|
input.animate(sweepFrames(input), { duration, easing: "cubic-bezier(0.33, 1, 0.68, 1)" });
|
|
192
211
|
}, [visible]);
|
|
193
|
-
return (_jsx(InputGroupButton, { ref: refs, "data-password-toggle": "", variant: "ghost", size: "icon", "aria-label": label ?? labels?.show ??
|
|
212
|
+
return (_jsx(InputGroupButton, { ref: refs, "data-password-toggle": "", variant: "ghost", size: "icon", "aria-label": label ?? labels?.show ?? text.showPassword, "aria-pressed": visible, onClick: (event) => {
|
|
194
213
|
pressed.current = true;
|
|
195
214
|
onVisibleChange(!visible);
|
|
196
215
|
onClick?.(event);
|
|
@@ -213,9 +232,10 @@ function EyeSlashIcon({ slashed }) {
|
|
|
213
232
|
* InputGroupClearButton — empties the field it sits in, smoothly: the text is erased right to
|
|
214
233
|
* left behind a soft edge, as if typed away, then the value clears and focus returns to the
|
|
215
234
|
* field. The button fades out while the field is empty and back in when there is text, instead of
|
|
216
|
-
* popping in and out.
|
|
235
|
+
* popping in and out. The keyboard (Enter, Space) and reduced motion clear at once.
|
|
217
236
|
*/
|
|
218
|
-
export function InputGroupClearButton({ onClear, label
|
|
237
|
+
export function InputGroupClearButton({ onClear, label, ref, className, ...props }) {
|
|
238
|
+
const text = useMessages("inputGroup", defaultMessages);
|
|
219
239
|
const own = React.useRef(null);
|
|
220
240
|
const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
|
|
221
241
|
const [empty, setEmpty] = React.useState(true);
|
|
@@ -247,7 +267,7 @@ export function InputGroupClearButton({ onClear, label = "Clear", ref, className
|
|
|
247
267
|
input.form?.removeEventListener("reset", reset);
|
|
248
268
|
};
|
|
249
269
|
}, []);
|
|
250
|
-
const clear = () => {
|
|
270
|
+
const clear = (event) => {
|
|
251
271
|
const input = groupInput(own.current);
|
|
252
272
|
if (!input || clearing.current)
|
|
253
273
|
return;
|
|
@@ -261,7 +281,9 @@ export function InputGroupClearButton({ onClear, label = "Clear", ref, className
|
|
|
261
281
|
}
|
|
262
282
|
input.focus();
|
|
263
283
|
};
|
|
264
|
-
|
|
284
|
+
// One --duration, and none for Enter or Space (a click with no pointer, detail 0): a keyboard
|
|
285
|
+
// action never waits for an animation.
|
|
286
|
+
const duration = event.detail === 0 ? 0 : cssDuration(input);
|
|
265
287
|
if (!duration || input.value === "") {
|
|
266
288
|
done();
|
|
267
289
|
return;
|
|
@@ -285,7 +307,7 @@ export function InputGroupClearButton({ onClear, label = "Clear", ref, className
|
|
|
285
307
|
release();
|
|
286
308
|
};
|
|
287
309
|
};
|
|
288
|
-
return (_jsx(InputGroupButton, { ref: refs, "data-clear-button": "", "data-empty": empty ? "" : undefined, variant: "ghost", size: "icon", "aria-label": label, "aria-hidden": empty || undefined, tabIndex: empty ? -1 : undefined, onClick: clear, className: cn(
|
|
310
|
+
return (_jsx(InputGroupButton, { ref: refs, "data-clear-button": "", "data-empty": empty ? "" : undefined, variant: "ghost", size: "icon", "aria-label": label ?? text.clear, "aria-hidden": empty || undefined, tabIndex: empty ? -1 : undefined, onClick: clear, className: cn(
|
|
289
311
|
// The fade rides the material's own transition list (--material-motion), which a transition
|
|
290
312
|
// utility would replace.
|
|
291
313
|
"[--material-motion:opacity_var(--duration)_var(--ease),scale_var(--duration)_var(--ease)] data-empty:pointer-events-none data-empty:scale-75 data-empty:opacity-0", className), ...props, children: _jsx(XIcon, {}) }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Input as BaseInput } from "@base-ui/react/input";
|
|
2
2
|
declare const sizes: {
|
|
3
|
-
readonly sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 file:h-
|
|
4
|
-
readonly default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] file:h-(--control-
|
|
3
|
+
readonly sm: "min-h-(--control-h-sm) px-2.5 text-[13px] pointer-coarse:text-base [&[type=file]]:p-0.5 [&[type=file]]:leading-none file:h-(--control-inset-sm)";
|
|
4
|
+
readonly default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] [&[type=file]]:leading-none file:h-(--control-inset)";
|
|
5
5
|
};
|
|
6
6
|
export interface InputProps extends Omit<BaseInput.Props, "size"> {
|
|
7
7
|
/** `sm` (30px) for dense surfaces; `default` (38px) everywhere else. */
|
package/dist/components/input.js
CHANGED
|
@@ -3,8 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { Input as BaseInput } from "@base-ui/react/input";
|
|
4
4
|
import { sx } from "../lib/cn.js";
|
|
5
5
|
const sizes = {
|
|
6
|
-
sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 file:h-
|
|
7
|
-
default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] file:h-(--control-
|
|
6
|
+
sm: "min-h-(--control-h-sm) px-2.5 text-[13px] pointer-coarse:text-base [&[type=file]]:p-0.5 [&[type=file]]:leading-none file:h-(--control-inset-sm)",
|
|
7
|
+
default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] [&[type=file]]:leading-none file:h-(--control-inset)",
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Input — a recessed single-line field. 10px radius, 38px default, 30px dense, full width of
|
|
@@ -17,7 +17,7 @@ export function Input({ size = "default", className, ...props }) {
|
|
|
17
17
|
// A file input's "Choose file" is a small raised button inside the field, inset like an
|
|
18
18
|
// InputGroup button (30px in 38, 24px in 30, 7px corners); the file name stays quiet.
|
|
19
19
|
"[&[type=file]]:cursor-pointer [&[type=file]]:text-muted-foreground",
|
|
20
|
-
"file:
|
|
20
|
+
"file:me-3 file:cursor-pointer file:rounded-item file:border-0 file:bg-control-surface file:bg-linear-to-b file:from-control-inner-edge file:to-transparent file:px-3 file:font-body file:text-[13px] file:font-medium file:text-foreground file:shadow-raised file:hover:bg-control-hover",
|
|
21
21
|
// The search field's clear button (×) is a button: it takes the pointer.
|
|
22
22
|
"[&::-webkit-search-cancel-button]:cursor-pointer",
|
|
23
23
|
sizes[size],
|
package/dist/components/kbd.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
2
|
import { formatShortcut, useShortcutKeys } from "../lib/platform.js";
|
|
3
3
|
export { formatShortcut, useShortcutKeys };
|
|
4
|
+
/**
|
|
5
|
+
* The modifier keys as keyboards other than Apple's print them, which differ by language
|
|
6
|
+
* (German keyboards print "Strg" for Ctrl). Apple keyboards print symbols, the same everywhere.
|
|
7
|
+
*/
|
|
8
|
+
export interface KbdMessages {
|
|
9
|
+
ctrl: string;
|
|
10
|
+
shift: string;
|
|
11
|
+
alt: string;
|
|
12
|
+
enter: string;
|
|
13
|
+
}
|
|
14
|
+
declare module "./locale" {
|
|
15
|
+
interface Messages {
|
|
16
|
+
kbd: KbdMessages;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** The key names a LocaleProvider sets, for `keyNames` and `formatShortcut` of your own. */
|
|
20
|
+
export declare function useKeyNames(): KbdMessages;
|
|
4
21
|
/**
|
|
5
22
|
* The key-cap look as a class string, for elements that must not be a `<kbd>` — e.g. an
|
|
6
23
|
* "Esc" hint that is really a close button: `<button className={kbdClassName}>Esc</button>`.
|
package/dist/components/kbd.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
import { formatShortcut, keyNames, useShortcutKeys } from "../lib/platform.js";
|
|
5
|
+
import { useMessages } from "./locale.js";
|
|
5
6
|
export { formatShortcut, useShortcutKeys };
|
|
7
|
+
const defaultMessages = { ctrl: "Ctrl", shift: "Shift", alt: "Alt", enter: "Enter" };
|
|
8
|
+
/** The key names a LocaleProvider sets, for `keyNames` and `formatShortcut` of your own. */
|
|
9
|
+
export function useKeyNames() {
|
|
10
|
+
return useMessages("kbd", defaultMessages);
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* The key-cap look as a class string, for elements that must not be a `<kbd>` — e.g. an
|
|
8
14
|
* "Esc" hint that is really a close button: `<button className={kbdClassName}>Esc</button>`.
|
|
@@ -32,7 +38,8 @@ export function KbdGroup({ className, ...props }) {
|
|
|
32
38
|
*/
|
|
33
39
|
export function KbdShortcut({ keys, ...props }) {
|
|
34
40
|
const { mod, hasKeyboard } = useShortcutKeys();
|
|
41
|
+
const names = useKeyNames();
|
|
35
42
|
if (!hasKeyboard)
|
|
36
43
|
return null;
|
|
37
|
-
return (_jsx(KbdGroup, { ...props, children: keyNames(keys, mod).map((key, i) => (_jsx(Kbd, { children: key }, i))) }));
|
|
44
|
+
return (_jsx(KbdGroup, { ...props, children: keyNames(keys, mod, names).map((key, i) => (_jsx(Kbd, { children: key }, i))) }));
|
|
38
45
|
}
|
|
@@ -116,7 +116,8 @@ export interface GrainProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Grain — an animated film-grain overlay that fills its positioned parent. It is
|
|
119
|
-
* `aria-hidden`, ignores the pointer and holds still under reduced motion
|
|
119
|
+
* `aria-hidden`, ignores the pointer and holds still under reduced motion, and on a phone or
|
|
120
|
+
* a touch screen: it moves only on a desktop.
|
|
120
121
|
*
|
|
121
122
|
* Use it on dark or large expressive regions to take the digital edge off a flat ground.
|
|
122
123
|
* The rule people break: putting it over small text, where it costs contrast.
|
|
@@ -89,6 +89,8 @@ export function Blueprint({ cell, interactive = true, className, style, children
|
|
|
89
89
|
const ref = useRef(null);
|
|
90
90
|
const enabled = useRef(false);
|
|
91
91
|
const frame = useRef(0);
|
|
92
|
+
/** Where the light is drawn, and where the pointer is: the light eases after it, frame by frame. */
|
|
93
|
+
const light = useRef({ x: 0, y: 0, cx: 0, cy: 0, last: 0, placed: false });
|
|
92
94
|
useEffect(() => {
|
|
93
95
|
if (!interactive || typeof window === "undefined" || !window.matchMedia)
|
|
94
96
|
return;
|
|
@@ -103,25 +105,66 @@ export function Blueprint({ cell, interactive = true, className, style, children
|
|
|
103
105
|
return () => {
|
|
104
106
|
mq.removeEventListener("change", sync);
|
|
105
107
|
cancelAnimationFrame(frame.current);
|
|
108
|
+
frame.current = 0;
|
|
106
109
|
};
|
|
107
110
|
}, [interactive]);
|
|
111
|
+
/**
|
|
112
|
+
* One frame of the light: it closes most of the way to the pointer (by the time since the last
|
|
113
|
+
* frame, so the same at any refresh rate) and keeps going until it is there. Tied to the pointer
|
|
114
|
+
* directly it moved like a cursor; easing after it, it moves like a light.
|
|
115
|
+
*/
|
|
116
|
+
const step = useCallback((now) => {
|
|
117
|
+
const el = ref.current;
|
|
118
|
+
const l = light.current;
|
|
119
|
+
if (!el) {
|
|
120
|
+
frame.current = 0;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// The pointer in the grid's box, read once a frame however many moves there were.
|
|
124
|
+
const r = el.getBoundingClientRect();
|
|
125
|
+
const tx = l.cx - r.left;
|
|
126
|
+
const ty = l.cy - r.top;
|
|
127
|
+
// Coming in, the light starts under the pointer (it fades in there), and eases after it.
|
|
128
|
+
if (!l.placed) {
|
|
129
|
+
l.placed = true;
|
|
130
|
+
l.x = tx;
|
|
131
|
+
l.y = ty;
|
|
132
|
+
}
|
|
133
|
+
const dt = l.last ? Math.min(64, now - l.last) : 16;
|
|
134
|
+
l.last = now;
|
|
135
|
+
const k = 1 - Math.exp(-dt / 70);
|
|
136
|
+
l.x += (tx - l.x) * k;
|
|
137
|
+
l.y += (ty - l.y) * k;
|
|
138
|
+
const done = Math.abs(tx - l.x) < 0.5 && Math.abs(ty - l.y) < 0.5;
|
|
139
|
+
if (done) {
|
|
140
|
+
l.x = tx;
|
|
141
|
+
l.y = ty;
|
|
142
|
+
}
|
|
143
|
+
el.style.setProperty("--mx", `${l.x.toFixed(1)}px`);
|
|
144
|
+
el.style.setProperty("--my", `${l.y.toFixed(1)}px`);
|
|
145
|
+
if (done) {
|
|
146
|
+
frame.current = 0;
|
|
147
|
+
l.last = 0;
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
frame.current = requestAnimationFrame(step);
|
|
151
|
+
}, []);
|
|
108
152
|
const handleMove = useCallback((e) => {
|
|
109
153
|
onPointerMove?.(e);
|
|
110
154
|
const el = ref.current;
|
|
111
155
|
if (!interactive || !enabled.current || !el || e.pointerType !== "mouse")
|
|
112
156
|
return;
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
}, [interactive, onPointerMove]);
|
|
157
|
+
const l = light.current;
|
|
158
|
+
l.cx = e.clientX;
|
|
159
|
+
l.cy = e.clientY;
|
|
160
|
+
el.dataset.lit = "true";
|
|
161
|
+
if (!frame.current)
|
|
162
|
+
frame.current = requestAnimationFrame(step);
|
|
163
|
+
}, [interactive, onPointerMove, step]);
|
|
122
164
|
const handleLeave = useCallback((e) => {
|
|
123
165
|
onPointerLeave?.(e);
|
|
124
|
-
|
|
166
|
+
// The light fades out where it is; the next entry places it afresh.
|
|
167
|
+
light.current.placed = false;
|
|
125
168
|
if (ref.current)
|
|
126
169
|
ref.current.dataset.lit = "false";
|
|
127
170
|
}, [onPointerLeave]);
|
|
@@ -140,7 +183,8 @@ export function DotField({ className, children, ...props }) {
|
|
|
140
183
|
}
|
|
141
184
|
/**
|
|
142
185
|
* Grain — an animated film-grain overlay that fills its positioned parent. It is
|
|
143
|
-
* `aria-hidden`, ignores the pointer and holds still under reduced motion
|
|
186
|
+
* `aria-hidden`, ignores the pointer and holds still under reduced motion, and on a phone or
|
|
187
|
+
* a touch screen: it moves only on a desktop.
|
|
144
188
|
*
|
|
145
189
|
* Use it on dark or large expressive regions to take the digital edge off a flat ground.
|
|
146
190
|
* The rule people break: putting it over small text, where it costs contrast.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface LightboxMessages {
|
|
4
|
+
/** The viewer's accessible name. */
|
|
5
|
+
title: string;
|
|
6
|
+
close: string;
|
|
7
|
+
previous: string;
|
|
8
|
+
next: string;
|
|
9
|
+
zoomIn: string;
|
|
10
|
+
zoomOut: string;
|
|
11
|
+
download: string;
|
|
12
|
+
/** Said while the large image loads. */
|
|
13
|
+
loading: string;
|
|
14
|
+
/** "Image 3 of 12", read out on every change, before the image's alt text. */
|
|
15
|
+
position: (index: number, count: number) => string;
|
|
16
|
+
}
|
|
17
|
+
declare module "./locale" {
|
|
18
|
+
interface Messages {
|
|
19
|
+
lightbox: LightboxMessages;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export interface LightboxImage {
|
|
23
|
+
/** The large image. */
|
|
24
|
+
src: string;
|
|
25
|
+
/** What the image shows — its name in the grid and in the viewer. Required: describe it. */
|
|
26
|
+
alt: string;
|
|
27
|
+
/** A smaller file for the grid; the large one is loaded only when it is opened. */
|
|
28
|
+
thumbnail?: string;
|
|
29
|
+
/** A line or two under the image in the viewer. */
|
|
30
|
+
caption?: React.ReactNode;
|
|
31
|
+
/** The large image's `srcSet` and `sizes`, for screens of every density. */
|
|
32
|
+
srcSet?: string;
|
|
33
|
+
sizes?: string;
|
|
34
|
+
/** What Download saves — another file, the original say. Defaults to `src`. `false` hides it for this image. */
|
|
35
|
+
download?: string | false;
|
|
36
|
+
}
|
|
37
|
+
export interface LightboxProps {
|
|
38
|
+
/** The images, in order. */
|
|
39
|
+
images: LightboxImage[];
|
|
40
|
+
/** The image shown, 0-based. */
|
|
41
|
+
index?: number;
|
|
42
|
+
defaultIndex?: number;
|
|
43
|
+
onIndexChange?: (index: number) => void;
|
|
44
|
+
/** Whether the viewer is open. */
|
|
45
|
+
open?: boolean;
|
|
46
|
+
defaultOpen?: boolean;
|
|
47
|
+
onOpenChange?: (open: boolean) => void;
|
|
48
|
+
/** Next on the last image goes to the first, and back. */
|
|
49
|
+
loop?: boolean;
|
|
50
|
+
/** Show a Download button for each image (an image can opt out with `download: false`). */
|
|
51
|
+
download?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Classes for the large image in the viewer: `invert` for black line art on a transparent
|
|
54
|
+
* ground, `bg-white` under a logo — either would otherwise vanish on the black.
|
|
55
|
+
*/
|
|
56
|
+
imageClassName?: string;
|
|
57
|
+
/** Interface text; a LocaleProvider sets it for every Lightbox. */
|
|
58
|
+
labels?: Partial<LightboxMessages>;
|
|
59
|
+
/** The thumbnails: a `LightboxGrid`, or your own `LightboxTrigger`s. */
|
|
60
|
+
children?: React.ReactNode;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Lightbox — images opened large over the page, one at a time: the photos of a listing, the
|
|
64
|
+
* figures of an article, the attachments of a report.
|
|
65
|
+
*
|
|
66
|
+
* Thumbnails (`LightboxGrid`, or `LightboxTrigger`s around your own) open a full-screen viewer on
|
|
67
|
+
* a black ground in either theme, with a mono "03 / 12" counter, previous and next buttons, the
|
|
68
|
+
* arrow keys and a swipe, zoom by double click or tap, wheel or pinch with a drag to pan, a
|
|
69
|
+
* caption and an optional download. It is a modal Dialog: focus stays inside, Escape closes it,
|
|
70
|
+
* and focus returns to the thumbnail of the image last shown.
|
|
71
|
+
*
|
|
72
|
+
* The rule people break: an empty `alt`. Every image is named, in the grid and in the viewer.
|
|
73
|
+
*/
|
|
74
|
+
export declare function Lightbox({ images, index: indexProp, defaultIndex, onIndexChange, open: openProp, defaultOpen, onOpenChange, loop, download, imageClassName, labels, children, }: LightboxProps): React.JSX.Element;
|
|
75
|
+
export interface LightboxTriggerProps extends BaseButton.Props {
|
|
76
|
+
/** The image it opens, 0-based. */
|
|
77
|
+
index: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Opens the viewer at one image. Put the thumbnail inside, with its `alt`: it names the button.
|
|
81
|
+
* Compose with `render` to draw it as something else.
|
|
82
|
+
*/
|
|
83
|
+
export declare function LightboxTrigger({ index, className, onClick, ref, ...props }: LightboxTriggerProps): React.JSX.Element;
|
|
84
|
+
declare const gridColumns: {
|
|
85
|
+
readonly 2: "grid-cols-2";
|
|
86
|
+
readonly 3: "grid-cols-2 sm:grid-cols-3";
|
|
87
|
+
readonly 4: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4";
|
|
88
|
+
readonly 5: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5";
|
|
89
|
+
readonly 6: "grid-cols-3 sm:grid-cols-4 md:grid-cols-6";
|
|
90
|
+
};
|
|
91
|
+
export interface LightboxGridProps extends React.ComponentProps<"ul"> {
|
|
92
|
+
/** Columns at full width; fewer on a phone. */
|
|
93
|
+
columns?: keyof typeof gridColumns;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The thumbnails of every image as a grid of square buttons, each cropped to fill its square and
|
|
97
|
+
* edged with a `--field-edge` hairline at 12px.
|
|
98
|
+
*/
|
|
99
|
+
export declare function LightboxGrid({ columns, className, ...props }: LightboxGridProps): React.JSX.Element;
|
|
100
|
+
export {};
|