Skip to content

Commit 48dc2d7

Browse files
author
rofrischmann
committed
added api docs and improved functions
1 parent b298a47 commit 48dc2d7

File tree

8 files changed

+82
-13
lines changed

8 files changed

+82
-13
lines changed

modules/functions/matrix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isObject from '../utils/isObject'
22

33
export default function matrix(a, b, c, d, x, y) {
4-
const values = isObject(a) ? [ r.a, r.b, r.c, r.d, r.x, r.y ] : [ a, b, c, d, x, y ]
4+
const values = isObject(a) ? [ a.a, a.b, a.c, a.d, a.x, a.y ] : [ a, b, c, d, x, y ]
55
return 'matrix(' + values.join(',') + ')'
66
}

modules/functions/matrix3d.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isObject from '../utils/isObject'
22

33
export default function matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
4-
const values = isObject(a1) ? [ r.a1, r.b1, r.c1, r.d1, r.a2, r.b2, r.c2, r.d2, r.a3, r.b3, r.c3, r.d3, r.a4, r.b4, r.c4, r.d4 ] : [ a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4 ]
4+
const values = isObject(a1) ? [ a1.a1, a1.b1, a1.c1, a1.d1, a1.a2, a1.b2, a1.c2, a1.d2, a1.a3, a1.b3, a1.c3, a1.d3, a1.a4, a1.b4, a1.c4, a1.d4 ] : [ a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4 ]
55
return 'matrix3d(' + values.join(',') + ')'
66
}

modules/functions/rotate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import isObject from '../utils/isObject'
22

33
export default function rotate(x, y) {
44
const values = isObject(x) ? [ r.x, r.y ] : [ x, y ]
5-
return 'rotate(' + values.join(',') + ')'
5+
return 'rotate(' + values.join('deg,') + 'deg' + ')'
66
}

modules/functions/rotate3d.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import isObject from '../utils/isObject'
22

33
export default function rotate3d(x, y, z) {
44
const values = isObject(x) ? [ r.x, r.y, r.z ] : [ x, y, z ]
5-
return 'rotate3d(' + values.join(',') + ')'
5+
return 'rotate3d(' + values.join('deg,') + 'deg' + ')'
66
}

modules/functions/rotateX.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function rotateX(x) {
2-
return 'rotateX(' + x + ')'
2+
return 'rotateX(' + x + 'deg)'
33
}

modules/functions/rotateY.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function rotateY(y) {
2-
return 'rotateY(' + y + ')'
2+
return 'rotateY(' + y + 'deg)'
33
}

modules/functions/rotateZ.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function rotateZ(z) {
2-
return 'rotateZ(' + z + ')'
2+
return 'rotateZ(' + z + 'deg)'
33
}

readme.md

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,78 @@
1-
## JS functions to build CSS functions
1+
## JavaScript functions to build CSS functions
2+
3+
This package ships functions that return the equivalent CSS function syntax.
4+
5+
## API
6+
Right now we ship 25 functions.<br>
7+
8+
* `hsl(h, s, l)`
9+
* `hsla(h, s, l, a)`
10+
* `matrix(a, b, c, d, x, y)`
11+
* `matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4)`
12+
* `perspective(p)`
13+
* `rgb(r, g, b)`
14+
* `rgba(r, g, b, a)`
15+
* `rotate(x, y)`
16+
* `rotate3d(x, y, z)`
17+
* `rotateX(x)`
18+
* `rotateY(y)`
19+
* `rotateZ(z)`
20+
* `scale(x, y)`
21+
* `scale3d(x, y, z)`
22+
* `scaleX(x)`
23+
* `scaleY(y)`
24+
* `scaleZ(z)`
25+
* `skew(x, y)`
26+
* `skewX(x)`
27+
* `skewY(y)`
28+
* `translate(x, y)`
29+
* `translate3d(x, y, z)`
30+
* `translateX(x)`
31+
* `translateY(y)`
32+
* `translateZ(z)`
33+
34+
### Parameter object notation
35+
All parameters can always be passed as a single objects as well.<br>
36+
The keys always match the parameter name e.g. `rotate3d({ x, y, z })` except for the following color functions:
37+
38+
* `hsl({ hue, saturation, lightness })`
39+
* `hsla({ hue, saturation, alpha })`
40+
* `rgb({ red, green, blue })`
41+
* `rgba({ red, green, blue, alpha })`
42+
43+
## Example
44+
```javascript
45+
import { rgba, translate3d } from 'css-functions'
46+
47+
// => 'rgba(255, 0, 255, 0.5)'
48+
const color = rgba(255, 0, 255, 0.5)
49+
const color = rgba({
50+
red: 255,
51+
green: 0,
52+
blue: 255,
53+
alpha: 0.5
54+
})
55+
56+
// => 'translate3d(10px, 10%, 0)'
57+
const transform = translate3d('10px', '10%', 0)
58+
const transform = translate3d({
59+
x: '10px',
60+
y: '10%',
61+
z: 0
62+
})
63+
```
64+
65+
## Multiple functions
66+
To combine multiple functions safely, it ships the `multiple` API.
67+
It safely combines both returned strings separated by a whitespace.
268

369
```javascript
4-
rgba(255, 255, 255, 0.5)
5-
```
70+
import { translateX, scale, rotateX, multiple } from 'css-functions'
671

7-
```css
8-
rgba(255, 255, 255, 0.5)
9-
```
72+
// => 'translateX('10%') scale(0.5, 0.5) rotateX(180deg)'
73+
const combined = multiple(
74+
translateX('10%'),
75+
scale(0.5, 0.5),
76+
rotateX(180)
77+
)
78+
```

0 commit comments

Comments
 (0)