Skip to content

Commit 0c22289

Browse files
committed
feat: add flip functionality to the LED element
add ability to flip LEDs along the x axis using the "flip" attribute in the diagram.json file. add a "Flipped" story to the storybook.
1 parent c77afa9 commit 0c22289

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/led-element.stories.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ storiesOf('LED', module)
3636
></wokwi-led>
3737
`
3838
)
39+
.add(
40+
'Flipped',
41+
() =>
42+
html`
43+
<wokwi-led
44+
color="red"
45+
.value=${boolean('value', false)}
46+
.flip=${boolean('flip', true)}
47+
></wokwi-led>
48+
`
49+
)
3950
.add(
4051
'Green',
4152
() =>

src/led-element.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ export class LEDElement extends LitElement {
1818
@property() color = 'red';
1919
@property() lightColor: string | null = null;
2020
@property() label = '';
21+
@property({ type: Boolean }) flip = false;
2122

22-
readonly pinInfo: ElementPin[] = [
23-
{ name: 'A', x: 24, y: 42, signals: [], description: 'Anode' },
24-
{ name: 'C', x: 16, y: 42, signals: [], description: 'Cathode' },
25-
];
23+
get pinInfo(): ElementPin[] {
24+
const anodeX = this.flip ? 16 : 24;
25+
const cathodeX = this.flip ? 24 : 16;
26+
27+
return [
28+
{ name: 'A', x: anodeX, y: 42, signals: [], description: 'Anode' },
29+
{ name: 'C', x: cathodeX, y: 42, signals: [], description: 'Cathode' },
30+
];
31+
}
2632

2733
static get styles() {
2834
return css`
@@ -48,15 +54,18 @@ export class LEDElement extends LitElement {
4854
}
4955

5056
render() {
51-
const { color, lightColor } = this;
57+
const { color, lightColor, flip } = this;
5258
const lightColorActual = lightColor || lightColors[color] || '#ff8080';
5359
const opacity = this.brightness ? 0.3 + this.brightness * 0.7 : 0;
5460
const lightOn = this.value && this.brightness > Number.EPSILON;
61+
const xScale = flip ? -1 : 1;
62+
5563
return html`
5664
<div class="led-container">
5765
<svg
5866
width="40"
5967
height="50"
68+
transform="scale(${xScale} 1)"
6069
version="1.2"
6170
viewBox="-10 -5 35.456 39.618"
6271
xmlns="http://www.w3.org/2000/svg"

0 commit comments

Comments
 (0)