@@ -38,9 +38,11 @@ export default class PgMenuIcon extends HTMLElement {
3838 @Part ( ) $colorPicker : any ;
3939 @Part ( ) $colorHexRgb : any ;
4040
41- @Local ( ) cachePngColor : string = '#000000' ;
42- @Local ( ) cachePngSize : string = '24' ;
43- @Local ( ) cacheSvgColor : string = '#000000' ;
41+ @Local ( 'store' ) store = new Map < string , any > ( [
42+ [ 'cachePngColor' , '#000000' ] ,
43+ [ 'cachePngSize' , 24 ] ,
44+ [ 'cacheSvgColor' , '#000000' ]
45+ ] ) ;
4446
4547 color = 'svg' ;
4648 @Prop ( ) currentIndex : number = 0 ;
@@ -50,19 +52,19 @@ export default class PgMenuIcon extends HTMLElement {
5052 // Wire Up Context Menu
5153 this . $copyIconName . addEventListener ( 'click' , this . handleCopyIconName . bind ( this ) ) ;
5254 this . $svgBlack . addEventListener ( 'click' , ( ) => {
53- this . cacheSvgColor = '#000000' ;
55+ this . store . set ( ' cacheSvgColor' , '#000000' ) ;
5456 this . render ( ) ;
5557 } ) ;
5658 this . $svgWhite . addEventListener ( 'click' , ( ) => {
57- this . cacheSvgColor = '#FFFFFF' ;
59+ this . store . set ( ' cacheSvgColor' , '#FFFFFF' ) ;
5860 this . render ( ) ;
5961 } ) ;
6062 let preventSvgColor = false ;
6163 this . $svgColor . addEventListener ( 'click' , ( ) => {
6264 if ( preventSvgColor ) { preventSvgColor = false ; return ; }
6365 this . color = 'svg' ;
64- this . $colorPicker . value = this . cacheSvgColor ;
65- this . $colorHexRgb . value = this . cacheSvgColor ;
66+ this . $colorPicker . value = this . store . get ( ' cacheSvgColor' ) ;
67+ this . $colorHexRgb . value = this . store . get ( ' cacheSvgColor' ) ;
6668 const self = this ;
6769 //createPopper(this.$svgColor, this.$color, {
6870 // placement: 'bottom-start'
@@ -83,19 +85,19 @@ export default class PgMenuIcon extends HTMLElement {
8385 document . addEventListener ( 'mousedown' , handleMouseDown ) ;
8486 } ) ;
8587 this . $pngBlack . addEventListener ( 'click' , ( ) => {
86- this . cachePngColor = '#000000' ;
88+ this . store . set ( ' cachePngColor' , '#000000' ) ;
8789 this . render ( ) ;
8890 } ) ;
8991 this . $pngWhite . addEventListener ( 'click' , ( ) => {
90- this . cachePngColor = '#FFFFFF' ;
92+ this . store . set ( ' cachePngColor' , '#FFFFFF' ) ;
9193 this . render ( ) ;
9294 } ) ;
9395 let preventPngColor = false ;
9496 this . $pngColor . addEventListener ( 'click' , ( ) => {
9597 if ( preventPngColor ) { preventPngColor = false ; return ; }
9698 this . color = 'png' ;
97- this . $colorPicker . value = this . cachePngColor ;
98- this . $colorHexRgb . value = this . cachePngColor ;
99+ this . $colorPicker . value = this . store . get ( ' cachePngColor' ) ;
100+ this . $colorHexRgb . value = this . store . get ( ' cachePngColor' ) ;
99101 const self = this ;
100102 //createPopper(this.$pngColor, this.$color, {
101103 // placement: 'bottom-start'
@@ -116,26 +118,26 @@ export default class PgMenuIcon extends HTMLElement {
116118 document . addEventListener ( 'mousedown' , handleMouseDown ) ;
117119 } ) ;
118120 this . $png24 . addEventListener ( 'click' , ( ) => {
119- this . cachePngSize = '24' ;
121+ this . store . set ( ' cachePngSize' , 24 ) ;
120122 this . render ( ) ;
121123 } ) ;
122124 this . $png36 . addEventListener ( 'click' , ( ) => {
123- this . cachePngSize = '36' ;
125+ this . store . set ( ' cachePngSize' , 36 ) ;
124126 this . render ( ) ;
125127 } ) ;
126128 this . $png48 . addEventListener ( 'click' , ( ) => {
127- this . cachePngSize = '48' ;
129+ this . store . set ( ' cachePngSize' , 48 ) ;
128130 this . render ( ) ;
129131 } ) ;
130132 this . $png96 . addEventListener ( 'click' , ( ) => {
131- this . cachePngSize = '96' ;
133+ this . store . set ( ' cachePngSize' , 96 ) ;
132134 this . render ( ) ;
133135 } ) ;
134136 this . $svgDownload . addEventListener ( 'click' , ( ) => {
135- alert ( `SVG ${ this . cacheSvgColor } ` ) ;
137+ alert ( `SVG ${ this . store . get ( ' cacheSvgColor' ) } ` ) ;
136138 } ) ;
137139 this . $pngDownload . addEventListener ( 'click' , ( ) => {
138- alert ( `SVG ${ this . cachePngSize } ${ this . cachePngColor } ` ) ;
140+ alert ( `SVG ${ this . store . get ( ' cachePngSize' ) } ${ this . store . get ( ' cachePngColor' ) } ` ) ;
139141 } ) ;
140142 this . $copySvgInline . addEventListener ( 'click' , ( ) => {
141143 const icon = this . icon ;
@@ -214,16 +216,19 @@ export default class PgMenuIcon extends HTMLElement {
214216
215217 render ( ) {
216218 // Context Menu
217- this . $svgBlack . classList . toggle ( 'active' , this . cacheSvgColor === '#000000' ) ;
218- this . $svgWhite . classList . toggle ( 'active' , this . cacheSvgColor === '#FFFFFF' ) ;
219- this . $svgColor . classList . toggle ( 'active' , this . cacheSvgColor !== '#000000' && this . cacheSvgColor !== '#FFFFFF' ) ;
220- this . $pngBlack . classList . toggle ( 'active' , this . cachePngColor === '#000000' ) ;
221- this . $pngWhite . classList . toggle ( 'active' , this . cachePngColor === '#FFFFFF' ) ;
222- this . $pngColor . classList . toggle ( 'active' , this . cachePngColor !== '#000000' && this . cachePngColor !== '#FFFFFF' ) ;
223- this . $png24 . classList . toggle ( 'active' , this . cachePngSize === '24' ) ;
224- this . $png36 . classList . toggle ( 'active' , this . cachePngSize === '36' ) ;
225- this . $png48 . classList . toggle ( 'active' , this . cachePngSize === '48' ) ;
226- this . $png96 . classList . toggle ( 'active' , this . cachePngSize === '96' ) ;
219+ const cacheSvgColor = this . store . get ( 'cacheSvgColor' ) ;
220+ const cachePngColor = this . store . get ( 'cachePngColor' ) ;
221+ const cachePngSize = this . store . get ( 'cachePngSize' ) ;
222+ this . $svgBlack . classList . toggle ( 'active' , cacheSvgColor === '#000000' ) ;
223+ this . $svgWhite . classList . toggle ( 'active' , cacheSvgColor === '#FFFFFF' ) ;
224+ this . $svgColor . classList . toggle ( 'active' , cacheSvgColor !== '#000000' && cacheSvgColor !== '#FFFFFF' ) ;
225+ this . $pngBlack . classList . toggle ( 'active' , cachePngColor === '#000000' ) ;
226+ this . $pngWhite . classList . toggle ( 'active' , cachePngColor === '#FFFFFF' ) ;
227+ this . $pngColor . classList . toggle ( 'active' , cachePngColor !== '#000000' && cachePngColor !== '#FFFFFF' ) ;
228+ this . $png24 . classList . toggle ( 'active' , cachePngSize === 24 ) ;
229+ this . $png36 . classList . toggle ( 'active' , cachePngSize === 36 ) ;
230+ this . $png48 . classList . toggle ( 'active' , cachePngSize === 48 ) ;
231+ this . $png96 . classList . toggle ( 'active' , cachePngSize === 96 ) ;
227232 this . $colorPicker . addEventListener ( 'select' , this . handleColorSelect . bind ( this ) ) ;
228233 this . $colorHexRgb . addEventListener ( 'change' , this . handleHexRgbChange . bind ( this ) ) ;
229234 this . syncEyedropper ( ) ;
@@ -232,10 +237,10 @@ export default class PgMenuIcon extends HTMLElement {
232237 handleColorSelect ( e ) {
233238 switch ( this . color ) {
234239 case 'svg' :
235- this . cacheSvgColor = e . detail . hex ;
240+ this . store . set ( ' cacheSvgColor' , e . detail . hex ) ;
236241 break ;
237242 case 'png' :
238- this . cachePngColor = e . detail . hex ;
243+ this . store . set ( ' cachePngColor' , e . detail . hex ) ;
239244 break ;
240245 }
241246 this . $colorHexRgb . value = e . detail . hex ;
@@ -245,24 +250,26 @@ export default class PgMenuIcon extends HTMLElement {
245250 handleHexRgbChange ( e ) {
246251 switch ( this . color ) {
247252 case 'svg' :
248- this . cacheSvgColor = e . detail . hex ;
253+ this . store . set ( ' cacheSvgColor' , e . detail . hex ) ;
249254 break ;
250255 case 'png' :
251- this . cachePngColor = e . detail . hex ;
256+ this . store . set ( ' cachePngColor' , e . detail . hex ) ;
252257 break ;
253258 }
254259 this . $colorPicker . value = e . detail . hex ;
255260 this . syncEyedropper ( ) ;
256261 }
257262
258263 syncEyedropper ( ) {
259- if ( this . cachePngColor !== '#000000' && this . cachePngColor !== '#FFFFFF' ) {
260- this . $pngColor . style . color = this . cachePngColor ;
264+ const cachePngColor = this . store . get ( 'cachePngColor' ) ;
265+ if ( cachePngColor !== '#000000' && cachePngColor !== '#FFFFFF' ) {
266+ this . $pngColor . style . color = cachePngColor ;
261267 } else {
262268 this . $pngColor . style . color = 'transparent' ;
263269 }
264- if ( this . cacheSvgColor !== '#000000' && this . cacheSvgColor !== '#FFFFFF' ) {
265- this . $svgColor . style . color = this . cacheSvgColor ;
270+ const cacheSvgColor = this . store . get ( 'cacheSvgColor' ) ;
271+ if ( cacheSvgColor !== '#000000' && cacheSvgColor !== '#FFFFFF' ) {
272+ this . $svgColor . style . color = cacheSvgColor ;
266273 } else {
267274 this . $svgColor . style . color = 'transparent' ;
268275 }
0 commit comments