@rubenpazch/radio-button 4.2.1 → 4.4.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 +24 -23
- package/dist/RadioButton.d.ts +3 -1
- package/dist/RadioButton.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +6 -0
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/index.cjs.js +6 -4
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +6 -4
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -35,28 +35,29 @@ npm install @rubenpazch/radio-button
|
|
|
35
35
|
|
|
36
36
|
## RadioGroup
|
|
37
37
|
|
|
38
|
-
| Prop | Tipo | Req. | Por defecto
|
|
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` | |
|
|
50
|
-
| `id` | `string` | |
|
|
51
|
-
| `label` | `string` | |
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
| `labels` | `Partial<{ selected: string; none: string; }>` | | | Textos de la interfaz. Por defecto, los del idioma activo (`UiLocaleProvider`); también se cambian para toda la app con su prop `messages`. |
|
|
53
|
+
| `orientation` | `"horizontal" \| "vertical"` | | `vertical` | |
|
|
54
|
+
| `required` | `boolean` | | `false` | |
|
|
55
|
+
| `selectedLabelText` | `string` | | | |
|
|
56
|
+
| `showSelectedLabel` | `boolean` | | `false` | |
|
|
57
|
+
| `size` | `"sm" \| "md" \| "lg"` | | `md` | |
|
|
58
|
+
| `value` | `string` | | | |
|
|
59
|
+
| `variant` | `"default" \| "primary" \| "success" \| "warning" \| "danger"` | | `default` | |
|
|
60
|
+
|
|
61
|
+
Tipos: `RadioButtonProps`, `RadioButtonNativeProps`, `RadioSize`, `RadioVariant`, `RadioGroupProps`, `RadioOption`, `RadioGroupOrientation`.
|
|
61
62
|
|
|
62
63
|
<!-- catalogo:fin -->
|
package/dist/RadioButton.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export type RadioSize = "sm" | "md" | "lg";
|
|
3
3
|
export type RadioVariant = "default" | "primary" | "success" | "warning" | "danger";
|
|
4
|
-
|
|
4
|
+
/** Atributos nativos del <input> que se pasan tal cual (aria-*, data-*, autoFocus, form…). */
|
|
5
|
+
export type RadioButtonNativeProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "id" | "name" | "value" | "checked" | "defaultChecked" | "onChange" | "disabled" | "className" | "required" | "size" | "type">;
|
|
6
|
+
export interface RadioButtonProps extends RadioButtonNativeProps {
|
|
5
7
|
id?: string;
|
|
6
8
|
name: string;
|
|
7
9
|
label: string;
|
|
@@ -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,
|
|
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,8FAA8F;AAC9F,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EACzC,IAAI,GACJ,MAAM,GACN,OAAO,GACP,SAAS,GACT,gBAAgB,GAChB,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,MAAM,GACN,MAAM,CACT,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAqDD,QAAA,MAAM,WAAW,2FAmHhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/dist/RadioGroup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { type UiMessages } from "@rubenpazch/shared";
|
|
2
3
|
import { RadioSize, RadioVariant } from "./RadioButton";
|
|
3
4
|
export type RadioGroupOrientation = "vertical" | "horizontal";
|
|
4
5
|
export interface RadioOption {
|
|
@@ -29,6 +30,11 @@ export interface RadioGroupProps {
|
|
|
29
30
|
groupLabel?: string;
|
|
30
31
|
bordered?: boolean;
|
|
31
32
|
borderLabel?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Textos de la interfaz. Por defecto, los del idioma activo (`UiLocaleProvider`);
|
|
35
|
+
* también se cambian para toda la app con su prop `messages`.
|
|
36
|
+
*/
|
|
37
|
+
labels?: Partial<UiMessages["radioGroup"]>;
|
|
32
38
|
}
|
|
33
39
|
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
34
40
|
export default RadioGroup;
|
package/dist/RadioGroup.d.ts.map
CHANGED
|
@@ -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,q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
|
var React = require('react');
|
|
6
|
+
var shared = require('@rubenpazch/shared');
|
|
6
7
|
|
|
7
8
|
var jsxRuntime = {exports: {}};
|
|
8
9
|
|
|
@@ -500,7 +501,7 @@ const variantClasses = {
|
|
|
500
501
|
focus: styles$1.radioFocusDanger,
|
|
501
502
|
},
|
|
502
503
|
};
|
|
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
|
+
const RadioButton = React.forwardRef(function RadioButton({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", ...nativeProps }, ref) {
|
|
504
505
|
const radioId = id || `radio-${name}-${value}`;
|
|
505
506
|
const describedBy = [description && `${radioId}-description`, error && `${radioId}-error`]
|
|
506
507
|
.filter(Boolean)
|
|
@@ -526,14 +527,15 @@ const RadioButton = React.forwardRef(function RadioButton({ id, name, label, val
|
|
|
526
527
|
: size === "lg"
|
|
527
528
|
? styles$1.errorLg
|
|
528
529
|
: styles$1.errorMd);
|
|
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
|
+
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", { ...nativeProps, 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
531
|
});
|
|
531
532
|
|
|
532
533
|
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
534
|
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"};
|
|
534
535
|
styleInject(css_248z);
|
|
535
536
|
|
|
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
|
|
537
|
+
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, groupLabel, bordered = false, borderLabel, labels, }, ref) {
|
|
538
|
+
const t = shared.useUiMessages("radioGroup", labels);
|
|
537
539
|
const generatedId = React.useId();
|
|
538
540
|
const baseId = id ?? `${name}-${generatedId}`;
|
|
539
541
|
const titulo = groupLabel ?? label;
|
|
@@ -547,7 +549,7 @@ const RadioGroup = React.forwardRef(function RadioGroup({ name, options, value,
|
|
|
547
549
|
};
|
|
548
550
|
const selectedOption = options.find((option) => option.value === value);
|
|
549
551
|
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 ||
|
|
552
|
+
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 ?? t.selected }), " ", selectedOption?.label || value || t.none] }))] }));
|
|
551
553
|
});
|
|
552
554
|
|
|
553
555
|
exports.RadioGroup = RadioGroup;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { UiMessages } from '@rubenpazch/shared';
|
|
2
3
|
|
|
3
4
|
type RadioSize = "sm" | "md" | "lg";
|
|
4
5
|
type RadioVariant = "default" | "primary" | "success" | "warning" | "danger";
|
|
5
|
-
|
|
6
|
+
/** Atributos nativos del <input> que se pasan tal cual (aria-*, data-*, autoFocus, form…). */
|
|
7
|
+
type RadioButtonNativeProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "id" | "name" | "value" | "checked" | "defaultChecked" | "onChange" | "disabled" | "className" | "required" | "size" | "type">;
|
|
8
|
+
interface RadioButtonProps extends RadioButtonNativeProps {
|
|
6
9
|
id?: string;
|
|
7
10
|
name: string;
|
|
8
11
|
label: string;
|
|
@@ -48,8 +51,13 @@ interface RadioGroupProps {
|
|
|
48
51
|
groupLabel?: string;
|
|
49
52
|
bordered?: boolean;
|
|
50
53
|
borderLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Textos de la interfaz. Por defecto, los del idioma activo (`UiLocaleProvider`);
|
|
56
|
+
* también se cambian para toda la app con su prop `messages`.
|
|
57
|
+
*/
|
|
58
|
+
labels?: Partial<UiMessages["radioGroup"]>;
|
|
51
59
|
}
|
|
52
60
|
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
53
61
|
|
|
54
62
|
export { RadioGroup, RadioButton as default };
|
|
55
|
-
export type { RadioButtonProps, RadioGroupOrientation, RadioGroupProps, RadioOption, RadioSize, RadioVariant };
|
|
63
|
+
export type { RadioButtonNativeProps, RadioButtonProps, RadioGroupOrientation, RadioGroupProps, RadioOption, RadioSize, RadioVariant };
|
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,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EACV,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,eAAe,EACf,WAAW,EACX,qBAAqB,GACtB,MAAM,cAAc,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { useUiMessages } from '@rubenpazch/shared';
|
|
2
3
|
|
|
3
4
|
var jsxRuntime = {exports: {}};
|
|
4
5
|
|
|
@@ -496,7 +497,7 @@ const variantClasses = {
|
|
|
496
497
|
focus: styles$1.radioFocusDanger,
|
|
497
498
|
},
|
|
498
499
|
};
|
|
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
|
+
const RadioButton = React.forwardRef(function RadioButton({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", ...nativeProps }, ref) {
|
|
500
501
|
const radioId = id || `radio-${name}-${value}`;
|
|
501
502
|
const describedBy = [description && `${radioId}-description`, error && `${radioId}-error`]
|
|
502
503
|
.filter(Boolean)
|
|
@@ -522,14 +523,15 @@ const RadioButton = React.forwardRef(function RadioButton({ id, name, label, val
|
|
|
522
523
|
: size === "lg"
|
|
523
524
|
? styles$1.errorLg
|
|
524
525
|
: styles$1.errorMd);
|
|
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
|
+
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", { ...nativeProps, 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
527
|
});
|
|
527
528
|
|
|
528
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\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
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","hint":"RadioGroup-module_hint__bFpkX"};
|
|
530
531
|
styleInject(css_248z);
|
|
531
532
|
|
|
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
|
|
533
|
+
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, groupLabel, bordered = false, borderLabel, labels, }, ref) {
|
|
534
|
+
const t = useUiMessages("radioGroup", labels);
|
|
533
535
|
const generatedId = React.useId();
|
|
534
536
|
const baseId = id ?? `${name}-${generatedId}`;
|
|
535
537
|
const titulo = groupLabel ?? label;
|
|
@@ -543,7 +545,7 @@ const RadioGroup = React.forwardRef(function RadioGroup({ name, options, value,
|
|
|
543
545
|
};
|
|
544
546
|
const selectedOption = options.find((option) => option.value === value);
|
|
545
547
|
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 ||
|
|
548
|
+
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 ?? t.selected }), " ", selectedOption?.label || value || t.none] }))] }));
|
|
547
549
|
});
|
|
548
550
|
|
|
549
551
|
export { RadioGroup, RadioButton as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/radio-button",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.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",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"usarCuando": "Elegir una sola opción entre pocas (2 a 6) visibles a la vez.",
|
|
44
44
|
"evitarCuando": "Muchas opciones: usa Select o Autocomplete."
|
|
45
45
|
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@rubenpazch/shared": "5.4.0"
|
|
48
|
+
},
|
|
46
49
|
"scripts": {
|
|
47
50
|
"build": "rollup -c",
|
|
48
51
|
"test": "jest --passWithNoTests"
|