components: added reusable gradient button style
This commit is contained in:
committed by
William Casarin
parent
dfd1032cd8
commit
90c22fdabd
45
damus/Components/GradientButtonStyle.swift
Normal file
45
damus/Components/GradientButtonStyle.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// GradientButtonStyle.swift
|
||||
// damus
|
||||
//
|
||||
// Created by eric on 5/20/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct GradientButtonStyle: ButtonStyle {
|
||||
func makeBody(configuration: Self.Configuration) -> some View {
|
||||
return configuration.label
|
||||
.padding()
|
||||
.foregroundColor(Color.white)
|
||||
.background {
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(PinkGradient.gradient)
|
||||
}
|
||||
.scaleEffect(configuration.isPressed ? 0.8 : 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct GradientButtonStyle_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
Button("Dynamic Size", action: {
|
||||
print("dynamic size")
|
||||
})
|
||||
.buttonStyle(GradientButtonStyle())
|
||||
|
||||
|
||||
Button(action: {
|
||||
print("infinite width")
|
||||
}) {
|
||||
HStack {
|
||||
Text("Infinite Width")
|
||||
}
|
||||
.frame(minWidth: 300, maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
.buttonStyle(GradientButtonStyle())
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user