|
| 1 | +# ezcss |
| 2 | + |
| 3 | +[![][npm-badge]][npm-url] [![][travis-badge]][travis-url] |
| 4 | + |
| 5 | +Super lite CSS-in-JS solution. |
| 6 | + |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +Import renderer. |
| 11 | + |
| 12 | +```js |
| 13 | +import {Renderer} from 'ezcss'; |
| 14 | + |
| 15 | +const renderer = new Renderer; |
| 16 | +const {rule, sheet, withStyles, useStyles, styled, css} = renderer; |
| 17 | +``` |
| 18 | + |
| 19 | +Render a single "rule". |
| 20 | + |
| 21 | +```js |
| 22 | +const className = rule({ |
| 23 | + border: '1px solid red' |
| 24 | +}, 'MyName'); |
| 25 | + |
| 26 | +<div className={className} /> |
| 27 | +``` |
| 28 | + |
| 29 | +Create a "styles sheet" with multiple lazy-evaluating rules. |
| 30 | + |
| 31 | +```js |
| 32 | +const styles = sheet({ |
| 33 | + main: { |
| 34 | + border: '1px solid red' |
| 35 | + }, |
| 36 | + element: { |
| 37 | + border: '1px solid blue' |
| 38 | + } |
| 39 | +}, 'MyName'); |
| 40 | + |
| 41 | +<div className={styles.main} /> |
| 42 | +``` |
| 43 | + |
| 44 | +Injects `styles` prop into component. |
| 45 | + |
| 46 | +```js |
| 47 | +const styles = { |
| 48 | + main: { |
| 49 | + border: '1px solid red' |
| 50 | + } |
| 51 | +}; |
| 52 | + |
| 53 | +const MyComp = withStyles(styles, function MyComp ({styles}) { |
| 54 | + return <div className={styles.main} /> |
| 55 | +}); |
| 56 | +``` |
| 57 | + |
| 58 | +Use `styles` object in your component. |
| 59 | + |
| 60 | +```js |
| 61 | +const styles = { |
| 62 | + main: { |
| 63 | + border: '1px solid red' |
| 64 | + } |
| 65 | +}; |
| 66 | + |
| 67 | +const MyComp = useStyles(styles, function MyComp (props, styles) { |
| 68 | + return <div className={styles.main} /> |
| 69 | +}); |
| 70 | +``` |
| 71 | + |
| 72 | +Create "styled" components. |
| 73 | + |
| 74 | +```js |
| 75 | +const Div = styled('div', { |
| 76 | + border: '1px solid red' |
| 77 | +}, 'RedBorderDiv'); |
| 78 | + |
| 79 | +<Div>Hello world!</Div> |
| 80 | +``` |
| 81 | + |
| 82 | +Stateful component style decorator. |
| 83 | + |
| 84 | +```js |
| 85 | +@css({ |
| 86 | + border: '1px solid red' |
| 87 | +}) |
| 88 | +class MyComponent extends Component { |
| 89 | + render () { |
| 90 | + |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | + |
| 96 | +## Server Side Rendering |
| 97 | + |
| 98 | +`excss` works in Node.js environment as well. Use `.raw` property to access raw CSS styles |
| 99 | +on server and include then in your template. |
| 100 | + |
| 101 | +```js |
| 102 | +const html += `<style>${renderer.raw}</style>`; |
| 103 | +``` |
| 104 | + |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +[Unlicense](./LICENSE) — public domain. |
| 109 | + |
| 110 | + |
| 111 | +[npm-url]: https://www.npmjs.com/package/ezcss |
| 112 | +[npm-badge]: https://img.shields.io/npm/v/ezcss.svg |
| 113 | +[travis-url]: https://travis-ci.org/streamich/ezcss |
| 114 | +[travis-badge]: https://travis-ci.org/streamich/ezcss.svg?branch=master |
0 commit comments