Update widget documentation

This commit is contained in:
Daniel Lautzenheiser 2022-11-02 15:42:21 -04:00
parent fdd51aefa3
commit 6de5363f12
23 changed files with 618 additions and 332 deletions

View File

@ -586,14 +586,13 @@ export interface ListField extends BaseField {
allow_add?: boolean; allow_add?: boolean;
collapsed?: boolean; collapsed?: boolean;
summary?: string; summary?: string;
minimize_collapsed?: boolean;
label_singular?: string; label_singular?: string;
fields?: Field[]; fields?: Field[];
max?: number; max?: number;
min?: number; min?: number;
add_to_top?: boolean; add_to_top?: boolean;
types?: ObjectField[]; types?: ObjectField[];
typeKey?: string; type_key?: string;
} }
export interface MapField extends BaseField { export interface MapField extends BaseField {

View File

@ -32,4 +32,6 @@ export function validateMinMax(
} else if (isNumber(max) && length > max) { } else if (isNumber(max) && length > max) {
return minMaxError('rangeMax'); return minMaxError('rangeMax');
} }
return false;
} }

View File

@ -3,7 +3,6 @@ export default {
allow_add: { type: 'boolean' }, allow_add: { type: 'boolean' },
collapsed: { type: 'boolean' }, collapsed: { type: 'boolean' },
summary: { type: 'string' }, summary: { type: 'string' },
minimize_collapsed: { type: 'boolean' },
label_singular: { type: 'string' }, label_singular: { type: 'string' },
i18n: { type: 'boolean' }, i18n: { type: 'boolean' },
min: { type: 'number' }, min: { type: 'number' },

View File

@ -1,7 +1,7 @@
import type { ListField, ObjectField, ObjectValue } from '../../interface'; import type { ListField, ObjectField, ObjectValue } from '../../interface';
export const TYPES_KEY = 'types'; export const TYPES_KEY = 'types';
export const TYPE_KEY = 'typeKey'; export const TYPE_KEY = 'type_key';
export const DEFAULT_TYPE_KEY = 'type'; export const DEFAULT_TYPE_KEY = 'type';
export function getTypedFieldForValue( export function getTypedFieldForValue(

View File

@ -4,15 +4,21 @@ title: Boolean
weight: 10 weight: 10
--- ---
The boolean widget translates a toggle switch input to a true/false value. ## Overview
- **Name**: `boolean`
- **UI**: Toggle switch
- **Data type**: `boolean`
The boolean widget translates a toggle switch input to a `true` or `false` value.
## Widget options ## Widget options
For common options, see [Common widget options](/docs/widgets#common-widget-options). For common options, see [Common widget options](/docs/widgets#common-widget-options).
|Name|Type|Default|Description| | Name | Type | Default | Description |
|----|----|-------|-----------| | ------- | ------- | ------- | ------------------------------------------- |
|default|boolean|`false`|_Optional_. The default value for the field| | default | boolean | `false` | _Optional_. The default value for the field |
## Example ## Example

View File

@ -3,6 +3,11 @@ group: Widgets
title: Code title: Code
weight: 11 weight: 11
--- ---
## Overview
- **Name**: `code`
- **UI**: Codemirror editor
- **Data type**: `string` or `{ code: 'My code here', lang: 'javascript' }`
The code widget provides a code editor (powered by [Codemirror](https://codemirror.net)) with optional syntax awareness. Can output the raw code value or an object with the selected language and the raw code value. The code widget provides a code editor (powered by [Codemirror](https://codemirror.net)) with optional syntax awareness. Can output the raw code value or an object with the selected language and the raw code value.

View File

@ -3,6 +3,11 @@ group: Widgets
title: Color title: Color
weight: 12 weight: 12
--- ---
## Overview
- **Name**: `color`
- **UI**: Color picker
- **Data type**: `string`
The color widget translates a color picker to a color string. The color widget translates a color picker to a color string.

View File

@ -3,6 +3,11 @@ group: Widgets
title: DateTime title: DateTime
weight: 13 weight: 13
--- ---
## Overview
- **Name**: `datetime`
- **UI**: Datetime picker
- **Data type**: [date-fns](https://date-fns.org/) formatted datetime string
The datetime widget translates a datetime picker to a datetime string. The datetime widget translates a datetime picker to a datetime string.

View File

@ -3,30 +3,42 @@ group: Widgets
title: File title: File
weight: 14 weight: 14
--- ---
## Overview
- **Name:** `file`
- **UI:** File picker button opens media gallery
- **Data type:** File path string
The file widget allows editors to upload a file or select an existing one from the media library. The path to the file will be saved to the field as a string. The file widget allows editors to upload a file or select an existing one from the media library. The path to the file will be saved to the field as a string.
* **Name:** `file` ## Widget options
* **UI:** file picker button opens media gallery
* **Data type:** file path string
* **Options:**
* `default`: accepts a file path string; defaults to null For common options, see [Common widget options](/docs/widgets#common-widget-options).
* `media_library`: media library settings to apply when a media library is opened by the
current widget
* `allow_multiple`: *(default: `true`)* when set to `false`, prevents multiple selection for any media library extension, but must be supported by the extension in use | Name | Type | Default | Description |
* `config`: a configuration object that will be passed directly to the media library being | ------------- | --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
used - available options are determined by the library | default | string | `null` | _Optional_. The default value for the field. Accepts a datetime string, or an empty string to accept blank input; otherwise defaults to current datetime |
* `media_folder` (Beta): file path where uploaded files will be saved specific to this control. Paths can be relative to a collection folder (e.g. `files` will add the file to a sub-folder in the collection folder) or absolute with reference to the base of the repo which needs to begin with `/` (e.g `/static/files` will save uploaded files to the `static` folder in a sub folder named `files`) | media_library | Media Library Options | `{}` | _Optional_. Media library settings to apply when a media library is opened by the current widget. See [Media Library Options](#media-library-options) |
* `choose_url`: *(default: `true`)* when set to `false`, the "Insert from URL" button will be hidden | media_folder | string | | _Optional_. Specifies the folder path where uploaded files should be saved, relative to the base of the repo |
* **Example:** | public_folder | string | | _Optional_. Specifies the folder path where the files uploaded by the media library will be accessed, relative to the base of the built site |
```yaml ### Media Library Options
- label: "Manual PDF"
title: "manual_pdf" | Name | Type | Default | Description |
widget: "file" | -------------- | ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
default: "/uploads/general-manual.pdf" | allow_multiple | boolean | `true` | _Optional_. When set to `false`, prevents multiple selection for any media library extension, but must be supported by the extension in use |
media_library: | config | string | `{}` | _Optional_. A configuration object that will be passed directly to the media library being used - available options are determined by the library |
config: | choose_url | string<br />\| boolean | `true` | _Optional_. When set to `false`, the "Insert from URL" button will be hidden |
multiple: true
``` ## Example
```yaml
name: manual_pdf
label: Manual PDF
widget: file
default: /uploads/general-manual.pdf
media_library:
choose_url: true
config:
multiple: true
```

View File

@ -3,15 +3,27 @@ group: Widgets
title: Hidden title: Hidden
weight: 15 weight: 15
--- ---
## Overview
- **Name:** `hidden`
- **UI:** None
- **Data type:** Any valid data type
Hidden widgets do not display in the UI. In folder collections that allow users to create new items, you will often want to set a default for hidden fields, so they will be set without requiring an input. Hidden widgets do not display in the UI. In folder collections that allow users to create new items, you will often want to set a default for hidden fields, so they will be set without requiring an input.
- **Name:** `hidden` ## Widget options
- **UI:** none
- **Data type:** any valid data type For common options, see [Common widget options](/docs/widgets#common-widget-options).
- **Options:**
- `default`: accepts any valid data type; recommended for collections that allow adding new items | Name | Type | Default | Description |
- **Example:** | ------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
```yaml | default | string | `null` | _Optional_. The default value for the field. Accepts any valid data type. Recommended for collections that allow adding new items. |
- {label: "Layout", title: "layout", widget: "hidden", default: "blog"}
``` ## Example
```yaml
name: layout
label: Layout
widget: hidden
default: blog
```

View File

@ -3,29 +3,42 @@ group: Widgets
title: Image title: Image
weight: 16 weight: 16
--- ---
The image widget allows editors to upload an image or select an existing one from the media library. The path to the image file will be saved to the field as a string. ## Overview
* **Name:** `image` - **Name:** `image`
* **UI:** file picker button opens media gallery allowing image files (jpg, jpeg, webp, gif, png, bmp, tiff, svg) only; displays selected image thumbnail - **UI:** File picker button opens media gallery allowing image files (jpg, jpeg, webp, gif, png, bmp, tiff, svg) only; displays selected image thumbnail
* **Data type:** file path string - **Data type:** File path string
* **Options:**
* `default`: accepts a file path string; defaults to null The file widget allows editors to upload a file or select an existing one from the media library. The path to the file will be saved to the field as a string.
* `media_library`: settings to apply when a media library is opened by the
current widget ## Widget options
* `allow_multiple`: *(default: `true`)* when set to `false`, multiple selection will be disabled even if the media library extension supports it
* `config`: a configuration object passed directly to the media library; check the documentation of your media library extension for available `config` options For common options, see [Common widget options](/docs/widgets#common-widget-options).
* `media_folder` (Beta): file path where uploaded images will be saved specific to this control. Paths can be relative to a collection folder (e.g. `images` will add the image to a sub-folder in the collection folder) or absolute with reference to the base of the repo which needs to begin with `/` (e.g `/static/images` will save uploaded images to the `static` folder in a sub folder named `images`)
* `choose_url`: *(default: `true`)* when set to `false`, the "Insert from URL" button will be hidden | Name | Type | Default | Description |
* **Example:** | ------------- | --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| default | string | `null` | _Optional_. The default value for the field. Accepts a datetime string, or an empty string to accept blank input; otherwise defaults to current datetime |
| media_library | Media Library Options | `{}` | _Optional_. Media library settings to apply when a media library is opened by the current widget. See [Media Library Options](#media-library-options) |
| media_folder | string | | _Optional_. Specifies the folder path where uploaded files should be saved, relative to the base of the repo |
| public_folder | string | | _Optional_. Specifies the folder path where the files uploaded by the media library will be accessed, relative to the base of the built site |
### Media Library Options
| Name | Type | Default | Description |
| -------------- | ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| allow_multiple | boolean | `true` | _Optional_. When set to `false`, prevents multiple selection for any media library extension, but must be supported by the extension in use |
| config | string | `{}` | _Optional_. A configuration object that will be passed directly to the media library being used - available options are determined by the library |
| choose_url | string<br />\| boolean | `true` | _Optional_. When set to `false`, the "Insert from URL" button will be hidden |
## Example
```yaml ```yaml
- label: "Featured Image" name: thumbnail
title: "thumbnail" label: Featured Image
widget: "image" widget: image
choose_url: true default: /uploads/chocolate-dogecoin.jpg
default: "/uploads/chocolate-dogecoin.jpg" media_library:
media_library: choose_url: true
config: config:
multiple: true multiple: true
``` ```

View File

@ -3,127 +3,231 @@ group: Widgets
title: List title: List
weight: 17 weight: 17
--- ---
The list widget allows you to create a repeatable item in the UI which saves as a list of widget values. map a user-provided string with a comma delimiter into a list. You can choose any widget as a child of a list widget—even other lists.
* **Name:** `list` ## Overview
* **UI:** without any `fields` specified, the list widget defaults to a text input for entering comma-separated values; with `fields` specified, the list widget contains a repeatable child widget, with controls for adding, deleting, and re-ordering the repeated widgets.
* **Data type:** list of widget values
* **Options:**
* `default`: you may specify a list of strings to populate the basic text - **Name:** `list`
field, or an array of list items for lists using the `fields` option. If no - **UI:** The list widget contains a repeatable child widget, with controls for adding, deleting, and re-ordering the repeated widgets.
default is declared when using `field` or `fields`, will default to a single - **Data type:** List of widget values
list item using the defaults on the child widgets
* `allow_add`: `false` hides the button to add additional items The list widget allows you to create a repeatable item in the UI which saves as a list of widget values. You can choose any widget as a child of a list widget—even other lists.
* `collapsed`: when `true`, the entries collapse by default
* `summary`: specify the label displayed on collapsed entries ## Widget options
* `minimize_collapsed`: when `true`, collapsing the list widget will hide all of it's entries instead of showing summaries
* `label_singular`: the text to show on the add button For common options, see [Common widget options](/docs/widgets#common-widget-options).
* `field`: a single widget field to be repeated
* `fields`: a nested list of multiple widget fields to be included in each repeatable iteration | Name | Type | Default | Description |
* `max`: maximum number of items in the list | -------------- | ---------------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* `min`: minimum number of items in the list | default | string | `Single item`<br />`(with child defaults)` | _Optional_. The default value for the field. Accepts an array of list items |
* `add_to_top`: when `true`, new entries will be added to the top of the list | allow_add | boolean | `true` | _Optional_. `false` - Hides the button to add additional items |
* **Example** (`field`/`fields` not specified): | collapsed | boolean | `true` | _Optional_. `true` - The entries collapse by default |
| summary | string | | _Optional_. The label displayed on collapsed entries |
| label_singular | string | `label` | _Optional_. The text to show on the add button |
| fields | list of widgets | [] | _Optional_. A nested list of multiple widget fields to be included in each repeatable iteration |
| max | number | | _Optional_. Maximum number of items in the list |
| min | number | | _Optional_. Minimum number of items in the list |
| add_to_top | boolean | `false` | _Optional_. <ul><li>`true` - New entries will be added to the top of the list</li><li>`false` - New entries will be added to the bottom of the list</li></ul> |
| types | list of object widgets | | _Optional_. A nested list of object widgets representing the available types for items in the list. Takes priority over `fields`. |
| type_key | string | `'type'` | _Optional_. The name of the field that will be added to every item in list representing the name of the object widget that item belongs to. Ignored if `types` is not defined |
## Examples
### Basic
```yaml ```yaml
- label: "Tags" name: testimonials
title: "tags" label: Testimonials
widget: "list" widget: list
default: ["news"] summary: '{{fields.quote}} - {{fields.author.name}}'
fields:
- name: quote
label: Quote
widget: string
default: Everything is awesome!
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
default: Emmet
- name: avatar
label: Avatar
widget: image
default: /img/emmet.jpg
``` ```
* **Example** (`allow_add` marked `false`): ### Allow Additions
```yaml ```yaml
- label: "Tags" name: testimonials
title: "tags" label: Testimonials
widget: "list" widget: list
allow_add: false summary: '{{fields.quote}} - {{fields.author.name}}'
default: ["news"] allow_add: false
fields:
- name: quote
label: Quote
widget: string
default: Everything is awesome!
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
default: Emmet
- name: avatar
label: Avatar
widget: image
default: /img/emmet.jpg
``` ```
* **Example** (with `field`): ### Default Value
```yaml ```yaml
- label: "Gallery" - name: galleryImages
title: "galleryImages" label: Gallery
widget: "list" widget: list
summary: '{{fields.image}}'
field: {label: Image, title: image, widget: image}
```
* **Example** (with `fields`):
```yaml
- label: "Testimonials"
title: "testimonials"
widget: "list"
summary: '{{fields.quote}} - {{fields.author.name}}'
fields: fields:
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"} - name: src
- label: Author label: Source
title: author widget: string
widget: object - name: alt
fields: label: Alt Text
- {label: Name, title: name, widget: string, default: "Emmet"} widget: string
- {label: Avatar, title: avatar, widget: image, default: "/img/emmet.jpg"}
```
* **Example** (with `default`):
```yaml
- label: "Gallery"
title: "galleryImages"
widget: "list"
fields:
- { label: "Source", title: "src", widget: "string" }
- { label: "Alt Text", title: "alt", widget: "string" }
default: default:
- { src: "/img/tennis.jpg", alt: "Tennis" } - src: /img/tennis.jpg
- { src: "/img/footbar.jpg", alt: "Football" } alt: Tennis
- src: /img/footbar.jpg
alt: Football
``` ```
* **Example** (`collapsed` marked `false`): ### Start Collapsed
```yaml ```yaml
- label: "Testimonials" name: testimonials
title: "testimonials" label: Testimonials
collapsed: false widget: list
widget: "list" summary: '{{fields.quote}} - {{fields.author.name}}'
fields: collapsed: false
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"} fields:
- {label: Author, title: author, widget: string } - name: quote
label: Quote
widget: string
default: Everything is awesome!
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
default: Emmet
- name: avatar
label: Avatar
widget: image
default: /img/emmet.jpg
``` ```
* **Example** (`minimize_collapsed` marked `true`): ### Min and Max
```yaml ```yaml
- label: "Testimonials" name: testimonials
title: "testimonials" label: Testimonials
minimize_collapsed: true widget: list
widget: "list" summary: '{{fields.quote}} - {{fields.author.name}}'
fields: min: 1
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"} max: 3
- {label: Author, title: author, widget: string } fields:
- name: quote
label: Quote
widget: string
default: Everything is awesome!
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
default: Emmet
- name: avatar
label: Avatar
widget: image
default: /img/emmet.jpg
``` ```
* **Example** (with `max` & `min`): ### Add To Top
```yaml ```yaml
- label: "Tags" name: testimonials
title: "tags" label: Testimonials
widget: "list" widget: list
max: 3 summary: '{{fields.quote}} - {{fields.author.name}}'
min: 1 add_to_top: true
default: ["news"] fields:
- name: quote
label: Quote
widget: string
default: Everything is awesome!
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
default: Emmet
- name: avatar
label: Avatar
widget: image
default: /img/emmet.jpg
``` ```
* **Example** (`add_to_top` marked `true`): ### Typed List
```yaml ```yaml
- label: "Tags" name: sections
title: "tags" label: Home Section
widget: "list" widget: list
add_to_top: true types:
``` - name: carousel
label: Carousel
widget: object
summary: '{{fields.header}}'
fields:
- name: header
label: Header
widget: string
default: Image Gallery
- name: template
label: Template
widget: string
default: carousel.html
- name: images
label: Images
widget: list
fields:
- name: image
label: Image
widget: image
- name: spotlight
label: Spotlight
widget: object
fields:
- name: header
label: Header
widget: string
default: Spotlight
- name: template
label: Template
widget: string
default: spotlight.html
- name: text
label: Text
widget: text
default: Hello World
```

View File

@ -3,18 +3,29 @@ group: Widgets
title: Map title: Map
weight: 18 weight: 18
--- ---
## Overview
- **Name:** `map`
- **UI:** Interactive map
- **Data type:** `GeoJSON string``
The map widget allows you to edit spatial data using an interactive map. Spatial data for a single piece of geometry saves as a GeoJSON string in WGS84 projection. The map widget allows you to edit spatial data using an interactive map. Spatial data for a single piece of geometry saves as a GeoJSON string in WGS84 projection.
* **Name:** `map` ## Widget options
* **UI:** interactive map
* **Data type:** GeoJSON string
* **Options:**
* `decimals`: accepts a number to specify precision of saved coordinates; defaults to 7 decimals For common options, see [Common widget options](/docs/widgets#common-widget-options).
* `default`: accepts a GeoJSON string containing a single geometry; defaults to an empty string
* `type`: accepts one string value of `Point`, `LineString` or `Polygon`; defaults to `Point`
* **Example:**
```yaml | Name | Type | Default | Description |
- {label: "Location", title: "location", widget: "map" } | -------- | ---------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------- |
``` | default | string | `''` | _Optional_. The default value for the field. Accepts a GeoJSON string containing a single geometry |
| decimals | number | `7` | _Optional_. Precision of saved coordinates |
| default | 'Point'<br />\| 'LineString'<br />\| 'Polygon' | `'Point'` | _Optional_. Data type |
## Example
```yaml
name: location
label: Location
widget: map
```

View File

@ -3,24 +3,35 @@ group: Widgets
title: Markdown title: Markdown
weight: 19 weight: 19
--- ---
The markdown widget provides a full fledged text editor allowing users to format text with features such as headings and blockquotes. Users can change their editing view with a handy toggle button.
*Please note:* If you want to use your markdown editor to fill a markdown file contents after its frontmatter, you'll have to name the field `body` so the CMS recognizes it and saves the file accordingly. ## Overview
* **Name:** `markdown` - **Name:** `markdown`
* **UI:** full text editor - **UI:** [Toast UI Editor](https://ui.toast.com/tui-editor)
* **Data type:** markdown - **Data type:** `markdown string`
* **Options:**
* `default`: accepts markdown content The markdown widget provides a full fledged text editor allowing users to format text with features such as headings and blockquotes. Users can change their editing view with a handy toggle button.
* **Example:**
```yaml _Please note:_ If you want to use your markdown editor to fill a markdown file contents after its frontmatter, you'll have to name the field `body` so the CMS recognizes it and saves the file accordingly.
- { label: 'Blog post content', title: 'body', widget: 'markdown' }
``` ## Widget options
For common options, see [Common widget options](/docs/widgets#common-widget-options).
| Name | Type | Default | Description |
| ------- | ------ | ------- | --------------------------------------------------------------------- |
| default | string | `''` | _Optional_. The default value for the field. Accepts markdown content |
## Example
```yaml
name: body
label: Blog post content
widget: markdown
```
This would render as: This would render as:
![Markdown widget example](/img/widgets-markdown.webp) ![Markdown widget example](/img/widgets-markdown.webp)
*Please note:* The markdown widget outputs a raw markdown string. Your static site generator may or may not render the markdown to HTML automatically. Consult with your static site generator's documentation for more information about rendering markdown. _Please note:_ The markdown widget outputs a raw markdown string. Your static site generator may or may not render the markdown to HTML automatically. Consult with your static site generator's documentation for more information about rendering markdown.

View File

@ -4,25 +4,35 @@ title: Number
weight: 20 weight: 20
--- ---
The number widget uses an HTML number input, saving the value as a string, integer, or floating point number. ## Overview
- **Name:** `number` - **Name:** `number`
- **UI:** HTML [number input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number) - **UI:** HTML [number input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number)
- **Data type:** string by default; configured by `value_type` option - **Data type:** `string` or `number`. Configured by `value_type` option
- **Options:**
- `default`: accepts string or number value; defaults to empty string The number widget uses an HTML number input, saving the value as a string, integer, or floating point number.
- `value_type`: accepts `int` or `float`; any other value results in saving as a string
- `min`: accepts a number for minimum value accepted; unset by default ## Widget options
- `max`: accepts a number for maximum value accepted; unset by default
- `step`: accepts a number for stepping up/down values in the input; 1 by default For common options, see [Common widget options](/docs/widgets#common-widget-options).
- **Example:**
```yaml | Name | Type | Default | Description |
- label: "Puppy Count" | ---------- | ------------------------------------ | ---------- | ----------------------------------------------------------------------------------- |
title: "puppies" | default | string<br />\| number | `''` | _Optional_. The default value for the field. Accepts a string or number |
widget: "number" | value_type | 'int'<br />\| 'float'<br />\| string | `'string'` | _Optional_. Accepts `int` or `float`; any other value results in saving as a string |
default: 2 | min | number | | _Optional_. Minimum value accepted |
value_type: "int" | max | number | | _Optional_. Maximum value accepted |
min: 1 | step | number | `1` | _Optional_. Size of steps when stepping up or down in input |
max: 101
step: 2 ## Example
```
```yaml
name: 'puppies'
label: 'Puppy Count'
widget: 'number'
default: 2
value_type: 'int'
min: 1
max: 101
step: 2
```

View File

@ -3,38 +3,59 @@ group: Widgets
title: Object title: Object
weight: 21 weight: 21
--- ---
The object widget allows you to group multiple widgets together, nested under a single field. You can choose any widget as a child of an object widget—even other objects.
* **Name:** `object` ## Overview
* **UI:** a field containing one or more child widgets
* **Data type:** list of child widget values
* **Options:**
* `default`: you can set defaults within each sub-field's configuration - **Name:** `object`
* `collapsed`: if added and labeled `true`, collapse the widget's content by default - **UI:** a field containing one or more child widgets
* `summary`: specify the label displayed when the object is collapsed - **Data type:** Object of child widget values
* `fields`: (**required**) a nested list of widget fields to include in your widget
* **Example:**
```yaml The object widget allows you to group multiple widgets together, nested under a single field. You can choose any widget as a child of an object widget, even other object widgets.
- label: "Profile"
title: "profile" ## Widget options
widget: "object"
summary: '{{fields.name}}: {{fields.birthdate}}' For common options, see [Common widget options](/docs/widgets#common-widget-options).
| Name | Type | Default | Description |
| --------- | ------- | ------- | ------------------------------------------------------------ |
| fields | boolean | `false` | A nested list of widget fields to include in your widget |
| collapsed | boolean | `false` | _Optional_. Collapse the widget's content by default |
| summary | string | `value` | _Optional_. The label displayed when the object is collapsed |
_Please note:_ A default value cannot be set directly on an object widget. Instead you can set defaults within each sub-field's configuration
## Example
```yaml
name: 'profile'
label: 'Profile'
widget: 'object'
summary: '{{fields.name}}: {{fields.birthdate}}'
fields:
- name: public
label: Public
widget: boolean
default: true
- name: name
label: Name
widget: string
- name: 'birthdate'
label: 'Birthdate'
widget: 'date'
default: ''
format: 'MM/DD/YYYY'
- name: 'address'
label: 'Address'
widget: 'object'
collapsed: true
fields: fields:
- {label: "Public", title: "public", widget: "boolean", default: true} - name: street
- {label: "Name", title: "name", widget: "string"} label: Street Address
- label: "Birthdate" widget: string
title: "birthdate" - name: city
widget: "date" label: City
default: "" widget: string
format: "MM/DD/YYYY" - name: post-code
- label: "Address" label: Postal Code
title: "address" widget: string
widget: "object" ```
collapsed: true
fields:
- {label: "Street Address", title: "street", widget: "string"}
- {label: "City", title: "city", widget: "string"}
- {label: "Postal Code", title: "post-code", widget: "string"}
```

View File

@ -3,62 +3,79 @@ group: Widgets
title: Relation title: Relation
weight: 22 weight: 22
--- ---
## Overview
- **Name:** `relation`
- **UI:** Text input with search result dropdown
- **Data type:** Data type of the value pulled from the related collection item
The relation widget allows you to reference items from another collection. It provides a search input with a list of entries from the collection you're referencing, and the list automatically updates with matched entries based on what you've typed. The relation widget allows you to reference items from another collection. It provides a search input with a list of entries from the collection you're referencing, and the list automatically updates with matched entries based on what you've typed.
* **Name:** `relation` ## Widget options
* **UI:** text input with search result dropdown
* **Data type:** data type of the value pulled from the related collection item
* **Options:**
* `collection`: (**required**) name of the referenced collection (string) For common options, see [Common widget options](/docs/widgets#common-widget-options).
* `value_field`: (**required**) name of the field from the referenced collection whose value will be stored for the relation. For nested fields, separate each subfield with a `.` (e.g. `name.first`). For list fields use a wildcard `*` to target all list items (e.g. `categories.*`).
* `search_fields`: (**required**) list of one or more names of fields in the referenced collection to search for the typed value. Syntax to reference nested fields is similar to that of *value_field*. | Name | Type | Default | Description |
* `file`: allows referencing a specific file when the referenced collection is a files collection (string) | -------------- | -------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* `display_fields`: list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. Defaults to `value_field`. Syntax to reference nested fields is similar to that of *value_field*. | collection | string | | Name of the referenced collection |
* `default`: accepts any widget data type; defaults to an empty string | value_field | string | | Name of the field from the referenced collection whose value will be stored for the relation. For nested fields, separate each subfield with a `.` (e.g. `name.first`). For list fields use a wildcard `*` to target all list items (e.g. `categories.*`) |
* `multiple` : accepts a boolean, defaults to `false` | search_fields | list of strings | | List of one or more names of fields in the referenced collection to search for the typed value. Syntax to reference nested fields is similar to that of _value_field_ |
* `min`: minimum number of items; ignored if **multiple** is `false` | default | Any widget data type | `''` | _Optional_. The default value for the field. Accepts any widget data type |
* `max`: maximum number of items; ignored if **multiple** is `false` | file | string | | _Optional_. Allows referencing a specific file when the referenced collection is a files collection |
* `options_length`: accepts integer to override number of options presented to user. Defaults to `20`. | display_fields | list of strings | | _Optional_. list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. Defaults to `value_field`. Syntax to reference nested fields is similar to that of _value_field_ |
* **Referencing a folder collection example** (assuming a separate "authors" collection with "name" and "twitterHandle" fields with subfields "first" and "last" for the "name" field): | multiple | boolean | `false` | _Optional_. Allow multiple values to be selected |
| min | number | | _Optional_. Minimum number of items. Ignored if **multiple** is `false` |
| max | number | | _Optional_. Maximum number of items. Ignored if **multiple** is `false` |
| options_length | number | `20` | _Optional_. Number of options presented to user |
## Examples
### Referencing A Folder Collection
_Assuming a separate "authors" collection with "name" and "twitterHandle" fields with subfields "first" and "last" for the "name" field._
```yaml ```yaml
- label: "Post Author" name: author
title: "author" label: Post Author
widget: "relation" widget: relation
collection: "authors" collection: authors
search_fields: ["name.first", "twitterHandle"] search_fields: ['name.first', 'twitterHandle']
value_field: "name.first" value_field: name.first
display_fields: ["twitterHandle", "followerCount"] display_fields: ['twitterHandle', 'followerCount']
``` ```
The generated UI input will search the authors collection by name and twitterHandle, and display each author's handle and follower count. On selection, the author's name is saved for the field. The generated UI input will search the authors collection by name and twitterHandle, and display each author's handle and follower count. On selection, the author's name is saved for the field.
* **String templates example** (assuming a separate "authors" collection with "name" and "twitterHandle" fields with subfields "first" and "last" for the "name" field): ### String Template
_Assuming a separate "authors" collection with "name" and "twitterHandle" fields with subfields "first" and "last" for the "name" field._
```yaml ```yaml
- label: "Post Author" name: author
title: "author" label: Post Author
widget: "relation" widget: relation
collection: "authors" collection: authors
search_fields: ['name.first'] search_fields: ['name.first']
value_field: "{{slug}}" value_field: '{{slug}}'
display_fields: ["{{twitterHandle}} - {{followerCount}}"] display_fields: ['{{twitterHandle}} - {{followerCount}}']
``` ```
The generated UI input will search the authors collection by name, and display each author's handle and follower count. On selection, the author entry slug is saved for the field. The generated UI input will search the authors collection by name, and display each author's handle and follower count. On selection, the author entry slug is saved for the field.
* **Referencing a file collection list field example** (assuming a separate "relation_files" collection with a file named "cities" with a list field "cities" with subfields "name" and "id"): ### Referencing A File Collection List Field
_Assuming a separate "relation_files" collection with a file named "cities" with a list field "cities" with subfields "name" and "id"._
```yaml ```yaml
- label: "City" name: city
title: "city" label: City
widget: "relation" widget: relation
collection: "relation_files" collection: relation_files
file: "cities" file: cities
search_fields: ["cities.*.name"] search_fields: ['cities.*.name']
display_fields: ["cities.*.name"] display_fields: ['cities.*.name']
value_field: "cities.*.id" value_field: 'cities.*.id'
``` ```
The generated UI input will search the cities file by city name, and display each city's name. On selection, the city id is saved for the field. The generated UI input will search the cities file by city name, and display each city's name. On selection, the city id is saved for the field.

View File

@ -3,78 +3,100 @@ group: Widgets
title: Select title: Select
weight: 23 weight: 23
--- ---
## Overview
- **Name:** `select`
- **UI:** Select input
- **Data type:** `string`, `number`, `list of strings` or `list of numbers`
The select widget allows you to pick a string value from a dropdown menu. The select widget allows you to pick a string value from a dropdown menu.
* **Name:** `select` ## Widget options
* **UI:** select input
* **Data type:** string or array
* **Options:**
* `default`: `options` must contain any default values For common options, see [Common widget options](/docs/widgets#common-widget-options).
* string values: accepts a string; defaults to an empty string. Accepts an array of strings and defaults to an empty array with `multiple: true` enabled. | Name | Type | Default | Description |
* object with `label` and `value` fields: accepts an object with `label` and `value` field or an array of such objects when `multiple: true` is enable. Defaults to no value | -------- | ------------------------------------------------------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* `options`: (**required**) there are two ways to list of options for the dropdown menu: | options | list of strings<br />\| list of numbers<br />\| object with `label` and `value` | | <ul><li>`string` or `number` - The dropdown displays the value directly</li><li>object with `label` and `value` fields - The label displays in the dropdown and the value saves in the file</li></ul> |
| default | string<br />\| number<br />\| list of string<br />\| list of number | `''`<br />`[]` if multiple is `true` | _Optional_. The default value for the field. Accepts a string |
| multiple | boolean | `false` | _Optional_. Allow multiple values/options to be selected |
| min | number | | _Optional_. Minimum number of items. Ignored if **multiple** is `false` |
| max | number | | _Optional_. Maximum number of items; ignored if **multiple** is `false` |
* string values: the dropdown displays the value directly ## Examples
* object with `label` and `value` fields: the label displays in the dropdown; the value saves in the file
* `multiple`: accepts a boolean; defaults to `false`
* `min`: minimum number of items; ignored if **multiple** is `false`
* `max`: maximum number of items; ignored if **multiple** is `false`
* **Example** (options as strings): ### Options As Strings
```yaml ```yaml
- label: "Align Content" name: align
title: "align" label: Align Content
widget: "select" widget: select
options: ["left", "center", "right"] options: ['left', 'center', 'right']
``` ```
Selecting the `center` option, will save the value as: Selecting the `center` option, will save the value as:
```yaml ```yaml
align: "center" align: center
``` ```
* **Example** (options as objects): ### Options As Numbers
```yaml ```yaml
- label: "City" name: align
title: "airport-code" label: Align Content
widget: "select" widget: select
options: options: [1, 2, 3]
- { label: "Chicago", value: "ORD" } ```
- { label: "Paris", value: "CDG" }
- { label: "Tokyo", value: "HND" } Selecting the `2` option, will save the value as:
```yaml
align: 2
```
### Options As Objects
```yaml
title: airport-code
label: City
widget: select
options:
- label: Chicago
value: ORD
- label: Paris
value: CDG
- label: Tokyo
value: HND
``` ```
Selecting the `Chicago` option, will save the value as: Selecting the `Chicago` option, will save the value as:
```yaml ```yaml
airport-code: "ORD" airport-code: ORD
``` ```
* **Example** (multiple): ### Multiple
```yaml ```yaml
- label: "Tags" name: 'tags'
title: "tags" label: 'Tags'
widget: "select" widget: 'select'
multiple: true multiple: true
options: ["Design", "UX", "Dev"] options: ['Design', 'UX', 'Dev']
default: ["Design"] default: ['Design']
``` ```
* **Example** (min/max): ### Min and Max
```yaml ```yaml
- label: "Tags" name: 'tags'
title: "tags" label: 'Tags'
widget: "select" widget: 'select'
multiple: true multiple: true
min: 1 min: 1
max: 3 max: 3
options: ["Design", "UX", "Dev"] options: ['Design', 'UX', 'Dev']
default: ["Design"] default: ['Design']
``` ```

View File

@ -4,14 +4,26 @@ title: String
weight: 24 weight: 24
--- ---
The string widget translates a basic text input to a string value. For larger textarea inputs, use the text widget. ## Overview
- **Name:** `string` - **Name:** `string`
- **UI:** text input - **UI:** Text input
- **Data type:** string - **Data type:** `string`
- **Options:**
- `default`: accepts a string; defaults to an empty string The string widget translates a basic text input to a string value. For larger textarea inputs, use the text widget.
- **Example:**
```yaml ## Widget options
- {label: "Title", title: "title", widget: "string"}
``` For common options, see [Common widget options](/docs/widgets#common-widget-options).
| Name | Type | Default | Description |
| ------- | ------ | ------- | ------------------------------------------------------------- |
| default | string | `''` | _Optional_. The default value for the field. Accepts a string |
## Example
```yaml
name: title
label: Title
widget: string
```

View File

@ -4,14 +4,26 @@ title: Text
weight: 25 weight: 25
--- ---
The text widget takes a multiline text field and saves it as a string. For shorter text inputs, use the string widget. ## Overview
- **Name:** `text` - **Name:** `text`
- **UI:** HTML textarea - **UI:** Textarea
- **Data type:** string - **Data type:** `string`
- **Options:**
- `default`: accepts a string; defaults to an empty string The text widget takes a multiline text field and saves it as a string. For shorter text inputs, use the string widget.
- **Example:**
```yaml ## Widget options
- {label: "Description", title: "description", widget: "text"}
``` For common options, see [Common widget options](/docs/widgets#common-widget-options).
| Name | Type | Default | Description |
| ------- | ------ | ------- | ------------------------------------------------------------- |
| default | string | `''` | _Optional_. The default value for the field. Accepts a string |
## Example
```yaml
name: description
label: Description
widget: text
```

View File

@ -23,8 +23,6 @@ The following options are available on all fields:
| hint | string | | _Optional_. Adds helper text directly below a widget. Useful for including instructions. Accepts markdown for bold, italic, strikethrough, and links. | | hint | string | | _Optional_. Adds helper text directly below a widget. Useful for including instructions. Accepts markdown for bold, italic, strikethrough, and links. |
| pattern | string | | _Optional_. Adds field validation by specifying a list with a [regex pattern](https://regexr.com/) and an error message; more extensive validation can be achieved with [custom widgets](/docs/custom-widgets/#advanced-field-validation) | | pattern | string | | _Optional_. Adds field validation by specifying a list with a [regex pattern](https://regexr.com/) and an error message; more extensive validation can be achieved with [custom widgets](/docs/custom-widgets/#advanced-field-validation) |
| i18n | boolean<br />\|'translate'<br />\|'duplicate'<br />\|'none' | | _Optional_. <img src="https://img.shields.io/badge/-Beta%20Feature-blue" alt="Beta Feature" /><ul><li>`translate` - Allows translation of the field</li><li>`duplicate` - Duplicates the value from the default locale</li><li>`true` - Accept parent values as default</li><li>`none` or `false` - Exclude field from translations</li></ul> | | i18n | boolean<br />\|'translate'<br />\|'duplicate'<br />\|'none' | | _Optional_. <img src="https://img.shields.io/badge/-Beta%20Feature-blue" alt="Beta Feature" /><ul><li>`translate` - Allows translation of the field</li><li>`duplicate` - Duplicates the value from the default locale</li><li>`true` - Accept parent values as default</li><li>`none` or `false` - Exclude field from translations</li></ul> |
| media_folder | string | | _Optional_. Specifies the folder path where uploaded files should be saved, relative to the base of the repo |
| public_folder | string | | _Optional_. Specifies the folder path where the files uploaded by the media library will be accessed, relative to the base of the built site |
| comment | string | | _Optional_. Adds comment before the field (only supported for yaml) | | comment | string | | _Optional_. Adds comment before the field (only supported for yaml) |
### Example ### Example

View File

@ -32,7 +32,7 @@ const DocsContent = styled('div')(
& div, & div,
& p:not(:first-of-type) { & p:not(:first-of-type) {
margin-top: 16px; margin-top: 8px;
} }
& :not(h1,h2,h3,h4,h5,h6) a { & :not(h1,h2,h3,h4,h5,h6) a {
@ -155,6 +155,10 @@ const DocsContent = styled('div')(
} }
} }
& h1 + h2 {
margin-top: 0;
}
& table thead tr th, & table thead tr th,
& table thead tr td { & table thead tr td {
white-space: nowrap; white-space: nowrap;
@ -252,6 +256,10 @@ const DocsContent = styled('div')(
margin: 0; margin: 0;
} }
& ul + p {
margin-top: 16px;
}
& abbr[title] { & abbr[title] {
text-decoration: underline double; text-decoration: underline double;
} }

View File

@ -145,6 +145,8 @@ export const getStaticProps: GetStaticProps = async ({ params }): Promise<{ prop
}, },
}); });
console.log(docsGroups.flatMap(group => group.links.flatMap(link => link.title)));
return { return {
props: { props: {
docsGroups, docsGroups,