File tree Expand file tree Collapse file tree 4 files changed +92
-2
lines changed
Controls and Indicators/Value Inputs
Layout Containers/Scroll Views Expand file tree Collapse file tree 4 files changed +92
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,10 @@ struct BuiltinRegistry {
48
48
Link ( element: element, context: context)
49
49
case " divider " :
50
50
Divider ( )
51
-
51
+ case " edit-button " :
52
+ EditButton ( )
53
+ case " toggle " :
54
+ Toggle ( element: element, context: context)
52
55
case " phx-form " :
53
56
PhxForm < R > ( element: element, context: context)
54
57
case " phx-submit-button " :
Original file line number Diff line number Diff line change @@ -206,3 +206,15 @@ extension String: FormValue {
206
206
self = formValue
207
207
}
208
208
}
209
+
210
+ extension Bool : FormValue {
211
+ public var formValue : String {
212
+ self . description
213
+ }
214
+
215
+ public init ? ( formValue: String ) {
216
+ guard let value = Bool ( formValue)
217
+ else { return nil }
218
+ self = value
219
+ }
220
+ }
Original file line number Diff line number Diff line change
1
+ //
2
+ // Toggle.swift
3
+ //
4
+ //
5
+ // Created by Carson Katri on 1/17/23.
6
+ //
7
+
8
+ import SwiftUI
9
+
10
+ struct Toggle < R: CustomRegistry > : View {
11
+ @ObservedElement private var element : ElementNode
12
+ let context : LiveContext < R >
13
+
14
+ @FormState ( default: false ) var value : Bool
15
+
16
+ init ( element: ElementNode , context: LiveContext < R > ) {
17
+ self . context = context
18
+ }
19
+
20
+ public var body : some View {
21
+ SwiftUI . Toggle ( isOn: $value) {
22
+ context. buildChildren ( of: element)
23
+ }
24
+ . applyToggleStyle (
25
+ element. attributeValue ( for: " toggle-style " ) . flatMap ( ToggleStyle . init) ?? . automatic
26
+ )
27
+ }
28
+ }
29
+
30
+ fileprivate enum ToggleStyle : String {
31
+ case automatic
32
+ case button
33
+ case `switch`
34
+ #if os(macOS)
35
+ case checkbox
36
+ #endif
37
+ }
38
+
39
+ fileprivate extension View {
40
+ @ViewBuilder
41
+ func applyToggleStyle( _ style: ToggleStyle ) -> some View {
42
+ switch style {
43
+ case . automatic:
44
+ self . toggleStyle ( . automatic)
45
+ case . button:
46
+ self . toggleStyle ( . button)
47
+ case . `switch`:
48
+ self . toggleStyle ( . switch)
49
+ #if os(macOS)
50
+ case . checkbox:
51
+ self . toggleStyle ( . checkbox)
52
+ #endif
53
+ }
54
+ }
55
+ }
Original file line number Diff line number Diff line change @@ -16,8 +16,28 @@ struct ScrollView<R: CustomRegistry>: View {
16
16
}
17
17
18
18
public var body : some View {
19
- SwiftUI . ScrollView {
19
+ SwiftUI . ScrollView ( axes , showsIndicators : showsIndicators ) {
20
20
context. buildChildren ( of: element)
21
21
}
22
22
}
23
+
24
+ private var axes : Axis . Set {
25
+ switch element. attributeValue ( for: " axes " ) {
26
+ case " all " :
27
+ return [ . horizontal, . vertical]
28
+ case " horizontal " :
29
+ return . horizontal
30
+ default :
31
+ return . vertical
32
+ }
33
+ }
34
+
35
+ private var showsIndicators : Bool {
36
+ if let attr = element. attributeValue ( for: " shows-indicators " ) {
37
+ return attr == " true "
38
+ } else {
39
+ return true
40
+ }
41
+ }
42
+
23
43
}
You can’t perform that action at this time.
0 commit comments