Skip to content

Commit

Permalink
✨ Add variable font dance
Browse files Browse the repository at this point in the history
  • Loading branch information
maici committed Dec 25, 2018
1 parent 1ce7095 commit 1c36b61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Dancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import swing, { reset as swingReset } from './dances/swing.js'
import neon, { reset as neonReset } from './dances/neon.js'
import kern, { reset as kernReset } from './dances/kern.js'
import fontSize, { reset as fontSizeReset } from './dances/font-size.js'
import variableFont, { reset as variableFontReset } from './dances/variable-font.js'
import borderWidth, {
reset as borderWidthReset,
} from './dances/border-width.js'
Expand All @@ -37,6 +38,8 @@ class Dancer {
this.registerDance('borderWidth', borderWidth, borderWidthReset)
this.registerDance('fontSize', fontSize, fontSizeReset)
this.registerDance('tilt', tilt, tiltReset)
this.registerDance('variableFont', variableFont, variableFontReset)

}

registerDance(type, dance, reset = () => {}) {
Expand Down
13 changes: 13 additions & 0 deletions src/dances/variable-font.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const generateFontVariationSettings = (value, options) => Object.entries(options).reduce((fontVariationSettings,[key, { min, max }]) => {
const computedValue = ((max - min) * value + min)
return `${fontVariationSettings ? `${fontVariationSettings},` : ''} '${key}' ${computedValue}`
}, null)

export default (elem, value, options = {}) => {
elem.style.fontVariationSettings = generateFontVariationSettings(value, options)
}

export const reset = elem => {
elem.style.fontVariationSettings = null
}

0 comments on commit 1c36b61

Please sign in to comment.