Digital ACT-191 ONEAPP-9311 story: aligning text to center
This commit is contained in:
parent
4e88ee936a
commit
90eb01cb24
@ -44,7 +44,7 @@ open class InputStepper: EntryFieldBase {
|
||||
/// auto(default) - The control's width is determined by the combined width of the value, trailing text and padding
|
||||
/// Value - The control's width can be set to a fixed pixel.
|
||||
open var controlWidth: String? = "auto" { didSet { setNeedsUpdate() } }
|
||||
|
||||
|
||||
/// Accepts percentage value to controlWidth of input stepper.
|
||||
open var controlWidthPercentage: CGFloat? {
|
||||
didSet {
|
||||
@ -72,7 +72,7 @@ open class InputStepper: EntryFieldBase {
|
||||
|
||||
/// Allows an id to be passed to input stepper.
|
||||
open var id: Int? { didSet { setNeedsUpdate() } }
|
||||
|
||||
|
||||
/// Maximum value of the input stepper, defaults to '99'.
|
||||
open var maxValue: Int? = 99 {
|
||||
didSet {
|
||||
@ -82,7 +82,7 @@ open class InputStepper: EntryFieldBase {
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Minimum value of the input stepper, defaults to '0'.
|
||||
open var minValue: Int? = 0 {
|
||||
didSet {
|
||||
@ -94,7 +94,7 @@ open class InputStepper: EntryFieldBase {
|
||||
}
|
||||
|
||||
/// The size of the input stepper. Defaults to 'large'.
|
||||
open var size: Size = .large {
|
||||
open var size: Size = .large {
|
||||
didSet {
|
||||
updateStepperContainerViewSize()
|
||||
setNeedsUpdate()
|
||||
@ -143,24 +143,25 @@ open class InputStepper: EntryFieldBase {
|
||||
$0.textStyle = .boldBodyLarge
|
||||
$0.numberOfLines = 1
|
||||
$0.lineBreakMode = .byTruncatingTail
|
||||
$0.textAlignment = .center
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
internal var stepperWidthConstraint: NSLayoutConstraint?
|
||||
internal var stepperHeightConstraint: NSLayoutConstraint?
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
internal override var containerSize: CGSize { CGSize(width: size == .large ? largeMinWidth : smallMinWidth, height: size == .large ? largeMinHeight : smallMinHeight) }
|
||||
|
||||
|
||||
internal var largeMinWidth = 121
|
||||
internal var smallMinWidth = 90
|
||||
internal var largeMinHeight = 44
|
||||
internal var smallMinHeight = 32
|
||||
|
||||
|
||||
internal let labelColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
||||
internal let labelDisabledColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark)
|
||||
|
||||
@ -182,11 +183,11 @@ open class InputStepper: EntryFieldBase {
|
||||
// Set initial states
|
||||
containerView.isEnabled = false
|
||||
statusIcon.isHidden = true
|
||||
|
||||
|
||||
// Add listeners
|
||||
decrementButton.onClick = { _ in self.decrementButtonClick() }
|
||||
incrementButton.onClick = { _ in self.incrementButtonClick() }
|
||||
|
||||
|
||||
// setting color config
|
||||
textLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
|
||||
}
|
||||
@ -195,12 +196,12 @@ open class InputStepper: EntryFieldBase {
|
||||
stepperStackView.addArrangedSubview(decrementButton)
|
||||
stepperStackView.addArrangedSubview(textLabel)
|
||||
stepperStackView.addArrangedSubview(incrementButton)
|
||||
|
||||
|
||||
// Set space between decrement button, label, and increment button relative to input Stepper size.
|
||||
let space = size == .large ? VDSLayout.space3X : VDSLayout.space2X
|
||||
stepperStackView.setCustomSpacing(space, after: decrementButton)
|
||||
stepperStackView.setCustomSpacing(space, after: textLabel)
|
||||
|
||||
|
||||
// Update Edge insets relative to input Stepper size.
|
||||
stepperStackView.pinToSuperView(.uniform(size == .large ? 6.0 : VDSLayout.space1X))
|
||||
|
||||
@ -221,20 +222,19 @@ open class InputStepper: EntryFieldBase {
|
||||
statusIcon.isHidden = true
|
||||
updateConstraintsToFieldStackView(flag: false)
|
||||
updateContainerView(flag: false)
|
||||
|
||||
|
||||
// Update label text, style, color, ande surface.
|
||||
textLabel.text = String(defaultValue) + " " + (trailingText ?? "")
|
||||
textLabel.textStyle = size == .large ? .boldBodyLarge : .boldBodySmall
|
||||
textLabel.textColorConfiguration = !isEnabled ? labelDisabledColorConfiguration.eraseToAnyColorable() : labelColorConfiguration.eraseToAnyColorable()
|
||||
textLabel.surface = surface
|
||||
|
||||
|
||||
// Update increment and decrement button.
|
||||
updateButtonStates()
|
||||
|
||||
// Update stepper container border and corner radius.
|
||||
setControlWidth(controlWidth)
|
||||
updateControlWidthPercentage()
|
||||
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
@ -262,7 +262,7 @@ open class InputStepper: EntryFieldBase {
|
||||
widthConstraint?.deactivate()
|
||||
trailingLessThanEqualsConstraint?.deactivate()
|
||||
trailingEqualsConstraint?.deactivate()
|
||||
|
||||
|
||||
if let width, width >= minWidth, width <= maxWidth {
|
||||
widthConstraint?.constant = width
|
||||
widthConstraint?.activate()
|
||||
@ -286,7 +286,7 @@ open class InputStepper: EntryFieldBase {
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
internal func checkDefaultValue() {
|
||||
if let _minValue = minValue, let _maxValue = maxValue {
|
||||
if let _minValue = minValue, let _maxValue = maxValue {
|
||||
defaultValue = defaultValue > _maxValue ? _maxValue : defaultValue < _minValue ? _minValue : defaultValue
|
||||
}
|
||||
}
|
||||
@ -308,7 +308,7 @@ open class InputStepper: EntryFieldBase {
|
||||
incrementButton.customContainerSize = size == .large ? 32 : 24
|
||||
decrementButton.surface = surface
|
||||
incrementButton.surface = surface
|
||||
|
||||
|
||||
if isReadOnly || !isEnabled {
|
||||
decrementButton.isEnabled = false
|
||||
incrementButton.isEnabled = false
|
||||
@ -341,7 +341,7 @@ open class InputStepper: EntryFieldBase {
|
||||
// Set controlWidth provided which is either pixel or percentage
|
||||
let width = width ?? CGFloat(containerView.frame.size.width)
|
||||
updateStepperContainerWidth(controlWidth: CGFloat(controlWidth), width: width)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handling the controlwidth without going beyond the width of the parent container.
|
||||
@ -359,7 +359,7 @@ open class InputStepper: EntryFieldBase {
|
||||
|
||||
private func updateControlWidthPercentage() {
|
||||
let superWidth = width ?? CGFloat(containerView.frame.size.width)
|
||||
|
||||
|
||||
// Set the inputStepper's controlWidth based on the controlWidth percentage received relative to its parentView's frame.
|
||||
if let controlWidthPercentage {
|
||||
controlWidth = String( Int( max(superWidth * ((controlWidthPercentage) / 100), minWidth)))
|
||||
@ -379,6 +379,5 @@ open class InputStepper: EntryFieldBase {
|
||||
updateControlWidthPercentage()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user