banner
kibo-ui-registry/bannerFreeComponent
A banner is a full-width component that can be used to show a message and action to the user.
Live preview
live · rendered by the registry
Rendered by Kibo UI Registry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.kibo-ui.com/r/banner.jsonSource
1"use client";23import { useControllableState } from "@radix-ui/react-use-controllable-state";4import { type LucideIcon, XIcon } from "lucide-react";5import {6 type ComponentProps,7 createContext,8 type HTMLAttributes,9 type MouseEventHandler,10 useContext,11} from "react";12import { Button } from "@/components/ui/button";13import { cn } from "@/lib/utils";1415type BannerContextProps = {16 show: boolean;17 setShow: (show: boolean) => void;18};1920export const BannerContext = createContext<BannerContextProps>({21 show: true,22 setShow: () => {},23});2425export type BannerProps = HTMLAttributes<HTMLDivElement> & {26 visible?: boolean;27 defaultVisible?: boolean;28 onClose?: () => void;29 inset?: boolean;30};3132export const Banner = ({33 children,34 visible,35 defaultVisible = true,36 onClose,37 className,38 inset = false,39 ...props40}: BannerProps) => {41 const [show, setShow] = useControllableState({42 defaultProp: defaultVisible,43 prop: visible,44 onChange: onClose,45 });4647 if (!show) {48 return null;49 }5051 return (52 <BannerContext.Provider value={{ show, setShow }}>53 <div54 className={cn(55 "flex w-full items-center justify-between gap-2 bg-primary px-4 py-2 text-primary-foreground",56 inset && "rounded-lg",57 className58 )}59 {...props}60 >61 {children}62 </div>63 </BannerContext.Provider>64 );65};6667export type BannerIconProps = HTMLAttributes<HTMLDivElement> & {68 icon: LucideIcon;69};7071export const BannerIcon = ({72 icon: Icon,73 className,74 ...props75}: BannerIconProps) => (76 <div77 className={cn(78 "rounded-full border border-background/20 bg-background/10 p-1 shadow-sm",79 className80 )}81 {...props}82 >83 <Icon size={16} />84 </div>85);8687export type BannerTitleProps = HTMLAttributes<HTMLParagraphElement>;8889export const BannerTitle = ({ className, ...props }: BannerTitleProps) => (90 <p className={cn("flex-1 text-sm", className)} {...props} />91);9293export type BannerActionProps = ComponentProps<typeof Button>;9495export const BannerAction = ({96 variant = "outline",97 size = "sm",98 className,99 ...props100}: BannerActionProps) => (101 <Button102 className={cn(103 "shrink-0 bg-transparent hover:bg-background/10 hover:text-background",104 className105 )}106 size={size}107 variant={variant}108 {...props}109 />110);111112export type BannerCloseProps = ComponentProps<typeof Button>;113114export const BannerClose = ({115 variant = "ghost",116 size = "icon",117 onClick,118 className,119// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Kibo UI Registry
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| announcementannouncement | Kibo UI Registry | Components | Free | no deps | |
| avatar-stackavatar-stack | Kibo UI Registry | Components | Free | no deps | |
| calendarcalendar | Kibo UI Registry | Components | Free | 3 deps | |
| choiceboxchoicebox | Kibo UI Registry | Components | Free | 2 deps | |
| code-blockcode-block | Kibo UI Registry | Components | Free | 5 deps · 2 files | |
| color-pickercolor-picker | Kibo UI Registry | Components | Free | 3 deps | |
| comboboxcombobox | Kibo UI Registry | Components | Free | 2 deps | |
| comparisoncomparison | Kibo UI Registry | Components | Free | 2 deps |
