@@ -9,13 +9,21 @@ export class PushbuttonElement extends LitElement {
9
9
@property ( ) pressed = false ;
10
10
@property ( ) label = '' ;
11
11
12
+ private static pushbuttonCounter = 0 ;
13
+ private uniqueId ;
14
+
12
15
readonly pinInfo : ElementPin [ ] = [
13
16
{ name : '1.l' , x : 0 , y : 13 , signals : [ ] } ,
14
17
{ name : '2.l' , x : 0 , y : 32 , signals : [ ] } ,
15
18
{ name : '1.r' , x : 67 , y : 13 , signals : [ ] } ,
16
19
{ name : '2.r' , x : 67 , y : 32 , signals : [ ] } ,
17
20
] ;
18
21
22
+ constructor ( ) {
23
+ super ( ) ;
24
+ this . uniqueId = 'pushbutton' + PushbuttonElement . pushbuttonCounter ++ ;
25
+ }
26
+
19
27
static get styles ( ) {
20
28
return css `
21
29
:host {
@@ -33,6 +41,14 @@ export class PushbuttonElement extends LitElement {
33
41
-moz-appearance: none;
34
42
}
35
43
44
+ .button-active-circle {
45
+ opacity: 0;
46
+ }
47
+
48
+ button:active .button-active-circle {
49
+ opacity: 1;
50
+ }
51
+
36
52
.clickable-element {
37
53
cursor: pointer;
38
54
}
@@ -51,8 +67,8 @@ export class PushbuttonElement extends LitElement {
51
67
}
52
68
53
69
render ( ) {
54
- const { color, label } = this ;
55
- const buttonFill = this . pressed ? `url(#grad-down-${ color } )` : `url(#grad-up-${ color } )` ;
70
+ const { color, label, uniqueId } = this ;
71
+ const buttonFill = this . pressed ? `url(#grad-down-${ uniqueId } )` : `url(#grad-up-${ uniqueId } )` ;
56
72
57
73
return html `
58
74
< button
@@ -72,19 +88,14 @@ export class PushbuttonElement extends LitElement {
72
88
xmlns ="http://www.w3.org/2000/svg "
73
89
xmlns:xlink ="http://www.w3.org/1999/xlink "
74
90
>
75
- < style >
76
- button : active .button-circle {
77
- fill : url (# grad- down- ${ color } );
78
- }
79
- </ style >
80
91
< defs >
81
- < linearGradient id ="grad-up- ${ color } " x1 ="0 " x2 ="1 " y1 ="0 " y2 ="1 ">
92
+ < linearGradient id ="grad-up- ${ uniqueId } " x1 ="0 " x2 ="1 " y1 ="0 " y2 ="1 ">
82
93
< stop stop-color ="#ffffff " offset ="0 " />
83
94
< stop stop-color ="${ color } " offset ="0.3 " />
84
95
< stop stop-color ="${ color } " offset ="0.5 " />
85
96
< stop offset ="1 " />
86
97
</ linearGradient >
87
- < linearGradient id ="grad-down- ${ color } " x1 ="1 " x2 ="0 " y1 ="1 " y2 ="0 ">
98
+ < linearGradient id ="grad-down- ${ uniqueId } " x1 ="1 " x2 ="0 " y1 ="1 " y2 ="0 ">
88
99
< stop stop-color ="#ffffff " offset ="0 " />
89
100
< stop stop-color ="${ color } " offset ="0.3 " />
90
101
< stop stop-color ="${ color } " offset ="0.5 " />
@@ -114,7 +125,14 @@ export class PushbuttonElement extends LitElement {
114
125
/>
115
126
</ g >
116
127
< g class ="clickable-element ">
117
- < circle class ="button-circle " cx ="6 " cy ="6 " r ="3.822 " fill ="${ buttonFill } " />
128
+ < circle cx ="6 " cy ="6 " r ="3.822 " fill ="${ buttonFill } " />
129
+ < circle
130
+ class ="button-active-circle "
131
+ cx ="6 "
132
+ cy ="6 "
133
+ r ="3.822 "
134
+ fill ="url(#grad-down-${ uniqueId } ) "
135
+ />
118
136
< circle
119
137
cx ="6 "
120
138
cy ="6 "
0 commit comments