vds_ios/VDS/Components/Line/Line.swift
Matt Bruce 56c2217b0c public to open
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-08-04 16:01:38 -05:00

64 lines
1.9 KiB
Swift

//
// Line.swift
// VDS
//
// Created by Nadigadda, Sumanth on 24/03/23.
//
import Foundation
import UIKit
import VDSColorTokens
@objc(VDSLine)
open class Line: View {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum Style: String, CaseIterable {
case primary, secondary
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var lineView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
open var style: Style = .primary { didSet { setNeedsUpdate() } }
//--------------------------------------------------
// MARK: - Configuration
//--------------------------------------------------
open var lineViewColorConfiguration: AnyColorable = {
let config = KeyedColorConfiguration<Line, Style>(keyPath: \.style)
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forKey: .primary)
config.setSurfaceColors(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark, forKey: .secondary)
return config.eraseToAnyColorable()
}()
//--------------------------------------------------
// MARK: - Lifecycle
//--------------------------------------------------
open override func setup() {
super.setup()
addSubview(lineView)
lineView.height(1)
lineView.pinToSuperView()
}
/// Resets to default settings.
open override func reset() {
super.reset()
style = .primary
}
/// Function used to make changes to the View based off a change events or from local properties.
open override func updateView() {
lineView.backgroundColor = lineViewColorConfiguration.getColor(self)
}
}