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>
14 changes: 11 additions & 3 deletions .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 @@ -57,16 +58,23 @@ const withWritingDirection = (Story, context) => {
direction === 'vrl'
? 'vertical-rl'
: direction === 'vlr'
? 'vertical-lr'
: 'horizontal-tb',
? 'vertical-lr'
: 'horizontal-tb',
}}
>
<Story />
</div>
);
};

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

const decorators = [withWritingDirection, withFont];

const preview = {
parameters,
Expand Down
3,033 changes: 1,590 additions & 1,443 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"devDependencies": {
"@babel/core": "^7.23.7",
"@csstools/postcss-global-data": "^2.1.1",
"@storybook/addon-a11y": "^7.6.10",
"@storybook/addon-actions": "^7.6.10",
"@storybook/addon-essentials": "^7.6.10",
"@storybook/addon-interactions": "^7.6.10",
"@storybook/addon-links": "^7.6.10",
"@storybook/nextjs": "^7.6.10",
"@storybook/react": "^7.6.10",
"@storybook/addon-a11y": "^7.6.17",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-interactions": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/nextjs": "^7.6.17",
"@storybook/react": "^7.6.17",
"@storybook/testing-library": "^0.2.2",
"@storybook/theming": "^7.6.10",
"@storybook/theming": "^7.6.17",
"@svgr/babel-plugin-add-jsx-attribute": "^8.0.0",
"@svgr/babel-plugin-remove-jsx-attribute": "^8.0.0",
"@svgr/cli": "^8.1.0",
Expand Down Expand Up @@ -71,7 +71,7 @@
"postcss-rem": "^2.0.2",
"prettier": "^3.2.4",
"prettier-plugin-organize-imports": "^3.2.4",
"storybook": "^7.6.10",
"storybook": "^7.6.17",
"style-loader": "^3.3.4",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^33.0.0",
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
165 changes: 94 additions & 71 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,92 +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).map(([name, fontFamily]) => (
<div className={styles.fonts} key={name}>
<h3
className={styles.family}
style={{
fontFamily,
}}
>
{name}
</h3>
{Object.entries(args.weights).map(([name, fontWeight]) => (
<div className={styles.item} key={name}>
<div
className={styles['preview-character']}
{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={{
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>
{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>
))}
</div>
))}
</>
);
},
args: {
fonts,
weights,
},
args: {},
};

export default meta;
Expand Down
Loading