@rubenpazch/radio-button 2.0.0 → 3.0.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/dist/RadioButton.d.ts.map +1 -1
- package/dist/index.cjs.js +69 -39
- package/dist/index.esm.js +69 -39
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../src/RadioButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
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,GACpB,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,QAAQ,CAAC;AAEb,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,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,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAgG3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -426,46 +426,78 @@ function requireJsxRuntime () {
|
|
|
426
426
|
|
|
427
427
|
var jsxRuntimeExports = requireJsxRuntime();
|
|
428
428
|
|
|
429
|
+
function styleInject(css, ref) {
|
|
430
|
+
if ( ref === void 0 ) ref = {};
|
|
431
|
+
var insertAt = ref.insertAt;
|
|
432
|
+
|
|
433
|
+
if (typeof document === 'undefined') { return; }
|
|
434
|
+
|
|
435
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
436
|
+
var style = document.createElement('style');
|
|
437
|
+
style.type = 'text/css';
|
|
438
|
+
|
|
439
|
+
if (insertAt === 'top') {
|
|
440
|
+
if (head.firstChild) {
|
|
441
|
+
head.insertBefore(style, head.firstChild);
|
|
442
|
+
} else {
|
|
443
|
+
head.appendChild(style);
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
head.appendChild(style);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (style.styleSheet) {
|
|
450
|
+
style.styleSheet.cssText = css;
|
|
451
|
+
} else {
|
|
452
|
+
style.appendChild(document.createTextNode(css));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
var css_248z = "/* Container */\n.RadioButton-module_container__djpgH {\n display: flex;\n}\n\n/* Radio wrapper */\n.RadioButton-module_radioWrapper__B--bk {\n display: flex;\n align-items: flex-start;\n}\n\n/* Radio input base styles */\n.RadioButton-module_radio__0qwuN {\n cursor: pointer;\n transition: all 150ms ease;\n border-width: 1px;\n border-style: solid;\n}\n\n.RadioButton-module_radio__0qwuN:focus {\n outline: none;\n box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);\n border-color: currentColor;\n}\n\n.RadioButton-module_radioDisabled__-Go-G {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.RadioButton-module_radioDisabled__-Go-G:focus {\n box-shadow: none;\n}\n\n/* Radio sizes */\n.RadioButton-module_radioSm__OFgkW {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.RadioButton-module_radioMd__ODMND {\n width: 1rem;\n height: 1rem;\n}\n\n.RadioButton-module_radioLg__JNQ1i {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n/* Container heights for alignment */\n.RadioButton-module_containerSm__lRtj6 {\n height: 1rem;\n}\n\n.RadioButton-module_containerMd__0M3ye {\n height: 1.25rem;\n}\n\n.RadioButton-module_containerLg__6cNDS {\n height: 1.5rem;\n}\n\n/* Radio border colors */\n.RadioButton-module_radioBorderDefault__XKQUN {\n border-color: #d1d5db;\n}\n\n.RadioButton-module_radioBorderRequired__P4-sB {\n border-color: #ef4444;\n}\n\n/* Radio variants - checked state colors */\n.RadioButton-module_radioDefault__3eGat {\n color: #2563eb;\n}\n\n.RadioButton-module_radioPrimary__SdKsD {\n color: #4f46e5;\n}\n\n.RadioButton-module_radioSuccess__Kktb6 {\n color: #16a34a;\n}\n\n.RadioButton-module_radioWarning__nGt0i {\n color: #ca8a04;\n}\n\n.RadioButton-module_radioDanger__VVih- {\n color: #dc2626;\n}\n\n/* Radio focus ring colors */\n.RadioButton-module_radioFocusDefault__2vgX4:focus {\n box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);\n}\n\n.RadioButton-module_radioFocusPrimary__xowqj:focus {\n box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);\n}\n\n.RadioButton-module_radioFocusSuccess__Kjf-i:focus {\n box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);\n}\n\n.RadioButton-module_radioFocusWarning__70geb:focus {\n box-shadow: 0 0 0 2px rgba(202, 138, 4, 0.2);\n}\n\n.RadioButton-module_radioFocusDanger__iEn6l:focus {\n box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);\n}\n\n/* Content wrapper */\n.RadioButton-module_contentWrapper__ZO1lz {\n margin-left: 0.75rem;\n flex: 1;\n}\n\n/* Label styles */\n.RadioButton-module_label__51-xH {\n display: block;\n font-weight: 500;\n cursor: pointer;\n}\n\n.RadioButton-module_labelSm__3EYBQ {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_labelMd__zaX9f {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.RadioButton-module_labelLg__GVVcz {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.RadioButton-module_labelDefault__JR0tu {\n color: #374151;\n}\n\n.RadioButton-module_labelDisabled__ZxGi4 {\n color: #9ca3af;\n cursor: not-allowed;\n}\n\n.RadioButton-module_labelRequired__zi0lY {\n color: #dc2626;\n cursor: pointer;\n}\n\n/* Description styles */\n.RadioButton-module_description__wQLxD {\n margin-top: 0.125rem;\n color: #6b7280;\n}\n\n.RadioButton-module_descriptionSm__HvSLH {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.RadioButton-module_descriptionMd__DPo-2 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_descriptionLg__ARNPn {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n/* Error message styles */\n.RadioButton-module_error__WmXjN {\n margin-top: 0.125rem;\n color: #dc2626;\n}\n\n.RadioButton-module_errorSm__um4SY {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.RadioButton-module_errorMd__DgI7N {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_errorLg__u-854 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n";
|
|
457
|
+
var styles = {"container":"RadioButton-module_container__djpgH","radioWrapper":"RadioButton-module_radioWrapper__B--bk","radio":"RadioButton-module_radio__0qwuN","radioDisabled":"RadioButton-module_radioDisabled__-Go-G","radioSm":"RadioButton-module_radioSm__OFgkW","radioMd":"RadioButton-module_radioMd__ODMND","radioLg":"RadioButton-module_radioLg__JNQ1i","containerSm":"RadioButton-module_containerSm__lRtj6","containerMd":"RadioButton-module_containerMd__0M3ye","containerLg":"RadioButton-module_containerLg__6cNDS","radioBorderDefault":"RadioButton-module_radioBorderDefault__XKQUN","radioBorderRequired":"RadioButton-module_radioBorderRequired__P4-sB","radioDefault":"RadioButton-module_radioDefault__3eGat","radioPrimary":"RadioButton-module_radioPrimary__SdKsD","radioSuccess":"RadioButton-module_radioSuccess__Kktb6","radioWarning":"RadioButton-module_radioWarning__nGt0i","radioDanger":"RadioButton-module_radioDanger__VVih-","radioFocusDefault":"RadioButton-module_radioFocusDefault__2vgX4","radioFocusPrimary":"RadioButton-module_radioFocusPrimary__xowqj","radioFocusSuccess":"RadioButton-module_radioFocusSuccess__Kjf-i","radioFocusWarning":"RadioButton-module_radioFocusWarning__70geb","radioFocusDanger":"RadioButton-module_radioFocusDanger__iEn6l","contentWrapper":"RadioButton-module_contentWrapper__ZO1lz","label":"RadioButton-module_label__51-xH","labelSm":"RadioButton-module_labelSm__3EYBQ","labelMd":"RadioButton-module_labelMd__zaX9f","labelLg":"RadioButton-module_labelLg__GVVcz","labelDefault":"RadioButton-module_labelDefault__JR0tu","labelDisabled":"RadioButton-module_labelDisabled__ZxGi4","labelRequired":"RadioButton-module_labelRequired__zi0lY","description":"RadioButton-module_description__wQLxD","descriptionSm":"RadioButton-module_descriptionSm__HvSLH","descriptionMd":"RadioButton-module_descriptionMd__DPo-2","descriptionLg":"RadioButton-module_descriptionLg__ARNPn","error":"RadioButton-module_error__WmXjN","errorSm":"RadioButton-module_errorSm__um4SY","errorMd":"RadioButton-module_errorMd__DgI7N","errorLg":"RadioButton-module_errorLg__u-854"};
|
|
458
|
+
styleInject(css_248z);
|
|
459
|
+
|
|
460
|
+
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
429
461
|
const sizeClasses = {
|
|
430
462
|
sm: {
|
|
431
|
-
radio:
|
|
432
|
-
label:
|
|
433
|
-
description:
|
|
434
|
-
container:
|
|
463
|
+
radio: styles.radioSm,
|
|
464
|
+
label: styles.labelSm,
|
|
465
|
+
description: styles.descriptionSm,
|
|
466
|
+
container: styles.containerSm,
|
|
435
467
|
},
|
|
436
468
|
md: {
|
|
437
|
-
radio:
|
|
438
|
-
label:
|
|
439
|
-
description:
|
|
440
|
-
container:
|
|
469
|
+
radio: styles.radioMd,
|
|
470
|
+
label: styles.labelMd,
|
|
471
|
+
description: styles.descriptionMd,
|
|
472
|
+
container: styles.containerMd,
|
|
441
473
|
},
|
|
442
474
|
lg: {
|
|
443
|
-
radio:
|
|
444
|
-
label:
|
|
445
|
-
description:
|
|
446
|
-
container:
|
|
475
|
+
radio: styles.radioLg,
|
|
476
|
+
label: styles.labelLg,
|
|
477
|
+
description: styles.descriptionLg,
|
|
478
|
+
container: styles.containerLg,
|
|
447
479
|
},
|
|
448
480
|
};
|
|
449
481
|
const variantClasses = {
|
|
450
482
|
default: {
|
|
451
|
-
checked:
|
|
452
|
-
focus:
|
|
483
|
+
checked: styles.radioDefault,
|
|
484
|
+
focus: styles.radioFocusDefault,
|
|
453
485
|
},
|
|
454
486
|
primary: {
|
|
455
|
-
checked:
|
|
456
|
-
focus:
|
|
487
|
+
checked: styles.radioPrimary,
|
|
488
|
+
focus: styles.radioFocusPrimary,
|
|
457
489
|
},
|
|
458
490
|
success: {
|
|
459
|
-
checked:
|
|
460
|
-
focus:
|
|
491
|
+
checked: styles.radioSuccess,
|
|
492
|
+
focus: styles.radioFocusSuccess,
|
|
461
493
|
},
|
|
462
494
|
warning: {
|
|
463
|
-
checked:
|
|
464
|
-
focus:
|
|
495
|
+
checked: styles.radioWarning,
|
|
496
|
+
focus: styles.radioFocusWarning,
|
|
465
497
|
},
|
|
466
498
|
danger: {
|
|
467
|
-
checked:
|
|
468
|
-
focus:
|
|
499
|
+
checked: styles.radioDanger,
|
|
500
|
+
focus: styles.radioFocusDanger,
|
|
469
501
|
},
|
|
470
502
|
};
|
|
471
503
|
const RadioButton = ({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }) => {
|
|
@@ -477,23 +509,21 @@ const RadioButton = ({ id, name, label, value, checked = false, onChange, disabl
|
|
|
477
509
|
onChange(event.target.value);
|
|
478
510
|
}
|
|
479
511
|
};
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
block
|
|
496
|
-
`, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: `${sizes.description} text-gray-500 mt-0.5`, children: description })), error && (jsxRuntimeExports.jsx("p", { className: `${sizes.description} text-red-600 mt-0.5`, children: error }))] })] }));
|
|
512
|
+
const radioClasses = classNames(styles.radio, sizes.radio, sizes.container, variants.checked, variants.focus, required && !checked
|
|
513
|
+
? styles.radioBorderRequired
|
|
514
|
+
: styles.radioBorderDefault, disabled && styles.radioDisabled);
|
|
515
|
+
const labelClasses = classNames(styles.label, sizes.label, disabled
|
|
516
|
+
? styles.labelDisabled
|
|
517
|
+
: required && !checked
|
|
518
|
+
? styles.labelRequired
|
|
519
|
+
: styles.labelDefault);
|
|
520
|
+
const descriptionClasses = classNames(styles.description, sizes.description);
|
|
521
|
+
const errorClasses = classNames(styles.error, size === "sm"
|
|
522
|
+
? styles.errorSm
|
|
523
|
+
: size === "lg"
|
|
524
|
+
? styles.errorLg
|
|
525
|
+
: styles.errorMd);
|
|
526
|
+
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles.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.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.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 })] })] }));
|
|
497
527
|
};
|
|
498
528
|
|
|
499
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, }) => {
|
package/dist/index.esm.js
CHANGED
|
@@ -422,46 +422,78 @@ function requireJsxRuntime () {
|
|
|
422
422
|
|
|
423
423
|
var jsxRuntimeExports = requireJsxRuntime();
|
|
424
424
|
|
|
425
|
+
function styleInject(css, ref) {
|
|
426
|
+
if ( ref === void 0 ) ref = {};
|
|
427
|
+
var insertAt = ref.insertAt;
|
|
428
|
+
|
|
429
|
+
if (typeof document === 'undefined') { return; }
|
|
430
|
+
|
|
431
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
432
|
+
var style = document.createElement('style');
|
|
433
|
+
style.type = 'text/css';
|
|
434
|
+
|
|
435
|
+
if (insertAt === 'top') {
|
|
436
|
+
if (head.firstChild) {
|
|
437
|
+
head.insertBefore(style, head.firstChild);
|
|
438
|
+
} else {
|
|
439
|
+
head.appendChild(style);
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
head.appendChild(style);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (style.styleSheet) {
|
|
446
|
+
style.styleSheet.cssText = css;
|
|
447
|
+
} else {
|
|
448
|
+
style.appendChild(document.createTextNode(css));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
var css_248z = "/* Container */\n.RadioButton-module_container__djpgH {\n display: flex;\n}\n\n/* Radio wrapper */\n.RadioButton-module_radioWrapper__B--bk {\n display: flex;\n align-items: flex-start;\n}\n\n/* Radio input base styles */\n.RadioButton-module_radio__0qwuN {\n cursor: pointer;\n transition: all 150ms ease;\n border-width: 1px;\n border-style: solid;\n}\n\n.RadioButton-module_radio__0qwuN:focus {\n outline: none;\n box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);\n border-color: currentColor;\n}\n\n.RadioButton-module_radioDisabled__-Go-G {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.RadioButton-module_radioDisabled__-Go-G:focus {\n box-shadow: none;\n}\n\n/* Radio sizes */\n.RadioButton-module_radioSm__OFgkW {\n width: 0.75rem;\n height: 0.75rem;\n}\n\n.RadioButton-module_radioMd__ODMND {\n width: 1rem;\n height: 1rem;\n}\n\n.RadioButton-module_radioLg__JNQ1i {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n/* Container heights for alignment */\n.RadioButton-module_containerSm__lRtj6 {\n height: 1rem;\n}\n\n.RadioButton-module_containerMd__0M3ye {\n height: 1.25rem;\n}\n\n.RadioButton-module_containerLg__6cNDS {\n height: 1.5rem;\n}\n\n/* Radio border colors */\n.RadioButton-module_radioBorderDefault__XKQUN {\n border-color: #d1d5db;\n}\n\n.RadioButton-module_radioBorderRequired__P4-sB {\n border-color: #ef4444;\n}\n\n/* Radio variants - checked state colors */\n.RadioButton-module_radioDefault__3eGat {\n color: #2563eb;\n}\n\n.RadioButton-module_radioPrimary__SdKsD {\n color: #4f46e5;\n}\n\n.RadioButton-module_radioSuccess__Kktb6 {\n color: #16a34a;\n}\n\n.RadioButton-module_radioWarning__nGt0i {\n color: #ca8a04;\n}\n\n.RadioButton-module_radioDanger__VVih- {\n color: #dc2626;\n}\n\n/* Radio focus ring colors */\n.RadioButton-module_radioFocusDefault__2vgX4:focus {\n box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);\n}\n\n.RadioButton-module_radioFocusPrimary__xowqj:focus {\n box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);\n}\n\n.RadioButton-module_radioFocusSuccess__Kjf-i:focus {\n box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);\n}\n\n.RadioButton-module_radioFocusWarning__70geb:focus {\n box-shadow: 0 0 0 2px rgba(202, 138, 4, 0.2);\n}\n\n.RadioButton-module_radioFocusDanger__iEn6l:focus {\n box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);\n}\n\n/* Content wrapper */\n.RadioButton-module_contentWrapper__ZO1lz {\n margin-left: 0.75rem;\n flex: 1;\n}\n\n/* Label styles */\n.RadioButton-module_label__51-xH {\n display: block;\n font-weight: 500;\n cursor: pointer;\n}\n\n.RadioButton-module_labelSm__3EYBQ {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_labelMd__zaX9f {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n.RadioButton-module_labelLg__GVVcz {\n font-size: 1rem;\n line-height: 1.5rem;\n}\n\n.RadioButton-module_labelDefault__JR0tu {\n color: #374151;\n}\n\n.RadioButton-module_labelDisabled__ZxGi4 {\n color: #9ca3af;\n cursor: not-allowed;\n}\n\n.RadioButton-module_labelRequired__zi0lY {\n color: #dc2626;\n cursor: pointer;\n}\n\n/* Description styles */\n.RadioButton-module_description__wQLxD {\n margin-top: 0.125rem;\n color: #6b7280;\n}\n\n.RadioButton-module_descriptionSm__HvSLH {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.RadioButton-module_descriptionMd__DPo-2 {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_descriptionLg__ARNPn {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n\n/* Error message styles */\n.RadioButton-module_error__WmXjN {\n margin-top: 0.125rem;\n color: #dc2626;\n}\n\n.RadioButton-module_errorSm__um4SY {\n font-size: 0.625rem;\n line-height: 0.875rem;\n}\n\n.RadioButton-module_errorMd__DgI7N {\n font-size: 0.75rem;\n line-height: 1rem;\n}\n\n.RadioButton-module_errorLg__u-854 {\n font-size: 0.875rem;\n line-height: 1.25rem;\n}\n";
|
|
453
|
+
var styles = {"container":"RadioButton-module_container__djpgH","radioWrapper":"RadioButton-module_radioWrapper__B--bk","radio":"RadioButton-module_radio__0qwuN","radioDisabled":"RadioButton-module_radioDisabled__-Go-G","radioSm":"RadioButton-module_radioSm__OFgkW","radioMd":"RadioButton-module_radioMd__ODMND","radioLg":"RadioButton-module_radioLg__JNQ1i","containerSm":"RadioButton-module_containerSm__lRtj6","containerMd":"RadioButton-module_containerMd__0M3ye","containerLg":"RadioButton-module_containerLg__6cNDS","radioBorderDefault":"RadioButton-module_radioBorderDefault__XKQUN","radioBorderRequired":"RadioButton-module_radioBorderRequired__P4-sB","radioDefault":"RadioButton-module_radioDefault__3eGat","radioPrimary":"RadioButton-module_radioPrimary__SdKsD","radioSuccess":"RadioButton-module_radioSuccess__Kktb6","radioWarning":"RadioButton-module_radioWarning__nGt0i","radioDanger":"RadioButton-module_radioDanger__VVih-","radioFocusDefault":"RadioButton-module_radioFocusDefault__2vgX4","radioFocusPrimary":"RadioButton-module_radioFocusPrimary__xowqj","radioFocusSuccess":"RadioButton-module_radioFocusSuccess__Kjf-i","radioFocusWarning":"RadioButton-module_radioFocusWarning__70geb","radioFocusDanger":"RadioButton-module_radioFocusDanger__iEn6l","contentWrapper":"RadioButton-module_contentWrapper__ZO1lz","label":"RadioButton-module_label__51-xH","labelSm":"RadioButton-module_labelSm__3EYBQ","labelMd":"RadioButton-module_labelMd__zaX9f","labelLg":"RadioButton-module_labelLg__GVVcz","labelDefault":"RadioButton-module_labelDefault__JR0tu","labelDisabled":"RadioButton-module_labelDisabled__ZxGi4","labelRequired":"RadioButton-module_labelRequired__zi0lY","description":"RadioButton-module_description__wQLxD","descriptionSm":"RadioButton-module_descriptionSm__HvSLH","descriptionMd":"RadioButton-module_descriptionMd__DPo-2","descriptionLg":"RadioButton-module_descriptionLg__ARNPn","error":"RadioButton-module_error__WmXjN","errorSm":"RadioButton-module_errorSm__um4SY","errorMd":"RadioButton-module_errorMd__DgI7N","errorLg":"RadioButton-module_errorLg__u-854"};
|
|
454
|
+
styleInject(css_248z);
|
|
455
|
+
|
|
456
|
+
const classNames = (...classes) => classes.filter(Boolean).join(" ");
|
|
425
457
|
const sizeClasses = {
|
|
426
458
|
sm: {
|
|
427
|
-
radio:
|
|
428
|
-
label:
|
|
429
|
-
description:
|
|
430
|
-
container:
|
|
459
|
+
radio: styles.radioSm,
|
|
460
|
+
label: styles.labelSm,
|
|
461
|
+
description: styles.descriptionSm,
|
|
462
|
+
container: styles.containerSm,
|
|
431
463
|
},
|
|
432
464
|
md: {
|
|
433
|
-
radio:
|
|
434
|
-
label:
|
|
435
|
-
description:
|
|
436
|
-
container:
|
|
465
|
+
radio: styles.radioMd,
|
|
466
|
+
label: styles.labelMd,
|
|
467
|
+
description: styles.descriptionMd,
|
|
468
|
+
container: styles.containerMd,
|
|
437
469
|
},
|
|
438
470
|
lg: {
|
|
439
|
-
radio:
|
|
440
|
-
label:
|
|
441
|
-
description:
|
|
442
|
-
container:
|
|
471
|
+
radio: styles.radioLg,
|
|
472
|
+
label: styles.labelLg,
|
|
473
|
+
description: styles.descriptionLg,
|
|
474
|
+
container: styles.containerLg,
|
|
443
475
|
},
|
|
444
476
|
};
|
|
445
477
|
const variantClasses = {
|
|
446
478
|
default: {
|
|
447
|
-
checked:
|
|
448
|
-
focus:
|
|
479
|
+
checked: styles.radioDefault,
|
|
480
|
+
focus: styles.radioFocusDefault,
|
|
449
481
|
},
|
|
450
482
|
primary: {
|
|
451
|
-
checked:
|
|
452
|
-
focus:
|
|
483
|
+
checked: styles.radioPrimary,
|
|
484
|
+
focus: styles.radioFocusPrimary,
|
|
453
485
|
},
|
|
454
486
|
success: {
|
|
455
|
-
checked:
|
|
456
|
-
focus:
|
|
487
|
+
checked: styles.radioSuccess,
|
|
488
|
+
focus: styles.radioFocusSuccess,
|
|
457
489
|
},
|
|
458
490
|
warning: {
|
|
459
|
-
checked:
|
|
460
|
-
focus:
|
|
491
|
+
checked: styles.radioWarning,
|
|
492
|
+
focus: styles.radioFocusWarning,
|
|
461
493
|
},
|
|
462
494
|
danger: {
|
|
463
|
-
checked:
|
|
464
|
-
focus:
|
|
495
|
+
checked: styles.radioDanger,
|
|
496
|
+
focus: styles.radioFocusDanger,
|
|
465
497
|
},
|
|
466
498
|
};
|
|
467
499
|
const RadioButton = ({ id, name, label, value, checked = false, onChange, disabled = false, description, error, className = "", required = false, size = "md", variant = "default", }) => {
|
|
@@ -473,23 +505,21 @@ const RadioButton = ({ id, name, label, value, checked = false, onChange, disabl
|
|
|
473
505
|
onChange(event.target.value);
|
|
474
506
|
}
|
|
475
507
|
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
block
|
|
492
|
-
`, children: label }), description && (jsxRuntimeExports.jsx("p", { id: `${radioId}-description`, className: `${sizes.description} text-gray-500 mt-0.5`, children: description })), error && (jsxRuntimeExports.jsx("p", { className: `${sizes.description} text-red-600 mt-0.5`, children: error }))] })] }));
|
|
508
|
+
const radioClasses = classNames(styles.radio, sizes.radio, sizes.container, variants.checked, variants.focus, required && !checked
|
|
509
|
+
? styles.radioBorderRequired
|
|
510
|
+
: styles.radioBorderDefault, disabled && styles.radioDisabled);
|
|
511
|
+
const labelClasses = classNames(styles.label, sizes.label, disabled
|
|
512
|
+
? styles.labelDisabled
|
|
513
|
+
: required && !checked
|
|
514
|
+
? styles.labelRequired
|
|
515
|
+
: styles.labelDefault);
|
|
516
|
+
const descriptionClasses = classNames(styles.description, sizes.description);
|
|
517
|
+
const errorClasses = classNames(styles.error, size === "sm"
|
|
518
|
+
? styles.errorSm
|
|
519
|
+
: size === "lg"
|
|
520
|
+
? styles.errorLg
|
|
521
|
+
: styles.errorMd);
|
|
522
|
+
return (jsxRuntimeExports.jsxs("div", { className: classNames(styles.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.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.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 })] })] }));
|
|
493
523
|
};
|
|
494
524
|
|
|
495
525
|
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, }) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/radio-button",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"sideEffects":
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"**/*.css"
|
|
21
|
+
],
|
|
20
22
|
"exports": {
|
|
21
23
|
".": {
|
|
22
24
|
"import": "./dist/index.esm.js",
|