Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Content Updates – Updated Documentation on the List Field #2183

Merged
merged 46 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1bfb2e8
TinaCMS content update
tina-cloud-app[bot] Sep 11, 2024
bb66ac0
TinaCMS content update
tina-cloud-app[bot] Sep 11, 2024
7564e46
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
85e5afc
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
3a7f5be
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
14af5f0
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
c51e4a3
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
46adccb
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
3410916
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
4b8b10e
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
8bb5235
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
5f74ec0
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
ed1e419
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
7733906
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
426fa43
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
d67b52a
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
ff36ddf
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
e8aaf53
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
9694081
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
86e8bd6
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
c0df5a8
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
7a92d65
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
b7b3819
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
dc34238
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
641d4ce
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
e58083d
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
d7ada9f
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
40db61f
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
89be65b
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
1c6ca2f
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
a124feb
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
8167a88
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
c1336af
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
c6d2d47
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
063ce4b
TinaCMS content update
tina-cloud-app[bot] Sep 12, 2024
e074ab4
TinaCMS content update
tina-cloud-app[bot] Sep 17, 2024
05cd5a7
allowing default settings to graphql – sometimes you may the response…
isaaclombardssw Sep 17, 2024
2efe5a1
TinaCMS content update
tina-cloud-app[bot] Sep 17, 2024
149fb2f
adding a default-selected field to the graphql component
isaaclombardssw Sep 17, 2024
9877913
merge with main
isaaclombardssw Sep 17, 2024
f6feb1f
TinaCMS content update
tina-cloud-app[bot] Sep 18, 2024
49f6e6b
TinaCMS content update
tina-cloud-app[bot] Sep 18, 2024
de5f2c3
TinaCMS content update
tina-cloud-app[bot] Sep 18, 2024
fdd5809
wiring up the new schema into the component
isaaclombardssw Sep 18, 2024
fcf291e
Merge branch 'tina/ironing-out-how-lists-work' of https://github.com/…
isaaclombardssw Sep 18, 2024
3f45ea2
merge with main
isaaclombardssw Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/ui/GraphQLQueryResponseTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Prism } from '../styles/Prism'

export const GraphQLQueryResponseTabs = ({ ...props }) => {

const [isQuery, setIsQuery] = useState(true);
const [isQuery, setIsQuery] = useState(!props.preselectResponse);

const buttonStyling = "flex justify-center relative leading-tight text-white mx-6 pt-[12px] pb-[10px] text-base font-medium transition duration-150 ease-out rounded-t-3xl flex items-center gap-1 font-tuner whitespace-nowrap px-2"
const activeButtonStyling = " hover:-translate-y-px active:translate-y-px hover:-translate-x-px active:translate-x-px hover:text-gray-50 opacity-50 hover:opacity-100"
Expand Down
8 changes: 5 additions & 3 deletions content/docs/reference/types/boolean.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
---
title: The "boolean" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-12T01:51:16.476Z'
next: ''
previous: ''
---

## `boolean` type
## `boolean` Type

```ts
type BooleanField = {
label: string
name: string
type: 'boolean'
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
list?: boolean
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
label?: string
description?: string
Expand Down
9 changes: 7 additions & 2 deletions content/docs/reference/types/datetime.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
---
title: The "datetime" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-12T01:51:42.540Z'
next: ''
previous: ''
---

## `datetime` Type

```ts
type DatetimeField = {
label: string
name: string
type: 'string'
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
list?: boolean
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
dateFormat: string // eg 'YYYY MM DD'
label?: string
Expand Down
9 changes: 6 additions & 3 deletions content/docs/reference/types/image.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
title: The "image" field
last_edited: '2022-06-15T15:51:56.737Z'
last_edited: '2024-09-12T01:51:04.538Z'
next: ''
previous: ''
---

# `image`
## `image` Type

```ts
type ImageField = {
label: string
name: string
type: 'image'
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
list?: boolean
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
label?: string
description?: string
Expand Down
8 changes: 5 additions & 3 deletions content/docs/reference/types/number.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
---
title: The "number" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-12T01:52:02.407Z'
next: ''
previous: ''
---

## `number` type
## `number` Type

```ts
type NumberField = {
label: string
name: string
type: 'number'
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
list?: boolean
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
label?: string
description?: string
Expand Down
36 changes: 29 additions & 7 deletions content/docs/reference/types/object.mdx
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
---
title: The "object" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-12T01:50:34.111Z'
next: content/docs/reference/types/rich-text.mdx
previous: content/docs/reference/types/reference.mdx
---

# `object`
## `object` Type

```ts
type ObjectField = {
label: string
name: string
type: 'object'
list?: boolean
/** `fields OR `templates` may be provided, not both **/
// `fields` OR `templates` may be provided, not both
fields?: Field[]
templates?: Template[]
/** Customize the default "_template" key that gets set
in a document to identify a block-type.
Only applicable when list: true **/
templatesKey?: string
list?: boolean
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
/** Weather or not the Visual Selector is enabled. See https://tina.io/docs/editing/blocks/#adding-a-visual-block-selector-experimental **/
// Whether or not the Visual Selector is enabled. See https://tina.io/docs/editing/blocks/#adding-a-visual-block-selector-experimental
visualSelector?: boolean,
// Note: defaultItem can only can be used when {list: true}
// defaultItem can only can be used when {list: true}
defaultItem?: Record<string, any> | () => Record<string, any>,
itemProps?(
item: Record<string, any>
Expand Down Expand Up @@ -107,6 +106,29 @@ Tina will generate the appropriate component depending on the configuration prov

![](https://res.cloudinary.com/forestry-demo/image/upload/v1722381170/Screenshot_2024-07-31_at_9.12.43_AM_gahppr.png)

### Using list object as a wrapper for other types

Number, boolean, datetime and rich-text field types can be used in this way to add list options to the TinaCMS editor.

Reference field types can be used in this way to create a list of references.

```javascript
{
label: "Author List",
name: "authorList",
type: "object",
list: true,
fields: [
{
label: 'Author',
name: 'author',
type: 'reference',
collections: ['author'],
},
]
}
```

### Using templates instead of fields

```javascript
Expand Down
16 changes: 8 additions & 8 deletions content/docs/reference/types/reference.mdx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
title: The "reference" field
last_edited: '2024-08-27T08:00:17.162Z'
last_edited: '2024-09-12T01:50:26.823Z'
next: ''
previous: ''
---

## `reference`
## `reference` Type

The `reference` field allows a "parent" document to connect to another document in different collection. This relationship only needs to be defined on *one side*.

Once defined, the values of the *referenced* document become available to the parent.

> Note: `reference` with `list: true` is not currently supported. See the "Temporary work around" section of [issue #2056](https://github.com/tinacms/tinacms/issues/2056) for a suggested approach to achieve a similar result

## Object Definition
> Note: `reference` with `list: true` is not currently supported. Object type lists can be used [as a wrapper](/docs/reference/types/object/#using-list-object-as-a-wrapper-for-other-types) around `reference` field types to create a list of references.

```ts
type ReferenceField = {
label: string
name: string
type: 'reference'
/** The `name` of another collection **/
// The `name` of another collection
collections: string[]
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
label?: string
description?: string
Expand Down Expand Up @@ -145,7 +145,7 @@ You can search your reference with reference selector.

The default reference selector displays the file path, there are cases where you may want to customize what is displayed in the dropdown to provide a better user experience. For example, showing the author's name instead of the file name can make the selection process more intuitive.

Below are some examples on how to customize the reference select using `ui.optionComponent`.
Below are some examples on how to customize the reference select using `ui.optionComponent`.

Check out [custom field](https://tina.io/docs/extending-tina/custom-field-components/) to lean more about `ui`.

Expand Down
75 changes: 58 additions & 17 deletions content/docs/reference/types/rich-text.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: The "rich-text" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-17T04:35:32.776Z'
next: ''
previous: ''
---

# `rich-text`
## `rich-text` Type

Tina's `rich-text` field leverages MDX so you can embed your own structured blocks. To render
a `rich-text` field with React we recommend the `<TinaMarkdown>` component from `tinacms`. See [usage](/docs/editing/markdown/#rendering-content-with-object-object)
Expand Down Expand Up @@ -88,15 +90,54 @@ This is some text

Results in the following response from the content API:

<Iframe
iframeSrc="/api/graphiql/?query=%7B%0A%20%20post(relativePath%3A%20%22voteForPedro.json%22)%20%7B%0A%20%20%20%20body%0A%20%20%7D%0A%7D%0A&#x22; "
height={400}
<GraphQLCodeBlock
query="{
##post(relativePath:#&#x22;voteForPedro.json&#x22;)#{
####body
##}
}"
response="{
##&#x22;data&#x22;:#{
####&#x22;post&#x22;:#{
######&#x22;body&#x22;:#{
########&#x22;type&#x22;:#&#x22;root&#x22;,
########&#x22;children&#x22;:#[
##########{
############&#x22;type&#x22;:#&#x22;h2&#x22;,
############&#x22;children&#x22;:#[
##############{
################&#x22;type&#x22;:#&#x22;text&#x22;,
################&#x22;text&#x22;:#&#x22;Hello,#world!&#x22;
##############}
############]
##########},
##########{
############&#x22;type&#x22;:#&#x22;p&#x22;,
############&#x22;children&#x22;:#[
##############{
################&#x22;type&#x22;:#&#x22;text&#x22;,
################&#x22;text&#x22;:#&#x22;This#is#some#text&#x22;
##############}
############]
##########},
##########{
############&#x22;type&#x22;:#&#x22;mdxJsxFlowElement&#x22;,
############&#x22;name&#x22;:#&#x22;Cta&#x22;,
############&#x22;props&#x22;:#{
##############&#x22;heading&#x22;:#&#x22;Welcome&#x22;
############}
##########}
########]
######}
####}
##}
}"
/>

## Using `TinaMarkdown`

The `<TinaMarkdown>` component allows you to control how each element
is rendered. You _must_ provide a component for each template registered
is rendered. You *must* provide a component for each template registered
in the `templates` property of your field definition. Note that you can also
control rendering of built-in elements like `<h1>, <a>, <img>`

Expand Down Expand Up @@ -131,7 +172,7 @@ export default function MyPage(props) {
}
```

---
***

## Caveats

Expand All @@ -140,12 +181,12 @@ step, Tina's approach adds some constraints to make things work as expected.
[Read more](/docs/editing/markdown/) about Tina's approach to handling markdown
and MDX.

### All content must be _serializable_
### All content must be *serializable*

When we say serializable, we mean that they must not be JavaScript expressions that would need to be executed at any point.

- No support for `import`/`export`
- No support for JavaScript expressions (eg. `const a = 2`, `console.log("Hello")`)
* No support for `import`/`export`
* No support for JavaScript expressions (eg. `const a = 2`, `console.log("Hello")`)

For example:

Expand All @@ -163,23 +204,23 @@ Then you can create a `Date` component which returns `new Date().toLocaleString(

### All JSX must be registered as a `template`

In the above example, if you failed to add the `Cta` _template_ in your schema definition, the JSX element
In the above example, if you failed to add the `Cta` *template* in your schema definition, the JSX element
will be treated as html

---
***

## Handling markdown

Since markdown is an open-format Tina does its best to handle the most common syntax's, but in some scenarios Tina will ignore or automatically alter content:

### Unsupported elements

While most markdown features are supported out of the box, Tina will ignore elements that it cannot handle. We _do not_ expect to support the full [CommonMark](https://commonmark.org/) and
While most markdown features are supported out of the box, Tina will ignore elements that it cannot handle. We *do not* expect to support the full [CommonMark](https://commonmark.org/) and
[GitHub Flavored Markdown](https://github.github.com/gfm/) specs. Be sure to voice your support for various rich-text features by reaching out through one of our [community channels](/community/)!

- Footnotes
- Code blocks via indentation (use ` ``` ` instead)
- Strikethrough
* Footnotes
* Code blocks via indentation (use ` ``` ` instead)
* Strikethrough

### Automatic transforms

Expand Down Expand Up @@ -416,7 +457,7 @@ fields: [

### Full Spec

The full Tina MDX spec can be found [here](https://github.com/tinacms/tinacms/blob/main/packages/%40tinacms/mdx/spec.md 'TinaCMS MDX Spec')
The full Tina MDX spec can be found [here](https://github.com/tinacms/tinacms/blob/main/packages/%40tinacms/mdx/spec.md "TinaCMS MDX Spec")

### Default values

Expand Down
12 changes: 7 additions & 5 deletions content/docs/reference/types/string.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: The "string" field
last_edited: '2021-07-27T15:51:56.737Z'
last_edited: '2024-09-12T01:52:13.442Z'
next: ''
previous: ''
---

## `string` type
## `string` Type

```ts
type StringField = {
Expand All @@ -12,16 +14,16 @@ type StringField = {
type: 'string'
list?: boolean
options?: (string | { value: string; label: string })[]
/** Represents the "body" of a markdown file **/
// Represents the "body" of a markdown file
isBody?: boolean
/** See https://tina.io/docs/extending-tina/overview/ for customizing the UI **/
// See https://tina.io/docs/extending-tina/overview/ for customizing the UI
ui?: {
label?: string
description?: string
component?: FC<any> | string | null
parse?: (value: string | string[], name: string, field: F) => any
format?: (value: string | string[], name: string, field: F) => any
// Note: defaultItem can only can be used when {list: true}
// defaultItem can only can be used when {list: true}
defaultItem?: () => string | string
validate?(
// string or string[] depends on list true or false
Expand Down
Loading