implement Monarch in Tilelet (first cut)
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4685c6d398
commit
46a1471282
@ -132,7 +132,7 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
open var aspectRatio: AspectRatio = .ratio1x1 { didSet { setNeedsUpdate() } }
|
open var aspectRatio: AspectRatio = .ratio1x1 { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Sets the background color for the component.
|
/// 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.
|
/// Sets the background effect for the component.
|
||||||
open var backgroundEffect: BackgroundEffect = .none { didSet { setNeedsUpdate() } }
|
open var backgroundEffect: BackgroundEffect = .none { didSet { setNeedsUpdate() } }
|
||||||
@ -192,13 +192,13 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
// MARK: - Configuration
|
// MARK: - Configuration
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private let cornerRadius = VDSFormControls.borderRadius * 2
|
private let cornerRadius = VDSFormControls.borderRadius * 2
|
||||||
private var backgroundColorConfiguration = BackgroundColorConfiguration()
|
internal var backgroundColorConfiguration = BackgroundColorConfiguration()
|
||||||
private let dropShadowConfiguration = DropShadowConfiguration().with {
|
private let dropShadowConfiguration = DropShadowConfiguration().with {
|
||||||
$0.shadowColorConfiguration = SurfaceColorConfiguration().with {
|
$0.shadowColorConfiguration = SurfaceColorConfiguration().with {
|
||||||
$0.lightColor = VDSColor.elementsPrimaryOnlight
|
$0.lightColor = VDSColor.elementsPrimaryOnlight
|
||||||
}.eraseToAnyColorable()
|
}.eraseToAnyColorable()
|
||||||
$0.shadowOffsetConfiguration = .init(.init(width: 0, height: 6), .zero)
|
$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)
|
$0.shadowOpacityConfiguration = .init(0.01, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyBackgroundEffects()
|
applyBackgroundEffects()
|
||||||
|
|
||||||
if showDropShadow, surface == .light {
|
if showDropShadow, surface == .light {
|
||||||
addDropShadow(dropShadowConfiguration)
|
addDropShadow(dropShadowConfiguration)
|
||||||
} else {
|
} else {
|
||||||
@ -457,17 +457,22 @@ extension TileContainerBase {
|
|||||||
required init() { }
|
required init() { }
|
||||||
|
|
||||||
func getColor(_ object: ObjectType) -> UIColor {
|
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:
|
case .primary:
|
||||||
primaryColorConfig.getColor(object.surface)
|
return primaryColorConfig.getColor(object.surface)
|
||||||
case .secondary:
|
case .secondary:
|
||||||
secondaryColorConfig.getColor(object.surface)
|
return secondaryColorConfig.getColor(object.surface)
|
||||||
case .white:
|
case .white:
|
||||||
whiteColorConfig.getColor(object.surface)
|
return whiteColorConfig.getColor(object.surface)
|
||||||
case .black:
|
case .black:
|
||||||
blackColorConfig.getColor(object.surface)
|
return blackColorConfig.getColor(object.surface)
|
||||||
case .custom(let hexCode):
|
case .custom(let hexCode):
|
||||||
UIColor(hexString: hexCode)
|
return UIColor(hexString: hexCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,6 +102,10 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
|||||||
$0.backgroundColor = .clear
|
$0.backgroundColor = .clear
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var backgroundColorSurface: Surface {
|
||||||
|
backgroundColorConfiguration.getColor(self).surface
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -444,7 +448,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
|||||||
badge.text = badgeModel.text
|
badge.text = badgeModel.text
|
||||||
badge.fillColor = badgeModel.fillColor
|
badge.fillColor = badgeModel.fillColor
|
||||||
badge.numberOfLines = badgeModel.numberOfLines
|
badge.numberOfLines = badgeModel.numberOfLines
|
||||||
badge.surface = badgeModel.surface
|
badge.surface = backgroundColorSurface
|
||||||
badge.maxWidth = badgeModel.maxWidth
|
badge.maxWidth = badgeModel.maxWidth
|
||||||
badgeLabelHeightGreaterThanConstraint?.constant = badge.label.minimumLineHeight
|
badgeLabelHeightGreaterThanConstraint?.constant = badge.label.minimumLineHeight
|
||||||
if badgeContainerView.superview == nil {
|
if badgeContainerView.superview == nil {
|
||||||
@ -474,7 +478,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
|||||||
|
|
||||||
if showTitleLockup {
|
if showTitleLockup {
|
||||||
//flip the surface for the titleLockup
|
//flip the surface for the titleLockup
|
||||||
titleLockup.surface = color == .black ? Surface.dark : Surface.light
|
titleLockup.surface = backgroundColorSurface
|
||||||
|
|
||||||
//titleLockup
|
//titleLockup
|
||||||
if let textWidth {
|
if let textWidth {
|
||||||
@ -529,14 +533,14 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
|||||||
if let descriptiveIconModel {
|
if let descriptiveIconModel {
|
||||||
descriptiveIcon.name = descriptiveIconModel.name
|
descriptiveIcon.name = descriptiveIconModel.name
|
||||||
descriptiveIcon.size = descriptiveIconModel.size
|
descriptiveIcon.size = descriptiveIconModel.size
|
||||||
descriptiveIcon.surface = descriptiveIconModel.surface
|
descriptiveIcon.surface = backgroundColorSurface
|
||||||
descriptiveIcon.accessibilityLabel = descriptiveIconModel.accessibleText
|
descriptiveIcon.accessibilityLabel = descriptiveIconModel.accessibleText
|
||||||
showIconContainerView = true
|
showIconContainerView = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if let directionalIconModel {
|
if let directionalIconModel {
|
||||||
directionalIcon.size = directionalIconModel.size
|
directionalIcon.size = directionalIconModel.size
|
||||||
directionalIcon.surface = directionalIconModel.surface
|
directionalIcon.surface = backgroundColorSurface
|
||||||
directionalIcon.accessibilityLabel = "Right arrow"
|
directionalIcon.accessibilityLabel = "Right arrow"
|
||||||
showIconContainerView = true
|
showIconContainerView = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,8 +36,8 @@ extension Tilelet {
|
|||||||
public var textAttributes: [any LabelAttributeModel]?
|
public var textAttributes: [any LabelAttributeModel]?
|
||||||
|
|
||||||
/// Text color that will be used for the subTitle label.
|
/// 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.
|
/// LineBreakMode used in Badge label.
|
||||||
public var lineBreakMode: NSLineBreakMode
|
public var lineBreakMode: NSLineBreakMode
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ extension Tilelet {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public init(text: String,
|
public init(text: String,
|
||||||
otherStandardStyle: OtherStandardStyle = .bodySmall,
|
otherStandardStyle: OtherStandardStyle = .bodySmall,
|
||||||
textColor: Use = .primary,
|
textColor: TitleLockup.TextColor = .primary,
|
||||||
textAttributes: [any LabelAttributeModel]? = nil,
|
textAttributes: [any LabelAttributeModel]? = nil,
|
||||||
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
||||||
self.text = text
|
self.text = text
|
||||||
@ -64,7 +64,8 @@ extension Tilelet {
|
|||||||
TitleLockup.SubTitleModel(text: text,
|
TitleLockup.SubTitleModel(text: text,
|
||||||
otherStandardStyle: otherStandardStyle.value,
|
otherStandardStyle: otherStandardStyle.value,
|
||||||
textColor: textColor,
|
textColor: textColor,
|
||||||
textAttributes: textAttributes, lineBreakMode: lineBreakMode)
|
textAttributes: textAttributes,
|
||||||
|
lineBreakMode: lineBreakMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,9 @@ extension Tilelet {
|
|||||||
/// Text that will be used for the title label.
|
/// Text that will be used for the title label.
|
||||||
public var text: String = ""
|
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.
|
/// Used in combination with standardStyle to set the textStyle that will be used for the title label.
|
||||||
public var isBold: Bool = false
|
public var isBold: Bool = false
|
||||||
/// Text attributes that will be used for the title label.
|
/// Text attributes that will be used for the title label.
|
||||||
@ -47,11 +50,13 @@ extension Tilelet {
|
|||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public init(text: String,
|
public init(text: String,
|
||||||
|
textColor: TitleLockup.TitleTextColor = .primary,
|
||||||
textAttributes: [any LabelAttributeModel]? = nil,
|
textAttributes: [any LabelAttributeModel]? = nil,
|
||||||
isBold: Bool = true,
|
isBold: Bool = true,
|
||||||
standardStyle: StandardStyle = .titleSmall,
|
standardStyle: StandardStyle = .titleSmall,
|
||||||
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.textColor = textColor
|
||||||
self.textAttributes = textAttributes
|
self.textAttributes = textAttributes
|
||||||
self.standardStyle = standardStyle
|
self.standardStyle = standardStyle
|
||||||
self.isBold = isBold
|
self.isBold = isBold
|
||||||
@ -64,8 +69,11 @@ extension Tilelet {
|
|||||||
/// Converts this type of model to a TitleLockup.TitleModel.
|
/// Converts this type of model to a TitleLockup.TitleModel.
|
||||||
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
|
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
|
||||||
TitleLockup.TitleModel(text: text,
|
TitleLockup.TitleModel(text: text,
|
||||||
|
textColor: textColor,
|
||||||
textAttributes: textAttributes,
|
textAttributes: textAttributes,
|
||||||
isBold: isBold, standardStyle: standardStyle.value, lineBreakMode: lineBreakMode)
|
isBold: isBold,
|
||||||
|
standardStyle: standardStyle.value,
|
||||||
|
lineBreakMode: lineBreakMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,9 @@ extension Tilelet {
|
|||||||
/// Text that will be used for the eyebrow label.
|
/// Text that will be used for the eyebrow label.
|
||||||
public var text: String = ""
|
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.
|
/// Used in combination with standardStyle to set the textStyle that will be used for the eyebrow label.
|
||||||
public var isBold: Bool = false
|
public var isBold: Bool = false
|
||||||
/// Text attributes that will be used for the eyebrow label.
|
/// Text attributes that will be used for the eyebrow label.
|
||||||
@ -33,11 +36,13 @@ extension Tilelet {
|
|||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public init(text: String,
|
public init(text: String,
|
||||||
|
textColor: TitleLockup.TextColor = .primary,
|
||||||
textAttributes: [any LabelAttributeModel]? = nil,
|
textAttributes: [any LabelAttributeModel]? = nil,
|
||||||
isBold: Bool = true,
|
isBold: Bool = true,
|
||||||
standardStyle: Tilelet.SubTitleModel.OtherStandardStyle = .bodySmall,
|
standardStyle: Tilelet.SubTitleModel.OtherStandardStyle = .bodySmall,
|
||||||
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
lineBreakMode: NSLineBreakMode = .byTruncatingTail) {
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.textColor = textColor
|
||||||
self.textAttributes = textAttributes
|
self.textAttributes = textAttributes
|
||||||
self.standardStyle = standardStyle
|
self.standardStyle = standardStyle
|
||||||
self.isBold = isBold
|
self.isBold = isBold
|
||||||
@ -49,7 +54,11 @@ extension Tilelet {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// Converts this type of model to a TitleLockup.TitleModel.
|
/// Converts this type of model to a TitleLockup.TitleModel.
|
||||||
public func toTitleLockupEyebrowModel() -> TitleLockup.EyebrowModel {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,4 +176,10 @@ extension UIColor {
|
|||||||
guard let found else { return nil}
|
guard let found else { return nil}
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var surface: Surface {
|
||||||
|
var greyScale: CGFloat = 0
|
||||||
|
getWhite(&greyScale, alpha: nil)
|
||||||
|
return greyScale < 0.5 ? .dark : .light
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user