Skip to content

Commit dd5ac8c

Browse files
committed
feat(pushbutton): add "label" attribute
1 parent af4e168 commit dd5ac8c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/pushbutton-element.stories.ts

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

28+
export const redWithLabel = () =>
29+
html`
30+
<wokwi-pushbutton
31+
color="red"
32+
label="Press me!"
33+
@button-press=${action('button-press')}
34+
@button-release=${action('button-release')}
35+
></wokwi-pushbutton>
36+
`;
37+
38+
export const redWithLongLabel = () =>
39+
html`
40+
<wokwi-pushbutton
41+
color="red"
42+
label="I have a realy long label..."
43+
@button-press=${action('button-press')}
44+
@button-release=${action('button-release')}
45+
></wokwi-pushbutton>
46+
`;
47+
2848
export const fourButtons = () =>
2949
html`
3050
<wokwi-pushbutton

src/pushbutton-element.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SPACE_KEYS } from './utils/keys';
66
export class PushbuttonElement extends LitElement {
77
@property() color = 'red';
88
@property() pressed = false;
9+
@property() label = '';
910

1011
readonly pinInfo: ElementPin[] = [
1112
{ name: '1.l', x: 2, y: 9, signals: [] },
@@ -16,6 +17,11 @@ export class PushbuttonElement extends LitElement {
1617

1718
static get styles() {
1819
return css`
20+
:host {
21+
display: inline-flex;
22+
flex-direction: column;
23+
}
24+
1925
button {
2026
border: none;
2127
background: none;
@@ -33,16 +39,27 @@ export class PushbuttonElement extends LitElement {
3339
.clickable-element {
3440
cursor: pointer;
3541
}
42+
43+
.label {
44+
width: 0;
45+
min-width: 100%;
46+
font-size: 12px;
47+
text-align: center;
48+
color: gray;
49+
position: relative;
50+
line-height: 1;
51+
top: -2px;
52+
}
3653
`;
3754
}
3855

3956
render() {
40-
const { color } = this;
57+
const { color, label } = this;
4158
const buttonFill = this.pressed ? 'url(#grad-down)' : 'url(#grad-up)';
4259

4360
return html`
4461
<button
45-
aria-label="${color} pushbutton"
62+
aria-label="${label} ${color} pushbutton"
4663
@mousedown=${this.down}
4764
@mouseup=${(e: MouseEvent) => !e.ctrlKey && this.up()}
4865
@touchstart=${this.down}
@@ -107,6 +124,7 @@ export class PushbuttonElement extends LitElement {
107124
</g>
108125
</svg>
109126
</button>
127+
<span class="label">${this.label}</span>
110128
`;
111129
}
112130

0 commit comments

Comments
 (0)