@rubenpazch/radio-button 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,62 @@
1
1
  # RadioButton
2
2
 
3
3
  Generated component package.
4
+
5
+ <!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
6
+
7
+ RadioButton y RadioGroup accesibles con variantes y validación.
8
+
9
+ - **Usar cuando:** Elegir una sola opción entre pocas (2 a 6) visibles a la vez.
10
+ - **Evitar cuando:** Muchas opciones: usa Select o Autocomplete.
11
+
12
+ Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
13
+
14
+ ```bash
15
+ npm install @rubenpazch/radio-button
16
+ ```
17
+
18
+ ## RadioButton
19
+
20
+ | Prop | Tipo | Req. | Por defecto | Descripción |
21
+ | ------------- | -------------------------------------------------------------- | ---- | ----------- | ----------- |
22
+ | `label` | `string` | sí | | |
23
+ | `name` | `string` | sí | | |
24
+ | `value` | `string` | sí | | |
25
+ | `checked` | `boolean` | | `false` | |
26
+ | `className` | `string` | | `` | |
27
+ | `description` | `string` | | | |
28
+ | `disabled` | `boolean` | | `false` | |
29
+ | `error` | `string` | | | |
30
+ | `id` | `string` | | | |
31
+ | `onChange` | `(value: string) => void` | | | |
32
+ | `required` | `boolean` | | `false` | |
33
+ | `size` | `"sm" \| "md" \| "lg"` | | `md` | |
34
+ | `variant` | `"default" \| "primary" \| "success" \| "warning" \| "danger"` | | `default` | |
35
+
36
+ ## RadioGroup
37
+
38
+ | Prop | Tipo | Req. | Por defecto | Descripción |
39
+ | ------------------- | -------------------------------------------------------------- | ---- | --------------- | ------------------------------------------- |
40
+ | `name` | `string` | sí | | |
41
+ | `onChange` | `(value: string) => void` | sí | | |
42
+ | `options` | `RadioOption[]` | sí | | |
43
+ | `bordered` | `boolean` | | `false` | |
44
+ | `borderLabel` | `string` | | | |
45
+ | `className` | `string` | | `` | |
46
+ | `disabled` | `boolean` | | `false` | |
47
+ | `error` | `string` | | | |
48
+ | `groupLabel` | `string` | | | |
49
+ | `hint` | `string` | | | Texto de ayuda bajo el grupo. |
50
+ | `id` | `string` | | | |
51
+ | `label` | `string` | | | Etiqueta del grupo (alias de `groupLabel`). |
52
+ | `orientation` | `"vertical" \| "horizontal"` | | `vertical` | |
53
+ | `required` | `boolean` | | `false` | |
54
+ | `selectedLabelText` | `string` | | `Seleccionado:` | |
55
+ | `showSelectedLabel` | `boolean` | | `false` | |
56
+ | `size` | `"sm" \| "md" \| "lg"` | | `md` | |
57
+ | `value` | `string` | | | |
58
+ | `variant` | `"default" \| "primary" \| "success" \| "warning" \| "danger"` | | `default` | |
59
+
60
+ Tipos: `RadioButtonProps`, `RadioSize`, `RadioVariant`, `RadioGroupProps`, `RadioOption`, `RadioGroupOrientation`.
61
+
62
+ <!-- catalogo:fin -->
@@ -16,6 +16,6 @@ export interface RadioButtonProps {
16
16
  size?: RadioSize;
17
17
  variant?: RadioVariant;
18
18
  }
19
- declare const RadioButton: React.FC<RadioButtonProps>;
19
+ declare const RadioButton: React.ForwardRefExoticComponent<RadioButtonProps & React.RefAttributes<HTMLInputElement>>;
20
20
  export default RadioButton;
21
21
  //# sourceMappingURL=RadioButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../src/RadioButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,MAAM,YAAY,GACtB,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAA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,CAAC;CACxB;AAqDD,QAAA,MAAM,WAAW,2FAiHhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -18,6 +18,11 @@ export interface RadioGroupProps {
18
18
  disabled?: boolean;
19
19
  required?: boolean;
20
20
  error?: string;
21
+ /** Texto de ayuda bajo el grupo. */
22
+ hint?: string;
23
+ /** Etiqueta del grupo (alias de `groupLabel`). */
24
+ label?: string;
25
+ id?: string;
21
26
  className?: string;
22
27
  showSelectedLabel?: boolean;
23
28
  selectedLabelText?: string;
@@ -25,6 +30,6 @@ export interface RadioGroupProps {
25
30
  bordered?: boolean;
26
31
  borderLabel?: string;
27
32
  }
28
- declare const RadioGroup: React.FC<RadioGroupProps>;
33
+ declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
29
34
  export default RadioGroup;
30
35
  //# sourceMappingURL=RadioGroup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RadioGroup.d.ts","sourceRoot":"","sources":["../src/RadioGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAoB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGrE,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,YAAY,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,IAAI,CAAC,EAAE,SAAS,CAAC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E,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,QAAA,MAAM,UAAU,wFAyHf,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var require$$0 = require('react');
5
+ var React = require('react');
6
6
 
7
7
  var jsxRuntime = {exports: {}};
8
8
 
@@ -340,7 +340,7 @@ function requireReactJsxRuntime_development () {
340
340
  object.$$typeof === REACT_ELEMENT_TYPE
341
341
  );
342
342
  }
343
- var React = require$$0,
343
+ var React$1 = React,
344
344
  REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
345
345
  REACT_PORTAL_TYPE = Symbol.for("react.portal"),
346
346
  REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
@@ -356,7 +356,7 @@ function requireReactJsxRuntime_development () {
356
356
  REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
357
357
  REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
358
358
  ReactSharedInternals =
359
- React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
359
+ React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
360
360
  hasOwnProperty = Object.prototype.hasOwnProperty,
361
361
  isArrayImpl = Array.isArray,
362
362
  createTask = console.createTask
@@ -364,15 +364,15 @@ function requireReactJsxRuntime_development () {
364
364
  : function () {
365
365
  return null;
366
366
  };
367
- React = {
367
+ React$1 = {
368
368
  react_stack_bottom_frame: function (callStackForError) {
369
369
  return callStackForError();
370
370
  }
371
371
  };
372
372
  var specialPropKeyWarningShown;
373
373
  var didWarnAboutElementRef = {};
374
- var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
375
- React,
374
+ var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
375
+ React$1,
376
376
  UnknownOwner
377
377
  )();
378
378
  var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
@@ -500,8 +500,11 @@ const variantClasses = {
500
500
  focus: styles$1.radioFocusDanger,
501
501
  },
502
502
  };
503
- const RadioButton = ({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }) => {
503
+ const RadioButton = React.forwardRef(function RadioButton({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }, ref) {
504
504
  const radioId = id || `radio-${name}-${value}`;
505
+ const describedBy = [description && `${radioId}-description`, error && `${radioId}-error`]
506
+ .filter(Boolean)
507
+ .join(" ") || undefined;
505
508
  const sizes = sizeClasses[size];
506
509
  const variants = variantClasses[variant];
507
510
  const handleChange = (event) => {
@@ -523,22 +526,29 @@ const RadioButton = ({ id, name, label, value, checked = false, onChange, disabl
523
526
  : size === "lg"
524
527
  ? styles$1.errorLg
525
528
  : styles$1.errorMd);
526
- return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.container, className), "data-testid": "radio-button-container", "data-size": size, "data-variant": variant, "data-checked": checked, "data-disabled": disabled, "data-error": !!error, children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.radioWrapper, sizes.container), children: jsxRuntimeExports.jsx("input", { id: radioId, name: name, type: "radio", value: value, checked: checked, onChange: handleChange, disabled: disabled, required: required, className: radioClasses, "aria-describedby": description ? `${radioId}-description` : undefined, "aria-invalid": !!error }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.contentWrapper, children: [jsxRuntimeExports.jsx("label", { htmlFor: radioId, className: labelClasses, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: descriptionClasses, children: description })), error && jsxRuntimeExports.jsx("p", { className: errorClasses, children: error })] })] }));
527
- };
529
+ return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.container, className), "data-testid": "radio-button-container", "data-size": size, "data-variant": variant, "data-checked": checked, "data-disabled": disabled, "data-error": !!error, children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.radioWrapper, sizes.container), children: jsxRuntimeExports.jsx("input", { ref: ref, id: radioId, name: name, type: "radio", value: value, checked: checked, onChange: handleChange, disabled: disabled, required: required, className: radioClasses, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.contentWrapper, children: [jsxRuntimeExports.jsx("label", { htmlFor: radioId, className: labelClasses, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: descriptionClasses, children: description })), error && (jsxRuntimeExports.jsx("p", { id: `${radioId}-error`, className: errorClasses, children: error }))] })] }));
530
+ });
528
531
 
529
- var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical__5DpXK {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.RadioGroup-module_groupHorizontal__SFlwH {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: var(--lb-space-4);\n}\n\n/* Group label */\n.RadioGroup-module_groupLabel__b5sBv {\n font-weight: var(--lb-font-weight-semibold);\n margin-bottom: var(--lb-space-3);\n color: var(--lb-color-foreground);\n}\n\n.RadioGroup-module_groupLabelInvalid__YrZzU {\n color: var(--lb-color-danger);\n}\n\n/* Bordered fieldset */\n.RadioGroup-module_fieldset__cXVuK {\n border-radius: var(--lb-radius-lg);\n padding: var(--lb-space-4);\n border: 1px solid var(--lb-color-border);\n min-inline-size: auto;\n}\n\n.RadioGroup-module_fieldsetInvalid__2ih-T {\n border: 2px solid var(--lb-color-danger);\n}\n\n.RadioGroup-module_legend__dJZQq {\n padding: 0 var(--lb-space-2);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-neutral-700);\n}\n\n.RadioGroup-module_legendInvalid__llTj2 {\n color: var(--lb-color-danger);\n}\n\n/* Error message */\n.RadioGroup-module_error__YzQEP {\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-danger);\n margin-top: var(--lb-space-2);\n}\n\n/* Selected label preview */\n.RadioGroup-module_selectedLabel__OG4Ln {\n margin-top: var(--lb-space-4);\n padding: var(--lb-space-3);\n background: var(--lb-color-neutral-100);\n border-radius: var(--lb-radius-sm);\n}\n";
530
- var styles = {"groupVertical":"RadioGroup-module_groupVertical__5DpXK","groupHorizontal":"RadioGroup-module_groupHorizontal__SFlwH","groupLabel":"RadioGroup-module_groupLabel__b5sBv","groupLabelInvalid":"RadioGroup-module_groupLabelInvalid__YrZzU","fieldset":"RadioGroup-module_fieldset__cXVuK","fieldsetInvalid":"RadioGroup-module_fieldsetInvalid__2ih-T","legend":"RadioGroup-module_legend__dJZQq","legendInvalid":"RadioGroup-module_legendInvalid__llTj2","error":"RadioGroup-module_error__YzQEP","selectedLabel":"RadioGroup-module_selectedLabel__OG4Ln"};
532
+ var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical__5DpXK {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.RadioGroup-module_groupHorizontal__SFlwH {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: var(--lb-space-4);\n}\n\n/* Group label */\n.RadioGroup-module_groupLabel__b5sBv {\n font-weight: var(--lb-font-weight-semibold);\n margin-bottom: var(--lb-space-3);\n color: var(--lb-color-foreground);\n}\n\n.RadioGroup-module_groupLabelInvalid__YrZzU {\n color: var(--lb-color-danger);\n}\n\n/* Bordered fieldset */\n.RadioGroup-module_fieldset__cXVuK {\n border-radius: var(--lb-radius-lg);\n padding: var(--lb-space-4);\n border: 1px solid var(--lb-color-border);\n min-inline-size: auto;\n}\n\n.RadioGroup-module_fieldsetInvalid__2ih-T {\n border: 2px solid var(--lb-color-danger);\n}\n\n.RadioGroup-module_legend__dJZQq {\n padding: 0 var(--lb-space-2);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-neutral-700);\n}\n\n.RadioGroup-module_legendInvalid__llTj2 {\n color: var(--lb-color-danger);\n}\n\n/* Error message */\n.RadioGroup-module_error__YzQEP {\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-danger);\n margin-top: var(--lb-space-2);\n}\n\n/* Selected label preview */\n.RadioGroup-module_selectedLabel__OG4Ln {\n margin-top: var(--lb-space-4);\n padding: var(--lb-space-3);\n background: var(--lb-color-neutral-100);\n border-radius: var(--lb-radius-sm);\n}\n\n.RadioGroup-module_hint__bFpkX {\n margin: 0.25rem 0 0;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n}\n";
533
+ var styles = {"groupVertical":"RadioGroup-module_groupVertical__5DpXK","groupHorizontal":"RadioGroup-module_groupHorizontal__SFlwH","groupLabel":"RadioGroup-module_groupLabel__b5sBv","groupLabelInvalid":"RadioGroup-module_groupLabelInvalid__YrZzU","fieldset":"RadioGroup-module_fieldset__cXVuK","fieldsetInvalid":"RadioGroup-module_fieldsetInvalid__2ih-T","legend":"RadioGroup-module_legend__dJZQq","legendInvalid":"RadioGroup-module_legendInvalid__llTj2","error":"RadioGroup-module_error__YzQEP","selectedLabel":"RadioGroup-module_selectedLabel__OG4Ln","hint":"RadioGroup-module_hint__bFpkX"};
531
534
  styleInject(css_248z);
532
535
 
533
- const RadioGroup = ({ name, options, value, onChange, orientation = "vertical", size = "md", variant = "default", disabled = false, required = false, error, className = "", showSelectedLabel = false, selectedLabelText = "Selected:", groupLabel, bordered = false, borderLabel, }) => {
536
+ const RadioGroup = React.forwardRef(function RadioGroup({ name, options, value, onChange, orientation = "vertical", size = "md", variant = "default", disabled = false, required = false, error, hint, label, id, className = "", showSelectedLabel = false, selectedLabelText = "Seleccionado:", groupLabel, bordered = false, borderLabel, }, ref) {
537
+ const generatedId = React.useId();
538
+ const baseId = id ?? `${name}-${generatedId}`;
539
+ const titulo = groupLabel ?? label;
540
+ const labelId = `${baseId}-etiqueta`;
541
+ const hintId = `${baseId}-ayuda`;
542
+ const errorId = `${baseId}-error`;
543
+ const describedBy = [hint && hintId, error && errorId].filter(Boolean).join(" ") || undefined;
534
544
  const orientationClasses = {
535
545
  vertical: styles.groupVertical,
536
546
  horizontal: styles.groupHorizontal,
537
547
  };
538
548
  const selectedOption = options.find((option) => option.value === value);
539
- const radioGroupContent = (jsxRuntimeExports.jsx("div", { className: orientationClasses[orientation], role: "radiogroup", children: options.map((option) => (jsxRuntimeExports.jsx(RadioButton, { name: name, label: option.label, value: option.value, checked: value === option.value, onChange: onChange, description: option.description, disabled: disabled || option.disabled, required: required, size: size, variant: variant }, option.value))) }));
540
- return (jsxRuntimeExports.jsxs("div", { className: className, children: [groupLabel && (jsxRuntimeExports.jsx("div", { className: `${styles.groupLabel} ${required && !value ? styles.groupLabelInvalid : ""}`, children: groupLabel })), bordered ? (jsxRuntimeExports.jsxs("fieldset", { className: `${styles.fieldset} ${required && !value ? styles.fieldsetInvalid : ""}`, children: [borderLabel && (jsxRuntimeExports.jsx("legend", { className: `${styles.legend} ${required && !value ? styles.legendInvalid : ""}`, children: borderLabel })), radioGroupContent] })) : (radioGroupContent), error && jsxRuntimeExports.jsx("p", { className: styles.error, children: error }), showSelectedLabel && (jsxRuntimeExports.jsxs("div", { className: styles.selectedLabel, children: [jsxRuntimeExports.jsx("strong", { children: selectedLabelText }), " ", selectedOption?.label || value || "None"] }))] }));
541
- };
549
+ const radioGroupContent = (jsxRuntimeExports.jsx("div", { ref: ref, id: baseId, className: orientationClasses[orientation], role: "radiogroup", "aria-labelledby": titulo ? labelId : undefined, "aria-label": !titulo ? borderLabel : undefined, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined, "aria-required": required || undefined, children: options.map((option) => (jsxRuntimeExports.jsx(RadioButton, { name: name, label: option.label, value: option.value, checked: value === option.value, onChange: onChange, description: option.description, disabled: disabled || option.disabled, required: required, size: size, variant: variant }, option.value))) }));
550
+ return (jsxRuntimeExports.jsxs("div", { className: className, children: [titulo && (jsxRuntimeExports.jsx("div", { id: labelId, className: `${styles.groupLabel} ${required && !value ? styles.groupLabelInvalid : ""}`, children: titulo })), bordered ? (jsxRuntimeExports.jsxs("fieldset", { className: `${styles.fieldset} ${required && !value ? styles.fieldsetInvalid : ""}`, children: [borderLabel && (jsxRuntimeExports.jsx("legend", { className: `${styles.legend} ${required && !value ? styles.legendInvalid : ""}`, children: borderLabel })), radioGroupContent] })) : (radioGroupContent), hint && (jsxRuntimeExports.jsx("p", { id: hintId, className: styles.hint, children: hint })), error && (jsxRuntimeExports.jsx("p", { id: errorId, className: styles.error, role: "alert", children: error })), showSelectedLabel && (jsxRuntimeExports.jsxs("div", { className: styles.selectedLabel, children: [jsxRuntimeExports.jsx("strong", { children: selectedLabelText }), " ", selectedOption?.label || value || "Ninguno"] }))] }));
551
+ });
542
552
 
543
553
  exports.RadioGroup = RadioGroup;
544
554
  exports.default = RadioButton;
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ interface RadioButtonProps {
17
17
  size?: RadioSize;
18
18
  variant?: RadioVariant;
19
19
  }
20
- declare const RadioButton: React.FC<RadioButtonProps>;
20
+ declare const RadioButton: React.ForwardRefExoticComponent<RadioButtonProps & React.RefAttributes<HTMLInputElement>>;
21
21
 
22
22
  type RadioGroupOrientation = "vertical" | "horizontal";
23
23
  interface RadioOption {
@@ -37,6 +37,11 @@ interface RadioGroupProps {
37
37
  disabled?: boolean;
38
38
  required?: boolean;
39
39
  error?: string;
40
+ /** Texto de ayuda bajo el grupo. */
41
+ hint?: string;
42
+ /** Etiqueta del grupo (alias de `groupLabel`). */
43
+ label?: string;
44
+ id?: string;
40
45
  className?: string;
41
46
  showSelectedLabel?: boolean;
42
47
  selectedLabelText?: string;
@@ -44,7 +49,7 @@ interface RadioGroupProps {
44
49
  bordered?: boolean;
45
50
  borderLabel?: string;
46
51
  }
47
- declare const RadioGroup: React.FC<RadioGroupProps>;
52
+ declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
48
53
 
49
54
  export { RadioGroup, RadioButton as default };
50
55
  export type { RadioButtonProps, RadioGroupOrientation, RadioGroupProps, RadioOption, RadioSize, RadioVariant };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import require$$0 from 'react';
1
+ import React from 'react';
2
2
 
3
3
  var jsxRuntime = {exports: {}};
4
4
 
@@ -336,7 +336,7 @@ function requireReactJsxRuntime_development () {
336
336
  object.$$typeof === REACT_ELEMENT_TYPE
337
337
  );
338
338
  }
339
- var React = require$$0,
339
+ var React$1 = React,
340
340
  REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
341
341
  REACT_PORTAL_TYPE = Symbol.for("react.portal"),
342
342
  REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
@@ -352,7 +352,7 @@ function requireReactJsxRuntime_development () {
352
352
  REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
353
353
  REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
354
354
  ReactSharedInternals =
355
- React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
355
+ React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
356
356
  hasOwnProperty = Object.prototype.hasOwnProperty,
357
357
  isArrayImpl = Array.isArray,
358
358
  createTask = console.createTask
@@ -360,15 +360,15 @@ function requireReactJsxRuntime_development () {
360
360
  : function () {
361
361
  return null;
362
362
  };
363
- React = {
363
+ React$1 = {
364
364
  react_stack_bottom_frame: function (callStackForError) {
365
365
  return callStackForError();
366
366
  }
367
367
  };
368
368
  var specialPropKeyWarningShown;
369
369
  var didWarnAboutElementRef = {};
370
- var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
371
- React,
370
+ var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
371
+ React$1,
372
372
  UnknownOwner
373
373
  )();
374
374
  var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
@@ -496,8 +496,11 @@ const variantClasses = {
496
496
  focus: styles$1.radioFocusDanger,
497
497
  },
498
498
  };
499
- const RadioButton = ({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }) => {
499
+ const RadioButton = React.forwardRef(function RadioButton({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }, ref) {
500
500
  const radioId = id || `radio-${name}-${value}`;
501
+ const describedBy = [description && `${radioId}-description`, error && `${radioId}-error`]
502
+ .filter(Boolean)
503
+ .join(" ") || undefined;
501
504
  const sizes = sizeClasses[size];
502
505
  const variants = variantClasses[variant];
503
506
  const handleChange = (event) => {
@@ -519,21 +522,28 @@ const RadioButton = ({ id, name, label, value, checked = false, onChange, disabl
519
522
  : size === "lg"
520
523
  ? styles$1.errorLg
521
524
  : styles$1.errorMd);
522
- return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.container, className), "data-testid": "radio-button-container", "data-size": size, "data-variant": variant, "data-checked": checked, "data-disabled": disabled, "data-error": !!error, children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.radioWrapper, sizes.container), children: jsxRuntimeExports.jsx("input", { id: radioId, name: name, type: "radio", value: value, checked: checked, onChange: handleChange, disabled: disabled, required: required, className: radioClasses, "aria-describedby": description ? `${radioId}-description` : undefined, "aria-invalid": !!error }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.contentWrapper, children: [jsxRuntimeExports.jsx("label", { htmlFor: radioId, className: labelClasses, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: descriptionClasses, children: description })), error && jsxRuntimeExports.jsx("p", { className: errorClasses, children: error })] })] }));
523
- };
525
+ return (jsxRuntimeExports.jsxs("div", { className: classNames(styles$1.container, className), "data-testid": "radio-button-container", "data-size": size, "data-variant": variant, "data-checked": checked, "data-disabled": disabled, "data-error": !!error, children: [jsxRuntimeExports.jsx("div", { className: classNames(styles$1.radioWrapper, sizes.container), children: jsxRuntimeExports.jsx("input", { ref: ref, id: radioId, name: name, type: "radio", value: value, checked: checked, onChange: handleChange, disabled: disabled, required: required, className: radioClasses, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined }) }), jsxRuntimeExports.jsxs("div", { className: styles$1.contentWrapper, children: [jsxRuntimeExports.jsx("label", { htmlFor: radioId, className: labelClasses, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: descriptionClasses, children: description })), error && (jsxRuntimeExports.jsx("p", { id: `${radioId}-error`, className: errorClasses, children: error }))] })] }));
526
+ });
524
527
 
525
- var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical__5DpXK {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.RadioGroup-module_groupHorizontal__SFlwH {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: var(--lb-space-4);\n}\n\n/* Group label */\n.RadioGroup-module_groupLabel__b5sBv {\n font-weight: var(--lb-font-weight-semibold);\n margin-bottom: var(--lb-space-3);\n color: var(--lb-color-foreground);\n}\n\n.RadioGroup-module_groupLabelInvalid__YrZzU {\n color: var(--lb-color-danger);\n}\n\n/* Bordered fieldset */\n.RadioGroup-module_fieldset__cXVuK {\n border-radius: var(--lb-radius-lg);\n padding: var(--lb-space-4);\n border: 1px solid var(--lb-color-border);\n min-inline-size: auto;\n}\n\n.RadioGroup-module_fieldsetInvalid__2ih-T {\n border: 2px solid var(--lb-color-danger);\n}\n\n.RadioGroup-module_legend__dJZQq {\n padding: 0 var(--lb-space-2);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-neutral-700);\n}\n\n.RadioGroup-module_legendInvalid__llTj2 {\n color: var(--lb-color-danger);\n}\n\n/* Error message */\n.RadioGroup-module_error__YzQEP {\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-danger);\n margin-top: var(--lb-space-2);\n}\n\n/* Selected label preview */\n.RadioGroup-module_selectedLabel__OG4Ln {\n margin-top: var(--lb-space-4);\n padding: var(--lb-space-3);\n background: var(--lb-color-neutral-100);\n border-radius: var(--lb-radius-sm);\n}\n";
526
- var styles = {"groupVertical":"RadioGroup-module_groupVertical__5DpXK","groupHorizontal":"RadioGroup-module_groupHorizontal__SFlwH","groupLabel":"RadioGroup-module_groupLabel__b5sBv","groupLabelInvalid":"RadioGroup-module_groupLabelInvalid__YrZzU","fieldset":"RadioGroup-module_fieldset__cXVuK","fieldsetInvalid":"RadioGroup-module_fieldsetInvalid__2ih-T","legend":"RadioGroup-module_legend__dJZQq","legendInvalid":"RadioGroup-module_legendInvalid__llTj2","error":"RadioGroup-module_error__YzQEP","selectedLabel":"RadioGroup-module_selectedLabel__OG4Ln"};
528
+ var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical__5DpXK {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-3);\n}\n\n.RadioGroup-module_groupHorizontal__SFlwH {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: var(--lb-space-4);\n}\n\n/* Group label */\n.RadioGroup-module_groupLabel__b5sBv {\n font-weight: var(--lb-font-weight-semibold);\n margin-bottom: var(--lb-space-3);\n color: var(--lb-color-foreground);\n}\n\n.RadioGroup-module_groupLabelInvalid__YrZzU {\n color: var(--lb-color-danger);\n}\n\n/* Bordered fieldset */\n.RadioGroup-module_fieldset__cXVuK {\n border-radius: var(--lb-radius-lg);\n padding: var(--lb-space-4);\n border: 1px solid var(--lb-color-border);\n min-inline-size: auto;\n}\n\n.RadioGroup-module_fieldsetInvalid__2ih-T {\n border: 2px solid var(--lb-color-danger);\n}\n\n.RadioGroup-module_legend__dJZQq {\n padding: 0 var(--lb-space-2);\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-neutral-700);\n}\n\n.RadioGroup-module_legendInvalid__llTj2 {\n color: var(--lb-color-danger);\n}\n\n/* Error message */\n.RadioGroup-module_error__YzQEP {\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-danger);\n margin-top: var(--lb-space-2);\n}\n\n/* Selected label preview */\n.RadioGroup-module_selectedLabel__OG4Ln {\n margin-top: var(--lb-space-4);\n padding: var(--lb-space-3);\n background: var(--lb-color-neutral-100);\n border-radius: var(--lb-radius-sm);\n}\n\n.RadioGroup-module_hint__bFpkX {\n margin: 0.25rem 0 0;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n}\n";
529
+ var styles = {"groupVertical":"RadioGroup-module_groupVertical__5DpXK","groupHorizontal":"RadioGroup-module_groupHorizontal__SFlwH","groupLabel":"RadioGroup-module_groupLabel__b5sBv","groupLabelInvalid":"RadioGroup-module_groupLabelInvalid__YrZzU","fieldset":"RadioGroup-module_fieldset__cXVuK","fieldsetInvalid":"RadioGroup-module_fieldsetInvalid__2ih-T","legend":"RadioGroup-module_legend__dJZQq","legendInvalid":"RadioGroup-module_legendInvalid__llTj2","error":"RadioGroup-module_error__YzQEP","selectedLabel":"RadioGroup-module_selectedLabel__OG4Ln","hint":"RadioGroup-module_hint__bFpkX"};
527
530
  styleInject(css_248z);
528
531
 
529
- const RadioGroup = ({ name, options, value, onChange, orientation = "vertical", size = "md", variant = "default", disabled = false, required = false, error, className = "", showSelectedLabel = false, selectedLabelText = "Selected:", groupLabel, bordered = false, borderLabel, }) => {
532
+ const RadioGroup = React.forwardRef(function RadioGroup({ name, options, value, onChange, orientation = "vertical", size = "md", variant = "default", disabled = false, required = false, error, hint, label, id, className = "", showSelectedLabel = false, selectedLabelText = "Seleccionado:", groupLabel, bordered = false, borderLabel, }, ref) {
533
+ const generatedId = React.useId();
534
+ const baseId = id ?? `${name}-${generatedId}`;
535
+ const titulo = groupLabel ?? label;
536
+ const labelId = `${baseId}-etiqueta`;
537
+ const hintId = `${baseId}-ayuda`;
538
+ const errorId = `${baseId}-error`;
539
+ const describedBy = [hint && hintId, error && errorId].filter(Boolean).join(" ") || undefined;
530
540
  const orientationClasses = {
531
541
  vertical: styles.groupVertical,
532
542
  horizontal: styles.groupHorizontal,
533
543
  };
534
544
  const selectedOption = options.find((option) => option.value === value);
535
- const radioGroupContent = (jsxRuntimeExports.jsx("div", { className: orientationClasses[orientation], role: "radiogroup", children: options.map((option) => (jsxRuntimeExports.jsx(RadioButton, { name: name, label: option.label, value: option.value, checked: value === option.value, onChange: onChange, description: option.description, disabled: disabled || option.disabled, required: required, size: size, variant: variant }, option.value))) }));
536
- return (jsxRuntimeExports.jsxs("div", { className: className, children: [groupLabel && (jsxRuntimeExports.jsx("div", { className: `${styles.groupLabel} ${required && !value ? styles.groupLabelInvalid : ""}`, children: groupLabel })), bordered ? (jsxRuntimeExports.jsxs("fieldset", { className: `${styles.fieldset} ${required && !value ? styles.fieldsetInvalid : ""}`, children: [borderLabel && (jsxRuntimeExports.jsx("legend", { className: `${styles.legend} ${required && !value ? styles.legendInvalid : ""}`, children: borderLabel })), radioGroupContent] })) : (radioGroupContent), error && jsxRuntimeExports.jsx("p", { className: styles.error, children: error }), showSelectedLabel && (jsxRuntimeExports.jsxs("div", { className: styles.selectedLabel, children: [jsxRuntimeExports.jsx("strong", { children: selectedLabelText }), " ", selectedOption?.label || value || "None"] }))] }));
537
- };
545
+ const radioGroupContent = (jsxRuntimeExports.jsx("div", { ref: ref, id: baseId, className: orientationClasses[orientation], role: "radiogroup", "aria-labelledby": titulo ? labelId : undefined, "aria-label": !titulo ? borderLabel : undefined, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined, "aria-required": required || undefined, children: options.map((option) => (jsxRuntimeExports.jsx(RadioButton, { name: name, label: option.label, value: option.value, checked: value === option.value, onChange: onChange, description: option.description, disabled: disabled || option.disabled, required: required, size: size, variant: variant }, option.value))) }));
546
+ return (jsxRuntimeExports.jsxs("div", { className: className, children: [titulo && (jsxRuntimeExports.jsx("div", { id: labelId, className: `${styles.groupLabel} ${required && !value ? styles.groupLabelInvalid : ""}`, children: titulo })), bordered ? (jsxRuntimeExports.jsxs("fieldset", { className: `${styles.fieldset} ${required && !value ? styles.fieldsetInvalid : ""}`, children: [borderLabel && (jsxRuntimeExports.jsx("legend", { className: `${styles.legend} ${required && !value ? styles.legendInvalid : ""}`, children: borderLabel })), radioGroupContent] })) : (radioGroupContent), hint && (jsxRuntimeExports.jsx("p", { id: hintId, className: styles.hint, children: hint })), error && (jsxRuntimeExports.jsx("p", { id: errorId, className: styles.error, role: "alert", children: error })), showSelectedLabel && (jsxRuntimeExports.jsxs("div", { className: styles.selectedLabel, children: [jsxRuntimeExports.jsx("strong", { children: selectedLabelText }), " ", selectedOption?.label || value || "Ninguno"] }))] }));
547
+ });
538
548
 
539
549
  export { RadioGroup, RadioButton as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubenpazch/radio-button",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Accessible radio button and radio group components with variants and validation",
5
5
  "private": false,
6
6
  "main": "dist/index.cjs.js",
@@ -29,7 +29,7 @@
29
29
  "peerDependencies": {
30
30
  "react": "^19.0.0",
31
31
  "react-dom": "^19.0.0",
32
- "@rubenpazch/tokens": "0.2.0"
32
+ "@rubenpazch/tokens": "0.4.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@rubenpazch/typescript-config": "3.0.0"
@@ -37,6 +37,12 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
+ "lbyte": {
41
+ "categoria": "formularios",
42
+ "resumen": "RadioButton y RadioGroup accesibles con variantes y validación.",
43
+ "usarCuando": "Elegir una sola opción entre pocas (2 a 6) visibles a la vez.",
44
+ "evitarCuando": "Muchas opciones: usa Select o Autocomplete."
45
+ },
40
46
  "scripts": {
41
47
  "build": "rollup -c",
42
48
  "test": "jest --passWithNoTests"