-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clipsToBounds and overflow modifiers.
Part of #51.
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Sources/Slipstream/Documentation.docc/TailwindCSS/Layout/Layout-Overflow.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Overflow | ||
|
||
Utilities for controlling how a view handles content that is too large for the container. | ||
|
||
## Topics | ||
|
||
### Modifiers | ||
|
||
- ``View/overflow(_:condition:)`` | ||
- ``View/overflow(_:axis:condition:)`` | ||
|
||
### Supporting types | ||
|
||
- ``Overflow`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Constants that control how a view handles content that is too large for the container. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [overflow](https://tailwindcss.com/docs/overflow) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public enum Overflow: String { | ||
case auto | ||
case hidden | ||
case clip | ||
case visible | ||
case scroll | ||
} | ||
|
||
extension View { | ||
/// Changes the clipping behavior of the modified view. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [overflow](https://tailwindcss.com/docs/overflow) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public func overflow(_ overflow: Overflow, condition: Condition? = nil) -> some View { | ||
return modifier(TailwindClassModifier(add: "overflow-" + overflow.rawValue, condition: condition)) | ||
} | ||
|
||
/// Changes the clipping behavior of the modified view for a specific axis. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [overflow](https://tailwindcss.com/docs/overflow) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public func overflow(_ overflow: Overflow, axis: Axis, condition: Condition? = nil) -> some View { | ||
return modifier(TailwindClassModifier(add: "overflow-" + axis.rawValue + "-" + overflow.rawValue, condition: condition)) | ||
} | ||
|
||
/// Enables clipping on the modified view. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [overflow](https://tailwindcss.com/docs/overflow) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public func clipsToBounds(condition: Condition? = nil) -> some View { | ||
return overflow(.hidden, condition: condition) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Tests/SlipstreamTests/TailwindCSS/Layout/OverflowTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Testing | ||
import Slipstream | ||
|
||
struct OverflowTests { | ||
@Test func options() throws { | ||
try #expect(renderHTML(Div {}.overflow(.auto)) == #"<div class="overflow-auto"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.hidden)) == #"<div class="overflow-hidden"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.clip)) == #"<div class="overflow-clip"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.visible)) == #"<div class="overflow-visible"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.scroll)) == #"<div class="overflow-scroll"></div>"#) | ||
} | ||
|
||
@Test func xAxis() throws { | ||
try #expect(renderHTML(Div {}.overflow(.auto, axis: .x)) == #"<div class="overflow-x-auto"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.hidden, axis: .x)) == #"<div class="overflow-x-hidden"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.clip, axis: .x)) == #"<div class="overflow-x-clip"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.visible, axis: .x)) == #"<div class="overflow-x-visible"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.scroll, axis: .x)) == #"<div class="overflow-x-scroll"></div>"#) | ||
} | ||
|
||
@Test func yAxis() throws { | ||
try #expect(renderHTML(Div {}.overflow(.auto, axis: .y)) == #"<div class="overflow-y-auto"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.hidden, axis: .y)) == #"<div class="overflow-y-hidden"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.clip, axis: .y)) == #"<div class="overflow-y-clip"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.visible, axis: .y)) == #"<div class="overflow-y-visible"></div>"#) | ||
try #expect(renderHTML(Div {}.overflow(.scroll, axis: .y)) == #"<div class="overflow-y-scroll"></div>"#) | ||
} | ||
|
||
@Test func clipsToBounds() throws { | ||
try #expect(renderHTML(Div {}.clipsToBounds()) == #"<div class="overflow-hidden"></div>"#) | ||
} | ||
} |