Skip to content

Commit

Permalink
image overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Mar 31, 2024
1 parent e47cde5 commit ec88f58
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
11 changes: 11 additions & 0 deletions packages/nextjs/app/rep-tokens-demo/_components/RepTokensDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAccount } from "wagmi";
import { tokenGroupCardConfigProps as mainTokenGroupCardConfigProps } from "~~/app/rep-tokens-demo/_components/configs/MainTokensCardConfig";
import { tokenGroupCardConfigProps as mainTokenGroupOverlayCardConfigProps } from "~~/app/rep-tokens-demo/_components/configs/MainTokensCardWithNumberOverlayConfig";
import { tokenGroupCardConfigProps as navBarTokenGroupConfigProps } from "~~/app/rep-tokens-demo/_components/configs/NavBarCardConfig";
import { BalanceImageOverlay } from "~~/components/rep-tokens/cards/stylized-cards/BalanceImageOverlay";
import { StylizedAddressCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedAddressCard";
import { StylizedBalanceCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedBalanceCard";
import { StylizedImageCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedImageCard";
Expand Down Expand Up @@ -182,12 +183,16 @@ export function RepTokensDemo() {
"MaxMintAmountPerTx",
];

const widgetComponents = ["Balance", "Image"];

return (
<>
<div className="py-5 space-y-5 flex flex-col justify-center items-center bg-primary bg-[length:100%_100%] py-1 px-5 sm:px-0 lg:py-auto max-w-[100vw] ">
<StylizedTokenCard>
<StylizedBalanceCard value={Number(tokensData.tokens[0]?.balance)} />
<StylizedImageCard src={tokensData.tokens[0]?.image} />
<BalanceImageOverlay balance={Number(tokensData.tokens[0]?.balance)} image={tokensData.tokens[0]?.image} />

<StylizedStringCard value={tokensData.tokens[0]?.name} color="violet" type="bold" />
<StylizedStringCard value={tokensData.tokens[0]?.description} color="lime" />
<StylizedAddressCard address={tokensData.tokens[0]?.address} color="pink" />
Expand All @@ -209,6 +214,12 @@ export function RepTokensDemo() {
<StylizedAddressCard address={tokensData.address} isGroup={true} />
</StylizedTokenGroupCard>

<StylizedTokenGroupCard tokens={tokensData.tokens} components={mainComponents} isBalanceOverlayed={true}>
<StylizedAddressCard address={tokensData.address} isGroup={true} />
</StylizedTokenGroupCard>

<StylizedTokenGroupCard tokens={tokensData.tokens} components={widgetComponents} isBalanceOverlayed={true} />

<p>Faucet Balance:</p>
<p>
0: {balanceOf0?.toString()}, 1: {balanceOf1?.toString()}, 2: {balanceOf2?.toString()}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Color } from "./Stylized";
import { StylizedBalanceCard } from "./StylizedBalanceCard";
import { StylizedImageCard } from "./StylizedImageCard";

type BalanceProps = {
balance: number;
image: string;
color?: Color;
};

export const BalanceImageOverlay = ({ balance, image }: BalanceProps) => {
return (
<div className="relative">
<StylizedBalanceCard value={Number(balance)} isOverlay />
<StylizedImageCard src={image} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ import { Color } from "./Stylized";
type BalanceProps = {
value: number;
color?: Color;
isOverlay?: boolean;
};

export const StylizedBalanceCard = ({ value, color = "slate" }: BalanceProps) => {
export const StylizedBalanceCard = ({ value, color = "slate", isOverlay }: BalanceProps) => {
let cardClasses;
let textClasses;

if (isOverlay) {
cardClasses = "absolute inset-10 items-center justify-center";
textClasses = "text-9xl mx-auto text-center text-black";
} else {
cardClasses = `rounded-lg bg-${color}-300`;
textClasses = "text-4xl mx-auto text-center text-black";
}

return (
<div className={`rounded-lg bg-${color}-300`}>
<p className="text-4xl mx-auto text-center text-black">{value.toString()}</p>
<div className={cardClasses}>
<p className={textClasses}>{value.toString()}</p>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface TokenCardInternalProps {
}

export const StylizedTokenCard = ({ color = "slate", children }: any) => {
return <div className={`bg-${color}-600 rounded-lg p-5 m-4 w-64`}>{children}</div>;
return <div className={`bg-${color}-600 rounded-lg relative p-5 m-4 w-64`}>{children}</div>;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BalanceImageOverlay } from "./BalanceImageOverlay";
import { Color } from "./Stylized";
import { StylizedAddressCard } from "./StylizedAddressCard";
import { StylizedBalanceCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedBalanceCard";
Expand All @@ -9,6 +10,7 @@ export interface TokenCardInternalProps {
tokens: any[];
components?: ReputationComponent[];
color?: Color;
isBalanceOverlayed?: boolean;
}

export type ReputationComponent =
Expand All @@ -34,7 +36,7 @@ export const StylizedTokenGroupCard = ({
"MaxMintAmountPerTx",
],
color = "slate",

isBalanceOverlayed,
children,
}: any) => {
const output: any[] = [];
Expand All @@ -44,11 +46,40 @@ export const StylizedTokenGroupCard = ({

for (let j = 0; j < components?.length; j++) {
if (components[j] === "Balance") {
cardContent.push(<StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} />);
if (isBalanceOverlayed) {
let doesImageComponentExist;
for (let k = 0; k < components?.length; k++) {
if (k === j) continue;

if (components[k] === "Image") {
doesImageComponentExist = true;
break;
}
}

if (doesImageComponentExist) {
cardContent.push(
<BalanceImageOverlay key={j} balance={Number(tokens[i]?.balance)} image={tokens[i]?.image} />,
);
} else {
cardContent.push(<StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} />);
}
} else {
cardContent.push(<StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} />);
}
}

if (components[j] === "Image") {
cardContent.push(<StylizedImageCard key={j} src={tokens[i]?.image} />);
// if (components[j] == "Balance")
// if (components[j] === "Balance") {
// cardContent.push(
// <StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={isBalanceOverlayed} />,
// );
// }

if (!isBalanceOverlayed) {
if (components[j] === "Image") {
cardContent.push(<StylizedImageCard key={j} src={tokens[i]?.image} />);
}
}

if (components[j] === "Name") {
Expand Down

0 comments on commit ec88f58

Please sign in to comment.