|
1
|
import { Tooltip, clx } from "@medusajs/ui" |
|
2
|
import { useTranslation } from "react-i18next" |
|
3
|
import { TruncatedText } from "../truncated-text" |
|
4
|
|
|
5
|
type ListSummaryProps = { |
|
6
|
/** |
|
7
|
* Number of initial items to display |
|
8
|
* @default 2 |
|
9
|
*/ |
|
10
|
n?: number |
|
11
|
/** |
|
12
|
* List of strings to display as abbreviated list |
|
13
|
*/ |
|
14
|
list: string[] |
|
15
|
/** |
|
16
|
* Is the summary displayed inline. |
|
17
|
* Determines whether the center text is truncated if there is no space in the container |
|
18
|
*/ |
|
19
|
inline?: boolean |
|
20
|
variant?: "base" | "compact" |
|
21
|
|
|
22
|
className?: string |
|
23
|
} |
|
24
|
|
|
25
|
export const ListSummary = ({ |
|
26
|
list, |
|
27
|
className, |
|
28
|
variant = "compact", |
|
29
|
inline, |
|
30
|
n = 2, |
|
31
|
}: ListSummaryProps) => { |
|
32
|
const { t } = useTranslation() |
|
33
|
|
|
34
|
const title = t("general.plusCountMore", { |
|
35
|
count: list.length - n, |
|
36
|
}) |
|
37
|
|
|
38
|
return ( |
|
39
|
<div |
|
40
|
className={clx( |
|
41
|
"text-ui-fg-subtle gap-x-1 overflow-hidden", |
|
42
|
{ |
|
43
|
"inline-flex": inline, |
|
44
|
flex: !inline, |
|
45
|
"txt-compact-small": variant === "compact", |
|
46
|
"txt-small": variant === "base", |
|
47
|
}, |
|
48
|
className |
|
49
|
)} |
|
50
|
> |
|
51
|
<TruncatedText text={list.slice(0, n).join(", ")} /> |
|
52
|
{list.length > n && ( |
|
53
|
<div className="whitespace-nowrap"> |
|
54
|
<Tooltip |
|
55
|
content={ |
|
56
|
<ul> |
|
57
|
{list.slice(n).map((c) => ( |
|
58
|
<li key={c}>{c}</li> |
|
59
|
))} |
|
60
|
</ul> |
|
61
|
} |
|
62
|
> |
|
63
|
<span className="cursor-default whitespace-nowrap">{title}</span> |
|
64
|
</Tooltip> |
|
65
|
</div> |
|
66
|
)} |
|
67
|
</div> |
|
68
|
) |
|
69
|
} |