-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: requirement building blocks #1571
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9da305d
feat: DataBlock component
BrickheadJohnny 1a8cc14
feat: ChainIndicator component
BrickheadJohnny b6bea92
feat: simplify the DataBlock component
BrickheadJohnny f3b52f1
feat: DataBlockWithCopy component
BrickheadJohnny 7eff16f
feat: Requirement compound component
BrickheadJohnny 2c5717f
feat: RequirementLink component
BrickheadJohnny dcbf40c
cleanup(DataBlock): remove unused stuff
BrickheadJohnny e1aa4a8
cleanup: simplify DataBlock stories
BrickheadJohnny 20286f6
fix(DataBlockWithCopy): adjust height, add `"use client"`
BrickheadJohnny 0ecff9f
fix(Providers): add TooltipProvider
BrickheadJohnny a01ffb6
fix(DataBlockWithCopy): tooltip trigger
BrickheadJohnny b746210
fix(DataBlockWithCopy): remove icon color
BrickheadJohnny c46e396
refactor: make a `SupportedChainID` type
BrickheadJohnny 6d25877
fix(Button): adjust spacing for `sm` size
BrickheadJohnny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Badge } from "@/components/ui/Badge"; | ||
import { CHAINS } from "@/config/chains"; | ||
import type { Register } from "wagmi"; | ||
|
||
export const ChainIndicator = ({ | ||
chain, | ||
}: { chain: Register["config"]["chains"][number]["id"] }) => ( | ||
<Badge size="sm"> | ||
<img | ||
src={CHAINS[chain].icon} | ||
alt={CHAINS[chain].name} | ||
className="size-3.5" | ||
/> | ||
<span>{CHAINS[chain].name}</span> | ||
</Badge> | ||
); |
BrickheadJohnny marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PropsWithChildren } from "react"; | ||
|
||
export const DataBlock = ({ children }: PropsWithChildren): JSX.Element => { | ||
return ( | ||
<span className="break-words rounded-md bg-blackAlpha px-1.5 py-0.5 font-mono text-sm dark:bg-blackAlpha-hard"> | ||
{children} | ||
</span> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipPortal, | ||
TooltipTrigger, | ||
} from "@/components/ui/Tooltip"; | ||
import { Check } from "@phosphor-icons/react/dist/ssr"; | ||
import { useClipboard } from "foxact/use-clipboard"; | ||
import { useDebouncedState } from "foxact/use-debounced-state"; | ||
import { type PropsWithChildren, useEffect } from "react"; | ||
import { DataBlock } from "./DataBlock"; | ||
|
||
type Props = { | ||
text: string; | ||
}; | ||
|
||
export const DataBlockWithCopy = ({ | ||
text, | ||
children, | ||
}: PropsWithChildren<Props>): JSX.Element => { | ||
const { copied, copy } = useClipboard({ | ||
timeout: 1500, | ||
}); | ||
|
||
/** | ||
* Maintaining a debounced copied state too, so we can change the tooltip content only after the tooltip is actually invisible | ||
*/ | ||
|
||
const [debouncedCopied, debouncilySetState] = useDebouncedState(copied, 200); | ||
|
||
useEffect(() => { | ||
debouncilySetState(copied); | ||
}, [debouncilySetState, copied]); | ||
|
||
const tooltipInCopiedState = copied || debouncedCopied; | ||
|
||
return ( | ||
<Tooltip open={copied || undefined}> | ||
<TooltipTrigger onClick={() => copy(text)} className="rounded-md"> | ||
<DataBlock> | ||
<span>{children ?? text}</span> | ||
</DataBlock> | ||
</TooltipTrigger> | ||
|
||
<TooltipPortal> | ||
<TooltipContent side="top" className="flex items-center gap-1.5"> | ||
{tooltipInCopiedState && ( | ||
<Check weight="bold" className="text-icon-success" /> | ||
)} | ||
<span>{tooltipInCopiedState ? "Copied" : "Click to copy"}</span> | ||
</TooltipContent> | ||
</TooltipPortal> | ||
</Tooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { cn } from "@/lib/cssUtils"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
export const Requirement = ({ | ||
className, | ||
children, | ||
}: PropsWithChildren<{ className?: string }>) => ( | ||
<div className={cn("flex w-full items-center gap-4 py-2", className)}> | ||
{children} | ||
</div> | ||
); | ||
|
||
export const RequirementImage = ({ | ||
className, | ||
children, | ||
}: PropsWithChildren<{ className?: string }>) => ( | ||
<div | ||
className={cn( | ||
"flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-full bg-blackAlpha dark:bg-blackAlpha-hard", | ||
className, | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); | ||
|
||
export const RequirementContent = ({ | ||
className, | ||
children, | ||
}: PropsWithChildren<{ className?: string }>) => ( | ||
<div className={cn("flex flex-grow flex-col items-start", className)}> | ||
{children} | ||
</div> | ||
); | ||
|
||
export const RequirementFooter = ({ | ||
className, | ||
children, | ||
}: PropsWithChildren<{ className?: string }>) => ( | ||
<div | ||
className={cn( | ||
"flex flex-wrap items-center gap-1.5 has-[>*]:mt-1", | ||
className, | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { PropsWithChildren } from "react"; | ||
import { Anchor } from "../ui/Anchor"; | ||
|
||
export const RequirementLink = ({ | ||
href, | ||
children, | ||
}: PropsWithChildren<{ href: string }>) => ( | ||
<Anchor | ||
href={href} | ||
target="_blank" | ||
rel="noopener" | ||
variant="secondary" | ||
showExternal | ||
className="font-medium text-xs" | ||
> | ||
{children} | ||
</Anchor> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ export const badgeVariants = cva( | |
{ | ||
variants: { | ||
size: { | ||
sm: "text-xs h-5", | ||
sm: "text-xs h-5 gap-1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could have this on all sizes like on button. |
||
md: "text-sm h-6", | ||
lg: "text-base h-8", | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { mainnet, sepolia } from "viem/chains"; | ||
import type { Register } from "wagmi"; | ||
|
||
export const CHAINS = { | ||
[mainnet.id]: { | ||
name: mainnet.name, | ||
icon: "/chainLogos/eth.svg", | ||
}, | ||
[sepolia.id]: { | ||
name: sepolia.name, | ||
icon: "/chainLogos/eth.svg", | ||
}, | ||
} satisfies Record< | ||
Register["config"]["chains"][number]["id"], | ||
{ | ||
name: string; | ||
icon: string; | ||
} | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ChainIndicator } from "@/components/requirements/ChainIndicator"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof ChainIndicator> = { | ||
title: "Requirement building blocks/ChainIndicator", | ||
component: ChainIndicator, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ChainIndicator>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
chain: 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DataBlock } from "@/components/requirements/DataBlock"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof DataBlock> = { | ||
title: "Requirement building blocks/DataBlock", | ||
component: DataBlock, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DataBlock>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: "DataBlock", | ||
}, | ||
}; |
BrickheadJohnny marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DataBlockWithCopy } from "@/components/requirements/DataBlockWithCopy"; | ||
import { TooltipProvider } from "@/components/ui/Tooltip"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof DataBlockWithCopy> = { | ||
title: "Requirement building blocks/DataBlockWithCopy", | ||
component: DataBlockWithCopy, | ||
decorators: (Story) => ( | ||
<TooltipProvider> | ||
<Story /> | ||
</TooltipProvider> | ||
), | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DataBlockWithCopy>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: "DataBlockWithCopy", | ||
text: "DataBlockWithCopy", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ChainIndicator } from "@/components/requirements/ChainIndicator"; | ||
import { DataBlockWithCopy } from "@/components/requirements/DataBlockWithCopy"; | ||
import { | ||
Requirement, | ||
RequirementContent, | ||
RequirementFooter, | ||
RequirementImage, | ||
} from "@/components/requirements/Requirement"; | ||
import { RequirementLink } from "@/components/requirements/RequirementLink"; | ||
import { Card } from "@/components/ui/Card"; | ||
import { TooltipProvider } from "@/components/ui/Tooltip"; | ||
import { QuestionMark } from "@phosphor-icons/react/dist/ssr"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const RequirementExample = () => ( | ||
<Card className="max-w-sm px-6 py-4"> | ||
<Requirement> | ||
<RequirementImage> | ||
<QuestionMark weight="bold" className="size-6" /> | ||
</RequirementImage> | ||
<RequirementContent> | ||
<p> | ||
<span>{"Copy "}</span> | ||
<DataBlockWithCopy text="this text" /> | ||
<span>{" to your clipboard"}</span> | ||
</p> | ||
|
||
<RequirementFooter className="text-secondary text-sm"> | ||
<ChainIndicator chain={1} /> | ||
<RequirementLink href="https://polygonscan.com/token/0xff04820c36759c9f5203021fe051239ad2dcca8a"> | ||
View on explorer | ||
</RequirementLink> | ||
</RequirementFooter> | ||
</RequirementContent> | ||
</Requirement> | ||
</Card> | ||
); | ||
|
||
const meta: Meta<typeof RequirementExample> = { | ||
title: "Requirement building blocks/Requirement", | ||
component: RequirementExample, | ||
decorators: (Story) => ( | ||
<TooltipProvider> | ||
<Story /> | ||
</TooltipProvider> | ||
), | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof RequirementExample>; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RequirementLink } from "@/components/requirements/RequirementLink"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof RequirementLink> = { | ||
title: "Requirement building blocks/RequirementLink", | ||
component: RequirementLink, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof RequirementLink>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
href: "https://polygonscan.com/token/0xff04820c36759c9f5203021fe051239ad2dcca8a", | ||
children: "Guild Pin contract", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think, should we extract the
Register["config"]["chains"][number]["id"]
to a type somewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a common type, we can extract it into a wagmi type file.