Raw
1 import { ExclamationCircle, MagnifyingGlass, PlusMini } from "@medusajs/icons"
2 import { Button, Text, clx } from "@medusajs/ui"
3 import React from "react"
4 import { useTranslation } from "react-i18next"
5 import { Link } from "react-router-dom"
6
7 export type NoResultsProps = {
8 title?: string
9 message?: string
10 className?: string
11 }
12
13 export const NoResults = ({ title, message, className }: NoResultsProps) => {
14 const { t } = useTranslation()
15
16 return (
17 <div
18 className={clx(
19 "flex h-[400px] w-full items-center justify-center",
20 className
21 )}
22 >
23 <div className="flex flex-col items-center gap-y-2">
24 <MagnifyingGlass />
25 <Text size="small" leading="compact" weight="plus">
26 {title ?? t("general.noResultsTitle")}
27 </Text>
28 <Text size="small" className="text-ui-fg-subtle">
29 {message ?? t("general.noResultsMessage")}
30 </Text>
31 </div>
32 </div>
33 )
34 }
35
36 type ActionProps = {
37 action?: {
38 to: string
39 label: string
40 }
41 }
42
43 type NoRecordsProps = {
44 title?: string
45 message?: string
46 className?: string
47 buttonVariant?: string
48 icon?: React.ReactNode
49 } & ActionProps
50
51 const DefaultButton = ({ action }: ActionProps) =>
52 action && (
53 <Link to={action.to}>
54 <Button variant="secondary" size="small">
55 {action.label}
56 </Button>
57 </Link>
58 )
59
60 const TransparentIconLeftButton = ({ action }: ActionProps) =>
61 action && (
62 <Link to={action.to}>
63 <Button variant="transparent" className="text-ui-fg-interactive">
64 <PlusMini /> {action.label}
65 </Button>
66 </Link>
67 )
68
69 export const NoRecords = ({
70 title,
71 message,
72 action,
73 className,
74 buttonVariant = "default",
75 icon = <ExclamationCircle className="text-ui-fg-subtle" />,
76 }: NoRecordsProps) => {
77 const { t } = useTranslation()
78
79 return (
80 <div
81 className={clx(
82 "flex h-[150px] w-full flex-col items-center justify-center gap-y-4",
83 className
84 )}
85 >
86 <div className="flex flex-col items-center gap-y-3">
87 {icon}
88
89 <div className="flex flex-col items-center gap-y-1">
90 <Text size="small" leading="compact" weight="plus">
91 {title ?? t("general.noRecordsTitle")}
92 </Text>
93
94 <Text size="small" className="text-ui-fg-muted">
95 {message ?? t("general.noRecordsMessage")}
96 </Text>
97 </div>
98 </div>
99
100 {buttonVariant === "default" && <DefaultButton action={action} />}
101 {buttonVariant === "transparentIconLeft" && (
102 <TransparentIconLeftButton action={action} />
103 )}
104 </div>
105 )
106 }