Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

empty.tsx

122 lines3.8 KB

1import { cva, type VariantProps } from "class-variance-authority";
2​
3import { cn } from "~/lib/utils";
4​
5const emptySizeClassName = {
6 compact:
7 "min-h-64 gap-4 p-6 md:p-10 [&_[data-slot=empty-media]]:mb-0 [&_[data-slot=empty-title]]:text-[1.0625rem] [&_[data-slot=empty-title]]:leading-6 [&_[data-slot=empty-description]]:text-[0.8125rem] [&_[data-slot=empty-description]]:leading-[1.125rem]",
8 default: "gap-6 p-6 md:p-12",
9 hero: "gap-6 p-6 md:p-12 [&_[data-slot=empty-title]]:text-2xl sm:[&_[data-slot=empty-title]]:text-3xl",
10} as const;
11​
12function Empty({
13 className,
14 size = "default",
15 ...props
16}: React.ComponentProps<"div"> & { size?: keyof typeof emptySizeClassName }) {
17 return (
18 <div
19 className={cn(
20 "flex min-w-0 flex-1 flex-col items-center justify-center text-balance text-center",
21 emptySizeClassName[size],
22 className,
23 )}
24 data-slot="empty"
25 {...props}
26 />
27 );
29​
30function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
31 return (
32 <div
33 className={cn("flex max-w-sm flex-col items-center text-center", className)}
34 data-slot="empty-header"
35 {...props}
36 />
37 );
39​
40const emptyMediaVariants = cva(
41 "flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
42 {
43 defaultVariants: {
44 variant: "default",
45 },
46 variants: {
47 variant: {
48 default: "bg-transparent",
49 icon: "relative flex size-9 shrink-0 items-center justify-center rounded-md border bg-card not-dark:bg-clip-padding text-foreground shadow-sm/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] [&_svg:not([class*='size-'])]:size-4.5",
50 },
51 },
52 },
53);
54​
55function EmptyMedia({
56 className,
57 variant = "default",
58 ...props
59}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
60 return (
61 <div
62 className={cn("relative mb-6", className)}
63 data-slot="empty-media"
64 data-variant={variant}
65 {...props}
66 >
67 {variant === "icon" && (
68 <>
69 <div
70 aria-hidden="true"
71 className={cn(
72 emptyMediaVariants({ className, variant }),
73 "-translate-x-0.5 -rotate-10 pointer-events-none absolute bottom-px origin-bottom-left scale-84 shadow-none",
74 )}
75 />
76 <div
77 aria-hidden="true"
78 className={cn(
79 emptyMediaVariants({ className, variant }),
80 "pointer-events-none absolute bottom-px origin-bottom-right translate-x-0.5 rotate-10 scale-84 shadow-none",
81 )}
82 />
83 </>
84 )}
85 <div className={cn(emptyMediaVariants({ className, variant }))} {...props} />
86 </div>
87 );
89​
90function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
91 return (
92 <div className={cn("font-semibold text-xl", className)} data-slot="empty-title" {...props} />
93 );
95​
96function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
97 return (
98 <div
99 className={cn(
100 "text-muted-foreground text-sm [&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4 [[data-slot=empty-title]+&]:mt-1 [[data-slot=empty-description]+&]:mt-1",
101 className,
102 )}
103 data-slot="empty-description"
104 {...props}
105 />
106 );
108​
109function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
110 return (
111 <div
112 className={cn(
113 "flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-balance text-sm",
114 className,
115 )}
116 data-slot="empty-content"
117 {...props}
118 />
119 );
121​
122export { Empty, EmptyHeader, EmptyTitle, EmptyDescription, EmptyContent, EmptyMedia };