-
Notifications
You must be signed in to change notification settings - Fork 5k
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
[ShadCN]: Move Color Stories to Tailwind #14915
Merged
pettinarip
merged 6 commits into
ethereum:dev
from
TylerAPfledderer:feat/color-stories-tailwind
Feb 17, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbe11ec
feat: move primitive color story to tailwind
TylerAPfledderer f06889f
feat: move semantic color story to tailwind
TylerAPfledderer 9a88036
chore: remove old colors story file
TylerAPfledderer 47c18ca
chore:(.storybook/main): remove commented story path
TylerAPfledderer fd0db90
chore(colors.stories): revert name of story title set
TylerAPfledderer b11ea8c
Merge remote-tracking branch 'upstream/dev' into feat/color-stories-t…
TylerAPfledderer 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
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 was deleted.
Oops, something went wrong.
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,149 @@ | ||
import { type ReactNode } from "react" | ||
import capitalize from "lodash/capitalize" | ||
import type { Meta, StoryObj } from "@storybook/react" | ||
|
||
import { HStack, Stack, VStack } from "@/components/ui/flex" | ||
|
||
import { cn } from "@/lib/utils/cn" | ||
|
||
const meta = { | ||
title: "Design System / Colors", | ||
parameters: { | ||
// Do not create snapshots for any stories in the file. | ||
chromatic: { disableSnapshot: true }, | ||
}, | ||
} satisfies Meta | ||
|
||
export default meta | ||
|
||
/** | ||
* Get all CSS Variables in the document. | ||
* | ||
* Used to search CSS Variables and retrieve their values. | ||
* | ||
* NOTE: Function created with AI assistance | ||
*/ | ||
const getCSSCustomPropIndex = () => { | ||
const rootStyles = document.styleSheets | ||
const variables = {} | ||
|
||
for (const sheet of rootStyles) { | ||
for (const rule of sheet.cssRules) { | ||
// Check for CSSStyleRule type as `selectorText` might not always be available | ||
if (rule instanceof CSSStyleRule && rule.selectorText === ":root") { | ||
for (const style of rule.style) { | ||
if (style.startsWith("--")) { | ||
variables[style] = rule.style.getPropertyValue(style).trim() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return variables as Record<string, string> | ||
} | ||
|
||
const cssVarsEntries = Object.entries(getCSSCustomPropIndex()) | ||
|
||
const primitiveColorKeys = ["gray", "purple"] as const | ||
export const Primitives: StoryObj = { | ||
render: () => { | ||
return ( | ||
<Stack className="gap-16"> | ||
{primitiveColorKeys.map((color) => ( | ||
<ColorGroupWrapper key={color} color={color}> | ||
<HStack className="justify-between gap-4"> | ||
{cssVarsEntries | ||
.filter(([key]) => key.startsWith(`--${color}`)) | ||
.map(([tokenKey, value]) => ( | ||
<VStack key={`${tokenKey}-${value}`}> | ||
<div> | ||
<div | ||
className="size-20" | ||
style={{ background: `hsla(var(${tokenKey}))` }} | ||
/> | ||
</div> | ||
<Stack> | ||
<span>{value}</span> | ||
<span>{tokenKey}</span> | ||
</Stack> | ||
</VStack> | ||
))} | ||
</HStack> | ||
</ColorGroupWrapper> | ||
))} | ||
</Stack> | ||
) | ||
}, | ||
} | ||
|
||
const ColorGroupWrapper = ({ | ||
color, | ||
children, | ||
}: { | ||
color: (typeof primitiveColorKeys)[number] | ||
children: ReactNode | ||
}) => ( | ||
<div | ||
key={color} | ||
className="bg-gradient-to-t from-[#1b1b1b] from-65% to-white to-35% p-8 text-white" | ||
> | ||
{children} | ||
</div> | ||
) | ||
|
||
export const SemanticScheme: StoryObj = { | ||
render: () => { | ||
const tokenNames = [ | ||
"primary", | ||
"body", | ||
"background", | ||
"disabled", | ||
"success", | ||
"warning", | ||
"error", | ||
] as const | ||
|
||
return ( | ||
<Stack className="gap-16"> | ||
{tokenNames.map((tokenName) => { | ||
const variableObj = cssVarsEntries.filter(([key]) => | ||
key.startsWith(`--${tokenName}`) | ||
) | ||
|
||
return ( | ||
<Stack key={tokenName} className="gap-4"> | ||
<h2>{capitalize(tokenName)}</h2> | ||
<HStack className="gap-8"> | ||
{variableObj.map((variable) => ( | ||
<SemanticColorBlock | ||
key={JSON.stringify(variable)} | ||
variable={variable} | ||
/> | ||
))} | ||
</HStack> | ||
</Stack> | ||
) | ||
})} | ||
</Stack> | ||
) | ||
}, | ||
} | ||
|
||
const SemanticColorBlock = ({ | ||
variable: [varName, varValue], | ||
}: { | ||
variable: [string, string] | ||
}) => ( | ||
<VStack key={`${varName}-${varValue}`} className="mb-auto"> | ||
<div | ||
className={cn( | ||
"size-20", | ||
varName === "--background" || varName === "--body-inverse" | ||
? "border" | ||
: undefined | ||
)} | ||
style={{ background: `hsla(var(${varName}))` }} | ||
/> | ||
<span>{varName}</span> | ||
</VStack> | ||
) |
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.
😆 nice!