aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgEditor/EnvironmentValues+EditorTheme.swift
blob: f0bc3c5df364fb39113b4ac43b04474ffa8aefab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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