From aac5339ac0384aa16a27fbb2cead5907521d3b74 Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Thu, 18 May 2017 10:37:41 -0400 Subject: [PATCH] boolean widget & some documentation (#396) --- docs/widgets.md | 4 ++++ src/components/Widgets.js | 2 ++ src/components/Widgets/BooleanControl.js | 23 +++++++++++++++++++++++ yarn.lock | 10 ++++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/components/Widgets/BooleanControl.js diff --git a/docs/widgets.md b/docs/widgets.md index 4a8e7bc1..70d50c61 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -7,6 +7,7 @@ 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 | switch for 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 @@ -14,5 +15,8 @@ Widget | UI | Data Type `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). diff --git a/src/components/Widgets.js b/src/components/Widgets.js index 4eabc067..671152d1 100644 --- a/src/components/Widgets.js +++ b/src/components/Widgets.js @@ -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 diff --git a/src/components/Widgets/BooleanControl.js b/src/components/Widgets/BooleanControl.js new file mode 100644 index 00000000..8486a255 --- /dev/null +++ b/src/components/Widgets/BooleanControl.js @@ -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 ( + + ); + } +} + +BooleanControl.propTypes = { + field: ImmutablePropTypes.map.isRequired, + onChange: PropTypes.func.isRequired, + forID: PropTypes.string.isRequired, + value: PropTypes.bool, +}; diff --git a/yarn.lock b/yarn.lock index ba011dcc..9edd85b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7749,6 +7749,12 @@ slide@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" +slug@^0.9.1: + version "0.9.1" + resolved "https://registry.yarnpkg.com/slug/-/slug-0.9.1.tgz#af08f608a7c11516b61778aa800dce84c518cfda" + dependencies: + unicode ">= 0.3.1" + sntp@1.x.x: version "1.0.9" resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" @@ -8540,6 +8546,10 @@ unc-path-regex@^0.1.0: version "0.1.2" resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa" +"unicode@>= 0.3.1": + version "9.0.1" + resolved "https://registry.yarnpkg.com/unicode/-/unicode-9.0.1.tgz#104706272c6464c574801be1b086f7245cf25158" + uniq@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"