Skip to content

Commit

Permalink
Solve issues with button colors
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikBucher12 committed Jan 18, 2024
1 parent 3069451 commit 776bfce
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Demo/iOS/EditorScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private extension EditorScreen {
trailingButtons: {}
) {
var sheet = $0
sheet.colorPickers = .all
sheet.colorPickers = .allRelevant
return sheet
}
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/macOS/EditorScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private extension EditorScreen {
var toolbar: some View {
RichTextFormatSidebar(
context: context,
colorPickers: .all
colorPickers: .allRelevant
)
.frame(width: 250)
}
Expand Down
19 changes: 13 additions & 6 deletions Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion Sources/RichTextKit/Colors/RichTextColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
7 changes: 4 additions & 3 deletions Sources/RichTextKit/Styles/RichTextStyleButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public struct RichTextStyleButton: View {
.foregroundColor(tintColor)
.contentShape(Rectangle())
}
.tint(tintColor)
.keyboardShortcut(for: style)
.accessibilityLabel(style.title)
}
Expand All @@ -98,15 +99,15 @@ 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
self.activeColor = activeColor
}

/// 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
Expand All @@ -127,7 +128,7 @@ private extension RichTextStyleButton {
value.wrappedValue
}

var tintColor: Color {
var tintColor: Color? {
isOn ? buttonStyle.activeColor : buttonStyle.inactiveColor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public extension RichTextViewComponent {
setRichTextAttributes(attributes)
}


@available(*, deprecated, message: "richTextAlignment")
var currentTextAlignment: RichTextAlignment? {
richTextAlignment
Expand Down

0 comments on commit 776bfce

Please sign in to comment.