Skip to content

Commit

Permalink
fix tokens table
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsnes committed Nov 28, 2024
1 parent 48500e6 commit 59649ad
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions apps/storefront/components/Tokens/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ const TokensTable = ({ tokens }: TokenTableProps) => {
{tokens.map(([, tokens]) => {
return tokens.map((token) => {
const value = token.$value as string;
const pxSize = /\b\d+px\b/.test(value)
? value
: `${parseFloat(value) * 16}px`;
const pxSize = calculateComputedValue(value);
const isBorderRadius = token.path.includes('border-radius');

return (
Expand Down Expand Up @@ -86,6 +84,21 @@ const TokensTable = ({ tokens }: TokenTableProps) => {
);
};

function calculateComputedValue(value: string) {
const elm = document.createElement('div');
elm.style.cssText = `width: ${value}; height: ${value};`;

document.body.appendChild(elm);

const computedValue = getComputedStyle(elm).width;

document.body.removeChild(elm);

console.log(computedValue);

return computedValue;
}

type TokenCardsProps = {
tokens: [string, Token[]][];
cols?: number;
Expand Down

0 comments on commit 59649ad

Please sign in to comment.