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

84 lines
1.9 KiB
JavaScript
Raw Normal View History

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,
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
}) => {
2016-10-28 02:37:31 +03:00
const _label = label || children;
const _children = label && children ? children : null;
const cn = classNames(
className,
styles.radio
);
2016-10-28 02:37:31 +03:00
const labelledby = `${styles.label}-label`;
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}
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}
/>
<span className={styles.span} id={labelledby}>
{_label}
</span>
</label>
<span>
{_children}
</span>
</div>
);
};
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;