3.8.3 • Published 1 month ago

@toujou/toujou-snackbar v3.8.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Toujou Snackbar

The toujou snackbar element is a way to provide brief messages / acknowledgements to the user.

It may or may not require an action from the user.

We can customize the toujou-snackbar type ('auto' or 'action'), message, duration and button properties, and use it with one of the available variants (default. success, warning, error, info).

Installation

  npm install @toujou/toujou-snackbar

Events

add-snackbar event

The toujou-snackbar element is triggered via the add-snackbar custom event (which can be dispatch by any other elements). The add-snackbar event needs:

PropertyTypeDescriptionAccepted ValuesDefaultRequired by
messageStringText that will be displayed in the snackbar--Always
typeStringThis defines if the snackbar needs action from the user of if is temporary'action', 'auto'-always
buttonTextStringDefines the text on the button-'OK'action'
durationNumberNumber of milliseconds to show the snackbar-3000'auto'
variantStringName of variant to use'success', 'warning', 'error', 'info'--

Examples of add-snackbar custom events

'Auto' Snackbar.

'Auto' Snackbars are dismissed automatically after a certain amount of time. The suggested values are between 3 and 10 seconds.

const addSnackbarEvent = new CustomEvent('add-snackbar', {
   bubbles: true,
   composed: true,
   detail: {
      message: `welcome to the bonus page!`,
      type: 'auto',
      duration: 4000,
      variant: 'success'
   }
})

'Action' Snackbar.

'Action' Snackbars are not dismissed automatically. The user needs to take action to dismiss them.

const addSnackbarEvent = new CustomEvent('add-snackbar', {
   bubbles: true,
   composed: true,
   detail: {
      message: `Settings saved!`,
      type: 'action',
      buttonText: 'Dismiss'
   }
})

Custom CSS properties

We can style the toujou-snackbar element by using custom css properties

Style the toujou-snackbar element:

PropertyDescriptionDefault
--toujou-snackbar-bg-colorSet background-color of the element#2c2c2c
--toujou-snackbar-borderSet border of the element1px solid --bg-color
--toujou-snackbar-displaySet display of the elementflex
--toujou-snackbar-widthSet width of the elementcalc(100% - 2rem)
--toujou-snackbar-max-widthSet max-width of the element640px
--toujou-snackbar-positionSet position of the elementfixed
--toujou-snackbar-bottomSet bottom of the element1rem
--toujou-snackbar-leftSet left of the element1rem
--toujou-snackbar-paddingSet padding of the element1rem
--toujou-snackbar-border-radiusSet border-radius of the element.25rem
--toujou-snackbar-z-indexSet z-index of the element100
--toujou-snackbar-transformSet transform of the elementtranslateY(calc(100% - 1rem))
--toujou-snackbar-opacitySet opacity of the element0
--toujou-snackbar-transitionSet transition of the elementall .25s ease-out

Style the toujou-snackbar[visible]:

PropertyDescriptionDefault
--toujou-snackbar-visible-transformSet transform of the element with visible attributetranslateY(0)
--toujou-snackbar-visible-opacitySet opacity of the element with visible attribute1

Style the .snackbar__message inside the toujou-snackbar element

PropertyDescriptionDefault
--toujou-snackbar-message-growSet flex-grow of the .snackbar__message1
--toujou-snackbar-message-colorSet color of the .snackbar__messagewhite
--toujou-snackbar-message-marginSet margin of the .snackbar__message0
--toujou-snackbar-message-paddingSet padding of the .snackbar__message0 1rem 0 0

Style the .snackbar__button inside the toujou-snackbar element

PropertyDescriptionDefault
--toujou-snackbar-button-borderSet border of the .snackbar__buttonnone
--toujou-snackbar-button-bgSet background of the .snackbar__buttonnone
--toujou-snackbar-button-font-sizeSet font-size of the .snackbar__button.875rem
--toujou-snackbar-button-text-transformSet text-transform of the .snackbar__buttonuppercase
--toujou-snackbar-button-colorSet color of the .snackbar__button--primary-color
--toujou-snackbar-button-marginSet margin of the .snackbar__button0
--toujou-snackbar-button-outlineSet outline of the .snackbar__buttonnone

Style the .snackbar__button:hover inside the toujou-snackbar element

PropertyDescriptionDefault
--toujou-snackbar-button-hover-cursorSet cursor of the .snackbar__button:hoverpointer
--toujou-snackbar-button-hover-opacitySet opacity of the .snackbar__button:hover.75

Variants

The toujou-snackbar element has 5 variants: default, success, warning, error and info.

To choose the variant you want to use you just need to add the variant property to the add-snackbar custom event.

If there is no variant property, the default variant will be used.

Variant styles

You can also customize some variant styles using custom CSS variables.

Success Variant

Should be used to show a success message to the user, for instance a 'successfully saved' message.

PropertyDescriptionDefault
--toujou-snackbar-success-borderSet border of the toujou-snackbar[success]1px solid --success-color
--toujou-snackbar-success-message-colorSet color of the toujou-snackbar[success] .snackbar__message--success-color
--toujou-snackbar-success-button-colorSet color of the toujou-snackbar[success] .snackbar__buttonwhite

Warning Variant

Should be used to show a warning message to the user, for instance a 'your consent expires tomorrow' message

PropertyDescriptionDefault
--toujou-snackbar-warning-borderSet border of the toujou-snackbar[warning]1px solid --warning-color
--toujou-snackbar-warning-message-colorSet color of the toujou-snackbar[warning] .snackbar__message--warning-color
--toujou-snackbar-warning-button-colorSet color of the toujou-snackbar[warning] .snackbar__buttonwhite

Error Variant

Should be used to show an error message to the user, for instance 'there was an error while saving your settings' message

PropertyDescriptionDefault
--toujou-snackbar-error-borderSet border of the toujou-snackbar[error]1px solid --error-color
--toujou-snackbar-error-message-colorSet color of the toujou-snackbar[error] .snackbar__message--error-color
--toujou-snackbar-error-button-colorSet color of the toujou-snackbar[error] .snackbar__buttonwhite

Info Variant

Should be used to show an information message to the user, for instance 'there is a new update available'

PropertyDescriptionDefault
--toujou-snackbar-info-borderSet border of the toujou-snackbar[info]1px solid #81d4fa
--toujou-snackbar-info-message-colorSet color of the toujou-snackbar[info] .snackbar__message#81d4fa
--toujou-snackbar-info-button-colorSet color of the toujou-snackbar[info] .snackbar__buttonwhite
3.8.3

1 month ago

3.0.0

5 months ago

2.1.0

7 months ago

2.0.22

10 months ago

2.0.18

10 months ago

2.0.17

10 months ago

2.0.16

10 months ago