85 lines
2.7 KiB
Swift
85 lines
2.7 KiB
Swift
//
|
|
// TrailingTooltipLabel.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 4/14/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import Combine
|
|
|
|
@objc(VDSTrailingTooltipLabel)
|
|
open class TrailingTooltipLabel: View {
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Private Properties
|
|
//--------------------------------------------------
|
|
private let toolTipAction = PassthroughSubject<Void, Never>()
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Properties
|
|
//--------------------------------------------------
|
|
open var label = Label()
|
|
|
|
open var labelText: String? { didSet { didChange() }}
|
|
|
|
open var labelTextStyle: TextStyle = .defaultStyle { didSet { didChange() }}
|
|
|
|
public lazy var textColorConfiguration: AnyColorable = {
|
|
label.textColorConfiguration
|
|
}() { didSet { didChange() }}
|
|
|
|
open var closeButtonText: String? = "Close" { didSet { didChange() }}
|
|
|
|
open var tooltipSize: Tooltip.Size = .medium { didSet { didChange() }}
|
|
|
|
open var tooltipTitle: String = "" { didSet { didChange() }}
|
|
|
|
open var tooltipContent: String = "" { didSet { didChange() }}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Overrides
|
|
//--------------------------------------------------
|
|
open override func setup() {
|
|
super.setup()
|
|
|
|
addSubview(label)
|
|
label.pinToSuperView()
|
|
|
|
//create the tooltip click event
|
|
toolTipAction.sink { [weak self] in
|
|
self?.showToolTip()
|
|
}.store(in: &subscribers)
|
|
}
|
|
|
|
open override func updateView() {
|
|
super.updateView()
|
|
|
|
var attributes: [any LabelAttributeModel] = []
|
|
var updatedLabelText = labelText
|
|
|
|
//add the tool tip
|
|
if let oldText = updatedLabelText {
|
|
let toolTipUpdateText = "\(oldText) " //create a little space between the final character and tooltip image
|
|
let toolTipAttribute = ToolTipLabelAttribute(action: toolTipAction,
|
|
location: toolTipUpdateText.count - 1,
|
|
length: 1,
|
|
tintColor: textColorConfiguration.getColor(self))
|
|
updatedLabelText = toolTipUpdateText
|
|
attributes.append(toolTipAttribute)
|
|
}
|
|
|
|
//set the titleLabel
|
|
label.text = updatedLabelText
|
|
label.attributes = attributes
|
|
label.textStyle = labelTextStyle
|
|
label.surface = surface
|
|
label.disabled = disabled
|
|
}
|
|
|
|
private func showToolTip(){
|
|
print("You should show the tooltip now!")
|
|
}
|
|
}
|