Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/functions/blur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import applyUnitToNumber from '../utils/applyUnitToNumber'

export default function blur(v) {
return 'blur(' + applyUnitToNumber(v) + ')'
}
3 changes: 3 additions & 0 deletions modules/functions/brightness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('brightness')
3 changes: 3 additions & 0 deletions modules/functions/contrast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('contrast')
9 changes: 9 additions & 0 deletions modules/functions/drop-shadow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import isObject from '../utils/isObject'
import applyUnitToNumbers from '../utils/applyUnitToNumber'

export default function dropShadow(x, y, blur, spread) {
const values = isObject(x) ? [ x.x, x.y, x.blur, x.spread ] : [ x, y, blur, spread ]
const filtred = values.filter(v => v != null)

return 'drop-shadow(' + applyUnitToNumbers(filtred) + ')'
}
3 changes: 3 additions & 0 deletions modules/functions/grayscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('grayscale')
5 changes: 5 additions & 0 deletions modules/functions/hueRotate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import applyUnitToNumber from '../utils/applyUnitToNumber'

export default function hueRotate(v) {
return 'hue-rotate(' + applyUnitToNumber(v, 'deg') + ')'
}
3 changes: 3 additions & 0 deletions modules/functions/invert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('invert')
3 changes: 3 additions & 0 deletions modules/functions/opacity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('opacity')
6 changes: 3 additions & 3 deletions modules/functions/perspective.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function perspective(p) {
return 'perspective(' + p + ')'
}
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('perspective')
3 changes: 3 additions & 0 deletions modules/functions/saturate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('saturate')
6 changes: 3 additions & 3 deletions modules/functions/scaleX.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function scaleX(x) {
return 'scaleX(' + x + ')'
}
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('scaleX')
6 changes: 3 additions & 3 deletions modules/functions/scaleY.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function scaleY(y) {
return 'scaleY(' + y + ')'
}
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('scaleY')
6 changes: 3 additions & 3 deletions modules/functions/scaleZ.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function scaleZ(z) {
return 'scaleZ(' + z + ')'
}
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('scaleZ')
3 changes: 3 additions & 0 deletions modules/functions/sepia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import simpleFunctionFactory from '../utils/simpleFunctionFactory'

export default simpleFunctionFactory('sepia')
2 changes: 2 additions & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export blur from './functions/blur'
export brightness from './functions/brightness'
export hsl from './functions/hsl'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please export the other functions as well

export hsla from './functions/hsla'
export matrix from './functions/matrix'
Expand Down
5 changes: 5 additions & 0 deletions modules/utils/simpleFunctionFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function simpleFunctionFactory(cssfunction) {
return function (v) {
return cssfunction + '(' + v + ')'
}
}
15 changes: 14 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ This package ships functions that return the equivalent CSS function syntax.
There will be automatic value validation in non-production mode soon.

## Functions
Right now we ship 25 functions.<br>
Right now we ship 35 functions.<br>

* `blur(v)`
* `brightness(v)`
* `contrast(v)`
* `dropShadow(offsetX, offsetY, blurRadius, spreadRadius, color)`
* `grayscale(v)`
* `hsl(h, s, l)`
* `hsla(h, s, l, a)`
* `hueRotate(v)`
* `invert(v)`
* `matrix(a, b, c, d, x, y)`
* `matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4)`
* `opacity(v)`
* `perspective(p)`
* `rgb(r, g, b)`
* `rgba(r, g, b, a)`
Expand All @@ -18,11 +26,13 @@ Right now we ship 25 functions.<br>
* `rotateX(x)`
* `rotateY(y)`
* `rotateZ(z)`
* `saturate(v)`
* `scale(x, y)`
* `scale3d(x, y, z)`
* `scaleX(x)`
* `scaleY(y)`
* `scaleZ(z)`
* `sepia(z)`
* `skew(x, y)`
* `skewX(x)`
* `skewY(y)`
Expand Down Expand Up @@ -82,13 +92,16 @@ const combined = multiple(
## Units
As the above example shows, we add default units to some numbers.
#### px
* `blur`
* `dropShadow`
* `translate`
* `translate3d`
* `translateX`
* `translateY`
* `translateZ`

#### deg
* `hueRotate`
* `rotate`
* `rotate3d`
* `rotateX`
Expand Down