1.2.0 • Published 3 years ago

snackfy v1.2.0

Weekly downloads
6
License
ISC
Repository
github
Last release
3 years ago

Snackfy

Snackfy is a notification provider for React that can easily show, stack up, queue and customize notifications inside your react app.

snackfy

Installation

Use npm package manager to install snackfy.

npm install snackfy

Basic usage

1) Wrap your App inside SnackbarProvider

import { SnackbarProvider } from 'snackfy';

<SnackbarProvider>
  <App/>
</SnackbarProvider>

2) Import useSnackbar, this hook has two methods "enqueueSnackbar" and "closeSnackbar". the method "enqueueSnackbar" returns the snackbar id that can be provided to "closeSnackbar" if needed.

import { useSnackbar } from 'snackfy';

const MyComponent = () => {
  const { enqueueSnackbar } = useSnackbar();

  const handleClick = () => {
    enqueueSnackbar({
      message: 'This is an awesome Snackbar!'
    });
  };

  return (
    <Button onClick={handleClick}>Show snackbar</Button>
  );
}

Props

SnackbarProvider

PropertyTypeDefaultDescription
maxSnacksnumber3Maximum amount of snackbars that will be displayed at same time (recommended to keep the maximum to 3 snackbars)
placementplacement objectundefinedObject that determines the vertical and horizontal placement
customIconanyundefinedProperty that replace the default snackbar icon
customDismissanyundefinedProperty to replace the default dismiss icon
customStylecustom style objectundefinedObject that replace the default style for all snackbars

placement props (object prop from SnackbarProvider)

PropertyTypeDefaultDescription
vertical'top' or 'bottom'Prop that determines the vertical placement
horizontal'left' or 'center' or 'right'Props that determines the horizontal placement

custom style props (object prop from SnackbarProvider and enqueueSnackbar options)

PropertyTypeDefaultDescription
defaultReact.CSSPropertiesundefinedProp that overides snackbar default style
successReact.CSSPropertiesundefinedProp that overides snackbar success variant default style
errorReact.CSSPropertiesundefinedProp that overides snackbar error variant default style
warningReact.CSSPropertiesundefinedProp that overides snackbar warning variant default style
infoReact.CSSPropertiesundefinedProp that overides snackbar info variant default style

enqueueSnackbar props (returns id type: number)

PropertyTypeDefaultDescription
messagestringMessage that will be displayed in the snackbar
actionsobject (Actions)Object that contains the actions (max: 2), for each action will be generated a button
optionsobject (Options)Object that contains the options to customize your snackbars

actions props (object prop from enqueueSnackbar)

PropertyTypeDefaultDescription
firstobject (Action)This is required only if actions is set on enqueueSnackbar and receive an action object (see below)
secondobject(Action)The second action is not required and receive an action object

options props (object prop from enqueueSnackbar)

PropertyTypeDefaultDescription
countdownnumber5000The amount of milliseconds the snackbar will remain open
persistbooleanfalseIf set to true, the snackbar will never be closed, unless if you pass the id to closeSnackbar or set dismissible to true (see more below)
dismissiblebooleanfalseSet to true to show a close icon (x) in the snackbar that closes the snackbar when pressed
variant'sucess' or 'error' or 'warning' or 'info'Apply the variant style to the snackbar
customIconanyundefinedProperty that replace the default snackbar icon (will override Provider customIcon)
customDismissanyundefinedProperty to replace the default dismiss icon (will override Provider customDismiss)
customStylecustom style objectundefinedObject that replace the default style for all snackbars (will override Provider customStyle)

action props (object prop from actions)

PropertyTypeDefaultDescription
namestringThe action name that will be displayed in the button
actionFunctionThe action that will be triggered when the button is pressed

Contributing

Pull requests are welcome. If you have any trouble, open an issue and I will solve soon as possible.

Author

Bruno Kurt

e-mail

instagram