From 416c6268733119e080a7571f3f677de669fa1d82 Mon Sep 17 00:00:00 2001 From: TFK70 Date: Mon, 8 Mar 2021 18:20:43 +0500 Subject: [PATCH] fix(theme): change font operations flow affects: @atlantis-lab/theme - Added additional fontsPath prop in injectGlobalStyles - Changed props order ISSUES CLOSED: #237 --- packages/theme/src/globals.ts | 31 ++++++++++++++++--------------- packages/theme/src/utils.ts | 10 +++++----- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/theme/src/globals.ts b/packages/theme/src/globals.ts index 4d5c12e2b..e589d47f0 100644 --- a/packages/theme/src/globals.ts +++ b/packages/theme/src/globals.ts @@ -4,21 +4,22 @@ import { FontFaces } from './theme' import { injectFontFaces } from './utils' export const injectGlobalStyles = ( - html: {} = {}, - body: {} = { - WebkitFontSmoothing: 'antialiased', - WebkitOverflowScrolling: 'touch', - height: '100%', - margin: 0, - }, - fontFaces: FontFaces, - ...rest + fontsPath: string, + fontFaces: FontFaces, + html: {} = {}, + body: {} = { + WebkitFontSmoothing: 'antialiased', + WebkitOverflowScrolling: 'touch', + height: '100%', + margin: 0, + }, + ...rest ) => { - injectFontFaces(fontFaces) + injectFontFaces(fontFaces, fontsPath) - injectGlobal({ - html, - body, - ...rest, - }) + injectGlobal({ + html, + body, + ...rest, + }) } diff --git a/packages/theme/src/utils.ts b/packages/theme/src/utils.ts index 586e5e8f6..7e7df8243 100644 --- a/packages/theme/src/utils.ts +++ b/packages/theme/src/utils.ts @@ -3,21 +3,21 @@ /* eslint-disable no-empty */ import { injectGlobal } from 'emotion' -const fontFace = (family, type, weight, style = 'normal') => ({ +const fontFace = (family, type, weight, fontsPath, style = 'normal') => ({ '@font-face': { fontFamily: family, fontWeight: weight, fontStyle: style, src: `local('${family}-${type}'), - url('${require(`../fonts/${family}-${type}.woff`)}') format('woff'), - url('${require(`../fonts/${family}-${type}.woff2`)}') format('woff2')`, + url('${require(`${fontsPath}/${family}-${type}.woff`)}') format('woff'), + url('${require(`${fontsPath}/${family}-${type}.woff2`)}') format('woff2')`, }, }) -export const injectFontFaces = (fontFaces = []) => +export const injectFontFaces = (fontFaces = [], fontsPath) => fontFaces.forEach(({ family, type, weight }) => { try { - injectGlobal(fontFace(family, type, weight)) + injectGlobal(fontFace(family, type, weight, fontsPath)) } catch (error) { console.log(error) // eslint-disable-line }