Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 54 |
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 | /** Event listener which fires when a change event occurs (varies on input type) */ |
||
17 | onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; |
||
18 | /** Event listener which fires when a input loses focus */ |
||
19 | onBlur?: (event: React.ChangeEvent<HTMLInputElement>) => void; |
||
20 | } |
||
21 | |||
22 | const Radio: React.FunctionComponent<RadioProps> = ({ |
||
23 | id, |
||
24 | name, |
||
25 | label, |
||
26 | checked, |
||
27 | value, |
||
28 | trigger, |
||
29 | onBlur, |
||
30 | onChange, |
||
31 | }): React.ReactElement => { |
||
32 | const clicked: boolean = id === value; |
||
33 | return ( |
||
34 | <label |
||
35 | data-tc-wenv-id={id} |
||
36 | data-tc-wenv-trigger={trigger} |
||
37 | className={clicked ? "active" : ""} |
||
38 | > |
||
39 | <input |
||
40 | id={id} |
||
41 | name={name} |
||
42 | type="radio" |
||
43 | checked={checked} |
||
44 | value={value} |
||
45 | onChange={onChange} |
||
46 | onBlur={onBlur} |
||
47 | /> |
||
48 | <span>{label}</span> |
||
49 | </label> |
||
50 | ); |
||
51 | }; |
||
52 | |||
53 | export default Radio; |
||
54 |