@@ -10,6 +10,8 @@ import {
1010 getDegreeSpanElement ,
1111 getGradientPreview ,
1212 getCssOrTailwindDropdown ,
13+ getTailwindButton ,
14+ getCssOrTailwindButton ,
1315} from '../lib/getElements' ;
1416import {
1517 copyCSSCodeToClipboard ,
@@ -21,6 +23,7 @@ import {
2123 createGradientPreview ,
2224 getColorsValue ,
2325 closeDropdown ,
26+ copyTailwindCodeToClipboard ,
2427} from '../lib/packages/utils' ;
2528
2629type Values = {
@@ -39,6 +42,40 @@ const resetButton = getResetButton(attribute);
3942const getCssOrTailwindDropdownElement = getCssOrTailwindDropdown ( attribute ) ;
4043const showCopyClass = 'show-css-tailwind' ;
4144
45+ export function gradientBackgroundGenerator (
46+ type : 'newResults' | 'oldResults' | null
47+ ) {
48+ if ( type === null ) return ;
49+
50+ const getOutputElement = getOutput ( attribute ) ;
51+ const resultPage = getResultPage ( ) ;
52+
53+ resultPage . style . display = 'flex' ;
54+ if ( type === 'oldResults' ) return ;
55+
56+ const values : Values = {
57+ degree : getDegreeElement . value ,
58+ } ;
59+ getGradientBackgroundResult ( attribute , values , getOutputElement ) ;
60+ }
61+
62+ export function addGradientBackgroundListener ( ) {
63+ whatColorButtonShouldShow ( attribute ) ;
64+ getNewColorButtonElement . addEventListener ( 'click' , ( ) => {
65+ addNewColorPicker ( attribute ) ;
66+ addEventListenerToTheNewColorPicker ( ) ;
67+ } ) ;
68+
69+ getRemoveColorButtonElement . addEventListener ( 'click' , ( ) => {
70+ removeColorPicker ( attribute ) ;
71+ addEventListenerToTheNewColorPicker ( ) ;
72+ } ) ;
73+
74+ inputEventListner ( ) ;
75+
76+ setGradientDegreeValue ( getDegreeElement ) ;
77+ }
78+
4279function copyHandler ( ) {
4380 const outputElement = getOutput ( attribute ) ;
4481 copyCSSCodeToClipboard ( attribute , outputElement ) ;
@@ -54,9 +91,6 @@ function getCssOrTailwind(e?: MouseEvent): void {
5491 getCssOrTailwindDropdownElement . classList . toggle ( showCopyClass ) ;
5592}
5693
57- // closes css and tailwind dropdown on outside click
58- closeDropdown ( getCssOrTailwind , getCssOrTailwindDropdownElement , showCopyClass ) ;
59-
6094/**
6195 * sets the result to the output element
6296 *
@@ -74,41 +108,13 @@ function getGradientBackgroundResult(
74108 } deg, ${ getColorsValue ( attribute ) . join ( ', ' ) } )`;
75109
76110 const getCodeButtonElement = getCopyCodeButton ( attribute ) ;
77- getCodeButtonElement . addEventListener ( 'click' , copyHandler ) ;
78- }
79-
80- export function gradientBackgroundGenerator (
81- type : 'newResults' | 'oldResults' | null
82- ) {
83- if ( type === null ) return ;
84-
85- const getOutputElement = getOutput ( attribute ) ;
86- const resultPage = getResultPage ( ) ;
87-
88- resultPage . style . display = 'flex' ;
89- if ( type === 'oldResults' ) return ;
90-
91- const values : Values = {
92- degree : getDegreeElement . value ,
93- } ;
94- getGradientBackgroundResult ( attribute , values , getOutputElement ) ;
95- }
96-
97- export function addGradientBackgroundListener ( ) {
98- whatColorButtonShouldShow ( attribute ) ;
99- getNewColorButtonElement . addEventListener ( 'click' , ( ) => {
100- addNewColorPicker ( attribute ) ;
101- addEventListenerToTheNewColorPicker ( ) ;
102- } ) ;
111+ const getTailwindCodeButtonElement = getTailwindButton ( attribute ) ;
112+ const getCssOrTailwindButtonElement = getCssOrTailwindButton ( attribute ) ;
103113
104- getRemoveColorButtonElement . addEventListener ( 'click' , ( ) => {
105- removeColorPicker ( attribute ) ;
106- addEventListenerToTheNewColorPicker ( ) ;
107- } ) ;
108-
109- inputEventListner ( ) ;
114+ getCodeButtonElement . addEventListener ( 'click' , copyHandler ) ;
115+ getTailwindCodeButtonElement . addEventListener ( 'click' , tailwindHandler ) ;
110116
111- setGradientDegreeValue ( getDegreeElement ) ;
117+ getCssOrTailwindButtonElement . addEventListener ( 'click' , getCssOrTailwind ) ;
112118}
113119
114120function addEventListenerToTheNewColorPicker ( ) {
@@ -153,7 +159,6 @@ function resetValues() {
153159}
154160
155161// get values from all targets to get notified when values change.
156-
157162function getValues ( ) {
158163 gradientBackgroundInputs . forEach ( ( input ) => {
159164 input . addEventListener ( 'input' , ( ) => {
@@ -164,5 +169,20 @@ function getValues() {
164169 } ) ;
165170 } ) ;
166171}
172+
173+ // Tailwind codecopy handler
174+ function tailwindHandler ( ) {
175+ const outputElement = getOutput ( attribute ) ;
176+ copyTailwindCodeToClipboard ( attribute , outputElement ) ;
177+
178+ showPopup (
179+ 'Tailwind Code Copied' ,
180+ 'Code has been successfully copied to clipboard' ,
181+ 'success'
182+ ) ;
183+ }
184+
185+ closeDropdown ( getCssOrTailwind , getCssOrTailwindDropdownElement , showCopyClass ) ;
186+
167187resetValues ( ) ;
168188getValues ( ) ;
0 commit comments