From 26d406c05baf47c581614b4e065310f37b85fc15 Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Thu, 16 Nov 2023 12:11:15 +0000 Subject: [PATCH] docs: add component reference docs --- apps/docs/components/Preview/index.tsx | 16 +- apps/docs/pages/docs/api-reference/_meta.json | 17 -- .../pages/docs/api-reference/components.mdx | 8 +- .../api-reference/components/drop-zone.mdx | 59 ++++ .../api-reference/components/field-label.mdx | 207 ++++++++++++++ .../docs/api-reference/components/puck.mdx | 252 ++++++++++++++++++ .../docs/api-reference/components/render.mdx | 71 +++++ apps/docs/pages/docs/api-reference/fields.mdx | 3 + .../pages/docs/api-reference/fields/array.mdx | 6 +- .../docs/api-reference/fields/custom.mdx | 71 +++-- apps/docs/pages/docs/getting-started.mdx | 12 +- .../pages/docs/integrating-puck/_meta.json | 2 +- 12 files changed, 639 insertions(+), 85 deletions(-) delete mode 100644 apps/docs/pages/docs/api-reference/_meta.json create mode 100644 apps/docs/pages/docs/api-reference/components/drop-zone.mdx create mode 100644 apps/docs/pages/docs/api-reference/components/field-label.mdx create mode 100644 apps/docs/pages/docs/api-reference/components/puck.mdx create mode 100644 apps/docs/pages/docs/api-reference/components/render.mdx create mode 100644 apps/docs/pages/docs/api-reference/fields.mdx diff --git a/apps/docs/components/Preview/index.tsx b/apps/docs/components/Preview/index.tsx index 181a13f68e..55bdc3d8be 100644 --- a/apps/docs/components/Preview/index.tsx +++ b/apps/docs/components/Preview/index.tsx @@ -1,7 +1,7 @@ export { InputOrGroup } from "@/core/components/InputOrGroup"; import { ReactNode, useReducer, useState } from "react"; -import "@/core/styles/global.css"; +import "@/core/styles.css"; import { AppProvider, defaultAppState } from "@/core/components/Puck/context"; import { PuckAction, createReducer } from "@/core/reducer"; import { InputOrGroup } from "@/core/components/InputOrGroup"; @@ -130,12 +130,14 @@ export const ConfigPreview = ({ /> ))} -
- {componentConfig.render({ - ...appState.data["content"][0].props, - puck: { renderDropZone: () =>
}, - })} -
+ {componentConfig.render && ( +
+ {componentConfig.render({ + ...appState.data["content"][0].props, + puck: { renderDropZone: () =>
}, + })} +
+ )}
)} /> diff --git a/apps/docs/pages/docs/api-reference/_meta.json b/apps/docs/pages/docs/api-reference/_meta.json deleted file mode 100644 index b19b727dc9..0000000000 --- a/apps/docs/pages/docs/api-reference/_meta.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "components": { - "title": "Components" - }, - "config": { - "title": "Config" - }, - "data": { - "title": "Data" - }, - "fields": { - "title": "Fields" - }, - "functions": { - "title": "Functions" - } -} diff --git a/apps/docs/pages/docs/api-reference/components.mdx b/apps/docs/pages/docs/api-reference/components.mdx index ce45c8b459..c4bbd1d54e 100644 --- a/apps/docs/pages/docs/api-reference/components.mdx +++ b/apps/docs/pages/docs/api-reference/components.mdx @@ -1,9 +1,3 @@ # Components -## DropZone - -## FieldLabel - -## Puck - -## Render +Puck provides several components to support different integration approaches. diff --git a/apps/docs/pages/docs/api-reference/components/drop-zone.mdx b/apps/docs/pages/docs/api-reference/components/drop-zone.mdx new file mode 100644 index 0000000000..6f2e10f665 --- /dev/null +++ b/apps/docs/pages/docs/api-reference/components/drop-zone.mdx @@ -0,0 +1,59 @@ +--- +title: DropZone +--- + +# DropZone + +Place droppable regions (zones) inside other components to enable nested components. + +```tsx {1,9} copy +import { DropZone } from "@measured/puck"; + +const config = { + components: { + Example: { + render: () => { + return ( +
+ +
+ ); + }, + }, + }, +}; +``` + +## Props + +| Param | Example | Type | Status | +| --------------- | ----------------- | ------ | -------- | +| [`zone`](#zone) | `zone: "my-zone"` | String | Required | + +## Required props + +### `zone` + +Set the zone identifier for the given DropZone. + +Must be unique within this component, but two different components can both define DropZones with the same `zone` value. + +```tsx /zone="my-content"/ copy +const config = { + components: { + Example: { + render: () => { + return ( +
+ +
+ ); + }, + }, + }, +}; +``` + +## Restrictions + +You can't drag between DropZones that don't share a parent component. diff --git a/apps/docs/pages/docs/api-reference/components/field-label.mdx b/apps/docs/pages/docs/api-reference/components/field-label.mdx new file mode 100644 index 0000000000..f491c8c1f2 --- /dev/null +++ b/apps/docs/pages/docs/api-reference/components/field-label.mdx @@ -0,0 +1,207 @@ +import { ConfigPreview } from "../../../../components/Preview"; +import { FieldLabel } from "@/core/components/InputOrGroup"; +import { Globe } from "react-feather"; + +# FieldLabel + +Render a styled `label` when creating [`custom` fields](/docs/api-reference/fields/custom). + + { + return ( + + + + ); + }, + }, + }, + defaultProps: { + title: "Hello, world", + }, + }} +/> + +```tsx {1,4-6} copy +import { FieldLabel } from "@measured/puck"; + +const CustomField = () => ( + + + +); + +const config = { + components: { + Example: { + fields: { + title: { + type: "custom", + render: MyCustomField, + }, + }, + }, + }, +}; +``` + +## Props + +| Param | Example | Type | Status | +| ------------------------- | ---------------------- | ---------------- | -------- | +| [`label`](#label) | `label: "Title"` | String | Required | +| [`children`](#children) | `children:
` | ReactNode | - | +| [`className`](#classname) | `className: "MyLabel"` | String | - | +| [`el`](#el) | `el: false` | "label" \| "div" | - | +| [`icon`](#icon) | `icon: ` | ReactNode | - | +| [`readOnly`](#readonly) | `readOnly: false` | Boolean | - | + +## Required props + +### `label` + +The label string for the fields. + +```tsx /label="Title"/ copy +import { FieldLabel } from "@measured/puck"; + +const CustomField = () => ( + + + +); + +// ... +``` + +## Optional props + +### `children` + +A node to render inside the FieldLabel's internal `