diff --git a/apps/demo/app/custom-ui/[...puckPath]/client.tsx b/apps/demo/app/custom-ui/[...puckPath]/client.tsx index 9bb5b198e..9c5a89ca2 100644 --- a/apps/demo/app/custom-ui/[...puckPath]/client.tsx +++ b/apps/demo/app/custom-ui/[...puckPath]/client.tsx @@ -1,13 +1,13 @@ "use client"; -import { Button, Data, Puck, Render } from "@/core"; +import { ActionBar, Button, Data, Puck, Render } from "@/core"; import { HeadingAnalyzer } from "@/plugin-heading-analyzer/src/HeadingAnalyzer"; import config, { UserConfig } from "../../../config"; import { useDemoData } from "../../../lib/use-demo-data"; import { IconButton, usePuck } from "@/core"; import { ReactNode, useEffect, useRef, useState } from "react"; import { Drawer } from "@/core/components/Drawer"; -import { ChevronUp, ChevronDown, Globe } from "lucide-react"; +import { ChevronUp, ChevronDown, Globe, Bug } from "lucide-react"; const CustomHeader = ({ onPublish }: { onPublish: (data: Data) => void }) => { const { appState, dispatch } = usePuck(); @@ -276,6 +276,26 @@ const CustomPuck = ({ dataKey }: { dataKey: string }) => { ); }; +const CustomActionBar = ({ children, label }) => { + const { appState, selectedItem } = usePuck(); + + const onClick = () => { + alert( + `Index: ${appState.ui.itemSelector.index} \nZone: ${ + appState.ui.itemSelector.zone + } \nData: ${JSON.stringify(selectedItem)}` + ); + }; + return ( + + + + + {children} + + ); +}; + export function Client({ path, isEdit }: { path: string; isEdit: boolean }) { const { data, resolvedData, key } = useDemoData({ path, @@ -293,6 +313,9 @@ export function Client({ path, isEdit }: { path: string; isEdit: boolean }) { outline: ({ children }) => (
{children}
), + actionBar: ({ children, label }) => ( + {children} + ), components: () => { return ( diff --git a/packages/core/components/ActionBar/index.tsx b/packages/core/components/ActionBar/index.tsx index 9b040fef0..338b67143 100644 --- a/packages/core/components/ActionBar/index.tsx +++ b/packages/core/components/ActionBar/index.tsx @@ -18,12 +18,14 @@ export const ActionBar = ({ export const Action = ({ children, + label, onClick, }: { children: ReactNode; + label?: string; onClick: (e: SyntheticEvent) => void; }) => ( - ); diff --git a/packages/core/components/DraggableComponent/index.tsx b/packages/core/components/DraggableComponent/index.tsx index a88a46f32..1d71a76a9 100644 --- a/packages/core/components/DraggableComponent/index.tsx +++ b/packages/core/components/DraggableComponent/index.tsx @@ -3,6 +3,7 @@ import { ReactNode, SyntheticEvent, useEffect, + useMemo, useState, } from "react"; import { Draggable } from "@measured/dnd"; @@ -15,6 +16,8 @@ import { useAppContext } from "../Puck/context"; import { DefaultDraggable } from "../Draggable"; import { Loader } from "../Loader"; import { ActionBar } from "../ActionBar"; +import { DefaultOverride } from "../DefaultOverride"; +import { useLoadedOverrides } from "../../lib/use-loaded-overrides"; const getClassName = getClassNameFactory("DraggableComponent", styles); @@ -24,6 +27,18 @@ const actionsOverlayTop = space * 6.5; const actionsTop = -(actionsOverlayTop - 8); const actionsRight = space; +const DefaultActionBar = ({ + label, + children, +}: { + label: string | undefined; + children: ReactNode; +}) => ( + + {children} + +); + export const DraggableComponent = ({ children, id, @@ -67,11 +82,9 @@ export const DraggableComponent = ({ indicativeHover?: boolean; style?: CSSProperties; }) => { - const { zoomConfig } = useAppContext(); + const { zoomConfig, status, overrides, plugins } = useAppContext(); const isModifierHeld = useModifierHeld("Alt"); - const { status } = useAppContext(); - const El = status !== "LOADING" ? Draggable : DefaultDraggable; useEffect(onMount, []); @@ -86,6 +99,16 @@ export const DraggableComponent = ({ } }, []); + const loadedOverrides = useLoadedOverrides({ + overrides: overrides, + plugins: plugins, + }); + + const CustomActionBar = useMemo( + () => loadedOverrides.actionBar || DefaultActionBar, + [loadedOverrides] + ); + return ( )} - -
+ {isSelected && (
- - - - - - - - +
+ + + + + + + + +
-
+ )} +
{children}
diff --git a/packages/core/types/Overrides.ts b/packages/core/types/Overrides.ts index 34ec94220..efe452a75 100644 --- a/packages/core/types/Overrides.ts +++ b/packages/core/types/Overrides.ts @@ -27,6 +27,10 @@ type OverridesGeneric = Shape; export type Overrides = OverridesGeneric<{ fieldTypes: Partial; header: RenderFunc<{ actions: ReactNode; children: ReactNode }>; + actionBar: RenderFunc<{ + label?: string; + children: ReactNode; + }>; headerActions: RenderFunc<{ children: ReactNode }>; preview: RenderFunc; fields: RenderFunc<{