| 1 | "use client"; |
| 2 | |
| 3 | import { useToggleButton, useToggleButtonState } from "@platejs/toggle/react"; |
| 4 | import { ChevronRight } from "lucide-react"; |
| 5 | import { PlateElement, type PlateElementProps } from "platejs/react"; |
| 6 | |
| 7 | import { Button } from "@/components/plate/ui/button"; |
| 8 | |
| 9 | export function ToggleElement(props: PlateElementProps) { |
| 10 | const element = props.element; |
| 11 | const state = useToggleButtonState(element.id as string); |
| 12 | const { buttonProps, open } = useToggleButton(state); |
| 13 | |
| 14 | return ( |
| 15 | <PlateElement {...props} className="pl-6"> |
| 16 | <Button |
| 17 | size="icon" |
| 18 | variant="ghost" |
| 19 | className="absolute top-0 -left-0.5 size-6 cursor-pointer items-center justify-center rounded-md p-px text-muted-foreground transition-colors select-none hover:bg-accent [&_svg]:size-4" |
| 20 | contentEditable={false} |
| 21 | {...buttonProps} |
| 22 | > |
| 23 | <ChevronRight |
| 24 | className={ |
| 25 | open |
| 26 | ? "rotate-90 transition-transform duration-75" |
| 27 | : "rotate-0 transition-transform duration-75" |
| 28 | } |
| 29 | /> |
| 30 | </Button> |
| 31 | {props.children} |
| 32 | </PlateElement> |
| 33 | ); |
| 34 | } |
| 35 |