0.0.14 • Published 2 years ago

react-snackbar-ui-customizable v0.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Example

without timer progressbarwith timer progressbar
imageimage2

Getting Started

Installation

$ npm i react-snackbar-ui-customizable
or
$ yarn add react-snackbar-ui-customizable

Features

Snackbar Provider Setup

To use snackbar, you must wrap the SnackbarContextProvider at the top of your application

import { SnackbarContextProvider } from 'react-snackbar-ui-customizable'

const App = () => {
  return (
    <SnackbarContextProvider>
      {children}
    </SnackbarContextProvider>
  )  
}

Snackbar Usage

Then you can use it by declaring it in a react hook method inside the component you need.

import { useSnackbar } from 'react-snackbar-ui-customizable'

const Example = (): JSX.Element => {
  const snackbar = useSnackbar();

  return (
    <button onClick={() => snackbar.on({ title: 'snackbar title', message: 'this is snackbar message' })}>
      Show Snackbar!
    </button>
  )
}

API

SnackbarContextProvider

( Required) | property name | Description | Type | | ------------- | ------------------------------ | --------- | | id | portal id. (default: snackbar-portal) | string | | option | portal options | OptionType | | `children` | your application components | JSX.Element |

option (all of the option property is optional) - OptionType

property nameDescriptionType
positionwill be displayed (top-left, top-center, top-right(default), bottom-left, bottom-center, bottom-right)string
zIndexz index (default: 100)number
duration0: infinity, 1 ~ : for the given time, snackbar appears and disappears (default: 3s)number(second(s))
successIconSuccess Icon (default: CheckCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
errorIconError Icon (default: WarningOutlined of @ant-design/icon)React.ReactNode | JSX.Element
warnIconWarning Icon (default: ExclamationCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
infoIconInformation Icon (default: InfoCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
closeIconClose Icon (default: CloseOutlined of @ant-design/icon)React.ReactNode | JSX.Element

useSnackbar

property nameDescriptionType
onexecution method for stacking snackbars on list(option: SnackbarOption) => void
offexcution method for removing snackbars on list(id: number) => void
lengthlength of snackbar listnumber
listsnack bar list currently being displayed on the screenArray

Snackbar Option (when you use on method of useSnackbar)

property nameDescriptionType
idsnackbar unique id (default: auto generation using uuid())string
titlesnackbar titlestring
message*snackbar messagestring
typesnackbar type'SUCCESS' | 'ERROR' | 'WARN' | 'INFO'
onCloseevent for close snackbar(id: string) => void
buttonTextaction button text located on the bottom rightstring
onClickButtonaction function when clicking action button, (caution) this property is always used with buttonText property() => void
duration0: infinity, 1 ~ : for the given time, snackbar appears and disappears (default: 3s)number(second(s))
successIconSuccess Icon (default: CheckCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
errorIconError Icon (default: WarningOutlined of @ant-design/icon)React.ReactNode | JSX.Element
warnIconWarning Icon (default: ExclamationCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
infoIconInformation Icon (default: InfoCircleOutlined of @ant-design/icon)React.ReactNode | JSX.Element
closeIconClose Icon (default: CloseOutlined of @ant-design/icon)React.ReactNode | JSX.Element

Guide

  1. Local option setting value is always applied before global option setting value.
    • In the example below, the duration is set to 10, which is set locally.
<SnackbarContextProvider
  id="snackbar-portal-unique-id"
  option={{ duration: 0 }}
>
  <Example />
</SnackbarContextProvider>

...
import { useSnackbar } from 'react-snackbar-ui-customizable'

const Example = (): JSX.Element => {
  const snackbar = useSnackbar();

  return (
    <button onClick={() => snackbar.on({ title: 'snackbar title', message: 'this is snackbar message', duration: 10 })}>
      Show Snackbar!
    </button>
  )
}

CSS Style

type is one of the injected snackbar type (SUCCESS, ERROR, WARN, INFO)

Snackbar Container

className: snackbar-container snackbar-container--{type}

Snackbar box

className: snackbar-box snackbar-box--{type}

Snackbar progressbar

className: snackbar-progressbar snackbar-progressbar--{type}

Snackbar title

className: snackbar-title snackbar-title--{type}

Snackbar description

className: snackbar-description snackbar-description--{type}

Snackbar button

className: snackbar-button snackbar-button--{type}

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago