Skip to content

Commit b9de01e

Browse files
authored
chore: adapted TokenCard for swaps (#156)
1 parent 9e735e2 commit b9de01e

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

src/components/modules/tokens/card/card.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ export const Decreasing: Story = {
4040
change: "-$1.78",
4141
},
4242
};
43+
44+
export const IncreasingAmount: Story = {
45+
args: {
46+
value: "$31.40",
47+
increasing: true,
48+
clickable: false,
49+
},
50+
};
51+
52+
export const DecreasingAmount: Story = {
53+
args: {
54+
value: "$31.40",
55+
decreasing: true,
56+
clickable: false,
57+
},
58+
};

src/components/modules/tokens/card/card.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ export interface TokenCardProps
1313
image: string | React.ReactNode;
1414
title: string | React.ReactNode;
1515
amount: string;
16+
increasing?: boolean;
17+
decreasing?: boolean;
1618
value?: string;
1719
change?: string;
20+
clickable?: boolean;
1821
className?: string;
1922
}
2023

2124
export const TokenCard = ({
2225
image,
2326
title,
2427
amount,
28+
increasing,
29+
decreasing,
2530
value,
2631
change,
32+
clickable = true,
2733
variant,
2834
className,
2935
...props
@@ -43,25 +49,43 @@ export const TokenCard = ({
4349
);
4450

4551
const style = useMemo(() => {
46-
if (change?.includes("+")) {
52+
if (increasing || change?.includes("+")) {
4753
return {
4854
backgroundImage: `linear-gradient(to right,transparent,color-mix(in srgb, var(--constructive-100) 3%, transparent))`,
4955
};
5056
}
51-
if (change?.includes("-")) {
57+
if (decreasing || change?.includes("-")) {
5258
return {
5359
backgroundImage: `linear-gradient(to right,transparent,color-mix(in srgb, var(--destructive-100) 3%, transparent))`,
5460
};
5561
}
5662
return {};
57-
}, [change]);
63+
}, [change, increasing, decreasing]);
64+
65+
const Amount = useMemo(() => {
66+
if (increasing) {
67+
return <p className="text-constructive-100">+{amount}</p>;
68+
}
69+
if (decreasing) {
70+
return <p className="text-destructive-100">-{amount}</p>;
71+
}
72+
return <>{amount}</>;
73+
}, [amount, increasing, decreasing]);
5874

5975
const Change = useMemo(() => {
6076
if (change?.includes("+")) {
61-
return <p className="text-constructive-100">{change}</p>;
77+
return (
78+
<p className="text-constructive-100">
79+
{change}
80+
</p>
81+
);
6282
}
6383
if (change?.includes("-")) {
64-
return <p className="text-destructive-100">{change}</p>;
84+
return (
85+
<p className="text-destructive-100">
86+
{change}
87+
</p>
88+
);
6589
}
6690
return <></>;
6791
}, [change]);
@@ -70,11 +94,11 @@ export const TokenCard = ({
7094
<ActivityCard
7195
Logo={Logo}
7296
title={title}
73-
subTitle={amount}
97+
subTitle={Amount}
7498
topic={value}
7599
subTopic={Change}
76100
variant={variant}
77-
className={cn("rounded-none", className)}
101+
className={cn("rounded-none", !clickable && "pointer-events-none", className)}
78102
style={style}
79103
onMouseEnter={() => setHover(true)}
80104
onMouseLeave={() => setHover(false)}

src/components/modules/tokens/summary/summary.stories.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Story = StoryObj<typeof TokenSummary>;
1616

1717
export const Default: Story = {
1818
render: () => (
19-
<TokenSummary>
19+
<TokenSummary title="Tokens">
2020
<TokenCard
2121
image={"https://static.cartridge.gg/presets/credit/icon.svg"}
2222
title={"Credits"}
@@ -59,6 +59,26 @@ export const Default: Story = {
5959
value={"$31.40"}
6060
change={"+$1.78"}
6161
/>
62+
<TokenCard
63+
image={
64+
"https://imagedelivery.net/0xPAQaDtnQhBs8IzYRIlNg/a3bfe959-50c4-4f89-0aef-b19207d82a00/logo"
65+
}
66+
title={"Lords"}
67+
amount={"0.01 LORDS"}
68+
value={"$31.40"}
69+
decreasing
70+
clickable={false}
71+
/>
72+
<TokenCard
73+
image={
74+
"https://imagedelivery.net/0xPAQaDtnQhBs8IzYRIlNg/811f019a-0461-4cff-6c1e-442102863f00/logo"
75+
}
76+
title={"Paper"}
77+
amount={"0.01 PAPER"}
78+
value={"$31.40"}
79+
increasing
80+
clickable={false}
81+
/>
6282
</TokenSummary>
6383
),
6484
};

src/components/modules/tokens/summary/summary.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { CardContent } from "@/index";
12
import { cn } from "@/utils";
23
import { cva, VariantProps } from "class-variance-authority";
34

45
export interface TokenSummaryProps
5-
extends React.HTMLAttributes<HTMLDivElement>,
6-
VariantProps<typeof tokenSummaryVariants> {}
6+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "title">,
7+
VariantProps<typeof tokenSummaryVariants> {
8+
title?: string | React.ReactNode;
9+
}
710

811
const tokenSummaryVariants = cva(
912
"rounded overflow-y-scroll w-full flex flex-col gap-y-px",
@@ -20,6 +23,7 @@ const tokenSummaryVariants = cva(
2023
);
2124

2225
export const TokenSummary = ({
26+
title,
2327
variant,
2428
className,
2529
children,
@@ -31,6 +35,11 @@ export const TokenSummary = ({
3135
{...props}
3236
style={{ scrollbarWidth: "none" }}
3337
>
38+
{title && (
39+
<CardContent className="text-foreground-400">
40+
{title}
41+
</CardContent>
42+
)}
3443
{children}
3544
</div>
3645
);

0 commit comments

Comments
 (0)