Raw
1 import { ArrowDownTray, Spinner } from "@medusajs/icons"
2 import { IconButton, Text } from "@medusajs/ui"
3 import { ActionGroup, ActionMenu } from "../action-menu"
4
5 export const FilePreview = ({
6 filename,
7 url,
8 loading,
9 activity,
10 actions,
11 hideThumbnail,
12 }: {
13 filename: string
14 url?: string
15 loading?: boolean
16 activity?: string
17 actions?: ActionGroup[]
18 hideThumbnail?: boolean
19 }) => {
20 return (
21 <div className="shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-3 py-2">
22 <div className="flex flex-row items-center justify-between gap-2">
23 <div className="flex flex-row items-center gap-3">
24 {!hideThumbnail && <FileThumbnail />}
25 <div className="flex flex-col justify-center">
26 <Text
27 size="small"
28 leading="compact"
29 className="max-w-[260px] truncate"
30 >
31 {filename}
32 </Text>
33
34 {loading && !!activity && (
35 <Text
36 leading="compact"
37 size="xsmall"
38 className="text-ui-fg-interactive"
39 >
40 {activity}
41 </Text>
42 )}
43 </div>
44 </div>
45
46 {loading && <Spinner className="animate-spin" />}
47 {!loading && actions && <ActionMenu groups={actions} />}
48 {!loading && url && (
49 <IconButton variant="transparent" asChild>
50 <a href={url} download={filename ?? `${Date.now()}`}>
51 <ArrowDownTray />
52 </a>
53 </IconButton>
54 )}
55 </div>
56 </div>
57 )
58 }
59
60 const FileThumbnail = () => {
61 return (
62 <svg
63 width="24"
64 height="32"
65 viewBox="0 0 24 32"
66 fill="none"
67 xmlns="http://www.w3.org/2000/svg"
68 >
69 <path
70 d="M20 31.75H4C1.92893 31.75 0.25 30.0711 0.25 28V4C0.25 1.92893 1.92893 0.25 4 0.25H15.9431C16.9377 0.25 17.8915 0.645088 18.5948 1.34835L22.6516 5.4052C23.3549 6.10847 23.75 7.06229 23.75 8.05685V28C23.75 30.0711 22.0711 31.75 20 31.75Z"
71 fill="url(#paint0_linear_6594_388107)"
72 stroke="url(#paint1_linear_6594_388107)"
73 strokeWidth="0.5"
74 />
75 <path
76 opacity="0.4"
77 d="M17.7857 12.8125V13.5357H10.3393V10.9643H15.9375C16.9569 10.9643 17.7857 11.7931 17.7857 12.8125ZM6.21429 16.9107V15.0893H8.78571V16.9107H6.21429ZM10.3393 16.9107V15.0893H17.7857V16.9107H10.3393ZM15.9375 21.0357H10.3393V18.4643H17.7857V19.1875C17.7857 20.2069 16.9569 21.0357 15.9375 21.0357ZM6.21429 19.1875V18.4643H8.78571V21.0357H8.0625C7.0431 21.0357 6.21429 20.2069 6.21429 19.1875ZM8.0625 10.9643H8.78571V13.5357H6.21429V12.8125C6.21429 11.7931 7.0431 10.9643 8.0625 10.9643Z"
78 fill="url(#paint2_linear_6594_388107)"
79 stroke="url(#paint3_linear_6594_388107)"
80 strokeWidth="0.428571"
81 />
82 <defs>
83 <linearGradient
84 id="paint0_linear_6594_388107"
85 x1="12"
86 y1="0"
87 x2="12"
88 y2="32"
89 gradientUnits="userSpaceOnUse"
90 >
91 <stop stopColor="#F4F4F5" />
92 <stop offset="1" stopColor="#E4E4E7" />
93 </linearGradient>
94 <linearGradient
95 id="paint1_linear_6594_388107"
96 x1="12"
97 y1="0"
98 x2="12"
99 y2="32"
100 gradientUnits="userSpaceOnUse"
101 >
102 <stop stopColor="#E4E4E7" />
103 <stop offset="1" stopColor="#D4D4D8" />
104 </linearGradient>
105 <linearGradient
106 id="paint2_linear_6594_388107"
107 x1="12"
108 y1="10.75"
109 x2="12"
110 y2="21.25"
111 gradientUnits="userSpaceOnUse"
112 >
113 <stop stopColor="#52525B" />
114 <stop offset="1" stopColor="#A1A1AA" />
115 </linearGradient>
116 <linearGradient
117 id="paint3_linear_6594_388107"
118 x1="12"
119 y1="10.75"
120 x2="12"
121 y2="21.25"
122 gradientUnits="userSpaceOnUse"
123 >
124 <stop stopColor="#18181B" />
125 <stop offset="1" stopColor="#52525B" />
126 </linearGradient>
127 </defs>
128 </svg>
129 )
130 }