@zonsh/ui 0.2.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -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/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 +9 -0
- package/dist/components/chart.js +40 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +2 -2
- 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 +61 -16
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +14 -4
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +20 -5
- 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 +84 -45
- package/dist/components/illustration.js +1 -1
- package/dist/components/input-group.d.ts +16 -5
- package/dist/components/input-group.js +35 -15
- 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/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -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/message.d.ts +3 -3
- package/dist/components/message.js +10 -7
- 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/number-field.d.ts +21 -2
- package/dist/components/number-field.js +27 -16
- 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 +28 -16
- 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 +14 -3
- package/dist/components/response.js +36 -8
- 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 +34 -18
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +73 -19
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -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 +12 -2
- package/dist/components/table.js +176 -39
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +65 -33
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +15 -7
- package/dist/components/time-field.d.ts +22 -3
- package/dist/components/time-field.js +19 -6
- 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/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +18 -7
- package/dist/components/toolbar.js +6 -1
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.js +17 -4
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +73 -33
- 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/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.js +23 -4
- 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 +20 -5
- package/dist/styles/index.css +3 -2
- package/dist/styles/material.css +7 -3
- package/dist/styles/parts/ai.css +2 -1
- package/dist/styles/parts/controls.css +62 -13
- package/dist/styles/parts/feedback.css +68 -1
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +194 -2
- package/dist/styles/parts/overlays.css +7 -7
- package/dist/styles/tokens.css +12 -3
- 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
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
export interface FileDropMessages {
|
|
3
|
+
/** The first line, for one file or several. */
|
|
4
|
+
title: (multiple: boolean) => string;
|
|
5
|
+
/** The line under it on a device with a keyboard, before the ⌘ V (Ctrl V) keys. */
|
|
6
|
+
clickOrPaste: string;
|
|
7
|
+
/** The line under it on a touch-only device. */
|
|
8
|
+
tap: string;
|
|
9
|
+
/** What screen readers hear about the zone when there is no `hint`. */
|
|
10
|
+
hint: (multiple: boolean) => string;
|
|
11
|
+
/** FileDropItem's remove button. */
|
|
12
|
+
remove: (fileName: string) => string;
|
|
13
|
+
}
|
|
14
|
+
declare module "./locale" {
|
|
15
|
+
interface Messages {
|
|
16
|
+
fileDrop: FileDropMessages;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
2
19
|
/** A file that was not taken, and why. */
|
|
3
20
|
export interface FileDropRejection {
|
|
4
21
|
file: File;
|
|
@@ -24,6 +41,8 @@ export interface FileDropProps extends Omit<React.ComponentProps<"div">, "onDrop
|
|
|
24
41
|
hint?: React.ReactNode;
|
|
25
42
|
/** Replace the content of the zone entirely. */
|
|
26
43
|
children?: React.ReactNode;
|
|
44
|
+
/** The default words; a LocaleProvider sets them for every FileDrop. */
|
|
45
|
+
labels?: Partial<FileDropMessages>;
|
|
27
46
|
}
|
|
28
47
|
/**
|
|
29
48
|
* FileDrop — a place to add files, three ways: drop one or more on it, click it (or press Enter or
|
|
@@ -36,15 +55,18 @@ export interface FileDropProps extends Omit<React.ComponentProps<"div">, "onDrop
|
|
|
36
55
|
* The rule people break: a zone that only takes drops. Dragging needs a mouse and a file manager
|
|
37
56
|
* beside the page; clicking and pasting are how most people add a file.
|
|
38
57
|
*/
|
|
39
|
-
export declare function FileDrop({ onFiles, onReject, accept, multiple, maxSize, disabled, title, description, hint, children, className, onKeyDown, onClick, onDragEnter, onDragOver, onDragLeave, onPointerEnter, onPointerLeave, ...props }: FileDropProps): React.JSX.Element;
|
|
40
|
-
/**
|
|
41
|
-
|
|
58
|
+
export declare function FileDrop({ onFiles, onReject, accept, multiple, maxSize, disabled, title, description, hint, children, className, onKeyDown, onClick, onDragEnter, onDragOver, onDragLeave, onPointerEnter, onPointerLeave, onFocus, onBlur, id, ref, labels, ...props }: FileDropProps): React.JSX.Element;
|
|
59
|
+
/**
|
|
60
|
+
* A size in bytes, as people read it: 840 B, 12 KB, 3.4 MB — the number written for `locale`
|
|
61
|
+
* (3,4 MB in German), or for the browser's language without one.
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatFileSize(bytes: number, locale?: string): string;
|
|
42
64
|
export interface FileDropItemProps extends Omit<React.ComponentProps<"div">, "children"> {
|
|
43
65
|
/** The file. Images show a thumbnail; other files an icon. */
|
|
44
66
|
file: File;
|
|
45
67
|
/** Shows a remove button. */
|
|
46
68
|
onRemove?: () => void;
|
|
47
|
-
/** Accessible name of the remove button. Default `Remove <file name
|
|
69
|
+
/** Accessible name of the remove button. Default `Remove <file name>` (`messages.fileDrop.remove`). */
|
|
48
70
|
removeLabel?: string;
|
|
49
71
|
}
|
|
50
72
|
/**
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Field as BaseField } from "@base-ui/react/field";
|
|
3
4
|
import { FileIcon, UploadIcon, XIcon } from "lucide-react";
|
|
4
5
|
import * as React from "react";
|
|
5
6
|
import { cn } from "../lib/cn.js";
|
|
6
|
-
import {
|
|
7
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { keyNames, useShortcutKeys } from "../lib/platform.js";
|
|
7
9
|
import { Button } from "./button.js";
|
|
8
10
|
import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "./item.js";
|
|
9
|
-
import { Kbd, KbdGroup } from "./kbd.js";
|
|
11
|
+
import { Kbd, KbdGroup, useKeyNames } from "./kbd.js";
|
|
12
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
13
|
+
const defaultMessages = {
|
|
14
|
+
title: (multiple) => (multiple ? "Drop files here" : "Drop a file here"),
|
|
15
|
+
clickOrPaste: "or click to choose — paste with",
|
|
16
|
+
tap: "or tap to choose",
|
|
17
|
+
hint: (multiple) => `Drop, choose or paste ${multiple ? "files" : "a file"}`,
|
|
18
|
+
remove: (fileName) => `Remove ${fileName}`,
|
|
19
|
+
};
|
|
10
20
|
/** Does `file` match an `accept` list: extensions (`.pdf`), types (`image/png`) and families (`image/*`)? */
|
|
11
21
|
function accepts(file, accept) {
|
|
12
22
|
if (!accept?.trim())
|
|
@@ -47,15 +57,22 @@ const takesText = (el) => !!el &&
|
|
|
47
57
|
* The rule people break: a zone that only takes drops. Dragging needs a mouse and a file manager
|
|
48
58
|
* beside the page; clicking and pasting are how most people add a file.
|
|
49
59
|
*/
|
|
50
|
-
export function FileDrop({ onFiles, onReject, accept, multiple = true, maxSize, disabled = false, title, description, hint, children, className, onKeyDown, onClick, onDragEnter, onDragOver, onDragLeave, onPointerEnter, onPointerLeave, ...props }) {
|
|
60
|
+
export function FileDrop({ onFiles, onReject, accept, multiple = true, maxSize, disabled = false, title, description, hint, children, className, onKeyDown, onClick, onDragEnter, onDragOver, onDragLeave, onPointerEnter, onPointerLeave, onFocus, onBlur, id, ref, labels, ...props }) {
|
|
61
|
+
const text = useMessages("fileDrop", defaultMessages, labels);
|
|
51
62
|
const zone = React.useRef(null);
|
|
63
|
+
const zoneRefs = React.useMemo(() => mergeRefs(zone, ref), [ref]);
|
|
52
64
|
const input = React.useRef(null);
|
|
53
65
|
const hovered = React.useRef(false);
|
|
54
66
|
const [dragging, setDragging] = React.useState(false);
|
|
55
67
|
const hintId = React.useId();
|
|
68
|
+
const contentId = React.useId();
|
|
69
|
+
// A hint of your own is drawn under the default contents; the default one is only read.
|
|
70
|
+
const hintShown = children == null && hint != null;
|
|
71
|
+
// Disabled by the prop or by a disabled Field, which Base UI sets on the Field's input.
|
|
72
|
+
const locked = React.useRef(disabled);
|
|
56
73
|
// One check for drops, the picker and pastes.
|
|
57
74
|
const take = React.useCallback((files) => {
|
|
58
|
-
if (
|
|
75
|
+
if (locked.current || !files.length)
|
|
59
76
|
return;
|
|
60
77
|
const taken = [];
|
|
61
78
|
const rejected = [];
|
|
@@ -96,83 +113,125 @@ export function FileDrop({ onFiles, onReject, accept, multiple = true, maxSize,
|
|
|
96
113
|
return () => document.removeEventListener("paste", paste);
|
|
97
114
|
}, [disabled, take]);
|
|
98
115
|
const open = () => {
|
|
99
|
-
if (!
|
|
116
|
+
if (!locked.current)
|
|
100
117
|
input.current?.click();
|
|
101
118
|
};
|
|
102
119
|
const hasFiles = (event) => event.dataTransfer.types.includes("Files");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
120
|
+
/*
|
|
121
|
+
* Inside a Field, the zone is its control: the label names it, the description and the error
|
|
122
|
+
* describe it, and an invalid Field marks it. The Field's own input, out of sight and without a
|
|
123
|
+
* name (the files are yours to send), stands in for it in validation: a Form that focuses it, to
|
|
124
|
+
* show an error, has it hand focus on to the zone.
|
|
125
|
+
*/
|
|
126
|
+
return (_jsx(BaseField.Control, { id: id, value: "", disabled: disabled, render: (control) => {
|
|
127
|
+
const { ref: fieldRef, id: controlId, name: _name, value: _value, disabled: fieldDisabled, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, onKeyDown: _onKeyDown, className: _className, defaultValue: _defaultValue, autoFocus: _autoFocus, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, ...state } = control;
|
|
128
|
+
const off = !!fieldDisabled;
|
|
129
|
+
locked.current = off;
|
|
130
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...state, ref: zoneRefs, id: controlId, role: "button", tabIndex: off ? -1 : 0, "aria-disabled": off || undefined, "aria-labelledby": [
|
|
131
|
+
props["aria-label"] ? controlId : null,
|
|
132
|
+
labelledBy,
|
|
133
|
+
contentId,
|
|
134
|
+
hintShown ? hintId : null,
|
|
135
|
+
]
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.join(" "), "aria-describedby": [describedBy, hintShown ? null : hintId].filter(Boolean).join(" ") || undefined, "aria-invalid": invalid, "data-slot": "file-drop", "data-dragging": dragging ? "" : undefined, "data-disabled": off ? "" : undefined, className: cn("group/file-drop relative flex min-h-40 w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-control border border-dashed border-field-edge bg-field-surface px-6 py-8 text-center shadow-field focus-ring outline-none select-none", "transition-[background-color,border-color,box-shadow] duration-(--duration) ease-(--ease)", "hover:border-muted-foreground data-dragging:border-control-focus data-dragging:bg-control-hover",
|
|
138
|
+
// A contrast theme keeps neither colour: there, the edge turns solid while files are over it.
|
|
139
|
+
"forced-colors:data-dragging:border-solid",
|
|
140
|
+
// Invalid, it takes the red edge and soft ring of an invalid field.
|
|
141
|
+
"data-invalid:border-destructive data-invalid:shadow-invalid", "data-disabled:pointer-events-none data-disabled:opacity-55", className), onFocus: (event) => {
|
|
142
|
+
onFocus?.(event);
|
|
143
|
+
fieldFocus?.(event);
|
|
144
|
+
}, onBlur: (event) => {
|
|
145
|
+
onBlur?.(event);
|
|
146
|
+
// Focus leaving the zone (not moving to a button inside it) is a blur for the Field.
|
|
147
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
148
|
+
return;
|
|
149
|
+
fieldBlur?.(event);
|
|
150
|
+
}, onClick: (event) => {
|
|
151
|
+
onClick?.(event);
|
|
152
|
+
// Clicks on the zone's own controls (a remove button inside custom children) stay theirs.
|
|
153
|
+
if (event.defaultPrevented || event.target.closest("button, a, input"))
|
|
154
|
+
return;
|
|
155
|
+
open();
|
|
156
|
+
}, onKeyDown: (event) => {
|
|
157
|
+
onKeyDown?.(event);
|
|
158
|
+
if (event.defaultPrevented || event.target !== event.currentTarget)
|
|
159
|
+
return;
|
|
160
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
open();
|
|
163
|
+
}
|
|
164
|
+
}, onDragEnter: (event) => {
|
|
165
|
+
onDragEnter?.(event);
|
|
166
|
+
if (off || !hasFiles(event))
|
|
167
|
+
return;
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
setDragging(true);
|
|
170
|
+
}, onDragOver: (event) => {
|
|
171
|
+
onDragOver?.(event);
|
|
172
|
+
if (off || !hasFiles(event))
|
|
173
|
+
return;
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
event.dataTransfer.dropEffect = "copy";
|
|
176
|
+
setDragging(true);
|
|
177
|
+
}, onDragLeave: (event) => {
|
|
178
|
+
onDragLeave?.(event);
|
|
179
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
180
|
+
setDragging(false);
|
|
181
|
+
}, onDrop: (event) => {
|
|
182
|
+
setDragging(false);
|
|
183
|
+
if (off || !hasFiles(event))
|
|
184
|
+
return;
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
take(filesOf(event.dataTransfer));
|
|
187
|
+
}, onPointerEnter: (event) => {
|
|
188
|
+
onPointerEnter?.(event);
|
|
189
|
+
hovered.current = true;
|
|
190
|
+
}, onPointerLeave: (event) => {
|
|
191
|
+
onPointerLeave?.(event);
|
|
192
|
+
hovered.current = false;
|
|
193
|
+
}, ...props, children: [_jsx("input", { ref: input, type: "file", hidden: true, tabIndex: -1, accept: accept, multiple: multiple, disabled: off, "data-slot": "file-drop-input", onChange: (event) => {
|
|
194
|
+
take([...(event.currentTarget.files ?? [])]);
|
|
195
|
+
// Reset, so the same file can be chosen again.
|
|
196
|
+
event.currentTarget.value = "";
|
|
197
|
+
} }), _jsx("span", { id: contentId, "data-slot": "file-drop-content", className: "contents", children: children ?? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, "data-slot": "file-drop-icon", className: "mb-3 inline-flex size-(--control-h-lg) items-center justify-center rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent text-foreground shadow-raised transition-[translate] duration-(--duration) ease-(--ease) group-data-dragging/file-drop:-translate-y-0.5 [&_svg]:size-5", children: _jsx(UploadIcon, {}) }), _jsx("span", { "data-slot": "file-drop-title", className: "text-sm font-medium text-foreground", children: title ?? text.title(multiple) }), " ", _jsx("span", { "data-slot": "file-drop-description", className: "text-[13px] text-muted-foreground", children: description ?? _jsx(DefaultDescription, { text: text }) })] })) }), " ", _jsx("span", { id: hintId, "data-slot": "file-drop-hint", className: cn("mt-2 font-mono text-[11px] text-muted-foreground", !hintShown && "sr-only"), children: hint ?? text.hint(multiple) })] }), _jsx("input", { ref: fieldRef, value: "", onChange: fieldChange, disabled: off, "aria-hidden": true, tabIndex: -1, autoComplete: "off", onFocus: () => zone.current?.focus(), className: "sr-only" })] }));
|
|
198
|
+
} }));
|
|
153
199
|
}
|
|
154
200
|
/**
|
|
155
201
|
* How else to add files: click to choose, or paste with the device's own keys (⌘ V on Apple,
|
|
156
202
|
* Ctrl V elsewhere). A touch-only phone or tablet has no keys to press, so it only says tap.
|
|
157
203
|
*/
|
|
158
|
-
function DefaultDescription() {
|
|
204
|
+
function DefaultDescription({ text }) {
|
|
159
205
|
const { mod, hasKeyboard } = useShortcutKeys();
|
|
206
|
+
const names = useKeyNames();
|
|
160
207
|
if (!hasKeyboard)
|
|
161
|
-
return
|
|
162
|
-
return (_jsxs(_Fragment, { children: [
|
|
208
|
+
return text.tap;
|
|
209
|
+
return (_jsxs(_Fragment, { children: [text.clickOrPaste, " ", _jsxs(KbdGroup, { className: "align-middle", children: [_jsx(Kbd, { children: keyNames(["mod"], mod, names)[0] }), _jsx(Kbd, { children: "V" })] })] }));
|
|
163
210
|
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
211
|
+
/**
|
|
212
|
+
* A size in bytes, as people read it: 840 B, 12 KB, 3.4 MB — the number written for `locale`
|
|
213
|
+
* (3,4 MB in German), or for the browser's language without one.
|
|
214
|
+
*/
|
|
215
|
+
export function formatFileSize(bytes, locale) {
|
|
216
|
+
const number = (n, digits) => new Intl.NumberFormat(locale, {
|
|
217
|
+
minimumFractionDigits: digits,
|
|
218
|
+
maximumFractionDigits: digits,
|
|
219
|
+
useGrouping: false,
|
|
220
|
+
}).format(n);
|
|
166
221
|
if (bytes < 1024)
|
|
167
|
-
return `${bytes} B`;
|
|
222
|
+
return `${number(bytes, 0)} B`;
|
|
168
223
|
const units = ["KB", "MB", "GB"];
|
|
224
|
+
// One decimal under 10, whole numbers above; 9.96 KB reads "10 KB", not "10.0 KB".
|
|
225
|
+
const shown = (n) => (n < 9.95 ? n.toFixed(1) : String(Math.round(n)));
|
|
169
226
|
let size = bytes / 1024;
|
|
170
227
|
let unit = 0;
|
|
171
|
-
|
|
228
|
+
// Decided on the number shown, so 1023.7 KB moves on to "1.0 MB" rather than reading "1024 KB".
|
|
229
|
+
while (Number(shown(size)) >= 1024 && unit < units.length - 1) {
|
|
172
230
|
size /= 1024;
|
|
173
231
|
unit++;
|
|
174
232
|
}
|
|
175
|
-
|
|
233
|
+
// The same thresholds as `shown`, written in the locale's digits and decimal sign.
|
|
234
|
+
return `${size < 9.95 ? number(size, 1) : number(Math.round(size), 0)} ${units[unit]}`;
|
|
176
235
|
}
|
|
177
236
|
/** An object URL for an image file while it is shown, revoked after. */
|
|
178
237
|
function usePreview(file) {
|
|
@@ -193,5 +252,7 @@ function usePreview(file) {
|
|
|
193
252
|
*/
|
|
194
253
|
export function FileDropItem({ file, onRemove, removeLabel, className, ...props }) {
|
|
195
254
|
const preview = usePreview(file);
|
|
196
|
-
|
|
255
|
+
const text = useMessages("fileDrop", defaultMessages);
|
|
256
|
+
const locale = useLocale();
|
|
257
|
+
return (_jsxs(Item, { variant: "outline", size: "sm", "data-slot": "file-drop-item", className: className, ...props, children: [preview ? (_jsx(ItemMedia, { variant: "image", children: _jsx("img", { src: preview, alt: "" }) })) : (_jsx(ItemMedia, { variant: "image", className: "grid place-items-center bg-control-surface text-muted-foreground", children: _jsx(FileIcon, { className: "size-4" }) })), _jsxs(ItemContent, { className: "min-w-0", children: [_jsx(ItemTitle, { className: "block max-w-full truncate", title: file.name, children: file.name }), _jsx(ItemDescription, { className: "font-mono text-[11px] tabular-nums", children: formatFileSize(file.size, locale) })] }), onRemove && (_jsx(ItemActions, { children: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": removeLabel ?? text.remove(file.name), onClick: onRemove, children: _jsx(XIcon, {}) }) }))] }));
|
|
197
258
|
}
|
|
@@ -70,6 +70,48 @@ export interface Filter {
|
|
|
70
70
|
operator: FilterOperator;
|
|
71
71
|
value: FilterValue;
|
|
72
72
|
}
|
|
73
|
+
export interface FilterBarMessages {
|
|
74
|
+
/** The bar's group name. */
|
|
75
|
+
group: string;
|
|
76
|
+
/** The add button. */
|
|
77
|
+
add: string;
|
|
78
|
+
clearAll: string;
|
|
79
|
+
/** A chip's group name, by its field's label. */
|
|
80
|
+
chip: (field: string) => string;
|
|
81
|
+
/** A chip's × button. */
|
|
82
|
+
remove: (field: string) => string;
|
|
83
|
+
/** The operator select in a chip's editor. */
|
|
84
|
+
condition: (field: string) => string;
|
|
85
|
+
/** The search field over a long list of options: its placeholder and its name. */
|
|
86
|
+
searchPlaceholder: (field: string) => string;
|
|
87
|
+
search: (field: string) => string;
|
|
88
|
+
/** Shown when the search matches no option. */
|
|
89
|
+
noMatch: (field: string) => string;
|
|
90
|
+
/** A text field's placeholder, when the field gives none. */
|
|
91
|
+
textPlaceholder: (field: string) => string;
|
|
92
|
+
/** Typed text as the chip shows it, in quotation marks. */
|
|
93
|
+
quote: (text: string) => string;
|
|
94
|
+
/** A date range open at its end, or its start: "from 1 Oct", "until 15 Oct". */
|
|
95
|
+
from: string;
|
|
96
|
+
until: string;
|
|
97
|
+
/** The operators, in the condition select — and, for options and text, on the chip. */
|
|
98
|
+
is: string;
|
|
99
|
+
isNot: string;
|
|
100
|
+
contains: string;
|
|
101
|
+
doesNotContain: string;
|
|
102
|
+
gte: string;
|
|
103
|
+
lte: string;
|
|
104
|
+
gt: string;
|
|
105
|
+
lt: string;
|
|
106
|
+
eq: string;
|
|
107
|
+
neq: string;
|
|
108
|
+
between: string;
|
|
109
|
+
}
|
|
110
|
+
declare module "./locale" {
|
|
111
|
+
interface Messages {
|
|
112
|
+
filterBar: FilterBarMessages;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
73
115
|
/**
|
|
74
116
|
* Whether a row passes every filter — for filtering on the client:
|
|
75
117
|
* `rows.filter((row) => matchesFilters(row, filters, fields))`. Filters without a value yet, and
|
|
@@ -88,10 +130,15 @@ export interface FilterBarProps extends Omit<React.ComponentProps<"div">, "defau
|
|
|
88
130
|
onValueChange?: (value: Filter[]) => void;
|
|
89
131
|
/** `sm` (default) 30px chips for toolbars above tables; `default` 38px. */
|
|
90
132
|
size?: "sm" | "default";
|
|
91
|
-
/** The locale for dates and numbers on the chips. Defaults to the browser's. */
|
|
133
|
+
/** The locale for dates and numbers on the chips. Defaults to the LocaleProvider's, else the browser's. */
|
|
92
134
|
locale?: string;
|
|
93
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* The add button's label. Defaults to "Filter".
|
|
137
|
+
* @deprecated Use `labels.add`.
|
|
138
|
+
*/
|
|
94
139
|
addLabel?: string;
|
|
140
|
+
/** The bar's words; a LocaleProvider sets them for every FilterBar. */
|
|
141
|
+
labels?: Partial<FilterBarMessages>;
|
|
95
142
|
}
|
|
96
143
|
/**
|
|
97
144
|
* FilterBar — faceted filters above a list or a table: each applied filter is a raised chip
|
|
@@ -102,5 +149,5 @@ export interface FilterBarProps extends Omit<React.ComponentProps<"div">, "defau
|
|
|
102
149
|
* value to a server. The rule people break: a filter bar for one or two fixed choices — that is a
|
|
103
150
|
* `ToggleGroup` or a `Select` beside the table, always visible.
|
|
104
151
|
*/
|
|
105
|
-
export declare function FilterBar({ fields, value: valueProp, defaultValue, onValueChange, size, locale, addLabel, className, ...props }: FilterBarProps): React.JSX.Element;
|
|
152
|
+
export declare function FilterBar({ fields, value: valueProp, defaultValue, onValueChange, size, locale: localeProp, addLabel, labels, className, ...props }: FilterBarProps): React.JSX.Element;
|
|
106
153
|
export {};
|
|
@@ -9,29 +9,60 @@ import { ButtonGroup } from "./button-group.js";
|
|
|
9
9
|
import { Calendar } from "./calendar.js";
|
|
10
10
|
import { ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "./combobox.js";
|
|
11
11
|
import { Input } from "./input.js";
|
|
12
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
12
13
|
import { Menu, MenuContent, MenuItem, MenuTrigger } from "./menu.js";
|
|
13
14
|
import { NumberField } from "./number-field.js";
|
|
14
15
|
import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from "./popover.js";
|
|
15
16
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
17
|
+
const defaultMessages = {
|
|
18
|
+
group: "Filters",
|
|
19
|
+
add: "Filter",
|
|
20
|
+
clearAll: "Clear all",
|
|
21
|
+
chip: (field) => `${field} filter`,
|
|
22
|
+
remove: (field) => `Remove ${field} filter`,
|
|
23
|
+
condition: (field) => `${field}: condition`,
|
|
24
|
+
searchPlaceholder: (field) => `Search ${field.toLowerCase()}…`,
|
|
25
|
+
search: (field) => `Search ${field.toLowerCase()}`,
|
|
26
|
+
noMatch: (field) => `No ${field.toLowerCase()} matches.`,
|
|
27
|
+
textPlaceholder: (field) => `${field}…`,
|
|
28
|
+
quote: (text) => `“${text}”`,
|
|
29
|
+
from: "from",
|
|
30
|
+
until: "until",
|
|
31
|
+
is: "is",
|
|
32
|
+
isNot: "is not",
|
|
33
|
+
contains: "contains",
|
|
34
|
+
doesNotContain: "does not contain",
|
|
35
|
+
gte: "at least",
|
|
36
|
+
lte: "at most",
|
|
37
|
+
gt: "more than",
|
|
38
|
+
lt: "less than",
|
|
39
|
+
eq: "is",
|
|
40
|
+
neq: "is not",
|
|
41
|
+
between: "between",
|
|
42
|
+
};
|
|
16
43
|
/* ── Matching ──────────────────────────────────────────────────────────────── */
|
|
44
|
+
/**
|
|
45
|
+
* Each kind's operators, by the message that names them. A number's chip shows its `symbol`;
|
|
46
|
+
* the others show their name.
|
|
47
|
+
*/
|
|
17
48
|
const operators = {
|
|
18
49
|
select: [
|
|
19
|
-
{ value: "is",
|
|
20
|
-
{ value: "is-not",
|
|
50
|
+
{ value: "is", key: "is" },
|
|
51
|
+
{ value: "is-not", key: "isNot" },
|
|
21
52
|
],
|
|
22
53
|
text: [
|
|
23
|
-
{ value: "contains",
|
|
24
|
-
{ value: "does-not-contain",
|
|
54
|
+
{ value: "contains", key: "contains" },
|
|
55
|
+
{ value: "does-not-contain", key: "doesNotContain" },
|
|
25
56
|
],
|
|
26
57
|
number: [
|
|
27
|
-
{ value: "gte",
|
|
28
|
-
{ value: "lte",
|
|
29
|
-
{ value: "gt",
|
|
30
|
-
{ value: "lt",
|
|
31
|
-
{ value: "eq",
|
|
32
|
-
{ value: "neq",
|
|
58
|
+
{ value: "gte", key: "gte", symbol: "≥" },
|
|
59
|
+
{ value: "lte", key: "lte", symbol: "≤" },
|
|
60
|
+
{ value: "gt", key: "gt", symbol: ">" },
|
|
61
|
+
{ value: "lt", key: "lt", symbol: "<" },
|
|
62
|
+
{ value: "eq", key: "eq", symbol: "=" },
|
|
63
|
+
{ value: "neq", key: "neq", symbol: "≠" },
|
|
33
64
|
],
|
|
34
|
-
date: [{ value: "between",
|
|
65
|
+
date: [{ value: "between", key: "between", symbol: "" }],
|
|
35
66
|
};
|
|
36
67
|
function emptyValue(kind) {
|
|
37
68
|
return kind === "select" ? [] : kind === "text" ? "" : kind === "number" ? null : {};
|
|
@@ -138,10 +169,11 @@ function formatDay(iso, locale) {
|
|
|
138
169
|
return new Intl.DateTimeFormat(locale, { day: "numeric", month: "short", year: "numeric" }).format(new Date(y, m - 1, d));
|
|
139
170
|
}
|
|
140
171
|
/** What the chip says after the field's name: the operator and the value, or null while empty. */
|
|
141
|
-
function describe(filter, field, locale) {
|
|
172
|
+
function describe(filter, field, text, locale) {
|
|
142
173
|
if (isEmpty(filter))
|
|
143
174
|
return null;
|
|
144
|
-
const
|
|
175
|
+
const entry = operators[field.kind].find((o) => o.value === filter.operator);
|
|
176
|
+
const op = entry && { symbol: entry.symbol ?? text[entry.key] };
|
|
145
177
|
switch (field.kind) {
|
|
146
178
|
case "select": {
|
|
147
179
|
// In the options' order, not the order they were picked in; a value no option has (from a
|
|
@@ -153,37 +185,37 @@ function describe(filter, field, locale) {
|
|
|
153
185
|
...[...picked].filter((v) => !known.has(v)).map(String),
|
|
154
186
|
];
|
|
155
187
|
const shown = labels.length > 2 ? `${labels.slice(0, 2).join(", ")} +${labels.length - 2}` : labels.join(", ");
|
|
156
|
-
return [op?.symbol ??
|
|
188
|
+
return [op?.symbol ?? text.is, shown];
|
|
157
189
|
}
|
|
158
190
|
case "text":
|
|
159
|
-
return [op?.symbol ??
|
|
191
|
+
return [op?.symbol ?? text.contains, text.quote(filter.value.trim())];
|
|
160
192
|
case "number":
|
|
161
193
|
return [op?.symbol ?? "=", new Intl.NumberFormat(locale, field.format).format(filter.value)];
|
|
162
194
|
case "date": {
|
|
163
195
|
const { from, to } = rangeOf(filter.value);
|
|
164
196
|
if (from && to)
|
|
165
197
|
return ["", `${formatDay(from, locale)} – ${formatDay(to, locale)}`];
|
|
166
|
-
return from ? [
|
|
198
|
+
return from ? [text.from, formatDay(from, locale)] : [text.until, formatDay(to, locale)];
|
|
167
199
|
}
|
|
168
200
|
}
|
|
169
201
|
}
|
|
170
|
-
function OperatorSelect({ field, filter, onChange }) {
|
|
202
|
+
function OperatorSelect({ field, filter, onChange, text }) {
|
|
171
203
|
const ops = operators[field.kind];
|
|
172
204
|
if (ops.length < 2)
|
|
173
205
|
return null;
|
|
174
|
-
return (_jsxs(Select, { value: filter.operator, onValueChange: (operator) => operator && onChange({ ...filter, operator: operator }), items: ops.map((o) => ({ value: o.value, label: o.
|
|
206
|
+
return (_jsxs(Select, { value: filter.operator, onValueChange: (operator) => operator && onChange({ ...filter, operator: operator }), items: ops.map((o) => ({ value: o.value, label: text[o.key] })), children: [_jsx(SelectTrigger, { size: "sm", "aria-label": text.condition(field.label), className: "w-auto min-w-0 gap-1.5", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: ops.map((o) => (_jsx(SelectItem, { value: o.value, children: text[o.key] }, o.value))) })] }));
|
|
175
207
|
}
|
|
176
208
|
/** The options as an inline Combobox: a search field over them when the list is long, checks for the picked. */
|
|
177
|
-
function SelectEditor({ field, filter, onChange }) {
|
|
209
|
+
function SelectEditor({ field, filter, onChange, text }) {
|
|
178
210
|
const searchable = field.searchable ?? field.options.length >= 8;
|
|
179
211
|
const byValue = React.useMemo(() => new Map(field.options.map((o) => [o.value, o])), [field.options]);
|
|
180
|
-
return (_jsxs(BaseCombobox.Root, { inline: true, open: true, multiple: true, items: field.options.map((o) => o.value), value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), itemToStringLabel: (value) => byValue.get(value)?.label ?? value, autoHighlight: true, children: [searchable ? (_jsx(ComboboxInput, { size: "sm", showTrigger: false, placeholder:
|
|
212
|
+
return (_jsxs(BaseCombobox.Root, { inline: true, open: true, multiple: true, items: field.options.map((o) => o.value), value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), itemToStringLabel: (value) => byValue.get(value)?.label ?? value, autoHighlight: true, children: [searchable ? (_jsx(ComboboxInput, { size: "sm", showTrigger: false, placeholder: text.searchPlaceholder(field.label), "aria-label": text.search(field.label) })) : (_jsx(BaseCombobox.Input, { "data-slot": "filter-bar-list-focus", "aria-label": field.label, className: "sr-only", readOnly: true })), _jsx(ComboboxEmpty, { children: text.noMatch(field.label) }), _jsx(ComboboxList, { children: (value) => {
|
|
181
213
|
const option = byValue.get(value);
|
|
182
214
|
return (_jsx(ComboboxItem, { value: value, children: _jsxs("span", { className: "flex items-center gap-2.5 [&_svg]:size-4 [&_svg]:text-muted-foreground", children: [option.icon, option.label] }) }, value));
|
|
183
215
|
} })] }));
|
|
184
216
|
}
|
|
185
|
-
function TextEditor({ field, filter, onChange, onDone }) {
|
|
186
|
-
return (_jsx(Input, { size: "sm", value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), onKeyDown: (event) => event.key === "Enter" && onDone(), placeholder: field.placeholder ??
|
|
217
|
+
function TextEditor({ field, filter, onChange, onDone, text }) {
|
|
218
|
+
return (_jsx(Input, { size: "sm", value: filter.value, onValueChange: (value) => onChange({ ...filter, value }), onKeyDown: (event) => event.key === "Enter" && onDone(), placeholder: field.placeholder ?? text.textPlaceholder(field.label), "aria-label": field.label }));
|
|
187
219
|
}
|
|
188
220
|
function NumberEditor({ field, filter, onChange, onDone }) {
|
|
189
221
|
// NumberField puts its `id` on the input; a hidden label names it (the popover's title shows it).
|
|
@@ -224,7 +256,10 @@ function Editor(props) {
|
|
|
224
256
|
* value to a server. The rule people break: a filter bar for one or two fixed choices — that is a
|
|
225
257
|
* `ToggleGroup` or a `Select` beside the table, always visible.
|
|
226
258
|
*/
|
|
227
|
-
export function FilterBar({ fields, value: valueProp, defaultValue = [], onValueChange, size = "sm", locale, addLabel
|
|
259
|
+
export function FilterBar({ fields, value: valueProp, defaultValue = [], onValueChange, size = "sm", locale: localeProp, addLabel, labels, className, ...props }) {
|
|
260
|
+
const messages = useMessages("filterBar", defaultMessages, labels);
|
|
261
|
+
const providedLocale = useLocale();
|
|
262
|
+
const locale = localeProp ?? providedLocale;
|
|
228
263
|
const [inner, setInner] = React.useState(defaultValue);
|
|
229
264
|
const value = valueProp ?? inner;
|
|
230
265
|
const setValue = (next) => {
|
|
@@ -235,6 +270,9 @@ export function FilterBar({ fields, value: valueProp, defaultValue = [], onValue
|
|
|
235
270
|
const [open, setOpen] = React.useState(null);
|
|
236
271
|
const pending = React.useRef(null);
|
|
237
272
|
const addRef = React.useRef(null);
|
|
273
|
+
// Scopes each chip's editor to this bar: two bars on a page may each filter a field of one id.
|
|
274
|
+
const uid = React.useId();
|
|
275
|
+
const editorKey = (field) => `${uid}:${field}`;
|
|
238
276
|
const fieldOf = (id) => fields.find((f) => f.id === id);
|
|
239
277
|
const update = (filter) => setValue(value.map((f) => (f.field === filter.field ? filter : f)));
|
|
240
278
|
const remove = (id) => {
|
|
@@ -259,16 +297,16 @@ export function FilterBar({ fields, value: valueProp, defaultValue = [], onValue
|
|
|
259
297
|
};
|
|
260
298
|
const chipSize = size === "sm" ? "sm" : "default";
|
|
261
299
|
const applied = value.filter((f) => fieldOf(f.field));
|
|
262
|
-
return (_jsxs("div", { role: "group", "aria-label":
|
|
300
|
+
return (_jsxs("div", { role: "group", "aria-label": messages.group, "data-slot": "filter-bar", "data-size": size, className: cn("flex flex-wrap items-center gap-2 font-body", className), ...props, children: [applied.map((filter) => {
|
|
263
301
|
const field = fieldOf(filter.field);
|
|
264
|
-
const text = describe(filter, field, locale);
|
|
265
|
-
return (_jsxs(ButtonGroup, { "data-slot": "filter-bar-chip", "aria-label":
|
|
302
|
+
const text = describe(filter, field, messages, locale);
|
|
303
|
+
return (_jsxs(ButtonGroup, { "data-slot": "filter-bar-chip", "aria-label": messages.chip(field.label),
|
|
266
304
|
// In a narrow bar a long value ends in an ellipsis; the chip never runs past the bar.
|
|
267
|
-
className: "max-w-full min-w-0", children: [_jsxs(Popover, { open: open === filter.field, onOpenChange: (next) => onOpenChange(filter.field, next), children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { variant: "secondary", size: chipSize }), "data-slot": "filter-bar-chip-trigger", className: "max-w-[22rem] min-w-0 shrink gap-1.5 font-normal", children: [_jsx("span", { className: "shrink-0 text-muted-foreground", children: field.label }), text ? (_jsxs(_Fragment, { children: [text[0] && _jsx("span", { className: "shrink-0 text-muted-foreground", children: text[0] }), _jsx("span", { className: "truncate font-medium text-foreground", children: text[1] })] })) : (_jsx("span", { className: "text-muted-foreground", children: "\u2026" }))] }), _jsxs(PopoverContent, { "data-slot": "filter-bar-editor", align: "start", sideOffset: 6, className: cn("gap-2 p-2", field.kind === "date" ? "w-auto" : "w-64"),
|
|
305
|
+
className: "max-w-full min-w-0", children: [_jsxs(Popover, { open: open === filter.field, onOpenChange: (next) => onOpenChange(filter.field, next), children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { variant: "secondary", size: chipSize }), "data-slot": "filter-bar-chip-trigger", className: "max-w-[22rem] min-w-0 shrink gap-1.5 font-normal", children: [_jsx("span", { className: "shrink-0 text-muted-foreground", children: field.label }), " ", text ? (_jsxs(_Fragment, { children: [text[0] && _jsx("span", { className: "shrink-0 text-muted-foreground", children: text[0] }), " ", _jsx("span", { className: "truncate font-medium text-foreground", children: text[1] })] })) : (_jsx("span", { className: "text-muted-foreground", children: "\u2026" }))] }), _jsxs(PopoverContent, { "data-slot": "filter-bar-editor", align: "start", sideOffset: 6, className: cn("gap-2 p-2", field.kind === "date" ? "w-auto" : "w-64"),
|
|
268
306
|
// Straight to the value — the search, the list, the text, the number, the calendar's
|
|
269
307
|
// day — not the condition.
|
|
270
308
|
initialFocus: () => {
|
|
271
|
-
const editor = `[data-filter-editor="${CSS.escape(filter.field)}"]`;
|
|
309
|
+
const editor = `[data-filter-editor="${CSS.escape(editorKey(filter.field))}"]`;
|
|
272
310
|
return (document.querySelector(`${editor} input:not([type=hidden]), ${editor} [data-slot=calendar-day-button][tabindex="0"]`) ?? true);
|
|
273
311
|
},
|
|
274
312
|
// Back to the chip, or to "Filter" for a filter that is not kept — unless the focus
|
|
@@ -277,20 +315,20 @@ export function FilterBar({ fields, value: valueProp, defaultValue = [], onValue
|
|
|
277
315
|
const active = document.activeElement;
|
|
278
316
|
const own = active
|
|
279
317
|
?.closest('[data-slot="filter-bar-editor"]')
|
|
280
|
-
?.querySelector(`[data-filter-editor="${CSS.escape(filter.field)}"]`);
|
|
318
|
+
?.querySelector(`[data-filter-editor="${CSS.escape(editorKey(filter.field))}"]`);
|
|
281
319
|
if (active && active !== document.body && !own)
|
|
282
320
|
return false;
|
|
283
321
|
return isEmpty(filter) ? addRef.current : true;
|
|
284
|
-
}, children: [_jsxs("div", { className: "flex min-h-(--control-h-sm) items-center justify-between gap-2
|
|
322
|
+
}, children: [_jsxs("div", { className: "flex min-h-(--control-h-sm) items-center justify-between gap-2 ps-1", children: [_jsx(PopoverTitle, { className: "eyebrow text-[11px]", children: field.label }), _jsx(OperatorSelect, { field: field, filter: filter, onChange: update, text: messages })] }), _jsx("div", { "data-filter-editor": editorKey(filter.field),
|
|
285
323
|
// The options scroll within 15rem, and within the room below the chip less the header.
|
|
286
|
-
className: "flex flex-col gap-1 [&_[data-slot=scroll-area]]:max-h-[min(15rem,calc(var(--available-height)-6rem))]", children: _jsx(Editor, { field: field, filter: filter, onChange: update, onDone: () => onOpenChange(filter.field, false) }) })] })] }), _jsx(Button, { variant: "secondary", size: chipSize, "data-slot": "filter-bar-chip-remove", "aria-label":
|
|
324
|
+
className: "flex flex-col gap-1 [&_[data-slot=scroll-area]]:max-h-[min(15rem,calc(var(--available-height)-6rem))]", children: _jsx(Editor, { field: field, filter: filter, onChange: update, onDone: () => onOpenChange(filter.field, false), text: messages }) })] })] }), _jsx(Button, { variant: "secondary", size: chipSize, "data-slot": "filter-bar-chip-remove", "aria-label": messages.remove(field.label), onClick: () => remove(filter.field), className: cn("text-muted-foreground hover:text-foreground", size === "sm" ? "px-2" : "px-2.5"), children: _jsx(XIcon, { className: "size-3.5" }) })] }, filter.field));
|
|
287
325
|
}), _jsxs(Menu, { onOpenChangeComplete: (next) => {
|
|
288
326
|
if (next || !pending.current)
|
|
289
327
|
return;
|
|
290
328
|
setOpen(pending.current);
|
|
291
329
|
pending.current = null;
|
|
292
|
-
}, children: [_jsxs(MenuTrigger, { ref: addRef, render: _jsx(Button, { variant: "ghost", size: chipSize }), "data-slot": "filter-bar-add", className: "text-foreground-soft", children: [_jsx(PlusIcon, {}), addLabel] }), _jsx(MenuContent, { className: "min-w-48", children: fields.map((field) => (_jsxs(MenuItem, { onClick: () => add(field), children: [field.icon, field.label] }, field.id))) })] }), applied.length > 0 && (_jsx(Button, { variant: "ghost", size: chipSize, "data-slot": "filter-bar-clear", onClick: () => {
|
|
330
|
+
}, children: [_jsxs(MenuTrigger, { ref: addRef, render: _jsx(Button, { variant: "ghost", size: chipSize }), "data-slot": "filter-bar-add", className: "text-foreground-soft", children: [_jsx(PlusIcon, {}), addLabel ?? messages.add] }), _jsx(MenuContent, { className: "min-w-48", children: fields.map((field) => (_jsxs(MenuItem, { onClick: () => add(field), children: [field.icon, field.label] }, field.id))) })] }), applied.length > 0 && (_jsx(Button, { variant: "ghost", size: chipSize, "data-slot": "filter-bar-clear", onClick: () => {
|
|
293
331
|
setValue([]);
|
|
294
332
|
addRef.current?.focus();
|
|
295
|
-
}, className: "text-muted-foreground", children:
|
|
333
|
+
}, className: "text-muted-foreground", children: messages.clearAll }))] }));
|
|
296
334
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Form as BaseForm } from "@base-ui/react/form";
|
|
2
|
-
import
|
|
2
|
+
import * as React from "react";
|
|
3
3
|
/**
|
|
4
4
|
* Form — a native `<form>` that collects `Field` validation and shows server errors.
|
|
5
5
|
*
|
|
6
6
|
* Fields stack with 20px between them. Pass `errors` (keyed by each `Field`'s `name`) to show
|
|
7
7
|
* errors returned by the server, and use `onFormSubmit` to receive the values as an object.
|
|
8
8
|
* End the form with `FormActions`, which puts the submit button on the right.
|
|
9
|
+
* With React Hook Form or TanStack Form, pass the library's submit handler to `onSubmit` and each
|
|
10
|
+
* field's error to `Field error`: the library validates every submit, the Form lays it out.
|
|
9
11
|
* The rule people break: validating only on the server — add `required`, `type` and
|
|
10
12
|
* `pattern` to the controls so people see what is wrong before they submit.
|
|
11
13
|
*/
|
|
12
|
-
export declare function Form<FormValues extends Record<string, any> = Record<string, any>>({ className, ...props }: BaseForm.Props<FormValues>): React.JSX.Element;
|
|
14
|
+
export declare function Form<FormValues extends Record<string, any> = Record<string, any>>({ className, onSubmit, onSubmitCapture, ...props }: BaseForm.Props<FormValues>): React.JSX.Element;
|
|
13
15
|
declare const actionAlign: {
|
|
14
16
|
/** Actions on the right, the primary last. The default. */
|
|
15
17
|
readonly end: "justify-end";
|