vds_ios/VDS/Components/Buttons/TextLink/TextLink.swift
Matt Bruce 6f7fb965e5 removed view and added line
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-08-21 13:25:21 -05:00

104 lines
3.0 KiB
Swift

//
// TextLink.swift
// VDS
//
// Created by Matt Bruce on 11/1/22.
//
import Foundation
import UIKit
import VDSColorTokens
import VDSFormControlsTokens
import Combine
@objc(VDSTextLink)
open class TextLink: ButtonBase {
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var lineHeightConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
open var size: ButtonSize = .large { didSet { setNeedsUpdate() }}
open override var availableSizes: [ButtonSize] { [.large, .small] }
open override var textStyle: TextStyle {
size == .large ? TextStyle.bodyLarge : TextStyle.bodySmall
}
open override var textColor: UIColor {
textColorConfiguration.getColor(self)
}
private var textColorConfiguration = ControlColorConfiguration().with {
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
}
private var height: CGFloat {
switch size {
case .large:
return 44
case .small:
return 32
}
}
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
}
public override init(frame: CGRect) {
super.init(frame: .zero)
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------
open override func setup() {
super.setup()
isAccessibilityElement = true
accessibilityTraits = .link
if let titleLabel {
titleLabel.debugBorder(show: true)
}
}
/// Resets to default settings.
open override func reset() {
super.reset()
shouldUpdateView = false
text = nil
size = .large
accessibilityCustomActions = []
isAccessibilityElement = true
accessibilityTraits = .link
shouldUpdateView = true
setNeedsUpdate()
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open override var intrinsicContentSize: CGSize {
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
}
open override func layoutSubviews() {
super.layoutSubviews()
addBorder(side: .bottom, width: 1, color: textColor)
}
}