banner
diceui-radix/bannerFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/banner.jsonSource
1"use client";23import { cva, type VariantProps } from "class-variance-authority";4import { X } from "lucide-react";5import { Slot as SlotPrimitive } from "radix-ui";6import * as React from "react";7import * as ReactDOM from "react-dom";8import { cn } from "@/lib/utils";9import { useAsRef } from "@/registry/bases/radix/hooks/use-as-ref";10import { useLazyRef } from "@/registry/bases/radix/hooks/use-lazy-ref";11import { Button } from "@/registry/bases/radix/ui/button";1213const BANNER_ANIMATION_DURATION = 400;14const DEFAULT_BANNER_PRIORITY = 0;15const DEFAULT_BANNER_DISMISSIBLE = true;1617type BannerVariant = "default" | "info" | "success" | "warning" | "destructive";18type BannerSide = "top" | "bottom";19type BannerStrategy = "fixed" | "static" | "sticky" | "absolute";2021interface DivProps extends React.ComponentProps<"div"> {22 asChild?: boolean;23}2425type CloseElement = React.ComponentRef<typeof BannerClose>;2627interface BannerRenderProps {28 id: string;29 variant?: BannerVariant;30 dismissible: boolean;31 onClose: () => void;32 onRemove: () => void;33}3435type BannerContent =36 | React.ReactNode37 | ((props: BannerRenderProps) => React.ReactNode);3839interface BannerData {40 id: string;41 content: BannerContent;42 variant?: BannerVariant;43 priority?: number;44 duration?: number;45 dismissible?: boolean;46 onDismiss?: () => void;47}4849interface StoreState {50 banners: BannerData[];51 removing: Set<string>;52 heights: Map<string, number>;53}5455interface Store {56 subscribe: (callback: () => void) => () => void;57 getState: () => StoreState;58 notify: () => void;59 onBannerAdd: (banner: Omit<BannerData, "id">) => string;60 onBannerRemove: (id: string) => void;61 onBannersClear: () => void;62 onRemovingChange: (id: string, value: boolean) => void;63 onHeightChange: (id: string, height: number) => void;64 onHeightRemove: (id: string) => void;65}6667const StoreContext = React.createContext<Store | null>(null);6869function useStoreContext(consumerName: string) {70 const context = React.useContext(StoreContext);71 if (!context) {72 throw new Error(`\`${consumerName}\` must be used within \`Banners\``);73 }74 return context;75}7677function useStore<T>(store: Store, selector: (state: StoreState) => T): T {78 return React.useSyncExternalStore(79 store.subscribe,80 () => selector(store.getState()),81 () => selector(store.getState()),82 );83}8485interface BannerContextValue {86 id?: string;87 variant?: BannerVariant | null;88 dismissible?: boolean;89 onClose?: () => void;90}9192// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps | |
| color-pickercolor-picker | diceui/radix | Components | Free | 1 dep · 3 files |
