Actions
Close Button
Dismiss control for dialogs, toasts, tags and banners — ghost or filled, three sizes.
react-aria-componentslucide-react
Preview
"use client";
import { CloseButton } from "@/components/ui/close-button";
export default function Example() {
return (
<div className="flex items-center gap-4">
<CloseButton size="sm" />
<CloseButton size="md" />
<CloseButton size="lg" />
<CloseButton size="sm" variant="filled" />
<CloseButton size="md" variant="filled" />
<CloseButton size="lg" variant="filled" />
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
close-button.tsxfile and paste the following code into it.src/components/ui/close-button.tsx"use client"; import { X } from "lucide-react"; import { Button as AriaButton, type ButtonProps as AriaButtonProps } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface CloseButtonProps extends Omit<AriaButtonProps, "className" | "children"> { size?: "sm" | "md" | "lg"; /** `ghost` is transparent until hovered; `filled` sits on a muted circle. */ variant?: "ghost" | "filled"; "aria-label"?: string; className?: string; } const sizes = { sm: "size-5 [&_svg]:size-3", md: "size-7 [&_svg]:size-3.5", lg: "size-8 [&_svg]:size-4" }; /** Dismiss control for dialogs, toasts, tags and banners. */ export function CloseButton({ size = "md", variant = "ghost", className, ...props }: CloseButtonProps) { return ( <AriaButton aria-label="Close" {...props} className={cx( "inline-flex shrink-0 cursor-default items-center justify-center text-fg-muted outline-none transition-colors data-focus-visible:shadow-focus data-disabled:text-fg-disabled", variant === "ghost" ? "rounded-sm data-hovered:bg-muted data-hovered:text-fg" : "rounded-full bg-muted data-hovered:bg-active data-hovered:text-fg", sizes[size], className, )} > <X strokeWidth={2} /> </AriaButton> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.