From 1208079710803748a5973b56af62dbf79598b59b Mon Sep 17 00:00:00 2001 From: Jacob Blomgren Date: Mon, 11 Mar 2019 14:50:47 +0100 Subject: [PATCH] fix: disallow extrabold for secondary, tertiary, caption (#579) * fix: disallow extrabold for secondary, tertiary, caption * fix: typings for typogaphy's weights --- src/styles/typography.js | 7 ++++--- types/index.ts | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/styles/typography.js b/src/styles/typography.js index 3786318a..7fb7b362 100644 --- a/src/styles/typography.js +++ b/src/styles/typography.js @@ -19,19 +19,20 @@ export default function createTypography() { ...ifSmallDevice(14, 16), fontWeight: WEIGHTS[weight] || WEIGHTS.regular, }); + const coerceExtraboldToBold = weight => (weight === 'extrabold' ? WEIGHTS.bold : WEIGHTS[weight]); const secondary = ({ weight = 'regular' } = {}) => ({ ...ifSmallDevice(12, 14), - fontWeight: WEIGHTS[weight] || WEIGHTS.regular, + fontWeight: coerceExtraboldToBold(weight) || WEIGHTS.regular, }); const tertiary = ({ weight = 'regular' } = {}) => ({ ...ifSmallDevice(10, 12), - fontWeight: WEIGHTS[weight] || WEIGHTS.regular, + fontWeight: coerceExtraboldToBold(weight) || WEIGHTS.regular, }); const caption = ({ weight = 'regular', uppercase = false } = {}) => ({ // @todo discuss lower value with designers ...ifSmallDevice(10, 10), - fontWeight: WEIGHTS[weight] || WEIGHTS.regular, + fontWeight: coerceExtraboldToBold(weight) || WEIGHTS.regular, ...(uppercase ? { textTransform: 'uppercase' } : {}), }); diff --git a/types/index.ts b/types/index.ts index 88e1ab5e..fba117ce 100644 --- a/types/index.ts +++ b/types/index.ts @@ -7,16 +7,17 @@ declare module 'nordnet-ui-kit' { letterSpacing: string; }; type Weight = 'regular' | 'bold' | 'extrabold'; + type WeightNoExtrabold = 'regular' | 'bold'; // prettier-ignore type TypographyScheme = { - caption: (options: { weight: Weight, uppercase: boolean }) => TypographyCSS & { textTransform: string}; - hero: (options: { weight: Weight }) => TypographyCSS; + caption: (options: { weight: WeightNoExtrabold, uppercase: boolean }) => TypographyCSS & { textTransform: string}; + hero: () => TypographyCSS; title1: (options: { weight: Weight }) => TypographyCSS; title2: (options: { weight: Weight }) => TypographyCSS; title3: (options: { weight: Weight }) => TypographyCSS; primary: (options: { weight: Weight }) => TypographyCSS; - secondary: (options: { weight: Weight }) => TypographyCSS; - tertiary: (options: { weight: Weight }) => TypographyCSS; + secondary: (options: { weight: WeightNoExtrabold }) => TypographyCSS; + tertiary: (options: { weight: WeightNoExtrabold }) => TypographyCSS; }; export type Theme = {