1.0.4 • Published 5 years ago

fantoastic v1.0.4

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

Fantoastic

A fantastic library for all your toast needs.

Getting started

1. Install the library (React >= 16.8.0 is required)

npm install fantoastic --save

2. Import the ToastProvider at the root of your React application (ex. App.jsx) and wrap your application

import { withToastProvider } from 'fantoastic';

const App = () => {
  ...
  ...
  ...
}

const AppWithToastProvider = withToastProvider(App);
export default AppWithToastProvider;

3. You can now use the toast hook anywhere in the app where a toast is needed.

import { useToast } from 'fantoastic';

const SomeComponent = () => {
  const toast = useToast();

  const handleCreateToast = () => {
    toast.add('The simplest of the toasts.');
  };

return (
  <>
    <button onClick={handleCreateToast}>Click me!</button>
  </>
)

Extra configuration

The toast can be called with a variety of options: toast.add(content, options)

  toast.add('I am a fantastic toast', {
    position: 'topRight',
    variant: 'default',
    duration: '5000',
    persist: false,
    withCloseIcon: false,
  })

The complete list of confirations:

OptionTypeDefault ValueDescription
positionString between: 'topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'top', 'bottom''topRight'Sets location on the screen where the toast will be rendered
variantString between: 'default', 'primary', 'success', 'danger''default'Sets the variant (color) of the toast
durationNumber (in milliseconds)5000Sets the duration until the toast will be automatically closed
persistBooleanfalseMakes the toast to stay visible until it's manually closed
withCloseIconBooleanfalseRenders the toast with an close icon (X) on the top left corner

Development

Download the repo and in the root run npm run i-all to install all dependancies.

Installing

After installing dependancies, run npm run dev to start the development environment.

Running the tests

Run the tests and listen for changes with npm run test or npm run test:once to run only once.

Contributing

Contributions are more than welcome!

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the ISC License.

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago