added button group
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5746a8d536
commit
8eca5ee691
@ -59,6 +59,7 @@
|
||||
EAA5EEAD28EB6924003B3210 /* TextEntryFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEAC28EB6924003B3210 /* TextEntryFieldViewController.swift */; };
|
||||
EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; };
|
||||
EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; };
|
||||
EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */; };
|
||||
EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLinkViewController.swift */; };
|
||||
EAF7F07D2899698800B287F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F07B2899698800B287F5 /* Assets.xcassets */; };
|
||||
EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */; };
|
||||
@ -120,6 +121,7 @@
|
||||
EAA5EEAC28EB6924003B3210 /* TextEntryFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryFieldViewController.swift; sourceTree = "<group>"; };
|
||||
EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
|
||||
EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewController.swift; sourceTree = "<group>"; };
|
||||
EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupViewController.swift; sourceTree = "<group>"; };
|
||||
EAC9257F29119FC400091998 /* TextLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkViewController.swift; sourceTree = "<group>"; };
|
||||
EAF7F07B2899698800B287F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxViewController.swift; sourceTree = "<group>"; };
|
||||
@ -237,6 +239,7 @@
|
||||
EA3C3BB228996775000CA526 /* MenuViewController.swift */,
|
||||
EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */,
|
||||
EA4DB30328DCD25B00103EE3 /* BadgeViewController.swift */,
|
||||
EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */,
|
||||
5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */,
|
||||
EA89204D28B67332006B9984 /* CheckBoxGroupViewController.swift */,
|
||||
EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */,
|
||||
@ -392,6 +395,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
EA3C3BB728996775000CA526 /* ToggleViewController.swift in Sources */,
|
||||
EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */,
|
||||
EA89204C28B66CE2006B9984 /* ScrollWrapperView.swift in Sources */,
|
||||
EA89205128B68307006B9984 /* TextField.swift in Sources */,
|
||||
EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */,
|
||||
|
||||
123
VDSSample/ViewControllers/ButtonGroupViewController.swift
Normal file
123
VDSSample/ViewControllers/ButtonGroupViewController.swift
Normal file
@ -0,0 +1,123 @@
|
||||
//
|
||||
// ButtonViewController.swift
|
||||
// VDSSample
|
||||
//
|
||||
// Created by Jarrod Courtney on 9/16/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import VDS
|
||||
import VDSColorTokens
|
||||
|
||||
class ButtonGroupViewController: BaseViewController {
|
||||
var collectionView: UICollectionView!
|
||||
|
||||
lazy var usePickerSelectorView = {
|
||||
PickerSelectorView<Use>(title: "",
|
||||
picker: self.picker,
|
||||
items: [.primary, .secondary])
|
||||
}()
|
||||
|
||||
lazy var buttonSizePickerSelectorView = {
|
||||
PickerSelectorView(title: "",
|
||||
picker: self.picker,
|
||||
items: ButtonSize.allCases)
|
||||
}()
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var textField = TextField()
|
||||
var widthTextField = TextField()
|
||||
|
||||
let buttonGroup = ButtonGroup()
|
||||
|
||||
let button = Button()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buttonGroup.buttons = [
|
||||
button,
|
||||
Button().with{$0.text = "Wide Label Button"},
|
||||
TextLink().with{$0.text = "Text Link Button"},
|
||||
TextLinkCaret().with{$0.text = "Caret Button"}
|
||||
]
|
||||
|
||||
addContentTopView(view: buttonGroup)
|
||||
|
||||
setupForm()
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupForm(){
|
||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||
addFormRow(label: "Use", view: usePickerSelectorView)
|
||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||
addFormRow(label: "Label", view: textField)
|
||||
addFormRow(label: "Width", view: widthTextField)
|
||||
addFormRow(label: "Size", view: buttonSizePickerSelectorView)
|
||||
|
||||
|
||||
disabledSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
self?.buttonGroup.disabled = sender.isOn
|
||||
}.store(in: &subscribers)
|
||||
|
||||
textField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.button.text = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
widthTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
if let n = NumberFormatter().number(from: text) {
|
||||
self?.button.width = CGFloat(truncating: n)
|
||||
}
|
||||
}.store(in: &subscribers)
|
||||
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
button.text = "Button"
|
||||
|
||||
button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { [weak self] control in
|
||||
let alertController:UIAlertController = UIAlertController(title: "Alert",
|
||||
message: "\(control.text!) Clicked",
|
||||
preferredStyle: UIAlertController.Style.alert)
|
||||
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
|
||||
self?.present(alertController, animated: true)
|
||||
print("clicked me")
|
||||
}.store(in: &subscribers)
|
||||
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = buttonGroup.surface.rawValue
|
||||
disabledSwitch.isOn = buttonGroup.disabled
|
||||
textField.text = button.text
|
||||
usePickerSelectorView.text = button.use.rawValue
|
||||
widthTextField.text = ""
|
||||
buttonSizePickerSelectorView.text = ButtonSize.large.rawValue
|
||||
}
|
||||
|
||||
func setupPicker(){
|
||||
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.buttonGroup.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
}
|
||||
|
||||
usePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.button.use = item
|
||||
self?.button.backgroundColor = item.color
|
||||
}
|
||||
|
||||
buttonSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.button.size = item
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,7 @@ class MenuViewController: UITableViewController {
|
||||
let items: [MenuComponent] = [
|
||||
MenuComponent(title: "Badge", viewController: BadgeViewController.self),
|
||||
MenuComponent(title: "Button", viewController: ButtonViewController.self),
|
||||
MenuComponent(title: "ButtonGroup", viewController: ButtonGroupViewController.self),
|
||||
MenuComponent(title: "Checkbox", viewController: CheckboxViewController.self),
|
||||
MenuComponent(title: "CheckboxGroup", viewController: CheckboxGroupViewController.self),
|
||||
MenuComponent(title: "Label", viewController: LabelViewController.self),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user