diff --git a/VDS/Components/Tooltip/ToolTipLaunchable.swift b/VDS/Components/Tooltip/ToolTipLaunchable.swift index 4305ee16..6a79e987 100644 --- a/VDS/Components/Tooltip/ToolTipLaunchable.swift +++ b/VDS/Components/Tooltip/ToolTipLaunchable.swift @@ -6,3 +6,22 @@ // import Foundation +import UIKit + +public protocol TooltipLaunchable { } + +extension TooltipLaunchable { + public func presentTooltip(surface: Surface, title: String, content: String, closeButtonText: String = "Close") { + if let presenting = UIApplication.topViewController() { + let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with { + $0.surface = surface + $0.titleText = title + $0.contentText = content + $0.closeButtonText = closeButtonText + $0.modalPresentationStyle = .overCurrentContext + $0.modalTransitionStyle = .crossDissolve + } + presenting.present(tooltipViewController, animated: true) + } + } +} diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index bb48a059..a3b3e612 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -12,7 +12,7 @@ import VDSFormControlsTokens import Combine @objc(VDSTooltip) -open class Tooltip: Control { +open class Tooltip: Control, TooltipLaunchable { //-------------------------------------------------- // MARK: - Enums @@ -117,7 +117,10 @@ open class Tooltip: Control { onClickSubscriber = publisher(for: .touchUpInside) .sink(receiveValue: { [weak self] tooltip in guard let self else { return} - self.presentTooltip() + self.presentTooltip(surface: tooltip.surface, + title: tooltip.title, + content: tooltip.content, + closeButtonText: tooltip.closeButtonText) }) } @@ -146,17 +149,4 @@ open class Tooltip: Control { accessibilityLabel = "Tooltip: \(title)" } - private func presentTooltip() { - if let presenting = UIApplication.topViewController() { - let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with { - $0.surface = surface - $0.titleText = title - $0.contentText = content - $0.closeButtonText = closeButtonText - $0.modalPresentationStyle = .overCurrentContext - $0.modalTransitionStyle = .crossDissolve - } - presenting.present(tooltipViewController, animated: true) - } - } } diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 0714ad04..26b29620 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -10,7 +10,7 @@ import UIKit import Combine @objc(VDSTrailingTooltipLabel) -open class TrailingTooltipLabel: View { +open class TrailingTooltipLabel: View, TooltipLaunchable { //-------------------------------------------------- // MARK: - Private Properties @@ -23,14 +23,16 @@ open class TrailingTooltipLabel: View { open var label = Label() open var labelText: String? { didSet { didChange() }} - + + open var labelAttributes: [any LabelAttributeModel]? { 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 closeButtonText: String = "Close" { didSet { didChange() }} open var tooltipSize: Tooltip.Size = .medium { didSet { didChange() }} @@ -49,7 +51,11 @@ open class TrailingTooltipLabel: View { //create the tooltip click event toolTipAction.sink { [weak self] in - self?.showToolTip() + guard let self else { return } + self.presentTooltip(surface: self.surface, + title: self.tooltipTitle, + content: self.tooltipContent, + closeButtonText: self.closeButtonText) }.store(in: &subscribers) } @@ -57,6 +63,10 @@ open class TrailingTooltipLabel: View { super.updateView() var attributes: [any LabelAttributeModel] = [] + if let labelAttributes { + attributes.append(contentsOf: labelAttributes) + } + var updatedLabelText = labelText //add the tool tip @@ -77,8 +87,4 @@ open class TrailingTooltipLabel: View { label.surface = surface label.disabled = disabled } - - private func showToolTip(){ - print("You should show the tooltip now!") - } }