diff options
Diffstat (limited to 'src/app/components/navbutton/root.zig')
| -rw-r--r-- | src/app/components/navbutton/root.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/app/components/navbutton/root.zig b/src/app/components/navbutton/root.zig new file mode 100644 index 0000000..a512d1d --- /dev/null +++ b/src/app/components/navbutton/root.zig @@ -0,0 +1,58 @@ +const std = @import("std"); +const app = @import("root").app; +const zilch = @import("zilch"); +const Object = zilch.Object; +const Promise = zilch.Promise; + +const Self = @This(); + +pub const component: zilch.Component = .build(.{ + .name = "navbutton", + .html = .parse(@embedFile("index.html")), + .css = @embedFile("index.css"), + .link = @This(), +}); + +element: *zilch.Object, +shadow_root: *zilch.Object, +button: struct { + classList: *zilch.Object, +}, + +pub fn init(self: *Self, element: *Object) !void { + var env: zilch.Env = .default; + defer env.deinit(); + + self.element = element; + + var shadow_root = self.element.get(&env, "shadowRoot"); + + var class_list = cls: { + var button = Object.call(shadow_root, &env, "getElementById", .{"button"}); + defer button.ignore(&env); + defer _ = Object.free(button, &env); + + break :cls Object.get(button, &env, "classList"); + }; + + self.button.classList = try class_list.await(&env, *Object); + + self.shadow_root = try shadow_root.await(&env, *Object); +} + +pub fn deinit(self: *Self) !void { + var env: zilch.Env = .default; + defer env.deinit(); + + _ = self.element.free(&env); + _ = self.shadow_root.free(&env); + _ = self.button.classList.free(&env); +} + +pub fn open(self: *Self) !void { + var env: zilch.Env = .default; + defer env.deinit(); + + var toggle_call = self.button.classList.call(&env, "toggle", .{"open"}); + toggle_call.ignore(&env); +} |