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

135 lines
2.6 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');
const {
boxes
} = constants;
const {
default: styled,
} = Styled;
const StyledInput = styled.input`
visibility: hidden;
&:checked + label::after {
opacity: 1;
}
&:disabled + label {
background-color: rgb(249, 249, 249);
}
&:disabled + label::after {
opacity: 0.3;
}
`;
const border = 1;
const StyledLabel = styled.label`
color: rgb(100, 100, 100);
position: absolute;
width: ${24 - border}px;
height: ${24 - border}px;
top: 0;
border-radius: 100%;
background-color: rgb(255, 255, 255);
box-shadow: ${boxes.insetShaddow};
border: ${boxes.border.unchecked};
&::after {
opacity: 0;
content: '';
position: absolute;
width: 8px;
height: 8px;
background: rgb(100, 100, 100);
top: ${(23 / 2) - 4}px;
left: ${(23 / 2) - 4}px;
border-radius: 100%;
transform: rotate(-45deg);
}
&:hover {
&::after {
opacity: 0.3;
}
}
`;
const StyledDiv = styled.div`
width: 24px;
height: 24px;
position: relative;
`;
const TextLabel = styled.label`
`;
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
}) => {
const _children = label && children ? children : null;
return (
2016-12-09 17:04:06 +02:00
<TextLabel>
<StyledDiv>
<StyledInput
2016-10-28 02:37:31 +03:00
checked={checked}
defaultChecked={defaultChecked}
disabled={disabled}
form={form}
2016-10-28 02:37:31 +03:00
id={id}
name={name}
onChange={onChange}
readOnly={readOnly}
required={required}
selectionDirection={selectionDirection}
tabIndex={tabIndex}
2016-10-28 02:37:31 +03:00
type='radio'
value={value}
/>
2016-12-09 17:04:06 +02:00
<StyledLabel />
</StyledDiv>
2016-10-28 02:37:31 +03:00
<span>
{_children}
</span>
2016-12-09 17:04:06 +02:00
</TextLabel>
);
};
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,
name: React.PropTypes.string.isRequired,
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;