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 all 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" />
79 changes: 42 additions & 37 deletions packages/design-tokens/docs/components/TokensTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,67 @@ import {
import { Token } from "../types/Token";
import { buildTokensTableRows } from "../utils";
import { TokenRow } from "../types/TokenRow";
import { Box } from "../../../components/src/primitives/Box";
import { TOKEN_COLUMNS } from "./constants";
import { TokenName } from "./TokenName";

export const TokensTable = ({
data,
category,
}: {
data: Record<string, Record<string, Token>>;
category: 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[category][token];
});
const rowGroups: TokenRow[][] = map(columnGroups, (columns, index) => {
const token = tokenNames[index];
return buildTokensTableRows(columns, data[token]);
});

return (
<Table style={{ width: "100%" }}>
<THead>
<Tr>
{map(columnGroups[0], (column) => {
return (
<Th key={column.name}>
<h3>{column.name}</h3>
</Th>
);
})}
</Tr>
</THead>
<TBody>
{map(rowGroups, (rows) =>
map(rows, (row) => {
const tokenName = row[0] as string;
return (
<Tr key={tokenName}>
{map(row, (cell, index) => {
const column = columnGroups[0][index].name;
return (
<Td key={`${tokenName}${column}`}>
{index === 0 ? (
<TokenName tokenName={cell as string} />
) : (
cell
)}
</Td>
);
})}
</Tr>
);
}),
)}
</TBody>
</Table>
<Box.div>
<Table style={{ width: "100%" }}>
<THead>
<Tr>
{map(columnGroups[0], (column) => {
return (
<Th key={column.name}>
<h3>{column.name}</h3>
</Th>
);
})}
</Tr>
</THead>
<TBody>
{map(rowGroups, (rows) =>
map(rows, (row) => {
const tokenName = row[0] as string;
return (
<Tr key={tokenName}>
{map(row, (cell, index) => {
const column = columnGroups[0][index]?.name;
return (
<Td key={`${tokenName}${column}`}>
{index === 0 ? (
<TokenName tokenName={cell as string} />
) : (
cell
)}
</Td>
);
})}
</Tr>
);
}),
)}
</TBody>
</Table>
</Box.div>
);
};
Loading
Loading