@@ -29,9 +29,9 @@ func title<V>(_ view: V, title: String) -> AnyView where V: View {
29
29
}
30
30
}
31
31
32
- struct NavItem : Identifiable {
33
- var id : String
34
- var destination : AnyView ?
32
+ struct NavItem : View {
33
+ let id : String
34
+ let destination : AnyView ?
35
35
36
36
init < V> ( _ id: String , destination: V ) where V: View {
37
37
self . id = id
@@ -40,124 +40,109 @@ struct NavItem: Identifiable {
40
40
41
41
init ( unavailable id: String ) {
42
42
self . id = id
43
+ destination = nil
43
44
}
44
- }
45
-
46
- var outlineGroupDemo : NavItem {
47
- if #available( OSX 10 . 16 , iOS 14 . 0 , * ) {
48
- return NavItem ( " OutlineGroup " , destination: OutlineGroupDemo ( ) )
49
- } else {
50
- return NavItem ( unavailable: " OutlineGroup " )
51
- }
52
- }
53
-
54
- #if !os(macOS)
55
- var listDemo : AnyView {
56
- if #available( iOS 14 . 0 , * ) {
57
- return AnyView ( ListDemo ( ) . listStyle ( InsetGroupedListStyle ( ) ) )
58
- } else {
59
- return AnyView ( ListDemo ( ) )
60
- }
61
- }
62
- #else
63
- var listDemo = ListDemo ( )
64
- #endif
65
-
66
- var sidebarDemo : NavItem {
67
- if #available( iOS 14 . 0 , * ) {
68
- return NavItem ( " Sidebar " , destination: SidebarListDemo ( ) . listStyle ( SidebarListStyle ( ) ) )
69
- } else {
70
- return NavItem ( unavailable: " Sidebar " )
71
- }
72
- }
73
-
74
- var gridDemo : NavItem {
75
- if #available( OSX 10 . 16 , iOS 14 . 0 , * ) {
76
- return NavItem ( " Grid " , destination: GridDemo ( ) )
77
- } else {
78
- return NavItem ( unavailable: " Grid " )
79
- }
80
- }
81
-
82
- var appStorageDemo : NavItem {
83
- if #available( OSX 11 . 0 , iOS 14 . 0 , * ) {
84
- return NavItem ( " AppStorage " , destination: AppStorageDemo ( ) )
85
- } else {
86
- return NavItem ( unavailable: " AppStorage " )
87
- }
88
- }
89
45
90
- var redactDemo : NavItem {
91
- if #available( OSX 11 . 0 , iOS 14 . 0 , * ) {
92
- return NavItem ( " Redact " , destination: RedactDemo ( ) )
93
- } else {
94
- return NavItem ( unavailable: " Redact " )
46
+ @ViewBuilder var body : some View {
47
+ if let dest = destination {
48
+ NavigationLink ( id, destination: HStack {
49
+ Spacer ( minLength: 0 )
50
+ dest
51
+ Spacer ( minLength: 0 )
52
+ } )
53
+ } else {
54
+ #if os(WASI)
55
+ Text ( id)
56
+ #elseif os(macOS)
57
+ Text ( id) . opacity ( 0.5 )
58
+ #else
59
+ HStack {
60
+ Text ( id)
61
+ Spacer ( )
62
+ Text ( " unavailable " ) . opacity ( 0.5 )
63
+ }
64
+ #endif
65
+ }
95
66
}
96
67
}
97
68
98
- var domRefDemo : NavItem {
99
- #if os(WASI)
100
- return NavItem ( " DOM reference " , destination: DOMRefDemo ( ) )
101
- #else
102
- return NavItem ( unavailable: " DOM reference " )
103
- #endif
104
- }
105
-
106
- let links = [
107
- NavItem ( " Counter " , destination:
108
- Counter ( count: Count ( value: 5 ) , limit: 15 )
109
- . padding ( )
110
- . background ( Color ( red: 0.9 , green: 0.9 , blue: 0.9 , opacity: 1.0 ) )
111
- . border ( Color . red, width: 3 ) ) ,
112
- NavItem ( " ZStack " , destination: ZStack {
113
- Text ( " I'm on bottom " )
114
- Text ( " I'm forced to the top " )
115
- . zIndex ( 1 )
116
- Text ( " I'm on top " )
117
- } . padding ( 20 ) ) ,
118
- NavItem ( " ButtonStyle " , destination: ButtonStyleDemo ( ) ) ,
119
- NavItem ( " ForEach " , destination: ForEachDemo ( ) ) ,
120
- NavItem ( " Text " , destination: TextDemo ( ) ) ,
121
- NavItem ( " Toggle " , destination: ToggleDemo ( ) ) ,
122
- NavItem ( " Path " , destination: PathDemo ( ) ) ,
123
- NavItem ( " TextField " , destination: TextFieldDemo ( ) ) ,
124
- NavItem ( " Spacer " , destination: SpacerDemo ( ) ) ,
125
- NavItem ( " Environment " , destination: EnvironmentDemo ( ) . font ( . system( size: 8 ) ) ) ,
126
- NavItem ( " Picker " , destination: PickerDemo ( ) ) ,
127
- NavItem ( " List " , destination: listDemo) ,
128
- sidebarDemo,
129
- outlineGroupDemo,
130
- NavItem ( " Color " , destination: ColorDemo ( ) ) ,
131
- appStorageDemo,
132
- gridDemo,
133
- redactDemo,
134
- domRefDemo,
135
- ]
136
-
137
69
struct TokamakDemoView : View {
138
70
var body : some View {
139
71
NavigationView { ( ) -> AnyView in
140
72
let list = title (
141
- List ( links) { link in
142
- if let dest = link. destination {
143
- NavigationLink ( link. id, destination: HStack {
144
- Spacer ( )
145
- dest
146
- Spacer ( )
147
- } )
148
- } else {
149
- #if os(WASI)
150
- Text ( link. id)
151
- #elseif os(macOS)
152
- Text ( link. id) . opacity ( 0.5 )
153
- #else
154
- HStack {
155
- Text ( link. id)
156
- Spacer ( )
157
- Text ( " unavailable " ) . opacity ( 0.5 )
73
+ List {
74
+ Section ( header: Text ( " Buttons " ) ) {
75
+ NavItem ( " Counter " , destination:
76
+ Counter ( count: Count ( value: 5 ) , limit: 15 )
77
+ . padding ( )
78
+ . background ( Color ( red: 0.9 , green: 0.9 , blue: 0.9 , opacity: 1.0 ) )
79
+ . border ( Color . red, width: 3 ) )
80
+ NavItem ( " ButtonStyle " , destination: ButtonStyleDemo ( ) )
81
+ }
82
+ Section ( header: Text ( " Containers " ) ) {
83
+ NavItem ( " ForEach " , destination: ForEachDemo ( ) )
84
+ if #available( iOS 14 . 0 , * ) {
85
+ #if os(macOS)
86
+ NavItem ( " List " , destination: ListDemo ( ) )
87
+ #else
88
+ NavItem ( " List " , destination: ListDemo ( ) . listStyle ( InsetGroupedListStyle ( ) ) )
89
+ #endif
90
+ } else {
91
+ NavItem ( " List " , destination: ListDemo ( ) )
158
92
}
159
- #endif
93
+ if #available( iOS 14 . 0 , * ) {
94
+ NavItem ( " Sidebar " , destination: SidebarListDemo ( ) . listStyle ( SidebarListStyle ( ) ) )
95
+ } else {
96
+ NavItem ( unavailable: " Sidebar " )
97
+ }
98
+ if #available( OSX 10 . 16 , iOS 14 . 0 , * ) {
99
+ NavItem ( " OutlineGroup " , destination: OutlineGroupDemo ( ) )
100
+ } else {
101
+ NavItem ( unavailable: " OutlineGroup " )
102
+ }
103
+ }
104
+ Section ( header: Text ( " Layout " ) ) {
105
+ if #available( OSX 10 . 16 , iOS 14 . 0 , * ) {
106
+ NavItem ( " Grid " , destination: GridDemo ( ) )
107
+ } else {
108
+ NavItem ( unavailable: " Grid " )
109
+ }
110
+ NavItem ( " Spacer " , destination: SpacerDemo ( ) )
111
+ NavItem ( " ZStack " , destination: ZStack {
112
+ Text ( " I'm on bottom " )
113
+ Text ( " I'm forced to the top " )
114
+ . zIndex ( 1 )
115
+ Text ( " I'm on top " )
116
+ } . padding ( 20 ) )
117
+ }
118
+ Section ( header: Text ( " Selectors " ) ) {
119
+ NavItem ( " Picker " , destination: PickerDemo ( ) )
120
+ NavItem ( " Toggle " , destination: ToggleDemo ( ) )
121
+ }
122
+ Section ( header: Text ( " Text " ) ) {
123
+ NavItem ( " Text " , destination: TextDemo ( ) )
124
+ NavItem ( " TextField " , destination: TextFieldDemo ( ) )
125
+ }
126
+ Section ( header: Text ( " Misc " ) ) {
127
+ NavItem ( " Path " , destination: PathDemo ( ) )
128
+ NavItem ( " Environment " , destination: EnvironmentDemo ( ) . font ( . system( size: 8 ) ) )
129
+ NavItem ( " Color " , destination: ColorDemo ( ) )
130
+ if #available( OSX 11 . 0 , iOS 14 . 0 , * ) {
131
+ NavItem ( " AppStorage " , destination: AppStorageDemo ( ) )
132
+ } else {
133
+ NavItem ( unavailable: " AppStorage " )
134
+ }
135
+ if #available( OSX 11 . 0 , iOS 14 . 0 , * ) {
136
+ NavItem ( " Redaction " , destination: RedactionDemo ( ) )
137
+ } else {
138
+ NavItem ( unavailable: " Redaction " )
139
+ }
140
+ }
141
+ #if os(WASI)
142
+ Section ( header: Text ( " TokamakDOM " ) ) {
143
+ NavItem ( " DOM reference " , destination: DOMRefDemo ( ) )
160
144
}
145
+ #endif
161
146
}
162
147
. frame ( minHeight: 300 ) ,
163
148
title: " Demos "
0 commit comments