Empty states
blok/empty-statesFreeComponent
Displays empty state variants for no search results, nothing created, and error scenarios.
Install it
npx shadcn@latest add https://blok.sitecore.com/r/empty-states.jsonSource
1import { Button } from "@/components/ui/button";2import { cn } from "@/lib/utils";3import { type VariantProps, cva } from "class-variance-authority";4import type * as React from "react";56const emptyStatesVariants = cva("flex items-center justify-center h-full", {7 variants: {8 variant: {9 "no-search-results": "",10 "nothing-created": "",11 error: "",12 },13 },14 defaultVariants: {15 variant: "no-search-results",16 },17});1819interface EmptyStatesProps20 extends React.ComponentProps<"div">,21 VariantProps<typeof emptyStatesVariants> {22 title?: string;23 description?: string;24 imageSrc?: string;25 imageAlt?: string;26 actions?: React.ReactNode;27}2829const emptyStateConfig = {30 "no-search-results": {31 imageSrc:32 "https://delivery-sitecore.sitecorecontenthub.cloud/api/public/content/spot-magnify-close-neutral",33 imageAlt: "magnifier icon",34 defaultTitle: "No search results",35 defaultDescription: "Try a different search query.",36 },37 "nothing-created": {38 imageSrc:39 "https://delivery-sitecore.sitecorecontenthub.cloud/api/public/content/spot-cactus-neutral",40 imageAlt: "desert icon",41 defaultTitle: "No widgets yet",42 defaultDescription: undefined,43 },44 error: {45 imageSrc:46 "https://delivery-sitecore.sitecorecontenthub.cloud/api/public/content/spot-alert-circle",47 imageAlt: "alert icon",48 defaultTitle: "Something went wrong",49 defaultDescription: "Description of the error.",50 },51};5253function EmptyStates({54 className,55 variant = "no-search-results",56 title,57 description,58 imageSrc,59 imageAlt,60 actions,61 ...props62}: EmptyStatesProps) {63 const config = emptyStateConfig[variant || "no-search-results"];64 const finalTitle = title || config.defaultTitle;65 const finalDescription = description || config.defaultDescription;66 const finalImageSrc = imageSrc || config.imageSrc;67 const finalImageAlt = imageAlt || config.imageAlt;6869 const defaultActions = {70 "no-search-results": <Button variant="link">Reset search</Button>,71 "nothing-created": <Button variant="default">Create widget</Button>,72 error: <Button variant="link">Try again</Button>,73 };7475 const finalActions =76 actions || defaultActions[variant || "no-search-results"];7778 return (79 <div80 data-slot="empty-states"81 className={cn(emptyStatesVariants({ variant }), className)}82 {...props}83 >84 <div className="flex flex-col items-center text-center gap-4 max-w-sm">85// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from blok
All 72 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | blok | Components | Free | 2 deps · 2 files | |
| Action baraction-bar | blok | Components | Free | 1 dep · 2 files | |
| Alertalert | blok | Components | Free | 2 deps · 2 files | |
| Alert dialogalert-dialog | blok | Components | Free | 2 deps | |
| Aspect ratioaspect-ratio | blok | Components | Free | 1 dep | |
| Avataravatar | blok | Components | Free | 1 dep | |
| Badgebadge | blok | Components | Free | 2 deps | |
| All componentsblok-components | blok | Components | Free | no deps |
