ziex/test/data/component/children_only.zig
Nurul Huda (Apon) 33ec71739d
refactor(ast): use direct import of zx
- This is to allow importing zx with any other decl name than zx
2026-02-09 11:14:05 +06:00

84 lines
2.4 KiB
Zig

pub fn Page(allocator: zx.Allocator) zx.Component {
var _zx = @import("zx").allocInit(allocator);
return _zx.ele(
.main,
.{
.allocator = allocator,
.children = &.{
_zx.cmp(
Wrapper,
.{},
.{ .children = _zx.ele(.fragment, .{ .children = &.{
_zx.ele(
.p,
.{
.children = &.{
_zx.txt("Wrapped content"),
},
},
),
} }) },
),
_zx.cmp(
Container,
.{},
.{ .children = _zx.ele(.fragment, .{ .children = &.{
_zx.ele(
.span,
.{
.children = &.{
_zx.txt("First"),
},
},
),
_zx.ele(
.span,
.{
.children = &.{
_zx.txt("Second"),
},
},
),
} }) },
),
},
},
);
}
const WrapperProps = struct { children: zx.Component };
fn Wrapper(allocator: zx.Allocator, props: WrapperProps) zx.Component {
var _zx = @import("zx").allocInit(allocator);
return _zx.ele(
.div,
.{
.allocator = allocator,
.attributes = _zx.attrs(.{
_zx.attr("class", "wrapper"),
}),
.children = &.{
_zx.expr(props.children),
},
},
);
}
const ContainerProps = struct { children: zx.Component };
fn Container(allocator: zx.Allocator, props: ContainerProps) zx.Component {
var _zx = @import("zx").allocInit(allocator);
return _zx.ele(
.section,
.{
.allocator = allocator,
.attributes = _zx.attrs(.{
_zx.attr("class", "container"),
}),
.children = &.{
_zx.expr(props.children),
},
},
);
}
const zx = @import("zx");