7
7
8
8
import SwiftUI
9
9
10
- struct EditorToolBarView : View {
10
+ public struct EditorToolBarView : View {
11
+ @Environment ( \. colorScheme) var colorScheme
12
+
11
13
@ObservedObject var state : RichEditorState
12
14
13
- var body : some View {
15
+ var selectedColor : Color {
16
+ colorScheme == . dark ? . white. opacity ( 0.3 ) : . gray. opacity ( 0.1 )
17
+ }
18
+
19
+ public init ( state: RichEditorState ) {
20
+ self . state = state
21
+ }
22
+
23
+ public var body : some View {
14
24
LazyHStack ( spacing: 5 , content: {
15
25
ForEach ( EditorTool . allCases, id: \. self) { tool in
16
26
if tool. isContainManu {
@@ -21,12 +31,15 @@ struct EditorToolBarView: View {
21
31
}
22
32
} )
23
33
. frame ( height: 50 )
34
+ . padding ( . horizontal, 15 )
24
35
. frame ( maxWidth: . infinity, alignment: . leading)
25
- . background ( Color . gray. opacity ( 0.1 ) )
36
+ . background ( selectedColor)
37
+ . clipShape ( . capsule)
26
38
}
27
39
}
28
40
29
41
private struct ToggleStyleButton : View {
42
+ @Environment ( \. colorScheme) var colorScheme
30
43
31
44
let tool : EditorTool
32
45
let appliedTools : Set < TextSpanStyle >
@@ -36,6 +49,13 @@ private struct ToggleStyleButton: View {
36
49
tool. isSelected ( appliedTools)
37
50
}
38
51
52
+ var normalDarkColor : Color {
53
+ colorScheme == . dark ? . white : . black
54
+ }
55
+
56
+ var selectedColor : Color {
57
+ colorScheme == . dark ? . gray. opacity ( 0.4 ) : . gray. opacity ( 0.1 )
58
+ }
39
59
40
60
var body : some View {
41
61
Button ( action: {
@@ -45,15 +65,18 @@ private struct ToggleStyleButton: View {
45
65
Image ( systemName: tool. systemImageName)
46
66
. font ( . title)
47
67
} )
48
- . foregroundColor ( isSelected ? . blue : . black)
49
- . frame ( width: 45 , height: 50 , alignment: . center)
50
- . padding ( . horizontal, 3 )
51
- . background ( isSelected ? Color . gray. opacity ( 0.1 ) : Color . clear)
68
+ . foregroundColor ( isSelected ? . blue : normalDarkColor)
69
+ . frame ( width: 40 , height: 40 , alignment: . center)
70
+ . background ( isSelected ? selectedColor : Color . clear)
71
+ . cornerRadius ( 5 )
72
+ . padding ( . vertical, 5 )
52
73
} )
53
74
}
54
75
}
55
76
56
77
struct TitleStyleButton : View {
78
+ @Environment ( \. colorScheme) var colorScheme
79
+
57
80
let tool : EditorTool
58
81
let appliedTools : Set < TextSpanStyle >
59
82
let setStyle : ( TextSpanStyle ) -> Void
@@ -64,6 +87,10 @@ struct TitleStyleButton: View {
64
87
65
88
@State var isExpanded : Bool = false
66
89
90
+ var normalDarkColor : Color {
91
+ colorScheme == . dark ? . white : . black
92
+ }
93
+
67
94
var body : some View {
68
95
69
96
Menu ( content: {
@@ -74,7 +101,7 @@ struct TitleStyleButton: View {
74
101
} , label: {
75
102
if hasStyle ( header. getTextSpanStyle ( ) ) {
76
103
Label ( header. title, systemImage: " checkmark " )
77
- . foregroundColor ( . blue )
104
+ . foregroundColor ( normalDarkColor )
78
105
} else {
79
106
Text ( header. title)
80
107
}
@@ -88,10 +115,12 @@ struct TitleStyleButton: View {
88
115
Image ( systemName: " chevron.down " )
89
116
. font ( . subheadline)
90
117
} )
91
- . foregroundColor ( isSelected ? . blue : . black )
92
- . frame ( width: 60 , height: 50 , alignment: . center)
118
+ . foregroundColor ( isSelected ? . blue : normalDarkColor )
119
+ . frame ( width: 50 , height: 40 , alignment: . center)
93
120
. padding ( . horizontal, 3 )
94
121
. background ( isSelected ? Color . gray. opacity ( 0.1 ) : Color . clear)
122
+ . cornerRadius ( 5 )
123
+ . padding ( . vertical, 5 )
95
124
} )
96
125
. onTapGesture {
97
126
isExpanded. toggle ( )
0 commit comments