Files
portainer/app/react/components/RadioGroup/RadioGroup.tsx
T
Steven Kang 2406d67bfc feat(fcm): initial release (#1153)
Co-authored-by: Ali <83188384+testA113@users.noreply.github.com>
Co-authored-by: James Player <james.player@portainer.io>
Co-authored-by: Cara Ryan <cara.ryan@portainer.io>
Co-authored-by: testA113 <aliharriss1995@gmail.com>
Co-authored-by: Viktor Pettersson <viktor.pettersson@portainer.io>
Co-authored-by: Viktor Pettersson <viktor.grasljunga@gmail.com>
Co-authored-by: Malcolm Lockyer <segfault88@users.noreply.github.com>
Co-authored-by: RHCowan <50324595+RHCowan@users.noreply.github.com>
Co-authored-by: Robbie Cowan <robert.cowan@portainer.io>
2025-12-09 08:05:38 +09:00

54 lines
1.3 KiB
TypeScript

import { ReactNode } from 'react';
// allow custom labels
export interface RadioGroupOption<TValue> {
value: TValue;
label: ReactNode;
disabled?: boolean;
}
interface Props<T extends string | number> {
options: Array<RadioGroupOption<T>> | ReadonlyArray<RadioGroupOption<T>>;
selectedOption: T;
name: string;
onOptionChange: (value: T) => void;
groupClassName?: string;
itemClassName?: string;
}
export function RadioGroup<T extends string | number = string>({
options,
selectedOption,
name,
onOptionChange,
groupClassName,
itemClassName,
}: Props<T>) {
return (
<div className={groupClassName ?? 'flex flex-wrap gap-x-2 gap-y-1'}>
{options.map((option) => (
<label
key={option.value}
className={
itemClassName ??
'col-sm-3 col-lg-2 control-label !p-0 text-left font-normal cursor-pointer'
}
>
<input
type="radio"
name={name}
value={option.value}
checked={selectedOption === option.value}
onChange={() => onOptionChange(option.value)}
style={{ margin: '0 4px 0 0' }}
data-cy={`radio-${option.value}`}
disabled={option.disabled}
className="cursor-pointer"
/>
{option.label}
</label>
))}
</div>
);
}