Skip to content
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(docs): change TOKEN_COLUMNS to avoid conflicting tokens with the same name #1736

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/weak-moons-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@localyze-pluto/design-tokens": patch
"@localyze-pluto/components": patch
---

Fix storybook pages by avoiding wrong parsed token names and name conflict
6 changes: 3 additions & 3 deletions packages/design-tokens/docs/borders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { TokensTable } from "./components/TokensTable";

## Border Styles

<TokensTable data={borderStyleTokens} />
<TokensTable data={borderStyleTokens} name="borderStyle" />

## Border Widths

<TokensTable data={borderWidthTokens} />
<TokensTable data={borderWidthTokens} name="borderWidth" />

## Border Radii

<TokensTable data={borderRadiiTokens} />
<TokensTable data={borderRadiiTokens} name="borderRadius" />
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import { TokensTable } from "./components/TokensTable";

<br />

<TokensTable data={colorTokens} />
<TokensTable data={colorTokens} name="color" />
6 changes: 4 additions & 2 deletions packages/design-tokens/docs/components/TokensTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import { TokenName } from "./TokenName";

export const TokensTable = ({
data,
name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that we are using category in the type. What do you think of also using it here? Or maybe changing there to name so we have the same naming in both places?

Copy link
Contributor Author

@rssilva rssilva Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call! I'm changing to category

}: {
data: Record<string, Record<string, Token>>;
name: string;
}): JSX.Element => {
const tokenNames: Array<string> = filter(
keys(data),
(item) => item !== "default",
);
const columnGroups = map(tokenNames, (token) => {
return TOKEN_COLUMNS[token];
return TOKEN_COLUMNS[name][token];
});
const rowGroups: TokenRow[][] = map(columnGroups, (columns, index) => {
const token = tokenNames[index];
Expand All @@ -53,7 +55,7 @@ export const TokensTable = ({
return (
<Tr key={tokenName}>
{map(row, (cell, index) => {
const column = columnGroups[0][index].name;
const column = columnGroups[0][index]?.name;
return (
<Td key={`${tokenName}${column}`}>
{index === 0 ? (
Expand Down
248 changes: 134 additions & 114 deletions packages/design-tokens/docs/components/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
hexToRgb,
hexToHsla,
} from "../utils";
import { Box } from "../../../components/src/primitives/Box";
import { Box, BoxProps } from "../../../components/src/primitives/Box";
import { Text } from "../../../components/src/primitives/Text";
import { TokenColumn } from "../types/TokenColumn";
import { Token } from "../types/Token";
Expand All @@ -35,7 +35,9 @@ const TEXT_PREVIEW = (
);

type TokenColumnsProps = {
[key: string]: Array<TokenColumn>;
[category: string]: {
[key: string]: Array<TokenColumn>;
};
};

const getTokenFromVariable = (tokens: unknown, token: Token): string => {
Expand Down Expand Up @@ -105,7 +107,7 @@ const FONT_SIZE = reduce(
name: "Name",
transform: getTokenNameFromTuple(prefix),
},
{ name: "Pixels", transform: getTokenComment },
{ name: "Weight", transform: getTokenValue },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use Weight only for font-weight?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this column since it doesn't make sense on font size!

{ name: "Rems", transform: getTokenValue },
{
name: "Preview",
Expand All @@ -114,11 +116,7 @@ const FONT_SIZE = reduce(
attribute: "fontSize",
children: TEXT_PREVIEW,
componentProps: {
p: "space40",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
overflow: "hidden",
maxWidth: "600px",
lineHeight: "1" as BoxProps["lineHeight"],
},
}),
},
Expand All @@ -132,6 +130,34 @@ const FONT_SIZE = reduce(
{},
);

const FONT_WEIGHT = reduce(
filter(keys(fontWeightTokens), (item) => item !== "default"),
(acc, prefix) => {
const columns = [
{
name: "Name",
transform: getTokenNameFromTuple(prefix),
},
{ name: "Weight", transform: getTokenValue },
{ name: "Rems", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(fontWeightTokens),
attribute: "fontWeight",
children: TEXT_PREVIEW,
}),
},
];

return {
...acc,
[prefix]: columns,
};
},
{},
);

const SPACE = reduce(
filter(keys(spaceTokens), (item) => item !== "default"),
(acc, prefix) => {
Expand Down Expand Up @@ -172,112 +198,106 @@ const SPACE = reduce(
);

export const TOKEN_COLUMNS: TokenColumnsProps = {
[getTokenKey(borderRadiiTokens)]: [
{
name: "Name",
transform: getTokenName(borderRadiiTokens),
},
{ name: "Pixels", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderRadiiTokens),
attribute: "borderRadius",
componentProps: {
borderStyle: "borderStyleSolid",
w: "50px",
h: "50px",
},
overrideProps: {
pill: {
h: "30px",
borderRadius: {
[getTokenKey(borderRadiiTokens)]: [
{
name: "Name",
transform: getTokenName(borderRadiiTokens),
},
{ name: "Pixels", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderRadiiTokens),
attribute: "borderRadius",
componentProps: {
borderStyle: "borderStyleSolid",
w: "50px",
h: "50px",
},
overrideProps: {
pill: {
h: "30px",
},
},
},
}),
},
],
[getTokenKey(borderWidthTokens)]: [
{
name: "Name",
transform: getTokenName(borderWidthTokens),
},
{ name: "Pixels", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderWidthTokens),
attribute: "borderWidth",
componentProps: {
borderStyle: "borderStyleSolid",
w: "50px",
h: "50px",
},
}),
},
],
[getTokenKey(borderStyleTokens)]: [
{
name: "Name",
transform: getTokenName(borderStyleTokens),
},
{ name: "Style", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderStyleTokens),
attribute: "borderStyle",
componentProps: {
w: "50px",
h: "50px",
},
}),
},
],
}),
},
],
},

[getTokenKey(iconSizeTokens)]: [
{
name: "Name",
transform: getTokenName(iconSizeTokens),
},
{ name: "Pixels", transform: getTokenComment },
{ name: "Rems", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(iconSizeTokens),
component: Icon,
componentProps: {
decorative: true,
display: "flex",
icon: "book-open",
},
attribute: "size",
children: (
<Box.div
backgroundColor="colorBackgroundPrimaryWeakest"
h="50px"
w="50px"
/>
),
}),
},
],
[getTokenKey(fontWeightTokens)]: [
{
name: "Name",
transform: getTokenName(fontWeightTokens),
},
{ name: "Weight", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(fontWeightTokens),
attribute: "fontWeight",
children: TEXT_PREVIEW,
}),
},
],
...SPACE,
...FONT_SIZE,
...COLORS,
borderWidth: {
[getTokenKey(borderWidthTokens)]: [
{
name: "Name",
transform: getTokenName(borderWidthTokens),
},
{ name: "Pixels", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderWidthTokens),
attribute: "borderWidth",
componentProps: {
borderStyle: "borderStyleSolid",
w: "50px",
h: "50px",
},
}),
},
],
},
borderStyle: {
[getTokenKey(borderStyleTokens)]: [
{
name: "Name",
transform: getTokenName(borderStyleTokens),
},
{ name: "Style", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(borderStyleTokens),
attribute: "borderStyle",
componentProps: {
w: "50px",
h: "50px",
},
}),
},
],
},
iconSize: {
[getTokenKey(iconSizeTokens)]: [
{
name: "Name",
transform: getTokenName(iconSizeTokens),
},
{ name: "Pixels", transform: getTokenComment },
{ name: "Rems", transform: getTokenValue },
{
name: "Preview",
transform: createPreview({
prefix: getTokenKey(iconSizeTokens),
component: Icon,
componentProps: {
decorative: true,
display: "flex",
icon: "book-open",
},
attribute: "size",
children: (
<Box.div
backgroundColor="colorBackgroundPrimaryWeakest"
h="50px"
w="50px"
/>
),
}),
},
],
},
space: { ...SPACE },
fontSize: { ...FONT_SIZE },
fontWeight: { ...FONT_WEIGHT },
color: { ...COLORS },
};
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/components/createPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createPreview =
([tokenName, token]: TokenTuple): JSX.Element => {
const tokenProps = overrideProps[token.value];
const normalizedSuffix = replace(
upperFirst(replace(tokenName, "-", "")),
upperFirst(replace(camelCase(tokenName), "-", "")),
"Negative",
"",
);
Expand Down
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/font-sizes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import * as fontSizeTokens from "../src/tokens/font-size.tokens.json";

<br />

<TokensTable data={fontSizeTokens} />
<TokensTable data={fontSizeTokens} name="fontSize" />
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/font-weights.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import * as fontWeightTokens from "../src/tokens/font-weight.tokens.json";

<br />

<TokensTable data={fontWeightTokens} />
<TokensTable data={fontWeightTokens} name="fontWeight" />
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/icon-sizes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import * as iconSizeTokens from "../src/tokens/size.tokens.json";

<br />

<TokensTable data={iconSizeTokens} />
<TokensTable data={iconSizeTokens} name="iconSize" />
2 changes: 1 addition & 1 deletion packages/design-tokens/docs/spacing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import * as spaceTokens from "../src/tokens/space.tokens.json";

<br />

<TokensTable data={spaceTokens} />
<TokensTable data={spaceTokens} name="space" />
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type TransformFn = (tuple: TokenTuple) => string;
export const getTokenNameFromTuple =
(prefix: string): TransformFn =>
([tokenName]: TokenTuple) => {
return `${camelCase(prefix)}${upperFirst(replace(tokenName, "-", ""))}`;
return `${camelCase(prefix)}${upperFirst(replace(camelCase(tokenName), "-", ""))}`;
};
Loading