All Projects → TeamWertarbyte → Material Ui Snackbar Provider

TeamWertarbyte / Material Ui Snackbar Provider

Licence: mit
A convenient way to use material-ui's snackbars.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Material Ui Snackbar Provider

Notistack
Highly customizable notification snackbars (toasts) that can be stacked on top of each other
Stars: ✭ 2,562 (+4170%)
Mutual labels:  material-ui, snackbar
Ct Vue Material Dashboard Pro
Vue Material Dashboard Pro - Material Design Admin
Stars: ✭ 58 (-3.33%)
Mutual labels:  material-ui
Luna
Manage npm dependencies through a modern UI.
Stars: ✭ 948 (+1480%)
Mutual labels:  material-ui
Veluxi Starter
Veluxi Vue.js Starter Project with Nuxt JS and Vuetify
Stars: ✭ 39 (-35%)
Mutual labels:  material-ui
Cameria Facial Recognition
A react-redux based progressive web application that makes use of material-ui to enable facial recognition
Stars: ✭ 32 (-46.67%)
Mutual labels:  material-ui
Feliz.materialui
Feliz-style Fable bindings for Material-UI
Stars: ✭ 42 (-30%)
Mutual labels:  material-ui
Elephant
Elephant is PHPHub Community Android unofficial client, base on Material Design + MVP+RxJava+Retrofit .
Stars: ✭ 949 (+1481.67%)
Mutual labels:  material-ui
Flutter gank
Flutter版 干货集中营
Stars: ✭ 60 (+0%)
Mutual labels:  material-ui
Material Ui Password Field
A password field using Material-UI.
Stars: ✭ 54 (-10%)
Mutual labels:  material-ui
Future Web
Starter kit to create PWA with cutting edge technologies
Stars: ✭ 38 (-36.67%)
Mutual labels:  material-ui
Nestpress
A production ready personal blogging system on top of NestJS and NEXT.js
Stars: ✭ 38 (-36.67%)
Mutual labels:  material-ui
Electra
A desktop application for test account managment
Stars: ✭ 32 (-46.67%)
Mutual labels:  material-ui
Vuetify Material Dashboard
Vuetify Material Dashboard - Open Source Material Design Admin
Stars: ✭ 1,023 (+1605%)
Mutual labels:  material-ui
Materialdesignlite
This project prime goal is to bind the google's Material Design Lite project to Seaside and as second goal to build widgets on top of Material Design to help Seaside developers to create web applications with material design faster.
Stars: ✭ 30 (-50%)
Mutual labels:  material-ui
Expenses
💰Expense tracker using Google Sheets 📉 as a storage written in React
Stars: ✭ 1,105 (+1741.67%)
Mutual labels:  material-ui
Web3studio Sojourn
A React Native DevKit with code for a Web3 Decentralized Data Storage Pattern.
Stars: ✭ 29 (-51.67%)
Mutual labels:  material-ui
Seven23
Fully manual budget app to track personal expenses. 100% opensource, with privacy by design.
Stars: ✭ 36 (-40%)
Mutual labels:  material-ui
React Material Admin
☄️React Material Admin is a React template built with Material-UI
Stars: ✭ 1,005 (+1575%)
Mutual labels:  material-ui
Fable Material Ui
Fable bindings for Material-UI https://mvsmal.github.io/fable-material-ui/
Stars: ✭ 60 (+0%)
Mutual labels:  material-ui
Catify
Utility for Spotify, even your cat can use Spotify now !
Stars: ✭ 59 (-1.67%)
Mutual labels:  material-ui

Material-UI Snackbar Provider

JavaScript Style Guide Build Status Coverage Status

A convenient way to use material-ui's snackbars.

Installation

npm i --save material-ui-snackbar-provider

Usage

Simply wrap all components that should display snackbars with the SnackbarProvider component, e.g. by wrapping your router with it.

import { SnackbarProvider } from 'material-ui-snackbar-provider'

// somewhere at the root of your app
<SnackbarProvider SnackbarProps={{ autoHideDuration: 4000 }}>
  {/* the rest of your app belongs here, e.g. the router */}
</SnackbarProvider>

You can then display messages with the useSnackbar hook. More examples can be found here.

import { useSnackbar } from 'material-ui-snackbar-provider'

export default function MyComponent (props) {
  const snackbar = useSnackbar()

  const handleSomething = () => {
    snackbar.showMessage(
      'Something happened!',
      'Undo', () => handleUndo()
    )
  }

  const handleUndo = () => {
    // *snip*
  }

  return (
    // *snip*
  )
}

If you're not using React ^16.8.0 and our you can't use hooks (e.g. in a class component), you can use the withSnackbar HOC and the injected snackbar prop instead.

import { withSnackbar } from 'material-ui-snackbar-provider'

class MyComponent {
  // *snip*

  handleSomething () {
    this.props.snackbar.showMessage(
      'Something happened!',
      'Undo', () => this.handleUndo())
  }

  handleUndo () {
    // *snip*
  }
}

export default withSnackbar()(MyComponent) // export the wrapped component

Snackbar variants

Snackbar variants (i.e. diffent styles for different types of messages) can be implemented using the Alert component from @material-ui/lab. An example that also adds a custom hook to display snackbars with different severities is available here.

SnackbarProvider Props

Name Type Default Description
ButtonProps object Props to pass through to the action button.
children node The children that are wrapped by this provider.
SnackbarComponent ReactElement Custom snackbar component.
SnackbarProps object Props to pass through to the snackbar.

* required property

Snackbar methods

snackbar.showMessage(message, [action, handler, customParameters])

  • message (string) – message to display
  • action (string, optional) – label for the action button
  • handler (function, optional) – click handler for the action button
  • customParameters (any, optional) - custom parameters that will be passed to the snackbar renderer

Concerns

Dude, this is not pretty React-like, I don't want to call a function to do something that changes the UI! I want to display a snackbar based on the state only, e.g. by using Redux.

I agree. And if it wouldn't be an absolute pain to do that if you intend to display more than one snackbar, this package wouldn't even exist. The thing is that most of the time, snackbars are displayed when state changes and not really depend on the state itself.

Also, calling a method after dispatching the action is pretty convenient, especially when using something like redux-thunk:

deleteEmail (id) {
  this.props.dispatch(someReduxThunkAction())
  .then(() => {
    this.snackbar.showMessage(
      'E-mail deleted',
      'Undo', () => this.restoreEmail(id))
  })
  .catch((e) => {
    this.snackbar.showMessage(
      'E-mail could not be deleted',
      'Retry', () => this.deleteEmail(id))
  })
}

So this package makes snackbars a lot easier to use, which is all it's intended to do.

License

The files included in this repository are licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].