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 float modifier. #89

Merged
merged 1 commit into from
Aug 5, 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
@@ -0,0 +1,13 @@
# Floats

Utilities for controlling the wrapping of content around a view.

## Topics

### Modifiers

- ``View/float(_:condition:)``

### Supporting types

- ``FloatMode``
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Slipstream implementations of Tailwind CSS's classes.
- ``HStack``
- ``VStack``
- <doc:Layout-Display>
- <doc:Layout-Float>

### Flexbox & Grid

Expand Down
21 changes: 21 additions & 0 deletions Sources/Slipstream/TailwindCSS/Layout/View+float.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Constants that control the wrapping of content around a view.
///
/// - SeeAlso: Tailwind CSS' [floats](https://tailwindcss.com/docs/float) documentation.
@available(iOS 17.0, macOS 14.0, *)
public enum FloatMode: String {
case start
case end
case right
case left
case none
}

extension View {
/// Change how content wraps around the modified view.
///
/// - SeeAlso: Tailwind CSS' [floats](https://tailwindcss.com/docs/float) documentation.
@available(iOS 17.0, macOS 14.0, *)
public func float(_ floatMode: FloatMode, condition: Condition? = nil) -> some View {
return modifier(TailwindClassModifier(add: "float-" + floatMode.rawValue, condition: condition))
}
}
3 changes: 2 additions & 1 deletion Tests/SlipstreamTests/Sites/CatalogSiteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private struct CatalogSite: View {

Heading(level: 2, "Generic heading 2")
}
.float(.right)
.flexGap(.x, width: 2)
.alignItems(.baseline)
.justifyContent(.center)
Expand Down Expand Up @@ -95,7 +96,7 @@ struct CatalogSiteTests {
<br />world!
<a href="/about">About</a>
<a href="/home">Home</a>
<div class="flex flex-col gap-x-0.5 items-baseline justify-center">
<div class="flex flex-col float-right gap-x-0.5 items-baseline justify-center">
<div class="flex flex-row gap-x-2.5">
<h1 class="text-xl font-mono font-bold text-start">Heading 1</h1>
<h2 class="text-3xl text-center leading-snug">Heading 2</h2>
Expand Down
12 changes: 12 additions & 0 deletions Tests/SlipstreamTests/TailwindCSS/Layout/FloatTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Testing
import Slipstream

struct FloatTests {
@Test func enumeration() throws {
try #expect(renderHTML(Div {}.float(.start)) == #"<div class="float-start"></div>"#)
try #expect(renderHTML(Div {}.float(.end)) == #"<div class="float-end"></div>"#)
try #expect(renderHTML(Div {}.float(.left)) == #"<div class="float-left"></div>"#)
try #expect(renderHTML(Div {}.float(.right)) == #"<div class="float-right"></div>"#)
try #expect(renderHTML(Div {}.float(.none)) == #"<div class="float-none"></div>"#)
}
}