Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KOA-5475 Badges semantic color #1425

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Backpack-SwiftUI/Badge/Classes/BPKBadge+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,38 @@
internal extension BPKBadge.Style {
var backgroundColor: BPKColor {
switch self {
case .normal:
return .skyGrayTint07.darkVariant(.blackTint02)
case .strong:
return .skyGray.darkVariant(.white)
case .success:
return .glencoe
return BPKColor.statusSuccessFillColor
case .warning:
return .erfoud
return BPKColor.statusWarningFillColor
case .destructive:
return .panjin
return BPKColor.statusDangerFillColor
case .inverse:
return .white
return BPKColor.surfaceDefaultColor
case .outline:
return .clear
return BPKColor.white.withAlphaComponent(0)
case .normal:
return BPKColor.surfaceHighlightColor
case .strong:
return BPKColor.corePrimaryColor
}
}

var foregroundColor: BPKColor {
switch self {
case .normal:
return .textPrimaryColor
case .strong:
return .white.darkVariant(.skyGray)
case .destructive, .outline:
return .white
default:
return .skyGray
case .success, .warning, .destructive:
return BPKColor.textOnLightColor
case .outline, .strong:
return BPKColor.textOnDarkColor
case .normal, .inverse:
return BPKColor.textPrimaryColor
}
}

var borderColor: BPKColor? {
switch self {
case .outline:
return .white
return BPKColor.textOnDarkColor
default:
return nil
}
Expand Down
26 changes: 25 additions & 1 deletion Backpack-SwiftUI/Badge/Classes/BPKBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ fileprivate extension View {

struct BPKBadge_Previews: PreviewProvider {
static var previews: some View {
BPKBadge("Success", icon: .return)
let styles: [(BPKBadge.Style, String, BPKIcon, Bool)] = [
(.normal, "Normal", .tickCircle, false),
(.strong, "Strong", .tickCircle, false),
(.success, "Success", .tickCircle, false),
(.warning, "Warning", .helpCircle, false),
(.destructive, "Critical", .exclamation, false),
(.inverse, "Inverse", .tickCircle, true),
(.outline, "Outline", .tickCircle, true)
]
return Group {
ForEach([ColorScheme.light, ColorScheme.dark], id: \.self) { scheme in
VStack(alignment: .leading, spacing: 0) {
ForEach(styles, id: \.0) { style in
BPKBadge(style.1, icon: style.2)
.badgeStyle(style.0)
.padding(10)
.background(style.3 ? BPKColor.surfaceHighlightColor : BPKColor.surfaceDefaultColor)

}

}
.previewLayout(.sizeThatFits)
.preferredColorScheme(scheme)
}
}
}
}
38 changes: 18 additions & 20 deletions Backpack-SwiftUI/Tests/Badge/BPKBadgeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,30 @@ import SwiftUI

class BPKBadgeTests: XCTestCase {

let styles: [BPKBadge.Style] = [
.normal,
.strong,
.success,
.warning,
.destructive,
.inverse,
.outline
let styles: [(BPKBadge.Style, BPKColor)] = [
(.normal, .surfaceDefaultColor),
(.strong, .surfaceDefaultColor),
(.success, .surfaceDefaultColor),
(.warning, .surfaceDefaultColor),
(.destructive, .surfaceDefaultColor),
(.inverse, .surfaceHighlightColor),
(.outline, .surfaceHighlightColor)
]

private func testView(icon: BPKIcon? = nil) -> some View {
ZStack {
Color(.skyGrayTint06.darkVariant(.black))
VStack {
ForEach(styles, id: \.self) {
BPKBadge("Test badge", icon: icon)
.badgeStyle($0)
}
VStack(spacing: 0) {
ForEach(styles, id: \.0) {
BPKBadge("Test badge", icon: icon)
.badgeStyle($0.0)
.padding(4)
.background($0.1)
}
.padding()
}
}
func test_allBadgesWithoutIcon() {
// Then
assertSnapshot(testView())

func test_allBadgesWithoutIcon() {
// Then
assertSnapshot(testView())
}

func test_allBadgesWithIcon() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 14 additions & 21 deletions Backpack/Badge/Classes/Badge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class BPKBadge: UIView {
label.textColor = type.textColor

if type == .outline {
layer.borderColor = BPKColor.white.cgColor
layer.borderColor = BPKColor.textOnDarkColor.cgColor
layer.borderWidth = BPKBorderWidthSm
}

Expand Down Expand Up @@ -127,47 +127,40 @@ public class BPKBadge: UIView {
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
updateLookAndFeel()
}

func changeContent(color: UIColor) {
guard type == .outline else { return }
backgroundColor = BPKColor.clear
layer.borderColor = color.cgColor
label.textColor = color
}
}

fileprivate extension BPKBadgeType {
var textColor: UIColor {
switch self {
case .outline, .destructive:
return BPKColor.white
case .normal:
case .success, .warning, .destructive:
return BPKColor.textOnLightColor
case .outline, .strong:
return BPKColor.textOnDarkColor
case .normal, .inverse:
return BPKColor.textPrimaryColor
case .strong:
return BPKColor.dynamicColor(withLightVariant: BPKColor.white, darkVariant: BPKColor.skyGray)
default:
case .light:
return BPKColor.skyGray
}
}

var backgroundColor: UIColor {
switch self {
case .success:
return BPKColor.glencoe
return BPKColor.statusSuccessFillColor
case .warning:
return BPKColor.erfoud
return BPKColor.statusWarningFillColor
case .destructive:
return BPKColor.panjin
return BPKColor.statusDangerFillColor
case .light:
return BPKColor.skyGrayTint07
case .inverse:
return BPKColor.white
return BPKColor.surfaceDefaultColor
case .outline:
return BPKColor.white.withAlphaComponent(0.2)
return BPKColor.white.withAlphaComponent(0)
case .normal:
return BPKColor.dynamicColor(withLightVariant: BPKColor.skyGrayTint07, darkVariant: BPKColor.blackTint02)
return BPKColor.surfaceHighlightColor
case .strong:
return BPKColor.dynamicColor(withLightVariant: BPKColor.skyGray, darkVariant: BPKColor.white)
return BPKColor.corePrimaryColor
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BPKBadgeSnapshotTest: XCTestCase {
private func createViewWithTypes(andIcon icon: BPKBadge.Icon? = nil) -> UIView {
let stackView = createStackView()
let parentView = UIView(frame: .zero)
parentView.backgroundColor = BPKColor.skyGrayTint06

parentView.translatesAutoresizingMaskIntoConstraints = false
parentView.addSubview(stackView)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-badge___all_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-badge___all_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-button___primaryOnDark_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-button___primaryOnDark_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-button___primaryOnLight_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-button___secondaryOnDark_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-calendar___custom-style_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-calendar___custom-style_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-calendar___with-prices_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-calendar___with-prices_lm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-dialog___delete-confirmation_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/iPhone 8-dialog___delete-confirmation_lm.png
Binary file modified screenshots/iPhone 8-dialog___in-app-messaging_dm.png
Binary file modified screenshots/iPhone 8-dialog___in-app-messaging_lm.png
Binary file modified screenshots/iPhone 8-dialog___no-icon_dm.png
Binary file modified screenshots/iPhone 8-dialog___no-icon_lm.png
Binary file modified screenshots/iPhone 8-dialog___no-title-no-icon_dm.png
Binary file modified screenshots/iPhone 8-dialog___no-title-no-icon_lm.png
Binary file modified screenshots/iPhone 8-dialog___no-title_dm.png
Binary file modified screenshots/iPhone 8-dialog___no-title_lm.png
Binary file modified screenshots/iPhone 8-dialog___success_dm.png
Binary file modified screenshots/iPhone 8-dialog___success_lm.png
Binary file modified screenshots/iPhone 8-dialog___warning_dm.png
Binary file modified screenshots/iPhone 8-dialog___warning_lm.png
Binary file modified screenshots/iPhone 8-dialog___with-cta_dm.png
Binary file modified screenshots/iPhone 8-dialog___with-cta_lm.png
Binary file modified screenshots/iPhone 8-map___default_dm.png
Binary file modified screenshots/iPhone 8-map___default_lm.png
Binary file modified screenshots/iPhone 8-skeleton___all_lm.png
Binary file modified screenshots/iPhone 8-star-rating___docs_dm.png
Binary file modified screenshots/iPhone 8-star-rating___docs_lm.png
Binary file modified screenshots/iPhone 8-swiftui_badge___default_dm.png
Binary file modified screenshots/iPhone 8-swiftui_badge___default_lm.png
Binary file modified screenshots/iPhone 8-swiftui_button___destructive_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___featured_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___link_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primaryOnDark_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primaryOnDark_lm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primaryOnLight_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primaryOnLight_lm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primary_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___primary_lm.png
Binary file modified screenshots/iPhone 8-swiftui_button___secondary_dm.png
Binary file modified screenshots/iPhone 8-swiftui_button___secondary_lm.png
Binary file modified screenshots/iPhone 8-swiftui_switch___default_dm.png
Binary file modified screenshots/iPhone 8-swiftui_switch___default_lm.png
Binary file modified screenshots/iPhone 8-switch___default_dm.png
Binary file modified screenshots/iPhone 8-switch___default_lm.png
Binary file modified screenshots/iPhone 8-toast___default_dm.png
Binary file modified screenshots/iPhone 8-toast___default_lm.png