Skip to content

Commit c2d178a

Browse files
committed
fix: cssobj param order bug
1 parent 9b37d11 commit c2d178a

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"plugins": ["./index"],
2+
"plugins": ["./index", "add-module-exports"],
33
"ignore": ["node_modules"]
44
}

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
1-
# babel-plugin-transform-cssobj-jsx
2-
Babel plugin to transform class names into cssobj localized names, easily transform existing code into cssobj.
1+
# babel-plugin-transform-cssobj
2+
Babel plugin to transform css into cssobj (CSS in JS solution), map class names into cssobj localized names
33

44
[![Join the chat at https://gitter.im/css-in-js/cssobj](https://badges.gitter.im/css-in-js/cssobj.svg)](https://gitter.im/css-in-js/cssobj)
5-
[![Build Status](https://travis-ci.org/cssobj/babel-plugin-transform-cssobj-jsx.svg?branch=master)](https://travis-ci.org/cssobj/babel-plugin-transform-cssobj-jsx)
6-
[![Coverage Status](https://coveralls.io/repos/github/cssobj/babel-plugin-transform-cssobj-jsx/badge.svg?branch=master)](https://coveralls.io/github/cssobj/babel-plugin-transform-cssobj-jsx?branch=master)
7-
[![npm](https://img.shields.io/npm/v/babel-plugin-transform-cssobj-jsx.svg "Version")](https://www.npmjs.com/package/cssobj)
5+
[![Build Status](https://travis-ci.org/cssobj/babel-plugin-transform-cssobj.svg?branch=master)](https://travis-ci.org/cssobj/babel-plugin-transform-cssobj)
6+
[![Coverage Status](https://coveralls.io/repos/github/cssobj/babel-plugin-transform-cssobj/badge.svg?branch=master)](https://coveralls.io/github/cssobj/babel-plugin-transform-cssobj?branch=master)
7+
[![npm](https://img.shields.io/npm/v/babel-plugin-transform-cssobj.svg "Version")](https://www.npmjs.com/package/cssobj)
88

99
## Usage
1010

1111
1. Install
1212

1313
``` bash
14-
npm install --save-dev babel-plugin-transform-cssobj-jsx
14+
npm install --save-dev babel-plugin-transform-cssobj
1515
```
1616

1717
2. In your `.babelrc`:
1818

1919
``` json
2020
{
21-
"plugins": ["transform-cssobj-jsx"]
21+
"plugins": ["transform-cssobj"]
2222
}
2323
```
2424

25-
3. **Wrap your JSX in result.mapClass()**
25+
3. **Write CSS as normal, Wrap JSX in result.mapClass()**
2626

2727
``` javascript
28-
const style = cssobj(obj)
29-
30-
const html = style.mapClass(
28+
const result = CSSOBJ`
29+
---
30+
plugins:
31+
- default-unit: px
32+
- flexbox
33+
---
34+
body { color: red; font-size:12 }
35+
.container { display: flex; height: ${ getWindowHeight() }; }
36+
.item { flex: 1; width: 100; height: ${ v=> v.prev + 1 } }
37+
`
38+
39+
const html = result.mapClass(
3140
<div className='container'>
3241
<div className={func()}>
3342
<p className='!news item active'> </p></div></div>
@@ -37,6 +46,27 @@ Babel plugin to transform class names into cssobj localized names, easily transf
3746
Which transform into below code:
3847

3948
``` javascript
49+
import cssobj from "cssobj";
50+
import cssobj_plugin_default_unit from "cssobj-plugin-default-unit";
51+
import cssobj_plugin_flexbox from "cssobj-plugin-flexbox";
52+
const result = cssobj({
53+
plugins: [cssobj_plugin_default_unit('px'), cssobj_plugin_flexbox()]
54+
}, {
55+
body: {
56+
color: 'red',
57+
fontSize: 12
58+
},
59+
'.container': {
60+
display: 'flex',
61+
height: getWindowHeight()
62+
},
63+
'.item': {
64+
flex: 1,
65+
width: 100,
66+
height: v => v.prev + 1
67+
}
68+
});
69+
4070
const html = (
4171
<div className={style.mapClass('container')}>
4272
<div className={style.mapClass(func())}>
@@ -72,7 +102,7 @@ You have two way to escape the transform
72102

73103
``` json
74104
{
75-
"plugins": [ ["transform-cssobj-jsx", {"mapName": "makeLocal"}] ]
105+
"plugins": [ ["transform-cssobj", {"mapName": "makeLocal"}] ]
76106
}
77107
```
78108

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = function (babel) {
9696
t.stringLiteral(cssobjNS.path)
9797
))
9898

99-
path.replaceWithSourceString(`${cssobjName} (${config}, ${objStr})`)
99+
path.replaceWithSourceString(`${cssobjName} (${objStr}, ${config})`)
100100
}
101101
},
102102
CallExpression (path, state) {

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "babel-plugin-transform-cssobj-jsx",
3-
"version": "2.1.0",
4-
"description": "Babel plugin to transform class names into cssobj localized",
2+
"name": "babel-plugin-transform-cssobj",
3+
"version": "3.0.1",
4+
"description": "Babel plugin to transform css into cssobj (CSS in JS engine), map class names into cssobj localized names",
55
"main": "index.js",
66
"directories": {
77
"test": "test"
@@ -36,6 +36,7 @@
3636
"homepage": "https://github.com/cssobj/babel-plugin-transform-cssobj-jsx#readme",
3737
"devDependencies": {
3838
"babel-core": "^6.21.0",
39+
"babel-plugin-transform-es2015-modules-umd": "^6.18.0",
3940
"chai": "^3.5.0",
4041
"coveralls": "^2.11.15",
4142
"gulp": "^3.9.1",
@@ -46,6 +47,6 @@
4647
"dependencies": {
4748
"babel-plugin-syntax-jsx": "^6.18.0",
4849
"cssobj-converter": "*",
49-
"objutil": "^2.0.6"
50+
"objutil": "^2.0.7"
5051
}
5152
}

test/test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ import cssobj_plugin_flexbox from "cssobj-plugin-flexbox";
7575
7676
var getUnit = v => v;
7777
var d = cssobj({
78-
plugins: [cssobj_plugin_default_unit(getUnit()), cssobj_plugin_default_unit_2('px'), cssobj_plugin_default_unit_3(), cssobj_plugin_flexbox({
79-
pref: 1234,
80-
abc: 'def'
81-
})]
82-
}, {
8378
body: [{
8479
color: 'red'
8580
}, {
8681
color: 'v=>v'
8782
}, {
8883
fontSize: 234
8984
}]
85+
}, {
86+
plugins: [cssobj_plugin_default_unit(getUnit()), cssobj_plugin_default_unit_2('px'), cssobj_plugin_default_unit_3(), cssobj_plugin_flexbox({
87+
pref: 1234,
88+
abc: 'def'
89+
})]
9090
});`)
9191
})
9292

@@ -109,9 +109,9 @@ plugins:
109109
import cssobj_plugin_default_unit from "cssobj-plugin-default-unit";
110110
import cssobj_plugin_flexbox from "cssobj-plugin-flexbox";
111111
112-
cssobj({
112+
cssobj({}, {
113113
plugins: [cssobj_plugin_default_unit('px'), cssobj_plugin_flexbox()]
114-
}, {});`)
114+
});`)
115115
})
116116

117117
it('should work with no config', function() {
@@ -123,15 +123,15 @@ body { color: $\{getColor()\}; }
123123
`
124124
expect(lib(node)).to.equal(`import cssobj from "cssobj";
125125
126-
var d = cssobj({}, {
126+
var d = cssobj({
127127
body: {
128128
color: getColor()
129129
},
130130
'.p1': {
131131
color: 'blue',
132132
fontSize: '12px'
133133
}
134-
});`)
134+
}, {});`)
135135

136136
node = `
137137
var d = CSSOBJ\`
@@ -142,11 +142,11 @@ body {color: red;}
142142
`
143143
expect(lib(node)).equal(`import cssobj from "cssobj";
144144
145-
var d = cssobj({}, {
145+
var d = cssobj({
146146
body: {
147147
color: 'red'
148148
}
149-
});`)
149+
}, {});`)
150150
})
151151

152152
it('should not change other templateLiteral', function() {
@@ -200,9 +200,9 @@ plugins:
200200
expect(lib(node)).equal(`import abc from "./cssobj";
201201
import unit from "./unit";
202202
import box from "cssobj-plugin-flexbox";
203-
abc({
203+
abc({}, {
204204
plugins: [unit(), box()]
205-
}, {});`)
205+
});`)
206206
})
207207

208208
})

0 commit comments

Comments
 (0)