@@ -3,6 +3,8 @@ import { ComponentModule } from "../../src/modules/component.js";
33class 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 }
0 commit comments