implement Monarch in Tilelet (first cut)

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-06 16:49:21 -05:00
parent 4685c6d398
commit 46a1471282
6 changed files with 53 additions and 20 deletions

View File

@ -132,7 +132,7 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
open var aspectRatio: AspectRatio = .ratio1x1 { didSet { setNeedsUpdate() } }
/// Sets the background color for the component.
open var color: BackgroundColor = .secondary { didSet { setNeedsUpdate() } }
open var color: BackgroundColor? { didSet { setNeedsUpdate() } }
/// Sets the background effect for the component.
open var backgroundEffect: BackgroundEffect = .none { didSet { setNeedsUpdate() } }
@ -192,13 +192,13 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
// MARK: - Configuration
//--------------------------------------------------
private let cornerRadius = VDSFormControls.borderRadius * 2
private var backgroundColorConfiguration = BackgroundColorConfiguration()
internal var backgroundColorConfiguration = BackgroundColorConfiguration()
private let dropShadowConfiguration = DropShadowConfiguration().with {
$0.shadowColorConfiguration = SurfaceColorConfiguration().with {
$0.lightColor = VDSColor.elementsPrimaryOnlight
}.eraseToAnyColorable()
$0.shadowOffsetConfiguration = .init(.init(width: 0, height: 6), .zero)
$0.shadowRadiusConfiguration = .init(3.0, 0.0)
$0.shadowRadiusConfiguration = .init(8.0, 0.0)
$0.shadowOpacityConfiguration = .init(0.01, 0.0)
}
@ -457,17 +457,22 @@ extension TileContainerBase {
required init() { }
func getColor(_ object: ObjectType) -> UIColor {
switch object.color {
guard let color = object.color else {
let config = object.surface == .light ? blackColorConfig : whiteColorConfig
return config.getColor(object.surface)
}
switch color {
case .primary:
primaryColorConfig.getColor(object.surface)
return primaryColorConfig.getColor(object.surface)
case .secondary:
secondaryColorConfig.getColor(object.surface)
return secondaryColorConfig.getColor(object.surface)
case .white:
whiteColorConfig.getColor(object.surface)
return whiteColorConfig.getColor(object.surface)
case .black:
blackColorConfig.getColor(object.surface)
return blackColorConfig.getColor(object.surface)
case .custom(let hexCode):
UIColor(hexString: hexCode)
return UIColor(hexString: hexCode)
}
}
}

View File

@ -102,6 +102,10 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
$0.backgroundColor = .clear
}
private var backgroundColorSurface: Surface {
backgroundColorConfiguration.getColor(self).surface
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
@ -444,7 +448,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
badge.text = badgeModel.text
badge.fillColor = badgeModel.fillColor
badge.numberOfLines = badgeModel.numberOfLines
badge.surface = badgeModel.surface
badge.surface = backgroundColorSurface
badge.maxWidth = badgeModel.maxWidth
badgeLabelHeightGreaterThanConstraint?.constant = badge.label.minimumLineHeight
if badgeContainerView.superview == nil {
@ -474,7 +478,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
if showTitleLockup {
//flip the surface for the titleLockup
titleLockup.surface = color == .black ? Surface.dark : Surface.light
titleLockup.surface = backgroundColorSurface
//titleLockup
if let textWidth {
@ -529,14 +533,14 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
if let descriptiveIconModel {
descriptiveIcon.name = descriptiveIconModel.name
descriptiveIcon.size = descriptiveIconModel.size
descriptiveIcon.surface = descriptiveIconModel.surface
descriptiveIcon.surface = backgroundColorSurface
descriptiveIcon.accessibilityLabel = descriptiveIconModel.accessibleText
showIconContainerView = true
}
if let directionalIconModel {
directionalIcon.size = directionalIconModel.size
directionalIcon.surface = directionalIconModel.surface
directionalIcon.surface = backgroundColorSurface
directionalIcon.accessibilityLabel = "Right arrow"
showIconContainerView = true
}

View File

@ -36,7 +36,7 @@ extension Tilelet {
public var textAttributes: [any LabelAttributeModel]?
/// Text color that will be used for the subTitle label.
public var textColor: Use = .primary
public var textColor: TitleLockup.TextColor
/// LineBreakMode used in Badge label.
public var lineBreakMode: NSLineBreakMode
@ -46,7 +46,7 @@ extension Tilelet {
//--------------------------------------------------
public init(text: String,
otherStandardStyle: OtherStandardStyle = .bodySmall,
textColor: Use = .primary,
textColor: TitleLockup.TextColor = .primary,
textAttributes: [any LabelAttributeModel]? = nil,
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
self.text = text
@ -64,7 +64,8 @@ extension Tilelet {
TitleLockup.SubTitleModel(text: text,
otherStandardStyle: otherStandardStyle.value,
textColor: textColor,
textAttributes: textAttributes, lineBreakMode: lineBreakMode)
textAttributes: textAttributes,
lineBreakMode: lineBreakMode)
}
}
}

View File

@ -32,6 +32,9 @@ extension Tilelet {
/// Text that will be used for the title label.
public var text: String = ""
/// TextColor that will be used for the title label.
public var textColor: TitleLockup.TitleTextColor
/// Used in combination with standardStyle to set the textStyle that will be used for the title label.
public var isBold: Bool = false
/// Text attributes that will be used for the title label.
@ -47,11 +50,13 @@ extension Tilelet {
// MARK: - Initializers
//--------------------------------------------------
public init(text: String,
textColor: TitleLockup.TitleTextColor = .primary,
textAttributes: [any LabelAttributeModel]? = nil,
isBold: Bool = true,
standardStyle: StandardStyle = .titleSmall,
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
self.text = text
self.textColor = textColor
self.textAttributes = textAttributes
self.standardStyle = standardStyle
self.isBold = isBold
@ -64,8 +69,11 @@ extension Tilelet {
/// Converts this type of model to a TitleLockup.TitleModel.
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
TitleLockup.TitleModel(text: text,
textColor: textColor,
textAttributes: textAttributes,
isBold: isBold, standardStyle: standardStyle.value, lineBreakMode: lineBreakMode)
isBold: isBold,
standardStyle: standardStyle.value,
lineBreakMode: lineBreakMode)
}
}
}

View File

@ -18,6 +18,9 @@ extension Tilelet {
/// Text that will be used for the eyebrow label.
public var text: String = ""
/// Text color that will be used for the eyebrow label
public var textColor: TitleLockup.TextColor
/// Used in combination with standardStyle to set the textStyle that will be used for the eyebrow label.
public var isBold: Bool = false
/// Text attributes that will be used for the eyebrow label.
@ -33,11 +36,13 @@ extension Tilelet {
// MARK: - Initializers
//--------------------------------------------------
public init(text: String,
textColor: TitleLockup.TextColor = .primary,
textAttributes: [any LabelAttributeModel]? = nil,
isBold: Bool = true,
standardStyle: Tilelet.SubTitleModel.OtherStandardStyle = .bodySmall,
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
self.text = text
self.textColor = textColor
self.textAttributes = textAttributes
self.standardStyle = standardStyle
self.isBold = isBold
@ -49,7 +54,11 @@ extension Tilelet {
//--------------------------------------------------
/// Converts this type of model to a TitleLockup.TitleModel.
public func toTitleLockupEyebrowModel() -> TitleLockup.EyebrowModel {
TitleLockup.EyebrowModel(text: text, isBold: isBold, standardStyle: standardStyle.value, textAttributes: textAttributes)
TitleLockup.EyebrowModel(text: text,
textColor: textColor,
isBold: isBold,
standardStyle: standardStyle.value,
textAttributes: textAttributes)
}
}
}

View File

@ -176,4 +176,10 @@ extension UIColor {
guard let found else { return nil}
return found
}
public var surface: Surface {
var greyScale: CGFloat = 0
getWhite(&greyScale, alpha: nil)
return greyScale < 0.5 ? .dark : .light
}
}