| 1 | // custom-elements/pyramid.tsx |
| 2 | import { PlateElement, type PlateElementProps } from "platejs/react"; |
| 3 | |
| 4 | import { cn } from "@/lib/utils"; |
| 5 | import { type TPyramidGroupElement } from "../plugins/pyramid-plugin"; |
| 6 | import { PyramidHeightProvider } from "./pyramid-height-context"; |
| 7 | |
| 8 | export default function Pyramid( |
| 9 | props: PlateElementProps<TPyramidGroupElement>, |
| 10 | ) { |
| 11 | const { alignment = "center" } = props.element; |
| 12 | |
| 13 | return ( |
| 14 | <PlateElement {...props} className="relative"> |
| 15 | {/* Container for alignment control */} |
| 16 | <div |
| 17 | className={cn( |
| 18 | "my-4 mb-8 flex w-full", |
| 19 | // Apply alignment to the container, not the grid |
| 20 | alignment === "left" && "justify-start", |
| 21 | alignment === "right" && "justify-end", |
| 22 | alignment === "center" && "justify-center", |
| 23 | )} |
| 24 | > |
| 25 | {/* Pyramid grid - always full width */} |
| 26 | <PyramidHeightProvider> |
| 27 | <div className="grid w-full grid-flow-row auto-rows-fr overflow-visible"> |
| 28 | {props.children} |
| 29 | </div> |
| 30 | </PyramidHeightProvider> |
| 31 | </div> |
| 32 | </PlateElement> |
| 33 | ); |
| 34 | } |
| 35 |