1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-10 19:10:13 +02:00
copilot/ui/src/components/radio/index.js

142 lines
2.5 KiB
JavaScript
Raw Normal View History

const React = require('react');
2016-12-09 17:04:06 +02:00
const constants = require('../../shared/constants');
const Styled = require('styled-components');
2016-12-14 15:53:19 +02:00
const fns = require('../../shared/functions');
2016-12-09 17:04:06 +02:00
const {
boxes
} = constants;
2016-12-14 15:53:19 +02:00
const {
remcalc
} = fns;
2016-12-09 17:04:06 +02:00
const {
default: styled,
} = Styled;
2016-12-14 14:30:25 +02:00
const CustomInputCircle = `
content: '';
position: absolute;
2016-12-14 15:53:19 +02:00
width: 14px;
height: 14px;
background: #646464;
top: -16px;
left: 12px;
2016-12-14 14:30:25 +02:00
border-radius: 100%;
`;
2016-12-09 17:04:06 +02:00
const StyledInput = styled.input`
visibility: hidden;
2016-12-14 14:30:25 +02:00
display: none;
2016-12-09 17:04:06 +02:00
2016-12-14 14:30:25 +02:00
&:checked + span::after {
${CustomInputCircle}
2016-12-09 17:04:06 +02:00
}
2016-12-14 14:30:25 +02:00
&:disabled + span {
2016-12-14 15:53:19 +02:00
background-color: #F9f9F9;
2016-12-09 17:04:06 +02:00
}
2016-12-14 14:30:25 +02:00
&:disabled + span::after {
2016-12-09 17:04:06 +02:00
opacity: 0.3;
2016-12-14 14:30:25 +02:00
${CustomInputCircle}
2016-12-09 17:04:06 +02:00
}
`;
const StyledLabel = styled.label`
2016-12-14 14:30:25 +02:00
`;
2016-12-14 15:53:19 +02:00
const StyledContent = styled.div`
margin-left: ${remcalc(45)};
padding-top: ${remcalc(10)};
`;
2016-12-14 14:30:25 +02:00
const StyledSpan = styled.span`
2016-12-14 15:53:19 +02:00
color: #646464;
2016-12-14 14:30:25 +02:00
position: relative;
&::before {
content: '';
2016-12-09 17:04:06 +02:00
position: absolute;
2016-12-14 15:53:19 +02:00
width: ${remcalc(26)};
height: ${remcalc(26)};
background-color: #FFFFFF;
2016-12-09 17:04:06 +02:00
box-shadow: ${boxes.insetShaddow};
border: ${boxes.border.unchecked};
2016-12-14 15:53:19 +02:00
top: 5px;
left: 5px;
2016-12-14 14:30:25 +02:00
border-radius: 100%;
}
2016-12-09 17:04:06 +02:00
2016-12-14 14:30:25 +02:00
&:hover {
2016-12-09 17:04:06 +02:00
&::after {
2016-12-14 14:30:25 +02:00
opacity: 0.3;
2016-12-09 17:04:06 +02:00
}
2016-12-14 14:30:25 +02:00
}
2016-12-09 17:04:06 +02:00
`;
const Radio = ({
checked,
2016-10-28 02:37:31 +03:00
children,
className,
2016-10-28 02:37:31 +03:00
defaultChecked,
disabled = false,
form,
id,
2016-10-28 02:37:31 +03:00
label,
name,
onChange,
readOnly,
required,
selectionDirection,
2016-10-28 02:37:31 +03:00
style,
tabIndex,
2016-10-28 02:37:31 +03:00
value
}) => {
return (
2016-12-14 14:30:25 +02:00
<StyledLabel>
<StyledInput
checked={checked}
defaultChecked={defaultChecked}
disabled={disabled}
form={form}
id={id}
name={name}
onChange={onChange}
readOnly={readOnly}
required={required}
selectionDirection={selectionDirection}
tabIndex={tabIndex}
type='radio'
value={value}
/>
<StyledSpan>
2016-12-14 15:53:19 +02:00
<StyledContent>
{children}
</StyledContent>
2016-12-14 14:30:25 +02:00
</StyledSpan>
</StyledLabel>
);
};
Radio.propTypes = {
2016-10-27 12:51:47 +03:00
checked: React.PropTypes.bool,
2016-10-28 02:37:31 +03:00
children: React.PropTypes.node,
className: React.PropTypes.string,
2016-10-28 02:37:31 +03:00
defaultChecked: React.PropTypes.bool,
2016-10-27 12:51:47 +03:00
disabled: React.PropTypes.bool,
form: React.PropTypes.string,
2016-10-27 12:51:47 +03:00
id: React.PropTypes.string,
2016-10-28 02:37:31 +03:00
label: React.PropTypes.string,
2016-12-13 13:01:18 +02:00
name: React.PropTypes.string,
2016-10-27 12:51:47 +03:00
onChange: React.PropTypes.func,
readOnly: React.PropTypes.bool,
required: React.PropTypes.bool,
selectionDirection: React.PropTypes.string,
2016-10-27 12:51:47 +03:00
style: React.PropTypes.object,
tabIndex: React.PropTypes.string,
2016-10-28 02:37:31 +03:00
value: React.PropTypes.string.isRequired
};
module.exports = Radio;