Skip to content

Commit

Permalink
feat: add "ui" prop to Puck to set the initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Dec 11, 2023
1 parent 22546d8 commit 71f8b2f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "react";
import { DragDropContext, DragStart, DragUpdate } from "@hello-pangea/dnd";

import type { AppState, Config, Data } from "../../types/Config";
import type { AppState, Config, Data, UiState } from "../../types/Config";
import { Button } from "../Button";

import { Plugin } from "../../types/Plugin";
Expand Down Expand Up @@ -68,6 +68,7 @@ export function Puck({
children,
config,
data: initialData = { content: [], root: { props: { title: "" } } },
ui: initialUi = defaultAppState.ui,
onChange,
onPublish,
plugins = [],
Expand All @@ -80,6 +81,7 @@ export function Puck({
children?: ReactNode;
config: Config<any, any, any>;
data: Data;
ui?: Partial<UiState>;
onChange?: (data: Data) => void;
onPublish: (data: Data) => void;
plugins?: Plugin[];
Expand Down Expand Up @@ -107,6 +109,7 @@ export function Puck({
data: initialData,
ui: {
...defaultAppState.ui,
...initialUi,
// Store categories under componentList on state to allow render functions and plugins to modify
componentList: config.categories
? Object.entries(config.categories).reduce(
Expand Down Expand Up @@ -422,7 +425,7 @@ export function Puck({
</div>
<div className={getClassName("headerTitle")}>
<Heading rank={2} size="xs">
{headerTitle || data.root.props.title || "Page"}
{headerTitle || rootProps.title || "Page"}
{headerPath && (
<>
{" "}
Expand Down

0 comments on commit 71f8b2f

Please sign in to comment.