-
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.
Add support for colspan and rowspan on TableCell. (#203)
- Loading branch information
Showing
3 changed files
with
29 additions
and
9 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
30 changes: 22 additions & 8 deletions
30
Sources/Slipstream/W3C/Elements/TabularData/TableCell.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 |
---|---|---|
@@ -1,16 +1,30 @@ | ||
import SwiftSoup | ||
|
||
/// 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 | ||
|
||
public struct TableCell<Content>: View where Content: View { | ||
/// Creates a table cell. | ||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
public init(rowSpan: Int? = nil, colSpan: Int? = nil, @ViewBuilder content: @escaping () -> Content) { | ||
self.content = content | ||
self.rowSpan = rowSpan | ||
self.colSpan = colSpan | ||
} | ||
|
||
@_documentation(visibility: private) | ||
public func render(_ container: Element, environment: EnvironmentValues) throws { | ||
let element = try container.appendElement("td") | ||
if let rowSpan { | ||
try element.attr("rowspan", "\(rowSpan)") | ||
} | ||
if let colSpan { | ||
try element.attr("colspan", "\(colSpan)") | ||
} | ||
try self.content().render(element, environment: environment) | ||
} | ||
|
||
@ViewBuilder private let content: () -> Content | ||
private let rowSpan: Int? | ||
private let colSpan: Int? | ||
} |
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