import dynamic from "next/dynamic"; import { ActionIcon, Badge, Box, Button, Card } from "@mantine/core"; import { IconChevronDown, IconChevronUp, IconExternalLink } from "@tabler/icons-react"; import combineClasses from "clsx"; import { useRequiredBoard } from "@homarr/boards/context"; import { useEditMode } from "@homarr/boards/edit-mode"; import { useI18n } from "@homarr/translation/client"; import type { ContainerSectionItem } from "~/app/[locale]/boards/_types"; import { COLLAPSED_SECTION_ROW_COUNT } from "~/components/board/layout"; import { SectionGrid } from "./grid/section-grid"; import { useSectionCollapse } from "./section-collapse"; import { useSectionContext } from "./section-context"; import { useOpenSectionApps } from "./use-open-section-apps"; import classes from "./item.module.css"; const BoardContainerMenu = dynamic( () => import("./container/container-menu").then((module) => module.BoardContainerMenu), { ssr: false }, ); interface Props { section: ContainerSectionItem; } export const BoardContainerSection = ({ section }: Props) => { const board = useRequiredBoard(); const { section: parentSection } = useSectionContext(); const [isEditMode] = useEditMode(); const t = useI18n("section.container"); const tSection = useI18n("section"); const options = section.options; const { open: openAllInNewTabs, isLoading: areAppsLoading } = useOpenSectionApps( section.id, options.showOpenAll && !isEditMode, ); const { isVisuallyCollapsed, toggle } = useSectionCollapse({ sectionId: section.id, collapsible: options.collapsible, }); const label = options.title.trim() || t("untitled"); const contentId = `board-container-${section.id}-content`; let labelLeft = 8; let labelRight = 8; if (isEditMode) { // Match the root/nested menu offsets in BoardContainerMenu, plus its width and gap. labelLeft = 36; if (parentSection.kind === "container") labelLeft = 68; } else if (options.showOpenAll) { labelRight = 40; } // Expanded controls sit on the border like the ordinary label, without reserving a header row. const toggleLayout = isVisuallyCollapsed ? { top: 0, left: 0, w: "100%", h: "100%", maw: "100%" } : { top: "calc(var(--mantine-spacing-xs) * -1)", left: labelLeft, w: "auto", h: 20, maw: `calc(100% - ${labelLeft + labelRight}px)`, }; const toggleIcon = isVisuallyCollapsed ? : ; return ( {options.collapsible && ( )} {!isVisuallyCollapsed && !options.collapsible && options.showLabel && options.title && ( {options.title} )} {options.showOpenAll && !isEditMode && ( )} {isEditMode && } ); };