boolean widget & some documentation (#396)
This commit is contained in:
parent
982d1db25d
commit
aac5339ac0
@ -7,6 +7,7 @@ Widgets define the data type and interface for entry fields. Netlify CMS comes w
|
|||||||
Widget | UI | Data Type
|
Widget | UI | Data Type
|
||||||
--- | --- | ---
|
--- | --- | ---
|
||||||
`string` | text input | string
|
`string` | text input | string
|
||||||
|
`boolean` | select input | switch for true and false
|
||||||
`text` | text area input | plain text, multiline input
|
`text` | text area input | plain text, multiline input
|
||||||
`number` | text input with `+` and `-` buttons | number
|
`number` | text input with `+` and `-` buttons | number
|
||||||
`markdown` | rich text editor with raw option | markdown-formatted string
|
`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
|
`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
|
`hidden` | No UI | Hidden element, typically only useful with a `default` attribute
|
||||||
`list` | text input | strings separated by commas
|
`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).
|
We’re always adding new widgets, and you can also [create your own](/docs/extending).
|
||||||
|
@ -25,6 +25,7 @@ import ObjectControl from './Widgets/ObjectControl';
|
|||||||
import ObjectPreview from './Widgets/ObjectPreview';
|
import ObjectPreview from './Widgets/ObjectPreview';
|
||||||
import RelationControl from './Widgets/RelationControl';
|
import RelationControl from './Widgets/RelationControl';
|
||||||
import RelationPreview from './Widgets/RelationPreview';
|
import RelationPreview from './Widgets/RelationPreview';
|
||||||
|
import BooleanControl from './Widgets/BooleanControl';
|
||||||
|
|
||||||
|
|
||||||
registry.registerWidget('string', StringControl, StringPreview);
|
registry.registerWidget('string', StringControl, StringPreview);
|
||||||
@ -39,6 +40,7 @@ registry.registerWidget('datetime', DateTimeControl, DateTimePreview);
|
|||||||
registry.registerWidget('select', SelectControl, SelectPreview);
|
registry.registerWidget('select', SelectControl, SelectPreview);
|
||||||
registry.registerWidget('object', ObjectControl, ObjectPreview);
|
registry.registerWidget('object', ObjectControl, ObjectPreview);
|
||||||
registry.registerWidget('relation', RelationControl, RelationPreview);
|
registry.registerWidget('relation', RelationControl, RelationPreview);
|
||||||
|
registry.registerWidget('boolean', BooleanControl);
|
||||||
registry.registerWidget('unknown', UnknownControl, UnknownPreview);
|
registry.registerWidget('unknown', UnknownControl, UnknownPreview);
|
||||||
|
|
||||||
export function resolveWidget(name) { // eslint-disable-line
|
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,
|
||||||
|
};
|
10
yarn.lock
10
yarn.lock
@ -7749,6 +7749,12 @@ slide@^1.1.5:
|
|||||||
version "1.1.6"
|
version "1.1.6"
|
||||||
resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707"
|
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:
|
sntp@1.x.x:
|
||||||
version "1.0.9"
|
version "1.0.9"
|
||||||
resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198"
|
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"
|
version "0.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
|
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:
|
uniq@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
|
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user