dookie-css
CSS library built on top of the Stylus preprocessor. It provides a couple of useful stylus mixins, utilities and components.
How to install
At first install package into your project:
npm install dookie-css
Express.js (Connect)
For express or connect framework you can simply include dookie middleware
method into Stylus' compiler:
var stylus = dookie = ; ... app
More about Stylus middleware here.
Other environments
As for pure node.js or some other cases dookie has method called css
. Here is an example of simple static server.js
using Stylus + dookie:
var stylus = dookie = ; ... // use stylus for styling // call dookie.css() function ;
Check out ./examples folder to see how dookie can be introduced with pure node.js static server or express framework.
So now all dookie utilities can be called within your .styl
files and it's time to check lib's documentation.
Stylus cli plugin
If you prefer use Stylus cli executable for converting Stylus to CSS, you can also use dookie with it. In --use
option specify path to dookie.js file, for example:
stylus --use /node_modules/dookie-css/dookiejs --out /
Further reading about Stylus cli here.
Documentation
Settings
Dookie contains default configuration settings.styl. So this depends on your needs, but it's recommended to create your own _settings.styl
(could be named whatever you like) and specify or overwrite existed variables.
Examples:
Here is custom _settings.styl
file which specifies vendors that are needed, and path to the folder with images:
//'
Now in your main Stylus file we add @import
configuration and start to use dookie easily:
List of global settings:
-
img-path
- path to the app folder with images (empty by default); -
vendors
- list of vendors you want to use (by default includeswebkit
,moz
,ms
,o
andofficial
which means unprefixed property); -
ie-support
- set totrue
to enable special IE properties likefilter: alpha(opacity = 100)
etc. -
font-stack
- global font-family stack; -
sans-serif
-serif
andmonospace
- default font-families; -
font-size
- global font-size variable; -
default-color
- global font color fallback;
Settings file is also a good place to put your own configuration on the project.
Reset mixins
These helpers are global (this also means you should use them in mixin form - mixin(args)
instead of mixin: args
):
reset()
- simple base and recommended reset;
normalize()
- popular normalize.css reset;
fields-reset()
- reset input fields from sometimes annoying browser based styles (on ::required, ::valid, ::invalid, etc. pseudo-classes);
Common useful helpers
Shorter replacements for display: block | inline-block | none
respectively:
block()
, inline-block()
, hide()
;
Frequently used text transformation and decoration properties shorthands:
reset-case()
, upcase()
, lowcase()
, nodecorate()
, underline()
, etc.
Font styles:
bold()
, italic()
, normal()
fs: [your font-size]
font-size shortener;
fw: [your font-weight]
font-weight shortener;
Examples:
) )) /* yields => */
clearfix()
basic clearfix, simply add it to your class name or call global mixin base-classes()
within your project to have it in .clearfix
class;
size: [width, height]
cool and useful dimensions shortener, example:
/* yields => */
bg: [path], [args optional]
background mixin shortener, example:
/* yields => */
bg-retina:[path], [args optional]
very similar mixin but adds background-size: contain
property for retina displays (use it together with @media all and (-webkit-min-device-pixel-ratio: 1.5)
);
Note: if you specify images folder in your settings img-path
variable it allows you to put only picture file name in all dookie mixins;
image-block: [path], [dimensions optional]
mixin that replaces block with image specified in it.
Note: .png
images could skip dimensions, because of Stylus native image-size()
built-in function, example:
/* yields => */
text-overflow: [width], [type optional]
useful when long text line need to be overflowed, default type is ellipsis, example:
/* yields => */
text-hide()
hiding text mixin;
no-select()
disallow user to select element;
round()
makes element rounded corners, useful for large ones;
opacity: [opacity]
same as native css property but if your settings set ie-support
to true
mixin adds old-school IE filter
property by itself;
triangle: [up|down|left|right], [size|default: 10px], [color|default: #000]
cool pure css triangle mixin, example:
/* yields => */
Positioning
Dookie allows you to shorten css element positioning while using simply one line property.
absolute: [name value], ...
relative: [name value], ...
fixed: [name value], ...
static: [name value], ...
Example:
/* yields => */
Sprites
Dookie has several helpers to simplify your work with sprites.
sprite-grid: [path], [x], [y], [grid]
basic grid helper, [path] to your sprite picture, [x], [y] - square counts where icon is placed and [grid] param is your grid step (also can be as 2 params - gridX
and gridY
), example:
/* yields => */
sprite-replace: [path], [x], [y], [grid]
same as previous one but also replaces text within an element with icon from the sprite;
Note: nice article describing these techniques by Niels Matthijs;
Vendor prefixes
Dookie intelligently simplifies usage of css properties that mostly need to be prefixed. Only thing that you should do is to setup in your _settings.styl
which prefixes you want to use (by default all of them are included). List of property mixins:
box-shadow: [args...]
border-radius: [args...]
box-sizing: [args...]
animation: [args...]
transition: [args...]
transformation: [args...]
perspective: [args...]
backface-visibility: [args...]
filters: [args...]
Note: Properties like animation
, transition
, transform
and perspective
also include all separate dependent props like animation-name
, transition-delay
, perspective-origin
etc.
-prefix: [property], [args...]
It is also good to know that if you need some property to be prefixed, you can use dookie's -prefix
method while passing into it property name and value, example:
) /* yields => */
Easings
Custom timing functions useful for ui-transitions, see all of them in action here:
ease-in- quad, cubic, quart, quint, sine, expo, circ, back
ease-out- quad, cubic, quart, quint, sine, expo, circ, back
ease-in-out- quad, cubic, quart, quint, sine, expo, circ, back
Example:
/* yields => */
Gradients
linear-gradient([start], [stops...])
mixin should be called within the property (background-image
or background
depends on what you prefer), example:
) /* yields => */
radial-gradient([stops...])
same as previous one but radial, example:
) /* yields => */
gradient: [colorStart], [colorStop]
shorthand for two colors linear-gradient, example:
/* yields => */
simple-gradient: [color], [strength percents|default: 10%]
generates linear-gradient from one color;
Global mixins
As reset helpers these mixins are global and should be called not within css selector but in file root.
base-classes()
adds couple of useful classes that you might add anyways, full list of them:
text-selection([highlight color], [text color|default: 'white'])
selection background and text color;
border-box()
enable border-box sizing globally;
font-face([name], [folder], [weight optional], [style optional])
bulletproof @font-face mixin, keep in mind that font name should be the same as font filename;
Example:
/) @);)),)),)),));
Test
Together with Stylus and dookie you can easily create tests for your mixins and utilities. Read more how you can test dookie itself with mocha.js and casper.js here - ./test/README.md.
Contribute
Dookie is in beta yet, so issues or useful pull requests are highly appreciated.
Why dookie?!
Because it's awesome Green Day's album from my childhood :)
MIT Licensed (c) 2013 Dmitri Voronianski