| 1 | "use client"; |
| 2 | |
| 3 | import { PlateElement, type PlateElementProps } from "platejs/react"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | import { type TStepsGroupElement } from "../plugins/steps-plugin"; |
| 7 | import { getDefaultColumnSize } from "../utils"; |
| 8 | |
| 9 | const columnSizeToColumns: Record<string, number> = { |
| 10 | sm: 4, |
| 11 | md: 3, |
| 12 | lg: 2, |
| 13 | xl: 1, |
| 14 | }; |
| 15 | |
| 16 | export default function StepsElement( |
| 17 | props: PlateElementProps<TStepsGroupElement>, |
| 18 | ) { |
| 19 | const columnSize = |
| 20 | props.element.columnSize ?? |
| 21 | getDefaultColumnSize(props.element.children.length); |
| 22 | |
| 23 | const columns = columnSizeToColumns[columnSize as string] ?? 3; |
| 24 | |
| 25 | const isVertical = columns === 1; |
| 26 | const horizontalAlignment = "items-stretch"; |
| 27 | |
| 28 | return ( |
| 29 | <PlateElement {...props} className="relative my-4"> |
| 30 | <div |
| 31 | className={cn( |
| 32 | "grid w-full", |
| 33 | isVertical ? "grid-flow-row gap-4" : `${horizontalAlignment} gap-6`, |
| 34 | )} |
| 35 | style={ |
| 36 | isVertical |
| 37 | ? { gridTemplateColumns: "1fr" } |
| 38 | : { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` } |
| 39 | } |
| 40 | > |
| 41 | {props.children} |
| 42 | </div> |
| 43 | </PlateElement> |
| 44 | ); |
| 45 | } |
| 46 |