ExitButton icon indicating copy to clipboard operation
ExitButton copied to clipboard

Add ButtonStyle

Open webserveis opened this issue 2 years ago • 1 comments

Alternative from (SwiftUI padowan)

struct ExitButtonStyle: ButtonStyle {
    @Environment(\.colorScheme) var colorScheme
    
    func makeBody(configuration: Configuration) -> some View {
        let isPressed = configuration.isPressed
        
        return configuration.label
        
            .padding()
            .background(
                Circle()
                    .fill(Color(white: colorScheme == .dark ? 0.19 : 0.93))
                    //.brightness(isPressed ? 0.1 : 0) // Aclara el color cuando está presionado
                    .frame(width: 40, height: 40)
            )
            .overlay(
                Image(systemName: "xmark")
                    .resizable()
                    .scaledToFit()
                    .font(Font.body.weight(.bold))
                    .scaleEffect(0.416)
                    .foregroundColor(Color(white: colorScheme == .dark ? 0.62 : 0.51))
                    
            )     
            .buttonStyle(PlainButtonStyle())
            .opacity(isPressed ? 0.18 : 1)

    }
}

Usage:

Button(action: { print("exit") }) {
    Text("")
}.buttonStyle(ExitButtonStyle())

webserveis avatar Jun 15 '23 18:06 webserveis

Hey @webserveis! Nice addition. Would you mind turning this into a pull request?

joogps avatar Jul 24 '23 04:07 joogps