142 lines
4.5 KiB
Swift
142 lines
4.5 KiB
Swift
//
|
|
// IconViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 1/9/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSCoreTokens
|
|
import Combine
|
|
|
|
class IconViewController: BaseViewController<Icon> {
|
|
enum IconColor: String, CaseIterable {
|
|
case `default`, token, custom
|
|
}
|
|
|
|
lazy var lightColorPickerSelectorView : TokenColorPickerSection = {
|
|
TokenColorPickerSection<IconColor>(rowTitle: "Light Color",
|
|
picker: self.picker).with {
|
|
$0.onSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
light = .black
|
|
setColorConfiguration()
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
light = color.uiColor
|
|
setColorConfiguration()
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
light = color
|
|
setColorConfiguration()
|
|
}
|
|
}
|
|
}()
|
|
|
|
lazy var darkColorPickerSelectorView: TokenColorPickerSection = {
|
|
TokenColorPickerSection<IconColor>(rowTitle: "Dark Color",
|
|
picker: self.picker).with {
|
|
$0.onSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
dark = .white
|
|
setColorConfiguration()
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
dark = color.uiColor
|
|
setColorConfiguration()
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
dark = color
|
|
setColorConfiguration()
|
|
}
|
|
}
|
|
}()
|
|
|
|
lazy var namePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Icon.Name.all.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var sizePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Icon.Size.allCases)
|
|
}()
|
|
|
|
var customSizeField = NumericField()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: component, pinTrailing: false)
|
|
setupPicker()
|
|
setupModel()
|
|
}
|
|
|
|
override func setupForm(){
|
|
super.setupForm()
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addFormRow(label: "Size", view: sizePickerSelectorView)
|
|
addFormRow(label: "Custom Size", view: customSizeField)
|
|
append(section: lightColorPickerSelectorView)
|
|
append(section: darkColorPickerSelectorView)
|
|
addFormRow(label: "Name", view: namePickerSelectorView)
|
|
|
|
customSizeField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
self?.component.customSize = number?.intValue
|
|
}.store(in: &subscribers)
|
|
}
|
|
|
|
func setupModel() {
|
|
let name = Icon.Name.accessibility
|
|
component.name = name
|
|
|
|
//setup UI
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
sizePickerSelectorView.text = component.size.rawValue
|
|
namePickerSelectorView.text = name.rawValue
|
|
}
|
|
func setupPicker(){
|
|
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
sizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.size = item
|
|
}
|
|
|
|
namePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.name = item
|
|
}
|
|
}
|
|
|
|
var light: UIColor = .black
|
|
var dark: UIColor = .white
|
|
func setColorConfiguration() {
|
|
component.colorConfiguration = .init(light, dark)
|
|
}
|
|
|
|
}
|
|
|
|
extension IconViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
let name = Icon.Name.accessibility
|
|
let color = UIColor.VDSColor.paletteBlack
|
|
component.color = color.uiColor
|
|
component.name = name
|
|
component.customSize = 50
|
|
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual, bottomPinningType: .lessThanOrEqual)
|
|
}
|
|
}
|