Skip to content

Commit

Permalink
feat(fontFace): Add missing font-face properties to mixin
Browse files Browse the repository at this point in the history
Add font-display, font-feature-settings & font-variation-settings to fontDisplay mixin

closes styled-components#286
  • Loading branch information
oliver.phillips committed Jan 26, 2018
1 parent 07c46ff commit 37b6665
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/mixins/fontFace.js
Expand Up @@ -11,6 +11,9 @@ type FontFaceConfiguration = {
fileFormats?: Array<string>,
localFonts?: Array<string>,
unicodeRange?: string,
fontDisplay?: string,
fontVariationSettings?: string,
fontFeatureSettings?: string,
}

function generateFileReferences(
Expand Down Expand Up @@ -79,6 +82,9 @@ function fontFace({
fileFormats = ['eot', 'woff2', 'woff', 'ttf', 'svg'],
localFonts,
unicodeRange,
fontDisplay,
fontVariationSettings,
fontFeatureSettings,
}: FontFaceConfiguration): Object {
// Error Handling
if (!fontFamily) throw new Error('fontFace expects a name of a font-family.')
Expand All @@ -103,6 +109,9 @@ function fontFace({
fontStyle,
fontVariant,
fontWeight,
fontDisplay,
fontVariationSettings,
fontFeatureSettings,
},
}

Expand Down
3 changes: 3 additions & 0 deletions src/mixins/test/__snapshots__/fontFace.test.js.snap
Expand Up @@ -46,10 +46,13 @@ Object {
exports[`fontFace should set passed font configuration variables 1`] = `
Object {
"@font-face": Object {
"fontDisplay": "swap",
"fontFamily": "Sans Pro",
"fontFeatureSettings": "\"smcp\" on",
"fontStretch": "condensed",
"fontStyle": "italic",
"fontVariant": "small-caps",
"fontVariationSettings": "\"XHGT\" 0.7",
"fontWeight": "bold",
"src": "url(\"path/to/file.eot\"), url(\"path/to/file.woff2\"), url(\"path/to/file.woff\"), url(\"path/to/file.ttf\"), url(\"path/to/file.svg\")",
"unicodeRange": "U+26",
Expand Down
3 changes: 3 additions & 0 deletions src/mixins/test/fontFace.test.js
Expand Up @@ -60,6 +60,9 @@ describe('fontFace', () => {
fontWeight: 'bold',
fontVariant: 'small-caps',
unicodeRange: 'U+26',
fontDisplay: 'swap',
fontVariationSettings: '"XHGT" 0.7',
fontFeatureSettings: '"smcp" on',
}),
}).toMatchSnapshot()
})
Expand Down

0 comments on commit 37b6665

Please sign in to comment.