vds_ios/VDS/Components/Pagination/PaginationCellItem.swift
2024-03-05 16:48:26 +05:30

52 lines
1.6 KiB
Swift

//
// PaginationCellItem.swift
// VDS
//
// Created by Bandaru, Krishna Kishore on 05/03/24.
//
import UIKit
import VDSColorTokens
final class PaginationCellItem: UICollectionViewCell {
static let identifier: String = String(describing: PaginationCellItem.self)
private let textColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
private var indexLabel: Label = Label().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textAlignment = .center
$0.numberOfLines = 1
}
override init(frame: CGRect) {
super.init(frame: frame)
setUp()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setUp()
}
private func setUp() {
let containerView = View()
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(indexLabel)
contentView.addSubview(containerView)
containerView.pinToSuperView()
indexLabel.pinToSuperView()
indexLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: VDSLayout.Spacing.space5X.value).activate()
contentView.backgroundColor = .clear
containerView.backgroundColor = .clear
indexLabel.backgroundColor = .clear
}
func update(_ selectedIndex: Int, currentIndex: Int, surface: Surface) {
indexLabel.textStyle = selectedIndex == currentIndex ? .boldBodySmall : .bodySmall
indexLabel.text = "\(currentIndex + 1)"
indexLabel.textColor = textColorConfiguration.getColor(surface)
}
}