Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit f2d1cfd

Browse files
authored
Merge pull request #862 from kiwicom/861-add-new-inkdark-button-theme
861 add new inkdark button theme
2 parents 89cde2a + 7acaeee commit f2d1cfd

File tree

9 files changed

+75
-56
lines changed

9 files changed

+75
-56
lines changed
Loading
22.9 KB
Loading

Sources/Orbit/Components/Button.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public enum ButtonType {
156156
case secondary
157157
case critical
158158
case criticalSubtle
159+
case prominent
159160
case status(Status?, isSubtle: Bool = false)
160161
}
161162

@@ -307,6 +308,7 @@ struct ButtonPreviews: PreviewProvider {
307308
buttons(.secondary)
308309
buttons(.critical)
309310
buttons(.criticalSubtle)
311+
buttons(.prominent)
310312
}
311313
.padding(.medium)
312314
}

Sources/Orbit/Components/ButtonLink.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public extension ButtonLink where Label == Text, LeadingIcon == Orbit.Icon, Trai
151151
public enum ButtonLinkType: Equatable, Sendable {
152152
case primary
153153
case critical
154+
case prominent
154155
case status(_ status: Status?)
155156
}
156157

@@ -223,10 +224,12 @@ struct ButtonLinkPreviews: PreviewProvider {
223224
VStack(alignment: .leading, spacing: .large) {
224225
ButtonLink("ButtonLink Primary", type: .primary, action: {})
225226
ButtonLink("ButtonLink Critical", type: .critical, action: {})
227+
ButtonLink("ButtonLink Prominent", type: .prominent, action: {})
226228
}
227229
VStack(alignment: .leading, spacing: .large) {
228230
ButtonLink("ButtonLink Primary", icon: .accommodation, type: .primary, action: {})
229231
ButtonLink("ButtonLink Critical", icon: .alertCircle, type: .critical, action: {})
232+
ButtonLink("ButtonLink Prominent", icon: .alertCircle, type: .prominent, action: {})
230233
}
231234
}
232235
.buttonSize(.compact)

Sources/Orbit/Components/Card.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public struct Card<Title: View, Description: View, Content: View, Action: View>:
132132
@ViewBuilder private var topTrailingAction: some View {
133133
action
134134
.buttonSize(.compact)
135+
// Remove any text or background overrides
136+
.environment(\.backgroundShape, nil)
137+
.textColor(nil)
135138
// Prevent the default ButtonLink from vertically expanding the header
136139
.padding(.vertical, -.xSmall)
137140
.accessibility(.cardAction)

Sources/Orbit/Support/ButtonStyles/OrbitButtonLinkButtonStyle.swift

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import SwiftUI
33
/// Button style for Orbit ``ButtonLink`` component.
44
public struct OrbitButtonLinkButtonStyle<LeadingIcon: View, TrailingIcon: View>: PrimitiveButtonStyle {
55

6+
@Environment(\.backgroundShape) private var backgroundShape
67
@Environment(\.buttonSize) private var buttonSize
78
@Environment(\.idealSize) private var idealSize
89
@Environment(\.status) private var status
10+
@Environment(\.textColor) private var textColor
911

1012
private let type: ButtonLinkType
1113
@ViewBuilder private let icon: LeadingIcon
@@ -28,17 +30,18 @@ public struct OrbitButtonLinkButtonStyle<LeadingIcon: View, TrailingIcon: View>:
2830
disclosureIcon
2931
}
3032
.textFontWeight(.medium)
31-
.textColor(textColor)
32-
.backgroundStyle(.clear, active: backgroundActive)
33+
.textColor(textColor ?? labelColor)
34+
.backgroundStyle(backgroundShape?.inactive ?? .clear, active: backgroundShape?.active ?? backgroundActive)
3335
.buttonSize(resolvedButtonSize)
3436
.idealSize(horizontal: idealSizeHorizontal, vertical: idealSize.vertical)
3537
}
3638

3739
private var backgroundActive: Color {
3840
switch type {
39-
case .primary: return .productLightActive
40-
case .critical: return .redLightActive
41-
case .status(let status): return (status ?? self.status)?.lightActiveColor ?? .productLightActive
41+
case .primary: .productLightActive
42+
case .critical: .redLightActive
43+
case .prominent: .cloudLightActive
44+
case .status(let status): (status ?? self.status)?.lightActiveColor ?? .productLightActive
4245
}
4346
}
4447

@@ -52,62 +55,64 @@ public struct OrbitButtonLinkButtonStyle<LeadingIcon: View, TrailingIcon: View>:
5255
: (resolvedButtonSize == .compact || idealSize.horizontal == true)
5356
}
5457

55-
private var textColor: Color {
58+
private var labelColor: Color {
5659
switch type {
57-
case .primary: return .productNormal
58-
case .critical: return .redNormal
59-
case .status(let status): return (status ?? self.status)?.color ?? .productNormal
60+
case .primary: .productNormal
61+
case .critical: .redNormal
62+
case .prominent: .inkDark
63+
case .status(let status): (status ?? self.status)?.color ?? .productNormal
6064
}
6165
}
6266

6367
private var textActiveColor: Color {
6468
switch type {
65-
case .primary: return .productDarkActive
66-
case .critical: return .redDarkActive
67-
case .status(let status): return (status ?? self.status)?.darkHoverColor ?? .productDarkActive
69+
case .primary: .productDarkActive
70+
case .critical: .redDarkActive
71+
case .prominent: .inkDarkActive
72+
case .status(let status): (status ?? self.status)?.darkHoverColor ?? .productDarkActive
6873
}
6974
}
7075

7176
private var resolvedStatus: Status {
7277
switch type {
73-
case .status(let status): return status ?? self.status ?? .info
74-
default: return .info
78+
case .status(let status): status ?? self.status ?? .info
79+
default: .info
7580
}
7681
}
7782

7883
private var hapticFeedback: HapticsProvider.HapticFeedbackType {
7984
switch type {
80-
case .primary: return .light(1)
81-
case .critical: return .notification(.error)
82-
case .status: return resolvedStatus.defaultHapticFeedback
85+
case .primary, .prominent: .light(1)
86+
case .critical: .notification(.error)
87+
case .status: resolvedStatus.defaultHapticFeedback
8388
}
8489
}
8590

8691
private var horizontalPadding: CGFloat {
8792
switch resolvedButtonSize {
88-
case .regular: return .small
89-
case .compact: return 0
93+
case .regular: .small
94+
case .compact: 0
9095
}
9196
}
9297

9398
private var verticalPadding: CGFloat {
9499
switch resolvedButtonSize {
95-
case .regular: return .small // = 44 height @ normal size
96-
case .compact: return 6 // = 32 height @ normal size
100+
case .regular: .small // = 44 height @ normal size
101+
case .compact: 6 // = 32 height @ normal size
97102
}
98103
}
99104

100105
private var horizontalBackgroundPadding: CGFloat {
101106
switch resolvedButtonSize {
102-
case .regular: return 0
103-
case .compact: return .xSmall
107+
case .regular: 0
108+
case .compact: .xSmall
104109
}
105110
}
106111

107112
private var verticalBackgroundPadding: CGFloat {
108113
switch resolvedButtonSize {
109-
case .regular: return 0
110-
case .compact: return .xxxSmall
114+
case .regular: 0
115+
case .compact: .xxxSmall
111116
}
112117
}
113118

Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,47 @@ public struct OrbitButtonStyle<LeadingIcon: View, TrailingIcon: View>: Primitive
3333

3434
private var background: Color {
3535
switch type {
36-
case .primary: return .productNormal
37-
case .primarySubtle: return .productLight
38-
case .secondary: return .cloudNormal
39-
case .critical: return .redNormal
40-
case .criticalSubtle: return .redLight
41-
case .status(let status, false): return (status ?? self.status)?.color ?? .productNormal
42-
case .status(let status, true): return (status ?? self.status)?.lightHoverColor ?? .productLight
36+
case .primary: .productNormal
37+
case .primarySubtle: .productLight
38+
case .secondary: .cloudNormal
39+
case .critical: .redNormal
40+
case .criticalSubtle: .redLight
41+
case .prominent: .inkDark
42+
case .status(let status, false): (status ?? self.status)?.color ?? .productNormal
43+
case .status(let status, true): (status ?? self.status)?.lightHoverColor ?? .productLight
4344
}
4445
}
4546

4647
private var backgroundActive: Color {
4748
switch type {
48-
case .primary: return .productNormalActive
49-
case .primarySubtle: return .productLightActive
50-
case .secondary: return .cloudNormalActive
51-
case .critical: return .redNormalActive
52-
case .criticalSubtle: return .redLightActive
53-
case .status(let status, false): return (status ?? self.status)?.activeColor ?? .productNormalActive
54-
case .status(let status, true): return (status ?? self.status)?.lightActiveColor ?? .productLightActive
49+
case .primary: .productNormalActive
50+
case .primarySubtle: .productLightActive
51+
case .secondary: .cloudNormalActive
52+
case .critical: .redNormalActive
53+
case .criticalSubtle: .redLightActive
54+
case .prominent: .inkDarkActive
55+
case .status(let status, false): (status ?? self.status)?.activeColor ?? .productNormalActive
56+
case .status(let status, true): (status ?? self.status)?.lightActiveColor ?? .productLightActive
5557
}
5658
}
5759

5860
private var labelColor: Color {
5961
switch type {
60-
case .primary: return .whiteNormal
61-
case .primarySubtle: return .productDark
62-
case .secondary: return .inkDark
63-
case .critical: return .whiteNormal
64-
case .criticalSubtle: return .redDark
65-
case .status(_, false): return .whiteNormal
66-
case .status(let status, true): return (status ?? self.status)?.darkHoverColor ?? .whiteNormal
62+
case .primary: .whiteNormal
63+
case .primarySubtle: .productDark
64+
case .secondary: .inkDark
65+
case .critical: .whiteNormal
66+
case .criticalSubtle: .redDark
67+
case .prominent: .whiteNormal
68+
case .status(_, false): .whiteNormal
69+
case .status(let status, true): (status ?? self.status)?.darkHoverColor ?? .whiteNormal
6770
}
6871
}
6972

7073
private var resolvedStatus: Status {
7174
switch type {
72-
case .status(let status, _): return status ?? self.status ?? .info
73-
default: return .info
75+
case .status(let status, _): status ?? self.status ?? .info
76+
default: .info
7477
}
7578
}
7679

@@ -80,24 +83,24 @@ public struct OrbitButtonStyle<LeadingIcon: View, TrailingIcon: View>: Primitive
8083

8184
private var hapticFeedback: HapticsProvider.HapticFeedbackType {
8285
switch type {
83-
case .primary: return .light(1)
84-
case .primarySubtle, .secondary: return .light(0.5)
85-
case .critical, .criticalSubtle: return .notification(.error)
86-
case .status: return resolvedStatus.defaultHapticFeedback
86+
case .primary, .prominent: .light(1)
87+
case .primarySubtle, .secondary: .light(0.5)
88+
case .critical, .criticalSubtle: .notification(.error)
89+
case .status: resolvedStatus.defaultHapticFeedback
8790
}
8891
}
8992

9093
private var textSize: Text.Size {
9194
switch resolvedButtonSize {
92-
case .regular: return .normal
93-
case .compact: return .small
95+
case .regular: .normal
96+
case .compact: .small
9497
}
9598
}
9699

97100
private var padding: CGFloat {
98101
switch resolvedButtonSize {
99-
case .regular: return .small // = 44 height @ normal size
100-
case .compact: return .xSmall // = 32 height @ normal size
102+
case .regular: .small // = 44 height @ normal size
103+
case .compact: .xSmall // = 32 height @ normal size
101104
}
102105
}
103106

Sources/OrbitStorybook/Detail/Items/StorybookButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct StorybookButton {
1010
buttons(.secondary)
1111
buttons(.critical)
1212
buttons(.criticalSubtle)
13+
buttons(.prominent)
1314
}
1415
.previewDisplayName()
1516
}

Sources/OrbitStorybook/Detail/Items/StorybookButtonLink.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ struct StorybookButtonLink {
88
VStack(alignment: .leading, spacing: .large) {
99
ButtonLink("ButtonLink Primary", type: .primary, action: {})
1010
ButtonLink("ButtonLink Critical", type: .critical, action: {})
11+
ButtonLink("ButtonLink Prominent", type: .prominent, action: {})
1112
}
1213
VStack(alignment: .leading, spacing: .large) {
1314
ButtonLink("ButtonLink Primary", icon: .accommodation, type: .primary, action: {})
1415
ButtonLink("ButtonLink Critical", icon: .alertCircle, type: .critical, action: {})
16+
ButtonLink("ButtonLink Prominent", icon: .alertCircle, type: .prominent, action: {})
1517
}
1618
}
1719
.buttonSize(.compact)

0 commit comments

Comments
 (0)