vds_ios/VDS/Components/Tilelet/TileletIconModels.swift
2024-06-05 14:01:17 -05:00

103 lines
3.0 KiB
Swift

//
// TiletDescriptiveIconModel.swift
// VDS
//
// Created by Matt Bruce on 1/11/23.
//
import Foundation
import UIKit
import VDSCoreTokens
extension Tilelet {
public enum IconColor: Equatable {
case token(UIColor.VDSColor)
case custom(UIColor)
private var reflectedValue: String { String(reflecting: self) }
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.reflectedValue == rhs.reflectedValue
}
public var uiColor: UIColor {
switch self {
case .token(let color):
return color.uiColor
case .custom(let color):
return color
}
}
}
/// Model that represents the options available for the descriptive icon.
public struct DescriptiveIcon {
/// A representation that will be used to render the icon with corresponding name.
public var name: Icon.Name
/// Color of the icon.
public var iconColor: IconColor?
/// Enum for a preset height and width for the icon.
public var size: Icon.Size
/// Accessible Text for the Icon
public var accessibleText: String
public init(name: Icon.Name = .multipleDocuments,
iconColor: IconColor? = nil,
size: Icon.Size = .medium,
accessibleText: String? = nil) {
self.name = name
self.iconColor = iconColor
self.accessibleText = accessibleText ?? name.rawValue
self.size = size
}
}
/// Model that represents the options available for the directional icon.
public struct DirectionalIcon {
public enum IconType: String, CaseIterable {
case rightArrow
case externalLink
public var iconName: Icon.Name {
return self == .rightArrow ? .rightArrow : .externalLink
}
}
public enum IconSize: String, EnumSubset {
case small
case medium
case large
public var defaultValue: Icon.Size { .medium }
}
/// Color of the icon.
public var iconColor: IconColor?
/// Accessible Text for the Icon
public var accessibleText: String
/// Enum for a icon type you want shown..
public var iconType: IconType
/// Enum for a preset height and width for the icon.
public var size: IconSize
public init(iconType: IconType = .rightArrow,
iconColor: IconColor? = nil,
size: IconSize = .medium,
accessibleText: String? = nil) {
self.iconType = iconType
self.iconColor = iconColor
self.accessibleText = accessibleText ?? iconType.iconName.rawValue
self.size = size
}
}
}