Snack

The Snack component provides a simple, customizable snack notification that can be used to display success, error, or other messages. It automatically fades out after a specified duration and can also be manually dismissed using a callback.

Installation

bash
npm i @anakin-gbit/snack

Usage

JSX
<Snack message="Operation successful!" />
<Snack message="An error occurred." type="error" />

Props

PropTypeDefaultDescription
messagestring-The message to display in the snack.
type'success' | 'error''success'The type of the snack, determining its color. Defaults to 'success'.
durationnumber3000The duration (in milliseconds) for which the snack will be displayed before automatically disappearing.
onClosefunction-An optional callback function that will be called when the snack closes.

Example Usage

JSX
<Snack message="Operation successful!" />
<Snack message="An error occurred." type="error" />

Styling

The snack component is styled using the following CSS classes:

  • .snackWrapper: The wrapper that controls the height transition when showing or hiding the snack.
  • .snack: The actual snack container. It has a default background color for success messages.
  • .snack.success: Specific styling for success messages.
  • .snack.error: Specific styling for error messages.

Example of Snack Types

Success
Error