2016-10-26 20:02:59 +03:00
|
|
|
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`
|
|
|
|
`;
|
2016-10-26 20:02:59 +03:00
|
|
|
|
|
|
|
const Radio = ({
|
|
|
|
checked,
|
2016-10-28 02:37:31 +03:00
|
|
|
children,
|
2016-10-26 20:02:59 +03:00
|
|
|
className,
|
2016-10-28 02:37:31 +03:00
|
|
|
defaultChecked,
|
|
|
|
disabled = false,
|
2016-10-31 18:02:33 +02:00
|
|
|
form,
|
2016-10-26 20:02:59 +03:00
|
|
|
id,
|
2016-10-28 02:37:31 +03:00
|
|
|
label,
|
|
|
|
name,
|
2016-10-26 20:02:59 +03:00
|
|
|
onChange,
|
2016-10-31 18:02:33 +02:00
|
|
|
readOnly,
|
|
|
|
required,
|
|
|
|
selectionDirection,
|
2016-10-28 02:37:31 +03:00
|
|
|
style,
|
2016-10-31 18:02:33 +02:00
|
|
|
tabIndex,
|
2016-10-28 02:37:31 +03:00
|
|
|
value
|
2016-10-26 20:02:59 +03:00
|
|
|
}) => {
|
2016-10-31 14:01:44 +02:00
|
|
|
const _children = label && children ? children : null;
|
2016-10-26 20:02:59 +03:00
|
|
|
|
|
|
|
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}
|
2016-10-31 18:02:33 +02:00
|
|
|
form={form}
|
2016-10-28 02:37:31 +03:00
|
|
|
id={id}
|
|
|
|
name={name}
|
|
|
|
onChange={onChange}
|
2016-10-31 18:02:33 +02:00
|
|
|
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>
|
2016-10-26 20:02:59 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2016-10-26 20:02:59 +03:00
|
|
|
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,
|
2016-10-31 18:02:33 +02:00
|
|
|
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,
|
2016-10-31 18:02:33 +02:00
|
|
|
readOnly: React.PropTypes.bool,
|
|
|
|
required: React.PropTypes.bool,
|
|
|
|
selectionDirection: React.PropTypes.string,
|
2016-10-27 12:51:47 +03:00
|
|
|
style: React.PropTypes.object,
|
2016-10-31 18:02:33 +02:00
|
|
|
tabIndex: React.PropTypes.string,
|
2016-10-28 02:37:31 +03:00
|
|
|
value: React.PropTypes.string.isRequired
|
2016-10-26 20:02:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Radio;
|