Search for a command to run...
Use the Empty component to display an empty state.
npx shadcn@latest add @zaidan/emptypnpx shadcn add @zaidan/emptyyarn dlx shadcn@latest add @zaidan/emptybunx shadcn@latest add @zaidan/emptyCopy and paste the following code into your project.
1import { cva, type VariantProps } from "class-variance-authority";2import type { ComponentProps } from "solid-js";3import { splitProps } from "solid-js";4import { cn } from "~/lib/utils";5
6type EmptyProps = ComponentProps<"div">;7
8const Empty = (props: EmptyProps) => {9 const [local, others] = splitProps(props, ["class"]);10
11 return (12 <div13 data-slot="empty"14 class={cn(15 "z-empty flex w-full min-w-0 flex-1 flex-col items-center justify-center text-balance text-center",16 local.class,17 )}18 {...others}19 />20 );21};22
23type EmptyHeaderProps = ComponentProps<"div">;24
25const EmptyHeader = (props: EmptyHeaderProps) => {26 const [local, others] = splitProps(props, ["class"]);27
28 return (29 <div30 data-slot="empty-header"31 class={cn("z-empty-header flex max-w-sm flex-col items-center", local.class)}32 {...others}33 />34 );35};36
37const emptyMediaVariants = cva(38 "z-empty-media flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",39 {40 variants: {41 variant: {42 default: "z-empty-media-default",43 icon: "z-empty-media-icon",44 },45 },46 defaultVariants: {47 variant: "default",48 },49 },50);51
52type EmptyMediaProps = ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>;53
54const EmptyMedia = (props: EmptyMediaProps) => {55 const [local, others] = splitProps(props, ["class", "variant"]);56
57 return (58 <div59 data-slot="empty-icon"60 data-variant={local.variant}61 class={cn(emptyMediaVariants({ variant: local.variant }), local.class)}62 {...others}63 />64 );65};66
67type EmptyTitleProps = ComponentProps<"div">;68
69const EmptyTitle = (props: EmptyTitleProps) => {70 const [local, others] = splitProps(props, ["class"]);71
72 return (73 <div74 data-slot="empty-title"75 class={cn("z-empty-title z-font-heading", local.class)}76 {...others}77 />78 );79};80
81type EmptyDescriptionProps = ComponentProps<"p">;82
83const EmptyDescription = (props: EmptyDescriptionProps) => {84 const [local, others] = splitProps(props, ["class"]);85
86 return (87 <div88 data-slot="empty-description"89 class={cn(90 "z-empty-description text-muted-foreground [&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",91 local.class,92 )}93 {...others}94 />95 );96};97
98type EmptyContentProps = ComponentProps<"div">;99
100const EmptyContent = (props: EmptyContentProps) => {101 const [local, others] = splitProps(props, ["class"]);102
103 return (104 <div105 data-slot="empty-content"106 class={cn(107 "z-empty-content flex w-full min-w-0 max-w-sm flex-col items-center text-balance",108 local.class,109 )}110 {...others}111 />112 );113};114
115export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle };Here are the source code of all the examples from the preview page:
import ArrowUpRight from "lucide-solid/icons/arrow-up-right";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle,} from "~/components/ui/empty";import { Button } from "~/components/ui/button";function EmptyBasic() { return ( <Example title="Basic"> <Empty> <EmptyHeader> <EmptyTitle>No projects yet</EmptyTitle> <EmptyDescription> You haven't created any projects yet. Get started by creating your first project. </EmptyDescription> </EmptyHeader> <EmptyContent> <div class="flex gap-2"> <Button as="a" href="#"> Create project </Button> <Button variant="outline">Import project</Button> </div> <Button variant="link" as="a" href="#" class="text-muted-foreground"> Learn more <ArrowUpRight /> </Button> </EmptyContent> </Empty> </Example> );}import ArrowUpRight from "lucide-solid/icons/arrow-up-right";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle,} from "~/components/ui/empty";import { Button } from "~/components/ui/button";function EmptyWithMutedBackground() { return ( <Example title="With Muted Background"> <Empty class="bg-muted"> <EmptyHeader> <EmptyTitle>No results found</EmptyTitle> <EmptyDescription> No results found for your search. Try adjusting your search terms. </EmptyDescription> </EmptyHeader> <EmptyContent> <Button>Try again</Button> <Button variant="link" as="a" href="#" class="text-muted-foreground"> Learn more <ArrowUpRight /> </Button> </EmptyContent> </Empty> </Example> );}import CircleDashed from "lucide-solid/icons/circle-dashed";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle,} from "~/components/ui/empty";import { InputGroup, InputGroupAddon, InputGroupInput } from "~/components/ui/input-group";import { Kbd } from "~/components/ui/kbd";function EmptyWithBorder() { return ( <Example title="With Border"> <Empty class="border"> <EmptyHeader> <EmptyTitle>404 - Not Found</EmptyTitle> <EmptyDescription> The page you're looking for doesn't exist. Try searching for what you need below. </EmptyDescription> </EmptyHeader> <EmptyContent> <InputGroup class="w-3/4"> <InputGroupInput placeholder="Try searching for pages..." /> <InputGroupAddon> <CircleDashed /> </InputGroupAddon> <InputGroupAddon align="inline-end"> <Kbd>/</Kbd> </InputGroupAddon> </InputGroup> <EmptyDescription> Need help? <a href="#">Contact support</a> </EmptyDescription> </EmptyContent> </Empty> </Example> );}import Folder from "lucide-solid/icons/folder";import Plus from "lucide-solid/icons/plus";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle,} from "~/components/ui/empty";import { Button } from "~/components/ui/button";function EmptyWithIcon() { return ( <Example title="With Icon"> <Empty class="border"> <EmptyHeader> <EmptyMedia variant="icon"> <Folder /> </EmptyMedia> <EmptyTitle>Nothing to see here</EmptyTitle> <EmptyDescription> No posts have been created yet. Get started by <a href="#">creating your first post</a>. </EmptyDescription> </EmptyHeader> <EmptyContent> <Button variant="outline"> <Plus /> New Post </Button> </EmptyContent> </Empty> </Example> );}import CircleDashed from "lucide-solid/icons/circle-dashed";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle,} from "~/components/ui/empty";import { InputGroup, InputGroupAddon, InputGroupInput } from "~/components/ui/input-group";import { Kbd } from "~/components/ui/kbd";function EmptyWithMutedBackgroundAlt() { return ( <Example title="With Muted Background Alt"> <Empty class="bg-muted/50"> <EmptyHeader> <EmptyTitle>404 - Not Found</EmptyTitle> <EmptyDescription> The page you're looking for doesn't exist. Try searching for what you need below. </EmptyDescription> </EmptyHeader> <EmptyContent> <InputGroup class="w-3/4"> <InputGroupInput placeholder="Try searching for pages..." /> <InputGroupAddon> <CircleDashed /> </InputGroupAddon> <InputGroupAddon align="inline-end"> <Kbd>/</Kbd> </InputGroupAddon> </InputGroup> <EmptyDescription> Need help? <a href="#">Contact support</a> </EmptyDescription> </EmptyContent> </Empty> </Example> );}import ArrowUpRight from "lucide-solid/icons/arrow-up-right";import Folder from "lucide-solid/icons/folder";import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle,} from "~/components/ui/empty";import { Button } from "~/components/ui/button";function EmptyInCard() { return ( <Example title="In Card"> <Empty> <EmptyHeader> <EmptyMedia variant="icon"> <Folder /> </EmptyMedia> <EmptyTitle>No projects yet</EmptyTitle> <EmptyDescription> You haven't created any projects yet. Get started by creating your first project. </EmptyDescription> </EmptyHeader> <EmptyContent> <div class="flex gap-2"> <Button as="a" href="#"> Create project </Button> <Button variant="outline">Import project</Button> </div> <Button variant="link" as="a" href="#" class="text-muted-foreground"> Learn more <ArrowUpRight /> </Button> </EmptyContent> </Empty> </Example> );}