2024-MacC-M14-Medio / SqoopDesignSystem / Sources / SQComponents / SQViews / SQToggle.swift
SQToggle.swift
Raw
//
//  SQToggle.swift
//  SqoopDesignSystem
//
//  Created by  on 11/23/24.
//

import SwiftUI

///    Toggle.
struct SQToggle: View {
    @Binding var isOn: Bool
    
    var body: some View {
        HStack {
            Spacer()
            Button {
                withAnimation {
                    isOn.toggle()
                }
            } label: {
                RoundedRectangle(cornerSize: CGSize(width: 100, height: 100))
                    .frame(width: 51, height: 31)
                    .foregroundColor(isOn ? .bgPrimary : .bgGrey2)
                    .overlay(
                        Circle()
                            .frame(width: 27, height: 27)
                            .foregroundColor(.white)
                            .offset(x: isOn ? 10 : -10)
                            .animation(.easeInOut, value: isOn)
                    )
            }
            .buttonStyle(PlainButtonStyle())
        }
    }
}