vds_ios/VDS/Components/TextLinkCaret/TextLinkCaret.swift
Matt Bruce ced2bec5c2 added TextLink/TextLinkCaret
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-11-01 15:13:11 -05:00

99 lines
2.7 KiB
Swift

//
// TextLinkCaret.swift
// VDS
//
// Created by Matt Bruce on 11/1/22.
//
import Foundation
import UIKit
import VDSColorTokens
import VDSFormControlsTokens
import Combine
public enum TextLinkIconPosition: String, CaseIterable {
case left, right
}
@objc(VDSTextLinkCaret)
open class TextLinkCaret: Control {
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var heightConstraint: NSLayoutConstraint?
private var label = Label()
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
open var text: String? { didSet { didChange() } }
open var iconPosition: TextLinkIconPosition = .right { didSet { didChange() } }
private var height: CGFloat {
44
}
//--------------------------------------------------
// 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 Functions
//--------------------------------------------------
open override func initialSetup() {
super.initialSetup()
}
open override func setup() {
super.setup()
addSubview(label)
//add tapGesture to self
publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in
self?.sendActions(for: .touchUpInside)
}.store(in: &subscribers)
//pin stackview to edges
label.topAnchor.constraint(equalTo: topAnchor).isActive = true
label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
label.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
heightAnchor.constraint(equalToConstant: height).isActive = true
}
open override func reset() {
super.reset()
accessibilityCustomActions = []
accessibilityTraits = .staticText
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open override func updateView() {
label.surface = surface
label.disabled = disabled
label.typograpicalStyle = TypographicalStyle.BoldBodyLarge
label.text = text ?? ""
}
}