diff --git a/components/Layout.tsx b/components/Layout.tsx new file mode 100644 index 00000000..5d002ba1 --- /dev/null +++ b/components/Layout.tsx @@ -0,0 +1,6 @@ +import { useContext } from "preact/hooks"; +import { createContext } from "preact"; + +export const LayoutContext = createContext({ isPreview: false }); + +export const useLayoutContext = () => useContext(LayoutContext); diff --git a/sections/Gallery.tsx b/sections/Gallery.tsx index 943586eb..2df82d5b 100644 --- a/sections/Gallery.tsx +++ b/sections/Gallery.tsx @@ -1,10 +1,11 @@ import { Section } from "deco/blocks/section.ts"; +import { LayoutContext } from "$store/components/Layout.tsx"; interface Props { children: Section; } -function Gallery({ children: { Component, props } }: Props) { +function Section({ children: { Component, props } }: Props) { return ( <> @@ -12,4 +13,12 @@ function Gallery({ children: { Component, props } }: Props) { ); } -export default Gallery; +export function Preview(props: Props) { + return ( + +
+ + ); +} + +export default Section; diff --git a/sections/Layout/Container.tsx b/sections/Layout/Container.tsx index b9bcbc06..9899acd1 100644 --- a/sections/Layout/Container.tsx +++ b/sections/Layout/Container.tsx @@ -1,11 +1,32 @@ import { Section } from "deco/blocks/section.ts"; +import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx"; interface Props { children?: Section; } -function Container({ children }: Props) { - if (!children) return null; +function Placeholder() { + return ( +
+ Content +
+ ); +} + +function Section({ children }: Props) { + const { isPreview } = useLayoutContext(); + + if (isPreview && typeof children?.Component !== "function") { + return ( +
+
+
+ ); + } + + if (!children) { + return null; + } return (
@@ -15,25 +36,11 @@ function Container({ children }: Props) { } export function Preview(props: Props) { - if (props.children) { - return ; - } - return ( -
- ( -
- Content -
- ), - props: {}, - }} - /> -
+ +
+ ); } -export default Container; +export default Section; diff --git a/sections/Layout/Flex.tsx b/sections/Layout/Flex.tsx index 6ccfc8a6..988efabd 100644 --- a/sections/Layout/Flex.tsx +++ b/sections/Layout/Flex.tsx @@ -1,3 +1,4 @@ +import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx"; import { clx } from "$store/sdk/clx.ts"; import { Section } from "deco/blocks/section.ts"; import { flex, VNode } from "../../constants.tsx"; @@ -33,6 +34,11 @@ interface Props { } function Section({ layout, children }: Props) { + const { isPreview } = useLayoutContext(); + const items = isPreview && !children?.length + ? new Array(4).fill(0).map(() => ) + : children; + return (
- {children?.length - ? children - : new Array(4).fill(0).map(() => )} + {items}
); } +export function Preview(props: Props) { + return ( + +
+ + ); +} + const ItemPreview = () => (
diff --git a/sections/Layout/Grid.tsx b/sections/Layout/Grid.tsx index 2ede29b6..bc12b65e 100644 --- a/sections/Layout/Grid.tsx +++ b/sections/Layout/Grid.tsx @@ -1,6 +1,7 @@ import { Section } from "deco/blocks/section.ts"; import { grid, VNode } from "../../constants.tsx"; import { clx } from "../../sdk/clx.ts"; +import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx"; interface Props { children?: VNode[] | null; @@ -65,6 +66,11 @@ interface Props { } function Section({ layout, children }: Props) { + const { isPreview } = useLayoutContext(); + const items = isPreview && !children?.length + ? new Array(12).fill(0).map(() => ) + : children; + return (
- {children?.length - ? children - : new Array(12).fill(0).map(() => )} + {items}
); } +export function Preview(props: Props) { + return ( + +
+ + ); +} + const ItemPreview = () => (