updated to instrinsic sizes and buttonable

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-18 10:02:27 -06:00
parent 0b63f5abea
commit 6f2d754015
3 changed files with 43 additions and 13 deletions

View File

@ -11,13 +11,19 @@ import VDSColorTokens
import VDSFormControlsTokens
import Combine
public protocol Buttonable: UIControl, Surfaceable, Disabling {
var availableSizes: [ButtonSize] { get }
var text: String? { get set }
var intrinsicContentSize: CGSize { get }
}
public enum ButtonSize: String, Codable, CaseIterable {
case large
case small
}
@objc(VDSButton)
open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
open class Button: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, Useable {
//--------------------------------------------------
// MARK: - Combine Properties
@ -36,6 +42,8 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public var availableSizes: [ButtonSize] { [.large, .small] }
open var text: String? { didSet { didChange() } }
open var use: Use = .primary { didSet { didChange() }}
@ -159,6 +167,15 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
override open var intrinsicContentSize: CGSize {
let intrinsicContentSize = super.intrinsicContentSize
let adjustedWidth = intrinsicContentSize.width + titleEdgeInsets.left + titleEdgeInsets.right
let adjustedHeight = intrinsicContentSize.height + titleEdgeInsets.top + titleEdgeInsets.bottom
return CGSize(width: adjustedWidth, height: adjustedHeight)
}
open func updateView() {
let bgColor = buttonBackgroundColorConfiguration.getColor(self)

View File

@ -12,7 +12,7 @@ import VDSFormControlsTokens
import Combine
@objc(VDSTextLink)
open class TextLink: Control {
open class TextLink: Control, Buttonable {
//--------------------------------------------------
// MARK: - Private Properties
@ -26,7 +26,9 @@ open class TextLink: Control {
open var text: String? { didSet { didChange() } }
open var size: ButtonSize = .large { didSet { didChange() }}
public var availableSizes: [ButtonSize] { [.large, .small] }
private var height: CGFloat {
switch size {
case .large:
@ -72,11 +74,8 @@ open class TextLink: Control {
}.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
label.pinToSuperView()
label.numberOfLines = 1
heightConstraint = heightAnchor.constraint(equalToConstant: height)
heightConstraint?.isActive = true
}
@ -94,6 +93,10 @@ open class TextLink: Control {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
override open var intrinsicContentSize: CGSize {
return CGSize(width: label.intrinsicContentSize.width, height: height)
}
open override func updateView() {
label.surface = surface
label.disabled = disabled

View File

@ -16,7 +16,7 @@ public enum TextLinkCaretPosition: String, CaseIterable {
}
@objc(VDSTextLinkCaret)
open class TextLinkCaret: Control {
open class TextLinkCaret: Control, Buttonable {
//--------------------------------------------------
// MARK: - Private Properties
@ -35,6 +35,8 @@ open class TextLinkCaret: Control {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public var availableSizes: [ButtonSize] { [.large] }
open var text: String? { didSet { didChange() } }
open var iconPosition: TextLinkCaretPosition = .right { didSet { didChange() } }
@ -81,10 +83,10 @@ open class TextLinkCaret: Control {
let size = caretView.size!.dimensions()
caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height)
addSubview(label)
label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
label.topAnchor.constraint(equalTo: topAnchor).isActive = true
label.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
label.pinToSuperView()
label.numberOfLines = 1
}
//--------------------------------------------------
@ -109,6 +111,14 @@ open class TextLinkCaret: Control {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
override open var intrinsicContentSize: CGSize {
var itemWidth = label.intrinsicContentSize.width
if let caretWidth = caretView.size?.dimensions().width {
itemWidth += caretWidth
}
return CGSize(width: itemWidth, height: height)
}
open override func updateView() {
let updatedText = text ?? ""