@rubenpazch/checkbox-input 3.2.5 → 3.3.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 +30 -4
- package/dist/CheckboxGroup.d.ts +58 -0
- package/dist/CheckboxGroup.d.ts.map +1 -0
- package/dist/index.cjs.js +91 -33
- package/dist/index.d.ts +59 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +86 -31
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@ Generated component package.
|
|
|
4
4
|
|
|
5
5
|
<!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
|
|
6
6
|
|
|
7
|
-
Casilla de verificación con etiqueta, ayuda y error.
|
|
7
|
+
Casilla de verificación con etiqueta, ayuda y error (CheckboxInput) y grupo de casillas con título, "Seleccionar todos" y máximo (CheckboxGroup).
|
|
8
8
|
|
|
9
|
-
- **Usar cuando:** Opciones sí/no o
|
|
10
|
-
- **Evitar cuando:** Elegir una sola opción entre varias: usa RadioGroup.
|
|
9
|
+
- **Usar cuando:** Opciones sí/no (CheckboxInput) o elegir varias opciones de una lista corta: permisos, días, especialidades (CheckboxGroup).
|
|
10
|
+
- **Evitar cuando:** Elegir una sola opción entre varias: usa RadioGroup. Listas largas o con búsqueda: usa Autocomplete. Activar/desactivar algo al instante: usa Switch.
|
|
11
11
|
|
|
12
12
|
Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
|
|
13
13
|
|
|
@@ -36,6 +36,32 @@ Casilla de verificación con etiqueta, descripción y error.
|
|
|
36
36
|
| `value` | `string` | | | Valor enviado con el formulario cuando está marcado. |
|
|
37
37
|
| `variant` | `"default" \| "primary" \| "success" \| "warning" \| "danger"` | | `default` | |
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
## CheckboxGroup
|
|
40
|
+
|
|
41
|
+
Grupo de casillas con título (`fieldset`/`legend`), ayuda y error: para elegir varias
|
|
42
|
+
opciones de una lista corta (permisos, días, especialidades).
|
|
43
|
+
|
|
44
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
45
|
+
| ------------- | -------------------------------------------------------------- | ---- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `label` | `string` | sí | | Título del grupo (se muestra como `<legend>` del `<fieldset>`). |
|
|
47
|
+
| `onChange` | `(value: string[]) => void` | sí | | Recibe la nueva lista de valores marcados (en el orden de `options`). |
|
|
48
|
+
| `options` | `CheckboxOption[]` | sí | | Opciones del grupo. |
|
|
49
|
+
| `value` | `string[]` | sí | | Valores marcados. |
|
|
50
|
+
| `className` | `string` | | | Clase extra del contenedor. |
|
|
51
|
+
| `columns` | `2 \| 3 \| 4` | | | Columnas en pantallas desde 640px (en móvil siempre 1). Ignora `orientation`. |
|
|
52
|
+
| `disabled` | `boolean` | | `false` | Deshabilita todo el grupo. |
|
|
53
|
+
| `error` | `string` | | | Mensaje de error del grupo. |
|
|
54
|
+
| `hideLabel` | `boolean` | | `false` | Ocultar el título visualmente (sigue disponible para lectores de pantalla). |
|
|
55
|
+
| `hint` | `string` | | | Texto de ayuda bajo el título. |
|
|
56
|
+
| `id` | `string` | | | id del fieldset; si no se pasa se genera uno. |
|
|
57
|
+
| `maxSelected` | `number` | | | Máximo de opciones marcadas: al llegar, las demás se deshabilitan. |
|
|
58
|
+
| `name` | `string` | | | name de cada casilla (formularios nativos: se envía una vez por valor marcado). |
|
|
59
|
+
| `orientation` | `"vertical" \| "horizontal"` | | `vertical` | `vertical` (por defecto) o `horizontal` (se ajusta a la siguiente línea). |
|
|
60
|
+
| `required` | `boolean` | | `false` | Marca el grupo como obligatorio (muestra *); la validación "al menos uno" va en `error`. |
|
|
61
|
+
| `selectAll` | `boolean \| string` | | `false` | Agrega una casilla "Seleccionar todos" (queda indeterminada si hay algunas marcadas). `true` usa el texto por defecto; un texto lo reemplaza. |
|
|
62
|
+
| `size` | `"sm" \| "md" \| "lg"` | | `md` | Tamaño de las casillas. |
|
|
63
|
+
| `variant` | `"default" \| "primary" \| "success" \| "warning" \| "danger"` | | `primary` | Color de las casillas marcadas. |
|
|
64
|
+
|
|
65
|
+
Tipos: `CheckboxInputProps`, `CheckboxGroupProps`, `CheckboxOption`.
|
|
40
66
|
|
|
41
67
|
<!-- catalogo:fin -->
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface CheckboxOption {
|
|
3
|
+
/** Texto visible de la casilla. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Valor que se agrega a la lista al marcarla. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Texto secundario bajo la etiqueta. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Deshabilita solo esta casilla. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckboxGroupProps {
|
|
13
|
+
/** Título del grupo (se muestra como `<legend>` del `<fieldset>`). */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Opciones del grupo. */
|
|
16
|
+
options: CheckboxOption[];
|
|
17
|
+
/** Valores marcados. */
|
|
18
|
+
value: string[];
|
|
19
|
+
/** Recibe la nueva lista de valores marcados (en el orden de `options`). */
|
|
20
|
+
onChange: (value: string[]) => void;
|
|
21
|
+
/** name de cada casilla (formularios nativos: se envía una vez por valor marcado). */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** `vertical` (por defecto) o `horizontal` (se ajusta a la siguiente línea). */
|
|
24
|
+
orientation?: "vertical" | "horizontal";
|
|
25
|
+
/** Columnas en pantallas desde 640px (en móvil siempre 1). Ignora `orientation`. */
|
|
26
|
+
columns?: 2 | 3 | 4;
|
|
27
|
+
/** Tamaño de las casillas. */
|
|
28
|
+
size?: "sm" | "md" | "lg";
|
|
29
|
+
/** Color de las casillas marcadas. */
|
|
30
|
+
variant?: "default" | "primary" | "success" | "warning" | "danger";
|
|
31
|
+
/** Deshabilita todo el grupo. */
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
/** Marca el grupo como obligatorio (muestra *); la validación "al menos uno" va en `error`. */
|
|
34
|
+
required?: boolean;
|
|
35
|
+
/** Texto de ayuda bajo el título. */
|
|
36
|
+
hint?: string;
|
|
37
|
+
/** Mensaje de error del grupo. */
|
|
38
|
+
error?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Agrega una casilla "Seleccionar todos" (queda indeterminada si hay algunas marcadas).
|
|
41
|
+
* `true` usa el texto por defecto; un texto lo reemplaza.
|
|
42
|
+
*/
|
|
43
|
+
selectAll?: boolean | string;
|
|
44
|
+
/** Máximo de opciones marcadas: al llegar, las demás se deshabilitan. */
|
|
45
|
+
maxSelected?: number;
|
|
46
|
+
/** Ocultar el título visualmente (sigue disponible para lectores de pantalla). */
|
|
47
|
+
hideLabel?: boolean;
|
|
48
|
+
/** Clase extra del contenedor. */
|
|
49
|
+
className?: string;
|
|
50
|
+
/** id del fieldset; si no se pasa se genera uno. */
|
|
51
|
+
id?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Grupo de casillas con título (`fieldset`/`legend`), ayuda y error: para elegir varias
|
|
55
|
+
* opciones de una lista corta (permisos, días, especialidades).
|
|
56
|
+
*/
|
|
57
|
+
export default function CheckboxGroup({ label, options, value, onChange, name, orientation, columns, size, variant, disabled, required, hint, error, selectAll, maxSelected, hideLabel, className, id, }: CheckboxGroupProps): React.JSX.Element;
|
|
58
|
+
//# sourceMappingURL=CheckboxGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CheckboxGroup.d.ts","sourceRoot":"","sources":["../src/CheckboxGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wBAAwB;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACpC,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC,oFAAoF;IACpF,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,8BAA8B;IAC9B,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,sCAAsC;IACtC,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACnE,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kFAAkF;IAClF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAKD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,WAAwB,EACxB,OAAO,EACP,IAAW,EACX,OAAmB,EACnB,QAAgB,EAChB,QAAgB,EAChB,IAAI,EACJ,KAAK,EACL,SAAiB,EACjB,WAAW,EACX,SAAiB,EACjB,SAAS,EACT,EAAE,GACH,EAAE,kBAAkB,qBAiHpB"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
4
6
|
var shared = require('@rubenpazch/shared');
|
|
5
7
|
|
|
6
8
|
var jsxRuntime = {exports: {}};
|
|
@@ -339,7 +341,7 @@ function requireReactJsxRuntime_development () {
|
|
|
339
341
|
object.$$typeof === REACT_ELEMENT_TYPE
|
|
340
342
|
);
|
|
341
343
|
}
|
|
342
|
-
var React =
|
|
344
|
+
var React$1 = React,
|
|
343
345
|
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
|
|
344
346
|
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
|
|
345
347
|
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
|
|
@@ -355,7 +357,7 @@ function requireReactJsxRuntime_development () {
|
|
|
355
357
|
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
|
|
356
358
|
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
|
|
357
359
|
ReactSharedInternals =
|
|
358
|
-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
360
|
+
React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
359
361
|
hasOwnProperty = Object.prototype.hasOwnProperty,
|
|
360
362
|
isArrayImpl = Array.isArray,
|
|
361
363
|
createTask = console.createTask
|
|
@@ -363,15 +365,15 @@ function requireReactJsxRuntime_development () {
|
|
|
363
365
|
: function () {
|
|
364
366
|
return null;
|
|
365
367
|
};
|
|
366
|
-
React = {
|
|
368
|
+
React$1 = {
|
|
367
369
|
react_stack_bottom_frame: function (callStackForError) {
|
|
368
370
|
return callStackForError();
|
|
369
371
|
}
|
|
370
372
|
};
|
|
371
373
|
var specialPropKeyWarningShown;
|
|
372
374
|
var didWarnAboutElementRef = {};
|
|
373
|
-
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
|
|
374
|
-
React,
|
|
375
|
+
var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
|
|
376
|
+
React$1,
|
|
375
377
|
UnknownOwner
|
|
376
378
|
)();
|
|
377
379
|
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
@@ -429,7 +431,7 @@ function styleInject(css, ref) {
|
|
|
429
431
|
if ( ref === void 0 ) ref = {};
|
|
430
432
|
var insertAt = ref.insertAt;
|
|
431
433
|
|
|
432
|
-
if (typeof document === 'undefined') { return; }
|
|
434
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
433
435
|
|
|
434
436
|
var head = document.head || document.getElementsByTagName('head')[0];
|
|
435
437
|
var style = document.createElement('style');
|
|
@@ -452,56 +454,112 @@ function styleInject(css, ref) {
|
|
|
452
454
|
}
|
|
453
455
|
}
|
|
454
456
|
|
|
455
|
-
var css_248z = ".CheckboxInput-module_wrapper__lJGfc {\n display: flex;\n align-items: flex-start;\n gap: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxContainer__ou1mg {\n display: flex;\n align-items: center;\n}\n\n.CheckboxInput-module_containerSm__zAmsB {\n height: 1rem;\n}\n\n.CheckboxInput-module_containerMd__lXzhK {\n height: 1.25rem;\n}\n\n.CheckboxInput-module_containerLg__ckD4Q {\n height: 1.5rem;\n}\n\n.CheckboxInput-module_checkbox__lYmgh {\n border: 1px solid var(--lb-color-neutral-300);\n border-radius: 0.25rem;\n background: var(--lb-color-background);\n cursor: pointer;\n transition: all 150ms ease;\n accent-color: var(--checkbox-color, var(--lb-color-primary));\n}\n\n.CheckboxInput-module_checkbox__lYmgh:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px\n var(\n --focus-ring,\n color-mix(in srgb, var(--lb-color-primary) 30%, transparent)\n );\n}\n\n.CheckboxInput-module_checkboxDisabled__B4hsr {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n opacity: 0.6;\n}\n\n.CheckboxInput-module_checkboxError__IAnd9 {\n border-color: var(--lb-color-danger);\n}\n\n.CheckboxInput-module_checkboxSm__h9Yfl {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxMd__Xn47v {\n width: 1rem;\n height: 1rem;\n}\n\n.CheckboxInput-module_checkboxLg__31itM {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.CheckboxInput-module_variantDefault__kOFV4 {\n --checkbox-color: var(--lb-color-primary);\n --focus-ring: color-mix(in srgb, var(--lb-color-primary) 30%, transparent);\n}\n\n.CheckboxInput-module_variantPrimary__oOcxM {\n --checkbox-color: var(--lb-color-indigo-accent);\n --focus-ring: rgba(79, 70, 229, 0.3);\n}\n\n.CheckboxInput-module_variantSuccess__Do-4i {\n --checkbox-color: var(--lb-color-success);\n --focus-ring: color-mix(in srgb, var(--lb-color-success) 30%, transparent);\n}\n\n.CheckboxInput-module_variantWarning__3-Z0F {\n --checkbox-color: var(--lb-color-warning);\n --focus-ring: color-mix(in srgb, var(--lb-color-warning) 30%, transparent);\n}\n\n.CheckboxInput-module_variantDanger__617R7 {\n --checkbox-color: var(--lb-color-danger);\n --focus-ring: color-mix(in srgb, var(--lb-color-danger) 30%, transparent);\n}\n\n.CheckboxInput-module_content__Qf9er {\n display: flex;\n flex-direction: column;\n}\n\n.CheckboxInput-module_label__rdC0e {\n font-weight: 500;\n}\n\n.CheckboxInput-module_labelSm__8m4I8 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_labelMd__LpiV4 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_labelLg__CZ1q0 {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.CheckboxInput-module_labelNormal__DxrKv {\n color: var(--lb-color-neutral-700);\n cursor: pointer;\n}\n\n.CheckboxInput-module_labelDisabled__wUItt {\n color: var(--lb-color-muted-foreground);\n cursor: not-allowed;\n}\n\n.CheckboxInput-module_required__hNTK3 {\n color: var(--lb-color-red-accent);\n margin-left: 0.25rem;\n}\n\n.CheckboxInput-module_description__cwaQ6 {\n color: var(--lb-color-neutral-500);\n margin-top: 0.25rem;\n}\n\n.CheckboxInput-module_descriptionSm__cdniJ {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.CheckboxInput-module_descriptionMd__21Bdi {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_descriptionLg__qCwRF {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_errorText__r7ffs {\n margin-top: 0.25rem;\n font-size: 0.75rem;\n line-height: 1rem;\n color: var(--lb-color-danger);\n}\n";
|
|
456
|
-
var styles = {"wrapper":"CheckboxInput-module_wrapper__lJGfc","checkboxContainer":"CheckboxInput-module_checkboxContainer__ou1mg","containerSm":"CheckboxInput-module_containerSm__zAmsB","containerMd":"CheckboxInput-module_containerMd__lXzhK","containerLg":"CheckboxInput-module_containerLg__ckD4Q","checkbox":"CheckboxInput-module_checkbox__lYmgh","checkboxDisabled":"CheckboxInput-module_checkboxDisabled__B4hsr","checkboxError":"CheckboxInput-module_checkboxError__IAnd9","checkboxSm":"CheckboxInput-module_checkboxSm__h9Yfl","checkboxMd":"CheckboxInput-module_checkboxMd__Xn47v","checkboxLg":"CheckboxInput-module_checkboxLg__31itM","variantDefault":"CheckboxInput-module_variantDefault__kOFV4","variantPrimary":"CheckboxInput-module_variantPrimary__oOcxM","variantSuccess":"CheckboxInput-module_variantSuccess__Do-4i","variantWarning":"CheckboxInput-module_variantWarning__3-Z0F","variantDanger":"CheckboxInput-module_variantDanger__617R7","content":"CheckboxInput-module_content__Qf9er","label":"CheckboxInput-module_label__rdC0e","labelSm":"CheckboxInput-module_labelSm__8m4I8","labelMd":"CheckboxInput-module_labelMd__LpiV4","labelLg":"CheckboxInput-module_labelLg__CZ1q0","labelNormal":"CheckboxInput-module_labelNormal__DxrKv","labelDisabled":"CheckboxInput-module_labelDisabled__wUItt","required":"CheckboxInput-module_required__hNTK3","description":"CheckboxInput-module_description__cwaQ6","descriptionSm":"CheckboxInput-module_descriptionSm__cdniJ","descriptionMd":"CheckboxInput-module_descriptionMd__21Bdi","descriptionLg":"CheckboxInput-module_descriptionLg__qCwRF","errorText":"CheckboxInput-module_errorText__r7ffs"};
|
|
457
|
-
styleInject(css_248z);
|
|
457
|
+
var css_248z$1 = ".CheckboxInput-module_wrapper__lJGfc {\n display: flex;\n align-items: flex-start;\n gap: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxContainer__ou1mg {\n display: flex;\n align-items: center;\n}\n\n.CheckboxInput-module_containerSm__zAmsB {\n height: 1rem;\n}\n\n.CheckboxInput-module_containerMd__lXzhK {\n height: 1.25rem;\n}\n\n.CheckboxInput-module_containerLg__ckD4Q {\n height: 1.5rem;\n}\n\n.CheckboxInput-module_checkbox__lYmgh {\n border: 1px solid var(--lb-color-neutral-300);\n border-radius: 0.25rem;\n background: var(--lb-color-background);\n cursor: pointer;\n transition: all 150ms ease;\n accent-color: var(--checkbox-color, var(--lb-color-primary));\n}\n\n.CheckboxInput-module_checkbox__lYmgh:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px\n var(\n --focus-ring,\n color-mix(in srgb, var(--lb-color-primary) 30%, transparent)\n );\n}\n\n.CheckboxInput-module_checkboxDisabled__B4hsr {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n opacity: 0.6;\n}\n\n.CheckboxInput-module_checkboxError__IAnd9 {\n border-color: var(--lb-color-danger);\n}\n\n.CheckboxInput-module_checkboxSm__h9Yfl {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxMd__Xn47v {\n width: 1rem;\n height: 1rem;\n}\n\n.CheckboxInput-module_checkboxLg__31itM {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.CheckboxInput-module_variantDefault__kOFV4 {\n --checkbox-color: var(--lb-color-primary);\n --focus-ring: color-mix(in srgb, var(--lb-color-primary) 30%, transparent);\n}\n\n.CheckboxInput-module_variantPrimary__oOcxM {\n --checkbox-color: var(--lb-color-indigo-accent);\n --focus-ring: rgba(79, 70, 229, 0.3);\n}\n\n.CheckboxInput-module_variantSuccess__Do-4i {\n --checkbox-color: var(--lb-color-success);\n --focus-ring: color-mix(in srgb, var(--lb-color-success) 30%, transparent);\n}\n\n.CheckboxInput-module_variantWarning__3-Z0F {\n --checkbox-color: var(--lb-color-warning);\n --focus-ring: color-mix(in srgb, var(--lb-color-warning) 30%, transparent);\n}\n\n.CheckboxInput-module_variantDanger__617R7 {\n --checkbox-color: var(--lb-color-danger);\n --focus-ring: color-mix(in srgb, var(--lb-color-danger) 30%, transparent);\n}\n\n.CheckboxInput-module_content__Qf9er {\n display: flex;\n flex-direction: column;\n}\n\n.CheckboxInput-module_label__rdC0e {\n font-weight: 500;\n}\n\n.CheckboxInput-module_labelSm__8m4I8 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_labelMd__LpiV4 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_labelLg__CZ1q0 {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.CheckboxInput-module_labelNormal__DxrKv {\n color: var(--lb-color-neutral-700);\n cursor: pointer;\n}\n\n.CheckboxInput-module_labelDisabled__wUItt {\n color: var(--lb-color-muted-foreground);\n cursor: not-allowed;\n}\n\n.CheckboxInput-module_required__hNTK3 {\n color: var(--lb-color-red-accent);\n margin-left: 0.25rem;\n}\n\n.CheckboxInput-module_description__cwaQ6 {\n color: var(--lb-color-neutral-500);\n margin-top: 0.25rem;\n}\n\n.CheckboxInput-module_descriptionSm__cdniJ {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.CheckboxInput-module_descriptionMd__21Bdi {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_descriptionLg__qCwRF {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_errorText__r7ffs {\n margin-top: 0.25rem;\n font-size: 0.75rem;\n line-height: 1rem;\n color: var(--lb-color-danger);\n}\n";
|
|
458
|
+
var styles$1 = {"wrapper":"CheckboxInput-module_wrapper__lJGfc","checkboxContainer":"CheckboxInput-module_checkboxContainer__ou1mg","containerSm":"CheckboxInput-module_containerSm__zAmsB","containerMd":"CheckboxInput-module_containerMd__lXzhK","containerLg":"CheckboxInput-module_containerLg__ckD4Q","checkbox":"CheckboxInput-module_checkbox__lYmgh","checkboxDisabled":"CheckboxInput-module_checkboxDisabled__B4hsr","checkboxError":"CheckboxInput-module_checkboxError__IAnd9","checkboxSm":"CheckboxInput-module_checkboxSm__h9Yfl","checkboxMd":"CheckboxInput-module_checkboxMd__Xn47v","checkboxLg":"CheckboxInput-module_checkboxLg__31itM","variantDefault":"CheckboxInput-module_variantDefault__kOFV4","variantPrimary":"CheckboxInput-module_variantPrimary__oOcxM","variantSuccess":"CheckboxInput-module_variantSuccess__Do-4i","variantWarning":"CheckboxInput-module_variantWarning__3-Z0F","variantDanger":"CheckboxInput-module_variantDanger__617R7","content":"CheckboxInput-module_content__Qf9er","label":"CheckboxInput-module_label__rdC0e","labelSm":"CheckboxInput-module_labelSm__8m4I8","labelMd":"CheckboxInput-module_labelMd__LpiV4","labelLg":"CheckboxInput-module_labelLg__CZ1q0","labelNormal":"CheckboxInput-module_labelNormal__DxrKv","labelDisabled":"CheckboxInput-module_labelDisabled__wUItt","required":"CheckboxInput-module_required__hNTK3","description":"CheckboxInput-module_description__cwaQ6","descriptionSm":"CheckboxInput-module_descriptionSm__cdniJ","descriptionMd":"CheckboxInput-module_descriptionMd__21Bdi","descriptionLg":"CheckboxInput-module_descriptionLg__qCwRF","errorText":"CheckboxInput-module_errorText__r7ffs"};
|
|
459
|
+
styleInject(css_248z$1);
|
|
458
460
|
|
|
459
461
|
const sizeClasses = {
|
|
460
462
|
sm: {
|
|
461
|
-
checkbox: styles.checkboxSm,
|
|
462
|
-
label: styles.labelSm,
|
|
463
|
-
description: styles.descriptionSm,
|
|
464
|
-
container: styles.containerSm,
|
|
463
|
+
checkbox: styles$1.checkboxSm,
|
|
464
|
+
label: styles$1.labelSm,
|
|
465
|
+
description: styles$1.descriptionSm,
|
|
466
|
+
container: styles$1.containerSm,
|
|
465
467
|
},
|
|
466
468
|
md: {
|
|
467
|
-
checkbox: styles.checkboxMd,
|
|
468
|
-
label: styles.labelMd,
|
|
469
|
-
description: styles.descriptionMd,
|
|
470
|
-
container: styles.containerMd,
|
|
469
|
+
checkbox: styles$1.checkboxMd,
|
|
470
|
+
label: styles$1.labelMd,
|
|
471
|
+
description: styles$1.descriptionMd,
|
|
472
|
+
container: styles$1.containerMd,
|
|
471
473
|
},
|
|
472
474
|
lg: {
|
|
473
|
-
checkbox: styles.checkboxLg,
|
|
474
|
-
label: styles.labelLg,
|
|
475
|
-
description: styles.descriptionLg,
|
|
476
|
-
container: styles.containerLg,
|
|
475
|
+
checkbox: styles$1.checkboxLg,
|
|
476
|
+
label: styles$1.labelLg,
|
|
477
|
+
description: styles$1.descriptionLg,
|
|
478
|
+
container: styles$1.containerLg,
|
|
477
479
|
},
|
|
478
480
|
};
|
|
479
481
|
const variantClasses = {
|
|
480
|
-
default: styles.variantDefault,
|
|
481
|
-
primary: styles.variantPrimary,
|
|
482
|
-
success: styles.variantSuccess,
|
|
483
|
-
warning: styles.variantWarning,
|
|
484
|
-
danger: styles.variantDanger,
|
|
482
|
+
default: styles$1.variantDefault,
|
|
483
|
+
primary: styles$1.variantPrimary,
|
|
484
|
+
success: styles$1.variantSuccess,
|
|
485
|
+
warning: styles$1.variantWarning,
|
|
486
|
+
danger: styles$1.variantDanger,
|
|
485
487
|
};
|
|
486
488
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
487
489
|
/** Casilla de verificación con etiqueta, descripción y error. */
|
|
488
|
-
const CheckboxInput =
|
|
490
|
+
const CheckboxInput = React.forwardRef(function CheckboxInput({ id, name, value, label, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", indeterminate = false, }, ref) {
|
|
489
491
|
const field = shared.useFieldIds({ id, name, required, error, hint: description });
|
|
490
492
|
const sizeConfig = sizeClasses[size];
|
|
491
493
|
const variantConfig = variantClasses[variant];
|
|
492
|
-
const checkboxRef =
|
|
493
|
-
|
|
494
|
+
const checkboxRef = React.useRef(null);
|
|
495
|
+
React.useEffect(() => {
|
|
494
496
|
if (checkboxRef.current) {
|
|
495
497
|
checkboxRef.current.indeterminate = indeterminate;
|
|
496
498
|
}
|
|
497
499
|
}, [indeterminate]);
|
|
498
|
-
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles.wrapper, className), children: [jsxRuntimeExports.jsx("div", { className: classNames(styles.checkboxContainer, sizeConfig.container), children: jsxRuntimeExports.jsx("input", { ref: shared.mergeRefs(checkboxRef, ref), ...field.controlProps, name: name, value: value, type: "checkbox", checked: checked, "aria-checked": indeterminate ? "mixed" : undefined, onChange: (e) => {
|
|
500
|
+
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.wrapper, className), children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.checkboxContainer, sizeConfig.container), children: jsxRuntimeExports.jsx("input", { ref: shared.mergeRefs(checkboxRef, ref), ...field.controlProps, name: name, value: value, type: "checkbox", checked: checked, "aria-checked": indeterminate ? "mixed" : undefined, onChange: (e) => {
|
|
499
501
|
if (disabled) {
|
|
500
502
|
return;
|
|
501
503
|
}
|
|
502
504
|
onChange?.(e.target.checked);
|
|
503
|
-
}, disabled: disabled, className: classNames(styles.checkbox, sizeConfig.checkbox, variantConfig, disabled && styles.checkboxDisabled, error && styles.checkboxError), required: required }) }), jsxRuntimeExports.jsxs("div", { className: styles.content, children: [jsxRuntimeExports.jsxs("label", { htmlFor: field.inputId, className: classNames(styles.label, sizeConfig.label, disabled ? styles.labelDisabled : styles.labelNormal), children: [label, required && (jsxRuntimeExports.jsx("span", { className: styles.required, "aria-hidden": "true", children: "*" }))] }), description && (jsxRuntimeExports.jsx("p", { id: field.hintId, className: classNames(styles.description, sizeConfig.description), children: description })), error && (jsxRuntimeExports.jsx("p", { id: field.errorId, className: styles.errorText, role: "alert", children: error }))] })] }));
|
|
505
|
+
}, disabled: disabled, className: classNames(styles$1.checkbox, sizeConfig.checkbox, variantConfig, disabled && styles$1.checkboxDisabled, error && styles$1.checkboxError), required: required }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.content, children: [jsxRuntimeExports.jsxs("label", { htmlFor: field.inputId, className: classNames(styles$1.label, sizeConfig.label, disabled ? styles$1.labelDisabled : styles$1.labelNormal), children: [label, required && (jsxRuntimeExports.jsx("span", { className: styles$1.required, "aria-hidden": "true", children: "*" }))] }), description && (jsxRuntimeExports.jsx("p", { id: field.hintId, className: classNames(styles$1.description, sizeConfig.description), children: description })), error && (jsxRuntimeExports.jsx("p", { id: field.errorId, className: styles$1.errorText, role: "alert", children: error }))] })] }));
|
|
504
506
|
});
|
|
505
507
|
CheckboxInput.displayName = "CheckboxInput";
|
|
506
508
|
|
|
507
|
-
|
|
509
|
+
var css_248z = ".CheckboxGroup-module_fieldset__5eB3Z {\n min-inline-size: 0;\n margin: 0;\n padding: 0;\n border: 0;\n font-family: var(--lb-font-sans);\n}\n\n.CheckboxGroup-module_legend__pNuxN {\n margin-bottom: var(--lb-space-2);\n padding: 0;\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n.CheckboxGroup-module_required__2lbzi {\n color: var(--lb-color-danger);\n}\n\n.CheckboxGroup-module_hint__2Pl7J {\n margin: 0 0 var(--lb-space-3);\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n}\n\n.CheckboxGroup-module_selectAll__qdf1U {\n margin-bottom: var(--lb-space-3);\n padding-bottom: var(--lb-space-3);\n border-bottom: 1px solid var(--lb-color-border);\n}\n\n.CheckboxGroup-module_vertical__D-Dlk {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.CheckboxGroup-module_horizontal__T8rDx {\n display: flex;\n flex-wrap: wrap;\n gap: var(--lb-space-3) var(--lb-space-6);\n}\n\n.CheckboxGroup-module_columns__ao0Db {\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n gap: var(--lb-space-3) var(--lb-space-6);\n}\n\n@media (min-width: 640px) {\n .CheckboxGroup-module_cols2__RdYv0 {\n grid-template-columns: repeat(2, minmax(0, 1fr));\n }\n .CheckboxGroup-module_cols3__03Tcs {\n grid-template-columns: repeat(3, minmax(0, 1fr));\n }\n .CheckboxGroup-module_cols4__sI6xr {\n grid-template-columns: repeat(4, minmax(0, 1fr));\n }\n}\n\n.CheckboxGroup-module_error__Y6n9J {\n margin: var(--lb-space-2) 0 0;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-danger);\n}\n\n.CheckboxGroup-module_srOnly__QdgTc {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n}\n";
|
|
510
|
+
var styles = {"fieldset":"CheckboxGroup-module_fieldset__5eB3Z","legend":"CheckboxGroup-module_legend__pNuxN","required":"CheckboxGroup-module_required__2lbzi","hint":"CheckboxGroup-module_hint__2Pl7J","selectAll":"CheckboxGroup-module_selectAll__qdf1U","vertical":"CheckboxGroup-module_vertical__D-Dlk","horizontal":"CheckboxGroup-module_horizontal__T8rDx","columns":"CheckboxGroup-module_columns__ao0Db","cols2":"CheckboxGroup-module_cols2__RdYv0","cols3":"CheckboxGroup-module_cols3__03Tcs","cols4":"CheckboxGroup-module_cols4__sI6xr","error":"CheckboxGroup-module_error__Y6n9J","srOnly":"CheckboxGroup-module_srOnly__QdgTc"};
|
|
511
|
+
styleInject(css_248z);
|
|
512
|
+
|
|
513
|
+
const cx = (...c) => c.filter(Boolean).join(" ");
|
|
514
|
+
/**
|
|
515
|
+
* Grupo de casillas con título (`fieldset`/`legend`), ayuda y error: para elegir varias
|
|
516
|
+
* opciones de una lista corta (permisos, días, especialidades).
|
|
517
|
+
*/
|
|
518
|
+
function CheckboxGroup({ label, options, value, onChange, name, orientation = "vertical", columns, size = "md", variant = "primary", disabled = false, required = false, hint, error, selectAll = false, maxSelected, hideLabel = false, className, id, }) {
|
|
519
|
+
const generado = React.useId();
|
|
520
|
+
const baseId = id ?? `checkbox-group-${generado}`;
|
|
521
|
+
const hintId = `${baseId}-ayuda`;
|
|
522
|
+
const errorId = `${baseId}-error`;
|
|
523
|
+
const describedBy = [hint && hintId, error && errorId].filter(Boolean).join(" ") || undefined;
|
|
524
|
+
const marcados = new Set(value);
|
|
525
|
+
const habilitadas = options.filter((o) => !o.disabled);
|
|
526
|
+
const lleno = maxSelected !== undefined && marcados.size >= maxSelected;
|
|
527
|
+
const cambiar = (valor, marcar) => {
|
|
528
|
+
const siguiente = new Set(marcados);
|
|
529
|
+
if (marcar)
|
|
530
|
+
siguiente.add(valor);
|
|
531
|
+
else
|
|
532
|
+
siguiente.delete(valor);
|
|
533
|
+
// Orden estable: el de las opciones; se conservan valores que no estén en options.
|
|
534
|
+
const enOpciones = options
|
|
535
|
+
.map((o) => o.value)
|
|
536
|
+
.filter((v) => siguiente.has(v));
|
|
537
|
+
const otros = value.filter((v) => siguiente.has(v) && !options.some((o) => o.value === v));
|
|
538
|
+
onChange([...enOpciones, ...otros]);
|
|
539
|
+
};
|
|
540
|
+
const todasMarcadas = habilitadas.length > 0 && habilitadas.every((o) => marcados.has(o.value));
|
|
541
|
+
const algunaMarcada = habilitadas.some((o) => marcados.has(o.value));
|
|
542
|
+
const alternarTodas = (marcar) => {
|
|
543
|
+
const habilitadasSet = new Set(habilitadas.map((o) => o.value));
|
|
544
|
+
const conservar = value.filter((v) => !habilitadasSet.has(v));
|
|
545
|
+
let nuevas = marcar ? habilitadas.map((o) => o.value) : [];
|
|
546
|
+
if (marcar && maxSelected !== undefined)
|
|
547
|
+
nuevas = nuevas.slice(0, Math.max(0, maxSelected - conservar.length));
|
|
548
|
+
const resultado = new Set([...conservar, ...nuevas]);
|
|
549
|
+
onChange([
|
|
550
|
+
...options.map((o) => o.value).filter((v) => resultado.has(v)),
|
|
551
|
+
...conservar.filter((v) => !options.some((o) => o.value === v)),
|
|
552
|
+
]);
|
|
553
|
+
};
|
|
554
|
+
return (jsxRuntimeExports.jsxs("fieldset", { id: baseId, className: cx(styles.fieldset, className), disabled: disabled, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined, children: [jsxRuntimeExports.jsxs("legend", { className: cx(styles.legend, hideLabel && styles.srOnly), children: [label, required && (jsxRuntimeExports.jsxs("span", { className: styles.required, "aria-hidden": "true", children: [" ", "*"] }))] }), hint && (jsxRuntimeExports.jsx("p", { id: hintId, className: styles.hint, children: hint })), selectAll && (jsxRuntimeExports.jsx("div", { className: styles.selectAll, children: jsxRuntimeExports.jsx(CheckboxInput, { label: typeof selectAll === "string" ? selectAll : "Seleccionar todos", checked: todasMarcadas, indeterminate: algunaMarcada && !todasMarcadas, onChange: alternarTodas, size: size, variant: variant, disabled: disabled }) })), jsxRuntimeExports.jsx("div", { className: cx(columns
|
|
555
|
+
? cx(styles.columns, styles[`cols${columns}`])
|
|
556
|
+
: orientation === "horizontal"
|
|
557
|
+
? styles.horizontal
|
|
558
|
+
: styles.vertical), children: options.map((o) => {
|
|
559
|
+
const marcada = marcados.has(o.value);
|
|
560
|
+
return (jsxRuntimeExports.jsx(CheckboxInput, { name: name, value: o.value, label: o.label, description: o.description, checked: marcada, onChange: (c) => cambiar(o.value, c), disabled: disabled || o.disabled || (lleno && !marcada), size: size, variant: variant }, o.value));
|
|
561
|
+
}) }), error && (jsxRuntimeExports.jsx("p", { id: errorId, className: styles.error, role: "alert", children: error }))] }));
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
exports.CheckboxGroup = CheckboxGroup;
|
|
565
|
+
exports.default = CheckboxInput;
|
package/dist/index.d.ts
CHANGED
|
@@ -24,5 +24,62 @@ interface CheckboxInputProps {
|
|
|
24
24
|
/** Casilla de verificación con etiqueta, descripción y error. */
|
|
25
25
|
declare const CheckboxInput: React.ForwardRefExoticComponent<CheckboxInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
interface CheckboxOption {
|
|
28
|
+
/** Texto visible de la casilla. */
|
|
29
|
+
label: string;
|
|
30
|
+
/** Valor que se agrega a la lista al marcarla. */
|
|
31
|
+
value: string;
|
|
32
|
+
/** Texto secundario bajo la etiqueta. */
|
|
33
|
+
description?: string;
|
|
34
|
+
/** Deshabilita solo esta casilla. */
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface CheckboxGroupProps {
|
|
38
|
+
/** Título del grupo (se muestra como `<legend>` del `<fieldset>`). */
|
|
39
|
+
label: string;
|
|
40
|
+
/** Opciones del grupo. */
|
|
41
|
+
options: CheckboxOption[];
|
|
42
|
+
/** Valores marcados. */
|
|
43
|
+
value: string[];
|
|
44
|
+
/** Recibe la nueva lista de valores marcados (en el orden de `options`). */
|
|
45
|
+
onChange: (value: string[]) => void;
|
|
46
|
+
/** name de cada casilla (formularios nativos: se envía una vez por valor marcado). */
|
|
47
|
+
name?: string;
|
|
48
|
+
/** `vertical` (por defecto) o `horizontal` (se ajusta a la siguiente línea). */
|
|
49
|
+
orientation?: "vertical" | "horizontal";
|
|
50
|
+
/** Columnas en pantallas desde 640px (en móvil siempre 1). Ignora `orientation`. */
|
|
51
|
+
columns?: 2 | 3 | 4;
|
|
52
|
+
/** Tamaño de las casillas. */
|
|
53
|
+
size?: "sm" | "md" | "lg";
|
|
54
|
+
/** Color de las casillas marcadas. */
|
|
55
|
+
variant?: "default" | "primary" | "success" | "warning" | "danger";
|
|
56
|
+
/** Deshabilita todo el grupo. */
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
/** Marca el grupo como obligatorio (muestra *); la validación "al menos uno" va en `error`. */
|
|
59
|
+
required?: boolean;
|
|
60
|
+
/** Texto de ayuda bajo el título. */
|
|
61
|
+
hint?: string;
|
|
62
|
+
/** Mensaje de error del grupo. */
|
|
63
|
+
error?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Agrega una casilla "Seleccionar todos" (queda indeterminada si hay algunas marcadas).
|
|
66
|
+
* `true` usa el texto por defecto; un texto lo reemplaza.
|
|
67
|
+
*/
|
|
68
|
+
selectAll?: boolean | string;
|
|
69
|
+
/** Máximo de opciones marcadas: al llegar, las demás se deshabilitan. */
|
|
70
|
+
maxSelected?: number;
|
|
71
|
+
/** Ocultar el título visualmente (sigue disponible para lectores de pantalla). */
|
|
72
|
+
hideLabel?: boolean;
|
|
73
|
+
/** Clase extra del contenedor. */
|
|
74
|
+
className?: string;
|
|
75
|
+
/** id del fieldset; si no se pasa se genera uno. */
|
|
76
|
+
id?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Grupo de casillas con título (`fieldset`/`legend`), ayuda y error: para elegir varias
|
|
80
|
+
* opciones de una lista corta (permisos, días, especialidades).
|
|
81
|
+
*/
|
|
82
|
+
declare function CheckboxGroup({ label, options, value, onChange, name, orientation, columns, size, variant, disabled, required, hint, error, selectAll, maxSelected, hideLabel, className, id, }: CheckboxGroupProps): React.JSX.Element;
|
|
83
|
+
|
|
84
|
+
export { CheckboxGroup, CheckboxInput as default };
|
|
85
|
+
export type { CheckboxGroupProps, CheckboxInputProps, CheckboxOption };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
2
|
import { useFieldIds, mergeRefs } from '@rubenpazch/shared';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = {exports: {}};
|
|
@@ -337,7 +337,7 @@ function requireReactJsxRuntime_development () {
|
|
|
337
337
|
object.$$typeof === REACT_ELEMENT_TYPE
|
|
338
338
|
);
|
|
339
339
|
}
|
|
340
|
-
var React =
|
|
340
|
+
var React$1 = React,
|
|
341
341
|
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
|
|
342
342
|
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
|
|
343
343
|
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
|
|
@@ -353,7 +353,7 @@ function requireReactJsxRuntime_development () {
|
|
|
353
353
|
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
|
|
354
354
|
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
|
|
355
355
|
ReactSharedInternals =
|
|
356
|
-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
356
|
+
React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
357
357
|
hasOwnProperty = Object.prototype.hasOwnProperty,
|
|
358
358
|
isArrayImpl = Array.isArray,
|
|
359
359
|
createTask = console.createTask
|
|
@@ -361,15 +361,15 @@ function requireReactJsxRuntime_development () {
|
|
|
361
361
|
: function () {
|
|
362
362
|
return null;
|
|
363
363
|
};
|
|
364
|
-
React = {
|
|
364
|
+
React$1 = {
|
|
365
365
|
react_stack_bottom_frame: function (callStackForError) {
|
|
366
366
|
return callStackForError();
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
var specialPropKeyWarningShown;
|
|
370
370
|
var didWarnAboutElementRef = {};
|
|
371
|
-
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
|
|
372
|
-
React,
|
|
371
|
+
var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
|
|
372
|
+
React$1,
|
|
373
373
|
UnknownOwner
|
|
374
374
|
)();
|
|
375
375
|
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
@@ -427,7 +427,7 @@ function styleInject(css, ref) {
|
|
|
427
427
|
if ( ref === void 0 ) ref = {};
|
|
428
428
|
var insertAt = ref.insertAt;
|
|
429
429
|
|
|
430
|
-
if (typeof document === 'undefined') { return; }
|
|
430
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
431
431
|
|
|
432
432
|
var head = document.head || document.getElementsByTagName('head')[0];
|
|
433
433
|
var style = document.createElement('style');
|
|
@@ -450,40 +450,40 @@ function styleInject(css, ref) {
|
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
var css_248z = ".CheckboxInput-module_wrapper__lJGfc {\n display: flex;\n align-items: flex-start;\n gap: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxContainer__ou1mg {\n display: flex;\n align-items: center;\n}\n\n.CheckboxInput-module_containerSm__zAmsB {\n height: 1rem;\n}\n\n.CheckboxInput-module_containerMd__lXzhK {\n height: 1.25rem;\n}\n\n.CheckboxInput-module_containerLg__ckD4Q {\n height: 1.5rem;\n}\n\n.CheckboxInput-module_checkbox__lYmgh {\n border: 1px solid var(--lb-color-neutral-300);\n border-radius: 0.25rem;\n background: var(--lb-color-background);\n cursor: pointer;\n transition: all 150ms ease;\n accent-color: var(--checkbox-color, var(--lb-color-primary));\n}\n\n.CheckboxInput-module_checkbox__lYmgh:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px\n var(\n --focus-ring,\n color-mix(in srgb, var(--lb-color-primary) 30%, transparent)\n );\n}\n\n.CheckboxInput-module_checkboxDisabled__B4hsr {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n opacity: 0.6;\n}\n\n.CheckboxInput-module_checkboxError__IAnd9 {\n border-color: var(--lb-color-danger);\n}\n\n.CheckboxInput-module_checkboxSm__h9Yfl {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxMd__Xn47v {\n width: 1rem;\n height: 1rem;\n}\n\n.CheckboxInput-module_checkboxLg__31itM {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.CheckboxInput-module_variantDefault__kOFV4 {\n --checkbox-color: var(--lb-color-primary);\n --focus-ring: color-mix(in srgb, var(--lb-color-primary) 30%, transparent);\n}\n\n.CheckboxInput-module_variantPrimary__oOcxM {\n --checkbox-color: var(--lb-color-indigo-accent);\n --focus-ring: rgba(79, 70, 229, 0.3);\n}\n\n.CheckboxInput-module_variantSuccess__Do-4i {\n --checkbox-color: var(--lb-color-success);\n --focus-ring: color-mix(in srgb, var(--lb-color-success) 30%, transparent);\n}\n\n.CheckboxInput-module_variantWarning__3-Z0F {\n --checkbox-color: var(--lb-color-warning);\n --focus-ring: color-mix(in srgb, var(--lb-color-warning) 30%, transparent);\n}\n\n.CheckboxInput-module_variantDanger__617R7 {\n --checkbox-color: var(--lb-color-danger);\n --focus-ring: color-mix(in srgb, var(--lb-color-danger) 30%, transparent);\n}\n\n.CheckboxInput-module_content__Qf9er {\n display: flex;\n flex-direction: column;\n}\n\n.CheckboxInput-module_label__rdC0e {\n font-weight: 500;\n}\n\n.CheckboxInput-module_labelSm__8m4I8 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_labelMd__LpiV4 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_labelLg__CZ1q0 {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.CheckboxInput-module_labelNormal__DxrKv {\n color: var(--lb-color-neutral-700);\n cursor: pointer;\n}\n\n.CheckboxInput-module_labelDisabled__wUItt {\n color: var(--lb-color-muted-foreground);\n cursor: not-allowed;\n}\n\n.CheckboxInput-module_required__hNTK3 {\n color: var(--lb-color-red-accent);\n margin-left: 0.25rem;\n}\n\n.CheckboxInput-module_description__cwaQ6 {\n color: var(--lb-color-neutral-500);\n margin-top: 0.25rem;\n}\n\n.CheckboxInput-module_descriptionSm__cdniJ {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.CheckboxInput-module_descriptionMd__21Bdi {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_descriptionLg__qCwRF {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_errorText__r7ffs {\n margin-top: 0.25rem;\n font-size: 0.75rem;\n line-height: 1rem;\n color: var(--lb-color-danger);\n}\n";
|
|
454
|
-
var styles = {"wrapper":"CheckboxInput-module_wrapper__lJGfc","checkboxContainer":"CheckboxInput-module_checkboxContainer__ou1mg","containerSm":"CheckboxInput-module_containerSm__zAmsB","containerMd":"CheckboxInput-module_containerMd__lXzhK","containerLg":"CheckboxInput-module_containerLg__ckD4Q","checkbox":"CheckboxInput-module_checkbox__lYmgh","checkboxDisabled":"CheckboxInput-module_checkboxDisabled__B4hsr","checkboxError":"CheckboxInput-module_checkboxError__IAnd9","checkboxSm":"CheckboxInput-module_checkboxSm__h9Yfl","checkboxMd":"CheckboxInput-module_checkboxMd__Xn47v","checkboxLg":"CheckboxInput-module_checkboxLg__31itM","variantDefault":"CheckboxInput-module_variantDefault__kOFV4","variantPrimary":"CheckboxInput-module_variantPrimary__oOcxM","variantSuccess":"CheckboxInput-module_variantSuccess__Do-4i","variantWarning":"CheckboxInput-module_variantWarning__3-Z0F","variantDanger":"CheckboxInput-module_variantDanger__617R7","content":"CheckboxInput-module_content__Qf9er","label":"CheckboxInput-module_label__rdC0e","labelSm":"CheckboxInput-module_labelSm__8m4I8","labelMd":"CheckboxInput-module_labelMd__LpiV4","labelLg":"CheckboxInput-module_labelLg__CZ1q0","labelNormal":"CheckboxInput-module_labelNormal__DxrKv","labelDisabled":"CheckboxInput-module_labelDisabled__wUItt","required":"CheckboxInput-module_required__hNTK3","description":"CheckboxInput-module_description__cwaQ6","descriptionSm":"CheckboxInput-module_descriptionSm__cdniJ","descriptionMd":"CheckboxInput-module_descriptionMd__21Bdi","descriptionLg":"CheckboxInput-module_descriptionLg__qCwRF","errorText":"CheckboxInput-module_errorText__r7ffs"};
|
|
455
|
-
styleInject(css_248z);
|
|
453
|
+
var css_248z$1 = ".CheckboxInput-module_wrapper__lJGfc {\n display: flex;\n align-items: flex-start;\n gap: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxContainer__ou1mg {\n display: flex;\n align-items: center;\n}\n\n.CheckboxInput-module_containerSm__zAmsB {\n height: 1rem;\n}\n\n.CheckboxInput-module_containerMd__lXzhK {\n height: 1.25rem;\n}\n\n.CheckboxInput-module_containerLg__ckD4Q {\n height: 1.5rem;\n}\n\n.CheckboxInput-module_checkbox__lYmgh {\n border: 1px solid var(--lb-color-neutral-300);\n border-radius: 0.25rem;\n background: var(--lb-color-background);\n cursor: pointer;\n transition: all 150ms ease;\n accent-color: var(--checkbox-color, var(--lb-color-primary));\n}\n\n.CheckboxInput-module_checkbox__lYmgh:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px\n var(\n --focus-ring,\n color-mix(in srgb, var(--lb-color-primary) 30%, transparent)\n );\n}\n\n.CheckboxInput-module_checkboxDisabled__B4hsr {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n opacity: 0.6;\n}\n\n.CheckboxInput-module_checkboxError__IAnd9 {\n border-color: var(--lb-color-danger);\n}\n\n.CheckboxInput-module_checkboxSm__h9Yfl {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.CheckboxInput-module_checkboxMd__Xn47v {\n width: 1rem;\n height: 1rem;\n}\n\n.CheckboxInput-module_checkboxLg__31itM {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.CheckboxInput-module_variantDefault__kOFV4 {\n --checkbox-color: var(--lb-color-primary);\n --focus-ring: color-mix(in srgb, var(--lb-color-primary) 30%, transparent);\n}\n\n.CheckboxInput-module_variantPrimary__oOcxM {\n --checkbox-color: var(--lb-color-indigo-accent);\n --focus-ring: rgba(79, 70, 229, 0.3);\n}\n\n.CheckboxInput-module_variantSuccess__Do-4i {\n --checkbox-color: var(--lb-color-success);\n --focus-ring: color-mix(in srgb, var(--lb-color-success) 30%, transparent);\n}\n\n.CheckboxInput-module_variantWarning__3-Z0F {\n --checkbox-color: var(--lb-color-warning);\n --focus-ring: color-mix(in srgb, var(--lb-color-warning) 30%, transparent);\n}\n\n.CheckboxInput-module_variantDanger__617R7 {\n --checkbox-color: var(--lb-color-danger);\n --focus-ring: color-mix(in srgb, var(--lb-color-danger) 30%, transparent);\n}\n\n.CheckboxInput-module_content__Qf9er {\n display: flex;\n flex-direction: column;\n}\n\n.CheckboxInput-module_label__rdC0e {\n font-weight: 500;\n}\n\n.CheckboxInput-module_labelSm__8m4I8 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_labelMd__LpiV4 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_labelLg__CZ1q0 {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.CheckboxInput-module_labelNormal__DxrKv {\n color: var(--lb-color-neutral-700);\n cursor: pointer;\n}\n\n.CheckboxInput-module_labelDisabled__wUItt {\n color: var(--lb-color-muted-foreground);\n cursor: not-allowed;\n}\n\n.CheckboxInput-module_required__hNTK3 {\n color: var(--lb-color-red-accent);\n margin-left: 0.25rem;\n}\n\n.CheckboxInput-module_description__cwaQ6 {\n color: var(--lb-color-neutral-500);\n margin-top: 0.25rem;\n}\n\n.CheckboxInput-module_descriptionSm__cdniJ {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.CheckboxInput-module_descriptionMd__21Bdi {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.CheckboxInput-module_descriptionLg__qCwRF {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.CheckboxInput-module_errorText__r7ffs {\n margin-top: 0.25rem;\n font-size: 0.75rem;\n line-height: 1rem;\n color: var(--lb-color-danger);\n}\n";
|
|
454
|
+
var styles$1 = {"wrapper":"CheckboxInput-module_wrapper__lJGfc","checkboxContainer":"CheckboxInput-module_checkboxContainer__ou1mg","containerSm":"CheckboxInput-module_containerSm__zAmsB","containerMd":"CheckboxInput-module_containerMd__lXzhK","containerLg":"CheckboxInput-module_containerLg__ckD4Q","checkbox":"CheckboxInput-module_checkbox__lYmgh","checkboxDisabled":"CheckboxInput-module_checkboxDisabled__B4hsr","checkboxError":"CheckboxInput-module_checkboxError__IAnd9","checkboxSm":"CheckboxInput-module_checkboxSm__h9Yfl","checkboxMd":"CheckboxInput-module_checkboxMd__Xn47v","checkboxLg":"CheckboxInput-module_checkboxLg__31itM","variantDefault":"CheckboxInput-module_variantDefault__kOFV4","variantPrimary":"CheckboxInput-module_variantPrimary__oOcxM","variantSuccess":"CheckboxInput-module_variantSuccess__Do-4i","variantWarning":"CheckboxInput-module_variantWarning__3-Z0F","variantDanger":"CheckboxInput-module_variantDanger__617R7","content":"CheckboxInput-module_content__Qf9er","label":"CheckboxInput-module_label__rdC0e","labelSm":"CheckboxInput-module_labelSm__8m4I8","labelMd":"CheckboxInput-module_labelMd__LpiV4","labelLg":"CheckboxInput-module_labelLg__CZ1q0","labelNormal":"CheckboxInput-module_labelNormal__DxrKv","labelDisabled":"CheckboxInput-module_labelDisabled__wUItt","required":"CheckboxInput-module_required__hNTK3","description":"CheckboxInput-module_description__cwaQ6","descriptionSm":"CheckboxInput-module_descriptionSm__cdniJ","descriptionMd":"CheckboxInput-module_descriptionMd__21Bdi","descriptionLg":"CheckboxInput-module_descriptionLg__qCwRF","errorText":"CheckboxInput-module_errorText__r7ffs"};
|
|
455
|
+
styleInject(css_248z$1);
|
|
456
456
|
|
|
457
457
|
const sizeClasses = {
|
|
458
458
|
sm: {
|
|
459
|
-
checkbox: styles.checkboxSm,
|
|
460
|
-
label: styles.labelSm,
|
|
461
|
-
description: styles.descriptionSm,
|
|
462
|
-
container: styles.containerSm,
|
|
459
|
+
checkbox: styles$1.checkboxSm,
|
|
460
|
+
label: styles$1.labelSm,
|
|
461
|
+
description: styles$1.descriptionSm,
|
|
462
|
+
container: styles$1.containerSm,
|
|
463
463
|
},
|
|
464
464
|
md: {
|
|
465
|
-
checkbox: styles.checkboxMd,
|
|
466
|
-
label: styles.labelMd,
|
|
467
|
-
description: styles.descriptionMd,
|
|
468
|
-
container: styles.containerMd,
|
|
465
|
+
checkbox: styles$1.checkboxMd,
|
|
466
|
+
label: styles$1.labelMd,
|
|
467
|
+
description: styles$1.descriptionMd,
|
|
468
|
+
container: styles$1.containerMd,
|
|
469
469
|
},
|
|
470
470
|
lg: {
|
|
471
|
-
checkbox: styles.checkboxLg,
|
|
472
|
-
label: styles.labelLg,
|
|
473
|
-
description: styles.descriptionLg,
|
|
474
|
-
container: styles.containerLg,
|
|
471
|
+
checkbox: styles$1.checkboxLg,
|
|
472
|
+
label: styles$1.labelLg,
|
|
473
|
+
description: styles$1.descriptionLg,
|
|
474
|
+
container: styles$1.containerLg,
|
|
475
475
|
},
|
|
476
476
|
};
|
|
477
477
|
const variantClasses = {
|
|
478
|
-
default: styles.variantDefault,
|
|
479
|
-
primary: styles.variantPrimary,
|
|
480
|
-
success: styles.variantSuccess,
|
|
481
|
-
warning: styles.variantWarning,
|
|
482
|
-
danger: styles.variantDanger,
|
|
478
|
+
default: styles$1.variantDefault,
|
|
479
|
+
primary: styles$1.variantPrimary,
|
|
480
|
+
success: styles$1.variantSuccess,
|
|
481
|
+
warning: styles$1.variantWarning,
|
|
482
|
+
danger: styles$1.variantDanger,
|
|
483
483
|
};
|
|
484
484
|
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
485
485
|
/** Casilla de verificación con etiqueta, descripción y error. */
|
|
486
|
-
const CheckboxInput =
|
|
486
|
+
const CheckboxInput = React.forwardRef(function CheckboxInput({ id, name, value, label, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", indeterminate = false, }, ref) {
|
|
487
487
|
const field = useFieldIds({ id, name, required, error, hint: description });
|
|
488
488
|
const sizeConfig = sizeClasses[size];
|
|
489
489
|
const variantConfig = variantClasses[variant];
|
|
@@ -493,13 +493,68 @@ const CheckboxInput = require$$0.forwardRef(function CheckboxInput({ id, name, v
|
|
|
493
493
|
checkboxRef.current.indeterminate = indeterminate;
|
|
494
494
|
}
|
|
495
495
|
}, [indeterminate]);
|
|
496
|
-
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles.wrapper, className), children: [jsxRuntimeExports.jsx("div", { className: classNames(styles.checkboxContainer, sizeConfig.container), children: jsxRuntimeExports.jsx("input", { ref: mergeRefs(checkboxRef, ref), ...field.controlProps, name: name, value: value, type: "checkbox", checked: checked, "aria-checked": indeterminate ? "mixed" : undefined, onChange: (e) => {
|
|
496
|
+
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.wrapper, className), children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.checkboxContainer, sizeConfig.container), children: jsxRuntimeExports.jsx("input", { ref: mergeRefs(checkboxRef, ref), ...field.controlProps, name: name, value: value, type: "checkbox", checked: checked, "aria-checked": indeterminate ? "mixed" : undefined, onChange: (e) => {
|
|
497
497
|
if (disabled) {
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
onChange?.(e.target.checked);
|
|
501
|
-
}, disabled: disabled, className: classNames(styles.checkbox, sizeConfig.checkbox, variantConfig, disabled && styles.checkboxDisabled, error && styles.checkboxError), required: required }) }), jsxRuntimeExports.jsxs("div", { className: styles.content, children: [jsxRuntimeExports.jsxs("label", { htmlFor: field.inputId, className: classNames(styles.label, sizeConfig.label, disabled ? styles.labelDisabled : styles.labelNormal), children: [label, required && (jsxRuntimeExports.jsx("span", { className: styles.required, "aria-hidden": "true", children: "*" }))] }), description && (jsxRuntimeExports.jsx("p", { id: field.hintId, className: classNames(styles.description, sizeConfig.description), children: description })), error && (jsxRuntimeExports.jsx("p", { id: field.errorId, className: styles.errorText, role: "alert", children: error }))] })] }));
|
|
501
|
+
}, disabled: disabled, className: classNames(styles$1.checkbox, sizeConfig.checkbox, variantConfig, disabled && styles$1.checkboxDisabled, error && styles$1.checkboxError), required: required }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.content, children: [jsxRuntimeExports.jsxs("label", { htmlFor: field.inputId, className: classNames(styles$1.label, sizeConfig.label, disabled ? styles$1.labelDisabled : styles$1.labelNormal), children: [label, required && (jsxRuntimeExports.jsx("span", { className: styles$1.required, "aria-hidden": "true", children: "*" }))] }), description && (jsxRuntimeExports.jsx("p", { id: field.hintId, className: classNames(styles$1.description, sizeConfig.description), children: description })), error && (jsxRuntimeExports.jsx("p", { id: field.errorId, className: styles$1.errorText, role: "alert", children: error }))] })] }));
|
|
502
502
|
});
|
|
503
503
|
CheckboxInput.displayName = "CheckboxInput";
|
|
504
504
|
|
|
505
|
-
|
|
505
|
+
var css_248z = ".CheckboxGroup-module_fieldset__5eB3Z {\n min-inline-size: 0;\n margin: 0;\n padding: 0;\n border: 0;\n font-family: var(--lb-font-sans);\n}\n\n.CheckboxGroup-module_legend__pNuxN {\n margin-bottom: var(--lb-space-2);\n padding: 0;\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n.CheckboxGroup-module_required__2lbzi {\n color: var(--lb-color-danger);\n}\n\n.CheckboxGroup-module_hint__2Pl7J {\n margin: 0 0 var(--lb-space-3);\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n}\n\n.CheckboxGroup-module_selectAll__qdf1U {\n margin-bottom: var(--lb-space-3);\n padding-bottom: var(--lb-space-3);\n border-bottom: 1px solid var(--lb-color-border);\n}\n\n.CheckboxGroup-module_vertical__D-Dlk {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.CheckboxGroup-module_horizontal__T8rDx {\n display: flex;\n flex-wrap: wrap;\n gap: var(--lb-space-3) var(--lb-space-6);\n}\n\n.CheckboxGroup-module_columns__ao0Db {\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n gap: var(--lb-space-3) var(--lb-space-6);\n}\n\n@media (min-width: 640px) {\n .CheckboxGroup-module_cols2__RdYv0 {\n grid-template-columns: repeat(2, minmax(0, 1fr));\n }\n .CheckboxGroup-module_cols3__03Tcs {\n grid-template-columns: repeat(3, minmax(0, 1fr));\n }\n .CheckboxGroup-module_cols4__sI6xr {\n grid-template-columns: repeat(4, minmax(0, 1fr));\n }\n}\n\n.CheckboxGroup-module_error__Y6n9J {\n margin: var(--lb-space-2) 0 0;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-danger);\n}\n\n.CheckboxGroup-module_srOnly__QdgTc {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n}\n";
|
|
506
|
+
var styles = {"fieldset":"CheckboxGroup-module_fieldset__5eB3Z","legend":"CheckboxGroup-module_legend__pNuxN","required":"CheckboxGroup-module_required__2lbzi","hint":"CheckboxGroup-module_hint__2Pl7J","selectAll":"CheckboxGroup-module_selectAll__qdf1U","vertical":"CheckboxGroup-module_vertical__D-Dlk","horizontal":"CheckboxGroup-module_horizontal__T8rDx","columns":"CheckboxGroup-module_columns__ao0Db","cols2":"CheckboxGroup-module_cols2__RdYv0","cols3":"CheckboxGroup-module_cols3__03Tcs","cols4":"CheckboxGroup-module_cols4__sI6xr","error":"CheckboxGroup-module_error__Y6n9J","srOnly":"CheckboxGroup-module_srOnly__QdgTc"};
|
|
507
|
+
styleInject(css_248z);
|
|
508
|
+
|
|
509
|
+
const cx = (...c) => c.filter(Boolean).join(" ");
|
|
510
|
+
/**
|
|
511
|
+
* Grupo de casillas con título (`fieldset`/`legend`), ayuda y error: para elegir varias
|
|
512
|
+
* opciones de una lista corta (permisos, días, especialidades).
|
|
513
|
+
*/
|
|
514
|
+
function CheckboxGroup({ label, options, value, onChange, name, orientation = "vertical", columns, size = "md", variant = "primary", disabled = false, required = false, hint, error, selectAll = false, maxSelected, hideLabel = false, className, id, }) {
|
|
515
|
+
const generado = React.useId();
|
|
516
|
+
const baseId = id ?? `checkbox-group-${generado}`;
|
|
517
|
+
const hintId = `${baseId}-ayuda`;
|
|
518
|
+
const errorId = `${baseId}-error`;
|
|
519
|
+
const describedBy = [hint && hintId, error && errorId].filter(Boolean).join(" ") || undefined;
|
|
520
|
+
const marcados = new Set(value);
|
|
521
|
+
const habilitadas = options.filter((o) => !o.disabled);
|
|
522
|
+
const lleno = maxSelected !== undefined && marcados.size >= maxSelected;
|
|
523
|
+
const cambiar = (valor, marcar) => {
|
|
524
|
+
const siguiente = new Set(marcados);
|
|
525
|
+
if (marcar)
|
|
526
|
+
siguiente.add(valor);
|
|
527
|
+
else
|
|
528
|
+
siguiente.delete(valor);
|
|
529
|
+
// Orden estable: el de las opciones; se conservan valores que no estén en options.
|
|
530
|
+
const enOpciones = options
|
|
531
|
+
.map((o) => o.value)
|
|
532
|
+
.filter((v) => siguiente.has(v));
|
|
533
|
+
const otros = value.filter((v) => siguiente.has(v) && !options.some((o) => o.value === v));
|
|
534
|
+
onChange([...enOpciones, ...otros]);
|
|
535
|
+
};
|
|
536
|
+
const todasMarcadas = habilitadas.length > 0 && habilitadas.every((o) => marcados.has(o.value));
|
|
537
|
+
const algunaMarcada = habilitadas.some((o) => marcados.has(o.value));
|
|
538
|
+
const alternarTodas = (marcar) => {
|
|
539
|
+
const habilitadasSet = new Set(habilitadas.map((o) => o.value));
|
|
540
|
+
const conservar = value.filter((v) => !habilitadasSet.has(v));
|
|
541
|
+
let nuevas = marcar ? habilitadas.map((o) => o.value) : [];
|
|
542
|
+
if (marcar && maxSelected !== undefined)
|
|
543
|
+
nuevas = nuevas.slice(0, Math.max(0, maxSelected - conservar.length));
|
|
544
|
+
const resultado = new Set([...conservar, ...nuevas]);
|
|
545
|
+
onChange([
|
|
546
|
+
...options.map((o) => o.value).filter((v) => resultado.has(v)),
|
|
547
|
+
...conservar.filter((v) => !options.some((o) => o.value === v)),
|
|
548
|
+
]);
|
|
549
|
+
};
|
|
550
|
+
return (jsxRuntimeExports.jsxs("fieldset", { id: baseId, className: cx(styles.fieldset, className), disabled: disabled, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined, children: [jsxRuntimeExports.jsxs("legend", { className: cx(styles.legend, hideLabel && styles.srOnly), children: [label, required && (jsxRuntimeExports.jsxs("span", { className: styles.required, "aria-hidden": "true", children: [" ", "*"] }))] }), hint && (jsxRuntimeExports.jsx("p", { id: hintId, className: styles.hint, children: hint })), selectAll && (jsxRuntimeExports.jsx("div", { className: styles.selectAll, children: jsxRuntimeExports.jsx(CheckboxInput, { label: typeof selectAll === "string" ? selectAll : "Seleccionar todos", checked: todasMarcadas, indeterminate: algunaMarcada && !todasMarcadas, onChange: alternarTodas, size: size, variant: variant, disabled: disabled }) })), jsxRuntimeExports.jsx("div", { className: cx(columns
|
|
551
|
+
? cx(styles.columns, styles[`cols${columns}`])
|
|
552
|
+
: orientation === "horizontal"
|
|
553
|
+
? styles.horizontal
|
|
554
|
+
: styles.vertical), children: options.map((o) => {
|
|
555
|
+
const marcada = marcados.has(o.value);
|
|
556
|
+
return (jsxRuntimeExports.jsx(CheckboxInput, { name: name, value: o.value, label: o.label, description: o.description, checked: marcada, onChange: (c) => cambiar(o.value, c), disabled: disabled || o.disabled || (lleno && !marcada), size: size, variant: variant }, o.value));
|
|
557
|
+
}) }), error && (jsxRuntimeExports.jsx("p", { id: errorId, className: styles.error, role: "alert", children: error }))] }));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export { CheckboxGroup, CheckboxInput as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/checkbox-input",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "CheckboxInput component",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"lbyte": {
|
|
45
45
|
"categoria": "formularios",
|
|
46
|
-
"resumen": "Casilla de verificación con etiqueta, ayuda y error.",
|
|
47
|
-
"usarCuando": "Opciones sí/no o
|
|
48
|
-
"evitarCuando": "Elegir una sola opción entre varias: usa RadioGroup."
|
|
46
|
+
"resumen": "Casilla de verificación con etiqueta, ayuda y error (CheckboxInput) y grupo de casillas con título, \"Seleccionar todos\" y máximo (CheckboxGroup).",
|
|
47
|
+
"usarCuando": "Opciones sí/no (CheckboxInput) o elegir varias opciones de una lista corta: permisos, días, especialidades (CheckboxGroup).",
|
|
48
|
+
"evitarCuando": "Elegir una sola opción entre varias: usa RadioGroup. Listas largas o con búsqueda: usa Autocomplete. Activar/desactivar algo al instante: usa Switch."
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "rollup -c",
|