11const _ = require ( 'lodash' ) ;
22const Color = require ( 'color' ) ;
33
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+
414module . exports = function ( ) {
515 return ( { theme, variants, e, addUtilities } ) => {
6- const defaultGradientDirections = {
16+ const defaultLinearGradientDirections = {
717 't' : 'to top' ,
818 'tr' : 'to top right' ,
919 'r' : 'to right' ,
@@ -13,30 +23,66 @@ module.exports = function() {
1323 'l' : 'to left' ,
1424 'tl' : 'to top left' ,
1525 } ;
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' ] ;
1847
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 ) ;
2256
23- const gradientUtilities = ( function ( ) {
57+ const linearGradientUtilities = ( function ( ) {
2458 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 ) => {
3261 utilities [ `.${ e ( `bg-gradient-${ directionKey } -${ colorKey } ` ) } ` ] = {
33- backgroundImage : `linear-gradient(${ direction } , ${ colors . join ( ', ' ) } )` ,
62+ backgroundImage : `linear-gradient(${ direction } , ${ listColors ( colors , true ) } )` ,
3463 } ;
3564 } ) ;
3665 } ) ;
3766 return utilities ;
3867 } ) ( ) ;
3968
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 ) ;
4187 } ;
4288} ;
0 commit comments