-
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
116 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
Sources/Slipstream/W3C/Elements/GroupingContent/List.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,42 @@ | ||
/// A view that represents a list of items. | ||
/// | ||
/// The items can be ordered, where changing the order would | ||
/// change the meaning of the document, or unordered, where | ||
/// the order of the items is not important. | ||
/// | ||
/// Lists are unordered by default. | ||
/// | ||
/// ```swift | ||
/// struct MySiteContent: View { | ||
/// var body: some View { | ||
/// Body { | ||
/// List { | ||
/// ListItem { | ||
/// Text("Item 1") | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [`ol`](https://html.spec.whatwg.org/multipage/grouping-content.html#the-ol-element) specification. | ||
/// - SeeAlso: W3C [`ul`](https://html.spec.whatwg.org/multipage/grouping-content.html#the-ul-element) specification. | ||
/// | ||
/// ## See Also | ||
/// | ||
/// - ``ListItem`` | ||
public struct List<Content>: W3CElement where Content: View { | ||
@_documentation(visibility: private) | ||
public var tagName: String { ordered ? "ol" : "ul" } | ||
|
||
/// Creates a list. | ||
public init(ordered: Bool = false, @ViewBuilder content: @escaping () -> Content) { | ||
self.ordered = ordered | ||
self.content = content | ||
} | ||
|
||
@_documentation(visibility: private) | ||
@ViewBuilder public let content: () -> Content | ||
private let ordered: Bool | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/Slipstream/W3C/Elements/GroupingContent/Listitem.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,33 @@ | ||
/// A view that represents a list item. | ||
/// | ||
/// ```swift | ||
/// struct MySiteContent: View { | ||
/// var body: some View { | ||
/// Body { | ||
/// List { | ||
/// ListItem { | ||
/// Text("Item 1") | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [`li`](https://html.spec.whatwg.org/multipage/grouping-content.html#the-li-element) specification. | ||
/// | ||
/// ## See Also | ||
/// | ||
/// - ``List`` | ||
public struct ListItem<Content>: W3CElement where Content: View { | ||
@_documentation(visibility: private) | ||
public let tagName: String = "li" | ||
|
||
/// Creates a list item. | ||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
self.content = content | ||
} | ||
|
||
@_documentation(visibility: private) | ||
@ViewBuilder public let 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,39 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct ListTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(List {}) == "<ul></ul>") | ||
try #expect(renderHTML(List(ordered: true) {}) == "<ol></ol>") | ||
} | ||
|
||
@Test func withItems() throws { | ||
try #expect(renderHTML(List { | ||
ListItem { | ||
Text("Item 1") | ||
} | ||
ListItem { | ||
Text("Item 2") | ||
} | ||
}) == """ | ||
<ul> | ||
<li>Item 1</li> | ||
<li>Item 2</li> | ||
</ul> | ||
""") | ||
try #expect(renderHTML(List(ordered: true) { | ||
ListItem { | ||
Text("Item 1") | ||
} | ||
ListItem { | ||
Text("Item 2") | ||
} | ||
}) == """ | ||
<ol> | ||
<li>Item 1</li> | ||
<li>Item 2</li> | ||
</ol> | ||
""") | ||
} | ||
} |