import type { ReactNode } from "react"; import { IconEye, IconEyeOff } from "@tabler/icons-react"; import { setCardHidden, useDashboardLayout } from "../utils/dashboardLayout"; import { t } from "../i18n"; /** Whether the person has hidden a dashboard card, whether they are arranging the dashboard, and so whether the card is to be drawn (hidden ones are drawn, dimmed, while arranging). */ export function useCardState(label: string): { hidden: boolean; editing: boolean; shown: boolean } { const { layout, editing } = useDashboardLayout(); const hidden = layout.hidden.includes(label); return { hidden, editing, shown: !hidden || editing }; } /** The bar above a card while the dashboard is being arranged: its name and a button to hide it or bring it back. */ export function HideBar({ label, hidden }: { label: string; hidden: boolean }) { return (
{label}
); } /** * A card at the top of the dashboard that the person can hide. Hidden, it is gone; while they arrange the dashboard (Customise) it is there, dimmed, under a bar that hides it or brings it back. * It is kept the same way as the other cards' arrangement — on their user record, so it follows them to any browser — and Reset to default shows it again. */ export default function Hideable({ label, children }: { label: string; children: ReactNode }) { const { hidden, editing, shown } = useCardState(label); if (!shown) return null; return (
{editing &&
); }