Spacing
Maintain a coherent spacing calculation throughout the app.
It is important to keep a regular spacing method in order to convey harmony to the end user. The spacing function can be used to fulfill that.
Usage
Parameters
The generateSpacing function accepts only one options parameter used to set the default values. It can have the following properties.
property
type
description
increment
number
the amount that will be multiplied by the input value
base
number
the base number of the calculation
unit
string
the unit to be used when returning strings
Default options
Custom defaults
You can define you own defaults but passing the options object into the generate function.
Note: the base value is always added to the final value with the formula
base + (input * increment)<unit>
, to bypass that you can input-0
as the spacing, and the function will return0<unit>
.
Spacing function
The spacing is the result of the generator function. You have to call it to get an actual distance unit string as output and it can be used throughout your app.
If called without parameters it will return the default values as shown above, but it has 6 valid signatures.
Calculate the default value and returns it as a number.
Calculates the value based on the spacing and returns it as a number.
Calculates the value based on the spacing and returns it as a string.
Calculates the value based on vertical and horizontal and returns it as a string.
Calculates the value based on top, horizontal and bottom and returns it as a string.
Calculates the value based on top, right, bottom and left and returns it as a string.
Last updated