Skip to content

Commit a914918

Browse files
committed
feat: enhance activity state component with dynamic state handling and toolbar integration
1 parent c8c0c05 commit a914918

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<app-header><h2>Activity State</h2></app-header>
22

3-
<activity-state data-state="busy"></activity-state>
4-
53
<tool-bar>
64
<button data-action="busy">Set Busy</button>
75
<button data-action="success">Set Success</button>
86
<button data-action="error">Set Error</button>
7+
<activity-state data-state="busy"></activity-state>
98
</tool-bar>

app/activity-state/activity-state.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ export default class ActivityStateView extends HTMLElement {
2727
}
2828

2929
#click(event) {
30-
if (event.target.dataset.action) {
31-
this.setState("busy");
30+
const target = event.composedPath()[0];
31+
if (target.dataset.action) {
32+
this.setState(target.dataset.action);
3233
}
3334
}
3435

3536
setState(state) {
3637
requestAnimationFrame(() => {
3738
const activityState = this.shadowRoot.querySelector("activity-state");
38-
activityState.dataset.state = state;
39+
activityState.setState(state);
3940
});
4041
}
4142
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
:host {
22
display: block;
3-
padding: var(--padding);
43
box-sizing: border-box;
4+
width: 1.5rem;
5+
height: 1.5rem;
56
}

components/activity-state/activity-state.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ class ActivityState extends HTMLElement {
1616

1717
this.style.display = "block";
1818
}
19+
20+
setState(state) {
21+
const materialIcon = this.shadowRoot.querySelector("material-icon");
22+
23+
const iconName = {
24+
"busy": "hourglass_full",
25+
"success": "check_circle",
26+
"error": "error",
27+
}[state];
28+
29+
ComponentModule.on_ready({
30+
element: materialIcon,
31+
callback: () => {
32+
materialIcon.setIcon(iconName);
33+
}
34+
})
35+
}
1936
}
2037

2138
customElements.define(ActivityState.name, ActivityState);

components/material-icon/material-icon.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ComponentModule } from "../../src/modules/component.js";
2+
13
export class MaterialIcon extends HTMLElement {
24
static name = Object.freeze("material-icon");
35

@@ -19,6 +21,8 @@ export class MaterialIcon extends HTMLElement {
1921
this.style.alignItems = "center";
2022
this.style.justifyContent = "center";
2123
this.style.pointerEvents = "none";
24+
25+
ComponentModule.ready({element: this});
2226
}
2327

2428
setIcon(iconName) {

components/tool-bar/tool-bar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ToolBar extends HTMLElement {
2424
url: import.meta.url,
2525
});
2626

27-
this.style.display = "block";
27+
this.style.display = "flex";
2828
}
2929
}
3030

0 commit comments

Comments
 (0)