Skip to content

Commit

Permalink
docs: add component reference docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Nov 20, 2023
1 parent bb1a76b commit 26d406c
Show file tree
Hide file tree
Showing 12 changed files with 639 additions and 85 deletions.
16 changes: 9 additions & 7 deletions apps/docs/components/Preview/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -130,12 +130,14 @@ export const ConfigPreview = ({
/>
))}
</div>
<div className={getClassNameConfigPreview("preview")}>
{componentConfig.render({
...appState.data["content"][0].props,
puck: { renderDropZone: () => <div /> },
})}
</div>
{componentConfig.render && (
<div className={getClassNameConfigPreview("preview")}>
{componentConfig.render({
...appState.data["content"][0].props,
puck: { renderDropZone: () => <div /> },
})}
</div>
)}
</div>
)}
/>
Expand Down
17 changes: 0 additions & 17 deletions apps/docs/pages/docs/api-reference/_meta.json

This file was deleted.

8 changes: 1 addition & 7 deletions apps/docs/pages/docs/api-reference/components.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Components

## DropZone

## FieldLabel

## Puck

## Render
Puck provides several components to support different integration approaches.
59 changes: 59 additions & 0 deletions apps/docs/pages/docs/api-reference/components/drop-zone.mdx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<DropZone zone="my-content" />
</div>
);
},
},
},
};
```

## 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 (
<div>
<DropZone zone="my-content" />
</div>
);
},
},
},
};
```

## Restrictions

You can't drag between DropZones that don't share a parent component.
207 changes: 207 additions & 0 deletions apps/docs/pages/docs/api-reference/components/field-label.mdx
Original file line number Diff line number Diff line change
@@ -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).

<ConfigPreview
label="Example"
componentConfig={{
fields: {
title: {
type: "custom",
render: () => {
return (
<FieldLabel label="Title">
<input style={{ border: "1px solid black", padding: 4 }} />
</FieldLabel>
);
},
},
},
defaultProps: {
title: "Hello, world",
},
}}
/>

```tsx {1,4-6} copy
import { FieldLabel } from "@measured/puck";

const CustomField = () => (
<FieldLabel label="Title">
<input />
</FieldLabel>
);

const config = {
components: {
Example: {
fields: {
title: {
type: "custom",
render: MyCustomField,
},
},
},
},
};
```

## Props

| Param | Example | Type | Status |
| ------------------------- | ---------------------- | ---------------- | -------- |
| [`label`](#label) | `label: "Title"` | String | Required |
| [`children`](#children) | `children: <div />` | ReactNode | - |
| [`className`](#classname) | `className: "MyLabel"` | String | - |
| [`el`](#el) | `el: false` | "label" \| "div" | - |
| [`icon`](#icon) | `icon: <svg />` | 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 = () => (
<FieldLabel label="Title">
<input />
</FieldLabel>
);

// ...
```

## Optional props

### `children`

A node to render inside the FieldLabel's internal `<label>` element. You can also define your input element as a sibling.

```tsx {5} copy
import { FieldLabel } from "@measured/puck";

const CustomField = () => (
<FieldLabel label="Title">
<input />
</FieldLabel>
);

// ...
```

### `className`

Define a custom class for the field label.

```tsx /className="MyClass"/ copy
import { FieldLabel } from "@measured/puck";

const CustomField = () => (
<FieldLabel className="MyClass" label="Title">
<input />
</FieldLabel>
);

// ...
```

### `el`

Specify whether to render a `label` or `div`. **Defaults to `"label"`**.

```tsx /el="div"/ copy
import { FieldLabel } from "@measured/puck";

const CustomField = () => (
<FieldLabel el="div" label="Title">
<input />
</FieldLabel>
);

// ...
```

### `icon`

Render an icon before the label text. Puck uses [react-feather](https://github.com/feathericons/react-feather) internally.

```tsx /icon={<Globe size="16" />}/ copy
import { FieldLabel } from "@measured/puck";
import { Globe } from "react-feather";

const CustomField = () => (
<FieldLabel icon={<Globe size="16" />} label="Title">
<input />
</FieldLabel>
);

// ...
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
title: {
type: "custom",
render: () => {
return (
<FieldLabel label="Title" icon={<Globe size="16" />}>
<input style={{ border: "1px solid black" }} />
</FieldLabel>
);
},
},
},
defaultProps: {
title: "Hello, world",
},
}}
/>

### `readOnly`

Indicate to the user that this field is in a read-only state by showing a padlock icon to the right of the text.

```tsx /readOnly/1 copy
import { FieldLabel } from "@measured/puck";

const CustomField = () => (
<FieldLabel label="Title" readOnly>
<input readOnly />
</FieldLabel>
);

// ...
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
title: {
type: "custom",
render: () => {
return (
<div style={{ maxWidth: "max-content" }}>
<FieldLabel label="Title" readOnly>
<input style={{ border: "1px solid black" }} readOnly />
</FieldLabel>
</div>
);
},
},
},
defaultProps: {
title: "Hello, world",
},
}}
/>
Loading

0 comments on commit 26d406c

Please sign in to comment.