-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typography presets to Storybook (#1272)
## What are you changing? - Adds documentation and examples for web typography presets to Storybook, and deprecates existing typography API documentation <img width="1015" alt="Screenshot 2024-03-12 at 14 50 21" src="https://github.com/guardian/csnx/assets/1166188/e421b6fd-7f6c-4e32-bcc7-c3931a0648c5">
- Loading branch information
Showing
3 changed files
with
387 additions
and
201 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
libs/@guardian/source-foundations/src/typography/storybookTypographyPresets.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,82 @@ | ||
import { tokens } from '@guardian/design-tokens'; | ||
import { css } from '@emotion/react'; | ||
import * as presets from './presets'; | ||
import { space } from '../space/space'; | ||
import { palette } from '../colour/palette'; | ||
|
||
const presetTokens = tokens.typography.presets; | ||
type Preset = keyof typeof presetTokens; | ||
|
||
const listCss = css` | ||
list-style: none; | ||
padding: 0; | ||
li + li { | ||
margin-top: ${space[4]}px; | ||
padding-top: ${space[4]}px; | ||
border-top: 1px solid ${palette.neutral[86]}; | ||
} | ||
`; | ||
|
||
const presetNameCss = css` | ||
display: block; | ||
font-weight: 700; | ||
`; | ||
|
||
const specimenCss = css` | ||
display: flex; | ||
gap: ${space[8]}px; | ||
`; | ||
|
||
const propertiesCss = css` | ||
display: flex; | ||
gap: ${space[4]}px; | ||
dt { | ||
${presets.textSans12} | ||
color: ${palette.neutral[38]}; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
dd { | ||
${presets.textSans14} | ||
margin: 0; | ||
padding: 0; | ||
} | ||
`; | ||
|
||
export const TypographyPresets = () => ( | ||
<ul css={listCss}> | ||
{Object.entries(presets).map(([preset, styles]) => { | ||
const token = presetTokens[preset as Preset]; | ||
return ( | ||
<li> | ||
<span css={presetNameCss}>{preset}</span> | ||
<span css={specimenCss}> | ||
<dl css={propertiesCss}> | ||
<div> | ||
<dt>Family</dt> | ||
<dd> | ||
{token.fontFamily[0]} ({token.fontWeight}) | ||
</dd> | ||
</div> | ||
<div> | ||
<dt>Size</dt> | ||
<dd>{token.fontSize}</dd> | ||
</div> | ||
<div> | ||
<dt>Line height</dt> | ||
<dd>{token.lineHeight}</dd> | ||
</div> | ||
</dl> | ||
<span | ||
css={css` | ||
${styles} | ||
`} | ||
> | ||
For facts' sake | ||
</span> | ||
</span> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
); |
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
Oops, something went wrong.