diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html index e69de29b..58b97dd1 100644 --- a/.storybook/preview-head.html +++ b/.storybook/preview-head.html @@ -0,0 +1,3 @@ + + + diff --git a/.storybook/preview.js b/.storybook/preview.js index 0f512f38..f40fd995 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,7 +1,6 @@ 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].*' }, @@ -67,14 +66,7 @@ const withWritingDirection = (Story, context) => { ); }; -const withFont = Story => ( - <> - - - -); - -const decorators = [withWritingDirection, withFont]; +const decorators = [withWritingDirection]; const preview = { parameters, diff --git a/pages/_app.tsx b/pages/_app.tsx index 4ba4c2bc..6556115f 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -13,7 +13,6 @@ 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 ( @@ -21,7 +20,6 @@ function MyApp({ Component, pageProps }: AppProps) { -
diff --git a/source/00-config/vars/typography.css b/source/00-config/vars/typography.css index 85eefe45..b6224e06 100644 --- a/source/00-config/vars/typography.css +++ b/source/00-config/vars/typography.css @@ -1,8 +1,5 @@ :root { - /* - * Uncomment if you are NOT using Next's font component. - * --font-family-primary: 'Source Sans Pro', Arial, sans-serif; - */ + --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', diff --git a/source/01-global/01-typography/fonts.stories.tsx b/source/01-global/01-typography/fonts.stories.tsx index a36792af..d73ee645 100644 --- a/source/01-global/01-typography/fonts.stories.tsx +++ b/source/01-global/01-typography/fonts.stories.tsx @@ -2,7 +2,6 @@ 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', @@ -16,114 +15,94 @@ interface WeightOptions { [name: string]: Property.FontWeight; } -const Fonts: StoryObj = { - render: function Render() { - const [fonts, setFonts] = useState(undefined); - const [weights, setWeights] = useState( - undefined, - ); +interface FontsArgs { + fonts: FontOptions; + weights: WeightOptions; +} - useEffect(() => { - const allVars = getCssVariables(); +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); - setFonts(fonts); +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 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 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 Fonts: StoryObj = { + render: args => { return ( <> - {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]) => ( -
-

- {name} -

- {weights && - Object.entries(weights).map(([name, fontWeight]) => ( -
-
- AaBbCc -
-
- ABCDEFGHIJKLMNOPQRSTUVWXYZ -
- abcdefghijklmnopqrstuvwxyz -
- 1234567890(,.;:?!$&*) -
-
-
{name}
-
- Weight: - {fontWeight} -
-
- Style: - {fontFamily} -
-
+ {Object.entries(args.fonts as FontOptions).map(([name, fontFamily]) => ( +
+

+ {name} +

+ {Object.entries(args.weights as WeightOptions).map( + ([name, fontWeight]) => ( +
+
+ AaBbCc +
+
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ +
+ abcdefghijklmnopqrstuvwxyz +
+ 1234567890(,.;:?!$&*) +
+
+
{name}
+
+ Weight: + {fontWeight}
- ))} -
- ))} +
+ Style: + {fontFamily} +
+
+
+ ), + )} +
+ ))} ); }, - args: {}, + args: { + fonts, + weights, + }, }; export default meta; diff --git a/source/01-global/01-typography/line-height.stories.tsx b/source/01-global/01-typography/line-height.stories.tsx index e89de6d8..bbbcda93 100644 --- a/source/01-global/01-typography/line-height.stories.tsx +++ b/source/01-global/01-typography/line-height.stories.tsx @@ -2,7 +2,6 @@ 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', @@ -16,82 +15,64 @@ interface LineHeightOptions { [name: string]: Property.LineHeight; } -const LineHeight: StoryObj = { - render: function Render() { - const [fonts, setFonts] = useState(undefined); - const [lineHeights, setLineHeights] = useState< - LineHeightOptions | undefined - >(undefined); +interface LineHeightArgs { + fonts: FontOptions; + lineHeights: LineHeightOptions; +} - useEffect(() => { - const allVars = getCssVariables(); +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); - setFonts(fonts); +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 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 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 LineHeight: StoryObj = { + render: args => { return ( <> - {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]) => ( -
-

{name}

-
- {lineHeights && - Object.entries(lineHeights).map(([name, lineHeight]) => ( -
-
{name}
-
- The line-height for this text is{' '} - {lineHeight} 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. -
-
- ))} -
-
- ))} + {Object.entries(args.fonts as FontOptions).map(([name, fontFamily]) => ( +
+

{name}

+
+ {Object.entries(args.lineHeights as LineHeightOptions).map( + ([name, lineHeight]) => ( +
+
{name}
+
+ The line-height for this text is{' '} + {lineHeight} 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. +
+
+ ), + )} +
+
+ ))} ); }, + args: { + fonts, + lineHeights, + }, }; export default meta; diff --git a/source/01-global/fonts/source-sans.tsx b/source/01-global/fonts/source-sans.tsx deleted file mode 100644 index 12a3f979..00000000 --- a/source/01-global/fonts/source-sans.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { Source_Sans_3 as SourceSansPro } from 'next/font/google'; - -const sourceSansPro = SourceSansPro({ - display: 'swap', - subsets: ['latin'], - weight: 'variable', -}); - -function SourceSansFontStyle() { - return ( - - ); -} - -export default SourceSansFontStyle; -export { sourceSansPro }; diff --git a/source/06-utility/storybook/getCssVariables.ts b/source/06-utility/storybook/getCssVariables.ts index ba67a970..c8ee81d8 100644 --- a/source/06-utility/storybook/getCssVariables.ts +++ b/source/06-utility/storybook/getCssVariables.ts @@ -7,7 +7,7 @@ function getCssVariables(): string[][] { .map(sheet => { const rules: CSSRulesWithLayers[] = Array.from(sheet.cssRules); return rules.map(r => { - if ('cssRules' in r && r.cssRules.length > 0) { + if ('cssRules' in r) { return Array.from(r.cssRules); } return r;