joyent-portal/ui/src/components/widget/index.js

53 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-10-28 16:59:28 +03:00
const classNames = require('classnames');
const React = require('react');
const styles = require('./style.css');
const Widget = ({
checked = false,
2016-10-28 16:59:28 +03:00
children,
className,
disabled = false,
name,
selectable = 'single',
style,
value = name
2016-10-28 16:59:28 +03:00
}) => {
const cn = classNames(
className,
styles.widget
);
const type = selectable === 'single' ? 'radio' : 'checkbox';
return (
<label className={cn} htmlFor={value}>
2016-10-28 16:59:28 +03:00
<input
checked={checked}
2016-10-28 16:59:28 +03:00
className={styles.input}
disabled={disabled}
id={value}
2016-10-28 16:59:28 +03:00
name={name}
type={type}
value={value}
2016-10-28 16:59:28 +03:00
/>
<div className={styles.content}>
{children}
</div>
</label>
);
};
Widget.propTypes = {
checked: React.PropTypes.bool,
2016-10-28 16:59:28 +03:00
children: React.PropTypes.object,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
2016-10-28 16:59:28 +03:00
name: React.PropTypes.string,
selectable: React.PropTypes.string,
style: React.PropTypes.object,
value: React.PropTypes.string
2016-10-28 16:59:28 +03:00
};
module.exports = Widget;