https://github.com/isapozhnik/snackbar
A Snackbar for macOS applications
https://github.com/isapozhnik/snackbar
appkit cocoa macos snackbar snackbar-notification swift toast toast-message toast-notifications
Last synced: about 1 month ago
JSON representation
A Snackbar for macOS applications
- Host: GitHub
- URL: https://github.com/isapozhnik/snackbar
- Owner: iSapozhnik
- License: mit
- Created: 2023-07-19T19:17:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-30T00:49:14.000Z (5 months ago)
- Last Synced: 2025-03-29T16:51:12.502Z (2 months ago)
- Topics: appkit, cocoa, macos, snackbar, snackbar-notification, swift, toast, toast-message, toast-notifications
- Language: Swift
- Homepage:
- Size: 2.26 MB
- Stars: 14
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Snackbar Component for Cocoa
[](LICENSE)
A lightweight and customizable Snackbar component for Cocoa, designed to display brief informative messages to users.
## Demo

## Features
- Display short messages or notifications to users
- Customizable appearance, including background color, text color, and animation duration
- Support for action buttons and callback handlers
- Easy integration into existing Cocoa projects## Installation
### Cocoapods
Swift PAckage manager is your friend.
## Usage
### Initialization
Make a theme
```swift
extension SnackbarTheme where Self == DefaultSnackbarTheme {
static var info: SnackbarTheme { DefaultSnackbarTheme(withStyle: .info) }
static var alert: SnackbarTheme { DefaultSnackbarTheme(withStyle: .alert) }
static var warning: SnackbarTheme { DefaultSnackbarTheme(withStyle: .warning) }
static var success: SnackbarTheme { DefaultSnackbarTheme(withStyle: .success) }
}struct DefaultSnackbarTheme: SnackbarTheme {
var style: SnackbarStyle
init(withStyle style: SnackbarStyle) {
self.style = style
}var textColor: NSColor { .labelColor }
var backgroundColor: NSColor {
switch style {
case .alert:
return .systemRed
case .success:
return .systemGreen
case .warning:
return .systemOrange
case .info:
return .systemBlue
}
}var borderColor: NSColor {
.secondaryLabelColor
}
}
```### Displaying a Snackbar
Snackbar with action buttons and icon.
```swift
let theme: SnackbarTheme = .alert
let actions = [
SnackbarAction(
title: NSLocalizedString("Remove", comment: ""),
icon: nil,
type: .primary,
action: {}
),
SnackbarAction(
title: NSLocalizedString("Later", comment: ""),
icon: nil,
type: .secondary,
action: {}
),
]
Snackbar.show(
theme: theme,
type: .permanent,
title: NSLocalizedString("Are you sure you want to remove all spaces?", comment: "").text,
subtitle: NSLocalizedString("You can not undo this action", comment: "").text,
actions: actions,
actionsLayout: .horizontal,
hasActionsSeparator: false,
icon: NSImage(named: "your_icon"),
fromWindow: view.window
)
```## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Contributing
Contributions are welcome! Please refer to the [Contribution Guidelines](CONTRIBUTING.md) for more details.
## Support
If you like Snackbar, consider also to check the app ([Lasso - Window Manager for macOS](https://thelasso.app)) where I'm using it'.