-
Notifications
You must be signed in to change notification settings - Fork 36
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
fix: Fixed onSurface to have the correct camel casing #571
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c730cf2
WIP
BrianAA b59976a
new color doc, fixed onSurface token to camel case
BrianAA 6bef4fa
fix linting errors
BrianAA 335a700
revert concurrency for dev command
BrianAA fb0a049
Fixed search input
BrianAA 54834f5
fix title and reorganize
BrianAA 2162d10
Fix to Update ThemeTokens.jsx
BrianAA b9ba913
Update color.mdx
BrianAA adc2d3e
Fixed border token
BrianAA 4eb82da
Update ColorSamples.jsx to use tokens and theme
BrianAA d6f60bd
Update ThemeTokens.jsx
BrianAA 01146ad
Improving Rendering performance per Art recs.
BrianAA 1edadbe
Update ColorSamples.jsx
BrianAA 3c0927f
Resolve conflicting Theme
BrianAA b2614c4
Update color.mdx
BrianAA 4259048
Update color.mdx - adjusted spacing
BrianAA 7816557
Merge branch 'main' into doc-color-update
BrianAA bcfc609
format and update from main
BrianAA 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
227 changes: 138 additions & 89 deletions
227
build.washingtonpost.com/components/Markdown/Examples/ColorSamples.jsx
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 |
---|---|---|
@@ -1,106 +1,155 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Box, styled, AlertBanner, theme } from "@washingtonpost/wpds-ui-kit"; | ||
import { toast } from "react-toastify"; | ||
import { styled } from "@washingtonpost/wpds-ui-kit"; | ||
import Tokens from "@washingtonpost/wpds-theme/src/wpds.tokens.json"; | ||
import { hex, score } from "wcag-contrast"; | ||
import { useTheme } from "next-themes"; | ||
|
||
import { Grid } from "../Components/Grid"; | ||
const xMapping = [0, 20, 40, 60, 80, 100, 200, 300, 400, 500, 600, 700]; | ||
const yMapping = [ | ||
"red", | ||
"blue", | ||
"green", | ||
"orange", | ||
"teal", | ||
"gold", | ||
"mustard", | ||
"purple", | ||
"pink", | ||
"yellow", | ||
"gray", | ||
]; | ||
|
||
const ColorSamples = ({ group }) => { | ||
const [colorGroupArray, setColorGroupArray] = useState([]); | ||
const [copyText, setCopyText] = useState(""); | ||
const PaletteGrid = styled("div", { | ||
display: "grid", | ||
gridTemplateColumns: "30px repeat(12, 1fr)", | ||
gridTemplateRows: "repeat(11, 1fr)", // Adjusted to match yMapping length | ||
gap: "$025", | ||
}); | ||
|
||
useEffect(() => { | ||
const colorArray = handleColor(group); | ||
setColorGroupArray(colorArray); | ||
}, [group]); | ||
const Swatch = styled("div", { | ||
minWidth: 20, | ||
minHeight: 40, | ||
width: "100%", | ||
height: "100%", | ||
borderRadius: "4px", | ||
borderColor: "#e1e1e1", | ||
borderWidth: "1px", | ||
borderStyle: "solid", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
color: "black", // Default text color | ||
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. nit pick could we use a color token if possible |
||
"@sm": { | ||
minWidth: "unset", | ||
minHeight: "unset", | ||
}, | ||
"& div": { | ||
"@sm": { | ||
display: "none", | ||
}, | ||
}, | ||
}); | ||
const AxisLabel = styled("div", { | ||
fontWeight: "bold", | ||
display: "flex", | ||
alignItems: "end", | ||
justifyContent: "center", | ||
}); | ||
|
||
export default function ColorGrid() { | ||
const { theme } = useTheme(); | ||
const [context, setContext] = useState(Tokens.color.light); | ||
|
||
useEffect(() => { | ||
const SuccessToast = () => ( | ||
<AlertBanner.Root variant="success"> | ||
<AlertBanner.Content css={{ minWidth: 250, paddingRight: "$050" }}> | ||
<b>Copied: </b> | ||
<Box as="span" css={{ fontSize: theme.fontSizes[100] }}> | ||
<Box as="i">{copyText}</Box> | ||
</Box> | ||
</AlertBanner.Content> | ||
</AlertBanner.Root> | ||
); | ||
setContext(theme === "dark" ? Tokens.color.dark : Tokens.color.light); | ||
}, [theme]); | ||
|
||
if (copyText) { | ||
window.navigator.clipboard.writeText(copyText); | ||
toast(<SuccessToast />, { | ||
position: "top-center", | ||
closeButton: false, | ||
autoClose: 2000, | ||
hideProgressBar: true, | ||
draggable: false, | ||
onClose: () => { | ||
setCopyText(null); | ||
}, | ||
}); | ||
} | ||
}, [copyText]); | ||
function lookUpValue(item) { | ||
let value = item.value; | ||
|
||
const handleColor = (group) => { | ||
const colorNamesArray = Object.keys(Tokens.color[group]); | ||
let lookUpKey = value?.substring(1, value.length - 1); | ||
|
||
return colorNamesArray.filter((colorName) => | ||
Object.prototype.hasOwnProperty.call( | ||
Tokens.color[group][colorName], | ||
"value" | ||
) | ||
); | ||
}; | ||
if (theme === "dark") { | ||
value = item.valueDark; | ||
lookUpKey = value?.substring(1, value.length - 1); | ||
return Tokens.color.dark[lookUpKey]?.hex; | ||
} else { | ||
return Tokens.color.light[lookUpKey]?.hex; | ||
} | ||
} | ||
|
||
const Swatch = styled("button", { | ||
backgroundColor: "transparent", | ||
border: "1px solid $subtle", | ||
padding: 0, | ||
"&:hover": { | ||
opacity: 0.5, | ||
}, | ||
}); | ||
const GetSwatchesWithLabels = () => { | ||
let elements = []; | ||
const background = lookUpValue(Tokens.color.theme.background); | ||
|
||
// Y-axis labels | ||
yMapping.forEach((label, index) => { | ||
elements.push( | ||
<AxisLabel | ||
key={`y-label-${index}`} | ||
css={{ | ||
textTransform: "capitalize", | ||
gridColumn: index + 2, | ||
gridRow: 1, | ||
"@sm": { | ||
display: "none", | ||
}, | ||
}} | ||
> | ||
{label} | ||
</AxisLabel> | ||
); | ||
}); | ||
|
||
const ColorExample = styled("div", { | ||
minHeight: "$500", | ||
width: "100%", | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}); | ||
const ColorID = styled("p", { | ||
fontSize: "$100", | ||
marginBlock: 0, | ||
padding: "$025", | ||
fontFamily: "$meta", | ||
color: "$primary", | ||
}); | ||
// X-axis labels | ||
xMapping.forEach((label, index) => { | ||
elements.push( | ||
<AxisLabel | ||
key={`x-label-${index}`} | ||
style={{ | ||
justifySelf: "end", | ||
alignSelf: "center", | ||
paddingRight: 4, | ||
gridRow: index + 2, | ||
gridColumn: 1, | ||
}} | ||
> | ||
{label} | ||
</AxisLabel> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<Grid maxSize={"120px"}> | ||
{colorGroupArray.map((key, i) => ( | ||
// Swatches | ||
yMapping.forEach((color, yIndex) => { | ||
xMapping.forEach((_, xIndex) => { | ||
const key = `${color.toLowerCase()}${xMapping[xIndex]}`; | ||
const hexColor = context[key]?.hex || "transparent"; // Use transparent for empty swatches | ||
const contrast = | ||
hexColor != undefined && | ||
hexColor !== "transparent" && | ||
hex(hexColor, background).toFixed(2); | ||
const TokenScore = contrast && score(contrast); | ||
elements.push( | ||
<Swatch | ||
key={i} | ||
onClick={() => | ||
setCopyText( | ||
`$${key.toLowerCase()}${group == "static" ? "-static" : ""}` | ||
) | ||
} | ||
css={{ | ||
backgroundColor: `$${key}`, | ||
gridRow: xIndex + 2, // Offset by 1 due to labels | ||
gridColumn: yIndex + 2, // Offset by 1 due to labels | ||
color: | ||
TokenScore && TokenScore !== "AA Large" && TokenScore !== "Fail" | ||
? "$gray700" | ||
: "$gray0", | ||
}} | ||
key={key} | ||
> | ||
<ColorExample | ||
css={{ | ||
backgroundColor: `$${key}${group == "static" ? "-static" : ""}`, | ||
}} | ||
/> | ||
<ColorID>{key}</ColorID> | ||
<div>{contrast}</div> | ||
</Swatch> | ||
))} | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
ColorSamples.displayName = "Color Samples"; | ||
); | ||
}); | ||
}); | ||
|
||
export default ColorSamples; | ||
return elements; | ||
}; | ||
return <PaletteGrid>{GetSwatchesWithLabels()}</PaletteGrid>; | ||
} |
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.
nit pick could we use a color token if possible