Files
community-rule/app/components/RadioGroup.js
T
adilallo fa5a190416
CI Pipeline / test (20) (pull_request) Successful in 2m30s
CI Pipeline / test (18) (pull_request) Successful in 3m51s
CI Pipeline / e2e (firefox) (pull_request) Successful in 3m22s
CI Pipeline / e2e (webkit) (pull_request) Successful in 3m45s
CI Pipeline / e2e (chromium) (pull_request) Successful in 11m49s
CI Pipeline / visual-regression (pull_request) Successful in 6m48s
CI Pipeline / storybook (pull_request) Successful in 1m35s
CI Pipeline / lint (pull_request) Successful in 1m12s
CI Pipeline / build (pull_request) Successful in 1m54s
CI Pipeline / performance (pull_request) Successful in 4m6s
Fix failing tests
2025-10-14 20:47:34 -06:00

66 lines
1.4 KiB
JavaScript

"use client";
import React, { memo, useCallback, useId } from "react";
import RadioButton from "./RadioButton";
const RadioGroup = ({
name,
value,
onChange,
mode = "standard",
state = "default",
disabled = false,
options = [],
className = "",
...props
}) => {
// Generate unique ID for accessibility if not provided
const generatedId = useId();
const groupId = name || `radio-group-${generatedId}`;
const handleChange = useCallback(
(optionValue) => {
if (!disabled && onChange) {
onChange({ value: optionValue });
}
},
[disabled, onChange],
);
return (
<div
className={`space-y-[8px] ${className}`}
role="radiogroup"
aria-label={props["aria-label"]}
{...props}
>
{options.map((option, index) => {
const isSelected = value === option.value;
return (
<RadioButton
key={option.value}
checked={isSelected}
mode={mode}
state={state}
disabled={disabled}
label={option.label}
name={groupId}
value={option.value}
ariaLabel={option.ariaLabel}
onChange={({ checked }) => {
if (checked) {
handleChange(option.value);
}
}}
/>
);
})}
</div>
);
};
RadioGroup.displayName = "RadioGroup";
export default memo(RadioGroup);