Skip to content

Commit

Permalink
Merge pull request #89 from aversini/fix-CSS-variables-should-allow-s…
Browse files Browse the repository at this point in the history
…imple-HEX-value

fix: CSS variables should allow simple HEX value
  • Loading branch information
aversini authored Nov 26, 2023
2 parents 0263924 + 88a49f5 commit 48d8870
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 2 additions & 4 deletions packages/ui-components/lib/twPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const parse = converter("rgb");
* exposed in our tokens. It creates an entry for each color
* in the tokens, with the following format:
*
* rgb(var(--av-<color-name>, <fallback-value>) / <alpha-value>)
* var(--av-<color-name>, rgb(<fallback-value>) / <alpha-value>))
*/
export const dynamicColors = () => {
const result = {};
Expand All @@ -18,7 +18,7 @@ export const dynamicColors = () => {
const variable = `--av-${name}`;
const fallbackValue = `${rgb.r * 255} ${rgb.g * 255} ${rgb.b * 255}`;

result[name] = `rgb(var(${variable}, ${fallbackValue}) / <alpha-value>)`;
result[name] = `var(${variable}, rgb(${fallbackValue} / <alpha-value>))`;
});

return result;
Expand Down Expand Up @@ -52,8 +52,6 @@ export const dynamicColorsClasses = () => {
}
if (name.startsWith("border-")) {
result.push(`border-${name}`);
result.push(`border-${name}/0`);
result.push(`border-${name}/100`);
}
if (name.startsWith("focus-")) {
result.push(`ring-${name}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Button modifiers", () => {
"focus:ring-focus-light",
"focus:ring-offset-0",
"border-2",
"border-border-dark/100",
"border-border-dark",
]);
});

Expand Down Expand Up @@ -112,7 +112,8 @@ describe("Button modifiers", () => {
it("should render a button with no borders", async () => {
render(<Button noBorder>hello</Button>);
const button = await screen.findByRole("button");
expect(button.className).toContain("border-border-dark/0");
expect(button.className).not.toContain("border-border-dark");
expect(button.className).toContain("border-transparent");
});

it("should render a raw button with no styling", async () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-components/src/components/Button/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ const getButtonBorderClasses = ({
kind: string;
noBorder: boolean;
}) => {
const borderOpacity = noBorder ? "0" : "100";
return `border-2 border-border-${kind}/${borderOpacity}`;
return clsx("border-2", {
[`border-border-${kind}`]: !noBorder,
"border-transparent": noBorder,
});
};

const getButtonFocusClasses = ({ focus }: { focus: string }) => {
Expand Down

0 comments on commit 48d8870

Please sign in to comment.