fleet/frontend/components/forms/fields/Radio/Radio.tsx
Gabriel Hernandez f1995bf79e
Fleet UI update to testing tooling user-event library (#7514)
* adding FE testing documentation

* extend radio button tests

* update test to work with new user-events lib version

* more testing docs
2022-09-12 16:10:10 +01:00

62 lines
1.3 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import TooltipWrapper from "components/TooltipWrapper";
const baseClass = "radio";
export interface IRadioProps {
label: string;
value: string;
id: string;
onChange: (value: string) => void;
checked?: boolean;
name?: string;
className?: string;
disabled?: boolean;
tooltip?: string;
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}
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;