2016-10-26 20:02:59 +03:00
|
|
|
const classNames = require('classnames');
|
|
|
|
const React = require('react');
|
|
|
|
const styles = require('./style.css');
|
|
|
|
|
|
|
|
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-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-28 02:37:31 +03:00
|
|
|
style,
|
|
|
|
value
|
2016-10-26 20:02:59 +03:00
|
|
|
}) => {
|
2016-10-28 02:37:31 +03:00
|
|
|
const _label = label || children;
|
2016-10-31 14:01:44 +02:00
|
|
|
const _children = label && children ? children : null;
|
2016-10-26 20:02:59 +03:00
|
|
|
|
|
|
|
const cn = classNames(
|
|
|
|
className,
|
|
|
|
styles.radio
|
|
|
|
);
|
|
|
|
|
2016-10-28 02:37:31 +03:00
|
|
|
const labelledby = `${styles.label}-label`;
|
|
|
|
|
2016-10-26 20:02:59 +03:00
|
|
|
return (
|
2016-10-28 02:37:31 +03:00
|
|
|
<div className={cn}>
|
|
|
|
<label className={styles.label} htmlFor={id}>
|
|
|
|
<input
|
|
|
|
aria-labelledby={labelledby}
|
|
|
|
checked={checked}
|
|
|
|
className={styles.input}
|
|
|
|
defaultChecked={defaultChecked}
|
|
|
|
disabled={disabled}
|
|
|
|
id={id}
|
|
|
|
name={name}
|
|
|
|
onChange={onChange}
|
|
|
|
type='radio'
|
|
|
|
value={value}
|
|
|
|
/>
|
|
|
|
<span className={styles.span} id={labelledby}>
|
|
|
|
{_label}
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
<span>
|
|
|
|
{_children}
|
|
|
|
</span>
|
|
|
|
</div>
|
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,
|
|
|
|
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,
|
|
|
|
style: React.PropTypes.object,
|
2016-10-28 02:37:31 +03:00
|
|
|
value: React.PropTypes.string.isRequired
|
2016-10-26 20:02:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Radio;
|