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