Skip to content

Commit

Permalink
Make rich text color picker add quick reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Jan 22, 2024
1 parent 0934684 commit 0f49c1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ This release starts moving types and views that relate to other types into the t

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

### 💡 Adjustments

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

* `RichTextColor` `.adjust` now takes an optional

### 🐛 Bug Fixes

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

### 🗑️ Deprecations

Expand Down
14 changes: 11 additions & 3 deletions Sources/RichTextKit/Colors/RichTextColor+Picker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public extension RichTextColor {
iconView
picker
if hasColors {
quickPickerDivider
HStack(spacing: spacing) {
quickPickerDivider
quickPickerButton(for: nil)
quickPickerDivider
}
quickPicker
}
}
Expand Down Expand Up @@ -126,11 +130,15 @@ private extension RichTextColor.Picker {
}.frame(maxWidth: .infinity)
}

func quickPickerButton(for color: Color) -> some View {
func quickPickerButton(for color: Color?) -> some View {
Button {
value = type.adjust(color, for: colorScheme)
} label: {
color
if let color {
color
} else {
Image(systemName: "circle.slash")
}
}
.buttonStyle(ColorButtonStyle())
}
Expand Down
14 changes: 3 additions & 11 deletions Sources/RichTextKit/Colors/RichTextColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,12 @@ public extension RichTextColor {

/// Adjust a `color` for a certain `colorScheme`.
func adjust(
_ color: Color,
_ color: Color?,
for scheme: ColorScheme
) -> Color {
switch self {
case .background:
if (color == .black && scheme == .dark) || (color == .white && scheme == .light) {
return .clear
}
return color
default:
if (color == .white && scheme == .dark) || (color == .black && scheme == .light) {
return .primary
}
return color
case .background: return color ?? .clear
default: return color ?? .primary
}
}
}
Expand Down

0 comments on commit 0f49c1b

Please sign in to comment.