Digital ACT-191 ONEAPP-9311 story: added size configuration property that includes large and small

This commit is contained in:
Vasavi Kanamarlapudi 2024-07-15 15:05:57 +05:30
parent 548984d499
commit 17f9240c7e

View File

@ -32,28 +32,30 @@ open class InputStepper: EntryFieldBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Enums // MARK: - Enums
//-------------------------------------------------- //--------------------------------------------------
/// Enum used to describe the control width of Input Stepper.
public enum controlWidth: String, CaseIterable {
case auto, value
}
/// Enum used to describe the size of Input Stepper. /// Enum used to describe the size of Input Stepper.
public enum Size: String, CaseIterable { public enum Size: String, CaseIterable {
case large, small case large, small
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
/// Accepts a string or number value to control the width of input stepper to a fixed pixel or percentage value. open var controlWidth: String? {
open var controlWidth: CGFloat? { didSet { setNeedsUpdate() } } get { _controlWidth }
set {
setControlWidth(newValue)
setNeedsUpdate()
}
}
/// Default value of the input stepper, defaults to '0'.
open var defaultValue:Int = 0 { didSet { setNeedsUpdate() } }
/// Maximum value of the input stepper, defaults to '99'. /// Maximum value of the input stepper, defaults to '99'.
open var maxValue: Int? { open var maxValue: Int? {
get { return _maxValue } get { return _maxValue }
set { set {
if let newValue, newValue < 100 && newValue > 0 { if let newValue, newValue <= 99 && newValue > 0 {
_maxValue = newValue _maxValue = newValue
} else { } else {
_maxValue = 99 _maxValue = 99
@ -80,7 +82,7 @@ open class InputStepper: EntryFieldBase {
get { return _size } get { return _size }
set { set {
_size = newValue _size = newValue
setNeedsUpdate() updateSize()
} }
} }
@ -90,13 +92,38 @@ open class InputStepper: EntryFieldBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var _controlWidth = "auto"
internal var _maxValue: Int = 99 internal var _maxValue: Int = 99
internal var _minValue: Int = 0 internal var _minValue: Int = 0
internal var _size: Size = .large internal var _size: Size = .large
private var stepperWidthConstraint: NSLayoutConstraint?
private var stepperHeightConstraint: NSLayoutConstraint?
private var largeMinWidth = 121
private var smallMinWidth = 90
let decrementButton = ButtonIcon().with {
$0.kind = .ghost
$0.iconName = Icon.Name(name: "minus")
$0.iconOffset = .init(x: -2, y: 0)
$0.customContainerSize = 32
$0.icon.customSize = 16
$0.backgroundColor = .clear
}
let incrementButton = ButtonIcon().with {
$0.kind = .ghost
$0.iconName = Icon.Name(name: "plus")
$0.iconOffset = .init(x: 2, y: 0)
$0.customContainerSize = 32
$0.icon.customSize = 16
$0.backgroundColor = .clear
}
let textLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.textStyle = .boldBodyLarge
$0.backgroundColor = .clear
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------
@ -108,8 +135,7 @@ open class InputStepper: EntryFieldBase {
super.setup() super.setup()
isAccessibilityElement = false isAccessibilityElement = false
accessibilityLabel = "Input Stepper" accessibilityLabel = "Input Stepper"
containerView.isEnabled = false
containerView.isEnabled = false
} }
open override func getFieldContainer() -> UIView { open override func getFieldContainer() -> UIView {
@ -120,50 +146,60 @@ open class InputStepper: EntryFieldBase {
$0.spacing = VDSLayout.space3X $0.spacing = VDSLayout.space3X
$0.backgroundColor = .clear $0.backgroundColor = .clear
} }
let view = View().with {
$0.clipsToBounds = true
$0.backgroundColor = .clear
}
let controlView = View().with { controlStackView.addArrangedSubview(decrementButton)
$0.clipsToBounds = true controlStackView.addArrangedSubview(textLabel)
$0.backgroundColor = .clear controlStackView.addArrangedSubview(incrementButton)
} return controlStackView
let label = Label().with {
$0.text = "Label"
}
let minusButton = ButtonIcon().with {
$0.kind = .ghost
$0.iconName = .leftCaret
$0.iconOffset = .init(x: -2, y: 0)
$0.customContainerSize = 40
$0.icon.customSize = 16
}
let plusButton = ButtonIcon().with {
$0.kind = .ghost
$0.iconName = .rightCaret
$0.iconOffset = .init(x: 2, y: 0)
$0.customContainerSize = 40
$0.icon.customSize = 16
}
controlStackView.addArrangedSubview(minusButton)
controlStackView.addArrangedSubview(label)
controlStackView.addArrangedSubview(plusButton)
controlView.addSubview(controlStackView)
controlStackView.pinToSuperView()
view.addSubview(controlView)
controlView.pinToSuperView()
view.pinToSuperView()
return view
} }
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
updateContainerView(flag: false) updateContainerView(flag: false)
textLabel.text = String(defaultValue) + " " + (trailingText ?? "")
decrementButton.surface = surface
incrementButton.surface = surface
textLabel.surface = surface
statusIcon.isHidden = true
} }
/// Resets to default settings.
open override func reset() {
super.reset()
textLabel.reset()
textLabel.textStyle = .boldBodyLarge
textLabel.text = ""
controlWidth = nil
minValue = nil
maxValue = nil
trailingText = nil
helperTextPlacement = .bottom
}
//--------------------------------------------------
// MARK: - Private Methods
//--------------------------------------------------
internal func updateSize() {
let value = size == .large ? 6.0 : VDSLayout.space1X
updateConstraintsToFieldStackView(value: value)
// textLabel.textStyle = size == .large ? .boldBodyLarge : .boldBodySmall
// textLabel.heightAnchor.constraint(equalToConstant: size == .large ? 44 : 32).activate()
// decrementButton.customContainerSize = size == .large ? 32 : 24
// incrementButton.customContainerSize = size == .large ? 32 : 24
}
internal func setControlWidth(_ text: String?) {
if let text, text == "auto" {
// Set fixed width relative to default value, trailing text label
} else if let controlWidth = Int(text ?? "") {
// Use provided new width either pixel or percentage
width = CGFloat(controlWidth)
} else {
// Use EntryFieldBase width
}
}
} }