@@ -19,6 +19,141 @@ struct CategoryMembershipItems: View {
1919 }
2020}
2121
22+ struct CategoryPickerButton : View {
23+ @ EnvironmentObject private var preferences : AppPreferences
24+ let app : AppEntry
25+ @ ObservedObject var store : CustomCategoryStore
26+ let onCreate : ( ) -> Void
27+ @ State private var isPresented = false
28+
29+ var body : some View {
30+ Button {
31+ isPresented . toggle ( )
32+ } label : {
33+ Label ( preferences . text ( " category.addTo " ) , systemImage : " folder.badge.plus " )
34+ }
35+ . buttonStyle ( IconButtonStyle ( ) )
36+ . help ( preferences . text ( " category.addTo " ) )
37+ . accessibilityLabel ( preferences . text ( " category.addTo " ) )
38+ . popover ( isPresented : $isPresented , arrowEdge : . top ) {
39+ CategoryPickerPanel ( app : app , store : store ) {
40+ isPresented = false
41+ onCreate ( )
42+ }
43+ }
44+ }
45+ }
46+
47+ private struct CategoryPickerPanel : View {
48+ @ EnvironmentObject private var preferences : AppPreferences
49+ let app : AppEntry
50+ @ ObservedObject var store : CustomCategoryStore
51+ let onCreate : ( ) -> Void
52+
53+ var body : some View {
54+ VStack ( alignment : . leading , spacing : 12 ) {
55+ Text ( preferences . text ( " category.addTo " ) )
56+ . font ( . callout . weight ( . semibold ) )
57+ . foregroundStyle ( . primary )
58+
59+ if store . categories . isEmpty {
60+ Text ( preferences . text ( " category.editorHelp " ) )
61+ . font ( . caption ) . foregroundStyle ( . secondary )
62+ } else {
63+ VStack ( spacing : 5 ) {
64+ ForEach ( store . categories ) { category in
65+ CategoryPickerRow (
66+ app : app ,
67+ category : category ,
68+ isSelected : store . contains ( app , in : category )
69+ ) {
70+ store . setMembership (
71+ app ,
72+ in : category ,
73+ included : ! store . contains ( app , in : category )
74+ )
75+ }
76+ }
77+ }
78+ }
79+
80+ Divider ( )
81+
82+ Button ( action : onCreate ) {
83+ HStack ( spacing : 8 ) {
84+ Image ( systemName : " plus.circle.fill " )
85+ Text ( preferences . text ( " category.new " ) )
86+ . font ( . callout . weight ( . medium ) )
87+ Spacer ( minLength : 0 )
88+ }
89+ . foregroundStyle ( Color . accentColor )
90+ . padding ( . horizontal , 10 )
91+ . padding ( . vertical , 8 )
92+ . background ( Color . accentColor . opacity ( 0.08 ) , in : RoundedRectangle ( cornerRadius : 8 ) )
93+ . contentShape ( RoundedRectangle ( cornerRadius : 8 ) )
94+ }
95+ . buttonStyle ( . plain )
96+ . accessibilityLabel ( preferences . text ( " category.new " ) )
97+ }
98+ . padding ( 14 )
99+ . frame ( width : 272 )
100+ . background ( Color ( nsColor : . controlBackgroundColor ) , in : RoundedRectangle ( cornerRadius : 12 ) )
101+ . overlay {
102+ RoundedRectangle ( cornerRadius : 12 )
103+ . strokeBorder ( Color . primary . opacity ( 0.07 ) , lineWidth : 1 )
104+ . allowsHitTesting ( false )
105+ }
106+ }
107+ }
108+
109+ private struct CategoryPickerRow : View {
110+ let app : AppEntry
111+ let category : CustomAppCategory
112+ let isSelected : Bool
113+ let action : ( ) -> Void
114+ @ State private var isHovering = false
115+
116+ private var emblemTint : Color { isSelected ? . accentColor : . secondary }
117+
118+ var body : some View {
119+ Button ( action : action ) {
120+ HStack ( spacing : 9 ) {
121+ Image ( systemName : isSelected ? " folder.fill " : " folder " )
122+ . font ( . system ( size : 11 , weight : . semibold ) )
123+ . foregroundStyle ( emblemTint )
124+ . frame ( width : 22 , height : 22 )
125+ . background ( emblemTint . opacity ( 0.10 ) , in : RoundedRectangle ( cornerRadius : 6 ) )
126+
127+ Text ( category . name )
128+ . font ( . callout . weight ( isSelected ? . medium : . regular ) )
129+ . foregroundStyle ( . primary )
130+ . lineLimit ( 1 )
131+
132+ Spacer ( minLength : 8 )
133+
134+ Image ( systemName : " checkmark " )
135+ . font ( . system ( size : 11 , weight : . semibold ) )
136+ . foregroundStyle ( Color . accentColor )
137+ . opacity ( isSelected ? 1 : 0 )
138+ }
139+ . padding ( . horizontal , 9 )
140+ . padding ( . vertical , 7 )
141+ . background (
142+ RoundedRectangle ( cornerRadius : 8 )
143+ . fill ( isSelected ? Color . accentColor . opacity ( isHovering ? 0.13 : 0.09 )
144+ : Color . primary . opacity ( isHovering ? 0.05 : 0.02 ) )
145+ )
146+ . contentShape ( RoundedRectangle ( cornerRadius : 8 ) )
147+ }
148+ . buttonStyle ( . plain )
149+ . onHover { isHovering = $0 }
150+ . animation ( . easeOut ( duration : 0.16 ) , value : isHovering )
151+ . animation ( . easeOut ( duration : 0.16 ) , value : isSelected )
152+ . accessibilityLabel ( category . name )
153+ . accessibilityValue ( isSelected ? " 1 " : " 0 " )
154+ }
155+ }
156+
22157struct CategoryEditor : View {
23158 @ EnvironmentObject private var preferences : AppPreferences
24159 @ Environment ( \. dismiss ) private var dismiss
0 commit comments