Skip to content

Commit 55444b6

Browse files
refactor: update colors in the Palette
1 parent 1d9d3f3 commit 55444b6

File tree

20 files changed

+242
-222
lines changed

20 files changed

+242
-222
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ struct ComponentColorPicker: View {
4040
var body: some View {
4141
Picker("Color", selection: self.$selection) {
4242
Text("Primary").tag(ComponentColor.primary)
43-
Text("Secondary").tag(ComponentColor.secondary)
4443
Text("Accent").tag(ComponentColor.accent)
4544
Text("Success").tag(ComponentColor.success)
4645
Text("Warning").tag(ComponentColor.warning)
4746
Text("Danger").tag(ComponentColor.danger)
4847
Text("Custom").tag(ComponentColor(
4948
main: .universal(.uiColor(.systemPurple)),
50-
contrast: .universal(.uiColor(.systemYellow)))
51-
)
49+
contrast: .universal(.uiColor(.systemYellow))
50+
))
5251
}
5352
}
5453
}
@@ -62,15 +61,14 @@ struct ComponentOptionalColorPicker: View {
6261
Picker("Color", selection: self.$selection) {
6362
Text("Default").tag(Optional<ComponentColor>.none)
6463
Text("Primary").tag(ComponentColor.primary)
65-
Text("Secondary").tag(ComponentColor.secondary)
6664
Text("Accent").tag(ComponentColor.accent)
6765
Text("Success").tag(ComponentColor.success)
6866
Text("Warning").tag(ComponentColor.warning)
6967
Text("Danger").tag(ComponentColor.danger)
7068
Text("Custom").tag(ComponentColor(
7169
main: .universal(.uiColor(.systemPurple)),
72-
contrast: .universal(.uiColor(.systemYellow)))
73-
)
70+
contrast: .universal(.uiColor(.systemYellow))
71+
))
7472
}
7573
}
7674
}
@@ -173,7 +171,6 @@ struct UniversalColorPicker: View {
173171
var body: some View {
174172
Picker(self.title, selection: self.$selection) {
175173
Text("Primary").tag(UniversalColor.primary)
176-
Text("Secondary").tag(UniversalColor.secondary)
177174
Text("Accent").tag(UniversalColor.accent)
178175
Text("Success").tag(UniversalColor.success)
179176
Text("Warning").tag(UniversalColor.warning)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ButtonPreview: View {
1818
}
1919
Form {
2020
AnimationScalePicker(selection: self.$model.animationScale)
21-
ComponentColorPicker(selection: self.$model.color)
21+
ComponentOptionalColorPicker(selection: self.$model.color)
2222
CornerRadiusPicker(selection: self.$model.cornerRadius) {
2323
Text("Custom: 20px").tag(ComponentRadius.custom(20))
2424
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/DividerPreview.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ struct DividerPreview: View {
1515
SUDivider(model: self.model)
1616
}
1717
Form {
18+
Picker("Color", selection: self.$model.color) {
19+
Text("Default").tag(Optional<ComponentColor>.none)
20+
Text("Primary").tag(ComponentColor.primary)
21+
Text("Accent").tag(ComponentColor.accent)
22+
Text("Success").tag(ComponentColor.success)
23+
Text("Warning").tag(ComponentColor.warning)
24+
Text("Danger").tag(ComponentColor.danger)
25+
Text("Custom").tag(ComponentColor(
26+
main: .universal(.uiColor(.systemPurple)),
27+
contrast: .universal(.uiColor(.systemYellow))
28+
))
29+
}
1830
Picker("Orientation", selection: self.$model.orientation) {
1931
Text("Horizontal").tag(DividerVM.Orientation.horizontal)
2032
Text("Vertical").tag(DividerVM.Orientation.vertical)
2133
}
2234
SizePicker(selection: self.$model.size)
23-
Picker("Color", selection: self.$model.color) {
24-
Text("Default").tag(Palette.Base.divider)
25-
Text("Primary").tag(UniversalColor.primary)
26-
Text("Secondary").tag(UniversalColor.secondary)
27-
Text("Accent").tag(UniversalColor.accent)
28-
Text("Success").tag(UniversalColor.success)
29-
Text("Warning").tag(UniversalColor.warning)
30-
Text("Danger").tag(UniversalColor.danger)
31-
Text("Custom").tag(UniversalColor.universal(.uiColor(.systemPurple)))
32-
}
3335
}
3436
}
3537
}

Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct SwiftUILogin: View {
3838

3939
var body: some View {
4040
ZStack {
41-
Palette.Base.background.color(for: self.colorScheme)
41+
UniversalColor.background.color(for: self.colorScheme)
4242

4343
ScrollView {
4444
VStack(spacing: 20) {

Examples/DemosApp/DemosApp/Demos/Login/UIKitLogin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ final class UIKitLogin: UIViewController {
157157
}
158158

159159
private func style() {
160-
self.scrollView.backgroundColor = Palette.Base.background.uiColor
160+
self.scrollView.backgroundColor = UniversalColor.background.uiColor
161161

162162
self.stackView.setCustomSpacing(50, after: self.pageControl)
163163
self.stackView.setCustomSpacing(50, after: self.titleLabel)

Sources/ComponentsKit/Button/Models/ButtonVM.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ public struct ButtonVM: ComponentVM {
1111
public var animationScale: AnimationScale = .medium
1212

1313
/// The color of the button.
14-
///
15-
/// Defaults to `.primary`.
16-
public var color: ComponentColor = .primary
14+
public var color: ComponentColor?
1715

1816
/// The corner radius of the button.
1917
///
@@ -53,18 +51,12 @@ public struct ButtonVM: ComponentVM {
5351

5452
extension ButtonVM {
5553
private var mainColor: UniversalColor {
56-
return self.isEnabled
57-
? self.color.main
58-
: self.color.main.withOpacity(
59-
ComponentsKitConfig.shared.layout.disabledOpacity
60-
)
54+
let color = self.color?.main ?? .content2
55+
return color.enabled(self.isEnabled)
6156
}
6257
private var contrastColor: UniversalColor {
63-
return self.isEnabled
64-
? self.color.contrast
65-
: self.color.contrast.withOpacity(
66-
ComponentsKitConfig.shared.layout.disabledOpacity
67-
)
58+
let color = self.color?.contrast ?? .foreground
59+
return color.enabled(self.isEnabled)
6860
}
6961
var backgroundColor: UniversalColor? {
7062
switch self.style {
@@ -81,7 +73,8 @@ extension ButtonVM {
8173
case .plain:
8274
return self.mainColor
8375
case .bordered:
84-
return self.mainColor
76+
let color = self.color?.main ?? .foreground
77+
return color.enabled(self.isEnabled)
8578
}
8679
}
8780
var borderWidth: CGFloat {
@@ -97,7 +90,11 @@ extension ButtonVM {
9790
case .filled, .plain:
9891
return nil
9992
case .bordered:
100-
return self.mainColor
93+
if let color {
94+
return color.main.enabled(self.isEnabled)
95+
} else {
96+
return .divider
97+
}
10198
}
10299
}
103100
var preferredFont: UniversalFont {

Sources/ComponentsKit/Checkbox/Models/CheckboxVM.swift

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,16 @@ public struct CheckboxVM: ComponentVM {
3838

3939
extension CheckboxVM {
4040
var backgroundColor: UniversalColor {
41-
return self.color.main.withOpacity(
42-
self.isEnabled
43-
? 1.0
44-
: ComponentsKitConfig.shared.layout.disabledOpacity
45-
)
41+
return self.color.main.enabled(self.isEnabled)
4642
}
4743
var foregroundColor: UniversalColor {
48-
return self.color.contrast.withOpacity(
49-
self.isEnabled
50-
? 1.0
51-
: ComponentsKitConfig.shared.layout.disabledOpacity
52-
)
44+
return self.color.contrast.enabled(self.isEnabled)
5345
}
5446
var titleColor: UniversalColor {
55-
return Palette.Text.primary.withOpacity(
56-
self.isEnabled
57-
? 1.0
58-
: ComponentsKitConfig.shared.layout.disabledOpacity
59-
)
47+
return .foreground.enabled(self.isEnabled)
6048
}
6149
var borderColor: UniversalColor {
62-
return .universal(.uiColor(.lightGray)).withOpacity(
63-
self.isEnabled
64-
? 1.0
65-
: ComponentsKitConfig.shared.layout.disabledOpacity
66-
)
50+
return .divider
6751
}
6852
var borderWidth: CGFloat {
6953
return 2.0

Sources/ComponentsKit/Checkbox/UKCheckbox.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ open class UKCheckbox: UIView, UKComponent {
262262
self.checkboxContainer.layer.borderColor = self.isSelected
263263
? UIColor.clear.cgColor
264264
: self.model.borderColor.uiColor.cgColor
265+
Self.Style.checkmarkLayer(self.checkmarkLayer, model: self.model)
265266
}
266267
}
267268

@@ -275,7 +276,7 @@ extension UKCheckbox {
275276
stackView.alignment = .center
276277
}
277278
static func titleLabel(_ label: UILabel, model: Model) {
278-
label.textColor = Palette.Text.primary.uiColor
279+
label.textColor = model.titleColor.uiColor
279280
label.numberOfLines = 0
280281
label.text = model.title
281282
label.textColor = model.titleColor.uiColor

0 commit comments

Comments
 (0)