aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/components/image')
-rw-r--r--src/app/components/image/index.css26
-rw-r--r--src/app/components/image/index.html3
-rw-r--r--src/app/components/image/root.zig32
3 files changed, 61 insertions, 0 deletions
diff --git a/src/app/components/image/index.css b/src/app/components/image/index.css
new file mode 100644
index 0000000..d9a9ff5
--- /dev/null
+++ b/src/app/components/image/index.css
@@ -0,0 +1,26 @@
+.image {
+ width: 100%;
+ padding-bottom: 100%;
+ height: 0;
+ background: var(--image);
+ background-size: cover;
+ background-position: center;
+}
+
+img {
+ content: var(--image);
+ width: 100%;
+ display: none;
+ visibility: hidden;
+}
+
+@container style(--gallery-splits: 1) {
+ .image {
+ padding-bottom: 0px;
+ height: unset;
+ }
+
+ img {
+ display: unset;
+ }
+}
diff --git a/src/app/components/image/index.html b/src/app/components/image/index.html
new file mode 100644
index 0000000..2b135dc
--- /dev/null
+++ b/src/app/components/image/index.html
@@ -0,0 +1,3 @@
+<div class="image">
+ <img>
+</div>
diff --git a/src/app/components/image/root.zig b/src/app/components/image/root.zig
new file mode 100644
index 0000000..1d46d30
--- /dev/null
+++ b/src/app/components/image/root.zig
@@ -0,0 +1,32 @@
+const std = @import("std");
+const zilch = @import("zilch");
+
+pub const component: zilch.Component = .build(.{
+ .name = "image",
+ .html = .parse(@embedFile("index.html")),
+ .css = @embedFile("index.css"),
+ .link = @This(),
+});
+
+const Self = @This();
+
+element: *zilch.Object,
+style: *zilch.Object,
+
+pub fn init(self: *Self, element: *zilch.Object) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.element = element;
+ self.style = blk: {
+ var style = self.element.get(&env, "style");
+ break :blk try style.await(&env, *zilch.Object);
+ };
+}
+
+pub fn setUrl(self: *Self, env: *zilch.Env, url: []const u8) zilch.Env.Future(void) {
+ var buffer: [1024]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buffer);
+ writer.print("url({s})", .{url}) catch unreachable;
+ return .fromAny(self.style.call(env, "setProperty", .{"--image", writer.buffered()}));
+}