Skip to content

Commit 6641e46

Browse files
add ButtonStylePicker helper
1 parent caf0a63 commit 6641e46

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewPickers.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct AutocapitalizationPicker: View {
3636

3737
struct BorderWidthPicker: View {
3838
@Binding var selection: BorderWidth
39-
39+
4040
var body: some View {
4141
Picker("Border Width", selection: self.$selection) {
4242
Text("None").tag(BorderWidth.none)
@@ -47,6 +47,22 @@ struct BorderWidthPicker: View {
4747
}
4848
}
4949

50+
struct ButtonStylePicker: View {
51+
@Binding var selection: ComponentsKit.ButtonStyle
52+
53+
var body: some View {
54+
Picker("Style", selection: $selection) {
55+
Text("Filled").tag(ButtonStyle.filled)
56+
Text("Plain").tag(ButtonStyle.plain)
57+
Text("Light").tag(ButtonStyle.light)
58+
Text("Minimal").tag(ButtonStyle.minimal)
59+
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
60+
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
61+
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))
62+
}
63+
}
64+
}
65+
5066
// MARK: - ComponentColorPicker
5167

5268
struct ComponentColorPicker: View {

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/AlertPreview.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,7 @@ struct AlertPreview: View {
115115
ComponentRadiusPicker(selection: buttonVM.cornerRadius) {
116116
Text("Custom: 20px").tag(ComponentRadius.custom(20))
117117
}
118-
Picker("Style", selection: buttonVM.style) {
119-
Text("Filled").tag(ButtonStyle.filled)
120-
Text("Plain").tag(ButtonStyle.plain)
121-
Text("Light").tag(ButtonStyle.light)
122-
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
123-
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
124-
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))
125-
}
118+
ButtonStylePicker(selection: buttonVM.style)
126119
}
127120
}
128121

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/ButtonPreview.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import SwiftUI
33
import UIKit
44

55
struct ButtonPreview: View {
6+
private static let title = "Button"
67
@State private var model = ButtonVM {
7-
$0.title = "Button"
8+
$0.title = Self.title
89
}
910

1011
var body: some View {
@@ -43,19 +44,11 @@ struct ButtonPreview: View {
4344
Toggle("Show Title", isOn: Binding<Bool>(
4445
get: { !self.model.title.isEmpty },
4546
set: { newValue in
46-
self.model.title = newValue ? "Button" : ""
47+
self.model.title = newValue ? Self.title : ""
4748
}
4849
))
4950
SizePicker(selection: self.$model.size)
50-
Picker("Style", selection: self.$model.style) {
51-
Text("Filled").tag(ButtonStyle.filled)
52-
Text("Plain").tag(ButtonStyle.plain)
53-
Text("Light").tag(ButtonStyle.light)
54-
Text("Minimal").tag(ButtonStyle.minimal)
55-
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
56-
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
57-
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))
58-
}
51+
ButtonStylePicker(selection: self.$model.style)
5952
}
6053
}
6154
}

0 commit comments

Comments
 (0)