-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRadioButton.tsx
More file actions
62 lines (60 loc) · 1.57 KB
/
RadioButton.tsx
File metadata and controls
62 lines (60 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { MouseEvent } from 'react';
import { Colors } from '..';
import { Typography } from '../Typography';
import {
LabelWrapper,
RadioButtonInput,
RadioButtonWrapper,
} from './RadioButtonStyle';
export interface RadioButtonProps
extends Omit<React.HTMLAttributes<HTMLInputElement>, 'onChange'> {
label?: string;
helperText?: string;
disabled?: boolean;
name?: string;
checked?: boolean;
value?: string;
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
}
/**
* This is a controlled component, so you need to pass in the `checked` and `onChange` prop to make it work.
*/
export const RadioButton = React.forwardRef<HTMLInputElement, RadioButtonProps>(
function RadioButton(
{
label,
helperText,
disabled,
name,
checked,
value,
onChange,
...props
}: RadioButtonProps,
ref
) {
return (
<RadioButtonWrapper>
<RadioButtonInput
ref={ref}
disabled={disabled}
name={name}
checked={checked}
value={value}
type="radio"
onChange={onChange}
onMouseDown={(e: MouseEvent<HTMLInputElement>) => e.preventDefault()}
{...props}
/>
<LabelWrapper data-disabled={disabled}>
<Typography variant="body1" as="span" color={Colors.Neutral.B18}>
{label}
</Typography>
<Typography variant="subtitle2" as="span" color={Colors.Neutral.B40}>
{helperText}
</Typography>
</LabelWrapper>
</RadioButtonWrapper>
);
}
);