Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chip implementation for uikit #111

Merged
merged 12 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let package = Package(
exclude: [
"Components/Badge/README.md",
"Components/Button/README.md",
"Components/Chip/README.md",
"Components/Progressbar/README.md",
"Components/Snackbar/README.md",
"Components/Switch/README.md",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Vitamin iOS
// Apache License 2.0
//

import UIKit
import Vitamin

final class ChipTableViewCell: UITableViewCell {
@IBOutlet weak var smallChip: VitaminChip!
@IBOutlet weak var mediumChip: VitaminChip!

func update(
config: VitaminChipDemoConfig
) {
smallChip.text = config.text
smallChip.variant = config.variant
smallChip.size = .small
smallChip.enabled = config.enabled

mediumChip.text = config.text
mediumChip.variant = config.variant
mediumChip.size = .medium
mediumChip.enabled = config.enabled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="chipCell" rowHeight="93" id="oYK-LA-MhX" customClass="ChipTableViewCell" customModule="Showcase">
<rect key="frame" x="0.0" y="0.0" width="426" height="93"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="oYK-LA-MhX" id="bRj-ws-6Oz">
<rect key="frame" x="0.0" y="0.0" width="426" height="93"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="EJE-qp-0GH">
<rect key="frame" x="20" y="5" width="386" height="83"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalCentering" alignment="center" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="GZT-YV-qC0">
<rect key="frame" x="0.0" y="0.0" width="386" height="83"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Pd6-fe-V3a" customClass="VitaminChip" customModule="Vitamin">
<rect key="frame" x="0.0" y="0.0" width="366" height="83"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wcP-H9-EBW" customClass="VitaminChip" customModule="Vitamin">
<rect key="frame" x="386" y="0.0" width="0.0" height="83"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="EJE-qp-0GH" secondAttribute="bottom" constant="5" id="3h4-Mo-GQj"/>
<constraint firstItem="EJE-qp-0GH" firstAttribute="leading" secondItem="bRj-ws-6Oz" secondAttribute="leading" constant="20" id="EV5-wQ-5As"/>
<constraint firstItem="EJE-qp-0GH" firstAttribute="top" secondItem="bRj-ws-6Oz" secondAttribute="top" constant="5" id="t9T-JM-R3l"/>
<constraint firstAttribute="trailing" secondItem="EJE-qp-0GH" secondAttribute="trailing" constant="20" id="yjj-4K-cNL"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="mediumChip" destination="wcP-H9-EBW" id="zik-VT-baw"/>
<outlet property="smallChip" destination="Pd6-fe-V3a" id="7wB-HR-Xd7"/>
</connections>
<point key="canvasLocation" x="95.652173913043484" y="98.772321428571431"/>
</tableViewCell>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
165 changes: 165 additions & 0 deletions Showcase/Application/UIKit/Components/Chip/ChipViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//
// Vitamin iOS
// Apache License 2.0
//

import UIKit
import Vitamin

final class ChipViewController: UITableViewController {
convenience init() {
self.init(style: .grouped)
}

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Chip"
tableView.register(
UINib(
nibName: "ChipTableViewCell",
bundle: nil),
forCellReuseIdentifier: "chipCell")
}

private static let sectionTitles = ["Filter", "Input", "Single Choice", "Action"]

private lazy var datasource: [String: [VitaminChipDemoConfig]] = {
var datasource: [String: [VitaminChipDemoConfig]] = [:]
var filterChips = ChipViewController.buildFilterChipsModel()
filterChips.append(contentsOf: ChipViewController.buildFilterChipsModel(enabled: false))

var inputChips = ChipViewController.buildInputChipsModel()
inputChips.append(contentsOf: ChipViewController.buildInputChipsModel(enabled: false))

var singleChoiceChips = ChipViewController.buildSingleChoiceChipsModel()
singleChoiceChips.append(contentsOf: ChipViewController.buildSingleChoiceChipsModel(enabled: false))

var actionChips = ChipViewController.buildActionChipsModel()
actionChips.append(contentsOf: ChipViewController.buildActionChipsModel(enabled: false))

datasource[ChipViewController.sectionTitles[0]] = filterChips
datasource[ChipViewController.sectionTitles[1]] = inputChips
datasource[ChipViewController.sectionTitles[2]] = singleChoiceChips
datasource[ChipViewController.sectionTitles[3]] = actionChips

return datasource
}()
}

extension ChipViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
datasource.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let data = datasource[Self.sectionTitles[section]] else {
return 0
}
return data.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let data = datasource[ChipViewController.sectionTitles[indexPath.section]] else {
return ChipTableViewCell(style: .default, reuseIdentifier: "chipCell")
}

guard let cell = tableView.dequeueReusableCell(withIdentifier: "chipCell") as? ChipTableViewCell else {
let cell = ChipTableViewCell(style: .default, reuseIdentifier: "chipCell")
cell.update(config: data[indexPath.row])
cell.selectionStyle = .none
return cell
}
let config = data[indexPath.row]
cell.update(config: config)
cell.selectionStyle = .none
return cell
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
ChipViewController.sectionTitles[section]
}
}

struct VitaminChipDemoConfig {
var text: String
var variant: VitaminChipVariant
var enabled: Bool
}

extension ChipViewController {
private static func buildFilterChipsModel(enabled: Bool = true) -> [VitaminChipDemoConfig] {
var chips: [VitaminChipDemoConfig] = []

chips.append(
VitaminChipDemoConfig(text: "filter1", variant: .filter(state: .selected, badge: nil), enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(text: "filter2", variant: .filter(state: .unselected, badge: nil), enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(text: "filter3", variant: .filter(state: .selected, badge: 59), enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(text: "filter4", variant: .filter(state: .unselected, badge: 59), enabled: enabled)
)
return chips
}

private static func buildInputChipsModel(enabled: Bool = true) -> [VitaminChipDemoConfig] {
var chips: [VitaminChipDemoConfig] = []
chips.append(
VitaminChipDemoConfig(
text: "input1",
variant: .input(),
enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(
text: "input1",
variant: .input(image: VitaminAssets.Placeholder.landscape.image),
enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(
text: "input2",
variant: .input(icon: Vitamix.Line.Map.mapPin.image),
enabled: enabled)
)

return chips
}

private static func buildSingleChoiceChipsModel(enabled: Bool = true) -> [VitaminChipDemoConfig] {
var chips: [VitaminChipDemoConfig] = []
chips.append(
VitaminChipDemoConfig(
text: "single1",
variant: .singleChoice(state: .selected),
enabled: enabled)
)
chips.append(
VitaminChipDemoConfig(
text: "single2",
variant: .singleChoice(state: .unselected),
enabled: enabled)
)

return chips
}

private static func buildActionChipsModel(enabled: Bool = true) -> [VitaminChipDemoConfig] {
var chips: [VitaminChipDemoConfig] = []
chips.append(
VitaminChipDemoConfig(
text: "action1",
variant: .action(icon: Vitamix.Line.System.settings.image),
enabled: enabled)
)

return chips
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extension MainTableViewController {
MenuSection(name: "🧩 Components", items: [
MenuItem(name: "🥇 Badge", viewController: BadgesViewController()),
MenuItem(name: "🕹 Button", viewController: ButtonsViewController()),
MenuItem(name: "🍟 Chip", viewController: ChipViewController()),
MenuItem(name: "⏳ Progressbar", viewController: ProgressbarViewController()),
MenuItem(name: "🌭 Snackbar", viewController: SnackbarViewController()),
MenuItem(name: "🎚 Switch", viewController: SwitchViewController()),
Expand Down
28 changes: 28 additions & 0 deletions Showcase/Vitamin Showcase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
6531B78227A9A23600808E1E /* RadiusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6531B77F27A9A23600808E1E /* RadiusTableViewCell.swift */; };
6531B78327A9A23600808E1E /* RadiusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6531B78027A9A23600808E1E /* RadiusTableViewCell.xib */; };
6531B78427A9A23600808E1E /* RadiusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6531B78127A9A23600808E1E /* RadiusViewController.swift */; };
6536D23F296F2C0500C14635 /* ChipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6536D23E296F2C0500C14635 /* ChipViewController.swift */; };
6548C67929718EB4005FFDC4 /* ChipTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6548C67729718EB4005FFDC4 /* ChipTableViewCell.xib */; };
6548C67A29718EB4005FFDC4 /* ChipTableVewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6548C67829718EB4005FFDC4 /* ChipTableVewCell.swift */; };
6551745B27EDBDFA0043700F /* BadgeCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6551745827EDBDFA0043700F /* BadgeCollectionViewCell.xib */; };
6551745C27EDBDFA0043700F /* BadgeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6551745927EDBDFA0043700F /* BadgeCollectionViewCell.swift */; };
6551745D27EDBDFA0043700F /* BadgesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6551745A27EDBDFA0043700F /* BadgesViewController.swift */; };
Expand Down Expand Up @@ -124,8 +127,11 @@
6531B77F27A9A23600808E1E /* RadiusTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadiusTableViewCell.swift; sourceTree = "<group>"; };
6531B78027A9A23600808E1E /* RadiusTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RadiusTableViewCell.xib; sourceTree = "<group>"; };
6531B78127A9A23600808E1E /* RadiusViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadiusViewController.swift; sourceTree = "<group>"; };
6536D23E296F2C0500C14635 /* ChipViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = "<group>"; };
654642B3276A513C00213415 /* vitamin-ios */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "vitamin-ios"; path = ..; sourceTree = "<group>"; };
654642B4276A528C00213415 /* vitamin-ios */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "vitamin-ios"; path = ..; sourceTree = "<group>"; };
6548C67729718EB4005FFDC4 /* ChipTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChipTableViewCell.xib; sourceTree = "<group>"; };
6548C67829718EB4005FFDC4 /* ChipTableVewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipTableVewCell.swift; sourceTree = "<group>"; };
6551745827EDBDFA0043700F /* BadgeCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeCollectionViewCell.xib; sourceTree = "<group>"; };
6551745927EDBDFA0043700F /* BadgeCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeCollectionViewCell.swift; sourceTree = "<group>"; };
6551745A27EDBDFA0043700F /* BadgesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgesViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -484,6 +490,7 @@
children = (
6551745627EDBDFA0043700F /* Badge */,
AA68B4C7256811FC00F1A4D7 /* Button */,
6536D23D296F2C0500C14635 /* Chip */,
65F1BC1927CE8836002D08D8 /* Progressbar */,
657606FD295C4C1C00D2ECB1 /* Snackbar */,
4AAD2B6D2767A99900727D8E /* Switch */,
Expand Down Expand Up @@ -572,6 +579,15 @@
path = Cell;
sourceTree = "<group>";
};
6536D23D296F2C0500C14635 /* Chip */ = {
isa = PBXGroup;
children = (
6548C67629718EB4005FFDC4 /* Cell */,
6536D23E296F2C0500C14635 /* ChipViewController.swift */,
);
path = Chip;
sourceTree = "<group>";
};
654642B2276A513C00213415 /* Packages */ = {
isa = PBXGroup;
children = (
Expand All @@ -581,6 +597,15 @@
name = Packages;
sourceTree = "<group>";
};
6548C67629718EB4005FFDC4 /* Cell */ = {
isa = PBXGroup;
children = (
6548C67729718EB4005FFDC4 /* ChipTableViewCell.xib */,
6548C67829718EB4005FFDC4 /* ChipTableVewCell.swift */,
);
path = Cell;
sourceTree = "<group>";
};
6551745627EDBDFA0043700F /* Badge */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -859,6 +884,7 @@
6551745B27EDBDFA0043700F /* BadgeCollectionViewCell.xib in Resources */,
AA68B4CE25681A6700F1A4D7 /* ButtonTableViewCell.xib in Resources */,
65F1BC2027CE8836002D08D8 /* LinearProgressbarTableViewCell.xib in Resources */,
6548C67929718EB4005FFDC4 /* ChipTableViewCell.xib in Resources */,
65F1BC2127CE8836002D08D8 /* CircularProgressbarTableViewCell.xib in Resources */,
65B52A1F273944DC008D9B5E /* SwitchTableViewCell.xib in Resources */,
6521D85F27DA100A00A15A06 /* TagCollectionViewCell.xib in Resources */,
Expand Down Expand Up @@ -929,6 +955,7 @@
4A35E4872816C1F4001526D8 /* ShadowsView.swift in Sources */,
65C518CA27D673FF00B87FF0 /* TagTableViewCell.swift in Sources */,
65C518C827D673FF00B87FF0 /* TagViewController.swift in Sources */,
6536D23F296F2C0500C14635 /* ChipViewController.swift in Sources */,
65F1BC2227CE8836002D08D8 /* ProgressbarTableViewCells.swift in Sources */,
4A35E483281304A1001526D8 /* RadiusesView.swift in Sources */,
AAC5D4412567FE710070667D /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -959,6 +986,7 @@
4A4C0B1D292EB187002653E1 /* TextFieldModel.swift in Sources */,
651EF24D272BE8D500121F7A /* TextFieldTableViewCell.swift in Sources */,
AAB029E925680D8D00F08C74 /* ColorTableViewCell.swift in Sources */,
6548C67A29718EB4005FFDC4 /* ChipTableVewCell.swift in Sources */,
65BD9F3E2768D06900EEDC0D /* IconCollectionViewCell.swift in Sources */,
6531B78227A9A23600808E1E /* RadiusTableViewCell.swift in Sources */,
6551746127EDBFAE0043700F /* BaseHeaderedCollectionViewController.swift in Sources */,
Expand Down
Loading