-
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 Tailwind Container implementation.
Part of #51.
- Loading branch information
Showing
5 changed files
with
69 additions
and
5 deletions.
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
9 changes: 9 additions & 0 deletions
9
Sources/Slipstream/Documentation.docc/Views/TailwindCSS/TailwindCSSViews.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,9 @@ | ||
# Views | ||
|
||
Slipstream implementations of Tailwind CSS views. | ||
|
||
## Topics | ||
|
||
### Layout | ||
|
||
- ``Container`` |
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,35 @@ | ||
/// A component for fixing an element's width to the current breakpoint. | ||
/// | ||
/// A ``Container`` is a ``Div``, and is similarly used to organize child | ||
/// views together. | ||
/// | ||
/// ```swift | ||
/// struct MySiteContent: View { | ||
/// var body: some View { | ||
/// Body { | ||
/// Container { | ||
/// Text("Hello, world!") | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [`container`](https://tailwindcss.com/docs/container) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public struct Container<Content: View>: View { | ||
/// Creates a Container view. | ||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
self.content = content | ||
} | ||
|
||
@_documentation(visibility: private) | ||
public var body: some View { | ||
Div { | ||
content() | ||
} | ||
.modifier(ClassModifier(add: "container")) | ||
} | ||
|
||
private let content: () -> Content | ||
} |
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
19 changes: 19 additions & 0 deletions
19
Tests/SlipstreamTests/Views/TailwindCSS/ContainerTests.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,19 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct ContainerTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(Container {}) == #"<div class="container"></div>"#) | ||
} | ||
|
||
@Test func withText() throws { | ||
try #expect(renderHTML(Container { | ||
Text("Hello, world!") | ||
}) == """ | ||
<div class="container"> | ||
Hello, world! | ||
</div> | ||
""") | ||
} | ||
} |