gr8-util
A little function for generating functional css utilities.
Usage
Given some options, gr8-util
returns a string of css utilities. It does its best to generate concise and logical css selectors.
var util = var css = console
API
css = util([opts])
Generate a string of css utility rules. opts
accepts the following values:
opts.prop
[String | Array | Object] css property(ies) *requiredopts.vals
[Number | String | Array | Object] css values *requiredopts.modifiers
[String | Array | Object] selector modifier(s)opts.unit
[String] unit to append to css values (only appended if values are numeric)opts.tail
[String] string to append after selectoropts.join
[String] string to join abbreviation and value in selectoropts.selector
[Function] css selector template functionopts.transform
[Function] value transform functionopts.parent
[String] global parent selector
Examples
These examples are primarily to demonstrate how options are used to generate a wide variety of css utilities. They are not necessarily very useful css utilities themselves.
Most basic, single prop
and single vals
var css =
Use an array as prop
and vals
, as well as define unit
. Notice how floating point values are sanitized in generated selector (decimal replaced with hyphen), and how unit is not appended to a value of 0.
var css =
Use an object as prop
and vals
in order to override generated abbreviations. Define join
to add things like hyphens to selectors.
var css =
Use a nested array as prop
in order to generate rules with multiple properties. Notice how kebab-case properties are abbreviated in selector.
var css =
Use an array which contains both strings and key/val objects as prop
in order to override only specific abbreviations.
var css =
Do the same as previous example with vals
as well.
var css =
Pass a function to selector
in order to create selectors other than class selectors. Function receives the generated selector name as input and should return a css selector as a string.
var css =
[
Use modifiers
in order to generate rules for things like pseudo-classes, pseudo-elements, and descendant selectors. Exceptionally useful for hover states.
var css =
Passing false
to modifiers generates rules without a modifier. This is useful for concisely creating sets of rules:
var css =
Use tail
in order to append an arbitrary string to a selector. Useful when adding things like pseudo-classes which do not need a modifier in the classname.
var css =
Use transform
in order to transform values as they are placed into declarations. Useful for things like columns:
var css =
Use parent
in order to namespace your rules. Useful for conditional utilities:
var css =
Why
Provides consistency and flexibility when generating functional css utility systems, such as gr8.
Todo
- Defaults
- Assertions