@akita-protocol/algomd-rn 1.0.0-alpha.1 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/presentation/icons.tsx +108 -1
- package/src/presentation/pluginColors.ts +1 -0
- package/src/presentation/runtime.tsx +26 -0
- package/src/refs/AccountRef.tsx +24 -10
- package/src/refs/GuildActions.tsx +925 -0
- package/src/refs/GuildProposalRef.tsx +86 -59
- package/src/refs/index.tsx +1 -0
- package/src/refs/primitives.tsx +51 -19
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import {
|
|
4
|
-
GUILD_ZERO_ADDRESS,
|
|
5
4
|
formatRelativeTime,
|
|
6
5
|
guildBallotOutcome,
|
|
7
6
|
guildProposalStatusLabel,
|
|
8
7
|
guildRequirementsText,
|
|
8
|
+
guildTallyText,
|
|
9
9
|
splitGuildProposalId,
|
|
10
10
|
type GuildBallotData,
|
|
11
11
|
type GuildProposalData,
|
|
12
12
|
type GuildProposalStatus,
|
|
13
13
|
} from "@akita-protocol/algomd-core";
|
|
14
14
|
import { useGuildProposal } from "@akita-protocol/algomd-core/react";
|
|
15
|
-
import {
|
|
15
|
+
import { GuildIcon, HandThumbDownIcon, HandThumbUpIcon } from "../presentation/icons";
|
|
16
|
+
import { PLUGIN_COLORS } from "../presentation/pluginColors";
|
|
16
17
|
import { Text, useAppTheme, usePresentation, type GuildVoteChoice } from "../presentation/runtime";
|
|
17
|
-
import { PersonRow } from "./AccountRef";
|
|
18
18
|
import { ActionButton, plural, useNow } from "./contractParts";
|
|
19
|
+
import { GuildActionList, GuildProposalPaid } from "./GuildActions";
|
|
19
20
|
import {
|
|
20
21
|
Card,
|
|
21
22
|
CardHeader,
|
|
22
23
|
CardSkeleton,
|
|
23
|
-
headerMedia,
|
|
24
24
|
InlinePill,
|
|
25
25
|
KindTile,
|
|
26
26
|
Note,
|
|
27
27
|
Row,
|
|
28
28
|
RowSkeleton,
|
|
29
|
-
Section,
|
|
30
29
|
StatusBadge,
|
|
31
30
|
Title,
|
|
32
31
|
Unavailable,
|
|
@@ -35,7 +34,7 @@ import {
|
|
|
35
34
|
} from "./primitives";
|
|
36
35
|
import type { RefViewProps } from "./types";
|
|
37
36
|
|
|
38
|
-
type CardAction = GuildVoteChoice | "submit" | "finalize" | "execute";
|
|
37
|
+
type CardAction = GuildVoteChoice | "submit" | "finalize" | "execute" | "cancel";
|
|
39
38
|
|
|
40
39
|
const PROGRESS: Record<CardAction, string> = {
|
|
41
40
|
approve: "Voting yes…",
|
|
@@ -43,7 +42,8 @@ const PROGRESS: Record<CardAction, string> = {
|
|
|
43
42
|
abstain: "Abstaining…",
|
|
44
43
|
submit: "Opening the vote…",
|
|
45
44
|
finalize: "Closing the vote…",
|
|
46
|
-
execute: "
|
|
45
|
+
execute: "Applying the changes…",
|
|
46
|
+
cancel: "Cancelling the proposal…",
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const VOTED: Record<GuildVoteChoice, string> = {
|
|
@@ -59,8 +59,12 @@ const STATUS_TONE: Record<GuildProposalStatus, Tone> = {
|
|
|
59
59
|
rejected: "bad",
|
|
60
60
|
approved: "good",
|
|
61
61
|
executed: "good",
|
|
62
|
+
cancelled: "neutral",
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
/** How long the host's automation gets before the card offers to do it by hand. */
|
|
66
|
+
const AUTOMATION_GRACE = 10 * 60;
|
|
67
|
+
|
|
64
68
|
function timeLeft(votingEnd: string, now: number): string {
|
|
65
69
|
const remaining = Number(votingEnd) - now;
|
|
66
70
|
if (remaining <= 0) return "Voting closed";
|
|
@@ -86,15 +90,15 @@ export function GuildProposalRef({ id, size = "large", params, onPress, visible
|
|
|
86
90
|
const retry = proposal.isError ? () => void proposal.refetch() : undefined;
|
|
87
91
|
|
|
88
92
|
if (size === "inline") {
|
|
89
|
-
return <InlinePill label={label} dim={proposal.isPending} leading={<
|
|
93
|
+
return <InlinePill label={label} dim={proposal.isPending} leading={<GuildIcon size={12} color={PLUGIN_COLORS.Guild} />} onPress={press} />;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
if (size === "small") {
|
|
93
97
|
if (proposal.isPending) return <RowSkeleton shape="rounded" />;
|
|
94
|
-
if (!data) return <Unavailable size="small" label={label} Icon={
|
|
98
|
+
if (!data) return <Unavailable size="small" label={label} Icon={GuildIcon} onRetry={retry} />;
|
|
95
99
|
return (
|
|
96
100
|
<Row
|
|
97
|
-
leading={<KindTile Icon={
|
|
101
|
+
leading={<KindTile Icon={GuildIcon} color={PLUGIN_COLORS.Guild} size={40} />}
|
|
98
102
|
title={<Title>{label}</Title>}
|
|
99
103
|
subtitle={`Guild proposal #${data.proposalId} · ${plural(data.actions.length, "action")}`}
|
|
100
104
|
trailing={<StatusBadge label={guildProposalStatusLabel(data.status)} tone={STATUS_TONE[data.status]} />}
|
|
@@ -105,7 +109,7 @@ export function GuildProposalRef({ id, size = "large", params, onPress, visible
|
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
if (proposal.isPending) return <CardSkeleton media="rounded" blocks={3} action full={size === "full"} />;
|
|
108
|
-
if (!data) return <Unavailable size={size} label={label} Icon={
|
|
112
|
+
if (!data) return <Unavailable size={size} label={label} Icon={GuildIcon} onRetry={retry} />;
|
|
109
113
|
return (
|
|
110
114
|
<GuildProposalCard
|
|
111
115
|
data={data}
|
|
@@ -152,21 +156,43 @@ function GuildProposalCard({
|
|
|
152
156
|
const { theme, tone } = usePalette();
|
|
153
157
|
const presentation = usePresentation();
|
|
154
158
|
const actions = presentation.actions;
|
|
155
|
-
const
|
|
159
|
+
const automated = !!presentation.guildAutomation;
|
|
160
|
+
const now = useNow(automated ? 15_000 : 60_000, data.status === "voting" || (automated && data.status === "approved"));
|
|
156
161
|
const [busy, setBusy] = useState<CardAction>();
|
|
157
162
|
const [error, setError] = useState<string>();
|
|
158
163
|
const [voted, setVoted] = useState<GuildVoteChoice>();
|
|
164
|
+
const [applyFailed, setApplyFailed] = useState(false);
|
|
159
165
|
const ballot = data.ballot;
|
|
160
166
|
const outcome = ballot ? guildBallotOutcome(ballot, now) : undefined;
|
|
161
167
|
const blocked = presentation.guildActionBlock?.(data.guildAppId);
|
|
162
168
|
const open = data.status === "voting" && !!ballot && !ballot.resolved;
|
|
163
169
|
const canVote = open && outcome === undefined && now <= Number(ballot!.votingEnd) && !!actions?.guildVote;
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
+
const noVote = canVote ? presentation.guildVoteBlock?.(data.guildAppId, data.proposalId) : undefined;
|
|
171
|
+
const isCreator = !!data.creator && data.creator === presentation.viewerAddress;
|
|
172
|
+
const settled = open && outcome !== undefined;
|
|
173
|
+
// Bootstrap proposals (no vote) only run for their creator, so the host's automation skips them.
|
|
174
|
+
const pendingRun = data.status === "approved" && data.votingTs !== "0";
|
|
175
|
+
const waiting = automated && (settled || pendingRun);
|
|
176
|
+
// When the automation's turn began: the vote's end, or when this card first saw it due.
|
|
177
|
+
const firstDue = useRef<number | undefined>(undefined);
|
|
178
|
+
if (waiting && firstDue.current === undefined) firstDue.current = now;
|
|
179
|
+
const dueSince = Math.min(Number(ballot?.votingEnd) || Infinity, firstDue.current ?? now);
|
|
180
|
+
const late = waiting && now - dueSince >= AUTOMATION_GRACE;
|
|
181
|
+
// Re-read the proposal while the automation works, so the card moves on by itself.
|
|
182
|
+
const refreshRef = useRef(refresh);
|
|
183
|
+
refreshRef.current = refresh;
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!waiting) return;
|
|
186
|
+
const t = setInterval(() => refreshRef.current(), 20_000);
|
|
187
|
+
return () => clearInterval(t);
|
|
188
|
+
}, [waiting]);
|
|
189
|
+
const canFinalize = settled && !!actions?.guildFinalize && (!automated || late);
|
|
190
|
+
const canExecute = (automated ? pendingRun && late : data.status === "approved") && !!actions?.guildExecute;
|
|
191
|
+
const canSubmit = data.status === "draft" && isCreator && !!actions?.guildSubmit;
|
|
192
|
+
// An approved proposal can be impossible to apply, e.g. a plugin the wallet already has. Its creator can withdraw it.
|
|
193
|
+
const canCancel = pendingRun && isCreator && (late || applyFailed) && !!actions?.guildCancel;
|
|
194
|
+
const statusLabel = settled ? (outcome === "approved" ? "Passed" : "Rejected") : guildProposalStatusLabel(data.status);
|
|
195
|
+
const statusTone: Tone = settled ? (outcome === "approved" ? "good" : "bad") : STATUS_TONE[data.status];
|
|
170
196
|
|
|
171
197
|
const run = async (action: CardAction) => {
|
|
172
198
|
if (busy || blocked) return;
|
|
@@ -179,9 +205,11 @@ function GuildProposalCard({
|
|
|
179
205
|
setVoted(action);
|
|
180
206
|
} else if (action === "submit") await actions?.guildSubmit?.(guildAppId, proposalId);
|
|
181
207
|
else if (action === "finalize") await actions?.guildFinalize?.(guildAppId, proposalId);
|
|
208
|
+
else if (action === "cancel") await actions?.guildCancel?.(guildAppId, proposalId);
|
|
182
209
|
else await actions?.guildExecute?.(guildAppId, proposalId);
|
|
183
210
|
refresh();
|
|
184
211
|
} catch (cause) {
|
|
212
|
+
if (action === "execute") setApplyFailed(true);
|
|
185
213
|
setError(cause instanceof Error ? cause.message : "The guild transaction failed.");
|
|
186
214
|
} finally {
|
|
187
215
|
setBusy(undefined);
|
|
@@ -191,12 +219,12 @@ function GuildProposalCard({
|
|
|
191
219
|
return (
|
|
192
220
|
<Card>
|
|
193
221
|
<CardHeader
|
|
194
|
-
|
|
222
|
+
eyebrow={{ label: "Guild proposal", Icon: GuildIcon, color: PLUGIN_COLORS.Guild }}
|
|
195
223
|
title={title}
|
|
196
224
|
titleLines={3}
|
|
197
225
|
full={full}
|
|
198
226
|
status={<StatusBadge label={statusLabel} tone={statusTone} />}
|
|
199
|
-
meta={
|
|
227
|
+
meta={`#${data.proposalId}${data.created && data.created !== "0" ? ` · ${formatRelativeTime(Number(data.created))}` : ""}`}
|
|
200
228
|
/>
|
|
201
229
|
|
|
202
230
|
{summary ? (
|
|
@@ -205,40 +233,22 @@ function GuildProposalCard({
|
|
|
205
233
|
</Text>
|
|
206
234
|
) : null}
|
|
207
235
|
|
|
208
|
-
{data.actions.length ?
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
{data.actions.map((action, i) => (
|
|
212
|
-
<View key={`${action.type}:${i}`} style={{ gap: 6 }}>
|
|
213
|
-
<View style={styles.actionRow}>
|
|
214
|
-
<View style={[styles.dot, { backgroundColor: theme.colors.primary }]} />
|
|
215
|
-
<Text size="xs" style={{ flex: 1 }}>
|
|
216
|
-
{action.label}
|
|
217
|
-
{action.pluginAppId ? ` #${action.pluginAppId}` : ""}
|
|
218
|
-
{action.caller === GUILD_ZERO_ADDRESS ? " for members by vote" : ""}
|
|
219
|
-
</Text>
|
|
220
|
-
</View>
|
|
221
|
-
{action.caller && action.caller !== GUILD_ZERO_ADDRESS ? (
|
|
222
|
-
<PersonRow address={action.caller} role={action.type === 40 ? "Loses the plugin" : "Gets the plugin"} visible={visible} />
|
|
223
|
-
) : null}
|
|
224
|
-
</View>
|
|
225
|
-
))}
|
|
226
|
-
</View>
|
|
227
|
-
</Section>
|
|
228
|
-
) : null}
|
|
236
|
+
{data.actions.length ? <GuildActionList actions={data.actions} consensus={data.consensus} feeAsset={data.feeAsset} visible={visible} /> : null}
|
|
237
|
+
|
|
238
|
+
{data.paid.token || full ? <GuildProposalPaid paid={data.paid} /> : null}
|
|
229
239
|
|
|
230
240
|
{ballot ? (
|
|
231
241
|
<View style={{ gap: 6 }}>
|
|
242
|
+
{guildRequirementsText(ballot, data.consensus?.kind) ? <Note>{guildRequirementsText(ballot, data.consensus?.kind)}</Note> : null}
|
|
232
243
|
<TallyBar ballot={ballot} />
|
|
233
244
|
<View style={styles.legend}>
|
|
234
245
|
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
235
|
-
{
|
|
246
|
+
{guildTallyText(ballot, data.consensus?.kind)}
|
|
236
247
|
</Text>
|
|
237
248
|
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
238
|
-
{ballot.resolved ? "Closed" : timeLeft(ballot.votingEnd, now)}
|
|
249
|
+
{ballot.resolved ? "Closed" : settled && now <= Number(ballot.votingEnd) ? "Decided early" : timeLeft(ballot.votingEnd, now)}
|
|
239
250
|
</Text>
|
|
240
251
|
</View>
|
|
241
|
-
{guildRequirementsText(ballot) ? <Note>{guildRequirementsText(ballot)}</Note> : null}
|
|
242
252
|
</View>
|
|
243
253
|
) : null}
|
|
244
254
|
|
|
@@ -250,24 +260,44 @@ function GuildProposalCard({
|
|
|
250
260
|
<Text size="xs" weight="semiBold" style={{ color: tone("good") }}>
|
|
251
261
|
{VOTED[voted]}
|
|
252
262
|
</Text>
|
|
263
|
+
) : noVote ? (
|
|
264
|
+
<Note>{noVote}</Note>
|
|
253
265
|
) : canVote ? (
|
|
254
266
|
<View style={styles.buttons}>
|
|
255
|
-
<
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
<
|
|
262
|
-
|
|
263
|
-
|
|
267
|
+
<ActionButton label="Abstain" variant="text" onPress={() => void run("abstain")} />
|
|
268
|
+
<ActionButton label="No" Icon={HandThumbDownIcon} variant="secondary" onPress={() => void run("reject")} accessibilityLabel="Vote no" />
|
|
269
|
+
<ActionButton label="Yes" Icon={HandThumbUpIcon} onPress={() => void run("approve")} accessibilityLabel="Vote yes" />
|
|
270
|
+
</View>
|
|
271
|
+
) : late && (canFinalize || canExecute) ? (
|
|
272
|
+
<View style={{ gap: 8 }}>
|
|
273
|
+
<Note tone="warn">
|
|
274
|
+
{canFinalize
|
|
275
|
+
? "Closing this vote is taking longer than usual. You can close it yourself; your wallet pays the network fee."
|
|
276
|
+
: "Applying this proposal is taking longer than usual. You can apply it yourself; your wallet pays the network fee."}
|
|
277
|
+
</Note>
|
|
278
|
+
<ActionButton
|
|
279
|
+
label={canFinalize ? "Close the vote now" : "Apply it now"}
|
|
280
|
+
variant="secondary"
|
|
281
|
+
onPress={() => void run(canFinalize ? "finalize" : "execute")}
|
|
282
|
+
/>
|
|
264
283
|
</View>
|
|
284
|
+
) : waiting ? (
|
|
285
|
+
<Note>{settled ? (outcome === "approved" ? "The vote passed. The changes apply automatically in a moment." : "The vote failed. It closes automatically in a moment.") : "Passed. The changes are being applied automatically."}</Note>
|
|
265
286
|
) : canFinalize ? (
|
|
266
287
|
<ActionButton label="Close the vote" onPress={() => void run("finalize")} />
|
|
267
288
|
) : canExecute ? (
|
|
268
|
-
<ActionButton label="
|
|
289
|
+
<ActionButton label="Apply the changes" onPress={() => void run("execute")} />
|
|
269
290
|
) : canSubmit ? (
|
|
270
291
|
<ActionButton label="Open voting" onPress={() => void run("submit")} />
|
|
292
|
+
) : data.status === "draft" && !isCreator ? (
|
|
293
|
+
<Note>Waiting for the proposer to open voting.</Note>
|
|
294
|
+
) : null}
|
|
295
|
+
|
|
296
|
+
{canCancel && !blocked && !busy ? (
|
|
297
|
+
<View style={{ gap: 8 }}>
|
|
298
|
+
<Note>If these changes can’t be applied, you can cancel the proposal. Its reserve goes back to whoever paid it.</Note>
|
|
299
|
+
<ActionButton label="Cancel proposal" variant="secondary" onPress={() => void run("cancel")} />
|
|
300
|
+
</View>
|
|
271
301
|
) : null}
|
|
272
302
|
|
|
273
303
|
{error ? <Note tone="bad">{error}</Note> : null}
|
|
@@ -278,8 +308,5 @@ function GuildProposalCard({
|
|
|
278
308
|
const styles = StyleSheet.create({
|
|
279
309
|
track: { borderRadius: 3, flexDirection: "row", height: 6, overflow: "hidden" },
|
|
280
310
|
legend: { flexDirection: "row", justifyContent: "space-between", gap: 12 },
|
|
281
|
-
|
|
282
|
-
dot: { borderRadius: 3, height: 6, marginTop: 6, width: 6 },
|
|
283
|
-
buttons: { flexDirection: "row", gap: 8 },
|
|
284
|
-
flex: { flex: 1 },
|
|
311
|
+
buttons: { alignItems: "center", flexDirection: "row", gap: 8, justifyContent: "flex-end" },
|
|
285
312
|
});
|
package/src/refs/index.tsx
CHANGED
|
@@ -37,6 +37,7 @@ export { SubscriptionRef } from "./SubscriptionRef";
|
|
|
37
37
|
export { TradeRef } from "./TradeRef";
|
|
38
38
|
export { DualStakeRef } from "./DualStakeRef";
|
|
39
39
|
export { GuildProposalRef } from "./GuildProposalRef";
|
|
40
|
+
export { GuildActionList, GuildPluginDetails } from "./GuildActions";
|
|
40
41
|
export { PageCardRef, PageLinksProvider, PrivateContentRef, type PageLinks } from "./HostRefs";
|
|
41
42
|
export { useAssetInfo, useFormattedAmount, ALGO_ASSET, type AssetInfo } from "./assetInfo";
|
|
42
43
|
export { Amount, StatusChip, ProvenanceNote, useNow } from "./contractParts";
|
package/src/refs/primitives.tsx
CHANGED
|
@@ -110,11 +110,11 @@ export function Avatar({ uri, size, shape = "circle", initial, icon }: AvatarPro
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/** The tile for kinds without their own image: the kind's icon on a primary tint. */
|
|
113
|
-
export function KindTile({ Icon, size, dim }: { Icon: IconComponent; size: number; dim?: boolean }) {
|
|
113
|
+
export function KindTile({ Icon, size, dim, color }: { Icon: IconComponent; size: number; dim?: boolean; color?: string }) {
|
|
114
114
|
const { theme, tint } = usePalette();
|
|
115
115
|
return (
|
|
116
116
|
<View style={[styles.center, { width: size, height: size, borderRadius: Math.max(4, size / 4), backgroundColor: dim ? theme.colors.border : tint }]}>
|
|
117
|
-
<Icon size={Math.round(size * 0.48)} color={dim ? theme.colors.textDim : theme.colors.primary} />
|
|
117
|
+
<Icon size={Math.round(size * 0.48)} color={dim ? theme.colors.textDim : (color ?? theme.colors.primary)} />
|
|
118
118
|
</View>
|
|
119
119
|
);
|
|
120
120
|
}
|
|
@@ -130,18 +130,20 @@ export interface InlinePillProps {
|
|
|
130
130
|
leading?: React.ReactNode;
|
|
131
131
|
trailing?: React.ReactNode;
|
|
132
132
|
dim?: boolean;
|
|
133
|
+
/** Tints the pill with the primary color, to pick a name out of a sentence. */
|
|
134
|
+
highlight?: boolean;
|
|
133
135
|
onPress?: () => void;
|
|
134
136
|
onLongPress?: () => void;
|
|
135
137
|
accessibilityLabel?: string;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
/** The inline shape. It is a View, so it can sit inside a Text run. */
|
|
139
|
-
export function InlinePill({ label, leading, trailing, dim, onPress, onLongPress, accessibilityLabel }: InlinePillProps) {
|
|
141
|
+
export function InlinePill({ label, leading, trailing, dim, highlight, onPress, onLongPress, accessibilityLabel }: InlinePillProps) {
|
|
140
142
|
const { theme } = useAppTheme();
|
|
141
143
|
const pill = (
|
|
142
|
-
<View style={[styles.pill, { backgroundColor: theme.colors.accentBackground, opacity: dim ? 0.6 : 1 }]}>
|
|
144
|
+
<View style={[styles.pill, { backgroundColor: highlight ? `${theme.colors.primary}24` : theme.colors.accentBackground, opacity: dim ? 0.6 : 1 }]}>
|
|
143
145
|
{leading}
|
|
144
|
-
<Text weight="medium" numberOfLines={1} style={[styles.pillText, { color: theme.colors.text }]}>
|
|
146
|
+
<Text weight="medium" numberOfLines={1} style={[styles.pillText, { color: highlight ? theme.colors.primary : theme.colors.text }]}>
|
|
145
147
|
{label}
|
|
146
148
|
</Text>
|
|
147
149
|
{trailing}
|
|
@@ -225,7 +227,13 @@ export function Card({ children, style }: { children: React.ReactNode; style?: S
|
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
export interface CardHeaderProps {
|
|
228
|
-
|
|
230
|
+
/** The image or kind tile. Leave out when the eyebrow already names the kind. */
|
|
231
|
+
media?: React.ReactNode;
|
|
232
|
+
/**
|
|
233
|
+
* The card's kind above the title, like the auction, listing and raffle
|
|
234
|
+
* cards: a small icon and an uppercase label in the kind's colour.
|
|
235
|
+
*/
|
|
236
|
+
eyebrow?: { label: string; Icon?: IconComponent; color?: string };
|
|
229
237
|
title: React.ReactNode;
|
|
230
238
|
verified?: boolean;
|
|
231
239
|
/** A status badge, shown before the meta line. */
|
|
@@ -244,12 +252,21 @@ export interface CardHeaderProps {
|
|
|
244
252
|
* line of context under it. Status sits under the title so a long name keeps
|
|
245
253
|
* the full width on a phone.
|
|
246
254
|
*/
|
|
247
|
-
export function CardHeader({ media, title, verified, status, meta, menu, full, titleLines = 2 }: CardHeaderProps) {
|
|
255
|
+
export function CardHeader({ media, eyebrow, title, verified, status, meta, menu, full, titleLines = 2 }: CardHeaderProps) {
|
|
248
256
|
const { theme } = useAppTheme();
|
|
257
|
+
const eyebrowColor = eyebrow?.color ?? theme.colors.primary;
|
|
249
258
|
return (
|
|
250
259
|
<View style={styles.header}>
|
|
251
260
|
{media}
|
|
252
261
|
<View style={styles.headerText}>
|
|
262
|
+
{eyebrow ? (
|
|
263
|
+
<View style={styles.eyebrow}>
|
|
264
|
+
{eyebrow.Icon ? <eyebrow.Icon size={13} color={eyebrowColor} /> : null}
|
|
265
|
+
<Text size="xxs" weight="semiBold" numberOfLines={1} style={{ color: eyebrowColor, letterSpacing: 0.6, textTransform: "uppercase" }}>
|
|
266
|
+
{eyebrow.label}
|
|
267
|
+
</Text>
|
|
268
|
+
</View>
|
|
269
|
+
) : null}
|
|
253
270
|
<View style={styles.inlineRow}>
|
|
254
271
|
{typeof title === "string" ? (
|
|
255
272
|
<Text size={full ? "lg" : "md"} weight="bold" numberOfLines={titleLines} style={{ flexShrink: 1 }}>
|
|
@@ -388,14 +405,31 @@ export function StatusBadge({ label, tone = "neutral" }: { label: string; tone?:
|
|
|
388
405
|
export interface ActionButtonProps {
|
|
389
406
|
label: string;
|
|
390
407
|
onPress: () => void;
|
|
391
|
-
/**
|
|
392
|
-
|
|
408
|
+
/**
|
|
409
|
+
* `secondary` is a quiet fill for the second of two actions. `text` has no
|
|
410
|
+
* fill, for an action to de-emphasize.
|
|
411
|
+
*/
|
|
412
|
+
variant?: "primary" | "secondary" | "text";
|
|
413
|
+
/** Draws the icon in place of the label, in a button only as wide as it needs. The label stays for accessibility. */
|
|
414
|
+
Icon?: IconComponent;
|
|
393
415
|
accessibilityLabel?: string;
|
|
394
416
|
}
|
|
395
417
|
|
|
396
418
|
/** The card's action, drawn like the Akita app's confirm buttons. */
|
|
397
|
-
export function ActionButton({ label, onPress, variant = "primary", accessibilityLabel }: ActionButtonProps) {
|
|
419
|
+
export function ActionButton({ label, onPress, variant = "primary", Icon, accessibilityLabel }: ActionButtonProps) {
|
|
398
420
|
const { theme, inset } = usePalette();
|
|
421
|
+
const color = variant === "primary" ? theme.gradients.interactiveText : variant === "text" ? theme.colors.textDim : theme.colors.text;
|
|
422
|
+
const content = Icon ? (
|
|
423
|
+
// Positioned, so the web renderer paints it above the gradient fill.
|
|
424
|
+
<View style={{ position: "relative" }}>
|
|
425
|
+
<Icon size={20} color={color} />
|
|
426
|
+
</View>
|
|
427
|
+
) : (
|
|
428
|
+
<Text size="sm" weight={variant === "text" ? "semiBold" : "bold"} numberOfLines={1} style={{ color }}>
|
|
429
|
+
{label}
|
|
430
|
+
</Text>
|
|
431
|
+
);
|
|
432
|
+
const shape = StyleSheet.flatten([styles.button, Icon && styles.iconButton, variant === "text" && styles.textButton]);
|
|
399
433
|
return (
|
|
400
434
|
<SquishyPressable pressedScale={0.97} onPress={onPress} accessibilityRole="button" accessibilityLabel={accessibilityLabel ?? label}>
|
|
401
435
|
{variant === "primary" ? (
|
|
@@ -404,18 +438,12 @@ export function ActionButton({ label, onPress, variant = "primary", accessibilit
|
|
|
404
438
|
locations={theme.gradients.interactiveLocations ? [...theme.gradients.interactiveLocations] : undefined}
|
|
405
439
|
start={{ x: 0, y: 0 }}
|
|
406
440
|
end={{ x: 1, y: 0 }}
|
|
407
|
-
style={
|
|
441
|
+
style={shape}
|
|
408
442
|
>
|
|
409
|
-
|
|
410
|
-
{label}
|
|
411
|
-
</Text>
|
|
443
|
+
{content}
|
|
412
444
|
</LinearGradient>
|
|
413
445
|
) : (
|
|
414
|
-
<View style={[
|
|
415
|
-
<Text size="sm" weight="bold" numberOfLines={1}>
|
|
416
|
-
{label}
|
|
417
|
-
</Text>
|
|
418
|
-
</View>
|
|
446
|
+
<View style={[shape, variant === "secondary" && { backgroundColor: inset }]}>{content}</View>
|
|
419
447
|
)}
|
|
420
448
|
</SquishyPressable>
|
|
421
449
|
);
|
|
@@ -570,6 +598,7 @@ const styles = StyleSheet.create({
|
|
|
570
598
|
card: { borderRadius: 16, gap: 16, overflow: "hidden", padding: 16 },
|
|
571
599
|
header: { alignItems: "center", flexDirection: "row", gap: 12 },
|
|
572
600
|
headerText: { flex: 1, minWidth: 0, gap: 4 },
|
|
601
|
+
eyebrow: { alignItems: "center", flexDirection: "row", gap: 4, marginBottom: -2 },
|
|
573
602
|
metaRow: { alignItems: "center", flexDirection: "row", flexWrap: "wrap", columnGap: 8, rowGap: 2 },
|
|
574
603
|
statRow: { borderRadius: 14, flexDirection: "row", gap: 12, paddingHorizontal: 14, paddingVertical: 12 },
|
|
575
604
|
inset: { borderRadius: 14, paddingHorizontal: 14, paddingVertical: 4 },
|
|
@@ -585,4 +614,7 @@ const styles = StyleSheet.create({
|
|
|
585
614
|
badge: { alignItems: "center", flexDirection: "row", gap: 5 },
|
|
586
615
|
dot: { borderRadius: 3, height: 6, marginHorizontal: 3, width: 6 },
|
|
587
616
|
button: { alignItems: "center", borderRadius: 14, height: 48, justifyContent: "center", paddingHorizontal: 16 },
|
|
617
|
+
// Icon buttons are pills: the radius is half the 48px height.
|
|
618
|
+
iconButton: { borderRadius: 24, paddingHorizontal: 28 },
|
|
619
|
+
textButton: { paddingHorizontal: 8 },
|
|
588
620
|
});
|