1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
const std = @import("std");
const z = @import("z");
const Self = @This();
pub const component: z.Component = .{
.name = "navbutton",
.html = .parse(@embedFile("index.html")),
.css = @embedFile("index.css"),
.link = @This(),
};
element: *z.Object,
shadow_root: *z.Object,
button: struct {
classList: *z.Object,
},
pub fn init(self: *Self, element: *z.Object) !void {
var env: z.Env = .default;
defer env.deinit();
self.element = element;
self.shadow_root = try self.element.get(&env, "shadowRoot").await(&env, .object);
const button = try self.shadow_root.call(&env, "getElementById", .{"button"}).await(&env, .object);
defer _ = button.free(&env);
self.button.classList = try button.get(&env, "classList").await(&env, .object);
}
pub fn open(self: *Self) !void {
var env: z.Env = .default;
defer env.deinit();
_ = self.button.classList.call(&env, "toggle", .{"open"});
}
|