| 1 | import { SlateElement, type SlateElementProps } from "platejs/static"; |
| 2 | import { type CSSProperties } from "react"; |
| 3 | |
| 4 | import { cn } from "@/lib/utils"; |
| 5 | import { type TTimelineGroupElement } from "../../plugins/timeline-plugin"; |
| 6 | import { containerVariants, lineVariants } from "../timeline"; |
| 7 | |
| 8 | export default function TimelineStatic( |
| 9 | props: SlateElementProps<TTimelineGroupElement>, |
| 10 | ) { |
| 11 | const orientation = props.element?.orientation ?? "vertical"; |
| 12 | const sidedness = props.element?.sidedness ?? "single"; |
| 13 | const alignment = props.element?.alignment ?? "left"; |
| 14 | const showLine = props.element?.showLine ?? true; |
| 15 | const itemCount = Math.max(props.element.children.length, 1); |
| 16 | const timelineColor = |
| 17 | (props.element.color as string) || "var(--presentation-smart-layout)"; |
| 18 | const lineStyle = { |
| 19 | backgroundColor: timelineColor, |
| 20 | "--timeline-line-inset": `calc(50% / ${itemCount})`, |
| 21 | } satisfies CSSProperties & { "--timeline-line-inset": string }; |
| 22 | |
| 23 | return ( |
| 24 | <SlateElement {...props} className="relative"> |
| 25 | {showLine ? ( |
| 26 | <div |
| 27 | data-shape="rect" |
| 28 | data-shape-role="timeline-rail" |
| 29 | data-fill-color={timelineColor} |
| 30 | data-orientation={orientation} |
| 31 | className={cn(lineVariants({ orientation, sidedness, alignment }))} |
| 32 | style={lineStyle} |
| 33 | /> |
| 34 | ) : null} |
| 35 | |
| 36 | <div |
| 37 | className={cn( |
| 38 | containerVariants({ orientation, sidedness }), |
| 39 | sidedness === "single" && orientation === "horizontal" && "*:flex-1", |
| 40 | orientation === "horizontal" && sidedness === "double" && "*:flex-1", |
| 41 | )} |
| 42 | > |
| 43 | {props.children} |
| 44 | </div> |
| 45 | </SlateElement> |
| 46 | ); |
| 47 | } |
| 48 |