-
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.
Part of #25.
- Loading branch information
Showing
4 changed files
with
69 additions
and
10 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
32 changes: 32 additions & 0 deletions
32
Sources/Slipstream/Views/W3C/Elements/GroupingContent/Div.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 @@ | ||
/// A view that has no special meaning at all. | ||
/// | ||
/// A Div represents its children. It can be used with the ``View/class(_:)``, | ||
/// ``View/language(_:)``, and ``View/title(_:)`` attributes to | ||
/// mark up semantics common to a group of consecutive elements. | ||
/// | ||
/// ```swift | ||
/// struct MySiteContent: View { | ||
/// var body: some View { | ||
/// Body { | ||
/// Div { | ||
/// Text("Hello, world!") | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [`div`](https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element) specification. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public struct Div<Content>: W3CElement where Content: View { | ||
@_documentation(visibility: private) | ||
public let tagName: String = "div" | ||
|
||
@_documentation(visibility: private) | ||
@ViewBuilder public let content: () -> Content | ||
|
||
/// Creates a Div view. | ||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
self.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
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 DivTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(Div {}) == "<div></div>") | ||
} | ||
|
||
@Test func withText() throws { | ||
try #expect(renderHTML(Div { | ||
Text("Hello, world!") | ||
}) == """ | ||
<div> | ||
Hello, world! | ||
</div> | ||
""") | ||
} | ||
} |