In Prismic, each slice is a composition of one or several variations. And each of these variation is itself a composition of a non-repeatable zone called primary and a repeatable zone called items.
And each of these zones is composed of Prismic fields (or widgets).
They define both the shape of the data your slices will receive from the API and what your editors will see inside Prismic. For each of these fields, pris-types
offers a corresponding helper and sometimes aliases.
4 Things to note:
All snake_cased
properties in Prismic, are mapped to camelCase
in pris-types
Some helpers are complex or require props, they are marked with a 🔺 emoji
Helpers may export mock functions that should be used in the Mocks
export
Don't define mocks everywhere, the builder provides meaningful mocks by default
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholderTrue | What to display for value "True" | No | True |
placeholderFalse | What to display for value "False" | No | False |
defaultValue | Default selected value for editors | No | True |
For mocking a Boolean field, you've got 3 helpers:
Rand
to get a random value between true & falseTrue
to always get trueFalse
to always get falseeg.
const field = PrisTypes.Boolean.Rand()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
For mocking a Color field, you've got 3 possibilities:
Rand
to get a random hex colorDark
to get a dark hex colorLight
to get a light hex coloreg.
const field = PrisTypes.Color.Rand() // #E1E1E1
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
For mocking a Date field, you've got 3 possibilities:
Now
to get the current dateFuture
to get a date up to a week after nowPast
to get a date up to a week before noweg.
const field = PrisTypes.Date.Now()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
The default mock configuration of GeoPoint works well enough and will return random, valid coordinates in Paris 💜 Feel free to skip mock configuration here!
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
constraint | A string with width and height sizes | Yes | eg. 500x500 |
key:thumbnailName | A string with width and height sizes | Yes | eg. portrait: "800x350" |
Say you want to define an Image field with a default constraint of 1000x1200 size, and some alternative constraints (called thumbnails in Prismic) for square images and portraits:
const img = PrisTypes.Image({ label: "My well defined Image", contraint: "1000x1200", square: "500x500", portrait: "800x350" })
The default mock configuration of Image fields provide you with a random image from Unsplash, that will be correctly dimensioned to constraints you defined. Feel free to skip the mock configuration here!
In Prismic, Links can define a relation to:
The Link field provides ways to define several sub-fields and therefore is sort of a low-level field, that might not be the most convenient for everyone. Consider using aliases instead!
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
allowTargetBlank | Boolean for links to web URL | No | true |
customTypes | Array of custom types for links to docs | If Document | null |
select | Select between media or document type | If Doc or Media | null |
const link = PrisTypes.Link({ label: "My link", placeholder: "Could be a link to use case, press article, signup...", allowTargetBlank: false })
const link = PrisTypes.Link({ label: "My link", placeholder: "Could be a link to homepage or author...", select: "document", customTypes: ["homepage", "author"] })
const link = PrisTypes.Link({ label: "My link", placeholder: "Could be a link to PDF file or video...", select: "media" })
Pretty much the same as a "no special config" Link
const link = PrisTypes.LinkToWeb()
Required property customTypes
, it sets select
to document
automatically:
const link = PrisTypes.LinkToDoc({ customTypes: ['homepage'] })
It sets select
to media
automatically:
const link = PrisTypes.LinkToMedia()
For mocking a Link field, you've got 3 helpers, each related to its dedicated link type:
Web
to create a web link mock
,Document
to create a document link mock
,Media
to create a document media mockeg.
const link = PrisTypes.Link.Web() || PrisTypes.LinkToWeb.Web() const docLink = PrisTypes.Link.Document() || PrisTypes.LinkToDoc.Document() const mediaLink = PrisTypes.Link.Media() || PrisTypes.LinkToMedia.Media()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
For mocking a Number field, you've got 3 possibilities:
Small
to return a number between 1 and 9
,Long
to return a number between 1000 and 100_000
,Negative
to return a number between -1000 and -1Note that not providing a mock configuration will work fine for most cases.
eg.
const field = PrisTypes.Number.Small()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
multi | Enable multiple paragraphs | No | false |
options | List of formatting options (see below) | No | RichTextOptions |
For mocking a RichText field, you've got 3 possibilities:
Paragraph
to
,Heading
to
,Story
toeg.
const field = PrisTypes.RichText.Paragraph()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
options | No | ||
defaultValue | No |
For mocking a Select field, you've got 1 possibilities:
Option
toeg.
const field = PrisTypes.Select.Option()
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
The default mock configuration of Text works well enough in most cases. I may add some helpers if needed.
Params | Description | Required | Default value |
---|---|---|---|
label | Input Label (content editors) | No | field name |
placeholder | Input Placeholder (content editors) | No | field name |
For mocking a Timestamp field, you've got 3 helpers:
Now
to get the current dateFuture
to get a date up to a week after nowPast
to get a date up to a week before noweg.
const field = PrisTypes.Timestamp.Now()