import type { Color } from "@yaakapp-internal/plugins"; import type { BannerProps } from "@yaakapp-internal/ui"; import { Banner } from "@yaakapp-internal/ui"; import classNames from "classnames"; import { useEffect } from "react"; import { useKeyValue } from "../../hooks/useKeyValue"; import type { ButtonProps } from "./Button"; import { Button } from "./Button"; export function DismissibleBanner({ children, className, id, onDismiss, onShow, actions, ...props }: BannerProps & { id: string; onDismiss?: () => void | Promise; onShow?: () => void | Promise; actions?: { label: string; onClick: () => void; color?: Color; variant?: ButtonProps["variant"]; }[]; }) { const { isLoading, set: setDismissed, value: dismissed, } = useKeyValue({ namespace: "global", key: ["dismiss-banner", id], fallback: false, }); const shouldShow = !isLoading && !dismissed; useEffect(() => { if (shouldShow) { Promise.resolve(onShow?.()).catch(console.error); } }, [onShow, shouldShow]); if (!shouldShow) return null; return (
{children}
{actions?.map((a) => ( ))}
); }