boolean widget & some documentation (#396)
This commit is contained in:
committed by
Benaiah Mischenko
parent
982d1db25d
commit
aac5339ac0
@ -25,6 +25,7 @@ import ObjectControl from './Widgets/ObjectControl';
|
||||
import ObjectPreview from './Widgets/ObjectPreview';
|
||||
import RelationControl from './Widgets/RelationControl';
|
||||
import RelationPreview from './Widgets/RelationPreview';
|
||||
import BooleanControl from './Widgets/BooleanControl';
|
||||
|
||||
|
||||
registry.registerWidget('string', StringControl, StringPreview);
|
||||
@ -39,6 +40,7 @@ registry.registerWidget('datetime', DateTimeControl, DateTimePreview);
|
||||
registry.registerWidget('select', SelectControl, SelectPreview);
|
||||
registry.registerWidget('object', ObjectControl, ObjectPreview);
|
||||
registry.registerWidget('relation', RelationControl, RelationPreview);
|
||||
registry.registerWidget('boolean', BooleanControl);
|
||||
registry.registerWidget('unknown', UnknownControl, UnknownPreview);
|
||||
|
||||
export function resolveWidget(name) { // eslint-disable-line
|
||||
|
23
src/components/Widgets/BooleanControl.js
Normal file
23
src/components/Widgets/BooleanControl.js
Normal file
@ -0,0 +1,23 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import ImmutablePropTypes from "react-immutable-proptypes";
|
||||
import Switch from 'react-toolbox/lib/switch';
|
||||
|
||||
export default class BooleanControl extends React.Component {
|
||||
render() {
|
||||
const { value, field, forId, onChange } = this.props;
|
||||
return (
|
||||
<Switch
|
||||
id={forId}
|
||||
checked={value === undefined ? field.get('defaultValue', false) : value}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
BooleanControl.propTypes = {
|
||||
field: ImmutablePropTypes.map.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
forID: PropTypes.string.isRequired,
|
||||
value: PropTypes.bool,
|
||||
};
|
Reference in New Issue
Block a user