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 Divider view. #94

Merged
merged 2 commits into from
Aug 6, 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
3 changes: 2 additions & 1 deletion Sources/Slipstream/Documentation.docc/W3C/W3CViews.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh

### Grouping content

- ``Div``
- ``Paragraph``
- ``Divider``
- ``Div``

### Text-level semantics

Expand Down
32 changes: 32 additions & 0 deletions Sources/Slipstream/W3C/Elements/GroupingContent/Divider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import SwiftSoup

/// A divider represents a paragraph-level thematic break, e.g., a
/// scene change in a story, or a transition to another topic within
/// a section of a reference book.
///
/// ```swift
/// struct MySiteContent: View {
/// var body: some View {
/// Body {
/// Div {
/// Paragraph("Hello, world!")
/// Divider()
/// Paragraph("Let's make a website!")
/// }
/// }
/// }
/// }
/// ```
///
/// - SeeAlso: W3C [`hr`](https://html.spec.whatwg.org/multipage/grouping-content.html#the-hr-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct Divider: View {
/// Creates a divider view.
public init() {
}

@_documentation(visibility: private)
public func render(_ container: Element, environment: EnvironmentValues) throws {
_ = try container.appendElement("hr")
}
}
1 change: 0 additions & 1 deletion Sources/Slipstream/W3C/Elements/Scripting/Script.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public struct Script: View {

@_documentation(visibility: private)
public func render(_ container: Element, environment: EnvironmentValues) throws {

switch storage {
case .url(let url, let executionMode):
guard let url else {
Expand Down
3 changes: 3 additions & 0 deletions Tests/SlipstreamTests/Sites/CatalogSiteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private struct CatalogSite: View {
.textColor(.white)
.display(.hidden)

Divider()

Heading(level: 2, "Generic heading 2")
}
.background(.black)
Expand Down Expand Up @@ -107,6 +109,7 @@ struct CatalogSiteTests {
<h4 class="antialiased h-12 max-h-24 max-w-4 min-h-6 min-w-1 w-2">Heading 4</h4>
<h5 class="mx-auto">Heading 5</h5>
<h6 class="my-8 text-white hidden">Heading 6</h6>
<hr />
<h2>Generic heading 2</h2>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions Tests/SlipstreamTests/W3C/DividerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Testing

import Slipstream

struct DividerTests {
@Test func divider() throws {
try #expect(renderHTML(Divider()) == "<hr />")
}
}