Style
/ API Reference / Plugins
Style
/ API Reference / Plugins

unit

This plugin converts numeric values to the given unit.
It is aware of unitless properties such as line-height, zero-values and also adds units to multiple values inside an array.

The Gist

import { unitPlugin } from '@weser/style'

const plugin = unitPlugin('px', {
  fontSize: 'rem',
})

Parameters

ParameterTypeDefaultDescription
defaultUnitstring'px'The global unit that gets applied to all numeric values.
propertyMapPartial<Record<keyof T_Style, string>>{}Property-specific unit overwrites.
isUnitlessProperty(property: string) => booleanisUnitlessProperty (new tab)A function that determines whether a property should remain unitless.

Returns

(Plugin) A plugin function that can be passed to the createRenderer function.

On this page