Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colorInvert modifier. #188

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Tailwind utility | Slipstream modifier
[Drop Shadow](https://tailwindcss.com/docs/drop-shadow) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Grayscale](https://tailwindcss.com/docs/grayscale) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Hue Rotate](https://tailwindcss.com/docs/hue-rotate) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Invert](https://tailwindcss.com/docs/invert) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Invert](https://tailwindcss.com/docs/invert) | ``View/colorInvert(condition:)``
[Saturate](https://tailwindcss.com/docs/saturate) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Sepia](https://tailwindcss.com/docs/sepia) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Backdrop Blur](https://tailwindcss.com/docs/backdrop-blur) | ``View/background(_:condition:)-89gyc``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ struct MyView: View {
}
```

## Filters

SwiftUI and Slipstream both provide the ability to invert colors.

### Offset

```swift
var body: some View {
Text("Inverted text")
.colorInvert()
}
```

## Layout

SwiftUI and Slipstream both provide the ability to affect the layout of views.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Slipstream implementations of Tailwind CSS's utility classes.
### Filters

- <doc:Filters-BackdropBlur>
- ``View/colorInvert(condition:)``

### Transitions and animations

Expand Down
11 changes: 11 additions & 0 deletions Sources/Slipstream/TailwindCSS/Filters/View+colorInvert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extension View {
/// Inverts all of the colors in a view so that each color displays as its complementary color.
///
/// For example, blue converts to yellow, and white converts to black.
///
/// - SeeAlso: Tailwind CSS' [invert](https://tailwindcss.com/docs/invert) documentation.
@available(iOS 17.0, macOS 14.0, *)
public func colorInvert(condition: Condition? = nil) -> some View {
return modifier(TailwindClassModifier(add: "invert", condition: condition))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Testing
import Slipstream

struct ColorInvertTests {
@Test func applies() throws {
try #expect(renderHTML(Div {}.colorInvert()) == #"<div class="invert"></div>"#)
}
}