This repository was archived by the owner on Apr 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathGenericItem.tsx
More file actions
202 lines (199 loc) · 8.51 KB
/
Copy pathGenericItem.tsx
File metadata and controls
202 lines (199 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { Check, Clock4, EyeOff, Globe, X, Zap } from "lucide-solid";
import { JSX, Match, Show, Switch } from "solid-js";
import { LabelCircle, LoadingSpinner } from "~/components";
import { useI18n } from "~/i18n/context";
export function GenericItem(props: {
primaryAvatarUrl?: string;
icon?: JSX.Element;
secondaryAvatarUrl?: string;
primaryName: string;
secondaryName?: string;
verb?: string;
amount?: bigint;
date?: string;
due?: string;
message?: string;
accent?: "green";
visibility?: "public" | "private";
showFiat?: boolean;
genericAvatar?: boolean;
forceSecondary?: boolean;
link?: string;
primaryOnClick?: () => void;
amountOnClick?: () => void;
secondaryOnClick?: () => void;
approveAction?: () => void;
rejectAction?: () => void;
shouldSpinny?: boolean;
}) {
const i18n = useI18n();
return (
<div
class="grid w-full py-3 first-of-type:pt-0"
classList={{
"grid-cols-[auto_1fr_auto]": true,
"opacity-50": props.shouldSpinny
}}
>
<div class="self-center">
<Switch>
<Match when={props.icon}>
<button
class="flex h-[3rem] w-[3rem] items-center justify-center"
onClick={() =>
props.primaryOnClick && props.primaryOnClick()
}
>
{props.icon}
</button>
</Match>
<Match when={true}>
<LabelCircle
label={false}
name={props.primaryName}
contact
image_url={props.primaryAvatarUrl}
generic={props.genericAvatar}
onClick={props.primaryOnClick}
/>
</Match>
</Switch>
</div>
<div class="flex flex-col items-start justify-center gap-1 self-center px-2">
{/* TITLE TEXT */}
<Show when={props.primaryName && props.verb}>
<h2 class="text-sm">
<strong
classList={{
"text-m-grey-400": props.genericAvatar
}}
>
{props.primaryName}
</strong>
<span class="font-light">{` ${props.verb} `}</span>
<Show when={props.secondaryName}>
<strong>{props.secondaryName}</strong>
</Show>
</h2>
</Show>
<div class="flex flex-wrap gap-1">
{/* AMOUNT */}
<Show when={props.amount}>
<button
onClick={() =>
props.amountOnClick && props.amountOnClick()
}
class="flex items-center gap-1 rounded-full px-2 py-1 text-xs font-semibold text-white"
classList={{
"bg-m-grey-800": !props.accent,
"bg-m-green/40 ": props.accent === "green"
}}
>
{/* <img src={bolt} width={8} height={8} /> */}
<Zap class="w-3" fill="currentColor" />
{`${props.amount!.toLocaleString()} sats`}
</button>
</Show>
{/* FIAT AMOUNT */}
<Show when={props.showFiat}>
<div class="flex items-center gap-1 rounded-full py-1 text-xs font-semibold text-m-grey-400">
{`~$42.00 USD`}
</div>
</Show>
{/* OPTIONAL MESSAGE */}
<Show when={props.message}>
<div class="font-regular line-clamp-1 min-w-0 break-all rounded-full bg-m-grey-800 px-2 py-1 text-xs leading-6">
{props.message}
</div>
</Show>
{/* DUE */}
<Show when={props.due}>
<div class="flex w-full items-center gap-1 text-m-grey-400">
<Clock4 class="w-3" />
<span class="text-xs text-m-grey-400">
{/* the date might include slashes so we don't want to escape those */}
{i18n.t("common.expires", {
time: props.due,
interpolation: { escapeValue: false }
})}
</span>
</div>
</Show>
</div>
{/* DATE WITH SECOND AVATAR */}
<Show when={props.date}>
<div class="flex items-center gap-1 text-m-grey-400">
<Show when={props.visibility === "public"}>
{/* <img src={globe} width={12} height={12} /> */}
<Globe class="w-3" />
</Show>
<Show when={props.visibility === "private"}>
<EyeOff class="w-3" />
{/* <img src={privateEye} width={12} height={12} /> */}
</Show>
<Show when={props.link && props.date}>
<a
href={props.link}
class="text-xs text-m-grey-400"
target="_blank"
rel="noopener noreferrer"
>
{props.date}
</a>
</Show>
<Show when={!props.link && props.date}>
<span class="text-xs text-m-grey-400">
{props.date}
</span>
</Show>
</div>
</Show>
</div>
<Show when={props.secondaryAvatarUrl || props.forceSecondary}>
<div class="self-center">
<LabelCircle
label={false}
name={props.secondaryName}
contact
image_url={props.secondaryAvatarUrl}
onClick={props.secondaryOnClick}
/>
</div>
</Show>
<Show when={!props.secondaryAvatarUrl && !props.forceSecondary}>
<div class="self-center">
{/* ACTIONS */}
<Show
when={
props.approveAction &&
props.rejectAction &&
!props.shouldSpinny
}
>
<div class="flex gap-4">
<button
class="flex h-10 w-10 items-center justify-center rounded bg-m-grey-800 p-1 text-m-green active:-mb-[1px] active:mt-[1px]"
onClick={() =>
props.approveAction && props.approveAction()
}
>
<Check />
</button>
<button
class="flex h-10 w-10 items-center justify-center rounded bg-m-grey-800 p-1 text-m-red active:-mb-[1px] active:mt-[1px]"
onClick={() =>
props.rejectAction && props.rejectAction()
}
>
<X />
</button>
</div>
</Show>
<Show when={props.shouldSpinny}>
<LoadingSpinner wide small />
</Show>
</div>
</Show>
</div>
);
}