third party plugins
Tailwind CSS Notyf (Toasts)
Transform Your User Experience with Seamlessly Integrated and Customizable Toast Notifications, Tailored for Modern Web Applications.
Below are the comprehensively outlined steps you can follow to seamlessly integrate Notyf JS with FlyonUI.
- 1Installation
Install
notyf
using npm:npm install notyf
- 2Include Notyf JavaScript and CSS
Add the following CSS and JavaScript to your page:
<head> <link rel="stylesheet" href="../path/to/notyf/notyf.css" /> </head> <body> <script src="../path/to/notyf/notyf.js"></script> </body>
Note: A CDN link will not work here because we need to customize the default Vendor CSS to align with FlyonUI's design.
- 3Update Tailwind Configuration
Update your Tailwind configuration file to include the path to the Notyf JavaScript files. Additionally, set
vendors: true
in the FlyonUI config to ensure the override CSS is generated:module.exports = { content: [ '../path/to/notyf/**/*.js', ], flyonui: { vendors: true // Enable vendor-specific CSS generation } }
- 4Initialize Notyf
Add the initialization JavaScript code for Notyf after including the Notyf JS library. Set up an event listener on any element to trigger the Notyf instance. Ensure this Notyf JS file is monitored by TailwindCSS, as described in step 3.
For more options and detailed configurations, refer to the Notyf JS documentation .
// Notyf instance const notyf = new Notyf(); // Trigger Notyf on button click document.getElementById('trigger-btn').addEventListener('click', function () { notyf.success('This is a primary notification!'); });
Use the example below for default notification, initialized with the JS code provided below.
<button class="btn btn-primary" id="notyf-default-example">Default notyf</button>
<script>
window.addEventListener('load', function () {
const notyfDefault = new Notyf()
document.getElementById('notyf-default-example').addEventListener('click', function () {
notyfDefault.success('This is primary notification!')
})
})
</script>
Use the example below for custom notification, initialized with the JS code provided below.
<button class="btn btn-primary" id="notyf-custom-example">Custom notyf</button>
<script>
window.addEventListener('load', function () {
const notyfCustom = new Notyf({
duration: 3000,
position: {
x: 'right',
y: 'top'
},
types: [
{
type: 'primary',
background: '#7367F0',
icon: { className: 'icon-[tabler--circle-check] !text-primary', tagName: 'i' },
text: '',
color: 'white'
}
]
})
document.getElementById('notyf-custom-example').addEventListener('click', function () {
notyfCustom.open({
type: 'primary',
message: 'This is primary notification!',
duration: 3000,
ripple: true,
dismissible: true
})
})
})
</script>
Use the Notyf generator
below to create custom notifications according to your requirements for position, type, behavior, message, and duration.
<div class="card mt-6 max-w-lg max-sm:w-64">
<form id="notificationForm">
<div class="card-body space-y-4">
<!-- Message -->
<label class="form-control">
<div class="label">
<span class="label-text">Message</span>
</div>
<input id="notyf-value" type="text" placeholder="Notification message" class="input" autofocus />
</label>
<!-- Number -->
<label class="form-control">
<div class="label">
<span class="label-text">Duration</span>
</div>
<input id="notyf-number" type="number" placeholder="1000 (Milliseconds)" class="input" min="1000" />
</label>
<!-- position - X -->
<div class="flex flex-col">
<label class="form-control">
<div class="label">
<span class="label-text">Position - X</span>
</div>
</label>
<div class="flex flex-wrap gap-3">
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-x" class="radio radio-primary" value="left" checked />
<span class="label cursor-pointer">
<span class="label-text text-base">Left</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-x" class="radio radio-primary" value="center" />
<span class="label cursor-pointer">
<span class="label-text text-base">Center</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-x" class="radio radio-primary" value="right" />
<span class="label cursor-pointer">
<span class="label-text text-base">Right</span>
</span>
</label>
</div>
</div>
<!-- position - Y -->
<div class="flex flex-col">
<label class="form-control">
<div class="label">
<span class="label-text">Position - Y</span>
</div>
</label>
<div class="flex flex-wrap gap-3">
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-y" class="radio radio-primary" value="top" checked />
<span class="label cursor-pointer">
<span class="label-text text-base">Top</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-y" class="radio radio-primary" value="center" />
<span class="label cursor-pointer">
<span class="label-text text-base">Center</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-y" class="radio radio-primary" value="bottom" />
<span class="label cursor-pointer">
<span class="label-text text-base">Bottom</span>
</span>
</label>
</div>
</div>
<!-- Behavior -->
<div class="flex flex-col">
<label class="form-control">
<div class="label">
<span class="label-text">Behavior</span>
</div>
</label>
<div class="flex flex-col gap-2 sm:flex-row sm:gap-4">
<label class="form-control flex items-center gap-2">
<input id="notyf-ripple" type="checkbox" class="checkbox checkbox-primary" checked />
<span class="label cursor-pointer">
<span class="label-text text-base">With Ripple effect</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input id="notyf-dismiss" type="checkbox" class="checkbox checkbox-primary" />
<span class="label cursor-pointer">
<span class="label-text text-base">Dismissible</span>
</span>
</label>
</div>
</div>
<!-- Type -->
<div class="flex flex-col">
<label class="form-control">
<div class="label">
<span class="label-text">Type</span>
</div>
</label>
<div class="flex flex-col gap-2 sm:flex-row sm:gap-4">
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-type" class="radio radio-primary" value="success" checked />
<span class="label cursor-pointer">
<span class="label-text text-base">Success</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-type" class="radio radio-primary" value="info" />
<span class="label cursor-pointer">
<span class="label-text text-base">Info</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-type" class="radio radio-primary" value="warning" />
<span class="label cursor-pointer">
<span class="label-text text-base">Warning</span>
</span>
</label>
<label class="form-control flex items-center gap-2">
<input type="radio" name="radio-type" class="radio radio-primary" value="error" />
<span class="label cursor-pointer">
<span class="label-text text-base">Error</span>
</span>
</label>
</div>
</div>
<button id="notyf-submit" type="submit" class="btn btn-primary">Show Notification</button>
</div>
</form>
</div>
<script>
window.addEventListener('load', function () {
const notyf = new Notyf({
duration: 3000,
position: {
x: 'right',
y: 'top'
},
types: [
{
// Added Info and Warning type
type: 'info',
background: '#06B6D4',
icon: { className: 'icon-[tabler--info-circle] !text-info', tagName: 'i' },
text: '',
color: 'white'
},
{
type: 'warning',
background: '#FCAA1D',
icon: { className: 'icon-[tabler--alert-triangle] !text-warning', tagName: 'i' },
text: '',
color: 'white'
}
]
})
document.getElementById('notificationForm').addEventListener('submit', function (event) {
event.preventDefault()
// Get values from the form
let message = document.getElementById('notyf-value').value || 'This is a notification!'
let duration = parseInt(document.getElementById('notyf-number').value) || 3000 // Default duration to 3000 if not specified
let positionX = document.querySelector('input[name="radio-x"]:checked').value
let positionY = document.querySelector('input[name="radio-y"]:checked').value
let ripple = document.getElementById('notyf-ripple').checked
let dismissible = document.getElementById('notyf-dismiss').checked
let type = document.querySelector('input[name="radio-type"]:checked').value
// Update Notyf instance with dynamic position
notyf.options.duration = duration
notyf.options.position = {
x: positionX,
y: positionY
}
// Show the toast notification
notyf.open({
type: type,
message: message,
duration: duration,
ripple: ripple,
dismissible: dismissible
})
})
})
</script>