import type { BorderSides, ColorInput } from "@opentui/core" import type { JSX } from "@opentui/solid" import { useTheme } from "../../context/theme" import { createContext, Show, splitProps, useContext } from "solid-js" export type Axis = "x" | "y" export type SeparatorEdge = "edge" | "edge-in" | "edge-out" export type PanelBorder = "start" | "end" | "both" | "none" const PanelGroupContext = createContext<{ axis: Axis }>() function crossAxis(axis: Axis) { return axis === "x" ? "y" : "x" } function usePanelGroup() { return useContext(PanelGroupContext) } export function PanelGroup(props: JSX.IntrinsicElements["box"] & { axis: Axis }) { const [local, boxProps] = splitProps(props, ["axis", "children"]) return ( {local.children} ) } export function Panel(props: Omit & { border?: PanelBorder }) { const group = usePanelGroup() const { theme } = useTheme() const [local, boxProps] = splitProps(props, ["border"]) const border = local.border ?? "start" const borderProps = border === "none" ? {} : { border: panelBorderSides(group?.axis ?? "y", border), borderColor: theme.border, } return ( ) } function panelBorderSides(axis: Axis, border: Exclude): BorderSides[] { if (axis === "x") return border === "both" ? ["top", "bottom"] : [border === "start" ? "top" : "bottom"] return border === "both" ? ["left", "right"] : [border === "start" ? "left" : "right"] } export function Separator(props: { axis?: Axis; color?: ColorInput; start?: SeparatorEdge; end?: SeparatorEdge }) { const group = usePanelGroup() const { theme } = useTheme() const color = () => props.color ?? theme.border const axis = () => props.axis ?? crossAxis(group?.axis ?? "y") if (axis() === "y") { return ( } > {(edge) => {verticalEdge(edge(), "start")}} {(edge) => {verticalEdge(edge(), "end")}} ) } return ( } > {(edge) => {horizontalEdge(edge(), "start")}} {(edge) => {horizontalEdge(edge(), "end")}} ) } function horizontalEdge(edge: SeparatorEdge, side: "start" | "end") { if (edge === "edge") return side === "start" ? "├" : "┤" if (edge === "edge-in") return "┴" return "┬" } function verticalEdge(edge: SeparatorEdge, side: "start" | "end") { if (edge === "edge") return side === "start" ? "┬" : "┴" if (edge === "edge-in") return "┤" return "├" }