@sincpro/web-ui 1.7.1 → 1.7.2
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.
|
@@ -8,6 +8,7 @@ import { bySurface, useSurface } from "../../foundations/surface.js";
|
|
|
8
8
|
import { Tags } from "../../primitives/tag/Tags.js";
|
|
9
9
|
import { ChevronRight, CornerDownRight, ListFilter, Search, SlidersHorizontal, X, } from "lucide-react";
|
|
10
10
|
import { Fragment, useEffect, useId, useRef, useState } from "react";
|
|
11
|
+
import { useOverlay } from "react-aria";
|
|
11
12
|
function Option({ o, onSelect }) {
|
|
12
13
|
const Icon = o.icon;
|
|
13
14
|
return (_jsxs("button", { type: "button", disabled: o.disabled, onClick: () => onSelect?.(o.id), className: `flex w-full items-start gap-2 rounded-control px-1.5 py-1 text-left transition-colors duration-(--duration-instant) disabled:pointer-events-none disabled:opacity-45 hover:bg-primary/8 ${o.checked === true ? "bg-primary/6" : ""}`, children: [_jsx("span", { className: "mt-0.5 flex size-(--size-icon-sm) shrink-0 items-center justify-center", children: o.checked === true ? (_jsx("span", { className: "size-1.5 rounded-pill bg-primary" })) : Icon !== undefined ? (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2 })) : (_jsx("span", { className: "size-3 rounded-pill border border-line-strong" })) }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${o.checked === true ? "font-medium text-ink" : "text-ink"}`, children: o.label }), o.badge === undefined ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-warn/30 bg-warn/10 px-2 py-0.5 text-micro text-warn", children: o.badge }))] }), o.hint === undefined ? null : (_jsx("span", { className: "mt-0.5 block truncate text-micro text-muted", children: o.hint }))] })] }));
|
|
@@ -73,6 +74,8 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
73
74
|
const puestos = criteria.length;
|
|
74
75
|
const input = useRef(null);
|
|
75
76
|
const box = useRef(null);
|
|
77
|
+
const toolsButton = useRef(null);
|
|
78
|
+
const panelBox = useRef(null);
|
|
76
79
|
const id = useId();
|
|
77
80
|
/* The suggestions are the input's popup (the ARIA combobox pattern): the input keeps the
|
|
78
81
|
focus and says which list it controls and which option is the active one, so a screen
|
|
@@ -134,25 +137,41 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
134
137
|
? []
|
|
135
138
|
: [{ title: copy.search.favorites, groups: favorites, onSelect: onFavoriteSelect }]),
|
|
136
139
|
];
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
/* THE PANEL IS A LAYER, and Escape closes the layer on top — only that one.
|
|
141
|
+
|
|
142
|
+
It listened for Escape and for a click outside on `document`, without stopping either.
|
|
143
|
+
Inside a dialog —the «Buscar más…» chooser, a composer modal— the dialog (React Aria's
|
|
144
|
+
`ModalOverlay`, which answers inside the React tree) closed FIRST, then the panel: whoever
|
|
145
|
+
pressed Escape to put the panel away lost the chooser. React Aria did not know the panel
|
|
146
|
+
sat on top of the dialog. Now it does: `useOverlay` puts the panel on React Aria's stack
|
|
147
|
+
of layers, the same one a `Select` or a `Picker` popover is on, so Escape and a press
|
|
148
|
+
outside close the top layer and leave the dialog open. A press inside the bar is not
|
|
149
|
+
«outside» (the button toggles, the input keeps typing). */
|
|
150
|
+
const closePanel = () => {
|
|
151
|
+
/* The focus goes back to the button that opened it — but only if it was inside the panel
|
|
152
|
+
(Escape): a press elsewhere already put it where the person wanted. */
|
|
153
|
+
const hadFocus = panelBox.current?.contains(document.activeElement) === true;
|
|
154
|
+
setPanel(false);
|
|
155
|
+
if (hadFocus)
|
|
156
|
+
toolsButton.current?.focus();
|
|
157
|
+
};
|
|
158
|
+
const { overlayProps } = useOverlay({
|
|
159
|
+
isOpen: panel,
|
|
160
|
+
onClose: closePanel,
|
|
161
|
+
isDismissable: true,
|
|
162
|
+
shouldCloseOnInteractOutside: (element) => box.current?.contains(element) !== true,
|
|
163
|
+
}, panelBox);
|
|
164
|
+
/* With the focus still in the bar (the input, the button) and the panel open, Escape is
|
|
165
|
+
the panel's too — used up the same way, so it does not reach the dialog either. With the
|
|
166
|
+
panel closed, Escape is not the bar's and goes on to whoever owns it. */
|
|
167
|
+
const closePanelOnEscape = (e) => {
|
|
168
|
+
if (e.key !== "Escape" || !panel || e.defaultPrevented)
|
|
139
169
|
return;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function onEscape(e) {
|
|
146
|
-
if (e.key === "Escape")
|
|
147
|
-
setPanel(false);
|
|
148
|
-
}
|
|
149
|
-
document.addEventListener("mousedown", outside);
|
|
150
|
-
document.addEventListener("keydown", onEscape);
|
|
151
|
-
return () => {
|
|
152
|
-
document.removeEventListener("mousedown", outside);
|
|
153
|
-
document.removeEventListener("keydown", onEscape);
|
|
154
|
-
};
|
|
155
|
-
}, [panel]);
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
e.stopPropagation();
|
|
172
|
+
setPanel(false);
|
|
173
|
+
toolsButton.current?.focus();
|
|
174
|
+
};
|
|
156
175
|
/**
|
|
157
176
|
* UNA PREGUNTA ENTERA entra como instancia, y la barra vuelve al principio.
|
|
158
177
|
*
|
|
@@ -222,7 +241,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
222
241
|
? one
|
|
223
242
|
: { ...node, of: [...node.of, one] };
|
|
224
243
|
}
|
|
225
|
-
return (_jsxs("div", { ref: box, className: "relative flex min-w-0 items-center gap-2", children: [_jsxs("div", { className: `@container/bar flex min-h-(--size-control-md) w-full min-w-0 items-start rounded-box border transition-colors duration-(--duration-instant) ${bySurface(sup, "border-line-strong bg-surface focus-within:border-primary/60",
|
|
244
|
+
return (_jsxs("div", { ref: box, onKeyDown: closePanelOnEscape, className: "relative flex min-w-0 items-center gap-2", children: [_jsxs("div", { className: `@container/bar flex min-h-(--size-control-md) w-full min-w-0 items-start rounded-box border transition-colors duration-(--duration-instant) ${bySurface(sup, "border-line-strong bg-surface focus-within:border-primary/60",
|
|
226
245
|
/* Sobre el cromo lo que define al campo es el BORDE, no el relleno. El
|
|
227
246
|
azul ya es casi negro, así que hundirlo no da contraste (1,05:1) y
|
|
228
247
|
levantarlo da 1,21:1 — en los dos casos el campo no se lee como un
|
|
@@ -345,16 +364,19 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
345
364
|
if (e.key === "Escape") {
|
|
346
365
|
if (text !== "") {
|
|
347
366
|
e.preventDefault();
|
|
367
|
+
e.stopPropagation();
|
|
348
368
|
setText("");
|
|
349
369
|
return;
|
|
350
370
|
}
|
|
351
371
|
if (step.op !== undefined) {
|
|
352
372
|
e.preventDefault();
|
|
373
|
+
e.stopPropagation();
|
|
353
374
|
setStep({ field: step.field });
|
|
354
375
|
return;
|
|
355
376
|
}
|
|
356
377
|
if (step.field !== undefined) {
|
|
357
378
|
e.preventDefault();
|
|
379
|
+
e.stopPropagation();
|
|
358
380
|
setStep({});
|
|
359
381
|
return;
|
|
360
382
|
}
|
|
@@ -362,6 +384,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
362
384
|
se deshace. */
|
|
363
385
|
if (openGroup !== null) {
|
|
364
386
|
e.preventDefault();
|
|
387
|
+
e.stopPropagation();
|
|
365
388
|
closeGroup();
|
|
366
389
|
}
|
|
367
390
|
return;
|
|
@@ -388,7 +411,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
388
411
|
onCriteriaChange([]);
|
|
389
412
|
setOpenGroup(null);
|
|
390
413
|
input.current?.focus();
|
|
391
|
-
}, "aria-label": copy.search.clearAll, title: copy.search.clearAll, className: `my-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center rounded-control px-1.5 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-muted hover:bg-ink/5 hover:text-ink", "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) })), columns.length === 0 && onOpenBuilder === undefined ? null : (_jsxs("button", { type: "button", onClick: () => setPanel((v) => !v), "aria-expanded": panel, "aria-controls": panel ? id : undefined, "aria-label": puestos === 0
|
|
414
|
+
}, "aria-label": copy.search.clearAll, title: copy.search.clearAll, className: `my-0.5 inline-flex h-(--size-control-sm) shrink-0 items-center rounded-control px-1.5 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-muted hover:bg-ink/5 hover:text-ink", "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) })), columns.length === 0 && onOpenBuilder === undefined ? null : (_jsxs("button", { ref: toolsButton, type: "button", onClick: () => setPanel((v) => !v), "aria-expanded": panel, "aria-controls": panel ? id : undefined, "aria-label": puestos === 0
|
|
392
415
|
? copy.search.tools
|
|
393
416
|
: fillCopy(puestos === 1 ? copy.search.toolsSetOne : copy.search.toolsSetMany, {
|
|
394
417
|
label: copy.search.tools,
|
|
@@ -411,7 +434,7 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
411
434
|
onSelect: () => pick(one),
|
|
412
435
|
})) }) })) : (_jsx("div", { id: listId, role: "listbox", "aria-label": copy.search.suggestions, className: "p-1", children: suggestions.map((one, at) => (_jsxs("div", { id: optionId(at), role: "option", "aria-selected": at === active,
|
|
413
436
|
/* The input keeps the focus: pressing an option must not take it. */
|
|
414
|
-
onMouseDown: (event) => event.preventDefault(), onClick: () => pick(one), onMouseEnter: () => setActive(at), className: `flex w-full cursor-pointer items-baseline gap-1.5 rounded-control px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${at === active ? "bg-primary/8" : "hover:bg-ink/4"}`, children: [_jsx("span", { className: "shrink-0 font-medium text-ink", children: one.label }), one.kind === "condition" || one.kind === "literal" ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "shrink-0 text-muted", children: ":" }), _jsx("span", { className: "min-w-0 truncate font-mono text-micro text-ink", children: one.hint })] })) : one.kind === "field" && one.hint !== undefined ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro text-muted", children: one.hint })) : null] }, one.id))) }))] })) : null, panel && (columns.length > 0 || onOpenBuilder !== undefined) ? (_jsxs("div", { id: id, className: "absolute top-full right-0 z-30 mt-1 flex w-max max-w-full flex-wrap overflow-hidden rounded-panel border border-line-strong bg-surface shadow-float", children: [columns.map((c, i) => (_jsxs("div", { className: `flex min-w-48 flex-1 flex-col ${i === 0 ? "" : "border-t border-line sm:border-t-0 sm:border-l"}`, children: [_jsx("div", { className: "border-b border-line px-2.5 py-1.5 text-micro font-medium text-muted", children: c.title }), _jsx("div", { className: "flex flex-col gap-0.5 p-1", children: c.content ??
|
|
437
|
+
onMouseDown: (event) => event.preventDefault(), onClick: () => pick(one), onMouseEnter: () => setActive(at), className: `flex w-full cursor-pointer items-baseline gap-1.5 rounded-control px-2 py-1.5 text-left text-meta transition-colors duration-(--duration-instant) ${at === active ? "bg-primary/8" : "hover:bg-ink/4"}`, children: [_jsx("span", { className: "shrink-0 font-medium text-ink", children: one.label }), one.kind === "condition" || one.kind === "literal" ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "shrink-0 text-muted", children: ":" }), _jsx("span", { className: "min-w-0 truncate font-mono text-micro text-ink", children: one.hint })] })) : one.kind === "field" && one.hint !== undefined ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro text-muted", children: one.hint })) : null] }, one.id))) }))] })) : null, panel && (columns.length > 0 || onOpenBuilder !== undefined) ? (_jsxs("div", { ...overlayProps, ref: panelBox, id: id, className: "absolute top-full right-0 z-30 mt-1 flex w-max max-w-full flex-wrap overflow-hidden rounded-panel border border-line-strong bg-surface shadow-float", children: [columns.map((c, i) => (_jsxs("div", { className: `flex min-w-48 flex-1 flex-col ${i === 0 ? "" : "border-t border-line sm:border-t-0 sm:border-l"}`, children: [_jsx("div", { className: "border-b border-line px-2.5 py-1.5 text-micro font-medium text-muted", children: c.title }), _jsx("div", { className: "flex flex-col gap-0.5 p-1", children: c.content ??
|
|
415
438
|
c.groups?.map((g, gi) => (_jsx(Group, { group: g, first: gi === 0, onSelect: c.onSelect }, g.label ?? gi))) })] }, c.title))), onOpenBuilder === undefined ? null : (_jsx("div", { className: "w-full border-t border-line p-1", children: _jsxs("button", { type: "button", onClick: () => {
|
|
416
439
|
onOpenBuilder();
|
|
417
440
|
setPanel(false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-ui",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|