Git Product home page Git Product logo

snackbar's Introduction

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

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.

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 file for details.

Contributing

Contributions are welcome! Please refer to the Contribution Guidelines for more details.

Support

If you like Snackbar, consider also to check the app (Lasso - Window Manager for macOS) where I'm using it'.

snackbar's People

Contributors

isapozhnik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.