-
Notifications
You must be signed in to change notification settings - Fork 97
/
CheckboxOwnSkin.js
63 lines (61 loc) · 1.63 KB
/
CheckboxOwnSkin.js
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
// @flow
// Extended version of Checkbox component from react-polymorph (simple skin)
import React from 'react';
import type { Element } from 'react';
// external libraries
import classnames from 'classnames';
import { pickDOMProps } from 'react-polymorph/lib/utils/props';
import ReactMarkdown from 'react-markdown';
import styles from './CheckboxOwnSkin.scss';
type Props = {
checked: boolean,
className: string,
disabled: boolean,
onChange: Function,
label: string | Element<any>,
description: string | Element<any>,
theme: Object,
themeId: string
};
export const CheckboxOwnSkin = (props: Props) => (
<div
role="presentation"
aria-hidden
className={classnames([
props.className,
props.theme[props.themeId].root,
props.disabled ? props.theme[props.themeId].disabled : null,
props.checked ? props.theme[props.themeId].checked : null
])}
onClick={event => {
if (!props.disabled && props.onChange) {
props.onChange(!props.checked, event);
}
}}
>
<input
{...pickDOMProps(props)}
className={props.theme[props.themeId].input}
type="checkbox"
/>
<div
className={classnames([
props.theme[props.themeId].check,
props.checked ? props.theme[props.themeId].checked : null
])}
/>
<div
className={styles.checkboxWrapper}
>
{props.label && (
// eslint-disable-next-line
<label className={props.theme[props.themeId].label}>
{props.label}
</label>
)}
{props.description && (
<ReactMarkdown source={props.description} />
)}
</div>
</div>
);