1 import React from "react"
2 import clsx from "clsx"
3 import { PlusMini } from "@medusajs/icons"
4
5 export type DetailsSummaryProps = {
6 title?: React.ReactNode
7 subtitle?: React.ReactNode
8 badge?: React.ReactNode
9 expandable?: boolean
10 open?: boolean
11 className?: string
12 titleClassName?: string
13 hideExpandableIcon?: boolean
14 summaryRef?: React.LegacyRef<HTMLDivElement>
15 } & Omit<React.HTMLAttributes<HTMLElement>, "title">
16
17 export const DetailsSummary = ({
18 title,
19 subtitle,
20 children,
21 badge,
22 expandable = true,
23 open = false,
24 className,
25 titleClassName,
26 hideExpandableIcon = false,
27 summaryRef,
28 ...rest
29 }: DetailsSummaryProps) => {
30 return (
31 <summary
32 className={clsx(
33 "py-docs_0.75 flex items-center justify-between",
34 expandable && "cursor-pointer",
35 !expandable &&
36 "border-medusa-border-base border-y border-solid border-x-0",
37 (expandable || badge !== undefined) && "gap-0.5",
38 "no-marker",
39 className
40 )}
41 ref={summaryRef}
42 {...rest}
43 >
44 <span className="gap-docs_0.25 flex flex-col">
45 <span
46 className={clsx(
47 "text-compact-medium-plus text-medusa-fg-base",
48 titleClassName
49 )}
50 data-testid="details-summary-title"
51 >
52 {title || children}
53 </span>
54 {subtitle && (
55 <span
56 className="text-compact-medium text-medusa-fg-subtle mt-0.5"
57 data-testid="details-summary-subtitle"
58 >
59 {subtitle}
60 </span>
61 )}
62 </span>
63 {(badge || expandable) && (
64 <span className="flex gap-docs_0.5" data-testid="details-summary-extra">
65 {badge}
66 {expandable && !hideExpandableIcon && (
67 <PlusMini
68 className={clsx("transition-transform", open && "rotate-45")}
69 />
70 )}
71 </span>
72 )}
73 </summary>
74 )
75 }