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

feat: add heading docs #38

Merged
merged 2 commits into from
Jun 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ status: in-development
## Font Weights

<FontWeightsTable />

## Typography

<Typography />
2 changes: 2 additions & 0 deletions apps/docs/src/components/document/mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Heading } from '../typography/heading';
import { ColorPrimitives } from '@/components/document/color/color-primitives';
import { FontSizesTable } from './typography/font-sizes-table';
import { FontWeightsTable } from './typography/font-weights-table';
import { Typography } from './typography/typography';

export type MdxProps = {
code: string;
Expand All @@ -18,6 +19,7 @@ export function Mdx({ code }: MdxProps) {
ColorPrimitives: () => <ColorPrimitives />,
FontSizesTable: () => <FontSizesTable />,
FontWeightsTable: () => <FontWeightsTable />,
Typography: () => <Typography />,
}}
/>
);
Expand Down
118 changes: 118 additions & 0 deletions apps/docs/src/components/document/typography/typography.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { meta } from '@govie-ds/tokens';
import { objectKeys } from 'ts-extras';
import { Table, Td } from './table';
import { TokenName } from '../color/token-name';
import { P } from 'vitest/dist/reporters-yx5ZTtEV.js';

function remToPx(remString: string) {
return `${Number(remString.replace('rem', '')) * 16}px`;
}

function unitlessToPx(unitless: number) {
return `${unitless * 16}px`;
}

function CellLabel({ label }: { label: string }) {
return <p className="font-semibold">{label}:</p>;
}

function TypographyCell({
fontFamily,
fontSize,
fontWeight,
lineHeight,
}: {
fontFamily: string[];
fontSize: string;
fontWeight: number;
lineHeight: number;
}) {
return (
<Td className="text-sm">
<div className="grid grid-cols-2">
<CellLabel label="Font family" />
<p>{fontFamily.join(', ')}</p>
<CellLabel label="Font size" />
<p>
{fontSize} ({remToPx(fontSize)})
</p>
<CellLabel label="Font weight" />
<p>{fontWeight}</p>
<CellLabel label="Line height" />
<p>
{lineHeight} ({unitlessToPx(lineHeight)})
</p>
</div>
</Td>
);
}

// TODO: type
function TypographyTable({
name,
tokens,
}: {
name: string;
tokens: Record<string, { regular: any; bold: any }>;
}) {
return (
<Table
headers={['Token', 'Regular', 'Bold']} // , 'Example']}
ids={objectKeys(tokens)}
renderRow={(id) => {
const { $value: regularValue } = tokens[id].regular;

const { $value: boldValue } = tokens[id].bold;

const {
fontFamily: fontFamilyRegular,
fontSize: fontSizeRegular,
fontWeight: fontWeightRegular,
lineHeight: lineHeightRegular,
} = regularValue;

const {
fontFamily: fontFamilyBold,
fontSize: fontSizeBold,
fontWeight: fontWeightBold,
lineHeight: lineHeightBold,
} = boldValue;

return (
<tr key={id}>
<Td className="whitespace-nowrap w-[1px] text-sm">
<TokenName name={`${name}/${id}`} />
</Td>
<TypographyCell
fontFamily={fontFamilyRegular}
fontSize={fontSizeRegular}
fontWeight={fontWeightRegular}
lineHeight={lineHeightRegular}
/>
<TypographyCell
fontFamily={fontFamilyBold}
fontSize={fontSizeBold}
fontWeight={fontWeightBold}
lineHeight={lineHeightBold}
/>
</tr>
);
}}
/>
);
}

export function Typography() {
return (
<div className="flex flex-col gap-2xl">
<TypographyTable
name="heading"
tokens={meta.light.resolved.primitive.heading}
/>
<TypographyTable
name="text"
tokens={meta.light.resolved.primitive.text}
/>
</div>
);
}
16 changes: 8 additions & 8 deletions tokens/tokens/light/primitive/heading.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1000}",
"fontWeight": "{primitive.font.weight.400}",
"lineHeight": "{primitive.font.lineHeight.900}"
"lineHeight": "{primitive.font.lineHeight.1000}"
}
},
"bold": {
Expand All @@ -157,7 +157,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1000}",
"fontWeight": "{primitive.font.weight.700}",
"lineHeight": "{primitive.font.lineHeight.900}"
"lineHeight": "{primitive.font.lineHeight.1000}"
}
}
},
Expand All @@ -168,7 +168,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1100}",
"fontWeight": "{primitive.font.weight.400}",
"lineHeight": "{primitive.font.lineHeight.1000}"
"lineHeight": "{primitive.font.lineHeight.1100}"
}
},
"bold": {
Expand All @@ -177,7 +177,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1100}",
"fontWeight": "{primitive.font.weight.700}",
"lineHeight": "{primitive.font.lineHeight.1000}"
"lineHeight": "{primitive.font.lineHeight.1100}"
}
}
},
Expand All @@ -188,7 +188,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1200}",
"fontWeight": "{primitive.font.weight.400}",
"lineHeight": "{primitive.font.lineHeight.1100}"
"lineHeight": "{primitive.font.lineHeight.1200}"
}
},
"bold": {
Expand All @@ -197,7 +197,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1200}",
"fontWeight": "{primitive.font.weight.700}",
"lineHeight": "{primitive.font.lineHeight.1100}"
"lineHeight": "{primitive.font.lineHeight.1200}"
}
}
},
Expand All @@ -208,7 +208,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1300}",
"fontWeight": "{primitive.font.weight.400}",
"lineHeight": "{primitive.font.lineHeight.1200}"
"lineHeight": "{primitive.font.lineHeight.1300}"
}
},
"bold": {
Expand All @@ -217,7 +217,7 @@
"fontFamily": "{primitive.font.family.primary}",
"fontSize": "{primitive.font.size.1300}",
"fontWeight": "{primitive.font.weight.700}",
"lineHeight": "{primitive.font.lineHeight.1200}"
"lineHeight": "{primitive.font.lineHeight.1300}"
}
}
}
Expand Down