diff options
Diffstat (limited to 'Sources/NorgEditor/EnvironmentValues+EditorTheme.swift')
| -rw-r--r-- | Sources/NorgEditor/EnvironmentValues+EditorTheme.swift | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Sources/NorgEditor/EnvironmentValues+EditorTheme.swift b/Sources/NorgEditor/EnvironmentValues+EditorTheme.swift new file mode 100644 index 0000000..f0bc3c5 --- /dev/null +++ b/Sources/NorgEditor/EnvironmentValues+EditorTheme.swift @@ -0,0 +1,21 @@ +#if canImport(UIKit) || canImport(AppKit) + import SwiftUI + + private struct NorgEditorThemeKey: EnvironmentKey { + static let defaultValue = EditorTheme.default + } + + /// Makes NorgTheme values accessible via the environment. + extension EnvironmentValues { + public var norgEditorTheme: EditorTheme { + get { self[NorgEditorThemeKey.self] } + set { self[NorgEditorThemeKey.self] = newValue } + } + } + + extension View { + public func norgEditorTheme(_ theme: EditorTheme) -> some View { + environment(\.norgEditorTheme, theme) + } + } +#endif |