Skip to content

Commit 29af48e

Browse files
merge with modal-uikit
2 parents 0a66a09 + fe30575 commit 29af48e

File tree

103 files changed

+3207
-1003
lines changed

Some content is hidden

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

103 files changed

+3207
-1003
lines changed

.github/workflows/swiftlint.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: SwiftLint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/swiftlint.yml'
7+
- '.swiftlint.yml'
8+
- '**/*.swift'
9+
10+
jobs:
11+
SwiftLint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Run SwiftLint
16+
uses: norio-nomura/[email protected]
17+
with:
18+
args: --strict

.swiftlint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ function_body_length:
409409

410410
included:
411411
- Sources
412-
- Examples
413412

414413
excluded:
415414
- .swiftpm

ComponentsKit.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ struct ModalPreviewHelpers {
5959
var body: some View {
6060
Section("Properties") {
6161
Picker("Background Color", selection: self.$model.backgroundColor) {
62-
Text("Primary").tag(Palette.Base.background)
63-
Text("Secondary").tag(Palette.Base.secondaryBackground)
64-
Text("Custom").tag(UniversalColor.success.withOpacity(0.5))
62+
Text("Default").tag(Optional<UniversalColor>.none)
63+
Text("Accent Background").tag(ComponentColor.accent.background)
64+
Text("Success Background").tag(ComponentColor.success.background)
65+
Text("Warning Background").tag(ComponentColor.warning.background)
66+
Text("Danger Background").tag(ComponentColor.danger.background)
6567
}
6668
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
6769
.disabled(self.footer == nil)
@@ -127,6 +129,7 @@ Enim habitant laoreet inceptos scelerisque senectus, tellus molestie ut. Eros ri
127129
private static let footerButtonVM = ButtonVM {
128130
$0.title = "Close"
129131
$0.isFullWidth = true
132+
$0.color = .primary
130133
}
131134
private static let footerCheckboxVM = CheckboxVM {
132135
$0.title = "Agree and continue"

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

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import ComponentsKit
22
import SwiftUI
33

4+
// MARK: - AnimationScalePicker
5+
6+
struct AnimationScalePicker: View {
7+
@Binding var selection: AnimationScale
8+
9+
var body: some View {
10+
Picker("Animation Scale", selection: self.$selection) {
11+
Text("None").tag(AnimationScale.none)
12+
Text("Small").tag(AnimationScale.small)
13+
Text("Medium").tag(AnimationScale.medium)
14+
Text("Large").tag(AnimationScale.large)
15+
Text("Custom: 0.9").tag(AnimationScale.custom(0.9))
16+
}
17+
}
18+
}
19+
420
// MARK: - AutocapitalizationPicker
521

622
struct AutocapitalizationPicker: View {
@@ -24,15 +40,14 @@ struct ComponentColorPicker: View {
2440
var body: some View {
2541
Picker("Color", selection: self.$selection) {
2642
Text("Primary").tag(ComponentColor.primary)
27-
Text("Secondary").tag(ComponentColor.secondary)
2843
Text("Accent").tag(ComponentColor.accent)
2944
Text("Success").tag(ComponentColor.success)
3045
Text("Warning").tag(ComponentColor.warning)
3146
Text("Danger").tag(ComponentColor.danger)
3247
Text("Custom").tag(ComponentColor(
3348
main: .universal(.uiColor(.systemPurple)),
34-
contrast: .universal(.uiColor(.systemYellow)))
35-
)
49+
contrast: .universal(.uiColor(.systemYellow))
50+
))
3651
}
3752
}
3853
}
@@ -46,15 +61,14 @@ struct ComponentOptionalColorPicker: View {
4661
Picker("Color", selection: self.$selection) {
4762
Text("Default").tag(Optional<ComponentColor>.none)
4863
Text("Primary").tag(ComponentColor.primary)
49-
Text("Secondary").tag(ComponentColor.secondary)
5064
Text("Accent").tag(ComponentColor.accent)
5165
Text("Success").tag(ComponentColor.success)
5266
Text("Warning").tag(ComponentColor.warning)
5367
Text("Danger").tag(ComponentColor.danger)
5468
Text("Custom").tag(ComponentColor(
5569
main: .universal(.uiColor(.systemPurple)),
56-
contrast: .universal(.uiColor(.systemYellow)))
57-
)
70+
contrast: .universal(.uiColor(.systemYellow))
71+
))
5872
}
5973
}
6074
}
@@ -77,18 +91,84 @@ struct CornerRadiusPicker<Custom: View>: View {
7791
}
7892
}
7993

80-
// MARK: - FontPicker
94+
// MARK: - FontPickers
8195

82-
struct FontPicker: View {
96+
struct BodyFontPicker: View {
97+
let title: String
8398
@Binding var selection: UniversalFont?
99+
100+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
101+
self.title = title
102+
self._selection = selection
103+
}
84104

85105
var body: some View {
86-
Picker("Font", selection: self.$selection) {
106+
Picker(self.title, selection: self.$selection) {
107+
Text("Default").tag(Optional<UniversalFont>.none)
108+
Text("Small").tag(UniversalFont.smBody)
109+
Text("Medium").tag(UniversalFont.mdBody)
110+
Text("Large").tag(UniversalFont.lgBody)
111+
Text("Custom: system semibold of size 16").tag(UniversalFont.system(size: 16, weight: .semibold))
112+
}
113+
}
114+
}
115+
116+
struct ButtonFontPicker: View {
117+
let title: String
118+
@Binding var selection: UniversalFont?
119+
120+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
121+
self.title = title
122+
self._selection = selection
123+
}
124+
125+
var body: some View {
126+
Picker(self.title, selection: self.$selection) {
127+
Text("Default").tag(Optional<UniversalFont>.none)
128+
Text("Small").tag(UniversalFont.smButton)
129+
Text("Medium").tag(UniversalFont.mdButton)
130+
Text("Large").tag(UniversalFont.lgButton)
131+
Text("Custom: system bold of size 16").tag(UniversalFont.system(size: 16, weight: .bold))
132+
}
133+
}
134+
}
135+
136+
struct HeadlineFontPicker: View {
137+
let title: String
138+
@Binding var selection: UniversalFont?
139+
140+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
141+
self.title = title
142+
self._selection = selection
143+
}
144+
145+
var body: some View {
146+
Picker(self.title, selection: self.$selection) {
147+
Text("Default").tag(Optional<UniversalFont>.none)
148+
Text("Small").tag(UniversalFont.smHeadline)
149+
Text("Medium").tag(UniversalFont.mdHeadline)
150+
Text("Large").tag(UniversalFont.lgHeadline)
151+
Text("Custom: system bold of size 20").tag(UniversalFont.system(size: 20, weight: .bold))
152+
}
153+
}
154+
}
155+
156+
struct CaptionFontPicker: View {
157+
let title: String
158+
@Binding var selection: UniversalFont?
159+
160+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
161+
self.title = title
162+
self._selection = selection
163+
}
164+
165+
var body: some View {
166+
Picker(self.title, selection: self.$selection) {
87167
Text("Default").tag(Optional<UniversalFont>.none)
88-
Text("Small").tag(UniversalFont.Component.small)
89-
Text("Medium").tag(UniversalFont.Component.medium)
90-
Text("Large").tag(UniversalFont.Component.large)
91-
Text("Custom: system bold of size 18").tag(UniversalFont.system(size: 18, weight: .bold))
168+
Text("Small").tag(UniversalFont.smCaption)
169+
Text("Medium").tag(UniversalFont.mdCaption)
170+
Text("Large").tag(UniversalFont.lgCaption)
171+
Text("Custom: system semibold of size 12").tag(UniversalFont.system(size: 12, weight: .semibold))
92172
}
93173
}
94174
}
@@ -157,7 +237,6 @@ struct UniversalColorPicker: View {
157237
var body: some View {
158238
Picker(self.title, selection: self.$selection) {
159239
Text("Primary").tag(UniversalColor.primary)
160-
Text("Secondary").tag(UniversalColor.secondary)
161240
Text("Accent").tag(UniversalColor.accent)
162241
Text("Success").tag(UniversalColor.success)
163242
Text("Warning").tag(UniversalColor.warning)

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewWrapper.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct PreviewWrapper<Content: View>: View {
2121
LinearGradient(
2222
gradient: Gradient(
2323
colors: [
24-
Palette.Brand.blue.color(for: self.colorScheme),
25-
Palette.Brand.purple.color(for: self.colorScheme)
24+
UniversalColor.blue.color(for: self.colorScheme),
25+
UniversalColor.purple.color(for: self.colorScheme),
2626
]
2727
),
2828
startPoint: .topLeading,
@@ -42,3 +42,16 @@ struct PreviewWrapper<Content: View>: View {
4242
.padding(.horizontal)
4343
}
4444
}
45+
46+
// MARK: - Colors
47+
48+
extension UniversalColor {
49+
fileprivate static let blue: Self = .themed(
50+
light: .hex("#3684F8"),
51+
dark: .hex("#0058DB")
52+
)
53+
fileprivate static let purple: Self = .themed(
54+
light: .hex("#A920FD"),
55+
dark: .hex("#7800C1")
56+
)
57+
}

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/UKComponentPreview.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct UKComponentPreview<View, Model>: UIViewRepresentable where View: UKCompon
3838
let model: Model
3939
let view: View
4040

41-
init(model: Model, view: @escaping () -> View) {
42-
self.view = view()
43-
self.model = model
41+
init(view: View) {
42+
self.view = view
43+
self.model = view.model
4444
}
4545

4646
func makeUIView(context: Context) -> Container {
@@ -51,3 +51,9 @@ struct UKComponentPreview<View, Model>: UIViewRepresentable where View: UKCompon
5151
container.component.model = self.model
5252
}
5353
}
54+
55+
extension UKComponent {
56+
var preview: some View {
57+
UKComponentPreview(view: self)
58+
}
59+
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/BottomModalPreview.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ struct BottomModalPreview: View {
1515
var body: some View {
1616
VStack {
1717
PreviewWrapper(title: "UIKit") {
18-
UKComponentPreview(model: .init { $0.title = "Show Modal" }) {
19-
UKButton {
20-
UIApplication.shared.topViewController?.present(
21-
UKBottomModalController(
22-
model: self.model,
23-
header: ModalPreviewHelpers.ukHeader(hasHeader: self.hasHeader),
24-
body: ModalPreviewHelpers.ukBody(body: self.contentBody),
25-
footer: ModalPreviewHelpers.ukFooter(footer: self.contentFooter)
26-
),
27-
animated: true
28-
)
29-
}
18+
UKButton(model: .init { $0.title = "Show Modal" }) {
19+
UIApplication.shared.topViewController?.present(
20+
UKBottomModalController(
21+
model: self.model,
22+
header: ModalPreviewHelpers.ukHeader(hasHeader: self.hasHeader),
23+
body: ModalPreviewHelpers.ukBody(body: self.contentBody),
24+
footer: ModalPreviewHelpers.ukFooter(footer: self.contentFooter)
25+
),
26+
animated: true
27+
)
3028
}
29+
.preview
3130
}
3231
PreviewWrapper(title: "SwiftUI") {
3332
SUButton(model: .init { $0.title = "Show Modal" }) {

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,28 @@ struct ButtonPreview: View {
1010
var body: some View {
1111
VStack {
1212
PreviewWrapper(title: "UIKit") {
13-
UKComponentPreview(model: self.model) {
14-
UKButton(model: self.model)
15-
}
13+
UKButton(model: self.model)
14+
.preview
1615
}
1716
PreviewWrapper(title: "SwiftUI") {
1817
SUButton(model: self.model)
1918
}
2019
Form {
21-
Picker("Animation Scale", selection: self.$model.animationScale) {
22-
Text("None").tag(AnimationScale.none)
23-
Text("Small").tag(AnimationScale.small)
24-
Text("Medium").tag(AnimationScale.medium)
25-
Text("Large").tag(AnimationScale.large)
26-
Text("Custom: 0.9").tag(AnimationScale.custom(0.9))
27-
}
28-
ComponentColorPicker(selection: self.$model.color)
20+
AnimationScalePicker(selection: self.$model.animationScale)
21+
ComponentOptionalColorPicker(selection: self.$model.color)
2922
CornerRadiusPicker(selection: self.$model.cornerRadius) {
3023
Text("Custom: 20px").tag(ComponentRadius.custom(20))
3124
}
32-
FontPicker(selection: self.$model.font)
25+
ButtonFontPicker(selection: self.$model.font)
3326
Toggle("Enabled", isOn: self.$model.isEnabled)
3427
Toggle("Full Width", isOn: self.$model.isFullWidth)
3528
SizePicker(selection: self.$model.size)
3629
Picker("Style", selection: self.$model.style) {
37-
Text("Filled").tag(ButtonStyle.filled)
38-
Text("Plain").tag(ButtonStyle.plain)
39-
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
40-
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
41-
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))
42-
Text("Bordered with custom border: 6px").tag(ButtonStyle.bordered(.custom(6)))
30+
Text("Filled").tag(ButtonVM.Style.filled)
31+
Text("Plain").tag(ButtonVM.Style.plain)
32+
Text("Bordered with small border").tag(ButtonVM.Style.bordered(.small))
33+
Text("Bordered with medium border").tag(ButtonVM.Style.bordered(.medium))
34+
Text("Bordered with large border").tag(ButtonVM.Style.bordered(.large))
4335
}
4436
}
4537
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CenterModalPreview.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ struct CenterModalPreview: View {
1515
var body: some View {
1616
VStack {
1717
PreviewWrapper(title: "UIKit") {
18-
UKComponentPreview(model: .init { $0.title = "Show Modal" }) {
19-
UKButton {
20-
UIApplication.shared.topViewController?.present(
21-
UKCenterModalController(
22-
model: self.model,
23-
header: ModalPreviewHelpers.ukHeader(hasHeader: self.hasHeader),
24-
body: ModalPreviewHelpers.ukBody(body: self.contentBody),
25-
footer: ModalPreviewHelpers.ukFooter(footer: self.contentFooter)
26-
),
27-
animated: true
28-
)
29-
}
18+
UKButton(model: .init { $0.title = "Show Modal" }) {
19+
UIApplication.shared.topViewController?.present(
20+
UKCenterModalController(
21+
model: self.model,
22+
header: ModalPreviewHelpers.ukHeader(hasHeader: self.hasHeader),
23+
body: ModalPreviewHelpers.ukBody(body: self.contentBody),
24+
footer: ModalPreviewHelpers.ukFooter(footer: self.contentFooter)
25+
),
26+
animated: true
27+
)
3028
}
29+
.preview
3130
}
3231
PreviewWrapper(title: "SwiftUI") {
3332
SUButton(model: .init { $0.title = "Show Modal" }) {

0 commit comments

Comments
 (0)