-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ status: in-development | |
## Font Weights | ||
|
||
<FontWeightsTable /> | ||
|
||
## Typography | ||
|
||
<Typography /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
apps/docs/src/components/document/typography/typography.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters