Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/openalloc/swiftnumberpad
A multi-platform SwiftUI component for basic number input
https://github.com/openalloc/swiftnumberpad
apple-watch decimal dialer digits ios ipados keyboard keypad macos number-pad numpad swift swift-lang swift-library swift-package swiftui swiftui-components watchos
Last synced: 2 months ago
JSON representation
A multi-platform SwiftUI component for basic number input
- Host: GitHub
- URL: https://github.com/openalloc/swiftnumberpad
- Owner: openalloc
- License: apache-2.0
- Created: 2023-03-14T18:53:31.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T23:59:28.000Z (over 1 year ago)
- Last Synced: 2024-10-31T12:41:32.560Z (3 months ago)
- Topics: apple-watch, decimal, dialer, digits, ios, ipados, keyboard, keypad, macos, number-pad, numpad, swift, swift-lang, swift-library, swift-package, swiftui, swiftui-components, watchos
- Language: Swift
- Homepage:
- Size: 161 KB
- Stars: 9
- Watchers: 0
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SwiftNumberPad
A multi-platform SwiftUI component for basic number input.
Available as an open source library to be incorporated in SwiftUI apps.
_SwiftNumberPad_ is part of the [OpenAlloc](https://github.com/openalloc) family of open source Swift software tools.
## Features
* Support for integer, floating point, and Decimal types
* Presently targeting .macOS(.v13), .iOS(.v16), .watchOS(.v9)
* No external dependencies!## Example
A basic example of Float-based input with a specified precision.
```swift
struct NumberPadExample: View {
@Binding var calories: Floatinit(myValue: Binding) {
_calories = myValue
config = .init(myValue.wrappedValue, precision: 1, upperBound: 1000)
}@ObservedObject var config: NPFloatConfig
var body: some View {
VStack {
Text("\(config.stringValue)")NumberPad(config: config)
.buttonStyle(.bordered)
}
.font(.largeTitle)
.navigationTitle("Calories")
.toolbar {
ToolbarItem {
Button("Save") {
calories = config.value ?? 0
}
}
}
.padding()
}
}struct NumPadExample_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
NumberPadExample(myValue: .constant(Float(233.6)))
}
}
}
```## TODO
Please submit pull requests if you'd like to tackle any of these. Thanks!
* Usage documentation in this README
* SwiftUI Preview not reliably working on macOS
* See if earlier versions of platforms can be supported
* Support for negative values## See Also
This library is a member of the _OpenAlloc Project_.
* [_OpenAlloc_](https://openalloc.github.io) - product website for all the _OpenAlloc_ apps and libraries
* [_OpenAlloc Project_](https://github.com/openalloc) - Github site for the development project, including full source code## License
Copyright 2023 OpenAlloc LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
## Contributing
Contributions are welcome. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features.
The pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.