Skip to content

Commit

Permalink
feat: support inline Drawers, deprecating unnecessary props
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Nov 21, 2024
1 parent 1b9a4ba commit 081915f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
12 changes: 1 addition & 11 deletions apps/docs/pages/docs/api-reference/components/drawer-item.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function Editor() {
| Prop | Example | Type | Status |
| ----------------------- | ------------------------- | -------- | -------- |
| [`name`](#name) | `name: "Orange"` | String | Required |
| [`index`](#index) | `index: 0` | Number | Required |
| [`children`](#children) | `children: () => <div />` | Function | - |
| [`id`](#id) | `id: "OrangeComponent"` | String | - |

Expand All @@ -41,13 +40,6 @@ The name of this drawer item.
- This will be rendered on the item by default.
- Will be used as the `id`, unless otherwise specified

### `index`

A numerical index for each item in the drawer.

- Must be sequential, i.e. `0`, `1`, `2`.
- Must start at `0`.

## Optional props

### `children`
Expand All @@ -61,9 +53,7 @@ export function Editor() {
return (
<Puck>
<Drawer>
<Drawer.Item name="Orange" index={0}>
{() => <div>Orange 🍊</div>}
</Drawer.Item>
<Drawer.Item name="Orange">{() => <div>Orange 🍊</div>}</Drawer.Item>
</Drawer>
</Puck>
);
Expand Down
27 changes: 4 additions & 23 deletions apps/docs/pages/docs/api-reference/components/drawer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Puck } from "@/core/components/Puck";

# \<Drawer\>

A vertical or horizontal list of items that can be dragged into a [`<Puck.Preview>`](puck-preview). Used for composing custom Puck UIs.
A list of items that can be dragged into a [`<Puck.Preview>`](puck-preview). Used for composing custom Puck UIs.

<PuckPreview
config={{ components: { Orange: { render: () => <div>Orange</div> } } }}
Expand All @@ -35,31 +35,12 @@ export function Editor() {

## Props

| Param | Example | Type | Status |
| ----------------------------- | --------------------------- | ------------------------ | -------- |
| [`children`](#children) | `children: <Drawer.Item />` | ReactNode | Required |
| [`direction`](#direction) | `direction: "horizontal"` | `horizontal`, `vertical` | - |
| [`droppableId`](#droppableId) | `droppableId: "my-drawer"` | String | - |
| Param | Example | Type | Status |
| ----------------------- | --------------------------- | --------- | -------- |
| [`children`](#children) | `children: <Drawer.Item />` | ReactNode | Required |

## Required props

### `children`

A React node representing the contents of the `<Drawer>`. Will likely contain [`<Drawer.Item>`](drawer-item) nodes.

## Optional props

### `direction`

Set the direction of the drawer.

Defaults to `vertical`.

### `droppableId`

Set a custom ID for the underlying [Droppable](https://github.com/hello-pangea/dnd/blob/main/docs/api/droppable.md).

- Must be unique.
- Will be prefixed with `component-list:`.

Defaults to `default`.
21 changes: 21 additions & 0 deletions packages/core/components/Drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const DrawerItem = ({
children,
id,
label,
index,
isDragDisabled,
}: {
name: string;
Expand All @@ -104,6 +105,12 @@ const DrawerItem = ({
const resolvedId = id || name;
const [dynamicId, setDynamicId] = useState(generateId(resolvedId));

if (typeof index !== "undefined") {
console.error(
"Warning: The `index` prop on Drawer.Item is deprecated and no longer required."
);
}

useDragListener(
"dragend",
() => {
Expand All @@ -128,11 +135,25 @@ const DrawerItem = ({

export const Drawer = ({
children,
droppableId,
direction,
}: {
children: ReactNode;
droppableId?: string; // TODO deprecate
direction?: "vertical" | "horizontal"; // TODO deprecate
}) => {
if (droppableId) {
console.error(
"Warning: The `droppableId` prop on Drawer is deprecated and no longer required."
);
}

if (direction) {
console.error(
"Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
);
}

return <div className={getClassName()}>{children}</div>;
};

Expand Down

0 comments on commit 081915f

Please sign in to comment.