mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 18:49:33 -06:00
41 lines
1.1 KiB
Zig
41 lines
1.1 KiB
Zig
/// Test: Components with error union of optional return type (!?Component)
|
|
pub fn Page(allocator: zx.Allocator) zx.Component {
|
|
var _zx = @import("zx").x.allocInit(allocator);
|
|
return _zx.ele(
|
|
.main,
|
|
.{
|
|
.allocator = allocator,
|
|
.children = &.{
|
|
_zx.cmp(
|
|
MaybeContent,
|
|
.{ .name = "MaybeContent" },
|
|
.{ .show = true },
|
|
),
|
|
_zx.cmp(
|
|
MaybeContent,
|
|
.{ .name = "MaybeContent" },
|
|
.{ .show = false },
|
|
),
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
/// Error union of optional - !?Component
|
|
const MaybeProps = struct { show: bool };
|
|
pub fn MaybeContent(ctx: *zx.ComponentCtx(MaybeProps)) !?zx.Component {
|
|
if (!ctx.props.show) return null;
|
|
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
|
return _zx.ele(
|
|
.div,
|
|
.{
|
|
.allocator = ctx.allocator,
|
|
.children = &.{
|
|
_zx.txt("Shown Content"),
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
const zx = @import("zx");
|