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 basic Table elements. #167

Merged
merged 3 commits into from
Aug 17, 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
2 changes: 1 addition & 1 deletion .github/workflows/package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Select Xcode
run: sudo xcode-select -s "/Applications/Xcode_16_beta_4.app"
run: sudo xcode-select -s "/Applications/Xcode_16_beta_5.app"
- name: Get swift version
run: swift --version
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips

W3C tag | Slipstream view
:--------|:----------------
[`<table>`](https://html.spec.whatwg.org/multipage/sections.html#the-table-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<table>`](https://html.spec.whatwg.org/multipage/sections.html#the-table-element) | ``Table``
[`<caption>`](https://html.spec.whatwg.org/multipage/sections.html#the-caption-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<colgroup>`](https://html.spec.whatwg.org/multipage/sections.html#the-colgroup-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<col>`](https://html.spec.whatwg.org/multipage/sections.html#the-col-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<tbody>`](https://html.spec.whatwg.org/multipage/sections.html#the-tbody-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<thead>`](https://html.spec.whatwg.org/multipage/sections.html#the-thead-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<tbody>`](https://html.spec.whatwg.org/multipage/sections.html#the-tbody-element) | ``TableBody``
[`<thead>`](https://html.spec.whatwg.org/multipage/sections.html#the-thead-element) | ``TableHeader``
[`<tfoot>`](https://html.spec.whatwg.org/multipage/sections.html#the-tfoot-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<tr>`](https://html.spec.whatwg.org/multipage/sections.html#the-tr-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<td>`](https://html.spec.whatwg.org/multipage/sections.html#the-td-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<th>`](https://html.spec.whatwg.org/multipage/sections.html#the-th-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<tr>`](https://html.spec.whatwg.org/multipage/sections.html#the-tr-element) | ``TableRow``
[`<td>`](https://html.spec.whatwg.org/multipage/sections.html#the-td-element) | ``TableCell``
[`<th>`](https://html.spec.whatwg.org/multipage/sections.html#the-th-element) | ``TableHeaderCell``

### Forms

Expand Down
9 changes: 9 additions & 0 deletions Sources/Slipstream/Documentation.docc/W3C/W3CViews.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh
- ``Image``
- ``RawHTML``

### Tabular data

- ``Table``
- ``TableHeader``
- ``TableHeaderCell``
- ``TableBody``
- ``TableRow``
- ``TableCell``

### Forms

- ``Form``
Expand Down
29 changes: 29 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/Table.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// A view that represents data with more than one dimension, in
/// the form of a table.
///
/// ```swift
/// struct MySiteContent: View {
/// var body: some View {
/// Body {
/// Table {
/// DOMString("Hello, world!")
/// }
/// }
/// }
/// }
/// ```
///
/// - SeeAlso: W3C [table](https://html.spec.whatwg.org/multipage/tables.html#the-table-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct Table<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "table"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
18 changes: 18 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/TableBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// A view that represents a block of rows that consist of a body of
/// data for the parent table view, if the ``TableBody`` has a
/// parent and it is a table.
///
/// - SeeAlso: W3C [tbody](https://html.spec.whatwg.org/multipage/tables.html#the-tbody-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct TableBody<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "tbody"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table body.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
16 changes: 16 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// A view that represents a data cell in a table.
///
/// - SeeAlso: W3C [td](https://html.spec.whatwg.org/multipage/tables.html#the-td-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct TableCell<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "td"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table cell.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
18 changes: 18 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/TableHeader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// A view that represents the block of rows that consist of the column
/// labels (headers) and any ancillary non-header cells for the parent
/// table element, if the view has a parent and it is a table.
///
/// - SeeAlso: W3C [thead](https://html.spec.whatwg.org/multipage/tables.html#the-thead-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct TableHeader<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "thead"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table header.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
16 changes: 16 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/TableHeaderCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// A view that represents a header cell in a table.
///
/// - SeeAlso: W3C [th](https://html.spec.whatwg.org/multipage/tables.html#the-th-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct TableHeaderCell<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "th"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table header cell.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
16 changes: 16 additions & 0 deletions Sources/Slipstream/W3C/Elements/TabularData/TableRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// A view that represents a row of cells in a table.
///
/// - SeeAlso: W3C [tr](https://html.spec.whatwg.org/multipage/tables.html#the-tr-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct TableRow<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "tr"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a table row.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableBodyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct TableBodyTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(TableBody {}) == "<tbody></tbody>")
}

@Test func withText() throws {
try #expect(renderHTML(TableBody {
DOMString("Hello, world!")
}) == """
<tbody>
Hello, world!
</tbody>
""")
}
}
17 changes: 17 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Testing

import Slipstream

struct TableCellTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(TableCell {}) == "<td></td>")
}

@Test func withText() throws {
try #expect(renderHTML(TableCell {
DOMString("Hello, world!")
}) == """
<td>Hello, world!</td>
""")
}
}
17 changes: 17 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableHeaderCellTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Testing

import Slipstream

struct TableHeaderCellTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(TableHeaderCell {}) == "<th></th>")
}

@Test func withText() throws {
try #expect(renderHTML(TableHeaderCell {
DOMString("Hello, world!")
}) == """
<th>Hello, world!</th>
""")
}
}
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableHeaderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct TableHeaderTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(TableHeader {}) == "<thead></thead>")
}

@Test func withText() throws {
try #expect(renderHTML(TableHeader {
DOMString("Hello, world!")
}) == """
<thead>
Hello, world!
</thead>
""")
}
}
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableRowTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct TableRowTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(TableRow {}) == "<tr></tr>")
}

@Test func withText() throws {
try #expect(renderHTML(TableRow {
DOMString("Hello, world!")
}) == """
<tr>
Hello, world!
</tr>
""")
}
}
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/TabularData/TableTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct TableTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(Table {}) == "<table></table>")
}

@Test func withText() throws {
try #expect(renderHTML(Table {
DOMString("Hello, world!")
}) == """
<table>
Hello, world!
</table>
""")
}
}