Skip to content

Commit

Permalink
Add colorInvert modifier. (#188)
Browse files Browse the repository at this point in the history
Part of #51.
  • Loading branch information
jverkoey authored Sep 14, 2024
1 parent 3ee1c1f commit d288c18
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
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>"#)
}
}

0 comments on commit d288c18

Please sign in to comment.