@@ -69,7 +69,6 @@ struct CustomButton: View {
6969 case primary
7070 case secondary
7171 case tertiary
72- case accent
7372 }
7473
7574 let title : String
@@ -149,82 +148,40 @@ struct CustomButton: View {
149148 self . destination = AnyView ( destination)
150149 }
151150
152- private var backgroundColor : Color {
153- if isLoading {
154- return . gray6
155- }
156-
157- if isDisabled && icon != nil {
158- return . white06
159- }
160-
161- if isDisabled {
162- return . clear
163- }
164-
165- switch variant {
166- case . primary:
167- if isPressed {
168- return . white32
169- } else {
170- return . white16
171- }
172- case . secondary, . tertiary:
173- return . clear
174- case . accent:
175- if isPressed {
176- return . brandAccent. opacity ( 0.8 )
177- } else {
178- return . brandAccent
179- }
180- }
181- }
182-
183- private var foregroundColor : Color {
184- if isDisabled {
185- return . white32
186- }
187-
188- switch variant {
189- case . primary:
190- return . textPrimary
191- case . secondary, . tertiary:
192- if isPressed {
193- return . textPrimary
194- } else {
195- return . white80
196- }
197- case . accent:
198- return . white
199- }
200- }
201-
202- private var borderColor : Color ? {
203- if isDisabled {
204- return nil
205- }
206-
151+ private var buttonVariantView : some View {
207152 switch variant {
208153 case . primary:
209- return nil
154+ AnyView ( PrimaryButtonView (
155+ title: title,
156+ size: size,
157+ icon: icon,
158+ isDisabled: isDisabled,
159+ isLoading: isLoading,
160+ isPressed: isPressed,
161+ shouldExpand: shouldExpand
162+ ) )
210163 case . secondary:
211- if isPressed {
212- return . white32
213- } else {
214- return . white16
215- }
164+ AnyView ( SecondaryButtonView (
165+ title: title,
166+ size: size,
167+ icon: icon,
168+ isDisabled: isDisabled,
169+ isPressed: isPressed
170+ ) )
216171 case . tertiary:
217- return nil
218- case . accent:
219- return nil
172+ AnyView ( TertiaryButtonView (
173+ title: title,
174+ icon: icon,
175+ isPressed: isPressed
176+ ) )
220177 }
221178 }
222179
223180 var body : some View {
224181 Group {
225182 if let destination {
226183 NavigationLink ( destination: destination) {
227- buttonContent
184+ buttonVariantView
228185 }
229186 . buttonStyle (
230187 CustomButtonStyle (
@@ -252,7 +209,7 @@ struct CustomButton: View {
252209 await action ( )
253210 }
254211 } label: {
255- buttonContent
212+ buttonVariantView
256213 }
257214 . buttonStyle (
258215 CustomButtonStyle (
@@ -264,58 +221,11 @@ struct CustomButton: View {
264221 )
265222 . disabled ( isDisabled || isLoading)
266223 } else {
267- buttonContent
224+ buttonVariantView
268225 . opacity ( isDisabled ? 0.5 : 1 )
269226 }
270227 }
271228 }
272-
273- private var buttonContent : some View {
274- HStack ( spacing: 8 ) {
275- if let icon, !isLoading {
276- icon
277- }
278-
279- if isLoading {
280- ProgressView ( )
281- . progressViewStyle ( CircularProgressViewStyle ( tint: foregroundColor) )
282- . frame ( width: 20 , height: 20 )
283- } else {
284- if size == . small {
285- CaptionBText ( title, textColor: foregroundColor)
286- } else {
287- BodySSBText ( title, textColor: foregroundColor)
288- }
289- }
290- }
291- . frame ( maxWidth: size == . large || shouldExpand ? . infinity : nil )
292- . frame ( height: size. height)
293- . padding ( . horizontal, size. horizontalPadding)
294- . background ( backgroundColor)
295- . cornerRadius ( size. cornerRadius)
296- . overlay (
297- Group {
298- if let borderColor {
299- RoundedRectangle ( cornerRadius: size. cornerRadius)
300- . stroke ( borderColor, lineWidth: 2 )
301- }
302- }
303- )
304- . contentShape ( Rectangle ( ) )
305- }
306- }
307-
308- // UIViewRepresentable for UIKit blur effect
309- struct BackdropBlurView : UIViewRepresentable {
310- let radius : CGFloat
311-
312- func makeUIView( context: Context ) -> UIVisualEffectView {
313- return UIVisualEffectView ( effect: UIBlurEffect ( style: . systemUltraThinMaterial) )
314- }
315-
316- func updateUIView( _ uiView: UIVisualEffectView , context: Context ) {
317- uiView. effect = UIBlurEffect ( style: . systemUltraThinMaterial)
318- }
319229}
320230
321231#Preview {
0 commit comments