-
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
55 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
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,30 @@ | ||
/// A view that represents a generic section of a document or application. | ||
/// A section, in this context, is a thematic grouping of content, typically | ||
/// with a heading. | ||
/// | ||
/// ```swift | ||
/// struct MySiteContent: View { | ||
/// var body: some View { | ||
/// Body { | ||
/// Section { | ||
/// Link("About", destination: URL(string: "/about")) | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [section](https://html.spec.whatwg.org/multipage/sections.html#the-section-element) specification. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public struct Section<Content>: W3CElement where Content: View { | ||
@_documentation(visibility: private) | ||
public let tagName: String = "section" | ||
|
||
@_documentation(visibility: private) | ||
@ViewBuilder public let content: () -> Content | ||
|
||
/// Creates a Section 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct SectionTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(Section {}) == "<section></section>") | ||
} | ||
|
||
@Test func withText() throws { | ||
try #expect(renderHTML(Section { | ||
DOMString("Hello, world!") | ||
}) == """ | ||
<section> | ||
Hello, world! | ||
</section> | ||
""") | ||
} | ||
|
||
@Test func attribute() throws { | ||
try #expect(renderHTML(Section {}.language("en")) == #"<section lang="en"></section>"#) | ||
} | ||
} |