@rubenpazch/radio-button 4.2.0 → 4.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 CHANGED
@@ -35,27 +35,28 @@ npm install @rubenpazch/radio-button
35
35
 
36
36
  ## RadioGroup
37
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` | |
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` | `"vertical" \| "horizontal"` | | `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` | |
59
60
 
60
61
  Tipos: `RadioButtonProps`, `RadioSize`, `RadioVariant`, `RadioGroupProps`, `RadioOption`, `RadioGroupOrientation`.
61
62
 
@@ -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;
@@ -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,qB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defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
+ var shared = require('@rubenpazch/shared');
6
7
 
7
8
  var jsxRuntime = {exports: {}};
8
9
 
@@ -533,7 +534,8 @@ var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical_
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 = "Seleccionado:", groupLabel, bordered = false, borderLabel, }, ref) {
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 || "Ninguno"] }))] }));
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,4 +1,5 @@
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";
@@ -48,6 +49,11 @@ interface RadioGroupProps {
48
49
  groupLabel?: string;
49
50
  bordered?: boolean;
50
51
  borderLabel?: string;
52
+ /**
53
+ * Textos de la interfaz. Por defecto, los del idioma activo (`UiLocaleProvider`);
54
+ * también se cambian para toda la app con su prop `messages`.
55
+ */
56
+ labels?: Partial<UiMessages["radioGroup"]>;
51
57
  }
52
58
  declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
53
59
 
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
 
@@ -529,7 +530,8 @@ var css_248z = "/* Radio group orientation */\n.RadioGroup-module_groupVertical_
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 = "Seleccionado:", groupLabel, bordered = false, borderLabel, }, ref) {
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 || "Ninguno"] }))] }));
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.2.0",
3
+ "version": "4.3.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.4.0"
32
+ "@rubenpazch/tokens": "0.5.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@rubenpazch/typescript-config": "3.0.0"
@@ -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"