Skip to content

Commit 34c4690

Browse files
Merge pull request #84 from componentskit/dev
v1.5.1
2 parents 0a29487 + 46e859b commit 34c4690

32 files changed

+977
-236
lines changed

Examples/DemosApp/DemosApp.xcodeproj/project.pbxproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 70;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -80,7 +80,6 @@
8080
740D221F2CD3BECA006731A5 /* Project object */ = {
8181
isa = PBXProject;
8282
attributes = {
83-
BuildIndependentTargetsInParallel = 1;
8483
LastSwiftUpdateCheck = 1610;
8584
LastUpgradeCheck = 1610;
8685
TargetAttributes = {

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

+32-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct AutocapitalizationPicker: View {
2323
@Binding var selection: TextAutocapitalization
2424

2525
var body: some View {
26-
Picker("Autocapitalization", selection: $selection) {
26+
Picker("Autocapitalization", selection: self.$selection) {
2727
Text("Never").tag(TextAutocapitalization.never)
2828
Text("Characters").tag(TextAutocapitalization.characters)
2929
Text("Words").tag(TextAutocapitalization.words)
@@ -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 {
@@ -203,13 +219,25 @@ struct CaptionFontPicker: View {
203219
}
204220
}
205221

222+
struct InputStylePicker: View {
223+
@Binding var selection: InputStyle
224+
225+
var body: some View {
226+
Picker("Style", selection: self.$selection) {
227+
Text("Light").tag(InputStyle.light)
228+
Text("Bordered").tag(InputStyle.bordered)
229+
Text("Faded").tag(InputStyle.faded)
230+
}
231+
}
232+
}
233+
206234
// MARK: - KeyboardTypePicker
207235

208236
struct KeyboardTypePicker: View {
209237
@Binding var selection: UIKeyboardType
210238

211239
var body: some View {
212-
Picker("Keyboard Type", selection: $selection) {
240+
Picker("Keyboard Type", selection: self.$selection) {
213241
Text("Default").tag(UIKeyboardType.default)
214242
Text("asciiCapable").tag(UIKeyboardType.asciiCapable)
215243
Text("numbersAndPunctuation").tag(UIKeyboardType.numbersAndPunctuation)
@@ -260,7 +288,7 @@ struct SubmitTypePicker: View {
260288
@Binding var selection: SubmitType
261289

262290
var body: some View {
263-
Picker("Submit Type", selection: $selection) {
291+
Picker("Submit Type", selection: self.$selection) {
264292
Text("done").tag(SubmitType.done)
265293
Text("go").tag(SubmitType.go)
266294
Text("join").tag(SubmitType.join)

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

+1-8
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

+26-11
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ 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
}
9-
10+
1011
var body: some View {
1112
VStack {
1213
PreviewWrapper(title: "UIKit") {
@@ -19,21 +20,35 @@ struct ButtonPreview: View {
1920
Form {
2021
AnimationScalePicker(selection: self.$model.animationScale)
2122
ComponentOptionalColorPicker(selection: self.$model.color)
23+
Picker("Content Spacing", selection: self.$model.contentSpacing) {
24+
Text("4").tag(CGFloat(4))
25+
Text("8").tag(CGFloat(8))
26+
Text("12").tag(CGFloat(12))
27+
}
2228
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
2329
Text("Custom: 20px").tag(ComponentRadius.custom(20))
2430
}
25-
ButtonFontPicker(selection: self.$model.font)
2631
Toggle("Enabled", isOn: self.$model.isEnabled)
32+
ButtonFontPicker(selection: self.$model.font)
2733
Toggle("Full Width", isOn: self.$model.isFullWidth)
28-
SizePicker(selection: self.$model.size)
29-
Picker("Style", selection: self.$model.style) {
30-
Text("Filled").tag(ButtonStyle.filled)
31-
Text("Plain").tag(ButtonStyle.plain)
32-
Text("Light").tag(ButtonStyle.light)
33-
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
34-
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
35-
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))
34+
Picker("Image Location", selection: self.$model.imageLocation) {
35+
Text("Leading").tag(ButtonVM.ImageLocation.leading)
36+
Text("Trailing").tag(ButtonVM.ImageLocation.trailing)
37+
}
38+
Picker("Image Source", selection: self.$model.imageSrc) {
39+
Text("SF Symbol").tag(ButtonVM.ImageSource.sfSymbol("camera.fill"))
40+
Text("Local").tag(ButtonVM.ImageSource.local("avatar_placeholder"))
41+
Text("None").tag(Optional<ButtonVM.ImageSource>.none)
3642
}
43+
Toggle("Loading", isOn: self.$model.isLoading)
44+
Toggle("Show Title", isOn: Binding<Bool>(
45+
get: { !self.model.title.isEmpty },
46+
set: { newValue in
47+
self.model.title = newValue ? Self.title : ""
48+
}
49+
))
50+
SizePicker(selection: self.$model.size)
51+
ButtonStylePicker(selection: self.$model.style)
3752
}
3853
}
3954
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CardPreview.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@ struct CardPreview: View {
1515
SUCard(model: self.model, content: self.suCardContent)
1616
}
1717
Form {
18+
AnimationScalePicker(selection: self.$model.animationScale)
1819
Picker("Background Color", selection: self.$model.backgroundColor) {
19-
Text("Default").tag(Optional<UniversalColor>.none)
20+
Text("Background").tag(UniversalColor.background)
2021
Text("Secondary Background").tag(UniversalColor.secondaryBackground)
2122
Text("Accent Background").tag(UniversalColor.accentBackground)
2223
Text("Success Background").tag(UniversalColor.successBackground)
2324
Text("Warning Background").tag(UniversalColor.warningBackground)
2425
Text("Danger Background").tag(UniversalColor.dangerBackground)
2526
}
27+
Picker("Border Color", selection: self.$model.borderColor) {
28+
Text("Divider").tag(UniversalColor.divider)
29+
Text("Primary").tag(UniversalColor.primary)
30+
Text("Accent").tag(UniversalColor.accent)
31+
Text("Success").tag(UniversalColor.success)
32+
Text("Warning").tag(UniversalColor.warning)
33+
Text("Danger").tag(UniversalColor.danger)
34+
Text("Custom").tag(UniversalColor.universal(.uiColor(.systemPurple)))
35+
}
2636
BorderWidthPicker(selection: self.$model.borderWidth)
2737
Picker("Content Paddings", selection: self.$model.contentPaddings) {
2838
Text("12px").tag(Paddings(padding: 12))
@@ -39,6 +49,7 @@ struct CardPreview: View {
3949
Text("Large").tag(Shadow.large)
4050
Text("Custom").tag(Shadow.custom(20.0, .zero, UniversalColor.accentBackground))
4151
}
52+
Toggle("Tappable", isOn: self.$model.isTappable)
4253
}
4354
}
4455
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/InputFieldPreview.swift

+23-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ struct InputFieldPreview: View {
3434
Form {
3535
AutocapitalizationPicker(selection: self.$model.autocapitalization)
3636
Toggle("Autocorrection Enabled", isOn: self.$model.isAutocorrectionEnabled)
37+
Toggle("Caption", isOn: .init(
38+
get: {
39+
return self.model.caption != nil
40+
},
41+
set: { newValue in
42+
self.model.caption = newValue ? Self.caption : nil
43+
}
44+
))
45+
CaptionFontPicker(title: "Caption Font", selection: self.$model.captionFont)
3746
ComponentOptionalColorPicker(selection: self.$model.color)
3847
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
3948
Text("Custom: 20px").tag(ComponentRadius.custom(20))
@@ -46,12 +55,13 @@ struct InputFieldPreview: View {
4655
return self.model.placeholder != nil
4756
},
4857
set: { newValue in
49-
self.model.placeholder = newValue ? "Placeholder" : nil
58+
self.model.placeholder = newValue ? Self.placeholder : nil
5059
}
5160
))
5261
Toggle("Required", isOn: self.$model.isRequired)
5362
Toggle("Secure Input", isOn: self.$model.isSecureInput)
5463
SizePicker(selection: self.$model.size)
64+
InputStylePicker(selection: self.$model.style)
5565
SubmitTypePicker(selection: self.$model.submitType)
5666
UniversalColorPicker(
5767
title: "Tint Color",
@@ -62,9 +72,14 @@ struct InputFieldPreview: View {
6272
return self.model.title != nil
6373
},
6474
set: { newValue in
65-
self.model.title = newValue ? "Title" : nil
75+
self.model.title = newValue ? Self.title : nil
6676
}
6777
))
78+
BodyFontPicker(title: "Title Font", selection: self.$model.titleFont)
79+
Picker("Title Position", selection: self.$model.titlePosition) {
80+
Text("Inside").tag(InputFieldVM.TitlePosition.inside)
81+
Text("Outside").tag(InputFieldVM.TitlePosition.outside)
82+
}
6883
}
6984
}
7085
.toolbar {
@@ -79,9 +94,14 @@ struct InputFieldPreview: View {
7994
}
8095
}
8196

97+
private static let title = "Email"
98+
private static let placeholder = "Enter your email"
99+
private static let caption = "Your email address will be used to send a verification code"
82100
private static var initialModel: InputFieldVM {
83101
return .init {
84-
$0.title = "Title"
102+
$0.title = Self.title
103+
$0.placeholder = Self.placeholder
104+
$0.caption = Self.caption
85105
}
86106
}
87107
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct TextInputPreviewPreview: View {
6060
}
6161
))
6262
SizePicker(selection: self.$model.size)
63+
InputStylePicker(selection: self.$model.style)
6364
SubmitTypePicker(selection: self.$model.submitType)
6465
UniversalColorPicker(
6566
title: "Tint Color",

Sources/ComponentsKit/Components/Alert/UKAlertController.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,14 @@ public class UKAlertController: UKCenterModalController {
143143
self.buttonsStackView.removeArrangedSubview(self.secondaryButton)
144144
self.buttonsStackView.insertArrangedSubview(self.secondaryButton, at: 0)
145145
self.buttonsStackView.axis = .horizontal
146+
self.buttonsStackView.distribution = .fillEqually
146147
case .vertical:
147148
self.buttonsStackView.axis = .vertical
149+
self.buttonsStackView.distribution = .fillProportionally
148150
}
149151
} else {
150152
self.buttonsStackView.axis = .vertical
153+
self.buttonsStackView.distribution = .fillProportionally
151154
}
152155
}
153156
}
@@ -173,7 +176,6 @@ extension UKAlertController {
173176
}
174177

175178
static func buttonsStackView(_ stackView: UIStackView) {
176-
stackView.distribution = .fillEqually
177179
stackView.spacing = AlertVM.buttonsSpacing
178180
}
179181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
3+
/// Specifies the position of the image relative to the button's title.
4+
extension ButtonVM {
5+
public enum ImageLocation {
6+
/// The image is displayed before the title.
7+
case leading
8+
/// The image is displayed after the title.
9+
case trailing
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Foundation
2+
3+
/// Defines the image source options for a button.
4+
extension ButtonVM {
5+
public enum ImageSource: Hashable {
6+
/// An image loaded from a system SF Symbol.
7+
///
8+
/// - Parameter name: The name of the SF Symbol.
9+
case sfSymbol(String)
10+
11+
/// An image loaded from a local asset.
12+
///
13+
/// - Parameters:
14+
/// - name: The name of the local image asset.
15+
/// - bundle: The bundle containing the image resource. Defaults to `nil` to use the main bundle.
16+
case local(String, bundle: Bundle? = nil)
17+
}
18+
}

0 commit comments

Comments
 (0)