1 "use client"
2
3 import React from "react"
4 import clsx from "clsx"
5 import { CardProps } from "@/components/Card"
6 import { BorderedIcon } from "@/components/BorderedIcon"
7 import { Button } from "@/components/Button"
8 import { ThemeImage } from "@/components/ThemeImage"
9 import { useIsExternalLink } from "@/hooks/use-is-external-link"
10 import Link from "next/link"
11 import Image from "next/image"
12 import { ArrowUpRightOnBox, TriangleRightMini, XMark } from "@medusajs/icons"
13
14 export const CardLayoutMini = ({
15 icon,
16 image,
17 themeImage,
18 title,
19 text,
20 href,
21 hrefProps = {},
22 closeable = false,
23 onClose,
24 className,
25 imageDimensions = { width: 45, height: 36 },
26 iconClassName,
27 cardRef,
28 onClick,
29 }: CardProps) => {
30 const isExternal = useIsExternalLink({ href })
31
32 return (
33 <div
34 className={clsx(
35 "relative rounded-docs_DEFAULT border-medusa-fg-on-inverted border",
36 "shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark",
37 "hover:shadow-elevation-card-hover dark:hover:shadow-elevation-card-hover-dark",
38 "bg-medusa-tag-neutral-bg dark:bg-medusa-bg-component",
39 "hover:bg-medusa-tag-neutral-bg-hover dark:hover:bg-medusa-bg-component-hover",
40 "w-fit transition-[shadow,background]",
41 className
42 )}
43 ref={cardRef}
44 >
45 <div
46 className={clsx(
47 "rounded-docs_DEFAULT flex gap-docs_0.75 py-docs_0.25",
48 "pl-docs_0.25 pr-docs_0.75 items-center"
49 )}
50 >
51 {icon && (
52 <BorderedIcon
53 wrapperClassName={clsx("p-[4.5px] bg-medusa-bg-component-hover")}
54 IconComponent={icon}
55 />
56 )}
57 {image && (
58 <Image
59 src={image}
60 className={clsx(
61 "shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark",
62 "rounded-docs_xs",
63 iconClassName
64 )}
65 width={imageDimensions.width}
66 height={imageDimensions.height}
67 alt={title || text || ""}
68 style={{
69 width: `${imageDimensions.width}px`,
70 height: `${imageDimensions.height}px`,
71 }}
72 />
73 )}
74 {themeImage && (
75 <ThemeImage
76 {...themeImage}
77 className={clsx(
78 "shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark",
79 "rounded-docs_xs",
80 iconClassName
81 )}
82 width={imageDimensions.width}
83 height={imageDimensions.height}
84 alt={title || text || ""}
85 style={{
86 width: `${imageDimensions.width}px`,
87 height: `${imageDimensions.height}px`,
88 }}
89 />
90 )}
91 <div className="flex flex-col">
92 {title && (
93 <span
94 className="text-x-small-plus text-medusa-fg-base"
95 data-testid="title"
96 >
97 {title}
98 </span>
99 )}
100 {text && (
101 <span
102 className="text-x-small-plus text-medusa-fg-subtle"
103 data-testid="text"
104 >
105 {text}
106 </span>
107 )}
108 </div>
109 {!closeable && (
110 <span className="text-medusa-fg-subtle">
111 {isExternal ? (
112 <ArrowUpRightOnBox data-testid="external-icon" />
113 ) : (
114 <TriangleRightMini data-testid="internal-icon" />
115 )}
116 </span>
117 )}
118 {href && (
119 <Link
120 href={href}
121 className="absolute left-0 top-0 w-full h-full z-[1]"
122 prefetch={false}
123 {...hrefProps}
124 rel={isExternal ? "noopener noreferrer" : undefined}
125 target={isExternal ? "_blank" : undefined}
126 aria-label={title}
127 onClick={onClick}
128 />
129 )}
130 {closeable && (
131 <Button
132 variant="transparent-clear"
133 onClick={onClose}
134 className="!p-[2.5px] z-[2] hover:!bg-medusa-button-transparent-hover focus:!shadow-none focus:!bg-transparent"
135 data-testid="close-button"
136 >
137 <XMark data-testid="close-icon" />
138 </Button>
139 )}
140 </div>
141 </div>
142 )
143 }