fleet/frontend/components/forms/fields/Radio/Radio.tsx

63 lines
1.3 KiB
TypeScript
Raw Normal View History

import React, { ReactNode } from "react";
2021-04-14 16:52:15 +00:00
import classnames from "classnames";
import TooltipWrapper from "components/TooltipWrapper";
2021-04-14 16:52:15 +00:00
const baseClass = "radio";
export interface IRadioProps {
label: ReactNode;
value: string;
id: string;
onChange: (value: string) => void;
checked?: boolean;
name?: string;
className?: string;
disabled?: boolean;
2023-11-07 21:15:49 +00:00
tooltip?: React.ReactNode;
testId?: string;
}
const Radio = ({
className,
id,
name,
value,
checked,
disabled,
label,
tooltip,
testId,
onChange,
}: IRadioProps): JSX.Element => {
const wrapperClasses = classnames(baseClass, className, {
[`disabled`]: disabled,
});
return (
<label htmlFor={id} className={wrapperClasses} data-testid={testId}>
<span className={`${baseClass}__input`}>
<input
type="radio"
id={id}
disabled={disabled}
name={name}
value={value}
checked={checked}
2021-04-14 16:52:15 +00:00
onChange={(event) => onChange(event.target.value)}
/>
<span className={`${baseClass}__control`} />
</span>
<span className={`${baseClass}__label`}>
{tooltip ? (
<TooltipWrapper tipContent={tooltip}>{label}</TooltipWrapper>
) : (
<>{label}</>
)}
</span>
</label>
);
};
export default Radio;