1
1
const _ = require ( 'lodash' ) ;
2
2
const Color = require ( 'color' ) ;
3
3
4
+ const listColors = function ( colors , transparentFirst = true ) {
5
+ if ( ! _ . isArray ( colors ) || colors . length === 1 ) {
6
+ const color = _ . isArray ( colors ) ? colors [ 0 ] : colors ;
7
+ const parsedColor = Color ( color ) ;
8
+ const transparentColor = parsedColor . alpha ( 0 ) . rgb ( ) . string ( ) ;
9
+ colors = transparentFirst ? [ transparentColor , color ] : [ color , transparentColor ] ;
10
+ }
11
+ return colors . join ( ', ' ) ;
12
+ } ;
13
+
4
14
module . exports = function ( ) {
5
15
return ( { theme, variants, e, addUtilities } ) => {
6
- const defaultGradientDirections = {
16
+ const defaultLinearGradientDirections = {
7
17
't' : 'to top' ,
8
18
'tr' : 'to top right' ,
9
19
'r' : 'to right' ,
@@ -13,30 +23,66 @@ module.exports = function() {
13
23
'l' : 'to left' ,
14
24
'tl' : 'to top left' ,
15
25
} ;
16
- const defaultGradientColors = { } ;
17
- const defaultGradientVariants = [ 'responsive' ] ;
26
+ const defaultLinearGradientColors = { } ;
27
+ const defaultLinearGradientVariants = [ 'responsive' ] ;
28
+ const defaultRadialGradientShapes = {
29
+ 'default' : 'ellipse' ,
30
+ } ;
31
+ const defaultRadialGradientSizes = {
32
+ 'default' : 'closest-side' ,
33
+ } ;
34
+ const defaultRadialGradientPositions = {
35
+ 'default' : 'center' ,
36
+ 't' : 'top' ,
37
+ 'tr' : 'top right' ,
38
+ 'r' : 'right' ,
39
+ 'br' : 'bottom right' ,
40
+ 'b' : 'bottom' ,
41
+ 'bl' : 'bottom left' ,
42
+ 'l' : 'left' ,
43
+ 'tl' : 'top left' ,
44
+ } ;
45
+ const defaultRadialGradientColors = { } ;
46
+ const defaultRadialGradientVariants = [ 'responsive' ] ;
18
47
19
- const gradientDirections = theme ( 'gradients.directions' , defaultGradientDirections ) ;
20
- const gradientColors = theme ( 'gradients.colors' , defaultGradientColors ) ;
21
- const gradientVariants = variants ( 'gradients' , defaultGradientVariants ) ;
48
+ const linearGradientDirections = theme ( 'linearGradients.directions' , defaultLinearGradientDirections ) ;
49
+ const linearGradientColors = theme ( 'linearGradients.colors' , defaultLinearGradientColors ) ;
50
+ const linearGradientVariants = variants ( 'linearGradients' , defaultLinearGradientVariants ) ;
51
+ const radialGradientShapes = theme ( 'radialGradients.shapes' , defaultRadialGradientShapes ) ;
52
+ const radialGradientSizes = theme ( 'radialGradients.sizes' , defaultRadialGradientSizes ) ;
53
+ const radialGradientPositions = theme ( 'radialGradients.positions' , defaultRadialGradientPositions ) ;
54
+ const radialGradientColors = theme ( 'radialGradients.colors' , defaultRadialGradientColors ) ;
55
+ const radialGradientVariants = variants ( 'radialGradients' , defaultRadialGradientVariants ) ;
22
56
23
- const gradientUtilities = ( function ( ) {
57
+ const linearGradientUtilities = ( function ( ) {
24
58
let utilities = { } ;
25
- _ . forEach ( gradientColors , ( colors , colorKey ) => {
26
- if ( ! _ . isArray ( colors ) || colors . length === 1 ) {
27
- let color = _ . isArray ( colors ) ? colors [ 0 ] : colors ;
28
- let parsedColor = Color ( color ) ;
29
- colors = [ parsedColor . alpha ( 0 ) . rgb ( ) . string ( ) , color ] ;
30
- }
31
- _ . forEach ( gradientDirections , ( direction , directionKey ) => {
59
+ _ . forEach ( linearGradientColors , ( colors , colorKey ) => {
60
+ _ . forEach ( linearGradientDirections , ( direction , directionKey ) => {
32
61
utilities [ `.${ e ( `bg-gradient-${ directionKey } -${ colorKey } ` ) } ` ] = {
33
- backgroundImage : `linear-gradient(${ direction } , ${ colors . join ( ', ' ) } )` ,
62
+ backgroundImage : `linear-gradient(${ direction } , ${ listColors ( colors , true ) } )` ,
34
63
} ;
35
64
} ) ;
36
65
} ) ;
37
66
return utilities ;
38
67
} ) ( ) ;
39
68
40
- addUtilities ( gradientUtilities , gradientVariants ) ;
69
+ const radialGradientUtilities = ( function ( ) {
70
+ let utilities = { } ;
71
+ _ . forEach ( radialGradientColors , ( colors , colorKey ) => {
72
+ _ . forEach ( radialGradientPositions , ( position , positionKey ) => {
73
+ _ . forEach ( radialGradientSizes , ( size , sizeKey ) => {
74
+ _ . forEach ( radialGradientShapes , ( shape , shapeKey ) => {
75
+ utilities [ `.${ e ( `bg-radial${ shapeKey === 'default' ? '' : `-${ shapeKey } ` } ${ sizeKey === 'default' ? '' : `-${ sizeKey } ` } ${ positionKey === 'default' ? '' : `-${ positionKey } ` } -${ colorKey } ` ) } ` ] = {
76
+ backgroundImage : `radial-gradient(${ shape } ${ size } at ${ position } , ${ listColors ( colors , false ) } )` ,
77
+ } ;
78
+ } ) ;
79
+ } ) ;
80
+ } ) ;
81
+ } ) ;
82
+ return utilities ;
83
+ } ) ( ) ;
84
+
85
+ addUtilities ( linearGradientUtilities , linearGradientVariants ) ;
86
+ addUtilities ( radialGradientUtilities , radialGradientVariants ) ;
41
87
} ;
42
88
} ;
0 commit comments