Skip to content

Commit 815c416

Browse files
committed
feat: enhance activity state component with new progress icon and animations
1 parent cbe311a commit 815c416

File tree

7 files changed

+60
-9
lines changed

7 files changed

+60
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
h2 {
22
color: darkgreen;
33
}
4+
5+
activity-state {
6+
margin: 1rem;
7+
}

app/material-icons/icons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ export const icons = [
923923
"present_to_all",
924924
"preview",
925925
"print",
926+
"progress_activity",
926927
"print_disabled",
927928
"priority_high",
928929
"privacy_tip",

components/activity-state/activity-state.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,26 @@
33
box-sizing: border-box;
44
width: 1.5rem;
55
height: 1.5rem;
6-
}
6+
}
7+
8+
.rotate {
9+
animation: rotate 2s linear infinite;
10+
}
11+
12+
@keyframes rotate {
13+
from {
14+
transform: rotate(0deg);
15+
}
16+
to {
17+
transform: rotate(360deg);
18+
}
19+
}
20+
21+
.success {
22+
fill: green;
23+
}
24+
25+
.error {
26+
fill: red;
27+
}
28+

components/activity-state/activity-state.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { ComponentModule } from "../../src/modules/component.js";
33
class ActivityState extends HTMLElement {
44
static name = Object.freeze("activity-state");
55

6+
#state;
7+
68
constructor() {
79
super();
810
this.attachShadow({ mode: "open" });
@@ -14,22 +16,41 @@ class ActivityState extends HTMLElement {
1416
url: import.meta.url,
1517
});
1618

17-
this.style.display = "block";
19+
requestAnimationFrame(() => {
20+
if (this.#state) {
21+
this.setState(this.#state);
22+
}
23+
this.style.display = "block";
24+
});
1825
}
1926

2027
setState(state) {
2128
const materialIcon = this.shadowRoot.querySelector("material-icon");
2229

30+
if (materialIcon == null) {
31+
this.#state = state;
32+
return;
33+
}
34+
2335
const iconName = {
24-
"busy": "hourglass_full",
25-
"success": "check_circle",
26-
"error": "error",
36+
"busy" : "progress_activity",
37+
"success" : "check",
38+
"error" : "error_outline",
2739
}[state];
2840

2941
ComponentModule.on_ready({
3042
element: materialIcon,
3143
callback: () => {
3244
materialIcon.setIcon(iconName);
45+
materialIcon.classList.remove("success", "error", "rotate");
46+
47+
if (state === "busy") {
48+
materialIcon.classList.add("rotate");
49+
} else if (state === "success") {
50+
materialIcon.classList.add("success");
51+
} else if (state === "error") {
52+
materialIcon.classList.add("error");
53+
}
3354
}
3455
})
3556
}
Lines changed: 1 addition & 0 deletions
Loading

components/material-icon/material-icon.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class MaterialIcon extends HTMLElement {
2121
this.style.alignItems = "center";
2222
this.style.justifyContent = "center";
2323
this.style.pointerEvents = "none";
24+
this.style.width = "24px";
25+
this.style.height = "24px";
2426

2527
ComponentModule.ready({element: this});
2628
}

src/validate/validate-args.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export function validateArgs(args, def, prefix = "") {
2929
const arg = def[key];
3030
const value = args[key];
3131

32-
if (arg.required && value === undefined) {
32+
if (arg.required && value == null) {
3333
throw new Error(`${prefix}Argument "${key}" is required`.trim());
3434
}
3535

36-
if (value !== undefined) {
36+
if (value != null) {
3737
const expectedType = arg.type.toLowerCase();
3838
const actualType = typeof value === "object"
39-
? value.constructor.name.toLowerCase()
39+
? value.constructor?.name.toLowerCase()
4040
: typeof value;
4141

4242
const globalType = globalThis[arg.type ?? ""];
@@ -45,7 +45,7 @@ export function validateArgs(args, def, prefix = "") {
4545
`${prefix}Argument "${key}" should be of type "${arg.type}"`.trim(),
4646
);
4747
}
48-
} else if (arg.default !== undefined) {
48+
} else if (arg.default != null) {
4949
args[key] = arg.default;
5050
}
5151
}

0 commit comments

Comments
 (0)