Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the link component to use the new presets #1289

Closed
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
38 changes: 1 addition & 37 deletions libs/@guardian/design-tokens/src/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,42 +530,6 @@
"$value": 700
}
},
"textDecorationThicknessForFontSize": {
"$type": "dimension",
"12": {
"$value": "2px"
},
"14": {
"$value": "2px"
},
"15": {
"$value": "2px"
},
"17": {
"$value": "2px"
},
"20": {
"$value": "3px"
},
"24": {
"$value": "3px"
},
"28": {
"$value": "3px"
},
"34": {
"$value": "4px"
},
"42": {
"$value": "5px"
},
"50": {
"$value": "6px"
},
"70": {
"$value": "6px"
}
},
"body": {
"$type": "typography",
"xSmall": {
Expand Down Expand Up @@ -1537,7 +1501,7 @@
"fontSize": "{typography.fontSize.14}",
"lineHeight": "{typography.lineHeight.regular}",
"fontWeight": "{typography.fontWeight.regular}",
"fontStyle": "Italic"
"fontStyle": "italic"
}
},
"textSansItalic15": {
Expand Down
15 changes: 1 addition & 14 deletions libs/@guardian/design-tokens/tokens.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ export declare const tokens: {
readonly fontSize: '14px';
readonly lineHeight: 1.3;
readonly fontWeight: 400;
readonly fontStyle: 'Italic';
readonly fontStyle: 'italic';
};
readonly textSansItalic15: {
readonly fontFamily: readonly [
Expand Down Expand Up @@ -1570,19 +1570,6 @@ export declare const tokens: {
readonly fontStyle: 'normal';
};
};
readonly textDecorationThicknessForFontSize: {
readonly '12': '2px';
readonly '14': '2px';
readonly '15': '2px';
readonly '17': '2px';
readonly '20': '3px';
readonly '24': '3px';
readonly '28': '3px';
readonly '34': '4px';
readonly '42': '5px';
readonly '50': '6px';
readonly '70': '6px';
};
readonly textSans: {
readonly large: {
readonly fontFamily: readonly [
Expand Down
15 changes: 1 addition & 14 deletions libs/@guardian/design-tokens/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ export const tokens = {
fontSize: '14px',
lineHeight: 1.3,
fontWeight: 400,
fontStyle: 'Italic',
fontStyle: 'italic',
},
textSansItalic15: {
fontFamily: [
Expand Down Expand Up @@ -1554,19 +1554,6 @@ export const tokens = {
fontStyle: 'normal',
},
},
textDecorationThicknessForFontSize: {
12: '2px',
14: '2px',
15: '2px',
17: '2px',
20: '3px',
24: '3px',
28: '3px',
34: '4px',
42: '5px',
50: '6px',
70: '6px',
},
textSans: {
large: {
fontFamily: [
Expand Down
13 changes: 1 addition & 12 deletions libs/@guardian/design-tokens/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@
--source-typography-presets-textSansItalic14-font-size: var(
--source-typography-fontSize-14
);
--source-typography-presets-textSansItalic14-font-style: Italic;
--source-typography-presets-textSansItalic14-font-style: italic;
--source-typography-presets-textSansItalic14-font-weight: var(
--source-typography-fontWeight-regular
);
Expand Down Expand Up @@ -1534,17 +1534,6 @@
--source-typography-presets-titlepiece70-line-height: var(
--source-typography-lineHeight-tight
);
--source-typography-textDecorationThicknessForFontSize-12: 0.125rem;
--source-typography-textDecorationThicknessForFontSize-14: 0.125rem;
--source-typography-textDecorationThicknessForFontSize-15: 0.125rem;
--source-typography-textDecorationThicknessForFontSize-17: 0.125rem;
--source-typography-textDecorationThicknessForFontSize-20: 0.1875rem;
--source-typography-textDecorationThicknessForFontSize-24: 0.1875rem;
--source-typography-textDecorationThicknessForFontSize-28: 0.1875rem;
--source-typography-textDecorationThicknessForFontSize-34: 0.25rem;
--source-typography-textDecorationThicknessForFontSize-42: 0.3125rem;
--source-typography-textDecorationThicknessForFontSize-50: 0.375rem;
--source-typography-textDecorationThicknessForFontSize-70: 0.375rem;
--source-typography-textSans-large-font-family: var(
--source-typography-fontFamily-textSans
);
Expand Down
18 changes: 8 additions & 10 deletions libs/@guardian/source-foundations/scripts/build-type-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { fontArrayToString, pxStringToRem } from '../src/utils/convert-value';
const STRIP_WHITESPACE = /^\s+/gm;
const STRIP_TABS = /^\t{3}|\t{2}/gm;

const { presets, fontSize, textDecorationThicknessForFontSize } =
tokens.typography;

type FontSize = keyof typeof fontSize;

const textDecorationThickness = (size: string) =>
textDecorationThicknessForFontSize[size.slice(0, -2) as FontSize];
const { presets } = tokens.typography;

console.log('Building typography presets…');

Expand All @@ -23,19 +17,23 @@ const banner = `
// Typography presets
// Auto-generated by scripts/build-type-presets.ts
// DO NOT EDIT

`.replace(STRIP_WHITESPACE, '');

const importStatement = `
import type { TypographyPreset } from './types';

`;
// Generate CSS representation of presets as a string
const css = Object.entries(presets)
.map(
([preset, properties]) => `
export const ${preset} = \`
export const ${preset}: TypographyPreset = \`
font-family: ${fontArrayToString(properties.fontFamily)};
font-size: ${pxStringToRem(properties.fontSize)}rem;
line-height: ${properties.lineHeight};
font-weight: ${properties.fontWeight};
font-style: ${properties.fontStyle};
--source-text-decoration-thickness: ${textDecorationThickness(properties.fontSize)};
\`;
`,
)
Expand All @@ -58,6 +56,6 @@ const object = Object.entries(presets)
.join('')
.replace(STRIP_TABS, '');

fs.writeFileSync(cssOutputPath, banner + css);
fs.writeFileSync(cssOutputPath, banner + importStatement + css);
fs.writeFileSync(objectOutputPath, banner + object);
console.log(`✓ ${presetTotal} presets built`);
1 change: 1 addition & 0 deletions libs/@guardian/source-foundations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type {
FontWeightDefinition,
Option,
TypographyStyles,
TypographyPreset,
TypographySizes,
TitlepieceSizes,
HeadlineSizes,
Expand Down
Loading