From d0f90548f5edb32225af4a1f79413a2a56d186c8 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 9 Oct 2026 09:40:06 +0200 Subject: app: add navbutton --- src/app/components/icons/index.css | 0 src/app/components/icons/menu.svg | 3 +++ src/app/components/icons/root.zig | 21 +++++++++++++++ src/app/components/icons/settings.svg | 4 +++ src/app/components/icons/upload.svg | 4 +++ src/app/components/navbutton/index.css | 46 +++++++++++++++++++++++++++++++-- src/app/components/navbutton/index.html | 12 ++++++++- src/app/components/navbutton/root.zig | 21 ++++++++++++++- src/app/components/root.zig | 6 +++-- 9 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 src/app/components/icons/index.css create mode 100644 src/app/components/icons/menu.svg create mode 100644 src/app/components/icons/root.zig create mode 100644 src/app/components/icons/settings.svg create mode 100644 src/app/components/icons/upload.svg (limited to 'src/app/components') diff --git a/src/app/components/icons/index.css b/src/app/components/icons/index.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/icons/menu.svg b/src/app/components/icons/menu.svg new file mode 100644 index 0000000..df05f82 --- /dev/null +++ b/src/app/components/icons/menu.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/app/components/icons/root.zig b/src/app/components/icons/root.zig new file mode 100644 index 0000000..a2b0fa6 --- /dev/null +++ b/src/app/components/icons/root.zig @@ -0,0 +1,21 @@ +const z = @import("z"); + +pub const icons: []const z.Component = &.{ + icon("menu"), + icon("upload"), + icon("settings"), +}; + +const Icon = struct { + pub fn init(_: *@This(), _: *z.Object) void {} +}; + +pub fn icon(name: []const u8) z.Component { + return .{ + .namespace = "icon", + .name = name, + .html = .parse(@embedFile(name ++ ".svg")), + .css = @embedFile("index.css"), + .link = Icon, + }; +} diff --git a/src/app/components/icons/settings.svg b/src/app/components/icons/settings.svg new file mode 100644 index 0000000..783f55f --- /dev/null +++ b/src/app/components/icons/settings.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/app/components/icons/upload.svg b/src/app/components/icons/upload.svg new file mode 100644 index 0000000..5187f80 --- /dev/null +++ b/src/app/components/icons/upload.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/app/components/navbutton/index.css b/src/app/components/navbutton/index.css index bf1b4ee..4c1a138 100644 --- a/src/app/components/navbutton/index.css +++ b/src/app/components/navbutton/index.css @@ -1,9 +1,51 @@ -#button { +:host { position: absolute; bottom: 10px; right: 10px; + --items-count: 2; +} + +#button { + position: relative; + width: 50px; + height: 50px; + background: var(--secondary); + border-radius: 50px; + cursor: pointer; + color: var(--color); + transition: 0.2s ease height; + display: grid; + justify-content: center; + align-content: end; + overflow: hidden; +} + +#button.open { + height: calc(50px * (var(--items-count) + 1)); +} + +#menu { width: 50px; height: 50px; + background: red; + border-radius: 50px; + display: grid; background: var(--primary); - border-radius: 100%; +} + +.icon { + margin: auto; + width: fit-content; + height: fit-content; + padding-top: 4px; +} + +.items { + height: calc(50px * var(--items-count)); + display: grid; + grid-template-rows: repeat(var(--items-count), auto); +} + +.item { + margin: auto; } diff --git a/src/app/components/navbutton/index.html b/src/app/components/navbutton/index.html index ab23160..f2c9ff8 100644 --- a/src/app/components/navbutton/index.html +++ b/src/app/components/navbutton/index.html @@ -1,2 +1,12 @@ -
+
+
+
+
+
+ +
diff --git a/src/app/components/navbutton/root.zig b/src/app/components/navbutton/root.zig index 0040c9d..1078924 100644 --- a/src/app/components/navbutton/root.zig +++ b/src/app/components/navbutton/root.zig @@ -1,3 +1,4 @@ +const std = @import("std"); const z = @import("z"); const Self = @This(); @@ -10,7 +11,25 @@ pub const component: z.Component = .{ }; 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(); -pub fn init(self: *Self, element: *z.Object) void { 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"}); } diff --git a/src/app/components/root.zig b/src/app/components/root.zig index 32ed436..934279f 100644 --- a/src/app/components/root.zig +++ b/src/app/components/root.zig @@ -1,5 +1,7 @@ const z = @import("z"); -pub const components: []const z.Component = &.{ +const icons = @import("icons/root.zig").icons; + +pub const components: []const z.Component = &[_]z.Component{ @import("navbutton/root.zig").component, -}; +} ++ icons; -- cgit v1.2.3-70-g09d2