-
Notifications
You must be signed in to change notification settings - Fork 395
/
Copy pathEnvironment+Table.swift
45 lines (39 loc) · 1.51 KB
/
Environment+Table.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
import SwiftUI
extension View {
/// Sets the table border style for the Markdown tables in a view hierarchy.
///
/// Use this modifier to customize the table border style inside the body of
/// the ``Theme/table`` block style.
///
/// - Parameter tableBorderStyle: The border style to set.
public func markdownTableBorderStyle(_ tableBorderStyle: TableBorderStyle) -> some View {
self.environment(\.tableBorderStyle, tableBorderStyle)
}
/// Sets the table background style for the Markdown tables in a view hierarchy.
///
/// Use this modifier to customize the table background style inside the body of
/// the ``Theme/table`` block style.
///
/// - Parameter tableBackgroundStyle: The background style to set.
public func markdownTableBackgroundStyle(
_ tableBackgroundStyle: TableBackgroundStyle
) -> some View {
self.environment(\.tableBackgroundStyle, tableBackgroundStyle)
}
}
extension EnvironmentValues {
var tableBorderStyle: TableBorderStyle {
get { self[TableBorderStyleKey.self] }
set { self[TableBorderStyleKey.self] = newValue }
}
var tableBackgroundStyle: TableBackgroundStyle {
get { self[TableBackgroundStyleKey.self] }
set { self[TableBackgroundStyleKey.self] = newValue }
}
}
private struct TableBorderStyleKey: EnvironmentKey {
static var defaultValue: TableBorderStyle { TableBorderStyle(color: .secondary) }
}
private struct TableBackgroundStyleKey: EnvironmentKey {
static var defaultValue: TableBackgroundStyle { TableBackgroundStyle.clear }
}