Digital ACT-191 ONEAPP-9314 story: update text
This commit is contained in:
parent
815024cc5c
commit
b1adbd7e0d
@ -39,6 +39,23 @@ open class PriceLockup: View {
|
|||||||
/// Enum used to describe the term of PriceLockup.
|
/// Enum used to describe the term of PriceLockup.
|
||||||
public enum Term: String, CaseIterable {
|
public enum Term: String, CaseIterable {
|
||||||
case month, year, biennial, none
|
case month, year, biennial, none
|
||||||
|
|
||||||
|
/// The default term is 'month'.
|
||||||
|
public static var defaultValue : Self { .month }
|
||||||
|
|
||||||
|
/// Text for this term of PriceLockup.
|
||||||
|
public var text: String {
|
||||||
|
switch self {
|
||||||
|
case .month:
|
||||||
|
return "mo"
|
||||||
|
case .year:
|
||||||
|
return "yr"
|
||||||
|
case .biennial:
|
||||||
|
return "biennial"
|
||||||
|
case .none:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enum type describing size of PriceLockup.
|
/// Enum type describing size of PriceLockup.
|
||||||
@ -80,9 +97,9 @@ open class PriceLockup: View {
|
|||||||
/// Does not apply a strikethrough format to leading and trailing text.
|
/// Does not apply a strikethrough format to leading and trailing text.
|
||||||
open var strikethrough: Bool = false { didSet { setNeedsUpdate() } }
|
open var strikethrough: Bool = false { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Term text for the component. Superscript placement can vary when term and delimeter are "none".
|
/// Term text for the component. The default term is 'month'.
|
||||||
/// The default term is 'month'.
|
/// Superscript placement can vary when term and delimeter are "none".
|
||||||
open var term: Term = .month { didSet { setNeedsUpdate() } }
|
open var term: Term = Term.defaultValue { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Trailing text for the component.
|
/// Trailing text for the component.
|
||||||
open var trailingText: String? { didSet { setNeedsUpdate() } }
|
open var trailingText: String? { didSet { setNeedsUpdate() } }
|
||||||
@ -101,11 +118,31 @@ open class PriceLockup: View {
|
|||||||
internal var containerView = View().with {
|
internal var containerView = View().with {
|
||||||
$0.clipsToBounds = true
|
$0.clipsToBounds = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal var label = Label().with {
|
||||||
|
$0.isAccessibilityElement = false
|
||||||
|
$0.lineBreakMode = .byWordWrapping
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
|
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
|
||||||
|
|
||||||
|
private var kindColorConfiguration: AnyColorable {
|
||||||
|
switch kind {
|
||||||
|
case .primary:
|
||||||
|
return ControlColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)}.eraseToAnyColorable()
|
||||||
|
case .secondary:
|
||||||
|
return ControlColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .normal)}.eraseToAnyColorable()
|
||||||
|
case .savings:
|
||||||
|
return ControlColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen36, forState: .normal)}.eraseToAnyColorable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -121,19 +158,24 @@ open class PriceLockup: View {
|
|||||||
.height(containerSize.height)
|
.height(containerSize.height)
|
||||||
|
|
||||||
containerView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
containerView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||||
|
|
||||||
|
// Price lockup
|
||||||
|
containerView.addSubview(label)
|
||||||
|
label.pinToSuperView()
|
||||||
|
label.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to make changes to the View based off a change events or from local properties.
|
/// Used to make changes to the View based off a change events or from local properties.
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
|
label.text = fetchText()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
shouldUpdateView = false
|
shouldUpdateView = false
|
||||||
|
label.reset()
|
||||||
shouldUpdateView = true
|
shouldUpdateView = true
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
@ -144,4 +186,27 @@ open class PriceLockup: View {
|
|||||||
}
|
}
|
||||||
set {}
|
set {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Private Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
open func fetchText() -> String {
|
||||||
|
var text : String = ""
|
||||||
|
let currency: String = hideCurrency ? "" : "$"
|
||||||
|
if let leadingStr = leadingText {
|
||||||
|
text = text + leadingStr + " "
|
||||||
|
}
|
||||||
|
if let value = price {
|
||||||
|
text = text + currency + "\(value)"
|
||||||
|
}
|
||||||
|
if term != .none {
|
||||||
|
text = text + "/" + term.text
|
||||||
|
}
|
||||||
|
if let trailingStr = trailingText {
|
||||||
|
text = text + " " + trailingStr
|
||||||
|
}
|
||||||
|
text = text + (superscript ?? "")
|
||||||
|
return text
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user