Snabbdom TypeStyle
Maintainable, scalable, and elegant styling with Snabbdom + TypeStyle
- All the power and benefits of TypeStyle
- Internal handling of classname mapping
- Server-side rendering support
Installation
npm install snabbdom-typestyle
Usage
Simply pass css
to your Snabbdom virtual node!
; { const buttonStyle: Style = color: 'blue' ; return <button css= buttonStyle > My Button </button> ; }
The CssModule is essentially a wrapper around TypeStyle style and can be passed either a single NestedCssProperties
or an array of NestedCssProperties
(or Style
, which is an alias provided by snabbdom-typestyle).
Make sure to pass the CssModule before the ClassModule when initializing Snabbdom.
; ; ; const modules = CssModule ClassModule ; const patch = ;
Or, if you are using Cycle.js pass modules
in the options of makeDOMdriver
.
;
For examples, take a look at this fork of the Cycle.js Todo-MVC implementation which uses snabbdom-typestyle.
Server-side Rendering
To use snabbdom-typestyle
in a server-side rendered environment, initialize Snabbdom with the serverSideCssModule
.
;;; const modules = serverSideCssModule modulesForHTMLclass; const patch = ;
When you are rendering your html, you can grab the styles via collectStyles(node: VNode): String
.
;
Then, on the client-side, pass a selector for the style element rendered by the server to makeClientSideCssModule(styleElementSelector: string | undefined)
.
Doing this avoids duplication of the style element when the application is hydrated.
;; const modules = ClassModule;
Take a look at the Cycle.js example here
License
MIT