|
1
|
import { InformationCircleSolid } from "@medusajs/icons"; |
|
2
|
import { Button, Heading, Text, Tooltip } from "@medusajs/ui"; |
|
3
|
import React from "react"; |
|
4
|
import { Link, LinkProps } from "react-router-dom"; |
|
5
|
import { ActionMenu, ActionMenuProps } from "./action-menu"; |
|
6
|
|
|
7
|
export type HeadingProps = { |
|
8
|
title: string; |
|
9
|
subtitle?: string; |
|
10
|
tooltip?: React.ReactNode; |
|
11
|
actions?: ( |
|
12
|
| { |
|
13
|
type: "button"; |
|
14
|
props: React.ComponentProps<typeof Button>; |
|
15
|
link?: LinkProps; |
|
16
|
} |
|
17
|
| { |
|
18
|
type: "action-menu"; |
|
19
|
props: ActionMenuProps; |
|
20
|
} |
|
21
|
| { |
|
22
|
type: "custom"; |
|
23
|
children: React.ReactNode; |
|
24
|
} |
|
25
|
)[]; |
|
26
|
}; |
|
27
|
|
|
28
|
export const Header = ({ |
|
29
|
title, |
|
30
|
subtitle, |
|
31
|
actions = [], |
|
32
|
tooltip, |
|
33
|
}: HeadingProps) => { |
|
34
|
return ( |
|
35
|
<div className="flex px-6 py-4"> |
|
36
|
<div className="flex justify-between w-full"> |
|
37
|
<div className="flex flex-col"> |
|
38
|
<Heading level="h2">{title}</Heading> |
|
39
|
{subtitle && ( |
|
40
|
<Text className="text-ui-fg-subtle" size="small"> |
|
41
|
{subtitle} |
|
42
|
</Text> |
|
43
|
)} |
|
44
|
</div> |
|
45
|
|
|
46
|
{tooltip && ( |
|
47
|
<Tooltip content={tooltip}> |
|
48
|
<InformationCircleSolid className="text-ui-fg-muted" /> |
|
49
|
</Tooltip> |
|
50
|
)} |
|
51
|
</div> |
|
52
|
{actions.length > 0 && ( |
|
53
|
<div className="flex items-center justify-center gap-x-2"> |
|
54
|
{actions.map((action, index) => ( |
|
55
|
<> |
|
56
|
{action.type === "button" && ( |
|
57
|
<Button |
|
58
|
{...action.props} |
|
59
|
size={action.props.size || "small"} |
|
60
|
key={index} |
|
61
|
> |
|
62
|
<> |
|
63
|
{action.props.children} |
|
64
|
{action.link && <Link {...action.link} />} |
|
65
|
</> |
|
66
|
</Button> |
|
67
|
)} |
|
68
|
{action.type === "action-menu" && ( |
|
69
|
<ActionMenu {...action.props} /> |
|
70
|
)} |
|
71
|
{action.type === "custom" && action.children} |
|
72
|
</> |
|
73
|
))} |
|
74
|
</div> |
|
75
|
)} |
|
76
|
</div> |
|
77
|
); |
|
78
|
}; |