Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucianobohrer/tagmenu
A SwiftUI horizontal tag menu, with single and multiple selection options, totally customizable
https://github.com/lucianobohrer/tagmenu
cocoapods component ios swift-packages swiftui
Last synced: 4 months ago
JSON representation
A SwiftUI horizontal tag menu, with single and multiple selection options, totally customizable
- Host: GitHub
- URL: https://github.com/lucianobohrer/tagmenu
- Owner: lucianobohrer
- License: mit
- Created: 2020-12-10T14:41:07.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T19:43:34.000Z (about 1 year ago)
- Last Synced: 2024-10-14T19:40:20.066Z (4 months ago)
- Topics: cocoapods, component, ios, swift-packages, swiftui
- Language: Swift
- Homepage:
- Size: 881 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TagMenu
[![Build Status](https://travis-ci.com/lucianobohrer/TagMenu.svg?token=qq5fjiKDEp43N6JsJhQv&branch=main)](https://travis-ci.com/lucianobohrer/TagMenu)
[![Version](https://img.shields.io/cocoapods/v/TagMenu.svg?style=flat)](https://cocoapods.org/pods/TagMenu)
[![License](https://img.shields.io/cocoapods/l/TagMenu.svg?style=flat)](https://cocoapods.org/pods/TagMenu)
[![Platform](https://img.shields.io/cocoapods/p/TagMenu.svg?style=flat)](https://cocoapods.org/pods/TagMenu)## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Usage
### Generic Elements
ViewModel generic type needs to conform to `Displayable` protocol that is responsible to represent the string shown in the tag view.### Single Selection
```swift
let viewModel = TagMenuViewModel(items: [
SelectableListItem(value: "Item 1", selected: true),
SelectableListItem(value: "Item 2"),
SelectableListItem(value: "Item 3"),
SelectableListItem(value: "Item 4")
],
title: "",
selection: .single)let view = TagMenuView(viewModel: viewModel)
```
### Multiple Selection```swift
let viewModel = TagMenuViewModel(items: [
SelectableListItem(value: "Item 1"),
SelectableListItem(value: "Item 2"),
SelectableListItem(value: "Item 3"),
SelectableListItem(value: "Item 4")
],
title: "Select until 3 items",
selection: .multiple(max: 3))let view = TagMenuView(viewModel: viewModel)
```### Handling Selection Event
Subscribe the `selectedItemsSubject` to get the current selected values when a new item is selected/deselected.
```swift
var cancellable: Cancellable?cancellable = viewModel.selectedItemsSubject.sink { (values) in
print(values)
}
```### Customizing the view
Set `TagMenuSettings` custom parameters
```swift
let view = TagMenu(viewModel: vm,
tagSettings: TagMenuSettings(highlightColor: .systemRed,
regularColor: .gray,
backgroundColor: .white,
cornerRadius: 8,
borderSize: 1))
```## Package
### For Xcode Projects
File > Swift Packages > Add Package Dependency: https://github.com/lucianobohrer/TagMenu
### For Swift Packages
Add a dependency in your your `Package.swift`
```swift
.package(url: "https://github.com/lucianobohrer/TagMenu.git", from: "1.0.0"),
```## CocoaPods
TagMenu is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'TagMenu'
```## Authors
- [lucianobohrer](https://github.com/lucianobohrer)
- [gabrielsilveiraa](https://github.com/gabrielsilveiraa)## License
TagMenu is available under the MIT license. See the LICENSE file for more info.