2024-MacC-M14-Medio / SqoopDesignSystem / Sources / SQComponents / CustomComponents / SQPaginationDot.swift
SQPaginationDot.swift
Raw
//
//  SQPaginationDot.swift
//  SqoopDesignSystem
//
//  Created by  on 11/1/24.
//

import SwiftUI

public struct SQPaginationDot: View {
    
    public let pageCount: Int
    public let currentPage: Int
    
    public init(pageCount: Int, currentPage: Int) {
        self.pageCount = pageCount
        self.currentPage = currentPage
    }
    
    ///       
    private var maxPageCount: Int {
        return min(pageCount, 5)
    }
    
    public var body: some View {
        HStack(spacing: 16) {
            ForEach(0..<maxPageCount, id: \.self) { index in
                Dot(isActive: index == currentPage)
            }
        }
    }
}

// MARK: - SQPaginationDot

private struct Dot: View {
    
    let isActive: Bool
    
    /// Dot 
    private var size: CGFloat {
        return 10
    }
    
    var body: some View {
        Circle()
            .frame(width: size, height: size)
            .foregroundStyle(isActive ? Color.iconSkyBlue : Color.bgGrey250)
    }
}

// MARK: - Preivew

#Preview {
    SQPaginationDot(
        pageCount: 3,
        currentPage: 0
    )
}