Skip to content

Commit e849315

Browse files
committed
Make rich text color picker add quick reset button
1 parent 0934684 commit e849315

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ This release starts moving types and views that relate to other types into the t
1414

1515
* `RichTextAlignment.Picker` has a new style parameter.
1616
* `RichTextCommand` is a new namespace for command-related views.
17+
* `RichTextColorPicker` now shows a quick button to reset the color.
1718
* `RichTextLabelValue` is a new protocol to harmonize label-compatible label values.
1819

1920
### 💡 Adjustments
2021

2122
* Many value types implement `RichTextLabelValue` to get a `label` property.
2223
* All types that implement `RichTextLabelValue` get a `label` that has improved accessibility.
2324

25+
* `RichTextColor` `.adjust` now takes an optional
26+
2427
### 🐛 Bug Fixes
2528

26-
* `Image.symbol(...)` removes `palette` rendering mode.
29+
* `Image.symbol(...)` removes `palette` rendering mode to fix incorrect color scheme behavior.
30+
* `RichTextColorPicker` no longer auto-adjusts black and white to make it possible to actually set those colors.
2731

2832
### 🗑️ Deprecations
2933

Sources/RichTextKit/Colors/RichTextColor+Picker.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public extension RichTextColor {
5959
iconView
6060
picker
6161
if hasColors {
62-
quickPickerDivider
62+
HStack(spacing: spacing) {
63+
quickPickerDivider
64+
quickPickerButton(for: nil)
65+
quickPickerDivider
66+
}
6367
quickPicker
6468
}
6569
}
@@ -126,11 +130,15 @@ private extension RichTextColor.Picker {
126130
}.frame(maxWidth: .infinity)
127131
}
128132

129-
func quickPickerButton(for color: Color) -> some View {
133+
func quickPickerButton(for color: Color?) -> some View {
130134
Button {
131135
value = type.adjust(color, for: colorScheme)
132136
} label: {
133-
color
137+
if let color {
138+
color
139+
} else {
140+
Image.richTextColorReset
141+
}
134142
}
135143
.buttonStyle(ColorButtonStyle())
136144
}

Sources/RichTextKit/Colors/RichTextColor.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,12 @@ public extension RichTextColor {
6565

6666
/// Adjust a `color` for a certain `colorScheme`.
6767
func adjust(
68-
_ color: Color,
68+
_ color: Color?,
6969
for scheme: ColorScheme
7070
) -> Color {
7171
switch self {
72-
case .background:
73-
if (color == .black && scheme == .dark) || (color == .white && scheme == .light) {
74-
return .clear
75-
}
76-
return color
77-
default:
78-
if (color == .white && scheme == .dark) || (color == .black && scheme == .light) {
79-
return .primary
80-
}
81-
return color
72+
case .background: return color ?? .clear
73+
default: return color ?? .primary
8274
}
8375
}
8476
}

Sources/RichTextKit/Images/Image+RichText.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public extension Image {
2626

2727
static let richTextColorBackground = symbol("highlighter")
2828
static let richTextColorForeground = symbol("character")
29+
static let richTextColorReset = symbol("circle.slash")
2930
static let richTextColorStroke = symbol("a.square")
3031
static let richTextColorStrikethrough = symbol("strikethrough")
3132
static let richTextColorUnderline = symbol("underline")

0 commit comments

Comments
 (0)