@@ -17,43 +17,68 @@ module.exports = plugin.withOptions(
1717 widthStart = "8px" ,
1818 widthEnd = "12px" ,
1919 } = { } ) => {
20- return function ( { addUtilities, e } ) {
20+ return function ( { addUtilities, e, theme } ) {
2121 const ANIMATION_NAME = "wobble" ;
2222 const OUTLINE_STYLE = "solid" ;
2323
24- const widthStartPx = `${ parsePx ( widthStart , 8 ) / 2 } px` ;
25- const widthEndPx = `${ parsePx ( widthEnd , 12 ) / 2 } px` ;
26-
27- const boxShadowStart = `inset ${ widthStartPx } ${ widthStartPx } ${ highlightColorStart } , inset -${ widthStartPx } -${ widthStartPx } ${ highlightColorStart } ` ;
28- const boxShadowEnd = `inset ${ widthEndPx } ${ widthEndPx } ${ highlightColorEnd } , inset -${ widthEndPx } -${ widthEndPx } ${ highlightColorEnd } ` ;
29-
30- const animation = enableAnimation
31- ? `${ e (
32- "?"
33- ) } ${ ANIMATION_NAME } ${ animationDuration } ease-in-out alternate infinite`
34- : "none" ;
35-
36- addUtilities ( {
37- [ `.${ e ( "?" ) } ` ] : {
38- "outline-style" : OUTLINE_STYLE ,
39- "outline-width" : widthStartPx ,
40- "outline-color" : highlightColorStart ,
41- "box-shadow" : boxShadowStart ,
42- animation : animation ,
43- } ,
44- [ `@keyframes ${ e ( "?" ) } ${ ANIMATION_NAME } ` ] : {
45- "0%" : {
24+ const createUtilitiesForColor = ( colorStart , colorEnd , colorName ) => {
25+ const className = colorName ? `?-${ colorName } ` : "?" ;
26+ const widthStartPx = `${ parsePx ( widthStart , 8 ) / 2 } px` ;
27+ const widthEndPx = `${ parsePx ( widthEnd , 12 ) / 2 } px` ;
28+
29+ const boxShadowStart = `inset ${ widthStartPx } ${ widthStartPx } ${ colorStart } , inset -${ widthStartPx } -${ widthStartPx } ${ colorStart } ` ;
30+ const boxShadowEnd = `inset ${ widthEndPx } ${ widthEndPx } ${ colorEnd } , inset -${ widthEndPx } -${ widthEndPx } ${ colorEnd } ` ;
31+
32+ const animation = enableAnimation
33+ ? `${ e ( className ) } ${ ANIMATION_NAME } ${ animationDuration } ease-in-out alternate infinite`
34+ : "none" ;
35+
36+ return {
37+ [ `.${ e ( className ) } ` ] : {
38+ "outline-style" : OUTLINE_STYLE ,
4639 "outline-width" : widthStartPx ,
47- "outline-color" : highlightColorStart ,
40+ "outline-color" : colorStart ,
4841 "box-shadow" : boxShadowStart ,
42+ animation : animation ,
4943 } ,
50- "100%" : {
51- "outline-width" : widthEndPx ,
52- "outline-color" : highlightColorEnd ,
53- "box-shadow" : boxShadowEnd ,
44+ [ `@keyframes ${ e ( className ) } ${ ANIMATION_NAME } ` ] : {
45+ "0%" : {
46+ "outline-width" : widthStartPx ,
47+ "outline-color" : colorStart ,
48+ "box-shadow" : boxShadowStart ,
49+ } ,
50+ "100%" : {
51+ "outline-width" : widthEndPx ,
52+ "outline-color" : colorEnd ,
53+ "box-shadow" : boxShadowEnd ,
54+ } ,
5455 } ,
56+ } ;
57+ } ;
58+
59+ const defaultUtilities = createUtilitiesForColor (
60+ highlightColorStart ,
61+ highlightColorEnd ,
62+ ) ;
63+
64+ const customColors = theme ( "colors" ) ;
65+ const customUtilities = Object . keys ( customColors ) . reduce (
66+ ( acc , colorName ) => {
67+ const colorValueStart =
68+ customColors [ colorName ] [ 400 ] || customColors [ colorName ] ;
69+ const colorValueEnd =
70+ customColors [ colorName ] [ 600 ] || customColors [ colorName ] ;
71+ const utilities = createUtilitiesForColor (
72+ colorValueStart ,
73+ colorValueEnd ,
74+ colorName ,
75+ ) ;
76+ return { ...acc , ...utilities } ;
5577 } ,
56- } ) ;
78+ { } ,
79+ ) ;
80+
81+ addUtilities ( { ...defaultUtilities , ...customUtilities } ) ;
5782 } ;
58- }
83+ } ,
5984) ;
0 commit comments