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 all 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
15 changes: 8 additions & 7 deletions components/tinaMarkdownComponents/docAndBlogComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { GraphQLQueryResponseTabs } from 'components/ui/GraphQLQueryResponseTabs';
import Image from 'next/image';
import { useState } from 'react';
import { BiRightArrowAlt } from 'react-icons/bi';
import { FaMinus, FaPlus } from 'react-icons/fa';
import { FiLink } from 'react-icons/fi';
import {
TinaMarkdown,
Components,
} from 'tinacms/dist/rich-text'
Components,
TinaMarkdown,
} from 'tinacms/dist/rich-text';
import { getDocId } from 'utils/docs/getDocIds';
import { WarningCallout } from 'utils/shortcodes';
import { Prism } from '../styles/Prism'
import Image from 'next/image';
import { Prism } from '../styles/Prism';

export const docAndBlogComponents: Components<{
Iframe: { iframeSrc: string; height: string }
Youtube: { embedSrc: string;}
CreateAppCta: { ctaText: string; cliText: string }
GraphQLCodeBlock: { query: string, response: string }
GraphQLCodeBlock: { query: string, response: string, preselectResponse: boolean }
Callout: {
title: string
description: string
Expand Down Expand Up @@ -226,10 +226,11 @@ export const docAndBlogComponents: Components<{
/>
)
},
GraphQLCodeBlock: ({ query, response }) => {
GraphQLCodeBlock: ({ query, response, preselectResponse }) => {
return <GraphQLQueryResponseTabs
query={query}
response={response}
preselectResponse={preselectResponse}
/>
},
CustomFieldComponentDemo: () => (
Expand Down
4 changes: 2 additions & 2 deletions components/ui/GraphQLQueryResponseTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useState } from 'react';
import { Prism } from '../styles/Prism'
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
13 changes: 9 additions & 4 deletions content/docs/editing/blocks.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: /docs/editing/blocks
title: Block-based editing
last_edited: '2024-08-15T00:21:26.449Z'
last_edited: '2024-09-18T01:51:44.261Z'
next: content/docs/editing/single-document-collections.mdx
previous: content/docs/editing/markdown.mdx
---
Expand All @@ -12,9 +12,9 @@ Tina supports block-based editing, so that your editors can build out full pages

Let's say you want your editors to build out a page, and you have 3 main "block" types to start:

- a "Hero" block
- a "Feature" block
- a "Main Content" block
* a "Hero" block
* a "Feature" block
* a "Main Content" block

We want to allow our editors to use various blocks on each page.

Expand Down Expand Up @@ -195,6 +195,11 @@ The fragment names are automatically generated based on the collection name and
####}
##}
}"
<<<<<<< HEAD
preselectResponse={false}
=======
preselectResponse={true}
>>>>>>> de5f2c35126ddcbc14a0d8442990981632405a42
/>

> For more info on how to query data with Tina's GraphQL API, check out the [Query Documentation](https://tina.io/docs/graphql/queries/)
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
6 changes: 3 additions & 3 deletions content/docs/reference/types/number.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
title: The "number" field
last_edited: '2024-09-11T05:28:51.869Z'
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
63 changes: 60 additions & 3 deletions content/docs/reference/types/rich-text.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: The "rich-text" field
last_edited: '2024-09-12T06:52:10.838Z'
last_edited: '2024-09-18T01:54:13.946Z'
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-tinamarkdown)
Expand Down Expand Up @@ -88,7 +88,54 @@ This is some text
<Cta heading="Welcome" />
```

## Using `TinaMarkdown`
Results in the following response from the content API:

<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;
############}
##########}
########]
######}
####}
##}
}"
preselectResponse={true}
/>

## Using `TinaMarkdown`

The `<TinaMarkdown>` component allows you to control how each element
is rendered. You *must* provide a component for each template registered
Expand Down Expand Up @@ -213,3 +260,13 @@ Then you can create a `Date` component which returns `new Date().toLocaleString(

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

## Other notes

### 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")

### Default values

If setting a default value for a rich-text field, you must provide the document AST. See [example here](/docs/schema/#default-value-for-rich-text)
Loading
Loading