From 3f36930a8988a3af2822586729e17eab39dd17b8 Mon Sep 17 00:00:00 2001 From: Pavel Holec Date: Wed, 18 Oct 2023 16:04:53 +0200 Subject: [PATCH 1/3] Rename `backgroundColor` to `backgroundStyle` --- Sources/Orbit/Components/Badge.swift | 14 ++-- Sources/Orbit/Components/Button.swift | 6 +- Sources/Orbit/Components/Card.swift | 14 ++-- Sources/Orbit/Components/ChoiceTile.swift | 8 +-- Sources/Orbit/Components/Collapse.swift | 4 +- Sources/Orbit/Components/ListChoice.swift | 6 +- .../Orbit/Components/NotificationBadge.swift | 14 ++-- Sources/Orbit/Components/SocialButton.swift | 2 +- Sources/Orbit/Components/Tag.swift | 4 +- Sources/Orbit/Components/Tile.swift | 4 +- .../ButtonStyles/AlertButtonStyle.swift | 2 +- .../ButtonStyles/AlertInlineButtonStyle.swift | 2 +- .../ButtonStyles/ListChoiceButtonStyle.swift | 16 ++--- .../OrbitButtonLinkButtonStyle.swift | 2 +- .../ButtonStyles/OrbitButtonStyle.swift | 4 +- .../Support/ButtonStyles/TagButtonStyle.swift | 16 ++--- .../ButtonStyles/TileButtonStyle.swift | 16 ++--- .../Components/OrbitCustomButtonContent.swift | 8 +-- .../Environment Keys/BackgroundColorKey.swift | 70 ------------------- .../Environment Keys/BackgroundShapeKey.swift | 70 +++++++++++++++++++ .../Detail/Items/StorybookBadge.swift | 4 +- .../Detail/Items/StorybookButton.swift | 6 +- .../Detail/Items/StorybookCard.swift | 2 +- .../Items/StorybookNotificationBadge.swift | 4 +- .../Foundation/StorybookColors.swift | 2 +- 25 files changed, 150 insertions(+), 150 deletions(-) delete mode 100644 Sources/Orbit/Support/Environment Keys/BackgroundColorKey.swift create mode 100644 Sources/Orbit/Support/Environment Keys/BackgroundShapeKey.swift diff --git a/Sources/Orbit/Components/Badge.swift b/Sources/Orbit/Components/Badge.swift index d1d393b3733..cf03c6e3d66 100644 --- a/Sources/Orbit/Components/Badge.swift +++ b/Sources/Orbit/Components/Badge.swift @@ -8,7 +8,7 @@ import SwiftUI /// - Note: [Orbit definition](https://orbit.kiwi/components/badge/) public struct Badge: View, PotentiallyEmptyView { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.sizeCategory) private var sizeCategory @Environment(\.status) private var status @Environment(\.textColor) private var textColor @@ -48,8 +48,8 @@ public struct Badge: View, PotentiallyEmp } @ViewBuilder var resolvedBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { defaultBackgroundColor } @@ -97,7 +97,7 @@ public extension Badge { /// Creates Orbit Badge component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - type: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. @@ -116,7 +116,7 @@ public extension Badge { /// Creates Orbit Badge component with custom icons. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - style: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. @@ -224,7 +224,7 @@ struct BadgePreviews: PreviewProvider { Badge("Custom", icon: .airplane) .iconColor(.pink) .textColor(.blueDark) - .backgroundColor(.whiteHover) + .backgroundStyle(.whiteHover) Badge("Flag") { CountryFlag("us") @@ -270,7 +270,7 @@ struct BadgePreviews: PreviewProvider { static func gradientBadge(_ gradient: Gradient) -> some View { badges(.neutral) .textColor(.whiteNormal) - .backgroundColor(gradient.background) + .backgroundStyle(gradient.background) .previewDisplayName("\(String(describing: gradient).titleCased)") } } diff --git a/Sources/Orbit/Components/Button.swift b/Sources/Orbit/Components/Button.swift index 604ada98ea6..b6e5c440c4e 100644 --- a/Sources/Orbit/Components/Button.swift +++ b/Sources/Orbit/Components/Button.swift @@ -198,13 +198,13 @@ struct ButtonPreviews: PreviewProvider { @ViewBuilder static var gradients: some View { LazyVStack(alignment: .leading, spacing: .xLarge) { buttons(.primary) - .backgroundColor(Gradient.bundleBasic.background, active: Gradient.bundleBasic.startColor) + .backgroundStyle(Gradient.bundleBasic.background, active: Gradient.bundleBasic.startColor) .previewDisplayName("Bundle Basic") buttons(.primary) - .backgroundColor(Gradient.bundleMedium.background, active: Gradient.bundleMedium.startColor) + .backgroundStyle(Gradient.bundleMedium.background, active: Gradient.bundleMedium.startColor) .previewDisplayName("Bundle Medium") buttons(.primary) - .backgroundColor(Gradient.bundleTop.background, active: Gradient.bundleTop.startColor) + .backgroundStyle(Gradient.bundleTop.background, active: Gradient.bundleTop.startColor) .previewDisplayName("Bundle Top") } .padding(.medium) diff --git a/Sources/Orbit/Components/Card.swift b/Sources/Orbit/Components/Card.swift index c5560a8790b..2a8a7249010 100644 --- a/Sources/Orbit/Components/Card.swift +++ b/Sources/Orbit/Components/Card.swift @@ -8,7 +8,7 @@ import SwiftUI /// - Important: Component expands horizontally unless prevented by `fixedSize` or `idealSize` modifier. public struct Card: View { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.idealSize) private var idealSize let title: String @@ -28,7 +28,7 @@ public struct Card: View { if isContentEmpty == false { VStack(alignment: contentAlignment, spacing: contentSpacing) { content - .backgroundColor(nil) + .backgroundStyle(nil) } .padding(.top, isHeaderEmpty ? contentPadding : 0) .padding([.horizontal, .bottom], contentPadding) @@ -78,8 +78,8 @@ public struct Card: View { } @ViewBuilder var resolvedBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { Color.whiteDarker } @@ -119,7 +119,7 @@ public extension Card { /// Creates Orbit Card component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", @@ -298,13 +298,13 @@ struct CardPreviews: PreviewProvider { ) { VStack(spacing: 0) { ListChoice("ListChoice", action: {}) - .backgroundColor(.blueLight, active: .greenLight) + .backgroundStyle(.blueLight, active: .greenLight) ListChoice("ListChoice", icon: .map, action: {}) ListChoice("ListChoice", description: "ListChoice description", icon: .airplane, showSeparator: false, action: {}) } .padding(.top, .xSmall) } - .backgroundColor(.clear) + .backgroundStyle(.clear) .previewDisplayName() } diff --git a/Sources/Orbit/Components/ChoiceTile.swift b/Sources/Orbit/Components/ChoiceTile.swift index e0022619fdf..28bb176ab0d 100644 --- a/Sources/Orbit/Components/ChoiceTile.swift +++ b/Sources/Orbit/Components/ChoiceTile.swift @@ -6,7 +6,7 @@ import SwiftUI /// - Important: Component expands horizontally unless prevented by `fixedSize` or `idealSize` modifier. public struct ChoiceTile: View { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.idealSize) private var idealSize @Environment(\.status) private var status @Environment(\.isHapticsEnabled) private var isHapticsEnabled @@ -232,7 +232,7 @@ public extension ChoiceTile { /// Creates Orbit ChoiceTile component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - content: The content shown below the header. @@ -271,7 +271,7 @@ public extension ChoiceTile { /// Creates Orbit ChoiceTile component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - content: The content shown below the header. @@ -525,7 +525,7 @@ struct ChoiceTilePreviews: PreviewProvider { @ViewBuilder static var content: some View { choiceTile(titleStyle: .title4, showHeader: true, isError: false, isSelected: false) - .backgroundColor(.redLight) + .backgroundStyle(.redLight) choiceTile(titleStyle: .title4, showHeader: true, isError: false, isSelected: true) choiceTile(titleStyle: .title3, showHeader: true, isError: false, isSelected: false) choiceTile(titleStyle: .title4, showHeader: false, isError: false, isSelected: true) diff --git a/Sources/Orbit/Components/Collapse.swift b/Sources/Orbit/Components/Collapse.swift index cf9ca997d35..99377b8a88d 100644 --- a/Sources/Orbit/Components/Collapse.swift +++ b/Sources/Orbit/Components/Collapse.swift @@ -52,7 +52,7 @@ public extension Collapse { /// Creates Orbit Collapse component with a binding to the expansion state. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( isExpanded: Binding, showSeparator: Bool = true, @@ -68,7 +68,7 @@ public extension Collapse { /// Creates Orbit Collapse component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init(@ViewBuilder content: () -> Content, showSeparator: Bool = true, @ViewBuilder header: () -> Header) { self.header = header() self.headerVerticalPadding = 0 diff --git a/Sources/Orbit/Components/ListChoice.swift b/Sources/Orbit/Components/ListChoice.swift index b08c01c05f4..6e7baff2cad 100644 --- a/Sources/Orbit/Components/ListChoice.swift +++ b/Sources/Orbit/Components/ListChoice.swift @@ -171,7 +171,7 @@ public struct ListChoice: View, Potenti /// Creates Orbit ListChoice component with custom content. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. public init( _ title: String = "", description: String = "", @@ -200,7 +200,7 @@ public extension ListChoice { /// Creates Orbit ListChoice component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", @@ -232,7 +232,7 @@ public extension ListChoice where Header == Text { /// Creates Orbit ListChoice component with text header value. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", diff --git a/Sources/Orbit/Components/NotificationBadge.swift b/Sources/Orbit/Components/NotificationBadge.swift index f53efd7883f..a807d813170 100644 --- a/Sources/Orbit/Components/NotificationBadge.swift +++ b/Sources/Orbit/Components/NotificationBadge.swift @@ -5,7 +5,7 @@ import SwiftUI /// - Note: [Orbit definition](https://orbit.kiwi/components/information/notificationbadge/) public struct NotificationBadge: View { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.status) private var status @Environment(\.sizeCategory) private var sizeCategory @Environment(\.textColor) private var textColor @@ -30,8 +30,8 @@ public struct NotificationBadge: View { @ViewBuilder var resolvedBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { defaultBackgroundColor } @@ -81,7 +81,7 @@ public struct NotificationBadge: View { /// Creates Orbit NotificationBadge component with custom content. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - type: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. @@ -99,7 +99,7 @@ public extension NotificationBadge { /// Creates Orbit NotificationBadge component containing text. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. /// /// - Parameters: /// - style: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. @@ -202,7 +202,7 @@ struct NotificationBadgePreviews: PreviewProvider { NotificationBadge(.airplane) .iconColor(.pink) .textColor(.blueDark) - .backgroundColor(.whiteNormal) + .backgroundStyle(.whiteNormal) NotificationBadge { CountryFlag("us") @@ -233,7 +233,7 @@ struct NotificationBadgePreviews: PreviewProvider { static func gradientBadge(_ gradient: Gradient) -> some View { badges(.neutral) - .backgroundColor(gradient.background) + .backgroundStyle(gradient.background) .textColor(.whiteNormal) .previewDisplayName("\(String(describing: gradient).titleCased)") } diff --git a/Sources/Orbit/Components/SocialButton.swift b/Sources/Orbit/Components/SocialButton.swift index b4979ee5d58..72a14b9d780 100644 --- a/Sources/Orbit/Components/SocialButton.swift +++ b/Sources/Orbit/Components/SocialButton.swift @@ -36,7 +36,7 @@ public struct SocialButton: View { } ) .textColor(textColor) - .backgroundColor(background, active: backgroundActive) + .backgroundStyle(background, active: backgroundActive) } @ViewBuilder var logo: some View { diff --git a/Sources/Orbit/Components/Tag.swift b/Sources/Orbit/Components/Tag.swift index cf5bcb16327..04f1735b270 100644 --- a/Sources/Orbit/Components/Tag.swift +++ b/Sources/Orbit/Components/Tag.swift @@ -66,7 +66,7 @@ public extension Tag { /// Creates Orbit Tag component with custom icon. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ label: String = "", style: TagStyle = .default, @@ -83,7 +83,7 @@ public extension Tag { /// Creates Orbit Tag component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ label: String = "", icon: Icon.Symbol? = nil, diff --git a/Sources/Orbit/Components/Tile.swift b/Sources/Orbit/Components/Tile.swift index b9c0f4811a6..f193c9e0238 100644 --- a/Sources/Orbit/Components/Tile.swift +++ b/Sources/Orbit/Components/Tile.swift @@ -144,7 +144,7 @@ public extension Tile { /// Creates Orbit Tile component. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", @@ -174,7 +174,7 @@ public extension Tile { /// Creates Orbit Tile component with custom icon. /// - /// Custom background color be specified using `.backgroundColor()` modifier. + /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", diff --git a/Sources/Orbit/Support/ButtonStyles/AlertButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/AlertButtonStyle.swift index b61fedad2af..bfd48f2a66d 100644 --- a/Sources/Orbit/Support/ButtonStyles/AlertButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/AlertButtonStyle.swift @@ -23,7 +23,7 @@ public struct AlertButtonStyle: PrimitiveButtonStyle { .textFontWeight(.medium) .textSize(.small) .textColor(textColor) - .backgroundColor(background, active: backgroundActive) + .backgroundStyle(background, active: backgroundActive) } var textColor: Color { diff --git a/Sources/Orbit/Support/ButtonStyles/AlertInlineButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/AlertInlineButtonStyle.swift index 64f3fed0d2c..8b4d291adb1 100644 --- a/Sources/Orbit/Support/ButtonStyles/AlertInlineButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/AlertInlineButtonStyle.swift @@ -22,7 +22,7 @@ struct AlertInlineButtonStyle: PrimitiveButtonStyle { } .textFontWeight(.medium) .textColor(resolvedStatus.darkColor) - .backgroundColor(.clear, active: resolvedStatus.color.opacity(0.24)) + .backgroundStyle(.clear, active: resolvedStatus.color.opacity(0.24)) .idealSize() } diff --git a/Sources/Orbit/Support/ButtonStyles/ListChoiceButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/ListChoiceButtonStyle.swift index 7d26520d6cc..e1e75d370fd 100644 --- a/Sources/Orbit/Support/ButtonStyles/ListChoiceButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/ListChoiceButtonStyle.swift @@ -3,7 +3,7 @@ import SwiftUI /// Button style for Orbit ``ListChoice`` component. public struct ListChoiceButtonStyle: ButtonStyle { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape public func makeBody(configuration: Configuration) -> some View { configuration.label @@ -22,16 +22,16 @@ public struct ListChoiceButtonStyle: ButtonStyle { } @ViewBuilder var resolvedInactiveBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { Color.clear } } @ViewBuilder var resolvedActiveBackground: some View { - if let backgroundColor { - backgroundColor.activeView + if let backgroundShape { + backgroundShape.activeView } else { Color.inkNormal.opacity(0.06) } @@ -63,13 +63,13 @@ struct ListChoiceButtonStylePreviews: PreviewProvider { static var colors: some View { VStack(alignment: .leading, spacing: .medium) { button - .backgroundColor(.orangeLight) + .backgroundStyle(.orangeLight) button - .backgroundColor(.orangeLight, active: .greenLight) + .backgroundStyle(.orangeLight, active: .greenLight) button - .backgroundColor(Gradient.bundleBasic.background, active: .redLight) + .backgroundStyle(Gradient.bundleBasic.background, active: .redLight) } .buttonStyle(ListChoiceButtonStyle()) .previewDisplayName() diff --git a/Sources/Orbit/Support/ButtonStyles/OrbitButtonLinkButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/OrbitButtonLinkButtonStyle.swift index b0f703c7a01..011d08ea8bb 100644 --- a/Sources/Orbit/Support/ButtonStyles/OrbitButtonLinkButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/OrbitButtonLinkButtonStyle.swift @@ -29,7 +29,7 @@ public struct OrbitButtonLinkButtonStyle: } .textFontWeight(.medium) .textColor(textColor) - .backgroundColor(.clear, active: backgroundActive) + .backgroundStyle(.clear, active: backgroundActive) .buttonSize(resolvedButtonSize) .idealSize(horizontal: idealSizeHorizontal, vertical: idealSize.vertical) } diff --git a/Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift index c1ab787e53a..9bcccf8a385 100644 --- a/Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift @@ -3,7 +3,7 @@ import SwiftUI /// Button style for Orbit ``Button`` component. public struct OrbitButtonStyle: PrimitiveButtonStyle { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.buttonSize) private var buttonSize @Environment(\.status) private var status @Environment(\.textColor) private var textColor @@ -28,7 +28,7 @@ public struct OrbitButtonStyle: Primitive .textFontWeight(.medium) .textColor(textColor ?? labelColor) .textSize(textSize) - .backgroundColor(backgroundColor?.inactive ?? background, active: backgroundColor?.active ?? backgroundActive) + .backgroundStyle(backgroundShape?.inactive ?? background, active: backgroundShape?.active ?? backgroundActive) } var background: Color { diff --git a/Sources/Orbit/Support/ButtonStyles/TagButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/TagButtonStyle.swift index 3e278d7c633..19300120e75 100644 --- a/Sources/Orbit/Support/ButtonStyles/TagButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/TagButtonStyle.swift @@ -6,7 +6,7 @@ public struct TagButtonStyle: ButtonStyle { public static let horizontalPadding: CGFloat = .xSmall public static let verticalPadding: CGFloat = 6 // = 32 height @ normal size text size - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.iconColor) private var iconColor @Environment(\.textColor) private var textColor @@ -48,16 +48,16 @@ public struct TagButtonStyle: ButtonStyle { } @ViewBuilder var resolvedInactiveBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { inactiveBackgroundColor } } @ViewBuilder var resolvedActiveBackground: some View { - if let backgroundColor { - backgroundColor.activeView + if let backgroundShape { + backgroundShape.activeView } else { activeBackgroundColor } @@ -160,15 +160,15 @@ struct TagButtonStylePreviews: PreviewProvider { static var colors: some View { VStack(alignment: .leading, spacing: .medium) { button - .backgroundColor(.orangeLight) + .backgroundStyle(.orangeLight) .textColor(.orangeDark) button - .backgroundColor(.orangeLight, active: .greenLight) + .backgroundStyle(.orangeLight, active: .greenLight) .textColor(.orangeDark) button - .backgroundColor(Gradient.bundleBasic.background, active: .redLight) + .backgroundStyle(Gradient.bundleBasic.background, active: .redLight) button .buttonStyle(TagButtonStyle(style: .removable(action: {}), isFocused: true, isSelected: true)) diff --git a/Sources/Orbit/Support/ButtonStyles/TileButtonStyle.swift b/Sources/Orbit/Support/ButtonStyles/TileButtonStyle.swift index 295f8296167..e3c22da42b1 100644 --- a/Sources/Orbit/Support/ButtonStyles/TileButtonStyle.swift +++ b/Sources/Orbit/Support/ButtonStyles/TileButtonStyle.swift @@ -5,7 +5,7 @@ public struct TileButtonStyle: ButtonStyle { public static let verticalTextPadding: CGFloat = 14 // = 52 height @ normal size - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape private let style: TileBorderStyle private let isSelected: Bool @@ -25,16 +25,16 @@ public struct TileButtonStyle: ButtonStyle { } @ViewBuilder var resolvedInactiveBackground: some View { - if let backgroundColor { - backgroundColor.inactiveView + if let backgroundShape { + backgroundShape.inactiveView } else { Color.whiteDarker } } @ViewBuilder var resolvedActiveBackground: some View { - if let backgroundColor { - backgroundColor.activeView + if let backgroundShape { + backgroundShape.activeView } else { Color.whiteHover } @@ -78,13 +78,13 @@ struct TileButtonStylePreviews: PreviewProvider { static var colors: some View { VStack(alignment: .leading, spacing: .medium) { button - .backgroundColor(.orangeLight) + .backgroundStyle(.orangeLight) button - .backgroundColor(.orangeLight, active: .greenLight) + .backgroundStyle(.orangeLight, active: .greenLight) button - .backgroundColor(Gradient.bundleBasic.background, active: .redLight) + .backgroundStyle(Gradient.bundleBasic.background, active: .redLight) } .buttonStyle(TileButtonStyle()) .previewDisplayName() diff --git a/Sources/Orbit/Support/Components/OrbitCustomButtonContent.swift b/Sources/Orbit/Support/Components/OrbitCustomButtonContent.swift index e8428b62844..f2429944b0f 100644 --- a/Sources/Orbit/Support/Components/OrbitCustomButtonContent.swift +++ b/Sources/Orbit/Support/Components/OrbitCustomButtonContent.swift @@ -2,7 +2,7 @@ import SwiftUI struct OrbitCustomButtonContent: View { - @Environment(\.backgroundColor) private var backgroundColor + @Environment(\.backgroundShape) private var backgroundShape @Environment(\.iconColor) private var iconColor @Environment(\.idealSize) private var idealSize @Environment(\.isHapticsEnabled) private var isHapticsEnabled @@ -86,9 +86,9 @@ struct OrbitCustomButtonContent: View { @ViewBuilder var backgroundView: some View { if isPressed { - backgroundColor?.activeView + backgroundShape?.activeView } else { - backgroundColor?.inactiveView + backgroundShape?.inactiveView } } @@ -167,7 +167,7 @@ struct OrbitCustomButtonContentPreviews: PreviewProvider { Icon(.chevronForward) } .textColor(.blueDark) - .backgroundColor(.orangeLight, active: .greenLight) + .backgroundStyle(.orangeLight, active: .greenLight) } } } diff --git a/Sources/Orbit/Support/Environment Keys/BackgroundColorKey.swift b/Sources/Orbit/Support/Environment Keys/BackgroundColorKey.swift deleted file mode 100644 index 0b3e94e6748..00000000000 --- a/Sources/Orbit/Support/Environment Keys/BackgroundColorKey.swift +++ /dev/null @@ -1,70 +0,0 @@ -import SwiftUI - -/// Stores background default and active color used for Orbit components that contain background, such as `Card` or `Tile`. -public struct BackgroundColor { - - public let inactive: any ShapeStyle - public let active: any ShapeStyle - - @ViewBuilder public var inactiveView: some View { - switch inactive { - case let color as Color: color - case let color as LinearGradient: color - case let color as RadialGradient: color - default: EmptyView() - } - } - - @ViewBuilder public var activeView: some View { - switch active { - case let color as Color: color - case let color as LinearGradient: color - case let color as RadialGradient: color - default: EmptyView() - } - } -} - -struct BackgroundColorKey: EnvironmentKey { - static let defaultValue: BackgroundColor? = nil -} - -public extension EnvironmentValues { - - /// A background color stored in a view’s environment, used for Orbit components that contain background, such as `Card` or `Tile`. - var backgroundColor: BackgroundColor? { - get { self[BackgroundColorKey.self] } - set { self[BackgroundColorKey.self] = newValue } - } -} - -public extension View { - - /// Set the separate inactive and active background colors for any supported Orbit component within the view hierarchy. - /// - /// - Parameters: - /// - color: A color or a gradient that will be used in supported touchable Orbit components such as `Tile` as inactive and active background style. - /// Pass `nil` to ignore environment value and to allow the system or the container to provide its own background style. - func backgroundColor(_ color: BackgroundColor?) -> some View { - environment(\.backgroundColor, color) - } - - /// Set separate inactive and active background colors for any supported Orbit component within the view hierarchy. - /// - /// - Parameters: - /// - shape: A color or a gradient that will be used in supported Orbit components such as `Card` or `Badge` as a background style. - /// - active: A color or a gradient that will be used in supported touchable Orbit components such as `Tile` as an active (pressed) background style. - func backgroundColor(_ shape: any ShapeStyle, active: any ShapeStyle) -> some View { - backgroundColor(.init(inactive: shape, active: shape)) - } - - /// Set the background color for any supported Orbit component within the view hierarchy. - /// - /// - Parameters: - /// - shape: A color or a gradient that will be used in supported Orbit components such as `Card` or `Badge` as a background style. - func backgroundColor(_ shape: any ShapeStyle) -> some View { - backgroundColor(shape, active: shape) - } - - -} diff --git a/Sources/Orbit/Support/Environment Keys/BackgroundShapeKey.swift b/Sources/Orbit/Support/Environment Keys/BackgroundShapeKey.swift new file mode 100644 index 00000000000..4005e407c1c --- /dev/null +++ b/Sources/Orbit/Support/Environment Keys/BackgroundShapeKey.swift @@ -0,0 +1,70 @@ +import SwiftUI + +/// Stores background shapes used for Orbit components that render their own background, such as `Card` or `Tile`. +public struct BackgroundShape { + + public let inactive: any ShapeStyle + public let active: any ShapeStyle + + @ViewBuilder public var inactiveView: some View { + switch inactive { + case let color as Color: color + case let color as LinearGradient: color + case let color as RadialGradient: color + default: EmptyView() + } + } + + @ViewBuilder public var activeView: some View { + switch active { + case let color as Color: color + case let color as LinearGradient: color + case let color as RadialGradient: color + default: EmptyView() + } + } +} + +struct BackgroundShapeKey: EnvironmentKey { + static let defaultValue: BackgroundShape? = nil +} + +public extension EnvironmentValues { + + /// An optional background shape style stored in a view’s environment, used for Orbit components that contain background, such as `Card` or `Tile`. + /// + /// This is an Orbit counterpart to the native `backgroundStyle` environment key available in iOS 16. + var backgroundShape: BackgroundShape? { + get { self[BackgroundShapeKey.self] } + set { self[BackgroundShapeKey.self] = newValue } + } +} + +public extension View { + + /// Set the inactive and active background shape styles for supported Orbit components within the view hierarchy. + /// + /// - Parameters: + /// - shape: An optional `Color` or a `LinearGradient` that will be used in supported touchable Orbit components such as `Tile` as inactive and active background style. + /// Pass `nil` to ignore environment value and to allow the system or the container to provide its own background style. + func backgroundStyle(_ shape: BackgroundShape?) -> some View { + environment(\.backgroundShape, shape) + } + + /// Set the inactive and active background shape styles for supported Orbit components within the view hierarchy. + /// + /// - Parameters: + /// - shape: A `Color` or a `LinearGradient` that will be used in supported Orbit components such as `Card` or `Badge` as a background style. + /// - shape: A `Color` or a `LinearGradient` that will be used in supported touchable Orbit components such as `Tile` as inactive and active background style. + func backgroundStyle(_ shape: any ShapeStyle, active: any ShapeStyle) -> some View { + backgroundStyle(.init(inactive: shape, active: shape)) + } + + /// Set the background shape style for supported Orbit components within the view hierarchy. + /// + /// - Parameters: + /// - shape: A `Color` or a `LinearGradient` that will be used in supported Orbit components such as `Card` or `Badge` as a background style. + func backgroundStyle(_ shape: any ShapeStyle) -> some View { + backgroundStyle(shape, active: shape) + } +} diff --git a/Sources/OrbitStorybook/Detail/Items/StorybookBadge.swift b/Sources/OrbitStorybook/Detail/Items/StorybookBadge.swift index 6a78bf071b3..44cdbee8726 100644 --- a/Sources/OrbitStorybook/Detail/Items/StorybookBadge.swift +++ b/Sources/OrbitStorybook/Detail/Items/StorybookBadge.swift @@ -40,7 +40,7 @@ struct StorybookBadge { Badge("Custom", icon: .airplane) .iconColor(.pink) .textColor(.blueDark) - .backgroundColor(.whiteHover) + .backgroundStyle(.whiteHover) Badge("Flag") { CountryFlag("us") @@ -81,7 +81,7 @@ struct StorybookBadge { static func gradientBadge(_ gradient: Orbit.Gradient) -> some View { badges(.neutral) .textColor(.whiteNormal) - .backgroundColor(gradient.background) + .backgroundStyle(gradient.background) .previewDisplayName("\(String(describing: gradient).titleCased)") } } diff --git a/Sources/OrbitStorybook/Detail/Items/StorybookButton.swift b/Sources/OrbitStorybook/Detail/Items/StorybookButton.swift index 1b0a7b74f77..daef917094a 100644 --- a/Sources/OrbitStorybook/Detail/Items/StorybookButton.swift +++ b/Sources/OrbitStorybook/Detail/Items/StorybookButton.swift @@ -27,13 +27,13 @@ struct StorybookButton { @ViewBuilder static var gradient: some View { LazyVStack(alignment: .leading, spacing: .xLarge) { buttons(.primary) - .backgroundColor(Gradient.bundleBasic.background, active: Gradient.bundleBasic.startColor) + .backgroundStyle(Gradient.bundleBasic.background, active: Gradient.bundleBasic.startColor) .previewDisplayName("Bundle Basic") buttons(.primary) - .backgroundColor(Gradient.bundleMedium.background, active: Gradient.bundleMedium.startColor) + .backgroundStyle(Gradient.bundleMedium.background, active: Gradient.bundleMedium.startColor) .previewDisplayName("Bundle Medium") buttons(.primary) - .backgroundColor(Gradient.bundleTop.background, active: Gradient.bundleTop.startColor) + .backgroundStyle(Gradient.bundleTop.background, active: Gradient.bundleTop.startColor) .previewDisplayName("Bundle Top") } .padding(.medium) diff --git a/Sources/OrbitStorybook/Detail/Items/StorybookCard.swift b/Sources/OrbitStorybook/Detail/Items/StorybookCard.swift index 961b22dc3f4..5bea88f8d1b 100644 --- a/Sources/OrbitStorybook/Detail/Items/StorybookCard.swift +++ b/Sources/OrbitStorybook/Detail/Items/StorybookCard.swift @@ -111,7 +111,7 @@ struct StorybookCard { } .padding(.top, .xSmall) } - .backgroundColor(.clear) + .backgroundStyle(.clear) } } diff --git a/Sources/OrbitStorybook/Detail/Items/StorybookNotificationBadge.swift b/Sources/OrbitStorybook/Detail/Items/StorybookNotificationBadge.swift index baf67fa52ee..97bfef1d5d9 100644 --- a/Sources/OrbitStorybook/Detail/Items/StorybookNotificationBadge.swift +++ b/Sources/OrbitStorybook/Detail/Items/StorybookNotificationBadge.swift @@ -35,7 +35,7 @@ struct StorybookNotificationBadge { NotificationBadge(.airplane) .iconColor(.pink) .textColor(.blueDark) - .backgroundColor(.whiteNormal) + .backgroundStyle(.whiteNormal) NotificationBadge { CountryFlag("us") @@ -65,7 +65,7 @@ struct StorybookNotificationBadge { static func gradientBadge(_ gradient: Orbit.Gradient) -> some View { badges(.neutral) - .backgroundColor(gradient.background) + .backgroundStyle(gradient.background) .textColor(.whiteNormal) .previewDisplayName("\(String(describing: gradient).titleCased)") } diff --git a/Sources/OrbitStorybook/Foundation/StorybookColors.swift b/Sources/OrbitStorybook/Foundation/StorybookColors.swift index d6e2bd293c9..06de1adbbbb 100644 --- a/Sources/OrbitStorybook/Foundation/StorybookColors.swift +++ b/Sources/OrbitStorybook/Foundation/StorybookColors.swift @@ -260,7 +260,7 @@ private struct ColorCard: View { .compositingGroup() .elevation(.level2) } - .backgroundColor(.clear) + .backgroundStyle(.clear) } } From cce51fd63e1d94f9d0dddd3aded6895a507ebf7f Mon Sep 17 00:00:00 2001 From: Pavel Holec Date: Wed, 18 Oct 2023 16:08:34 +0200 Subject: [PATCH 2/3] Remove backgroundShape comment from inits --- Sources/Orbit/Components/Badge.swift | 4 ---- Sources/Orbit/Components/Card.swift | 2 -- Sources/Orbit/Components/ChoiceTile.swift | 4 ---- Sources/Orbit/Components/Collapse.swift | 4 ---- Sources/Orbit/Components/ListChoice.swift | 6 ------ Sources/Orbit/Components/NotificationBadge.swift | 4 ---- Sources/Orbit/Components/Tag.swift | 4 ---- Sources/Orbit/Components/Tile.swift | 4 ---- 8 files changed, 32 deletions(-) diff --git a/Sources/Orbit/Components/Badge.swift b/Sources/Orbit/Components/Badge.swift index cf03c6e3d66..6f9cd435c6e 100644 --- a/Sources/Orbit/Components/Badge.swift +++ b/Sources/Orbit/Components/Badge.swift @@ -97,8 +97,6 @@ public extension Badge { /// Creates Orbit Badge component. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - type: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. init( @@ -116,8 +114,6 @@ public extension Badge { /// Creates Orbit Badge component with custom icons. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - style: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. init( diff --git a/Sources/Orbit/Components/Card.swift b/Sources/Orbit/Components/Card.swift index 2a8a7249010..85efa21c101 100644 --- a/Sources/Orbit/Components/Card.swift +++ b/Sources/Orbit/Components/Card.swift @@ -118,8 +118,6 @@ public struct Card: View { public extension Card { /// Creates Orbit Card component. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", diff --git a/Sources/Orbit/Components/ChoiceTile.swift b/Sources/Orbit/Components/ChoiceTile.swift index 28bb176ab0d..da73dba94d0 100644 --- a/Sources/Orbit/Components/ChoiceTile.swift +++ b/Sources/Orbit/Components/ChoiceTile.swift @@ -232,8 +232,6 @@ public extension ChoiceTile { /// Creates Orbit ChoiceTile component. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - content: The content shown below the header. /// - header: A trailing view placed inside the tile header. @@ -271,8 +269,6 @@ public extension ChoiceTile { /// Creates Orbit ChoiceTile component. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - content: The content shown below the header. /// - header: A trailing view placed inside the tile header. diff --git a/Sources/Orbit/Components/Collapse.swift b/Sources/Orbit/Components/Collapse.swift index 99377b8a88d..17d51882a75 100644 --- a/Sources/Orbit/Components/Collapse.swift +++ b/Sources/Orbit/Components/Collapse.swift @@ -51,8 +51,6 @@ public struct Collapse: View { public extension Collapse { /// Creates Orbit Collapse component with a binding to the expansion state. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( isExpanded: Binding, showSeparator: Bool = true, @@ -67,8 +65,6 @@ public extension Collapse { } /// Creates Orbit Collapse component. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init(@ViewBuilder content: () -> Content, showSeparator: Bool = true, @ViewBuilder header: () -> Header) { self.header = header() self.headerVerticalPadding = 0 diff --git a/Sources/Orbit/Components/ListChoice.swift b/Sources/Orbit/Components/ListChoice.swift index 6e7baff2cad..0e2640889e3 100644 --- a/Sources/Orbit/Components/ListChoice.swift +++ b/Sources/Orbit/Components/ListChoice.swift @@ -170,8 +170,6 @@ public struct ListChoice: View, Potenti } /// Creates Orbit ListChoice component with custom content. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. public init( _ title: String = "", description: String = "", @@ -199,8 +197,6 @@ public struct ListChoice: View, Potenti public extension ListChoice { /// Creates Orbit ListChoice component. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", @@ -231,8 +227,6 @@ public extension ListChoice { public extension ListChoice where Header == Text { /// Creates Orbit ListChoice component with text header value. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", diff --git a/Sources/Orbit/Components/NotificationBadge.swift b/Sources/Orbit/Components/NotificationBadge.swift index a807d813170..8f3fe51b343 100644 --- a/Sources/Orbit/Components/NotificationBadge.swift +++ b/Sources/Orbit/Components/NotificationBadge.swift @@ -81,8 +81,6 @@ public struct NotificationBadge: View { /// Creates Orbit NotificationBadge component with custom content. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - type: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. public init( @@ -99,8 +97,6 @@ public extension NotificationBadge { /// Creates Orbit NotificationBadge component containing text. /// - /// Custom background color be specified using `.backgroundStyle()` modifier. - /// /// - Parameters: /// - style: A visual style of component. A `status` style can be optionally modified using `status()` modifier when `nil` value is provided. init( diff --git a/Sources/Orbit/Components/Tag.swift b/Sources/Orbit/Components/Tag.swift index 04f1735b270..05ddba0f3b9 100644 --- a/Sources/Orbit/Components/Tag.swift +++ b/Sources/Orbit/Components/Tag.swift @@ -65,8 +65,6 @@ public struct Tag: View, PotentiallyEmptyView { public extension Tag { /// Creates Orbit Tag component with custom icon. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ label: String = "", style: TagStyle = .default, @@ -82,8 +80,6 @@ public extension Tag { } /// Creates Orbit Tag component. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ label: String = "", icon: Icon.Symbol? = nil, diff --git a/Sources/Orbit/Components/Tile.swift b/Sources/Orbit/Components/Tile.swift index f193c9e0238..8111b7f5e6c 100644 --- a/Sources/Orbit/Components/Tile.swift +++ b/Sources/Orbit/Components/Tile.swift @@ -143,8 +143,6 @@ public struct Tile: View { public extension Tile { /// Creates Orbit Tile component. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", @@ -173,8 +171,6 @@ public extension Tile { } /// Creates Orbit Tile component with custom icon. - /// - /// Custom background color be specified using `.backgroundStyle()` modifier. init( _ title: String = "", description: String = "", From eeef50c13b155f4a02b84d315c2b72ca6ef2a04b Mon Sep 17 00:00:00 2001 From: Pavel Holec Date: Wed, 18 Oct 2023 16:24:04 +0200 Subject: [PATCH 3/3] Rename BackgroundColor in docs --- Sources/Orbit/Orbit.docc/Components/Extensions/Badge.md | 2 +- Sources/Orbit/Orbit.docc/Components/Extensions/Card.md | 2 +- Sources/Orbit/Orbit.docc/Components/Extensions/ChoiceTile.md | 2 +- Sources/Orbit/Orbit.docc/Components/Extensions/Tag.md | 2 +- Sources/Orbit/Orbit.docc/Components/Extensions/Tile.md | 2 +- Sources/Orbit/Orbit.docc/Uncategorized.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Orbit/Orbit.docc/Components/Extensions/Badge.md b/Sources/Orbit/Orbit.docc/Components/Extensions/Badge.md index a994b88ee32..495724aac7c 100644 --- a/Sources/Orbit/Orbit.docc/Components/Extensions/Badge.md +++ b/Sources/Orbit/Orbit.docc/Components/Extensions/Badge.md @@ -9,4 +9,4 @@ ### Customizing Appearance - ``BadgeType`` -- ``BackgroundColor`` +- ``BackgroundShape`` diff --git a/Sources/Orbit/Orbit.docc/Components/Extensions/Card.md b/Sources/Orbit/Orbit.docc/Components/Extensions/Card.md index b8f6cfe26e6..1f56d8bc652 100644 --- a/Sources/Orbit/Orbit.docc/Components/Extensions/Card.md +++ b/Sources/Orbit/Orbit.docc/Components/Extensions/Card.md @@ -13,4 +13,4 @@ ### Customizing Appearance - ``CardContentLayout`` -- ``BackgroundColor`` +- ``BackgroundShape`` diff --git a/Sources/Orbit/Orbit.docc/Components/Extensions/ChoiceTile.md b/Sources/Orbit/Orbit.docc/Components/Extensions/ChoiceTile.md index bf6de02e314..3bac045fae1 100644 --- a/Sources/Orbit/Orbit.docc/Components/Extensions/ChoiceTile.md +++ b/Sources/Orbit/Orbit.docc/Components/Extensions/ChoiceTile.md @@ -8,4 +8,4 @@ ### Customizing Appearance -- ``BackgroundColor`` +- ``BackgroundShape`` diff --git a/Sources/Orbit/Orbit.docc/Components/Extensions/Tag.md b/Sources/Orbit/Orbit.docc/Components/Extensions/Tag.md index 24d3590bbc4..a7642b2b213 100644 --- a/Sources/Orbit/Orbit.docc/Components/Extensions/Tag.md +++ b/Sources/Orbit/Orbit.docc/Components/Extensions/Tag.md @@ -10,4 +10,4 @@ - ``TagButtonStyle`` - ``TagStyle`` -- ``BackgroundColor`` +- ``BackgroundShape`` diff --git a/Sources/Orbit/Orbit.docc/Components/Extensions/Tile.md b/Sources/Orbit/Orbit.docc/Components/Extensions/Tile.md index a01e77a1941..aa41cf3ef41 100644 --- a/Sources/Orbit/Orbit.docc/Components/Extensions/Tile.md +++ b/Sources/Orbit/Orbit.docc/Components/Extensions/Tile.md @@ -12,4 +12,4 @@ - ``TileBorderStyle`` - ``TileButtonStyle`` - ``TileDisclosure`` -- ``BackgroundColor`` +- ``BackgroundShape`` diff --git a/Sources/Orbit/Orbit.docc/Uncategorized.md b/Sources/Orbit/Orbit.docc/Uncategorized.md index deaabdaf375..5fc513ef916 100644 --- a/Sources/Orbit/Orbit.docc/Uncategorized.md +++ b/Sources/Orbit/Orbit.docc/Uncategorized.md @@ -59,7 +59,7 @@ Supporting types and components under development. ### Other - ``AssetNameProviding`` -- ``BackgroundColor`` +- ``BackgroundShape`` - ``BadgeListType`` - ``BarButton`` - ``BorderWidth``