182 lines
5.8 KiB
Swift
182 lines
5.8 KiB
Swift
//
|
|
// TrailingTooltipLabel.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 4/14/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSColorTokens
|
|
|
|
class TrailingTooltipLabelViewController: BaseViewController<TrailingTooltipLabel> {
|
|
|
|
lazy var textSizePickerSelectorView = {
|
|
TextSizePickerSelectorView(title: "",
|
|
picker: self.picker)
|
|
}()
|
|
|
|
lazy var fontCategoryPickerSelectorView = {
|
|
FontCategoryPickerSelectorView(title: "",
|
|
picker: self.picker)
|
|
}()
|
|
|
|
lazy var textPositionPickerSelectorView = {
|
|
PickerSelectorView(title: TextPosition.left.rawValue,
|
|
picker: self.picker,
|
|
items: TextPosition.allCases)
|
|
}()
|
|
|
|
var boldSwitch = Toggle()
|
|
var disabledSwitch = Toggle()
|
|
var textField = TextField()
|
|
|
|
var titleTextField = TextField()
|
|
var contentTextField = TextField()
|
|
var closeButtonTextField = TextField()
|
|
|
|
private var isBold: Bool = false
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0)
|
|
|
|
setupPicker()
|
|
setupModel()
|
|
}
|
|
|
|
override func setupForm(){
|
|
super.setupForm()
|
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
|
addFormRow(label: "Bold", view: boldSwitch)
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
|
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
|
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
|
addFormRow(label: "Text", view: textField)
|
|
addFormRow(label: "Tooltip Title", view: titleTextField)
|
|
addFormRow(label: "Tooltip Content", view: contentTextField)
|
|
addFormRow(label: "Tooltip Close Button Text", view: closeButtonTextField)
|
|
|
|
disabledSwitch.onChange = { [weak self] sender in
|
|
self?.component.disabled = sender.isOn
|
|
}
|
|
|
|
boldSwitch
|
|
.publisher(for: .valueChanged)
|
|
.sink { [weak self] sender in
|
|
self?.isBold = sender.isOn
|
|
self?.updateLabelStyle()
|
|
}.store(in: &subscribers)
|
|
|
|
textField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.component.labelText = text
|
|
}.store(in: &subscribers)
|
|
|
|
titleTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.component.tooltipTitle = text
|
|
}.store(in: &subscribers)
|
|
|
|
contentTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.component.tooltipContent = text
|
|
}.store(in: &subscribers)
|
|
|
|
closeButtonTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.component.tooltipCloseButtonText = text
|
|
}.store(in: &subscribers)
|
|
|
|
}
|
|
|
|
func setupModel() {
|
|
component.labelText = "5G Ultra Wideband is available in your area"
|
|
component.tooltipTitle = "5G Ultra Wideband is available in your area."
|
|
component.tooltipContent = "$799.99 (128 GB only)"
|
|
|
|
//setup UI
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
disabledSwitch.isOn = component.disabled
|
|
boldSwitch.isOn = isBold
|
|
textField.text = component.labelText
|
|
|
|
//set the font
|
|
fontCategory = .body
|
|
textSize = .small
|
|
|
|
//setup UI
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
disabledSwitch.isOn = component.disabled
|
|
titleTextField.text = component.tooltipTitle
|
|
contentTextField.text = component.tooltipContent
|
|
closeButtonTextField.text = component.tooltipCloseButtonText
|
|
|
|
}
|
|
|
|
//Picker
|
|
private var fontCategory: TextStyle.FontCategory = .feature {
|
|
didSet {
|
|
fontCategoryPickerSelectorView.text = fontCategory.rawValue
|
|
textSizePickerSelectorView.items = fontCategory.sizes
|
|
if textSizePickerSelectorView.items.count > 0 {
|
|
textSize = textSizePickerSelectorView.items[0]
|
|
} else {
|
|
textSize = nil
|
|
}
|
|
updateLabelStyle()
|
|
}
|
|
}
|
|
|
|
private var textSize: TextStyle.FontSize? = .large {
|
|
didSet {
|
|
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
|
|
updateLabelStyle()
|
|
}
|
|
|
|
}
|
|
|
|
func updateLabelStyle(){
|
|
if let style = fontCategory.style(for: textSize, isBold: isBold) {
|
|
component.labelTextStyle = style
|
|
}
|
|
}
|
|
|
|
func setupPicker(){
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.labelTextPosition = item
|
|
}
|
|
|
|
textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.textSize = item
|
|
}
|
|
|
|
fontCategoryPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.fontCategory = item
|
|
}
|
|
}
|
|
}
|
|
|
|
extension TrailingTooltipLabelViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
component.labelText = "5G Ultra Wideband is available in your area"
|
|
component.tooltipTitle = "5G Ultra Wideband is available in your area."
|
|
component.tooltipContent = "$799.99 (128 GB only)"
|
|
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
|
}
|
|
}
|
|
|
|
|