@dubix/ui 0.11.0 → 0.13.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 +247 -18
- package/dist/filter-bar/FilterBar.d.ts +1 -1
- package/dist/pagination/Pagination.d.ts +3 -1
- package/dist/pagination/Pagination.js +3 -3
- package/dist/search-input/SearchInput.d.ts +4 -2
- package/dist/search-input/SearchInput.js +5 -3
- package/dist/side-panel/SidePanel.d.ts +55 -0
- package/dist/side-panel/SidePanel.js +130 -0
- package/dist/side-panel/index.d.ts +2 -0
- package/dist/side-panel/index.js +1 -0
- package/dist/skip-link/SkipLink.d.ts +11 -0
- package/dist/skip-link/SkipLink.js +9 -0
- package/dist/skip-link/index.d.ts +2 -0
- package/dist/skip-link/index.js +1 -0
- package/dist/styles.css +330 -3
- package/dist/table/Table.d.ts +9 -3
- package/dist/table/Table.js +3 -3
- package/dist/table/TableRowTrigger.d.ts +28 -0
- package/dist/table/TableRowTrigger.js +93 -0
- package/dist/table/index.d.ts +2 -0
- package/dist/table/index.js +1 -0
- package/package.json +9 -1
|
@@ -2,7 +2,7 @@ import type { ComponentPropsWithRef, ReactNode } from 'react';
|
|
|
2
2
|
export interface FilterBarProps extends Omit<ComponentPropsWithRef<'div'>, 'role' | 'aria-label' | 'children'> {
|
|
3
3
|
/** Nombre de la región de búsqueda (p. ej. «Filtros de comprobantes de venta»). Obligatorio: `role="search"` va con nombre. */
|
|
4
4
|
'aria-label': string;
|
|
5
|
-
/** El buscador: un SearchInput (con su propio `aria-label`).
|
|
5
|
+
/** El buscador: un SearchInput (con su propio `aria-label`). Arranca en `--dx-size-search` (340px) y crece hasta 480px si hay lugar; en angosto, todo el ancho. */
|
|
6
6
|
search?: ReactNode;
|
|
7
7
|
/** Los filtros a la vista (FilterButton dentro de PopoverTrigger, FilterToggle) y, si hay, el botón «Filtrar». */
|
|
8
8
|
children?: ReactNode;
|
|
@@ -13,6 +13,8 @@ export interface PaginationProps extends Omit<ComponentPropsWithRef<'nav'>, 'chi
|
|
|
13
13
|
onPageChange: (page: number) => void;
|
|
14
14
|
/** Qué se cuenta, en plural («empresas»): va al final del rango («51–75 de 312 empresas»). */
|
|
15
15
|
itemLabel?: string | undefined;
|
|
16
|
+
/** Lo mismo en singular («empresa»): con `total` 1, el rango dice «1 empresa» en vez de «1–1 de 1 empresas». */
|
|
17
|
+
itemLabelSingular?: string | undefined;
|
|
16
18
|
/**
|
|
17
19
|
* Con `onPageSizeChange`, al lado del rango va «Filas por página» con un Select sm. Recibe las filas elegidas; la pantalla
|
|
18
20
|
* vuelve a la página 1. Sin `onPageSizeChange`, Pagination queda como siempre.
|
|
@@ -29,4 +31,4 @@ export interface PaginationProps extends Omit<ComponentPropsWithRef<'nav'>, 'chi
|
|
|
29
31
|
* 5 → 1 … 4 5 6 … 10; en la 10 → 1 … 6 7 8 9 10.
|
|
30
32
|
*/
|
|
31
33
|
export declare function paginationRange(page: number, pageCount: number): PaginationItem[];
|
|
32
|
-
export declare function Pagination({ page, pageSize, total, onPageChange, itemLabel, onPageSizeChange, pageSizeOptions, pageSizeLabel, className, 'aria-label': ariaLabel, ...rest }: PaginationProps): import("react").JSX.Element | null;
|
|
34
|
+
export declare function Pagination({ page, pageSize, total, onPageChange, itemLabel, itemLabelSingular, onPageSizeChange, pageSizeOptions, pageSizeLabel, className, 'aria-label': ariaLabel, ...rest }: PaginationProps): import("react").JSX.Element | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from 'react';
|
|
3
3
|
import { Button } from '../button/index.js';
|
|
4
4
|
import { Select, SelectItem } from '../select/index.js';
|
|
@@ -34,7 +34,7 @@ const Chevron = ({ d }) => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", st
|
|
|
34
34
|
*/
|
|
35
35
|
/** Las filas por página por defecto. */
|
|
36
36
|
const PAGE_SIZE_OPTIONS = [25, 50, 100];
|
|
37
|
-
export function Pagination({ page, pageSize, total, onPageChange, itemLabel, onPageSizeChange, pageSizeOptions = PAGE_SIZE_OPTIONS, pageSizeLabel = 'Filas por página', className, 'aria-label': ariaLabel = 'Paginación', ...rest }) {
|
|
37
|
+
export function Pagination({ page, pageSize, total, onPageChange, itemLabel, itemLabelSingular, onPageSizeChange, pageSizeOptions = PAGE_SIZE_OPTIONS, pageSizeLabel = 'Filas por página', className, 'aria-label': ariaLabel = 'Paginación', ...rest }) {
|
|
38
38
|
const sizeLabelId = useId();
|
|
39
39
|
// TypeScript no lo frena (es un number); un error claro en vez de un rango con NaN o Infinity.
|
|
40
40
|
if (!(pageSize > 0) || !Number.isFinite(pageSize))
|
|
@@ -48,5 +48,5 @@ export function Pagination({ page, pageSize, total, onPageChange, itemLabel, onP
|
|
|
48
48
|
const go = (target) => () => { onPageChange(target); };
|
|
49
49
|
const first = current === 1;
|
|
50
50
|
const last = current === pageCount;
|
|
51
|
-
return (_jsxs("nav", { ...rest, "aria-label": ariaLabel, className: className ? `dx-pagination ${className}` : 'dx-pagination', children: [
|
|
51
|
+
return (_jsxs("nav", { ...rest, "aria-label": ariaLabel, className: className ? `dx-pagination ${className}` : 'dx-pagination', children: [_jsx("p", { className: "dx-pagination__range", "aria-live": "polite", "aria-atomic": "true", children: total === 1 && itemLabelSingular ? '1 ' + itemLabelSingular : _jsxs(_Fragment, { children: [fmt(from), "\u2013", fmt(to), " de ", fmt(total), itemLabel ? ' ' + itemLabel : null] }) }), onPageSizeChange && (_jsxs("div", { className: "dx-pagination__size", children: [_jsx("span", { className: "dx-pagination__size-label", id: sizeLabelId, children: pageSizeLabel }), _jsx(Select, { size: "sm", className: "dx-pagination__size-select", "aria-labelledby": sizeLabelId, value: String(pageSize), onValueChange: (next) => { onPageSizeChange(Number(next)); }, children: [...new Set([...pageSizeOptions, pageSize])].sort((a, b) => a - b).map((n) => (_jsx(SelectItem, { value: String(n), children: fmt(n) }, n))) })] })), pageCount > 1 && (_jsxs("div", { className: "dx-pagination__controls", children: [_jsx(Button, { variant: "ghost", size: "sm", className: "dx-pagination__step", "data-step": "prev", iconStart: _jsx(Chevron, { d: "m15 18-6-6 6-6" }), "aria-disabled": first ? true : undefined, onClick: first ? undefined : go(current - 1), children: _jsx("span", { className: "dx-pagination__label", children: "Anterior" }) }), _jsx("span", { className: "dx-pagination__pages", children: paginationRange(current, pageCount).map((item, i) => item === 'ellipsis' ? (_jsx("span", { className: "dx-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" }, i < 3 ? 'ellipsis-start' : 'ellipsis-end')) : (_jsx(Button, { variant: "ghost", size: "sm", className: "dx-pagination__page", "aria-label": 'Página ' + String(item), "aria-current": item === current ? 'page' : undefined, onClick: item === current ? undefined : go(item), children: fmt(item) }, item))) }), _jsxs("span", { className: "dx-pagination__status", children: [fmt(current), " de ", fmt(pageCount)] }), _jsx(Button, { variant: "ghost", size: "sm", className: "dx-pagination__step", "data-step": "next", iconEnd: _jsx(Chevron, { d: "m9 18 6-6-6-6" }), "aria-disabled": last ? true : undefined, onClick: last ? undefined : go(current + 1), children: _jsx("span", { className: "dx-pagination__label", children: "Siguiente" }) })] }))] }));
|
|
52
52
|
}
|
|
@@ -14,6 +14,8 @@ export interface SearchInputProps extends Omit<ComponentPropsWithRef<'input'>, '
|
|
|
14
14
|
/**
|
|
15
15
|
* Campo de búsqueda (Search md del DS v1): un Input `type="search"` con el ícono de búsqueda al principio, fondo
|
|
16
16
|
* `--dx-bg-sunken` y, cuando hay texto, un IconButton para limpiar al final. Las props van al `<input>` (también `ref`);
|
|
17
|
-
* `className`, al contenedor `.dx-search-input`. Sin debounce: lo hace la pantalla.
|
|
17
|
+
* `className`, al contenedor `.dx-search-input`. Sin debounce: lo hace la pantalla. Sin corrector ortográfico, autocorrección
|
|
18
|
+
* ni mayúsculas automáticas (lo que se busca son nombres, códigos y CUIT): la app los vuelve a prender con `spellCheck`,
|
|
19
|
+
* `autoCorrect` y `autoCapitalize`.
|
|
18
20
|
*/
|
|
19
|
-
export declare function SearchInput({ value, defaultValue, onValueChange, onClear, clearLabel, onChange, onKeyDown, className, ref, ...rest }: SearchInputProps): import("react").JSX.Element;
|
|
21
|
+
export declare function SearchInput({ value, defaultValue, onValueChange, onClear, clearLabel, spellCheck, autoCorrect, autoCapitalize, onChange, onKeyDown, className, ref, ...rest }: SearchInputProps): import("react").JSX.Element;
|
|
@@ -21,9 +21,11 @@ const keepFocus = (event) => { event.preventDefault(); };
|
|
|
21
21
|
/**
|
|
22
22
|
* Campo de búsqueda (Search md del DS v1): un Input `type="search"` con el ícono de búsqueda al principio, fondo
|
|
23
23
|
* `--dx-bg-sunken` y, cuando hay texto, un IconButton para limpiar al final. Las props van al `<input>` (también `ref`);
|
|
24
|
-
* `className`, al contenedor `.dx-search-input`. Sin debounce: lo hace la pantalla.
|
|
24
|
+
* `className`, al contenedor `.dx-search-input`. Sin debounce: lo hace la pantalla. Sin corrector ortográfico, autocorrección
|
|
25
|
+
* ni mayúsculas automáticas (lo que se busca son nombres, códigos y CUIT): la app los vuelve a prender con `spellCheck`,
|
|
26
|
+
* `autoCorrect` y `autoCapitalize`.
|
|
25
27
|
*/
|
|
26
|
-
export function SearchInput({ value, defaultValue = '', onValueChange, onClear, clearLabel = 'Limpiar búsqueda', onChange, onKeyDown, className, ref, ...rest }) {
|
|
28
|
+
export function SearchInput({ value, defaultValue = '', onValueChange, onClear, clearLabel = 'Limpiar búsqueda', spellCheck = false, autoCorrect = 'off', autoCapitalize = 'off', onChange, onKeyDown, className, ref, ...rest }) {
|
|
27
29
|
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
28
30
|
const input = useRef(null);
|
|
29
31
|
const controlled = value !== undefined;
|
|
@@ -53,5 +55,5 @@ export function SearchInput({ value, defaultValue = '', onValueChange, onClear,
|
|
|
53
55
|
event.stopPropagation();
|
|
54
56
|
clear();
|
|
55
57
|
};
|
|
56
|
-
return (_jsxs("div", { className: className ? `dx-search-input ${className}` : 'dx-search-input', children: [_jsx(Input, { ...rest, ref: mergeRefs(input, ref), type: "search", value: text, onChange: handleChange, onKeyDown: handleKeyDown, iconStart: _jsx(SearchIcon, {}), className: "dx-search-input__field" }), canClear && (_jsx(IconButton, { label: clearLabel, icon: _jsx(ClearIcon, {}), variant: "ghost", size: "xs", className: "dx-search-input__clear", onMouseDown: keepFocus, onClick: clear }))] }));
|
|
58
|
+
return (_jsxs("div", { className: className ? `dx-search-input ${className}` : 'dx-search-input', children: [_jsx(Input, { ...rest, ref: mergeRefs(input, ref), type: "search", spellCheck: spellCheck, autoCorrect: autoCorrect, autoCapitalize: autoCapitalize, value: text, onChange: handleChange, onKeyDown: handleKeyDown, iconStart: _jsx(SearchIcon, {}), className: "dx-search-input__field" }), canClear && (_jsx(IconButton, { label: clearLabel, icon: _jsx(ClearIcon, {}), variant: "ghost", size: "xs", className: "dx-search-input__clear", onMouseDown: keepFocus, onClick: clear }))] }));
|
|
57
59
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactNode } from 'react';
|
|
2
|
+
export interface SidePanelLayoutProps extends ComponentPropsWithRef<'div'> {
|
|
3
|
+
/** El contenido de la página (el `<main>`). Va en `.dx-side-layout__main`, que ocupa el ancho que queda. */
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
/** Ancho del layout, en px, desde el que el panel va acoplado; por debajo, flota sobre el borde derecho. Por defecto 1100. */
|
|
6
|
+
dockMinWidth?: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface SidePanelProps {
|
|
9
|
+
/** Título del panel (un `h2`); lo nombra (`aria-labelledby`). */
|
|
10
|
+
title: ReactNode;
|
|
11
|
+
/** Al lado del título y fuera del `h2` (p. ej. una Badge de estado). */
|
|
12
|
+
titleAside?: ReactNode | undefined;
|
|
13
|
+
/** Bajada debajo del título; describe al panel (`aria-describedby`). */
|
|
14
|
+
subtitle?: ReactNode | undefined;
|
|
15
|
+
/** La llaman la × y Esc. La pantalla desmonta el panel. */
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
/** Registro anterior. Con `onPrevious` o `onNext` se muestran los dos botones; el que no tiene función va deshabilitado. */
|
|
18
|
+
onPrevious?: (() => void) | undefined;
|
|
19
|
+
/** Registro siguiente. */
|
|
20
|
+
onNext?: (() => void) | undefined;
|
|
21
|
+
/** Por defecto «Anterior». */
|
|
22
|
+
previousLabel?: string | undefined;
|
|
23
|
+
/** Por defecto «Siguiente». */
|
|
24
|
+
nextLabel?: string | undefined;
|
|
25
|
+
/** Nombre de la ×. Por defecto «Cerrar». */
|
|
26
|
+
closeLabel?: string | undefined;
|
|
27
|
+
/** Herramientas del encabezado, entre anterior/siguiente y la × (p. ej. «Abrir la ficha completa»). */
|
|
28
|
+
actions?: ReactNode | undefined;
|
|
29
|
+
/** Pie fijo con las acciones. Sin `footer` no se renderiza. */
|
|
30
|
+
footer?: ReactNode | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Identifica el registro que se muestra. Cuando cambia con el panel abierto, el cuerpo vuelve arriba y el lector de
|
|
33
|
+
* pantalla anuncia el título nuevo, sin mover el foco.
|
|
34
|
+
*/
|
|
35
|
+
recordKey?: string | number | undefined;
|
|
36
|
+
/** Con `false`, no mueve el foco al montar (p. ej. el panel ya viene abierto por la URL al cargar la página). Por defecto true. */
|
|
37
|
+
focusOnMount?: boolean | undefined;
|
|
38
|
+
/** El cuerpo, con scroll propio. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
/** Se suma a `dx-side-panel`. */
|
|
41
|
+
className?: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* El armazón donde vive el panel: lo pone la app una sola vez, alrededor del `<main>` (no adentro: el `<aside>` es una
|
|
45
|
+
* región de la página). Mide su propio ancho con ResizeObserver (la primera vez antes de pintar) y lo expone en
|
|
46
|
+
* `data-docked`; `data-open` mientras haya un panel montado. Sin container queries: `container-type` haría del layout el
|
|
47
|
+
* bloque contenedor de todo lo `position: fixed` de adentro (Toaster, Drawer, ConfirmDialog).
|
|
48
|
+
*/
|
|
49
|
+
export declare function SidePanelLayout({ children, dockMinWidth, className, ref, ...rest }: SidePanelLayoutProps): import("react").JSX.Element;
|
|
50
|
+
/**
|
|
51
|
+
* Panel lateral no modal para la vista rápida de un registro: un `<aside>` nombrado por su título, al costado del
|
|
52
|
+
* contenido, sin velo y sin atrapar el foco. Se renderiza en cualquier lugar adentro de SidePanelLayout y se monta en su
|
|
53
|
+
* salida (portal). En el servidor no se renderiza: aparece al hidratar.
|
|
54
|
+
*/
|
|
55
|
+
export declare function SidePanel(props: SidePanelProps): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { IconButton } from '../icon-button/IconButton.js';
|
|
6
|
+
// 'use client' a propósito: el layout mide su ancho (ResizeObserver) y el panel usa estado, contexto, un portal y el
|
|
7
|
+
// teclado del documento. tsc conserva la directiva porque es la primera sentencia del archivo.
|
|
8
|
+
/**
|
|
9
|
+
* Ancho del layout, en px, desde el que el panel va acoplado (al lado del contenido, que se achica). Valor nuevo, sin
|
|
10
|
+
* token: deja al menos 660px de contenido con el panel de 440px. AUTORIZADO (Fede, 2026-11-23): confirmado sabiendo que
|
|
11
|
+
* D2.1 acopla el detalle desde 1680px (breakpoint app-dock).
|
|
12
|
+
*/
|
|
13
|
+
const DOCK_MIN_WIDTH = 1100;
|
|
14
|
+
const Ctx = createContext(null);
|
|
15
|
+
const cx = (own, extra) => (extra ? own + ' ' + extra : own);
|
|
16
|
+
const hasContent = (node) => node !== undefined && node !== null && typeof node !== 'boolean' && node !== '';
|
|
17
|
+
function mergeRefs(...refs) {
|
|
18
|
+
return (node) => {
|
|
19
|
+
for (const ref of refs) {
|
|
20
|
+
if (typeof ref === 'function')
|
|
21
|
+
ref(node);
|
|
22
|
+
else if (ref)
|
|
23
|
+
ref.current = node;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Lo que se escribe: si el foco está en uno de estos fuera del panel, Esc es del campo y el panel no se cierra. */
|
|
28
|
+
const EDITABLE = 'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
|
|
29
|
+
/**
|
|
30
|
+
* El armazón donde vive el panel: lo pone la app una sola vez, alrededor del `<main>` (no adentro: el `<aside>` es una
|
|
31
|
+
* región de la página). Mide su propio ancho con ResizeObserver (la primera vez antes de pintar) y lo expone en
|
|
32
|
+
* `data-docked`; `data-open` mientras haya un panel montado. Sin container queries: `container-type` haría del layout el
|
|
33
|
+
* bloque contenedor de todo lo `position: fixed` de adentro (Toaster, Drawer, ConfirmDialog).
|
|
34
|
+
*/
|
|
35
|
+
export function SidePanelLayout({ children, dockMinWidth = DOCK_MIN_WIDTH, className, ref, ...rest }) {
|
|
36
|
+
const root = useRef(null);
|
|
37
|
+
const [outlet, setOutlet] = useState(null);
|
|
38
|
+
const [docked, setDocked] = useState(false);
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
const el = root.current;
|
|
42
|
+
if (!el)
|
|
43
|
+
return;
|
|
44
|
+
const measure = () => { setDocked(el.getBoundingClientRect().width >= dockMinWidth); };
|
|
45
|
+
measure();
|
|
46
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
47
|
+
window.addEventListener('resize', measure);
|
|
48
|
+
return () => { window.removeEventListener('resize', measure); };
|
|
49
|
+
}
|
|
50
|
+
const observer = new ResizeObserver(measure);
|
|
51
|
+
observer.observe(el);
|
|
52
|
+
return () => { observer.disconnect(); };
|
|
53
|
+
}, [dockMinWidth]);
|
|
54
|
+
return (_jsx("div", { ...rest, ref: mergeRefs(root, ref), className: cx('dx-side-layout', className), "data-open": open ? 'true' : undefined, "data-docked": docked ? 'true' : 'false', children: _jsxs(Ctx, { value: { outlet, docked, setOpen }, children: [_jsx("div", { className: "dx-side-layout__main", children: children }), _jsx("div", { className: "dx-side-layout__outlet", ref: setOutlet })] }) }));
|
|
55
|
+
}
|
|
56
|
+
const ChevronUp = () => (_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", focusable: "false", children: _jsx("path", { d: "M4 10l4-4 4 4" }) }));
|
|
57
|
+
const ChevronDown = () => (_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", focusable: "false", children: _jsx("path", { d: "M4 6l4 4 4-4" }) }));
|
|
58
|
+
/** La × de Drawer. */
|
|
59
|
+
const CloseIcon = () => (_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", focusable: "false", children: _jsx("path", { d: "M4.5 4.5l7 7M11.5 4.5l-7 7" }) }));
|
|
60
|
+
/**
|
|
61
|
+
* Panel lateral no modal para la vista rápida de un registro: un `<aside>` nombrado por su título, al costado del
|
|
62
|
+
* contenido, sin velo y sin atrapar el foco. Se renderiza en cualquier lugar adentro de SidePanelLayout y se monta en su
|
|
63
|
+
* salida (portal). En el servidor no se renderiza: aparece al hidratar.
|
|
64
|
+
*/
|
|
65
|
+
export function SidePanel(props) {
|
|
66
|
+
const ctx = useContext(Ctx);
|
|
67
|
+
if (!ctx)
|
|
68
|
+
throw new Error('SidePanel tiene que ir dentro de <SidePanelLayout>.');
|
|
69
|
+
if (!ctx.outlet)
|
|
70
|
+
return null;
|
|
71
|
+
return createPortal(_jsx(Panel, { ...props, docked: ctx.docked, setOpen: ctx.setOpen }), ctx.outlet);
|
|
72
|
+
}
|
|
73
|
+
function Panel({ title, titleAside, subtitle, onClose, onPrevious, onNext, previousLabel = 'Anterior', nextLabel = 'Siguiente', closeLabel = 'Cerrar', actions, footer, recordKey, focusOnMount = true, children, className, docked, setOpen, }) {
|
|
74
|
+
const id = useId();
|
|
75
|
+
const titleId = id + '-titulo';
|
|
76
|
+
const subtitleId = id + '-bajada';
|
|
77
|
+
const aside = useRef(null);
|
|
78
|
+
const titleRef = useRef(null);
|
|
79
|
+
const body = useRef(null);
|
|
80
|
+
const live = useRef(null);
|
|
81
|
+
// Solo cuenta al montar: cambiar de registro no mueve el foco.
|
|
82
|
+
const [focusAtMount] = useState(focusOnMount);
|
|
83
|
+
const hasSubtitle = hasContent(subtitle);
|
|
84
|
+
const hasNav = onPrevious !== undefined || onNext !== undefined;
|
|
85
|
+
// Montado: data-open en el layout (el contenido se achica antes de pintar) y el foco. Al desmontar, el foco vuelve a quien
|
|
86
|
+
// lo tenía al montar si quedó adentro del panel o en el <body> (y ese elemento sigue en el DOM).
|
|
87
|
+
useLayoutEffect(() => {
|
|
88
|
+
const node = aside.current;
|
|
89
|
+
const active = document.activeElement;
|
|
90
|
+
const origin = active instanceof HTMLElement && active !== document.body ? active : null;
|
|
91
|
+
setOpen(true);
|
|
92
|
+
if (focusAtMount)
|
|
93
|
+
node?.focus({ preventScroll: true });
|
|
94
|
+
return () => {
|
|
95
|
+
setOpen(false);
|
|
96
|
+
const now = document.activeElement;
|
|
97
|
+
const lost = !now || now === document.body || (node?.contains(now) ?? false);
|
|
98
|
+
if (lost && origin?.isConnected)
|
|
99
|
+
origin.focus();
|
|
100
|
+
};
|
|
101
|
+
}, [focusAtMount, setOpen]);
|
|
102
|
+
// Otro registro con el panel abierto: el cuerpo vuelve arriba y la región anuncia el título nuevo (el foco queda donde está).
|
|
103
|
+
const shownKey = useRef(recordKey);
|
|
104
|
+
useLayoutEffect(() => {
|
|
105
|
+
if (shownKey.current === recordKey)
|
|
106
|
+
return;
|
|
107
|
+
shownKey.current = recordKey;
|
|
108
|
+
if (body.current)
|
|
109
|
+
body.current.scrollTop = 0;
|
|
110
|
+
if (live.current)
|
|
111
|
+
live.current.textContent = titleRef.current?.textContent ?? '';
|
|
112
|
+
}, [recordKey]);
|
|
113
|
+
// Esc desde cualquier lugar de la página. Un menú, un Select, un Popover o un diálogo abiertos (Radix) lo atienden
|
|
114
|
+
// primero con preventDefault y el panel queda; un campo editable de afuera se queda con su Esc.
|
|
115
|
+
const onEscape = useEffectEvent((event) => {
|
|
116
|
+
if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing)
|
|
117
|
+
return;
|
|
118
|
+
const target = event.target;
|
|
119
|
+
if (target instanceof Element && target.closest(EDITABLE) && !aside.current?.contains(target))
|
|
120
|
+
return;
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
onClose();
|
|
123
|
+
});
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const listener = (event) => { onEscape(event); };
|
|
126
|
+
document.addEventListener('keydown', listener);
|
|
127
|
+
return () => { document.removeEventListener('keydown', listener); };
|
|
128
|
+
}, []);
|
|
129
|
+
return (_jsxs("aside", { ref: aside, className: cx('dx-side-panel', className), "data-docked": docked ? 'true' : 'false', tabIndex: -1, "aria-labelledby": titleId, "aria-describedby": hasSubtitle ? subtitleId : undefined, children: [_jsxs("div", { className: "dx-side-panel__header", children: [_jsxs("div", { className: "dx-side-panel__tools", children: [_jsx("div", { className: "dx-side-panel__nav", children: hasNav && (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: "sm", label: previousLabel, icon: _jsx(ChevronUp, {}), tooltipSide: "bottom", disabled: !onPrevious, onClick: onPrevious }), _jsx(IconButton, { size: "sm", label: nextLabel, icon: _jsx(ChevronDown, {}), tooltipSide: "bottom", disabled: !onNext, onClick: onNext })] })) }), _jsxs("div", { className: "dx-side-panel__actions", children: [actions, _jsx(IconButton, { size: "sm", label: closeLabel, icon: _jsx(CloseIcon, {}), tooltipSide: "bottom", onClick: onClose })] })] }), _jsxs("div", { className: "dx-side-panel__heading", children: [_jsx("h2", { ref: titleRef, id: titleId, className: "dx-side-panel__title", children: title }), hasContent(titleAside) && _jsx("span", { className: "dx-side-panel__aside", children: titleAside })] }), hasSubtitle && _jsx("p", { id: subtitleId, className: "dx-side-panel__subtitle", children: subtitle })] }), _jsx("div", { ref: body, className: "dx-side-panel__body", children: children }), hasContent(footer) && _jsx("div", { className: "dx-side-panel__footer", children: footer }), _jsx("div", { ref: live, className: "dx-side-panel__live", "aria-live": "polite" })] }));
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SidePanel, SidePanelLayout } from './SidePanel.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef } from 'react';
|
|
2
|
+
export interface SkipLinkProps extends ComponentPropsWithRef<'a'> {
|
|
3
|
+
/** A dónde salta: el `id` del contenido principal, con `#`. Por defecto `#contenido`. */
|
|
4
|
+
href?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Enlace «Saltar al contenido»: el primer elemento enfocable de la página, que solo se ve con el foco del teclado, arriba a la
|
|
8
|
+
* izquierda. Lleva al contenido principal (por defecto `#contenido`) sin pasar por la barra lateral. El texto se cambia con
|
|
9
|
+
* `children`. `className` se suma a `dx-skip-link`; `ref` y el resto de las props van al `<a>`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function SkipLink({ href, children, className, ...rest }: SkipLinkProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Enlace «Saltar al contenido»: el primer elemento enfocable de la página, que solo se ve con el foco del teclado, arriba a la
|
|
4
|
+
* izquierda. Lleva al contenido principal (por defecto `#contenido`) sin pasar por la barra lateral. El texto se cambia con
|
|
5
|
+
* `children`. `className` se suma a `dx-skip-link`; `ref` y el resto de las props van al `<a>`.
|
|
6
|
+
*/
|
|
7
|
+
export function SkipLink({ href = '#contenido', children = 'Saltar al contenido', className, ...rest }) {
|
|
8
|
+
return (_jsx("a", { ...rest, href: href, className: className ? `dx-skip-link ${className}` : 'dx-skip-link', children: children }));
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SkipLink } from './SkipLink.js';
|