From b1adbd7e0d0240eee87b3e3a98d2103a18c2d6a6 Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Mon, 12 Aug 2024 15:45:18 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-9314 story: update text --- VDS/Components/PriceLockup/PriceLockup.swift | 75 ++++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/VDS/Components/PriceLockup/PriceLockup.swift b/VDS/Components/PriceLockup/PriceLockup.swift index ef11a2cb..e127fd9a 100644 --- a/VDS/Components/PriceLockup/PriceLockup.swift +++ b/VDS/Components/PriceLockup/PriceLockup.swift @@ -39,6 +39,23 @@ open class PriceLockup: View { /// Enum used to describe the term of PriceLockup. public enum Term: String, CaseIterable { 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. @@ -80,9 +97,9 @@ open class PriceLockup: View { /// Does not apply a strikethrough format to leading and trailing text. open var strikethrough: Bool = false { didSet { setNeedsUpdate() } } - /// Term text for the component. Superscript placement can vary when term and delimeter are "none". - /// The default term is 'month'. - open var term: Term = .month { didSet { setNeedsUpdate() } } + /// Term text for the component. The default term is 'month'. + /// Superscript placement can vary when term and delimeter are "none". + open var term: Term = Term.defaultValue { didSet { setNeedsUpdate() } } /// Trailing text for the component. open var trailingText: String? { didSet { setNeedsUpdate() } } @@ -101,11 +118,31 @@ open class PriceLockup: View { internal var containerView = View().with { $0.clipsToBounds = true } + + internal var label = Label().with { + $0.isAccessibilityElement = false + $0.lineBreakMode = .byWordWrapping + } + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- 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 //-------------------------------------------------- @@ -121,19 +158,24 @@ open class PriceLockup: View { .height(containerSize.height) 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. open override func updateView() { super.updateView() - + label.text = fetchText() } /// Resets to default settings. open override func reset() { super.reset() shouldUpdateView = false - + label.reset() shouldUpdateView = true setNeedsUpdate() } @@ -144,4 +186,27 @@ open class PriceLockup: View { } 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 + + } }