1
0
mirror of https://github.com/yldio/copilot.git synced 2024-09-22 14:23:50 +03:00
copilot/ui/src/components/checkbox/index.js

118 lines
2.2 KiB
JavaScript
Raw Normal View History

const React = require('react');
2016-12-08 14:41:37 +02:00
const constants = require('../../shared/constants');
const Styled = require('styled-components');
const {
boxes
} = constants;
const {
default: styled,
} = Styled;
const StyledInput = styled.input`
2016-12-08 17:39:16 +02:00
visibility: hidden;
&:checked + label::after {
opacity: 1;
}
&:disabled + label {
background-color: rgb(249, 249, 249);
}
&:disabled + label::after {
opacity: 0.3;
}
2016-12-08 14:41:37 +02:00
`;
const StyledLabel = styled.label`
2016-12-08 17:39:16 +02:00
color: rgb(100, 100, 100);
position: absolute;
width: 24px;
height: 24px;
top: 0;
border-radius: ${boxes.borderRadius};
background-color: rgb(255, 255, 255);
box-shadow: ${boxes.insetShaddow};
border: ${boxes.border.unchecked};
&::after {
opacity: 0;
content: '';
position: absolute;
width: 9px;
height: 4px;
background: transparent;
top: 7px;
left: 7px;
border: 3px solid #333;
border-top: none;
border-right: none;
transform: rotate(-45deg);
}
&:hover {
&::after {
opacity: 0.3;
}
}
`;
const StyledDiv = styled.div`
width: 24px;
height: 24px;
position: relative;
2016-12-08 14:41:37 +02:00
`;
const Checkbox = ({
checked = false,
children,
className,
disabled = false,
form,
2016-10-26 16:44:17 +03:00
id,
name,
onChange,
readOnly,
required,
selectionDirection,
style,
tabIndex
}) => {
return (
2016-12-08 17:39:16 +02:00
<StyledDiv>
2016-12-08 14:41:37 +02:00
<StyledInput
checked={checked}
disabled={disabled}
form={form}
name={name}
2016-10-26 16:44:17 +03:00
onChange={onChange}
readOnly={readOnly}
required={required}
2016-10-26 16:44:17 +03:00
style={style}
tabIndex={tabIndex}
type='checkbox'
/>
2016-12-08 17:39:16 +02:00
<StyledLabel>
<span>{children}</span>
</StyledLabel>
</StyledDiv>
);
};
Checkbox.propTypes = {
2016-10-26 16:44:17 +03:00
checked: React.PropTypes.bool,
children: React.PropTypes.node,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
form: React.PropTypes.string,
2016-10-26 16:44:17 +03:00
id: React.PropTypes.string,
name: React.PropTypes.string,
onChange: React.PropTypes.func,
readOnly: React.PropTypes.bool,
required: React.PropTypes.bool,
selectionDirection: React.PropTypes.string,
style: React.PropTypes.object,
tabIndex: React.PropTypes.string
};
module.exports = Checkbox;