| Total Complexity | 1 |
| Complexity/F | 0 |
| Lines of Code | 58 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import React from "react"; |
||
| 2 | |||
| 3 | export interface RadioProps { |
||
| 4 | /** HTML id of the input element */ |
||
| 5 | id: string; |
||
| 6 | /** HTML name of the input element */ |
||
| 7 | name: string; |
||
| 8 | /** Holds text for label associated with input element */ |
||
| 9 | label: string; |
||
| 10 | /** boolean indicating if this radio is selected */ |
||
| 11 | checked?: boolean; |
||
| 12 | /** The value of the input */ |
||
| 13 | value?: string | number | string[]; |
||
| 14 | /** Optional boolean to trigger a related context block. */ |
||
| 15 | trigger?: boolean; |
||
| 16 | /** boolean indicating if input must have a value, or not */ |
||
| 17 | required?: boolean; |
||
| 18 | /** Event listener which fires when a change event occurs (varies on input type) */ |
||
| 19 | onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; |
||
| 20 | /** Event listener which fires when a input loses focus */ |
||
| 21 | onBlur?: (event: React.ChangeEvent<HTMLInputElement>) => void; |
||
| 22 | } |
||
| 23 | |||
| 24 | const Radio: React.FunctionComponent<RadioProps> = ({ |
||
| 25 | id, |
||
| 26 | name, |
||
| 27 | label, |
||
| 28 | checked, |
||
| 29 | value, |
||
| 30 | required, |
||
| 31 | trigger, |
||
| 32 | onBlur, |
||
| 33 | onChange, |
||
| 34 | }): React.ReactElement => { |
||
| 35 | const clicked: boolean = id === value; |
||
| 36 | return ( |
||
| 37 | <label |
||
| 38 | data-tc-wenv-id={id} |
||
| 39 | data-tc-wenv-trigger={trigger} |
||
| 40 | className={clicked ? "active" : ""} |
||
| 41 | > |
||
| 42 | <input |
||
| 43 | id={id} |
||
| 44 | name={name} |
||
| 45 | type="radio" |
||
| 46 | checked={checked} |
||
| 47 | value={value} |
||
| 48 | onChange={onChange} |
||
| 49 | onBlur={onBlur} |
||
| 50 | required={required} |
||
| 51 | /> |
||
| 52 | <span>{label}</span> |
||
| 53 | </label> |
||
| 54 | ); |
||
| 55 | }; |
||
| 56 | |||
| 57 | export default Radio; |
||
| 58 |