Skip to content

Commit 71f8b2f

Browse files
committed
feat: add "ui" prop to Puck to set the initial state
1 parent 22546d8 commit 71f8b2f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/core/components/Puck/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "react";
99
import { DragDropContext, DragStart, DragUpdate } from "@hello-pangea/dnd";
1010

11-
import type { AppState, Config, Data } from "../../types/Config";
11+
import type { AppState, Config, Data, UiState } from "../../types/Config";
1212
import { Button } from "../Button";
1313

1414
import { Plugin } from "../../types/Plugin";
@@ -68,6 +68,7 @@ export function Puck({
6868
children,
6969
config,
7070
data: initialData = { content: [], root: { props: { title: "" } } },
71+
ui: initialUi = defaultAppState.ui,
7172
onChange,
7273
onPublish,
7374
plugins = [],
@@ -80,6 +81,7 @@ export function Puck({
8081
children?: ReactNode;
8182
config: Config<any, any, any>;
8283
data: Data;
84+
ui?: Partial<UiState>;
8385
onChange?: (data: Data) => void;
8486
onPublish: (data: Data) => void;
8587
plugins?: Plugin[];
@@ -107,6 +109,7 @@ export function Puck({
107109
data: initialData,
108110
ui: {
109111
...defaultAppState.ui,
112+
...initialUi,
110113
// Store categories under componentList on state to allow render functions and plugins to modify
111114
componentList: config.categories
112115
? Object.entries(config.categories).reduce(
@@ -422,7 +425,7 @@ export function Puck({
422425
</div>
423426
<div className={getClassName("headerTitle")}>
424427
<Heading rank={2} size="xs">
425-
{headerTitle || data.root.props.title || "Page"}
428+
{headerTitle || rootProps.title || "Page"}
426429
{headerPath && (
427430
<>
428431
{" "}

0 commit comments

Comments
 (0)