aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/gallery
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-26 09:23:55 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-26 09:23:55 +0100
commit91d9b6992ac0ebee13704a3faefa8fd41a00075e (patch)
treeea0a30cc0cfb2232d3e60c845c20a67b6cdf0b99 /src/app/components/gallery
parent65300a13dcd11037218bf8ba61efd8ca19e5920e (diff)
zilch: dynamic element creation
Diffstat (limited to 'src/app/components/gallery')
-rw-r--r--src/app/components/gallery/index.css3
-rw-r--r--src/app/components/gallery/index.html1
-rw-r--r--src/app/components/gallery/root.zig38
3 files changed, 42 insertions, 0 deletions
diff --git a/src/app/components/gallery/index.css b/src/app/components/gallery/index.css
new file mode 100644
index 0000000..c6a5817
--- /dev/null
+++ b/src/app/components/gallery/index.css
@@ -0,0 +1,3 @@
+:host {
+ background: gray;
+}
diff --git a/src/app/components/gallery/index.html b/src/app/components/gallery/index.html
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/app/components/gallery/index.html
@@ -0,0 +1 @@
+
diff --git a/src/app/components/gallery/root.zig b/src/app/components/gallery/root.zig
new file mode 100644
index 0000000..7a06d5f
--- /dev/null
+++ b/src/app/components/gallery/root.zig
@@ -0,0 +1,38 @@
+const std = @import("std");
+const zilch = @import("zilch");
+const Object = zilch.Object;
+const components = @import("../root.zig");
+const Image = components.Image;
+
+const app = @import("root").app;
+
+pub const component: zilch.Component = .build(.{
+ .name = "gallery",
+ .html = .parse(@embedFile("index.html")),
+ .css = @embedFile("index.css"),
+ .link = @This(),
+});
+
+const Self = @This();
+
+element: *Object,
+image: *Image,
+body: *Object,
+
+pub fn init(self: *Self, element: *Object) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.element = element;
+
+ self.image = try std.heap.wasm_allocator.create(Image);
+ var el = Image.component.new(self.image, &env);
+ try self.image.init(try el.await(&env));
+
+ var body = self.element.get(&env, "shadowRoot");
+
+ var append_call = Object.call(body, &env, "append", .{self.image.element});
+ append_call.ignore(&env);
+
+ self.body = try body.await(&env, *Object);
+}