Skip to content

Commit

Permalink
fix(theme): change font operations flow
Browse files Browse the repository at this point in the history
affects: @atlantis-lab/theme

- Added additional fontsPath prop in injectGlobalStyles
- Changed props order

ISSUES CLOSED: #237
  • Loading branch information
TFK70 committed Mar 8, 2021
1 parent 322de1f commit 416c626
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
31 changes: 16 additions & 15 deletions packages/theme/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
10 changes: 5 additions & 5 deletions packages/theme/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 416c626

Please sign in to comment.