11const plugin = require ( 'tailwindcss/plugin' )
22
3- module . exports = plugin (
4- function ( { addUtilities } ) {
5- addUtilities ( [
6- {
7- '.loading' : {
8- position : 'relative' ,
9- overflow : 'hidden' ,
10- backgroundColor : '#c7c7c7' ,
11- } ,
12- '.loading::after' : {
13- display : 'block' ,
14- position : 'absolute' ,
15- height : '100%' ,
16- top : 0 ,
3+ module . exports = plugin ( function ( { theme, addUtilities } ) {
4+ let styleDefault = {
5+ 'DEFAULT' : {
6+ baseColor : '#c7c7c7' ,
7+ movingColor : 'linear-gradient(to right, transparent 0%, #E8E8E8 50%, transparent 100%)' ,
8+ duration : '1s' ,
9+ timing : 'cubic-bezier(0.4, 0.0, 0.2, 1)' ,
10+ } ,
11+ }
12+ const styles = { ...styleDefault , ...theme ( 'skeletonScreen' , { } ) }
13+ const utilities = Object . entries ( styles ) . map ( ( [ key , value ] ) => {
14+ let className = '.loading' + ( key === 'DEFAULT' ? '' : '-' + key )
15+
16+ return {
17+ [ className ] : {
18+ position : 'relative' ,
19+ overflow : 'hidden' ,
20+ backgroundColor : value . baseColor ,
21+ } ,
22+ [ `${ className } ::after` ] : {
23+ display : 'block' ,
24+ position : 'absolute' ,
25+ height : '100%' ,
26+ top : 0 ,
27+ left : '-10rem' ,
28+ width : '10rem' ,
29+ content : "''" ,
30+ background : value . movingColor ,
31+ animation : `skeletonloading ${ value . duration } ${ value . timing } infinite` ,
32+ } ,
33+ '@keyframes skeletonloading' : {
34+ from : {
1735 left : '-10rem' ,
18- width : '10rem' ,
19- content : "''" ,
20- background : 'linear-gradient(to right, transparent 0%, #E8E8E8 50%, transparent 100%)' ,
21- animation : 'skeletonloading 1s cubic-bezier(0.4, 0.0, 0.2, 1) infinite' ,
2236 } ,
23- '@keyframes skeletonloading' : {
24- from : {
25- left : '-10rem' ,
26- } ,
27- to : {
28- left : '100%' ,
29- } ,
37+ to : {
38+ left : '100%' ,
3039 } ,
3140 } ,
32- ] )
33- }
34- )
41+ }
42+ } )
43+
44+ addUtilities ( utilities )
45+ } )
0 commit comments