Skip to content

Commit c08d790

Browse files
merge with dev
2 parents 4e8055d + 44350ca commit c08d790

File tree

58 files changed

+1578
-645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1578
-645
lines changed

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ only_rules:
166166
- is_disjoint
167167

168168
# Tuples shouldn’t have too many members. Create a custom type instead
169-
- large_tuple
169+
# - large_tuple
170170

171171
# Prefer using .last(where:) over .filter { }.last in collections
172172
- last_where

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/ModalPreview+Helpers.swift

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct ModalPreviewHelpers {
6565
Text("Warning Background").tag(ComponentColor.warning.background)
6666
Text("Danger Background").tag(ComponentColor.danger.background)
6767
}
68+
BorderWidthPicker(selection: self.$model.borderWidth)
6869
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
6970
.disabled(self.footer == nil)
7071
Picker("Outer Paddings", selection: self.$model.outerPaddings) {
@@ -82,30 +83,17 @@ struct ModalPreviewHelpers {
8283
Text("16px").tag(Paddings(padding: 16))
8384
Text("20px").tag(Paddings(padding: 20))
8485
}
85-
Picker("Corner Radius", selection: self.$model.cornerRadius) {
86-
Text("None").tag(ModalRadius.none)
87-
Text("Small").tag(ModalRadius.small)
88-
Text("Medium").tag(ModalRadius.medium)
89-
Text("Large").tag(ModalRadius.large)
90-
Text("Custom 30px").tag(ModalRadius.custom(30))
91-
}
92-
Picker("Overlay Style", selection: self.$model.overlayStyle) {
93-
Text("Blurred").tag(ModalOverlayStyle.blurred)
94-
Text("Dimmed").tag(ModalOverlayStyle.dimmed)
95-
Text("Transparent").tag(ModalOverlayStyle.transparent)
86+
ContainerRadiusPicker(selection: self.$model.cornerRadius) {
87+
Text("Custom 30px").tag(ContainerRadius.custom(30))
9688
}
89+
OverlayStylePicker(selection: self.$model.overlayStyle)
9790
Picker("Size", selection: self.$model.size) {
9891
Text("Small").tag(ModalSize.small)
9992
Text("Medium").tag(ModalSize.medium)
10093
Text("Large").tag(ModalSize.large)
10194
Text("Full").tag(ModalSize.full)
10295
}
103-
Picker("Transition", selection: self.$model.transition) {
104-
Text("None").tag(ModalTransition.none)
105-
Text("Fast").tag(ModalTransition.fast)
106-
Text("Normal").tag(ModalTransition.normal)
107-
Text("Slow").tag(ModalTransition.slow)
108-
}
96+
TransitionPicker(selection: self.$model.transition)
10997
self.additionalPickers()
11098
}
11199
}

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ struct AutocapitalizationPicker: View {
3232
}
3333
}
3434

35+
// MARK: - BorderWidthPicker
36+
37+
struct BorderWidthPicker: View {
38+
@Binding var selection: BorderWidth
39+
40+
var body: some View {
41+
Picker("Border Width", selection: self.$selection) {
42+
Text("None").tag(BorderWidth.none)
43+
Text("Small").tag(BorderWidth.small)
44+
Text("Medium").tag(BorderWidth.medium)
45+
Text("Large").tag(BorderWidth.large)
46+
}
47+
}
48+
}
49+
3550
// MARK: - ComponentColorPicker
3651

3752
struct ComponentColorPicker: View {
@@ -75,7 +90,7 @@ struct ComponentOptionalColorPicker: View {
7590

7691
// MARK: - CornerRadiusPicker
7792

78-
struct CornerRadiusPicker<Custom: View>: View {
93+
struct ComponentRadiusPicker<Custom: View>: View {
7994
@Binding var selection: ComponentRadius
8095
@ViewBuilder var custom: () -> Custom
8196

@@ -91,6 +106,21 @@ struct CornerRadiusPicker<Custom: View>: View {
91106
}
92107
}
93108

109+
struct ContainerRadiusPicker<Custom: View>: View {
110+
@Binding var selection: ContainerRadius
111+
@ViewBuilder var custom: () -> Custom
112+
113+
var body: some View {
114+
Picker("Corner Radius", selection: self.$selection) {
115+
Text("None").tag(ContainerRadius.none)
116+
Text("Small").tag(ContainerRadius.small)
117+
Text("Medium").tag(ContainerRadius.medium)
118+
Text("Large").tag(ContainerRadius.large)
119+
self.custom()
120+
}
121+
}
122+
}
123+
94124
// MARK: - FontPickers
95125

96126
struct BodyFontPicker: View {
@@ -196,6 +226,20 @@ struct KeyboardTypePicker: View {
196226
}
197227
}
198228

229+
// MARK: - OverlayStylePicker
230+
231+
struct OverlayStylePicker: View {
232+
@Binding var selection: ModalOverlayStyle
233+
234+
var body: some View {
235+
Picker("Overlay Style", selection: self.$selection) {
236+
Text("Blurred").tag(ModalOverlayStyle.blurred)
237+
Text("Dimmed").tag(ModalOverlayStyle.dimmed)
238+
Text("Transparent").tag(ModalOverlayStyle.transparent)
239+
}
240+
}
241+
}
242+
199243
// MARK: - SizePicker
200244

201245
struct SizePicker: View {
@@ -228,6 +272,21 @@ struct SubmitTypePicker: View {
228272
}
229273
}
230274

275+
// MARK: - TransitionPicker
276+
277+
struct TransitionPicker: View {
278+
@Binding var selection: ModalTransition
279+
280+
var body: some View {
281+
Picker("Transition", selection: self.$selection) {
282+
Text("None").tag(ModalTransition.none)
283+
Text("Fast").tag(ModalTransition.fast)
284+
Text("Normal").tag(ModalTransition.normal)
285+
Text("Slow").tag(ModalTransition.slow)
286+
}
287+
}
288+
}
289+
231290
// MARK: - UniversalColorPicker
232291

233292
struct UniversalColorPicker: View {
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct AlertPreview: View {
6+
@State var isAlertPresented: Bool = false
7+
@State private var model = AlertVM {
8+
$0.title = Self.alertTitle
9+
$0.message = AlertMessage.short.rawValue
10+
$0.primaryButton = Self.initialPrimaryButton
11+
$0.secondaryButton = Self.initialSecondaryButton
12+
}
13+
14+
var body: some View {
15+
VStack {
16+
PreviewWrapper(title: "UIKit") {
17+
UKButton(model: .init { $0.title = "Show Alert" }) {
18+
UIApplication.shared.topViewController?.present(
19+
UKAlertController(model: self.model),
20+
animated: true
21+
)
22+
}
23+
.preview
24+
}
25+
PreviewWrapper(title: "SwiftUI") {
26+
SUButton(model: .init { $0.title = "Show Alert" }) {
27+
self.isAlertPresented = true
28+
}
29+
.suAlert(
30+
isPresented: self.$isAlertPresented,
31+
model: self.model
32+
)
33+
}
34+
Form {
35+
Section("Title") {
36+
Toggle("Has Title", isOn: .init(
37+
get: { return self.model.title != nil },
38+
set: { newValue in
39+
self.model.title = newValue ? Self.alertTitle : nil
40+
}
41+
))
42+
}
43+
44+
Section("Message") {
45+
Picker("Alert Message", selection: self.$model.message) {
46+
Text("None").tag(Optional<String>.none)
47+
Text("Short").tag(AlertMessage.short.rawValue)
48+
Text("Long").tag(AlertMessage.long.rawValue)
49+
}
50+
}
51+
52+
Section("Primary Button") {
53+
Toggle("Has Primary Button", isOn: .init(
54+
get: { return self.model.primaryButton != nil },
55+
set: { newValue in
56+
self.model.primaryButton = newValue ? Self.initialPrimaryButton : nil
57+
}
58+
))
59+
if self.model.primaryButton != nil {
60+
Picker("Title", selection: self.primaryButtonVMOrDefault.title) {
61+
Text("Short").tag(PrimaryButtonText.short.rawValue)
62+
Text("Longer").tag(PrimaryButtonText.longer.rawValue)
63+
}
64+
self.buttonPickers(for: self.primaryButtonVMOrDefault)
65+
}
66+
}
67+
68+
Section("Secondary Button") {
69+
Toggle("Has Secondary Button", isOn: .init(
70+
get: { return self.model.secondaryButton != nil },
71+
set: { newValue in
72+
self.model.secondaryButton = newValue ? Self.initialSecondaryButton : nil
73+
}
74+
))
75+
if self.model.secondaryButton != nil {
76+
Picker("Title", selection: self.secondaryButtonVMOrDefault.title) {
77+
Text("Short").tag(SecondaryButtonText.short.rawValue)
78+
Text("Longer").tag(SecondaryButtonText.longer.rawValue)
79+
}
80+
self.buttonPickers(for: self.secondaryButtonVMOrDefault)
81+
}
82+
}
83+
84+
Section("Main Properties") {
85+
Picker("Background Color", selection: self.$model.backgroundColor) {
86+
Text("Default").tag(Optional<UniversalColor>.none)
87+
Text("Accent Background").tag(ComponentColor.accent.background)
88+
Text("Success Background").tag(ComponentColor.success.background)
89+
Text("Warning Background").tag(ComponentColor.warning.background)
90+
Text("Danger Background").tag(ComponentColor.danger.background)
91+
}
92+
BorderWidthPicker(selection: self.$model.borderWidth)
93+
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
94+
Picker("Content Paddings", selection: self.$model.contentPaddings) {
95+
Text("12px").tag(Paddings(padding: 12))
96+
Text("16px").tag(Paddings(padding: 16))
97+
Text("20px").tag(Paddings(padding: 20))
98+
}
99+
ContainerRadiusPicker(selection: self.$model.cornerRadius) {
100+
Text("Custom 30px").tag(ContainerRadius.custom(30))
101+
}
102+
OverlayStylePicker(selection: self.$model.overlayStyle)
103+
TransitionPicker(selection: self.$model.transition)
104+
}
105+
}
106+
}
107+
}
108+
109+
// MARK: - Reusable Pickers
110+
111+
private func buttonPickers(for buttonVM: Binding<AlertButtonVM>) -> some View {
112+
Group {
113+
AnimationScalePicker(selection: buttonVM.animationScale)
114+
ComponentOptionalColorPicker(selection: buttonVM.color)
115+
ComponentRadiusPicker(selection: buttonVM.cornerRadius) {
116+
Text("Custom: 20px").tag(ComponentRadius.custom(20))
117+
}
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+
}
126+
}
127+
}
128+
129+
// MARK: - Helpers
130+
131+
enum AlertMessage: String {
132+
case short = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
133+
case long = """
134+
Lorem ipsum odor amet, consectetuer adipiscing elit. Vitae vehicula pellentesque lectus orci fames. Cras suscipit dui tortor penatibus turpis ultrices. Laoreet montes adipiscing ante dapibus facilisis. Lorem per fames nec duis quis eleifend imperdiet. Tincidunt id interdum adipiscing eros dis quis platea varius. Potenti eleifend eu molestie laoreet varius sapien. Adipiscing nascetur platea penatibus curabitur tempus nibh laoreet porttitor. Augue et curabitur cras sed semper inceptos nunc montes mollis.
135+
136+
Lectus arcu pellentesque inceptos tempor fringilla nascetur. Erat curae convallis integer mi, quis facilisi tortor. Phasellus aliquam molestie vehicula odio in dis maximus diam elit. Rutrum gravida amet euismod feugiat fusce. Est egestas velit vulputate senectus sociosqu fringilla eget nibh. Nam pellentesque aenean mi platea tincidunt quam sem purus. Himenaeos suspendisse nec sapien habitasse ultricies maecenas libero odio. Rutrum senectus maximus ultrices, ad nam ultricies placerat.
137+
138+
Enim habitant laoreet inceptos scelerisque senectus, tellus molestie ut. Eros risus nibh morbi eu aenean. Velit ligula magnis aliquet at luctus. Dapibus vestibulum consectetur euismod vitae per ultrices litora quis. Aptent eleifend dapibus urna lacinia felis nisl. Sit amet fusce nullam feugiat posuere. Urna amet curae velit fermentum interdum vestibulum penatibus. Penatibus vivamus sem ultricies pellentesque congue id mattis diam. Aliquam efficitur mi gravida sollicitudin; amet imperdiet. Rutrum mollis risus justo tortor in duis cursus.
139+
"""
140+
}
141+
enum PrimaryButtonText: String {
142+
case short = "Continue"
143+
case longer = "Remind me later"
144+
}
145+
enum SecondaryButtonText: String {
146+
case short = "Cancel"
147+
case longer = "Cancel, Don't Do That"
148+
}
149+
static let alertTitle = "Alert Title"
150+
static let initialPrimaryButton = AlertButtonVM {
151+
$0.title = PrimaryButtonText.short.rawValue
152+
$0.style = .filled
153+
$0.color = .primary
154+
}
155+
static let initialSecondaryButton = AlertButtonVM {
156+
$0.title = SecondaryButtonText.short.rawValue
157+
$0.style = .light
158+
}
159+
160+
var primaryButtonVMOrDefault: Binding<AlertButtonVM> {
161+
return .init(
162+
get: { self.model.primaryButton ?? Self.initialPrimaryButton },
163+
set: { self.model.primaryButton = $0 }
164+
)
165+
}
166+
var secondaryButtonVMOrDefault: Binding<AlertButtonVM> {
167+
return .init(
168+
get: { self.model.secondaryButton ?? Self.initialSecondaryButton },
169+
set: { self.model.secondaryButton = $0 }
170+
)
171+
}
172+
}
173+
174+
#Preview {
175+
AlertPreview()
176+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ struct ButtonPreview: View {
1919
Form {
2020
AnimationScalePicker(selection: self.$model.animationScale)
2121
ComponentOptionalColorPicker(selection: self.$model.color)
22-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
22+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
2323
Text("Custom: 20px").tag(ComponentRadius.custom(20))
2424
}
2525
ButtonFontPicker(selection: self.$model.font)
2626
Toggle("Enabled", isOn: self.$model.isEnabled)
2727
Toggle("Full Width", isOn: self.$model.isFullWidth)
2828
SizePicker(selection: self.$model.size)
2929
Picker("Style", selection: self.$model.style) {
30-
Text("Filled").tag(ButtonVM.Style.filled)
31-
Text("Plain").tag(ButtonVM.Style.plain)
32-
Text("Light").tag(ButtonVM.Style.light)
33-
Text("Bordered with small border").tag(ButtonVM.Style.bordered(.small))
34-
Text("Bordered with medium border").tag(ButtonVM.Style.bordered(.medium))
35-
Text("Bordered with large border").tag(ButtonVM.Style.bordered(.large))
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))
3636
}
3737
}
3838
}

0 commit comments

Comments
 (0)