import { useParams } from 'common/hooks' import { HTMLMotionProps, motion } from 'framer-motion' import { X } from 'lucide-react' import { ReactNode } from 'react' import { Button, cn } from 'ui' import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' // Base props common to all feature banners interface BaseFeatureBannerProps extends HTMLMotionProps<'div'> { children: ReactNode className?: string dismissClassName?: string defaultDismissed?: boolean illustration?: ReactNode bgAlt?: boolean } // Type for non-dismissable banners (no storageKey needed) interface NonDismissableFeatureBannerProps extends BaseFeatureBannerProps { dismissable?: false storageKey?: never } // Type for dismissable banners (requires storageKey) interface DismissableFeatureBannerProps extends BaseFeatureBannerProps { dismissable: true storageKey: string | ((ref: string) => string) } // Union type that enforces the constraint export type FeatureBannerProps = NonDismissableFeatureBannerProps | DismissableFeatureBannerProps export const FeatureBanner = ({ storageKey, children, className, dismissClassName, defaultDismissed = false, illustration, dismissable = false, bgAlt = false, ...props }: FeatureBannerProps) => { const { ref } = useParams() const key = storageKey && typeof storageKey === 'function' ? storageKey(ref ?? '') : storageKey const [isDismissed, setIsDismissed] = useLocalStorageQuery( key || 'feature-banner-dismissed', defaultDismissed ) if (dismissable && storageKey && isDismissed) return null return ( {children} {illustration} {dismissable && storageKey && (
)}
) }