Skip to content
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
3 changes: 0 additions & 3 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,600;1,700&display=swap" rel="stylesheet" crossorigin>
10 changes: 9 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../source/00-config/index.css';
import '../source/01-global/index.css';
import '../source/06-utility/index.css';
import SourceSansFontStyle from '../source/01-global/fonts/source-sans';

const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand Down Expand Up @@ -66,7 +67,14 @@ const withWritingDirection = (Story, context) => {
);
};

const decorators = [withWritingDirection];
const withFont = Story => (
<>
<SourceSansFontStyle />
<Story />
</>
);

const decorators = [withWritingDirection, withFont];

const preview = {
parameters,
Expand Down
2 changes: 2 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import SiteName from '../source/03-components/SiteName/SiteName';
import Skiplink from '../source/03-components/Skiplink/Skiplink';
import addBasePath from '../source/06-utility/addBasePath';
import '../source/06-utility/index.css';
import SourceSansFontStyle from '../source/01-global/fonts/source-sans';

function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<link rel="icon" href={addBasePath('/favicon.ico')} />
</Head>
<SourceSansFontStyle />
<Skiplink />
<SiteContainer>
<Header>
Expand Down
5 changes: 4 additions & 1 deletion source/00-config/vars/typography.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
:root {
--font-family-primary: 'Source Sans Pro', Arial, sans-serif;
/*
* Uncomment if you are NOT using Next's font component.
* --font-family-primary: 'Source Sans Pro', Arial, sans-serif;
*/
--font-family-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Oxygen-Sans', Ubuntu, Cantarell, 'Fira Sans', Droid Sans, sans-serif;
--font-family-monospace: Menlo, Consolas, 'Lucida Console', 'Liberation Mono',
Expand Down
177 changes: 99 additions & 78 deletions source/01-global/01-typography/fonts.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meta, StoryObj } from '@storybook/react';
import { Property } from 'csstype';
import getCssVariables from '../../06-utility/storybook/getCssVariables';
import styles from './fonts.module.css';
import { useEffect, useState } from 'react';

const meta: Meta = {
title: 'Global/Typography/Fonts',
Expand All @@ -15,94 +16,114 @@ interface WeightOptions {
[name: string]: Property.FontWeight;
}

interface FontsArgs {
fonts: FontOptions;
weights: WeightOptions;
}
const Fonts: StoryObj = {
render: function Render() {
const [fonts, setFonts] = useState<FontOptions | undefined>(undefined);
const [weights, setWeights] = useState<WeightOptions | undefined>(
undefined,
);

const allVars = getCssVariables();
useEffect(() => {
const allVars = getCssVariables();

const fonts = allVars.reduce((allFonts, [key, value]) => {
if (key.indexOf('--font-family') === 0) {
const name =
key.substring(14).charAt(0).toUpperCase() + key.substring(14).slice(1);
allFonts[name] = value;
}
return allFonts;
}, {} as FontOptions);
const fonts = allVars.reduce((allFonts, [key, value]) => {
if (key.indexOf('--font-family') === 0) {
const name =
key.substring(14).charAt(0).toUpperCase() +
key.substring(14).slice(1);
allFonts[name] = value;
}
return allFonts;
}, {} as FontOptions);
setFonts(fonts);

const weights = allVars.reduce((allWeights, [key, value]) => {
if (key.indexOf('--font-weight') === 0) {
const name = key.substring(14);
allWeights[name] = value;
}
return allWeights;
}, {} as WeightOptions);
const weights = allVars.reduce((allWeights, [key, value]) => {
if (key.indexOf('--font-weight') === 0) {
const name = key.substring(14);
allWeights[name] = value;
}
return allWeights;
}, {} as WeightOptions);
setWeights(weights);
}, []);

const Fonts: StoryObj<FontsArgs> = {
render: args => {
return (
<>
{Object.entries(args.fonts as FontOptions).map(([name, fontFamily]) => (
<div className={styles.fonts} key={name}>
<h3
className={styles.family}
style={{
fontFamily,
}}
>
{name}
</h3>
{Object.entries(args.weights as WeightOptions).map(
([name, fontWeight]) => (
<div className={styles.item} key={name}>
<div
className={styles['preview-character']}
style={{
fontStyle: 'normal',
fontFamily,
fontWeight,
}}
>
AaBbCc
</div>
<div
className={styles.preview}
style={{
fontStyle: 'normal',
fontFamily,
fontWeight,
}}
>
ABCDEFGHIJKLMNOPQRSTUVWXYZ
<br />
abcdefghijklmnopqrstuvwxyz
<br />
1234567890(,.;:?!$&*)
</div>
<div className={styles['preview-meta']}>
<div className={styles.name}>{name}</div>
<div className={styles.weight}>
<span className={styles.label}>Weight:</span>
{fontWeight}
{fonts &&
Object.entries(fonts)
.sort((fontA, fontB) => {
// Sort fonts so that Primary and Secondary (if used) appear at the
// top of the list.
if (fontA[0].toLowerCase().includes('primary')) {
return -1;
}
if (fontB[0].toLowerCase().includes('primary')) {
return 1;
}
if (fontA[0].toLowerCase().includes('secondary')) {
return -1;
}
if (fontB[0].toLowerCase().includes('secondary')) {
return 1;
}
return 0;
})
.map(([name, fontFamily]) => (
<div className={styles.fonts} key={name}>
<h3
className={styles.family}
style={{
fontFamily,
}}
>
{name}
</h3>
{weights &&
Object.entries(weights).map(([name, fontWeight]) => (
<div className={styles.item} key={name}>
<div
className={styles['preview-character']}
style={{
fontStyle: 'normal',
fontFamily,
fontWeight,
}}
>
AaBbCc
</div>
<div
className={styles.preview}
style={{
fontStyle: 'normal',
fontFamily,
fontWeight,
}}
>
ABCDEFGHIJKLMNOPQRSTUVWXYZ
<br />
abcdefghijklmnopqrstuvwxyz
<br />
1234567890(,.;:?!$&*)
</div>
<div className={styles['preview-meta']}>
<div className={styles.name}>{name}</div>
<div className={styles.weight}>
<span className={styles.label}>Weight:</span>
{fontWeight}
</div>
<div className={styles.style}>
<span className={styles.label}>Style:</span>
{fontFamily}
</div>
</div>
</div>
<div className={styles.style}>
<span className={styles.label}>Style:</span>
{fontFamily}
</div>
</div>
</div>
),
)}
</div>
))}
))}
</div>
))}
</>
);
},
args: {
fonts,
weights,
},
args: {},
};

export default meta;
Expand Down
117 changes: 68 additions & 49 deletions source/01-global/01-typography/line-height.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meta, StoryObj } from '@storybook/react';
import { Property } from 'csstype';
import getCssVariables from '../../06-utility/storybook/getCssVariables';
import styles from './line-height.module.css';
import { useEffect, useState } from 'react';

const meta: Meta = {
title: 'Global/Typography/Line Height',
Expand All @@ -15,64 +16,82 @@ interface LineHeightOptions {
[name: string]: Property.LineHeight;
}

interface LineHeightArgs {
fonts: FontOptions;
lineHeights: LineHeightOptions;
}
const LineHeight: StoryObj = {
render: function Render() {
const [fonts, setFonts] = useState<FontOptions | undefined>(undefined);
const [lineHeights, setLineHeights] = useState<
LineHeightOptions | undefined
>(undefined);

const allVars = getCssVariables();
useEffect(() => {
const allVars = getCssVariables();

const fonts = allVars.reduce((allFonts, [key, value]) => {
if (key.indexOf('--font-family') === 0) {
const name =
key.substring(14).charAt(0).toUpperCase() + key.substring(14).slice(1);
allFonts[name] = value;
}
return allFonts;
}, {} as FontOptions);
const fonts = allVars.reduce((allFonts, [key, value]) => {
if (key.indexOf('--font-family') === 0) {
const name =
key.substring(14).charAt(0).toUpperCase() +
key.substring(14).slice(1);
allFonts[name] = value;
}
return allFonts;
}, {} as FontOptions);
setFonts(fonts);

const lineHeights = allVars.reduce((allLineHeights, [key, value]) => {
if (key.indexOf('--line-height') === 0) {
const name = key.substring(14);
allLineHeights[name] = value;
}
return allLineHeights;
}, {} as LineHeightOptions);
const lineHeights = allVars.reduce((allLineHeights, [key, value]) => {
if (key.indexOf('--line-height') === 0) {
const name = key.substring(14);
allLineHeights[name] = value;
}
return allLineHeights;
}, {} as LineHeightOptions);
setLineHeights(lineHeights);
}, []);

const LineHeight: StoryObj<LineHeightArgs> = {
render: args => {
return (
<>
{Object.entries(args.fonts as FontOptions).map(([name, fontFamily]) => (
<div className={styles['line-height']} key={name}>
<h2 className={styles.heading}>{name}</h2>
<div style={{ fontFamily }}>
{Object.entries(args.lineHeights as LineHeightOptions).map(
([name, lineHeight]) => (
<div className={styles.row} key={name}>
<div className={styles.label}>{name}</div>
<div className={styles.preview} style={{ lineHeight }}>
The line-height for this text is{' '}
<strong>{lineHeight}</strong> times the font-size. It’s
worth remembering that line height is affected by the
x-height. Much like how different typefaces can appear to
be different heights despite being set at the same font
size, so too can line height appear to be more open or
tighter, depending on each individual font.
</div>
</div>
),
)}
</div>
</div>
))}
{fonts &&
Object.entries(fonts)
.sort((fontA, fontB) => {
if (fontA[0].toLowerCase().includes('primary')) {
return -1;
}
if (fontB[0].toLowerCase().includes('primary')) {
return 1;
}
if (fontA[0].toLowerCase().includes('secondary')) {
return -1;
}
if (fontB[0].toLowerCase().includes('secondary')) {
return 1;
}
return 0;
})
.map(([name, fontFamily]) => (
<div className={styles['line-height']} key={name}>
<h2 className={styles.heading}>{name}</h2>
<div style={{ fontFamily }}>
{lineHeights &&
Object.entries(lineHeights).map(([name, lineHeight]) => (
<div className={styles.row} key={name}>
<div className={styles.label}>{name}</div>
<div className={styles.preview} style={{ lineHeight }}>
The line-height for this text is{' '}
<strong>{lineHeight}</strong> times the font-size.
It’s worth remembering that line height is affected by
the x-height. Much like how different typefaces can
appear to be different heights despite being set at
the same font size, so too can line height appear to
be more open or tighter, depending on each individual
font.
</div>
</div>
))}
</div>
</div>
))}
</>
);
},
args: {
fonts,
lineHeights,
},
};

export default meta;
Expand Down
Loading