Skip to content

Commit 01fc6e0

Browse files
committed
fix(pushbutton-element): The button gradient turns black when there are multiple buttons with the same color and we change the color of one of these buttons.
#153
1 parent 85f23f8 commit 01fc6e0

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/pushbutton-element.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ export class PushbuttonElement extends LitElement {
99
@property() pressed = false;
1010
@property() label = '';
1111

12+
private static pushbuttonCounter = 0;
13+
private uniqueId;
14+
1215
readonly pinInfo: ElementPin[] = [
1316
{ name: '1.l', x: 0, y: 13, signals: [] },
1417
{ name: '2.l', x: 0, y: 32, signals: [] },
1518
{ name: '1.r', x: 67, y: 13, signals: [] },
1619
{ name: '2.r', x: 67, y: 32, signals: [] },
1720
];
1821

22+
constructor() {
23+
super();
24+
this.uniqueId = 'pushbutton' + PushbuttonElement.pushbuttonCounter++;
25+
}
26+
1927
static get styles() {
2028
return css`
2129
:host {
@@ -33,6 +41,14 @@ export class PushbuttonElement extends LitElement {
3341
-moz-appearance: none;
3442
}
3543
44+
.button-active-circle {
45+
opacity: 0;
46+
}
47+
48+
button:active .button-active-circle {
49+
opacity: 1;
50+
}
51+
3652
.clickable-element {
3753
cursor: pointer;
3854
}
@@ -51,8 +67,8 @@ export class PushbuttonElement extends LitElement {
5167
}
5268

5369
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})`;
5672

5773
return html`
5874
<button
@@ -72,19 +88,14 @@ export class PushbuttonElement extends LitElement {
7288
xmlns="http://www.w3.org/2000/svg"
7389
xmlns:xlink="http://www.w3.org/1999/xlink"
7490
>
75-
<style>
76-
button:active .button-circle {
77-
fill: url(#grad-down-${color});
78-
}
79-
</style>
8091
<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">
8293
<stop stop-color="#ffffff" offset="0" />
8394
<stop stop-color="${color}" offset="0.3" />
8495
<stop stop-color="${color}" offset="0.5" />
8596
<stop offset="1" />
8697
</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">
8899
<stop stop-color="#ffffff" offset="0" />
89100
<stop stop-color="${color}" offset="0.3" />
90101
<stop stop-color="${color}" offset="0.5" />
@@ -114,7 +125,14 @@ export class PushbuttonElement extends LitElement {
114125
/>
115126
</g>
116127
<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+
/>
118136
<circle
119137
cx="6"
120138
cy="6"

0 commit comments

Comments
 (0)