File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed
Sources/Slipstream/W3C/Elements/TabularData
Tests/SlipstreamTests/W3C/TabularData Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change 11
11
runs-on : macos-latest
12
12
steps :
13
13
- name : Select Xcode
14
- run : sudo xcode-select -s "/Applications/Xcode_16.1_beta. app"
14
+ run : sudo xcode-select -s "/Applications/Xcode_16.app"
15
15
- name : Get swift version
16
16
run : swift --version
17
17
- uses : actions/checkout@v4
Original file line number Diff line number Diff line change
1
+ import SwiftSoup
2
+
1
3
/// A view that represents a data cell in a table.
2
4
///
3
5
/// - SeeAlso: W3C [td](https://html.spec.whatwg.org/multipage/tables.html#the-td-element) specification.
4
6
@available ( iOS 17 . 0 , macOS 14 . 0 , * )
5
- public struct TableCell < Content> : W3CElement where Content: View {
6
- @_documentation ( visibility: private)
7
- public let tagName : String = " td "
8
-
9
- @_documentation ( visibility: private)
10
- @ViewBuilder public let content : ( ) -> Content
11
-
7
+ public struct TableCell < Content> : View where Content: View {
12
8
/// Creates a table cell.
13
- public init ( @ViewBuilder content: @escaping ( ) -> Content ) {
9
+ public init ( rowSpan : Int ? = nil , colSpan : Int ? = nil , @ViewBuilder content: @escaping ( ) -> Content ) {
14
10
self . content = content
11
+ self . rowSpan = rowSpan
12
+ self . colSpan = colSpan
15
13
}
14
+
15
+ @_documentation ( visibility: private)
16
+ public func render( _ container: Element , environment: EnvironmentValues ) throws {
17
+ let element = try container. appendElement ( " td " )
18
+ if let rowSpan {
19
+ try element. attr ( " rowspan " , " \( rowSpan) " )
20
+ }
21
+ if let colSpan {
22
+ try element. attr ( " colspan " , " \( colSpan) " )
23
+ }
24
+ try self . content ( ) . render ( element, environment: environment)
25
+ }
26
+
27
+ @ViewBuilder private let content : ( ) -> Content
28
+ private let rowSpan : Int ?
29
+ private let colSpan : Int ?
16
30
}
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ struct TableCellTests {
7
7
try #expect( renderHTML ( TableCell { } ) == " <td></td> " )
8
8
}
9
9
10
+ @Test func spans( ) throws {
11
+ try #expect( renderHTML ( TableCell ( rowSpan: 2 ) { } ) == #"<td rowspan="2"></td>"# )
12
+ try #expect( renderHTML ( TableCell ( colSpan: 3 ) { } ) == #"<td colspan="3"></td>"# )
13
+ try #expect( renderHTML ( TableCell ( rowSpan: 2 , colSpan: 4 ) { } ) == #"<td rowspan="2" colspan="4"></td>"# )
14
+ }
15
+
10
16
@Test func withText( ) throws {
11
17
try #expect( renderHTML ( TableCell {
12
18
DOMString ( " Hello, world! " )
You can’t perform that action at this time.
0 commit comments