Skip to content

Commit 8f12cc8

Browse files
Merge pull request #37 from componentskit/button/light-style
New button style: `light`
2 parents 96c8a70 + bf0773e commit 8f12cc8

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ButtonPreview: View {
2929
Picker("Style", selection: self.$model.style) {
3030
Text("Filled").tag(ButtonVM.Style.filled)
3131
Text("Plain").tag(ButtonVM.Style.plain)
32+
Text("Light").tag(ButtonVM.Style.light)
3233
Text("Bordered with small border").tag(ButtonVM.Style.bordered(.small))
3334
Text("Bordered with medium border").tag(ButtonVM.Style.bordered(.medium))
3435
Text("Bordered with large border").tag(ButtonVM.Style.bordered(.large))

Sources/ComponentsKit/Components/Button/Models/ButtonStyle.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extension ButtonVM {
77
case filled
88
/// A button with a transparent background.
99
case plain
10+
/// A button with a partially transparent background.
11+
case light
1012
/// A button with a transparent background and a border.
1113
case bordered(BorderWidth)
1214
}

Sources/ComponentsKit/Components/Button/Models/ButtonVM.swift

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,44 +50,38 @@ public struct ButtonVM: ComponentVM {
5050
// MARK: Shared Helpers
5151

5252
extension ButtonVM {
53-
private var mainColor: UniversalColor {
54-
let color = self.color?.main ?? .content2
55-
return color.enabled(self.isEnabled)
56-
}
57-
private var contrastColor: UniversalColor {
58-
let color = self.color?.contrast ?? .foreground
59-
return color.enabled(self.isEnabled)
60-
}
6153
var backgroundColor: UniversalColor? {
6254
switch self.style {
6355
case .filled:
64-
return self.mainColor
56+
let color = self.color?.main ?? .content2
57+
return color.enabled(self.isEnabled)
58+
case .light:
59+
let color = self.color?.background ?? .content1
60+
return color.enabled(self.isEnabled)
6561
case .plain, .bordered:
6662
return nil
6763
}
6864
}
6965
var foregroundColor: UniversalColor {
70-
switch self.style {
66+
let color = switch self.style {
7167
case .filled:
72-
return self.contrastColor
73-
case .plain:
74-
return self.mainColor
75-
case .bordered:
76-
let color = self.color?.main ?? .foreground
77-
return color.enabled(self.isEnabled)
68+
self.color?.contrast ?? .foreground
69+
case .plain, .light, .bordered:
70+
self.color?.main ?? .foreground
7871
}
72+
return color.enabled(self.isEnabled)
7973
}
8074
var borderWidth: CGFloat {
8175
switch self.style {
82-
case .filled, .plain:
76+
case .filled, .plain, .light:
8377
return 0.0
8478
case .bordered(let borderWidth):
8579
return borderWidth.value
8680
}
8781
}
8882
var borderColor: UniversalColor? {
8983
switch self.style {
90-
case .filled, .plain:
84+
case .filled, .plain, .light:
9185
return nil
9286
case .bordered:
9387
if let color {

0 commit comments

Comments
 (0)