@dubix/ui 0.4.0 → 0.6.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 +348 -13
- package/dist/drawer/Drawer.d.ts +44 -0
- package/dist/drawer/Drawer.js +81 -0
- package/dist/drawer/index.d.ts +2 -0
- package/dist/drawer/index.js +1 -0
- package/dist/pagination/Pagination.d.ts +29 -0
- package/dist/pagination/Pagination.js +47 -0
- package/dist/pagination/index.d.ts +2 -0
- package/dist/pagination/index.js +1 -0
- package/dist/search-input/SearchInput.d.ts +19 -0
- package/dist/search-input/SearchInput.js +57 -0
- package/dist/search-input/index.d.ts +2 -0
- package/dist/search-input/index.js +1 -0
- package/dist/select/Select.d.ts +50 -0
- package/dist/select/Select.js +87 -0
- package/dist/select/index.d.ts +2 -0
- package/dist/select/index.js +1 -0
- package/dist/styles.css +679 -1
- package/dist/toast/Toast.d.ts +33 -0
- package/dist/toast/Toast.js +50 -0
- package/dist/toast/index.d.ts +2 -0
- package/dist/toast/index.js +1 -0
- package/package.json +21 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** Acción opcional del toast (p. ej. «Deshacer»). Al hacer clic llama a `alHacer` y cierra el toast. */
|
|
3
|
+
export interface ToastAccion {
|
|
4
|
+
/** Texto del botón. */
|
|
5
|
+
etiqueta: string;
|
|
6
|
+
alHacer: () => void;
|
|
7
|
+
/** Cómo hacer lo mismo sin el toast (p. ej. «Deshacer desde el historial»): el lector lo anuncia en lugar del botón. */
|
|
8
|
+
textoAlternativo: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ToastOpciones {
|
|
11
|
+
accion?: ToastAccion | undefined;
|
|
12
|
+
/** Milisegundos hasta que se cierra. Por defecto 2500; con acción, 5000. */
|
|
13
|
+
duracion?: number | undefined;
|
|
14
|
+
/** Ícono antes del texto (p. ej. de lucide-react); se renderiza con `aria-hidden`. */
|
|
15
|
+
icono?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export interface ToasterProps {
|
|
18
|
+
/** Se suma a `dx-toast__viewport` (la lista fija, abajo y centrada). */
|
|
19
|
+
className?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Muestra un aviso breve en el Toaster de la app y devuelve su id. Un toast nuevo reemplaza al anterior. Se llama desde
|
|
23
|
+
* un componente cliente (un manejador de eventos, un efecto), no durante el render.
|
|
24
|
+
*/
|
|
25
|
+
export declare const toast: ((mensaje: ReactNode, opciones?: ToastOpciones) => string) & {
|
|
26
|
+
cerrar: (id: string) => void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* El proveedor de los toasts: se monta una vez, en el layout de la app, dentro del elemento que fija el tema (`.dx-app`,
|
|
30
|
+
* `.dark` o `[data-theme="dark"]`). Muestra el toast de `toast()` abajo y centrado, sobre Toast de Radix: se cierra solo,
|
|
31
|
+
* se pausa con hover y con foco, F8 lleva el foco a la lista y el texto se anuncia sin mover el foco.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Toaster({ className }: ToasterProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { Toast as ToastPrimitive } from 'radix-ui';
|
|
5
|
+
/** Duraciones del DS v1 (ítem 19): un éxito, 2,5 s; con acción, 5 s para llegar a usarla. */
|
|
6
|
+
const DURACION = 2500;
|
|
7
|
+
const DURACION_CON_ACCION = 5000;
|
|
8
|
+
// Store del módulo: un solo toast por vez. Cerrar no lo saca: queda con open: false para que Radix anime la salida.
|
|
9
|
+
let actual = null;
|
|
10
|
+
let siguiente = 0;
|
|
11
|
+
const oyentes = new Set();
|
|
12
|
+
const avisar = () => { for (const oyente of oyentes)
|
|
13
|
+
oyente(); };
|
|
14
|
+
const suscribir = (oyente) => {
|
|
15
|
+
oyentes.add(oyente);
|
|
16
|
+
return () => { oyentes.delete(oyente); };
|
|
17
|
+
};
|
|
18
|
+
const leer = () => actual;
|
|
19
|
+
const leerEnServidor = () => null;
|
|
20
|
+
function cerrar(id) {
|
|
21
|
+
if (actual?.id !== id || !actual.open)
|
|
22
|
+
return;
|
|
23
|
+
actual = { ...actual, open: false };
|
|
24
|
+
avisar();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Muestra un aviso breve en el Toaster de la app y devuelve su id. Un toast nuevo reemplaza al anterior. Se llama desde
|
|
28
|
+
* un componente cliente (un manejador de eventos, un efecto), no durante el render.
|
|
29
|
+
*/
|
|
30
|
+
export const toast = Object.assign((mensaje, opciones = {}) => {
|
|
31
|
+
siguiente += 1;
|
|
32
|
+
const id = 'dx-toast-' + String(siguiente);
|
|
33
|
+
actual = { id, mensaje, opciones, open: true };
|
|
34
|
+
avisar();
|
|
35
|
+
return id;
|
|
36
|
+
}, { cerrar });
|
|
37
|
+
const CloseIcon = () => (_jsx("svg", { viewBox: "0 0 16 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" }) }));
|
|
38
|
+
/**
|
|
39
|
+
* El proveedor de los toasts: se monta una vez, en el layout de la app, dentro del elemento que fija el tema (`.dx-app`,
|
|
40
|
+
* `.dark` o `[data-theme="dark"]`). Muestra el toast de `toast()` abajo y centrado, sobre Toast de Radix: se cierra solo,
|
|
41
|
+
* se pausa con hover y con foco, F8 lleva el foco a la lista y el texto se anuncia sin mover el foco.
|
|
42
|
+
*/
|
|
43
|
+
export function Toaster({ className }) {
|
|
44
|
+
const item = useSyncExternalStore(suscribir, leer, leerEnServidor);
|
|
45
|
+
const accion = item?.opciones.accion;
|
|
46
|
+
return (_jsxs(ToastPrimitive.Provider, { label: "Aviso", children: [item && (_jsxs(ToastPrimitive.Root, { className: "dx-toast",
|
|
47
|
+
// background: el anuncio es aria-live="polite" (foreground sería assertive).
|
|
48
|
+
type: "background", open: item.open, onOpenChange: (open) => { if (!open)
|
|
49
|
+
cerrar(item.id); }, duration: item.opciones.duracion ?? (accion ? DURACION_CON_ACCION : DURACION), children: [item.opciones.icono !== undefined && _jsx("span", { className: "dx-toast__icon", "aria-hidden": "true", children: item.opciones.icono }), _jsx(ToastPrimitive.Title, { className: "dx-toast__message", children: item.mensaje }), accion && (_jsxs(_Fragment, { children: [_jsx(ToastPrimitive.Action, { className: "dx-toast__action", altText: accion.textoAlternativo, onClick: accion.alHacer, children: accion.etiqueta }), _jsx(ToastPrimitive.Close, { className: "dx-toast__close", "aria-label": "Cerrar", children: _jsx(CloseIcon, {}) })] }))] }, item.id)), _jsx(ToastPrimitive.Viewport, { className: className ? `dx-toast__viewport ${className}` : 'dx-toast__viewport', label: "Avisos ({hotkey})" })] }));
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Toaster, toast } from './Toast.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dubix/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Componentes React 19 de Dubix (D2 · Tinta, referencia D2.1) con CSS propio sobre las variables --dx-* de @dubix/tokens.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"types": "./dist/dropdown-menu/index.d.ts",
|
|
45
45
|
"default": "./dist/dropdown-menu/index.js"
|
|
46
46
|
},
|
|
47
|
+
"./drawer": {
|
|
48
|
+
"types": "./dist/drawer/index.d.ts",
|
|
49
|
+
"default": "./dist/drawer/index.js"
|
|
50
|
+
},
|
|
47
51
|
"./empty-state": {
|
|
48
52
|
"types": "./dist/empty-state/index.d.ts",
|
|
49
53
|
"default": "./dist/empty-state/index.js"
|
|
@@ -64,6 +68,18 @@
|
|
|
64
68
|
"types": "./dist/input/index.d.ts",
|
|
65
69
|
"default": "./dist/input/index.js"
|
|
66
70
|
},
|
|
71
|
+
"./pagination": {
|
|
72
|
+
"types": "./dist/pagination/index.d.ts",
|
|
73
|
+
"default": "./dist/pagination/index.js"
|
|
74
|
+
},
|
|
75
|
+
"./search-input": {
|
|
76
|
+
"types": "./dist/search-input/index.d.ts",
|
|
77
|
+
"default": "./dist/search-input/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./select": {
|
|
80
|
+
"types": "./dist/select/index.d.ts",
|
|
81
|
+
"default": "./dist/select/index.js"
|
|
82
|
+
},
|
|
67
83
|
"./sidebar": {
|
|
68
84
|
"types": "./dist/sidebar/index.d.ts",
|
|
69
85
|
"default": "./dist/sidebar/index.js"
|
|
@@ -88,6 +104,10 @@
|
|
|
88
104
|
"types": "./dist/textarea/index.d.ts",
|
|
89
105
|
"default": "./dist/textarea/index.js"
|
|
90
106
|
},
|
|
107
|
+
"./toast": {
|
|
108
|
+
"types": "./dist/toast/index.d.ts",
|
|
109
|
+
"default": "./dist/toast/index.js"
|
|
110
|
+
},
|
|
91
111
|
"./tooltip": {
|
|
92
112
|
"types": "./dist/tooltip/index.d.ts",
|
|
93
113
|
"default": "./dist/tooltip/index.js"
|