Raw
1 ---
2 sidebar_label: "Empty States"
3 ---
4
5 import { TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `Empty States - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 These components are available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0).
16
17 </Note>
18
19 The `NoRecords` and `NoResults` components show the empty states of lists and tables in the Medusa Admin. Use `NoRecords` when a list has no data at all, and `NoResults` when a search or filter returns no matches.
20
21 ```tsx
22 import {
23 NoRecords,
24 NoResults,
25 } from "@medusajs/dashboard/components"
26 ```
27
28 Both components fall back to the Medusa Admin's default translated messages when you don't pass a title or a message. Learn more about translations in the [Admin Translations](!docs!/learn/fundamentals/admin/translations) documentation.
29
30 ---
31
32 ## NoRecords
33
34 The `NoRecords` component shows an icon, a title, a message, and an optional link button. The Medusa Admin uses it in sections that have no data yet, such as a customer with no addresses.
35
36 ### Example
37
38 ```tsx
39 import { defineWidgetConfig } from "@medusajs/admin-sdk"
40 import { NoRecords } from "@medusajs/dashboard/components"
41 import { Container } from "@medusajs/ui"
42
43 const CampaignsWidget = () => {
44 const campaigns = []
45
46 return (
47 <Container className="p-0">
48 {campaigns.length === 0 && (
49 <NoRecords
50 title="No campaigns"
51 message="Create a campaign to get started."
52 action={{
53 to: "/campaigns/create",
54 label: "Create campaign",
55 }}
56 />
57 )}
58 </Container>
59 )
60 }
61
62 export const config = defineWidgetConfig({
63 zone: "product.details.after",
64 })
65
66 export default CampaignsWidget
67 ```
68
69 ### Props
70
71 <TypeList
72 types={[
73 {
74 name: "title",
75 type: "`string`",
76 optional: true,
77 description:
78 "The empty state's title. Defaults to the Medusa Admin's translated `general.noRecordsTitle` message.",
79 },
80 {
81 name: "message",
82 type: "`string`",
83 optional: true,
84 description:
85 "The message shown under the title. Defaults to the Medusa Admin's translated `general.noRecordsMessage` message.",
86 },
87 {
88 name: "action",
89 type: "`object`",
90 optional: true,
91 description:
92 "A button shown under the message that links to the `to` path. If not passed, no button is shown.",
93 children: [
94 {
95 name: "to",
96 type: "`string`",
97 optional: false,
98 description: "The path that the button links to.",
99 },
100 {
101 name: "label",
102 type: "`string`",
103 optional: false,
104 description: "The button's label.",
105 },
106 ],
107 },
108 {
109 name: "buttonVariant",
110 type: "`\"default\"` \\| `\"transparentIconLeft\"`",
111 optional: true,
112 defaultValue: "default",
113 description:
114 "The action button's style. `default` shows a secondary button, and `transparentIconLeft` shows a transparent button with a plus icon.",
115 },
116 {
117 name: "icon",
118 type: "`React.ReactNode`",
119 optional: true,
120 description:
121 "The icon shown above the title. Defaults to an exclamation-circle icon.",
122 },
123 {
124 name: "className",
125 type: "`string`",
126 optional: true,
127 description:
128 "Additional CSS classes to apply to the empty state's container.",
129 },
130 ]}
131 />
132
133 ---
134
135 ## NoResults
136
137 The `NoResults` component shows a magnifying-glass icon, a title, and a message. The Medusa Admin uses it in tables when a search query or a filter returns no matching records.
138
139 ### Example
140
141 ```tsx
142 import { defineWidgetConfig } from "@medusajs/admin-sdk"
143 import { NoResults } from "@medusajs/dashboard/components"
144 import { Container } from "@medusajs/ui"
145
146 const SearchResultsWidget = () => {
147 const results = []
148
149 return (
150 <Container className="p-0">
151 {results.length === 0 && <NoResults />}
152 </Container>
153 )
154 }
155
156 export const config = defineWidgetConfig({
157 zone: "product.details.after",
158 })
159
160 export default SearchResultsWidget
161 ```
162
163 ### Props
164
165 <TypeList
166 types={[
167 {
168 name: "title",
169 type: "`string`",
170 optional: true,
171 description:
172 "The empty state's title. Defaults to the Medusa Admin's translated `general.noResultsTitle` message.",
173 },
174 {
175 name: "message",
176 type: "`string`",
177 optional: true,
178 description:
179 "The message shown under the title. Defaults to the Medusa Admin's translated `general.noResultsMessage` message.",
180 },
181 {
182 name: "className",
183 type: "`string`",
184 optional: true,
185 description:
186 "Additional CSS classes to apply to the empty state's container.",
187 },
188 ]}
189 />
190
191 The `NoResultsProps` type is also exported, so you can use it to type your own wrapper components:
192
193 ```tsx
194 import type {
195 NoResultsProps,
196 } from "@medusajs/dashboard/components"
197 ```