Simple notifications component
npm install notification-basisnotifications are alerting components types.
.notifications already on DOM) or triggered manually (eg. after a user has clicked on something)
.notification is when a user has just been redirected to a new page after some kind of event.
Welcome on your profile page
.notification class on one of your template's element.
.dismiss class directly on the notification or on a trigger element inside it.
Click anywhere to dismiss me
Click here to dismiss me
.--sticky class, it will remove the default duration.
I won't disappear... like ever...
--position-right, --width-auto):
--transition-slide):
--transition-fade):
.notification is to give a direct feedback to the user (without redirection or page reload).
create method.
typescript
`
#### Notification options
The create method accepts an option object as an optional second parameter:
`typescript
`
- classes: an array of classes (eg. classes: ["error", "small"])
default: empty array
Just pass the css classes you want for your notification (eg. "my-warning-notification").
- position: a string, either 'left' or 'right'
default: "left"
This option is used with width and/or transitions options.
Used with width: 'auto', the notification will stick on the position side of the screen (if its content isn't already screen wide).
Used with transitions: ['slide'], the notification will appear on screen from the position-hand side.
- width: a string, either 'full' or 'auto'
default: "auto"
By default a notification will be displayed on the entire device screen width ('full').
If this option is set to 'auto', the notification with only be as wide as its content.
- transitions: an array of transition modifiers (eg. transitions: ["slide", "fade", "insert-your-own"])
default: ["slide", "fade"]
Those two transitions are set by default because you will likely want them on your typical notification.
You can get rid of them by passing an empty array transitions: [] or your own custom transition(s).
Reveal Basis ships with a few transition modifiers:
"slide" will make your notification slide in and out of the screen.
"fade" will make it fade in and out.
You totally can combine all the transitions to achieve the effect you want.
To create your own transition, you will have to follow some simple rules:
- its class name has to start with .--transition-
- define the 'normal' and the 'is-visible' state
`css
/ my custom transition /
.--transition-custom {
transform: rotateZ(0deg);
width: 100%;
}
.--transition-custom.is-visible {
transform: rotateZ(720deg);
width: 25%;
}
`
- duration: an int
default: 6000
Duration is set in milliseconds (1000 equals 1 second) and represents the time the notification will be displayed.
A duration of 0 will keep the notification indefinitely on screen.
- speed: an int
default: 300
Speed is the transition speed. It will have no effect if no transitions are set transitions: [].
- dismissOnClick: a boolean
default: true
As its name implies, if dismissOnClick option is passed, the notification will be dismiss when user click on it.
The library add a dismiss` class on the notification. You can take advantage on this to add custom style to differentiate between dismissible notifications and non-dismissible ones.