This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
radio_setting.tsx
64 lines (57 loc) · 2.01 KB
/
radio_setting.tsx
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
63
64
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import Setting from './setting';
type RadioSettingProps = {
id: string;
options: {text: string;value: string}[];
label: React.ReactNode;
onChange(name: string, value: any): void;
value?: string;
labelClassName?: string;
inputClassName?: string;
helpText?: React.ReactNode;
}
export default class RadioSetting extends React.Component<RadioSettingProps> {
public static defaultProps = {
labelClassName: '',
inputClassName: '',
options: [],
};
private handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
this.props.onChange(this.props.id, e.target.value);
}
public render() {
return (
<Setting
label={this.props.label}
labelClassName={this.props.labelClassName}
inputClassName={this.props.inputClassName}
helpText={this.props.helpText}
inputId={this.props.id}
>
{
this.props.options.map(({value, text}) => {
return (
<div
className='radio'
key={value}
>
<label>
<input
type='radio'
value={value}
name={this.props.id}
checked={value === this.props.value}
onChange={this.handleChange}
/>
{text}
</label>
</div>
);
})
}
</Setting>
);
}
}