Skip to content

Commit

Permalink
boolean widget & some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
daddykotex committed May 10, 2017
1 parent 018616d commit eb1538c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ Widgets define the data type and interface for entry fields. Netlify CMS comes w
Widget | UI | Data Type
--- | --- | ---
`string` | text input | string
`boolean` | select input | dropdown filled true and false
`text` | text area input | plain text, multiline input
`number` | text input with `+` and `-` buttons | number
`markdown` | rich text editor with raw option | markdown-formatted string
`datetime` | date picker widget | ISO date string
`image` | file picker widget with drag-and-drop | file path saved as string, image uploaded to media folder
`hidden` | No UI | Hidden element, typically only useful with a `default` attribute
`list` | text input | strings separated by commas
`file` | file input | input file upload
`select` | select input | dropdown filled with `options` from the config
`object` | custom | `fields` as a list defined in the config

We’re always adding new widgets, and you can also [create your own](/docs/extending).
2 changes: 2 additions & 0 deletions src/components/Widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/components/Widgets/BooleanControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 {

handleChange = (e) => {
this.props.onChange(e);
};

render() {
const finalValue = (this.props.value !== undefined) ? this.props.value : this.props.field.get('defaultValue', false);

return (<Switch
id={this.props.forID}
checked={finalValue}
onChange={this.handleChange}
/>);
}
}

BooleanControl.propTypes = {
field: ImmutablePropTypes.map.isRequired,
onChange: PropTypes.func.isRequired,
forID: PropTypes.string.isRequired,
value: PropTypes.bool,
};

0 comments on commit eb1538c

Please sign in to comment.