2019-03-08 04:32:08 +00:00
|
|
|
import React, { useContext } from 'react';
|
2018-11-24 18:29:07 +00:00
|
|
|
import { CheckIcon } from './Icons';
|
2018-10-28 02:56:25 +00:00
|
|
|
import styles from './Checkbox.module.css';
|
2019-03-08 04:32:08 +00:00
|
|
|
import ThemeContext from './ThemeContext';
|
2018-10-26 12:38:01 +00:00
|
|
|
|
2019-03-08 04:32:08 +00:00
|
|
|
export default ({ className, value, accentSelected, onChange, label }) => {
|
|
|
|
const { getActiveColorOrFallback } = useContext(ThemeContext);
|
|
|
|
return (
|
|
|
|
<label
|
|
|
|
className={ [styles.wrapper, className].join(' ') }
|
|
|
|
style={{
|
|
|
|
color: value && accentSelected
|
|
|
|
? getActiveColorOrFallback(['accent3'])
|
|
|
|
: getActiveColorOrFallback(['shade7']),
|
|
|
|
}}
|
|
|
|
tabIndex="0"
|
|
|
|
onKeyDown={ evt => {
|
|
|
|
if (evt.key === ' ' || evt.key === 'Enter') {
|
|
|
|
evt.preventDefault();
|
|
|
|
onChange(!value);
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
className={ styles.input }
|
|
|
|
checked={ value }
|
|
|
|
onChange={ evt => onChange(evt.target.checked) }
|
|
|
|
/>
|
|
|
|
<CheckIcon
|
|
|
|
backgroundColor={
|
|
|
|
value
|
|
|
|
? ( accentSelected
|
|
|
|
? getActiveColorOrFallback(['accent3'])
|
2019-03-09 20:06:27 +00:00
|
|
|
: getActiveColorOrFallback(['shade7'])
|
2019-03-08 04:32:08 +00:00
|
|
|
) : 'transparent'
|
|
|
|
}
|
|
|
|
outlineColor={ value ? 'transparent' : getActiveColorOrFallback(['shade7']) }
|
|
|
|
checkColor={ value ? getActiveColorOrFallback(['shade0'], true) : 'transparent' }
|
|
|
|
/>
|
|
|
|
<span className={ styles.label }>{ label }</span>
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|