Skip to content

Commit 7fbf47b

Browse files
committed
feat(pushbutton): add x-ray attribute
1 parent 4b03323 commit 7fbf47b

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

src/pushbutton-6mm-element.stories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ export const FourButtons = () =>
6868
@button-release=${action('white button-release')}
6969
></wokwi-pushbutton-6mm>
7070
`;
71+
72+
export const RedWithXray = () =>
73+
html` <wokwi-pushbutton-6mm color="red" xray=${true}></wokwi-pushbutton-6mm> `;

src/pushbutton-6mm-element.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { css, html, LitElement } from 'lit';
1+
import { css, html, LitElement, svg } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { ElementPin } from './pin';
44
import { ctrlCmdPressed, SPACE_KEYS } from './utils/keys';
@@ -8,7 +8,7 @@ export class Pushbutton6mmElement extends LitElement {
88
@property() color = 'red';
99
@property() pressed = false;
1010
@property() label = '';
11-
11+
@property({ type: Boolean, attribute: 'xray' }) xray = false;
1212
private static pushbuttonCounter = 0;
1313
private uniqueId;
1414

@@ -67,7 +67,7 @@ export class Pushbutton6mmElement extends LitElement {
6767
}
6868

6969
render() {
70-
const { color, label, uniqueId } = this;
70+
const { color, label, uniqueId, xray } = this;
7171
const buttonFill = this.pressed ? `url(#grad-down-${uniqueId})` : `url(#grad-up-${uniqueId})`;
7272

7373
return html`
@@ -191,6 +191,27 @@ export class Pushbutton6mmElement extends LitElement {
191191
y="0.59993488"
192192
rx="0.014974313"
193193
/>
194+
${xray
195+
? svg`
196+
<rect
197+
style="opacity:0.3;fill:#b3b3b3;stroke-width:3.86235;paint-order:stroke markers fill"
198+
id="rect18-7"
199+
width="12.124171"
200+
height="0.51113945"
201+
x="-0.047361366"
202+
y="0.90351838"
203+
rx="0.12476496" />
204+
<rect
205+
style="opacity:0.3;fill:#b3b3b3;stroke-width:3.86235;paint-order:stroke markers fill"
206+
id="rect18-7-4"
207+
width="12.124171"
208+
height="0.51113945"
209+
x="-0.098103404"
210+
y="10.614529"
211+
rx="0.12476496"
212+
/>
213+
`
214+
: ''}
194215
<rect
195216
style="fill:#b3b3b3;stroke-width:1.69238;paint-order:stroke markers fill"
196217
id="rect18-5"

src/pushbutton-element.stories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export const Green = () =>
2525
></wokwi-pushbutton>
2626
`;
2727

28+
export const RedWithXray = () =>
29+
html` <wokwi-pushbutton color="red" xray=${true}></wokwi-pushbutton> `;
30+
2831
export const RedWithLabel = () =>
2932
html`
3033
<wokwi-pushbutton

src/pushbutton-element.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { css, html, LitElement } from 'lit';
1+
import { css, html, LitElement, svg } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { ElementPin } from './pin';
44
import { ctrlCmdPressed, SPACE_KEYS } from './utils/keys';
@@ -8,6 +8,7 @@ export class PushbuttonElement extends LitElement {
88
@property() color = 'red';
99
@property() pressed = false;
1010
@property() label = '';
11+
@property({ type: Boolean, attribute: 'xray' }) xray = false;
1112

1213
private static pushbuttonCounter = 0;
1314
private uniqueId;
@@ -68,7 +69,7 @@ export class PushbuttonElement extends LitElement {
6869
}
6970

7071
render() {
71-
const { color, label, uniqueId } = this;
72+
const { color, label, uniqueId, xray } = this;
7273
const buttonFill = this.pressed ? `url(#grad-down-${uniqueId})` : `url(#grad-up-${uniqueId})`;
7374

7475
return html`
@@ -106,6 +107,26 @@ export class PushbuttonElement extends LitElement {
106107
</defs>
107108
<rect x="0" y="0" width="12" height="12" rx=".44" ry=".44" fill="#464646" />
108109
<rect x=".75" y=".75" width="10.5" height="10.5" rx=".211" ry=".211" fill="#eaeaea" />
110+
${xray
111+
? svg`
112+
<rect
113+
style="opacity:0.3;fill:#999999;stroke-width:0.563001;paint-order:stroke markers fill"
114+
id="rect17"
115+
width="12.087865"
116+
height="1.0371729"
117+
x="-0.00075517414"
118+
y="2.9106798"
119+
/>
120+
<rect
121+
style="opacity:0.3;fill:#999999;stroke-width:0.534365;paint-order:stroke markers fill"
122+
id="rect17-3"
123+
width="12.087865"
124+
height="0.93434691"
125+
x="-0.071111664"
126+
y="8.0458994"
127+
/>
128+
`
129+
: ''}
109130
<g fill="#1b1b1">
110131
<circle cx="1.767" cy="1.7916" r=".37" />
111132
<circle cx="10.161" cy="1.7916" r=".37" />

0 commit comments

Comments
 (0)