joyent-portal/ui/src/components/widget/index.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

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 = ({
checked = false,
2016-10-28 16:59:28 +03:00
children,
className,
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
checked={checked}
disabled={disabled}
id={value}
2016-10-28 16:59:28 +03:00
name={name}
type={type}
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 = {
checked: React.PropTypes.bool,
2016-10-28 16:59:28 +03:00
children: React.PropTypes.object,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
2016-10-28 16:59:28 +03:00
name: React.PropTypes.string,
selectable: React.PropTypes.string,
style: React.PropTypes.object,
value: React.PropTypes.string
2016-10-28 16:59:28 +03:00
};
module.exports = Widget;