Skip to content

Commit

Permalink
Add Section.
Browse files Browse the repository at this point in the history
Part of #25.
  • Loading branch information
jverkoey committed Sep 12, 2024
1 parent 6223762 commit 90778c3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
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>"#)
}
}

0 comments on commit 90778c3

Please sign in to comment.