├── .babelrc
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── lib
└── index.js
├── package.json
├── src
└── index.js
└── test
└── index.spec.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "stage": 0
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 | node_modules
4 | bower_components
5 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .babelrc
3 | src
4 | test
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Maximiliano Guzenski
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Easy Style
2 |
3 | A tiny library to easy apply css/styles to react components with **zero references** to your css classes or to inline-styles.
4 |
5 | ## Install
6 |
7 | `npm install react-easy-style`
8 |
9 | you'll need also:
10 | `webpack`, `css-loader`, `react`
11 |
12 | ## Why?
13 | The React community is highly fragmented when it comes to styling. Right now, there is more then 16 project for inline css on the github, all of they are trying to fix some "issue" that css has, like global scope... but, I think, they all are creating a lot of new one as well.
14 |
15 | **React Easy Style** "borrow" ideas from one of those projects: react-css (1). And join it with webpack css-loader (2) to make a very light and useful library to easy use classes and styles on react components.
16 |
17 | 1. [react-css](http://reactcss.com/): seems to be the only one to have noticed that style and react props/state are strong linked to each other.
18 |
19 | 2. [webpack css-loader](https://github.com/webpack/css-loader): with support to [CSS Module spec](https://github.com/css-modules/css-modules) that fix css global scope issue.
20 |
21 |
22 | ## How?
23 |
24 | Take a look!
25 |
26 | ```javascript
27 | // button.jsx
28 |
29 | import React from 'react'
30 | import EasyStyle from 'react-easy-style'
31 |
32 | // import css/scss/less with webpack css-loader
33 | // webpack.config sample loaders: [{test: /\.scss$/, loader: "style!css!sass" }]
34 | import css from './button.scss'
35 |
36 | @EasyStyle( css )
37 | export default class Button extends React.Component {
38 | static defaultProps = {
39 | kind: 'default', circle: false
40 | }
41 |
42 | render() {
43 | return
44 | }
45 | }
46 |
47 | // if you don't use decorators:
48 | // class Button extends React.component { ... }
49 | // export default EasyStyle(css)(Button)
50 | ```
51 | ```sass
52 | // button.scss
53 |
54 | :local .Button {
55 | border: 1px solid transparent;
56 | // a lot of other styles
57 |
58 | // browser state rules
59 | &:focus { outline: none; }
60 |
61 | // React props/state rules
62 | // pattern: className--propsKey-propsValue
63 |
64 | &--circle-true { border-radius: 50% }
65 |
66 | &--kind-default { /*...*/ }
67 | &--kind-primary { /*...*/ }
68 | &--kind-success { /*...*/ }
69 | }
70 | ```
71 | And that is it. Seriously! For small/medium components you will end up with 0 (zero) css references on you code.
72 |
73 | Here a example of how to call it and its output:
74 |
75 | ```javascript
76 | // when you call
77 |
78 |
79 | // ... you'll receive this final html
80 |
81 |
82 | // ps.: On real world, css-modules will change classes names
83 | // to make they unique (no more global namespace!), something like:
84 |
85 |
86 | ```
87 | For more complex components, please, keep reading ;-)
88 |
89 |
90 | ## Other examples
91 |
92 | #### When you need pass internal and external classNames...
93 | ```javascript
94 | class Button extends React.Component {
95 | render() {
96 | return (
97 |
98 | )
99 | }
100 | }
101 |
102 | // call
103 |
104 |
105 | // html output
106 |
107 | ```
108 |
109 | #### You can make references to a nested class (using 'is' attribute)
110 | ```javascript
111 | class Button extends React.Component {
112 | render() {
113 | return (
114 |
118 | )
119 | }
120 | }
121 |
122 | // call
123 |
124 |
125 | // html output
126 | // don't forget, with css-modules, label and desc class names will receive unique names
127 | // so... using a generic name like 'label' isn't a issue
128 |
132 |
133 | ```
134 | ```scss
135 | // button.scss
136 |
137 | :local .Button {
138 | .label { color: #000 }
139 | .desc { font-size: 85% }
140 |
141 | // and into your states...
142 | .&--kind-primary .label {}
143 | .&--kind-primary .desc {}
144 | }
145 |
146 | ```
147 |
148 | #### Classes and styles defined on nested element will be merged as well
149 | ```javascript
150 | class Button extends React.Component {
151 | render() {
152 | return (
153 |
157 | )
158 | }
159 | }
160 |
161 | // call
162 |
163 |
164 | // html output
165 |
169 | ```
170 |
171 |
172 | #### Your root and nested elements can receive classes and styles from outside
173 |
174 | To nested elements that use, for example, is='label' you'll have labelClasses='class1' and labelStyle={{...}}.
175 | for top-level element (root) you have rootClasses, rootStyle, className and style.
176 | In another word: Themeable for free.
177 |
178 | ```javascript
179 | class Button extends React.Component {
180 | render() {
181 | return (
182 |
186 | )
187 | }
188 | }
189 |
190 | // call
191 | // ps.: for root you can use className/style or rootClasses/rootStyle or both ;)
192 | // all styles will be merged
193 |
200 |
201 | // html output
202 |
206 | ```
207 |
208 | #### If your top-level element is not your root element, use is='root'
209 | ```javascript
210 | class Button extends React.Component {
211 | render() {
212 | return (
213 |
214 | )
215 | }
216 | }
217 |
218 | // call
219 |
220 |
221 | //output
222 |