-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathConfigElement.tsx
84 lines (73 loc) · 2.07 KB
/
ConfigElement.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import MenuItem from './MenuItem';
import styles from './ConfigElement.module.css';
interface ButtonProps extends ConfigElementProps {
id: string;
label: string;
onClick: () => any;
}
export const Button: React.SFC<ButtonProps> =
({ label, onClick, ...rest }) => (
<ConfigElement {...rest}>
<div className={styles.toggle}>
<button onClick={onClick}>{label}</button>
</div>
</ConfigElement>
);
interface EitherProps extends ConfigElementProps {
id: string;
a: string;
b: string;
aLabel?: string;
bLabel?: string;
value: string;
onChange: (_: string) => any;
}
export const Either: React.FC<EitherProps> =
({ id, a, b, aLabel = a, bLabel = b, value, onChange, ...rest }) => (
<ConfigElement {...rest}>
<div className={styles.toggle}>
<input id={`${id}-a`}
name={id}
value={a}
type="radio"
checked={value === a}
onChange={() => onChange(a)} />
<label htmlFor={`${id}-a`}>{aLabel}</label>
<input id={`${id}-b`}
name={id}
value={b}
type="radio"
checked={value === b}
onChange={() => onChange(b)} />
<label htmlFor={`${id}-b`}>{bLabel}</label>
</div>
</ConfigElement>
);
interface SelectProps extends ConfigElementProps {
value: string;
onChange: (_: string) => any;
}
export const Select: React.FC<SelectProps> = ({ value, onChange, children, ...rest }) => (
<ConfigElement {...rest}>
<select className={styles.select} value={value} onChange={e => onChange(e.target.value)}>
{children}
</select>
</ConfigElement>
);
interface ConfigElementProps {
name: string;
isNotDefault?: boolean;
aside?: JSX.Element,
}
const ConfigElement: React.FC<ConfigElementProps> = ({ name, isNotDefault, aside, children }) => (
<MenuItem>
<div className={styles.container}>
<span className={isNotDefault ? styles.notDefault : styles.name}>{name}</span>
<div className={styles.value}>
{children}
</div>
</div>
{aside}
</MenuItem>
);