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 Section. #178

Merged
merged 1 commit into from
Sep 12, 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
Expand Up @@ -65,7 +65,7 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips
:--------|:----------------
[`<body>`](https://html.spec.whatwg.org/multipage/sections.html#the-body-element) | ``Body``
[`<article>`](https://html.spec.whatwg.org/multipage/sections.html#the-article-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<section>`](https://html.spec.whatwg.org/multipage/sections.html#the-section-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<section>`](https://html.spec.whatwg.org/multipage/sections.html#the-section-element) | ``Section``
[`<nav>`](https://html.spec.whatwg.org/multipage/sections.html#the-nav-element) | ``Navigation``
[`<aside>`](https://html.spec.whatwg.org/multipage/sections.html#the-aside-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<h1>`](https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements) | ``H1`` or ``Heading``
Expand Down
1 change: 1 addition & 0 deletions Sources/Slipstream/Documentation.docc/W3C/W3CViews.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh
### Sections

- ``Body``
- ``Section``
- ``Navigation``
- ``Heading``
- ``H1``
Expand Down
30 changes: 30 additions & 0 deletions Sources/Slipstream/W3C/Elements/Sections/Section.swift
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
}
}
23 changes: 23 additions & 0 deletions Tests/SlipstreamTests/W3C/SectionTests.swift
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>"#)
}
}