Skip to content

Commit

Permalink
feat: allow configuring font-stretch property in override
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Apr 4, 2024
1 parent bfc55e6 commit d7ff458
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/css/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function generateFontFace (family: string, font: NormalizedFontFaceData)
font.unicodeRange && ` unicode-range: ${font.unicodeRange};`,
font.weight && ` font-weight: ${Array.isArray(font.weight) ? font.weight.join(' ') : font.weight};`,
font.style && ` font-style: ${font.style};`,
font.stretch && ` font-stretch: ${font.stretch};`,
font.featureSettings && ` font-feature-settings: ${font.featureSettings};`,
font.variationSettings && ` font-variation-settings: ${font.variationSettings};`,
`}`
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface FontFaceData {
display?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional'
/** A font-weight value. */
weight?: string | number | [number, number]
/** A font-stretch value. */
stretch?: string
/** A font-style value. */
style?: string
/** The range of Unicode code points to be used from the font. */
Expand Down
19 changes: 19 additions & 0 deletions test/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,23 @@ describe('rendering @font-face', () => {
}"
`)
})
it('should support additional properties', () => {
const css = generateFontFace('Helvetica Neue', {
src: [{ url: '/helvetica-neue.woff2' }],
stretch: 'expanded',
display: 'fallback',
style: 'italic',
weight: '400'
})
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'Helvetica Neue';
src: url("/helvetica-neue.woff2");
font-display: fallback;
font-weight: 400;
font-style: italic;
font-stretch: expanded;
}"
`)
})
})

0 comments on commit d7ff458

Please sign in to comment.