-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathTableBorderStyle.swift
91 lines (83 loc) · 2.69 KB
/
TableBorderStyle.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import SwiftUI
/// A type that represents the appearance of table borders.
///
/// To customize the table borders in a ``Markdown`` view, use the `markdownTableBorderStyle(_:)`
/// modifier inside the body of the ``Theme/table`` block style.
///
/// The following example customizes the table style to display only the outside borders with a dashed stroke style.
///
/// ```swift
/// Markdown {
/// """
/// | First Header | Second Header |
/// | ------------- | ------------- |
/// | Content Cell | Content Cell |
/// | Content Cell | Content Cell |
/// | Content Cell | Content Cell |
/// """
/// }
/// .markdownBlockStyle(\.table) { configuration in
/// configuration.label
/// .markdownTableBorderStyle(
/// TableBorderStyle(
/// .outsideBorders,
/// color: Color.mint,
/// strokeStyle: .init(lineWidth: 2, lineJoin: .round, dash: [4])
/// )
/// )
/// }
/// ```
///
/// 
public struct TableBorderStyle {
public struct Border {
/// The visible table borders.
public var visibleBorders: TableBorderSelector
/// The table border color.
public var color: Color
public init(visibleBorders: TableBorderSelector, color: Color) {
self.visibleBorders = visibleBorders
self.color = color
}
}
/// The table's list of borders
public var borders: [Border]
/// The table border stroke style.
public var strokeStyle: StrokeStyle
/// Creates a table border style with the given borders and stroke style.
/// - Parameters:
/// - borders: The visible table borders.
/// - strokeStyle: The table border stroke style.
public init(
_ borders: [Border],
strokeStyle: StrokeStyle
) {
self.borders = borders
self.strokeStyle = strokeStyle
}
/// Creates a table border style with the given visible borders, color, and stroke style.
/// - Parameters:
/// - visibleBorders: The visible table borders.
/// - color: The table border color.
/// - strokeStyle: The table border stroke style.
public init(
_ visibleBorders: TableBorderSelector = .allBorders,
color: Color,
strokeStyle: StrokeStyle
) {
self.borders = [.init(visibleBorders: visibleBorders, color: color)]
self.strokeStyle = strokeStyle
}
/// Creates a table border style with the given visible borders, color, and line width.
/// - Parameters:
/// - visibleBorders: The visible table borders.
/// - color: The table border color.
/// - width: The table border line width.
public init(
_ visibleBorders: TableBorderSelector = .allBorders,
color: Color,
width: CGFloat = 1
) {
self.init(visibleBorders, color: color, strokeStyle: .init(lineWidth: width))
}
}