| 1 | import { NodeApi, PathApi } from "platejs"; |
| 2 | import { SlateElement, type SlateElementProps } from "platejs/static"; |
| 3 | import { useRef } from "react"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | import { |
| 7 | type TArrowListElement, |
| 8 | type TArrowListItemElement, |
| 9 | } from "../../plugins/arrow-plugin"; |
| 10 | import { getAlignmentClasses } from "../../utils"; |
| 11 | import { ArrowChevron } from "../arrow-item"; |
| 12 | |
| 13 | export function ArrowItemStatic( |
| 14 | props: SlateElementProps<TArrowListItemElement>, |
| 15 | ) { |
| 16 | const path = props.editor.api.findPath(props.element) ?? [-1]; |
| 17 | const parentPath = PathApi.parent(path); |
| 18 | const parentElement = NodeApi.get(props.editor, parentPath); |
| 19 | const { orientation, svgType, showIcon } = parentElement as TArrowListElement; |
| 20 | const isHorizontal = orientation === "horizontal"; |
| 21 | const { icon } = props.element as unknown as { icon?: string }; |
| 22 | |
| 23 | // Get alignment - use item alignment if set, otherwise inherit from parent |
| 24 | const itemAlignment = props.element.alignment; |
| 25 | const parentAlignment = (parentElement as TArrowListElement)?.alignment; |
| 26 | const alignment = itemAlignment ?? parentAlignment ?? "left"; |
| 27 | |
| 28 | const contentRef = useRef<HTMLDivElement | null>(null); |
| 29 | return ( |
| 30 | <div |
| 31 | className={cn( |
| 32 | "group/arrow-item relative mb-2 flex w-full max-w-full min-w-0 gap-6 pl-4", |
| 33 | isHorizontal && "flex-col gap-3 pl-0", |
| 34 | !isHorizontal && "items-start", |
| 35 | alignment === "right" && !isHorizontal && "pr-4 pl-0 flex-row-reverse", |
| 36 | alignment === "center" && "justify-center", |
| 37 | )} |
| 38 | > |
| 39 | {/* Chevron icon column */} |
| 40 | <div |
| 41 | className={cn( |
| 42 | "relative grid shrink-0", |
| 43 | isHorizontal ? "h-24 w-full" : "h-full w-24", |
| 44 | )} |
| 45 | > |
| 46 | <ArrowChevron |
| 47 | className={cn( |
| 48 | "relative z-50 block overflow-visible", |
| 49 | isHorizontal ? "top-0 left-0" : "top-0", |
| 50 | )} |
| 51 | isHorizontal={isHorizontal} |
| 52 | sizeTargetRef={contentRef} |
| 53 | svgType={svgType} |
| 54 | color={ |
| 55 | (parentElement?.color as string) || |
| 56 | "var(--presentation-smart-layout, var(--presentation-primary))" |
| 57 | } |
| 58 | icon={icon} |
| 59 | showIcon={!!showIcon} |
| 60 | disabled={true} |
| 61 | /> |
| 62 | </div> |
| 63 | |
| 64 | {/* Content column */} |
| 65 | <div |
| 66 | ref={contentRef} |
| 67 | className={cn("grid min-w-0 flex-1", !isHorizontal && "self-start")} |
| 68 | > |
| 69 | <SlateElement |
| 70 | {...props} |
| 71 | className={cn("min-w-0 w-full", getAlignmentClasses(alignment))} |
| 72 | > |
| 73 | {props.children} |
| 74 | </SlateElement> |
| 75 | </div> |
| 76 | </div> |
| 77 | ); |
| 78 | } |
| 79 |