2016-10-28 16:59:28 +03:00
|
|
|
const React = require('react');
|
2017-02-15 03:19:26 +02:00
|
|
|
const composers = require('../../shared/composers');
|
2016-12-09 12:40:57 +02:00
|
|
|
const constants = require('../../shared/constants');
|
2016-12-09 16:56:34 +02:00
|
|
|
const fns = require('../../shared/functions');
|
2016-12-09 12:40:57 +02:00
|
|
|
const Styled = require('styled-components');
|
|
|
|
|
|
|
|
const {
|
|
|
|
boxes
|
|
|
|
} = constants;
|
|
|
|
|
2017-02-15 03:19:26 +02:00
|
|
|
const {
|
|
|
|
Baseline
|
|
|
|
} = composers;
|
|
|
|
|
2016-12-09 16:56:34 +02:00
|
|
|
const {
|
2017-01-12 21:04:52 +02:00
|
|
|
rndId,
|
|
|
|
remcalc
|
2016-12-09 16:56:34 +02:00
|
|
|
} = fns;
|
|
|
|
|
2016-12-09 12:40:57 +02:00
|
|
|
const {
|
2017-02-20 16:51:54 +02:00
|
|
|
default: styled
|
2016-12-09 12:40:57 +02:00
|
|
|
} = Styled;
|
|
|
|
|
2016-12-09 16:56:34 +02:00
|
|
|
const classNames = {
|
|
|
|
content: rndId()
|
|
|
|
};
|
|
|
|
|
2016-12-09 12:40:57 +02:00
|
|
|
const StyledInput = styled.input`
|
|
|
|
display: none;
|
|
|
|
visibility: hidden;
|
|
|
|
|
|
|
|
&:checked {
|
2016-12-09 16:56:34 +02:00
|
|
|
& ~ .${classNames.content} {
|
2016-12-09 12:40:57 +02:00
|
|
|
border: ${boxes.border.checked};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
2016-12-09 16:56:34 +02:00
|
|
|
& ~ .${classNames.content} {
|
2016-12-09 12:40:57 +02:00
|
|
|
cursor: not-allowed;
|
|
|
|
filter: grayscale(80%);
|
|
|
|
opacity: 0.4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledContent = styled.div`
|
|
|
|
border: ${boxes.border.unchecked};
|
2017-01-12 21:04:52 +02:00
|
|
|
border-radius: ${remcalc(4)};
|
2016-12-09 12:40:57 +02:00
|
|
|
cursor: pointer;
|
2017-02-15 15:59:49 +02:00
|
|
|
padding: ${remcalc(36)};
|
2016-12-09 12:40:57 +02:00
|
|
|
|
|
|
|
& img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
`;
|
2016-10-28 16:59:28 +03:00
|
|
|
|
|
|
|
const Widget = ({
|
2016-10-28 18:01:23 +03:00
|
|
|
checked = false,
|
2016-10-28 16:59:28 +03:00
|
|
|
children,
|
|
|
|
className,
|
2016-10-28 18:01:23 +03:00
|
|
|
disabled = false,
|
2016-12-09 16:56:34 +02:00
|
|
|
id,
|
2016-10-28 18:01:23 +03:00
|
|
|
name,
|
|
|
|
selectable = 'single',
|
|
|
|
style,
|
|
|
|
value = name
|
2016-10-28 16:59:28 +03:00
|
|
|
}) => {
|
|
|
|
const type = selectable === 'single' ? 'radio' : 'checkbox';
|
|
|
|
|
|
|
|
return (
|
2016-12-09 16:56:34 +02:00
|
|
|
<label
|
|
|
|
className={className}
|
|
|
|
htmlFor={value}
|
|
|
|
id={id}
|
|
|
|
>
|
2016-12-09 12:40:57 +02:00
|
|
|
<StyledInput
|
2016-10-28 18:01:23 +03:00
|
|
|
checked={checked}
|
|
|
|
disabled={disabled}
|
|
|
|
id={value}
|
2016-10-28 16:59:28 +03:00
|
|
|
name={name}
|
|
|
|
type={type}
|
2016-10-28 18:01:23 +03:00
|
|
|
value={value}
|
2016-10-28 16:59:28 +03:00
|
|
|
/>
|
2016-12-09 16:56:34 +02:00
|
|
|
<StyledContent className={classNames.content}>
|
2016-10-28 16:59:28 +03:00
|
|
|
{children}
|
2016-12-09 12:40:57 +02:00
|
|
|
</StyledContent>
|
2016-10-28 16:59:28 +03:00
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Widget.propTypes = {
|
2016-10-28 18:01:23 +03:00
|
|
|
checked: React.PropTypes.bool,
|
2016-10-28 16:59:28 +03:00
|
|
|
children: React.PropTypes.object,
|
|
|
|
className: React.PropTypes.string,
|
2016-10-28 18:01:23 +03:00
|
|
|
disabled: React.PropTypes.bool,
|
2016-12-09 16:56:34 +02:00
|
|
|
id: React.PropTypes.string,
|
2016-10-28 16:59:28 +03:00
|
|
|
name: React.PropTypes.string,
|
|
|
|
selectable: React.PropTypes.string,
|
2016-10-28 18:01:23 +03:00
|
|
|
style: React.PropTypes.object,
|
|
|
|
value: React.PropTypes.string
|
2016-10-28 16:59:28 +03:00
|
|
|
};
|
|
|
|
|
2017-02-15 03:19:26 +02:00
|
|
|
module.exports = Baseline(
|
|
|
|
Widget
|
|
|
|
);
|