updated to instrinsic sizes and buttonable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
0b63f5abea
commit
6f2d754015
@ -11,13 +11,19 @@ import VDSColorTokens
|
|||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
import Combine
|
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 {
|
public enum ButtonSize: String, Codable, CaseIterable {
|
||||||
case large
|
case large
|
||||||
case small
|
case small
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(VDSButton)
|
@objc(VDSButton)
|
||||||
open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
|
open class Button: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, Useable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Combine Properties
|
// MARK: - Combine Properties
|
||||||
@ -36,6 +42,8 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
public var availableSizes: [ButtonSize] { [.large, .small] }
|
||||||
|
|
||||||
open var text: String? { didSet { didChange() } }
|
open var text: String? { didSet { didChange() } }
|
||||||
|
|
||||||
open var use: Use = .primary { didSet { didChange() }}
|
open var use: Use = .primary { didSet { didChange() }}
|
||||||
@ -159,6 +167,15 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// 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() {
|
open func updateView() {
|
||||||
|
|
||||||
let bgColor = buttonBackgroundColorConfiguration.getColor(self)
|
let bgColor = buttonBackgroundColorConfiguration.getColor(self)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
|||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
@objc(VDSTextLink)
|
@objc(VDSTextLink)
|
||||||
open class TextLink: Control {
|
open class TextLink: Control, Buttonable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
@ -26,7 +26,9 @@ open class TextLink: Control {
|
|||||||
open var text: String? { didSet { didChange() } }
|
open var text: String? { didSet { didChange() } }
|
||||||
|
|
||||||
open var size: ButtonSize = .large { didSet { didChange() }}
|
open var size: ButtonSize = .large { didSet { didChange() }}
|
||||||
|
|
||||||
|
public var availableSizes: [ButtonSize] { [.large, .small] }
|
||||||
|
|
||||||
private var height: CGFloat {
|
private var height: CGFloat {
|
||||||
switch size {
|
switch size {
|
||||||
case .large:
|
case .large:
|
||||||
@ -72,11 +74,8 @@ open class TextLink: Control {
|
|||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//pin stackview to edges
|
//pin stackview to edges
|
||||||
label.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
label.pinToSuperView()
|
||||||
label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
label.numberOfLines = 1
|
||||||
label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
||||||
label.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
||||||
|
|
||||||
heightConstraint = heightAnchor.constraint(equalToConstant: height)
|
heightConstraint = heightAnchor.constraint(equalToConstant: height)
|
||||||
heightConstraint?.isActive = true
|
heightConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
@ -94,6 +93,10 @@ open class TextLink: Control {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
override open var intrinsicContentSize: CGSize {
|
||||||
|
return CGSize(width: label.intrinsicContentSize.width, height: height)
|
||||||
|
}
|
||||||
|
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
label.surface = surface
|
label.surface = surface
|
||||||
label.disabled = disabled
|
label.disabled = disabled
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public enum TextLinkCaretPosition: String, CaseIterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc(VDSTextLinkCaret)
|
@objc(VDSTextLinkCaret)
|
||||||
open class TextLinkCaret: Control {
|
open class TextLinkCaret: Control, Buttonable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
@ -35,6 +35,8 @@ open class TextLinkCaret: Control {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
public var availableSizes: [ButtonSize] { [.large] }
|
||||||
|
|
||||||
open var text: String? { didSet { didChange() } }
|
open var text: String? { didSet { didChange() } }
|
||||||
|
|
||||||
open var iconPosition: TextLinkCaretPosition = .right { didSet { didChange() } }
|
open var iconPosition: TextLinkCaretPosition = .right { didSet { didChange() } }
|
||||||
@ -81,10 +83,10 @@ open class TextLinkCaret: Control {
|
|||||||
let size = caretView.size!.dimensions()
|
let size = caretView.size!.dimensions()
|
||||||
caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height)
|
caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height)
|
||||||
addSubview(label)
|
addSubview(label)
|
||||||
label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
label.pinToSuperView()
|
||||||
label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
||||||
label.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
label.numberOfLines = 1
|
||||||
label.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -109,6 +111,14 @@ open class TextLinkCaret: Control {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// 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() {
|
open override func updateView() {
|
||||||
|
|
||||||
let updatedText = text ?? ""
|
let updatedText = text ?? ""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user