1 ---
2 sidebar_label: "Header"
3 ---
4
5 import { TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `Header - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 The `@medusajs/dashboard` package doesn't export a header component, so this guide is still the recommended way to build one. Refer to the [Components reference](../../components/page.mdx) for the components that Medusa does export.
16
17 </Note>
18
19 In this guide, you'll learn how to create a header component that matches the Medusa Admin's design conventions.
20
21 Each section in the Medusa Admin has a header with a title, and optionally a subtitle with buttons to perform an action.
22
23 ![Example of a header in a section](https://res.cloudinary.com/dza7lstvk/image/upload/v1728288562/Medusa%20Resources/header_dtz4gl.png)
24
25 To create a component that uses the same header styling and structure, create the file `src/admin/components/header.tsx` with the following content:
26
27 ```tsx title="src/admin/components/header.tsx"
28 import { Heading, Button, Text } from "@medusajs/ui"
29 import React from "react"
30 import { Link, LinkProps } from "react-router-dom"
31 import { ActionMenu, ActionMenuProps } from "./action-menu"
32
33 export type HeadingProps = {
34 title: string
35 subtitle?: string
36 actions?: (
37 {
38 type: "button",
39 props: React.ComponentProps<typeof Button>
40 link?: LinkProps
41 } |
42 {
43 type: "action-menu"
44 props: ActionMenuProps
45 } |
46 {
47 type: "custom"
48 children: React.ReactNode
49 }
50 )[]
51 }
52
53 export const Header = ({
54 title,
55 subtitle,
56 actions = [],
57 }: HeadingProps) => {
58 return (
59 <div className="flex items-center justify-between px-6 py-4">
60 <div>
61 <Heading level="h2">{title}</Heading>
62 {subtitle && (
63 <Text className="text-ui-fg-subtle" size="small">
64 {subtitle}
65 </Text>
66 )}
67 </div>
68 {actions.length > 0 && (
69 <div className="flex items-center justify-center gap-x-2">
70 {actions.map((action, index) => (
71 <>
72 {action.type === "button" && (
73 <Button
74 {...action.props}
75 size={action.props.size || "small"}
76 key={index}
77 >
78 <>
79 {action.props.children}
80 {action.link && <Link {...action.link} />}
81 </>
82 </Button>
83 )}
84 {action.type === "action-menu" && (
85 <ActionMenu {...action.props} />
86 )}
87 {action.type === "custom" && action.children}
88 </>
89 ))}
90 </div>
91 )}
92 </div>
93 )
94 }
95 ```
96
97 The `Header` component shows a title, and optionally a subtitle and action buttons.
98
99 <Note>
100
101 The component also uses the [ActionMenu](../../components/action-menu/page.mdx) component.
102
103 </Note>
104
105 It accepts the following props:
106
107 <TypeList
108 types={[
109 {
110 name: "title",
111 type: "`string`",
112 optional: false,
113 description: "The section's title."
114 },
115 {
116 name: "subtitle",
117 type: "`string`",
118 optional: true,
119 description: "The section's subtitle."
120 },
121 {
122 name: "actions",
123 type: "`object[]`",
124 optional: true,
125 description: "An array of actions to show.",
126 children: [
127 {
128 name: "type",
129 type: "`button` \\| `action-menu` \\| `custom`",
130 optional: false,
131 description: "The type of action to add.\n\n- If its value is `button`, it'll show a button that can have a link or an on-click action.\n\n- If its value is `action-menu`, it'll show a three dot icon with a dropdown of actions.\n\n- If its value is `custom`, you can pass any React nodes to render.",
132 },
133 {
134 name: "props",
135 type: "object",
136 optional: false,
137 description: `This property is only accepted if \`type\` is \`button\` or \`action-menu\`. If \`type\` is \`button\`, it accepts the [props to pass to the UI Button component](https://docs.medusajs.com/components/button). If \`type\` is \`action-menu\`, it accepts the props to pass to the action menu, explained in [this reference](../../components/action-menu/page.mdx).`,
138 },
139 {
140 name: "link",
141 type: `[LinkProps](https://reactrouter.com/api/components/Link)`,
142 optional: true,
143 description: "This property is only accepted if `type` is `button`. If provided, a link is rendered inside the button. Its value is the props to pass the `Link` component of `react-router-dom`."
144 },
145 {
146 name: "children",
147 type: "React.ReactNode",
148 optional: true,
149 description: "This property is only accepted if `type` is `custom`. Its content is rendered as part of the actions."
150 }
151 ]
152 }
153 ]}
154 />
155
156 ---
157
158 ## Example
159
160 Use the `Header` component in any widget or UI route.
161
162 For example, create the widget `src/admin/widgets/product-widget.tsx` with the following content:
163
164 ```tsx title="src/admin/widgets/product-widget.tsx"
165 import { defineWidgetConfig } from "@medusajs/admin-sdk"
166 import { Container } from "../components/container"
167 import { Header } from "../components/header"
168
169 const ProductWidget = () => {
170 return (
171 <Container>
172 <Header
173 title="Product Widget"
174 subtitle="This is my custom product widget"
175 actions={[
176 {
177 type: "button",
178 props: {
179 children: "Click me",
180 variant: "secondary",
181 onClick: () => {
182 alert("You clicked the button.")
183 },
184 },
185 },
186 ]}
187 />
188 </Container>
189 )
190 }
191
192 export const config = defineWidgetConfig({
193 zone: "product.details",
194 })
195
196 export default ProductWidget
197 ```
198
199 This widget also uses a [Container](../container/page.mdx) custom component.