Skip to content

Commit 9d5e14d

Browse files
add borderColor param to CardVM
1 parent 0e99fb5 commit 9d5e14d

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ struct CardPreview: View {
1616
}
1717
Form {
1818
Picker("Background Color", selection: self.$model.backgroundColor) {
19-
Text("Default").tag(Optional<UniversalColor>.none)
19+
Text("Background").tag(UniversalColor.background)
2020
Text("Secondary Background").tag(UniversalColor.secondaryBackground)
2121
Text("Accent Background").tag(UniversalColor.accentBackground)
2222
Text("Success Background").tag(UniversalColor.successBackground)
2323
Text("Warning Background").tag(UniversalColor.warningBackground)
2424
Text("Danger Background").tag(UniversalColor.dangerBackground)
2525
}
26+
Picker("Border Color", selection: self.$model.borderColor) {
27+
Text("Divider").tag(UniversalColor.divider)
28+
Text("Primary").tag(UniversalColor.primary)
29+
Text("Accent").tag(UniversalColor.accent)
30+
Text("Success").tag(UniversalColor.success)
31+
Text("Warning").tag(UniversalColor.warning)
32+
Text("Danger").tag(UniversalColor.danger)
33+
Text("Custom").tag(UniversalColor.universal(.uiColor(.systemPurple)))
34+
}
2635
BorderWidthPicker(selection: self.$model.borderWidth)
2736
Picker("Content Paddings", selection: self.$model.contentPaddings) {
2837
Text("12px").tag(Paddings(padding: 12))

Sources/ComponentsKit/Components/Card/Models/CardVM.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import Foundation
33
/// A model that defines the appearance properties for a card component.
44
public struct CardVM: ComponentVM {
55
/// The background color of the card.
6-
public var backgroundColor: UniversalColor?
6+
public var backgroundColor: UniversalColor = .background
7+
8+
/// The border color of the card.
9+
public var borderColor: UniversalColor = .divider
710

811
/// The border thickness of the card.
912
///
@@ -28,11 +31,3 @@ public struct CardVM: ComponentVM {
2831
/// Initializes a new instance of `CardVM` with default values.
2932
public init() {}
3033
}
31-
32-
// MARK: - Helpers
33-
34-
extension CardVM {
35-
var preferredBackgroundColor: UniversalColor {
36-
return self.backgroundColor ?? .background
37-
}
38-
}

Sources/ComponentsKit/Components/Card/SUCard.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ public struct SUCard<Content: View>: View {
3939
public var body: some View {
4040
self.content()
4141
.padding(self.model.contentPaddings.edgeInsets)
42-
.background(self.model.preferredBackgroundColor.color)
42+
.background(self.model.backgroundColor.color)
4343
.cornerRadius(self.model.cornerRadius.value)
4444
.overlay(
4545
RoundedRectangle(cornerRadius: self.model.cornerRadius.value)
46-
.stroke(UniversalColor.divider.color, lineWidth: self.model.borderWidth.value)
46+
.stroke(
47+
self.model.borderColor.color,
48+
lineWidth: self.model.borderWidth.value
49+
)
4750
)
4851
.shadow(self.model.shadow)
4952
}

Sources/ComponentsKit/Components/Card/UKCard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
130130
extension UKCard {
131131
fileprivate enum Style {
132132
static func mainView(_ view: UIView, model: Model) {
133-
view.backgroundColor = model.preferredBackgroundColor.uiColor
133+
view.backgroundColor = model.backgroundColor.uiColor
134134
view.layer.cornerRadius = model.cornerRadius.value
135135
view.layer.borderWidth = model.borderWidth.value
136-
view.layer.borderColor = UniversalColor.divider.cgColor
136+
view.layer.borderColor = model.borderColor.cgColor
137137
view.shadow(model.shadow)
138138
}
139139
}

0 commit comments

Comments
 (0)