@sincpro/web-ui 2.20.0 → 2.21.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/README.md CHANGED
@@ -374,7 +374,7 @@ The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`
374
374
  `sidebar.user`, `sidebar.me` (the person at the foot, `account="menu"`), `sidebar.search`,
375
375
  `sidebar.nav`, `sidebar.account`, `navigation`, `navigation.item`, `menu.header`, `tabs` (with
376
376
  `data-look`), `tabs.tab`, `dirty.blocked`, `dirty.bar`, `field`, `field.label`, `form.section`,
377
- `form.card`, `form.index`, `dock`, `dock.pill`, `dock.bare`, `dock.message` (with `data-tone`),
377
+ `form.card`, `form.index`, `dock`, `dock.pill`, `dock.bare`, `dock.message` (with `data-tone`), `dock.sentence` (a button with the whole of it in a tooltip, when cut), `dock.text`, `dock.detail`,
378
378
  `setup`, `setup.step`, `setup.reason`, `setup.preview`, `page`, `pager`, `pagination`, `smart`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
379
379
  `guide.progress`, `guide.title`, `guide.body`, `guide.actions`. A part that is one of many
380
380
  carries `data-key` too (`navigation.item`). Put your rules in a cascade layer above web-ui's, or
@@ -9,7 +9,9 @@ import type { DockMoment } from "./dock.js";
9
9
  * The visible part is keyed by its text: a new sentence enters with a short rise, so dirty → saved → the record's state reads as one place
10
10
  * changing, not as a pill rebuilt. The global reduced-motion rule flattens it.
11
11
  *
12
- * It gives way first: one row on a phone too, the sentence truncates and the buttons stay.
12
+ * It gives way first: one row on a phone too, the sentence truncates and the buttons stay —
13
+ * and, cut, it is still read whole: its text and help in a `Tooltip`, on hover and on keyboard
14
+ * focus (`Entero`). Nothing cut, nothing added: no tooltip, no extra Tab stop.
13
15
  */
14
16
  export declare function DockMessage({ moment, detailId, }: {
15
17
  moment: DockMoment | undefined;
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useSurface } from "../../foundations/surface.js";
4
+ import { Tooltip, TooltipTrigger } from "../../primitives/overlay/Tooltip.js";
4
5
  import { DOT_TONE } from "../../primitives/tag/Tag.js";
6
+ import { useLayoutEffect, useState } from "react";
5
7
  /* The mark in each tone when it is an icon; the dot is `Tag`'s own (`DOT_TONE`). */
6
8
  const INK = {
7
9
  neutral: { canvas: "text-muted", chrome: "text-chrome-muted" },
@@ -21,11 +23,42 @@ const INK = {
21
23
  * The visible part is keyed by its text: a new sentence enters with a short rise, so dirty → saved → the record's state reads as one place
22
24
  * changing, not as a pill rebuilt. The global reduced-motion rule flattens it.
23
25
  *
24
- * It gives way first: one row on a phone too, the sentence truncates and the buttons stay.
26
+ * It gives way first: one row on a phone too, the sentence truncates and the buttons stay —
27
+ * and, cut, it is still read whole: its text and help in a `Tooltip`, on hover and on keyboard
28
+ * focus (`Entero`). Nothing cut, nothing added: no tooltip, no extra Tab stop.
25
29
  */
26
30
  export function DockMessage({ moment, detailId, }) {
27
31
  const surface = useSurface() === "chrome" ? "chrome" : "canvas";
28
32
  const tone = moment?.tone ?? "neutral";
29
33
  const Icon = moment?.icon;
30
- return (_jsx(_Fragment, { children: moment === undefined ? null : (_jsxs("span", { "data-ui": "dock.message", "data-tone": tone, className: "flex min-w-0 shrink! items-center gap-2 px-2.5 transition-[opacity,translate] duration-(--duration-quick) ease-(--ease-out) starting:translate-y-0.5 starting:opacity-0", children: [Icon === undefined ? (_jsxs("span", { "aria-hidden": true, className: "relative flex size-1.5 shrink-0", children: [moment.busy === true ? (_jsx("span", { className: `absolute inline-flex size-full animate-ping rounded-pill opacity-70 ${DOT_TONE[tone][surface]}` })) : null, _jsx("span", { className: `relative inline-flex size-1.5 rounded-pill ${DOT_TONE[tone][surface]}` })] })) : (_jsx(Icon, { "aria-hidden": true, strokeWidth: 2.25, className: `size-(--size-icon-sm) shrink-0 ${INK[tone][surface]}` })), _jsxs("span", { className: "flex min-w-0 flex-col leading-tight", children: [_jsx("span", { className: `truncate text-meta font-medium ${surface === "chrome" ? "text-chrome-ink" : "text-ink"}`, children: moment.text }), moment.detail === undefined ? null : (_jsx("span", { ...(detailId === undefined ? {} : { id: detailId }), className: `truncate text-micro ${surface === "chrome" ? "text-chrome-muted" : "text-muted"}`, children: moment.detail }))] })] }, moment.text)) }));
34
+ return (_jsx(_Fragment, { children: moment === undefined ? null : (_jsxs("span", { "data-ui": "dock.message", "data-tone": tone, className: "flex min-w-0 shrink! items-center gap-2 px-2.5 transition-[opacity,translate] duration-(--duration-quick) ease-(--ease-out) starting:translate-y-0.5 starting:opacity-0", children: [Icon === undefined ? (_jsxs("span", { "aria-hidden": true, className: "relative flex size-1.5 shrink-0", children: [moment.busy === true ? (_jsx("span", { className: `absolute inline-flex size-full animate-ping rounded-pill opacity-70 ${DOT_TONE[tone][surface]}` })) : null, _jsx("span", { className: `relative inline-flex size-1.5 rounded-pill ${DOT_TONE[tone][surface]}` })] })) : (_jsx(Icon, { "aria-hidden": true, strokeWidth: 2.25, className: `size-(--size-icon-sm) shrink-0 ${INK[tone][surface]}` })), _jsxs(Entero, { text: moment.text, detail: moment.detail, children: [_jsx("span", { "data-ui": "dock.text", className: `truncate text-meta font-medium ${surface === "chrome" ? "text-chrome-ink" : "text-ink"}`, children: moment.text }), moment.detail === undefined ? null : (_jsx("span", { ...(detailId === undefined ? {} : { id: detailId }), "data-ui": "dock.detail", className: `truncate text-micro ${surface === "chrome" ? "text-chrome-muted" : "text-muted"}`, children: moment.detail }))] })] }, moment.text)) }));
35
+ }
36
+ /**
37
+ * The sentence and its help, and — only when one of them is cut — the whole of both in a
38
+ * `Tooltip`. Measured after layout and again on every resize: a pill that widens shows it all
39
+ * and drops the tooltip; one that narrows takes it.
40
+ *
41
+ * Context: cut, the block is a button — a tooltip's trigger must take focus and have a role —
42
+ * that shows it on hover and on keyboard focus, and pins it on a press: the pill is cut mostly
43
+ * on a phone, where nothing hovers. Not cut, it is plain text: no extra Tab stop.
44
+ */
45
+ function Entero({ text, detail, children, }) {
46
+ // The node by state, not by a ref object: becoming a button mounts a new one, and the
47
+ // measuring has to follow it.
48
+ const [nodo, setNodo] = useState(null);
49
+ const [cortado, setCortado] = useState(false);
50
+ const [abierto, setAbierto] = useState(false);
51
+ useLayoutEffect(() => {
52
+ if (nodo === null)
53
+ return;
54
+ const medir = () => setCortado([...nodo.children].some((linea) => linea.scrollWidth > linea.clientWidth));
55
+ medir();
56
+ const observador = new ResizeObserver(medir);
57
+ observador.observe(nodo);
58
+ return () => observador.disconnect();
59
+ }, [nodo, text, detail]);
60
+ const clase = "flex min-w-0 flex-col leading-tight";
61
+ if (!cortado)
62
+ return (_jsx("span", { ref: setNodo, "data-ui": "dock.sentence", className: clase, children: children }));
63
+ return (_jsxs(TooltipTrigger, { open: abierto, onOpenChange: setAbierto, closeOnPress: false, children: [_jsx("button", { ref: setNodo, type: "button", "data-ui": "dock.sentence", onClick: () => setAbierto((ahora) => !ahora), className: `${clase} cursor-default rounded-control text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`, children: children }), _jsxs(Tooltip, { children: [_jsx("span", { className: "block font-medium", children: text }), detail === undefined ? null : _jsx("span", { className: "mt-0.5 block", children: detail })] })] }));
31
64
  }
@@ -27,7 +27,7 @@ export declare function useInTooltipTrigger(): boolean;
27
27
  * with the system's own buttons — they forward `ref` and spread native props — or with a
28
28
  * plain `<button>`, and never has to know the adapter exists.
29
29
  */
30
- export declare function TooltipTrigger({ children, delay, closeDelay, disabled, }: {
30
+ export declare function TooltipTrigger({ children, delay, closeDelay, disabled, open, onOpenChange, closeOnPress, }: {
31
31
  /** The control — one element that forwards `ref` and spreads native props, like every
32
32
  * system button — then the `Tooltip`. */
33
33
  children: ReactNode;
@@ -35,4 +35,11 @@ export declare function TooltipTrigger({ children, delay, closeDelay, disabled,
35
35
  delay?: number;
36
36
  closeDelay?: number;
37
37
  disabled?: boolean;
38
+ /** Open by the consumer — a tooltip a press pins, for a screen with no pointer to hover —,
39
+ * told every change by `onOpenChange`. Absent, React Aria decides. */
40
+ open?: boolean;
41
+ onOpenChange?: (open: boolean) => void;
42
+ /** Pressing the control closes the tooltip (on by default): off when the press is what
43
+ * opens it. */
44
+ closeOnPress?: boolean;
38
45
  }): import("react").JSX.Element;
@@ -68,7 +68,7 @@ function isDisabledControl(control) {
68
68
  * with the system's own buttons — they forward `ref` and spread native props — or with a
69
69
  * plain `<button>`, and never has to know the adapter exists.
70
70
  */
71
- export function TooltipTrigger({ children, delay, closeDelay, disabled = false, }) {
71
+ export function TooltipTrigger({ children, delay, closeDelay, disabled = false, open, onOpenChange, closeOnPress = true, }) {
72
72
  const [control, ...tooltip] = Children.toArray(children);
73
- return (_jsxs(AriaTooltipTrigger, { delay: delay, closeDelay: closeDelay, isDisabled: disabled, children: [_jsx(InTooltipTrigger.Provider, { value: true, children: _jsx(Focusable, { isDisabled: isDisabledControl(control), children: control }) }), tooltip] }));
73
+ return (_jsxs(AriaTooltipTrigger, { delay: delay, closeDelay: closeDelay, isDisabled: disabled, shouldCloseOnPress: closeOnPress, ...(open === undefined ? {} : { isOpen: open }), ...(onOpenChange === undefined ? {} : { onOpenChange }), children: [_jsx(InTooltipTrigger.Provider, { value: true, children: _jsx(Focusable, { isDisabled: isDisabledControl(control), children: control }) }), tooltip] }));
74
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-ui",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
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",