Skip to content

Commit b30e434

Browse files
Merge pull request #61 from componentskit/dev
v1.4.0
2 parents 4c06c46 + 3446130 commit b30e434

Some content is hidden

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

49 files changed

+2514
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "avatar.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "avatar_placeholder.svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct AvatarGroupPreview: View {
6+
@State private var model = AvatarGroupVM {
7+
$0.items = [
8+
.init {
9+
$0.imageSrc = .remote(URL(string: "https://i.pravatar.cc/150?img=12")!)
10+
},
11+
.init {
12+
$0.imageSrc = .remote(URL(string: "https://i.pravatar.cc/150?img=14")!)
13+
},
14+
.init {
15+
$0.imageSrc = .remote(URL(string: "https://i.pravatar.cc/150?img=15")!)
16+
},
17+
.init(),
18+
.init(),
19+
.init {
20+
$0.placeholder = .text("IM")
21+
},
22+
.init {
23+
$0.placeholder = .sfSymbol("person.circle")
24+
},
25+
]
26+
}
27+
28+
var body: some View {
29+
VStack {
30+
PreviewWrapper(title: "UIKit") {
31+
UKAvatarGroup(model: self.model)
32+
.preview
33+
}
34+
PreviewWrapper(title: "SwiftUI") {
35+
SUAvatarGroup(model: self.model)
36+
}
37+
Form {
38+
Picker("Border Color", selection: self.$model.borderColor) {
39+
Text("Background").tag(UniversalColor.background)
40+
Text("Accent Background").tag(ComponentColor.accent.background)
41+
Text("Success Background").tag(ComponentColor.success.background)
42+
Text("Warning Background").tag(ComponentColor.warning.background)
43+
Text("Danger Background").tag(ComponentColor.danger.background)
44+
}
45+
ComponentOptionalColorPicker(selection: self.$model.color)
46+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
47+
Text("Custom: 4px").tag(ComponentRadius.custom(4))
48+
}
49+
Picker("Max Visible Avatars", selection: self.$model.maxVisibleAvatars) {
50+
Text("3").tag(3)
51+
Text("5").tag(5)
52+
Text("7").tag(7)
53+
}
54+
SizePicker(selection: self.$model.size)
55+
}
56+
}
57+
}
58+
}
59+
60+
#Preview {
61+
AvatarGroupPreview()
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct AvatarPreview: View {
6+
@State private var model = AvatarVM {
7+
$0.placeholder = .icon("avatar_placeholder")
8+
}
9+
10+
var body: some View {
11+
VStack {
12+
PreviewWrapper(title: "UIKit") {
13+
UKAvatar(model: self.model)
14+
.preview
15+
}
16+
PreviewWrapper(title: "SwiftUI") {
17+
SUAvatar(model: self.model)
18+
}
19+
Form {
20+
ComponentOptionalColorPicker(selection: self.$model.color)
21+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
22+
Text("Custom: 4px").tag(ComponentRadius.custom(4))
23+
}
24+
Picker("Image Source", selection: self.$model.imageSrc) {
25+
Text("Remote").tag(AvatarVM.ImageSource.remote(URL(string: "https://i.pravatar.cc/150?img=12")!))
26+
Text("Local").tag(AvatarVM.ImageSource.local("avatar_image"))
27+
Text("None").tag(Optional<AvatarVM.ImageSource>.none)
28+
}
29+
Picker("Placeholder", selection: self.$model.placeholder) {
30+
Text("Text").tag(AvatarVM.Placeholder.text("IM"))
31+
Text("SF Symbol").tag(AvatarVM.Placeholder.sfSymbol("person"))
32+
Text("Icon").tag(AvatarVM.Placeholder.icon("avatar_placeholder"))
33+
}
34+
SizePicker(selection: self.$model.size)
35+
}
36+
}
37+
}
38+
}
39+
40+
#Preview {
41+
AvatarPreview()
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct BadgePreview: View {
6+
@State private var model = BadgeVM {
7+
$0.title = "Badge"
8+
}
9+
10+
var body: some View {
11+
VStack {
12+
PreviewWrapper(title: "UIKit") {
13+
UKBadge(model: self.model)
14+
.preview
15+
}
16+
PreviewWrapper(title: "SwiftUI") {
17+
SUBadge(model: self.model)
18+
}
19+
Form {
20+
Picker("Font", selection: self.$model.font) {
21+
Text("Default").tag(Optional<UniversalFont>.none)
22+
Text("Small").tag(UniversalFont.smButton)
23+
Text("Medium").tag(UniversalFont.mdButton)
24+
Text("Large").tag(UniversalFont.lgButton)
25+
Text("Custom: system bold of size 16").tag(UniversalFont.system(size: 16, weight: .bold))
26+
}
27+
ComponentOptionalColorPicker(selection: self.$model.color)
28+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
29+
Text("Custom: 4px").tag(ComponentRadius.custom(4))
30+
}
31+
Picker("Style", selection: self.$model.style) {
32+
Text("Filled").tag(BadgeVM.Style.filled)
33+
Text("Light").tag(BadgeVM.Style.light)
34+
}
35+
Picker("Paddings", selection: self.$model.paddings) {
36+
Text("8px; 6px")
37+
.tag(Paddings(top: 6, leading: 8, bottom: 6, trailing: 8))
38+
Text("10px; 8px")
39+
.tag(Paddings(top: 8, leading: 10, bottom: 8, trailing: 10))
40+
Text("12px; 10px")
41+
.tag(Paddings(top: 10, leading: 12, bottom: 10, trailing: 12))
42+
}
43+
}
44+
}
45+
}
46+
}
47+
48+
#Preview {
49+
BadgePreview()
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct ProgressBarPreview: View {
6+
@State private var model = Self.initialModel
7+
@State private var currentValue: CGFloat = Self.initialValue
8+
9+
private let progressBar = UKProgressBar(initialValue: Self.initialValue, model: Self.initialModel)
10+
11+
private let timer = Timer
12+
.publish(every: 0.1, on: .main, in: .common)
13+
.autoconnect()
14+
15+
var body: some View {
16+
VStack {
17+
PreviewWrapper(title: "UIKit") {
18+
self.progressBar
19+
.preview
20+
.onAppear {
21+
self.progressBar.currentValue = self.currentValue
22+
self.progressBar.model = Self.initialModel
23+
}
24+
.onChange(of: self.model) { newValue in
25+
self.progressBar.model = newValue
26+
}
27+
}
28+
PreviewWrapper(title: "SwiftUI") {
29+
SUProgressBar(currentValue: self.$currentValue, model: self.model)
30+
}
31+
Form {
32+
ComponentColorPicker(selection: self.$model.color)
33+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
34+
Text("Custom: 2px").tag(ComponentRadius.custom(2))
35+
}
36+
SizePicker(selection: self.$model.size)
37+
Picker("Style", selection: self.$model.style) {
38+
Text("Light").tag(ProgressBarVM.Style.light)
39+
Text("Filled").tag(ProgressBarVM.Style.filled)
40+
Text("Striped").tag(ProgressBarVM.Style.striped)
41+
}
42+
}
43+
}
44+
.onReceive(self.timer) { _ in
45+
if self.currentValue < self.model.maxValue {
46+
self.currentValue += (self.model.maxValue - self.model.minValue) / 100
47+
} else {
48+
self.currentValue = self.model.minValue
49+
}
50+
51+
self.progressBar.currentValue = self.currentValue
52+
}
53+
}
54+
55+
// MARK: - Helpers
56+
57+
private static var initialValue: Double {
58+
return 0.0
59+
}
60+
private static var initialModel: ProgressBarVM {
61+
return .init()
62+
}
63+
}
64+
65+
#Preview {
66+
ProgressBarPreview()
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import SwiftUI
2+
import ComponentsKit
3+
4+
struct SliderPreview: View {
5+
@State private var model = SliderVM {
6+
$0.style = .light
7+
$0.minValue = 0
8+
$0.maxValue = 100
9+
$0.cornerRadius = .full
10+
}
11+
@State private var currentValue: CGFloat = 30
12+
13+
var body: some View {
14+
VStack {
15+
PreviewWrapper(title: "UIKit") {
16+
UKSlider(initialValue: self.currentValue, model: self.model)
17+
.preview
18+
}
19+
PreviewWrapper(title: "SwiftUI") {
20+
SUSlider(currentValue: self.$currentValue, model: self.model)
21+
}
22+
Form {
23+
ComponentColorPicker(selection: self.$model.color)
24+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
25+
Text("Custom: 2px").tag(ComponentRadius.custom(2))
26+
}
27+
SizePicker(selection: self.$model.size)
28+
Picker("Step", selection: self.$model.step) {
29+
Text("1").tag(CGFloat(1))
30+
Text("5").tag(CGFloat(5))
31+
Text("10").tag(CGFloat(10))
32+
Text("25").tag(CGFloat(25))
33+
Text("50").tag(CGFloat(50))
34+
}
35+
Picker("Style", selection: self.$model.style) {
36+
Text("Light").tag(SliderVM.Style.light)
37+
Text("Striped").tag(SliderVM.Style.striped)
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
#Preview {
45+
SliderPreview()
46+
}

Examples/DemosApp/DemosApp/Core/App.swift

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ struct App: View {
88
NavigationLinkWithTitle("Alert") {
99
AlertPreview()
1010
}
11+
NavigationLinkWithTitle("Avatar") {
12+
AvatarPreview()
13+
}
14+
NavigationLinkWithTitle("Avatar Group") {
15+
AvatarGroupPreview()
16+
}
17+
NavigationLinkWithTitle("Badge") {
18+
BadgePreview()
19+
}
1120
NavigationLinkWithTitle("Button") {
1221
ButtonPreview()
1322
}
@@ -29,6 +38,9 @@ struct App: View {
2938
NavigationLinkWithTitle("Loading") {
3039
LoadingPreview()
3140
}
41+
NavigationLinkWithTitle("Progress Bar") {
42+
ProgressBarPreview()
43+
}
3244
NavigationLinkWithTitle("Modal (Bottom)") {
3345
BottomModalPreview()
3446
}
@@ -41,6 +53,9 @@ struct App: View {
4153
NavigationLinkWithTitle("Segmented Control") {
4254
SegmentedControlPreview()
4355
}
56+
NavigationLinkWithTitle("Slider") {
57+
SliderPreview()
58+
}
4459
NavigationLinkWithTitle("Text Input") {
4560
TextInputPreviewPreview()
4661
}

Sources/ComponentsKit/Components/Alert/Helpers/AlertButtonsOrientationCalculator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ struct AlertButtonsOrientationCalculator {
66
case horizontal
77
}
88

9-
private static let primaryButton = UKButton()
10-
private static let secondaryButton = UKButton()
9+
private static let primaryButton = UKButton(model: .init())
10+
private static let secondaryButton = UKButton(model: .init())
1111

1212
private init() {}
1313

0 commit comments

Comments
 (0)