Skip to content

Add css filtering functions #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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')
10 changes: 10 additions & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export blur from './functions/blur'
export brightness from './functions/brightness'
export contrast from './function/contrast'
export dropShadow from './functions/dropShadow'
export grayscale from './function/grayscale'
export hsl from './functions/hsl'
export hsla from './functions/hsla'
export hueRotate from './functions/hueRotate'
export invert from './functions/invert'
export matrix from './functions/matrix'
export matrix3d from './functions/matrix3d'
export opacity from './functions/opacity'
export perspective from './functions/perspective'
export rgb from './functions/rgb'
export rgba from './functions/rgba'
Expand All @@ -10,11 +18,13 @@ export rotate3d from './functions/rotate3d'
export rotateX from './functions/rotateX'
export rotateY from './functions/rotateY'
export rotateZ from './functions/rotateZ'
export saturate from './function/saturate'
export scale from './functions/scale'
export scale3d from './functions/scale3d'
export scaleX from './functions/scaleX'
export scaleY from './functions/scaleY'
export scaleZ from './functions/scaleZ'
export sepia from './function/sepia'
export skew from './functions/skew'
export skewX from './functions/skewX'
export skewY from './functions/skewY'
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