diff --git a/Demo/iOS/EditorScreen.swift b/Demo/iOS/EditorScreen.swift index fc4903cfe..29ec9f476 100644 --- a/Demo/iOS/EditorScreen.swift +++ b/Demo/iOS/EditorScreen.swift @@ -59,7 +59,7 @@ private extension EditorScreen { trailingButtons: {} ) { var sheet = $0 - sheet.colorPickers = .all + sheet.colorPickers = .allRelevant return sheet } } diff --git a/Demo/macOS/EditorScreen.swift b/Demo/macOS/EditorScreen.swift index d117e7ba7..82d4a1142 100644 --- a/Demo/macOS/EditorScreen.swift +++ b/Demo/macOS/EditorScreen.swift @@ -59,7 +59,7 @@ private extension EditorScreen { var toolbar: some View { RichTextFormatSidebar( context: context, - colorPickers: .all + colorPickers: .allRelevant ) .frame(width: 250) } diff --git a/Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift b/Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift index 301ff618a..068602a0f 100644 --- a/Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift +++ b/Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift @@ -17,7 +17,7 @@ public extension RichTextAlignment { be styled and configured with plain SwiftUI. */ struct Picker: View { - + @Environment(\.colorScheme) var colorScheme /** Create a rich text alignment picker. @@ -46,10 +46,11 @@ public extension RichTextAlignment { SwiftUI.Picker("", selection: $selection) { ForEach(RichTextAlignment.allCases) { value in value.icon - .foregroundColor(style.iconColor) .accessibilityLabel(value.title) .tag(value) + .foregroundColor(colorScheme == .dark ? style.darkIconColor : style.lightIconColor) } + } .accessibilityLabel(RTKL10n.textAlignment.text) } @@ -62,18 +63,24 @@ public extension RichTextAlignment.Picker { struct Style { public init( - iconColor: Color = .primary + lightIconColor: Color = Color.black, + darkIconColor: Color = Color.white ) { - self.iconColor = iconColor + self.lightIconColor = lightIconColor + self.darkIconColor = darkIconColor } - public var iconColor: Color + public var lightIconColor: Color + public var darkIconColor: Color } } public extension RichTextAlignment.Picker.Style { - static var standard = Self.init() + static var standard = Self.init( + lightIconColor: .black, + darkIconColor: .white + ) } struct RichTextAlignment_Picker_Previews: PreviewProvider { diff --git a/Sources/RichTextKit/Colors/RichTextColor.swift b/Sources/RichTextKit/Colors/RichTextColor.swift index afd9d6f68..8faa80f78 100644 --- a/Sources/RichTextKit/Colors/RichTextColor.swift +++ b/Sources/RichTextKit/Colors/RichTextColor.swift @@ -84,6 +84,13 @@ public extension RichTextColor { } public extension Collection where Element == RichTextColor { - + static var allRelevant: [RichTextColor] { Element.allCases - .undefined } + static var all: [RichTextColor] { Element.allCases } } + +extension Array where Element == RichTextColor { + static func - (lhs: [RichTextColor], rhs: RichTextColor) -> [RichTextColor] { + return lhs.filter { $0 != rhs } + } +} diff --git a/Sources/RichTextKit/Styles/RichTextStyleButton.swift b/Sources/RichTextKit/Styles/RichTextStyleButton.swift index 8771263c7..12ada5860 100644 --- a/Sources/RichTextKit/Styles/RichTextStyleButton.swift +++ b/Sources/RichTextKit/Styles/RichTextStyleButton.swift @@ -78,6 +78,7 @@ public struct RichTextStyleButton: View { .foregroundColor(tintColor) .contentShape(Rectangle()) } + .tint(tintColor) .keyboardShortcut(for: style) .accessibilityLabel(style.title) } @@ -98,7 +99,7 @@ public extension RichTextStyleButton { - activeColor: The color to apply when the button is active, by default `.blue`. */ public init( - inactiveColor: Color = .primary, + inactiveColor: Color? = nil, activeColor: Color = .blue ) { self.inactiveColor = inactiveColor @@ -106,7 +107,7 @@ public extension RichTextStyleButton { } /// The color to apply when the button is inactive. - public var inactiveColor: Color + public var inactiveColor: Color? /// The color to apply when the button is active. public var activeColor: Color @@ -127,7 +128,7 @@ private extension RichTextStyleButton { value.wrappedValue } - var tintColor: Color { + var tintColor: Color? { isOn ? buttonStyle.activeColor : buttonStyle.inactiveColor } diff --git a/Sources/RichTextKit/_Deprecated/RichTextAlignment+Deprecated.swift b/Sources/RichTextKit/_Deprecated/RichTextAlignment+Deprecated.swift index daa50b820..16b461c95 100644 --- a/Sources/RichTextKit/_Deprecated/RichTextAlignment+Deprecated.swift +++ b/Sources/RichTextKit/_Deprecated/RichTextAlignment+Deprecated.swift @@ -2,3 +2,12 @@ import SwiftUI @available(*, deprecated, renamed: "RichTextAlignment.Picker") public typealias RichTextAlignmentPicker = RichTextAlignment.Picker + +public extension RichTextAlignment.Picker.Style { + + @available(*, deprecated, renamed: "init(lightIconColor:darkIconColor:)") + init(iconColor: Color = .primary) { + self.lightIconColor = iconColor + self.darkIconColor = iconColor + } +} diff --git a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift index 2c38e6bc3..9bd080088 100644 --- a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift +++ b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift @@ -135,7 +135,6 @@ public extension RichTextViewComponent { setRichTextAttributes(attributes) } - @available(*, deprecated, message: "richTextAlignment") var currentTextAlignment: RichTextAlignment? { richTextAlignment