vds_ios/VDS/Components/Tilet/Tilet.swift
Matt Bruce a340598861 updating to fix for height
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-12-20 12:04:44 -06:00

138 lines
4.2 KiB
Swift

//
// Tilet.swift
// VDS
//
// Created by Matt Bruce on 12/19/22.
//
import Foundation
import Foundation
import VDSColorTokens
import UIKit
public enum TiletTitleTypographicalStyle: String, Codable, EnumSubset {
case TitleXLarge
case BoldTitleXLarge
case TitleLarge
case BoldTitleLarge
case TitleMedium
case BoldTitleMedium
case TitleSmall
case BoldTitleSmall
public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall }
}
public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset {
case BodyLarge
case BoldBodyLarge
case BodyMedium
case BoldBodyMedium
case BodySmall
case BoldBodySmall
public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall }
}
@objc(VDSTilet)
open class Tilet: TileContainer {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
initialSetup()
}
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
initialSetup()
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
private var titleLockup = TitleLockup()
open override var surface: Surface {
didSet {
//flip the color
let flippedColor:ContainerBackgroundColor = surface == .dark ? .white : .black
containerBackgroundColor = flippedColor
//flip the surface for the titleLockup
let flippedSurface: Surface = surface == .dark ? .light : .dark
titleLockup.surface = flippedSurface
}
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
//style
open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }}
open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }}
//text
open var titleText: String = "" { didSet { didChange() }}
open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var subTitleText: String = "" { didSet { didChange() }}
open var subTitleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var subTitleColor: Use = .primary { didSet { didChange() }}
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
internal var contentViewWithConstraint: NSLayoutConstraint?
//functions
//--------------------------------------------------
// MARK: - Lifecycle
//--------------------------------------------------
open override func setup() {
super.setup()
aspectRatio = .none
surface = .light
addContentView(titleLockup)
contentViewWithConstraint = titleLockup.widthAnchor.constraint(equalToConstant: width - (padding * 2))
contentViewWithConstraint?.isActive = true
}
public override func reset() {
super.reset()
titleLockup.reset()
titleText = ""
titleTextAttributes = nil
subTitleText = ""
subTitleTextAttributes = nil
subTitleColor = .primary
}
//--------------------------------------------------
// MARK: - State
//--------------------------------------------------
open override func updateView() {
super.updateView()
contentViewWithConstraint?.constant = width - (padding * 2)
titleLockup.titleText = titleText
titleLockup.titleTypograpicalStyle = titleTypograpicalStyle.value
titleLockup.titleTextAttributes = titleTextAttributes
titleLockup.subTitleText = subTitleText
titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value
titleLockup.subTitleTextAttributes = titleTextAttributes
titleLockup.subTitleColor = subTitleColor
}
}