Skip to content

Commit

Permalink
feat: convert design-tokens to DTCG format (#2240)
Browse files Browse the repository at this point in the history
fixes #2196 

Its mostly appending `$` on `value` and `type` properties on json
design-tokens files.

- Updated some missed transformer codes to support DTCG format.
- Update Storefront tokens preview to new format.
  • Loading branch information
mimarz authored Aug 14, 2024
1 parent fe8f9de commit f32f1fb
Show file tree
Hide file tree
Showing 45 changed files with 10,018 additions and 10,103 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-dingos-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@digdir/designsystemet': minor
---

feat: Convert to W3C design token format
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getColorWeight(value: string): ColorNumber | undefined {
const TokenColor = ({ value, token }: TokenColorProps) => {
const colorModalRef = useRef<HTMLDialogElement>(null);

const weight = getColorWeight(token.original.value as string);
const weight = getColorWeight(token.original.$value as string);
const Element = weight ? 'button' : 'div';

return (
Expand Down
10 changes: 5 additions & 5 deletions apps/storefront/components/Tokens/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const TokensTable = ({ tokens }: TokenTableProps) => {
<Table.Body>
{tokens.map(([, tokens]) => {
return tokens.map((token) => {
const value = token.value as string;
const value = token.$value as string;
const pxSize = /\b\d+px\b/.test(value)
? value
: `${parseFloat(value) * 16}px`;
Expand All @@ -68,7 +68,7 @@ const TokensTable = ({ tokens }: TokenTableProps) => {
value={token.name}
/>
</Table.Cell>
<Table.Cell>{token.value}</Table.Cell>
<Table.Cell>{token.$value}</Table.Cell>
<Table.Cell>{pxSize}</Table.Cell>
<Table.Cell>
{isBorderRadius ? (
Expand Down Expand Up @@ -128,12 +128,12 @@ type TokenCardProps = {
} & HTMLAttributes<HTMLDivElement>;

const TokenCard = ({ token, type, hideValue, ...rest }: TokenCardProps) => {
const val = token.value as string;
const val = token.$value as string;
const title = token.path
.slice(token.path.length - 1, token.path.length)
.toString();

const weight = getColorWeight(token.original.value as string);
const weight = getColorWeight(token.original.$value as string);

return (
<div className={classes.card} {...rest}>
Expand All @@ -153,7 +153,7 @@ const TokenCard = ({ token, type, hideValue, ...rest }: TokenCardProps) => {
value={token.name}
/>
</Heading>
{!hideValue && <div className={classes.value}>{token.value}</div>}
{!hideValue && <div className={classes.value}>{token.$value}</div>}
</div>
</div>
);
Expand Down
Loading

0 comments on commit f32f1fb

Please sign in to comment.