Skip to content

Commit 95aaf07

Browse files
committed
Update MenuItemsBuilder to support optional and either blocks
1 parent 28a2db7 commit 95aaf07

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Sources/SwiftCrossUI/Builders/MenuItemsBuilder.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public struct MenuItemsBuilder {
1313
[.submenu(first)]
1414
}
1515

16+
public static func buildPartialBlock(first: Block) -> [MenuItem] {
17+
first.items
18+
}
19+
1620
public static func buildPartialBlock(
1721
accumulated: [MenuItem],
1822
next: Button
@@ -33,4 +37,29 @@ public struct MenuItemsBuilder {
3337
) -> [MenuItem] {
3438
accumulated + [.submenu(next)]
3539
}
40+
41+
public static func buildPartialBlock(
42+
accumulated: [MenuItem],
43+
next: Block
44+
) -> [MenuItem] {
45+
accumulated + next.items
46+
}
47+
48+
public static func buildOptional(_ component: [MenuItem]?) -> Block {
49+
Block(items: component ?? [])
50+
}
51+
52+
public static func buildEither(first component: [MenuItem]) -> Block {
53+
Block(items: component)
54+
}
55+
56+
public static func buildEither(second component: [MenuItem]) -> Block {
57+
Block(items: component)
58+
}
59+
60+
/// An implementation detail of ``MenuItemBuilder``'s support for
61+
/// `if`/`else if`/`else` blocks.
62+
public struct Block {
63+
var items: [MenuItem]
64+
}
3665
}

0 commit comments

Comments
 (0)