2016-10-28 16:59:28 +03:00
|
|
|
const React = require('react');
|
2016-12-09 12:40:57 +02:00
|
|
|
const constants = require('../../shared/constants');
|
|
|
|
const Styled = require('styled-components');
|
|
|
|
|
|
|
|
const {
|
|
|
|
boxes
|
|
|
|
} = constants;
|
|
|
|
|
|
|
|
const {
|
|
|
|
default: styled,
|
|
|
|
} = Styled;
|
|
|
|
|
|
|
|
const StyledInput = styled.input`
|
|
|
|
display: none;
|
|
|
|
visibility: hidden;
|
|
|
|
|
|
|
|
&:checked {
|
|
|
|
& ~ .content {
|
|
|
|
border: ${boxes.border.checked};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
& ~ .content {
|
|
|
|
cursor: not-allowed;
|
|
|
|
filter: grayscale(80%);
|
|
|
|
opacity: 0.4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledContent = styled.div`
|
|
|
|
border: ${boxes.border.unchecked};
|
|
|
|
border-radius: 4px;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: remcalc(36);
|
|
|
|
|
|
|
|
& 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,
|
|
|
|
name,
|
|
|
|
selectable = 'single',
|
|
|
|
style,
|
|
|
|
value = name
|
2016-10-28 16:59:28 +03:00
|
|
|
}) => {
|
|
|
|
const type = selectable === 'single' ? 'radio' : 'checkbox';
|
|
|
|
|
|
|
|
return (
|
2016-12-09 12:40:57 +02:00
|
|
|
<label className={className} htmlFor={value}>
|
|
|
|
<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 12:40:57 +02:00
|
|
|
<StyledContent>
|
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-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
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Widget;
|