aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/image/root.zig
blob: 1d46d304418955baee76ddcd8b2604abba1ac826 (plain)
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
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()}));
}