mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-14 20:40:52 -05:00
43 lines
782 B
TypeScript
43 lines
782 B
TypeScript
|
import React from 'react'
|
||
|
|
||
|
type RadioChipProps<ValueType> = {
|
||
|
checked?: boolean
|
||
|
disabled?: boolean
|
||
|
name: string
|
||
|
onChange: (value: ValueType) => void
|
||
|
required?: boolean
|
||
|
label: React.ReactElement | string
|
||
|
value: ValueType
|
||
|
}
|
||
|
|
||
|
const RadioChip = <T extends string>({
|
||
|
checked,
|
||
|
disabled,
|
||
|
name,
|
||
|
onChange,
|
||
|
label,
|
||
|
required,
|
||
|
value,
|
||
|
}: RadioChipProps<T>) => {
|
||
|
const handleChange = () => {
|
||
|
onChange(value)
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<label className="radio-chip" data-disabled={disabled ? 'true' : undefined}>
|
||
|
<input
|
||
|
checked={checked}
|
||
|
disabled={disabled}
|
||
|
name={name}
|
||
|
onChange={handleChange}
|
||
|
type="radio"
|
||
|
required={required}
|
||
|
value={value}
|
||
|
/>
|
||
|
{label}
|
||
|
</label>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export default RadioChip
|