cToast

Features
- 🌗 Themes
- 🪝 Config base toasts
- 🧊 Offline icons
- 🪟 More toast positions
Quick Setup
- Add
ctoast dependency to your project
pnpm add ctoast
yarn add ctoast
npm install ctoast
- Add
ctoast to the modules section of nuxt.config.ts
export default defineNuxtConfig({
modules: [
'ctoast'
]
})
That's it! You can now use cToast in your Nuxt app ✨
Setting standard parameters
There are 2 ways to pass parameters to the module
- Transfer when adding a module
export default defineNuxtConfig({
modules: [
['ctoast', { args }]
]
})
- Passing parameters through the namespace
export default {
ctoast: {
args
}
}
Parameters (args)
interface ModuleOptions {
position: CToastOptionsPosition
maxToasts: number
loaderSwitchDelay: number
infinityDestroyDelay: number
massClearDelay: number
toast: {
delay: number
timer: boolean
onClick: CToastOnClickConfig
}
icons: {
default: {
success: string
error: string
warn: string
}
loader: {
header: string
status: {
load: string
success: string
error: string
}
}
}
}
type CToastOptionsPosition =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right';
type CToastOnClickConfig = {
delete?: boolean
};
CToast
type CToastType = 'success' | 'error' | 'warn';
type CToastOnClick = {
delete?: boolean
func?: (toast: CToastPrepared) => void
};
interface CToast {
type: CToastType
title: string
description?: string
delay?: number | false
name?: string
icon?: string
timer?: boolean
onClick?: CToastOnClick
}
CToastLoader
interface CToastLoaderData {
success: {
toast: CToast
on?: (toast: CToastPrepared) => void
}
error: {
toast: CToast
on?: (toast: CToastPrepared, stage: keyof CToastLoaderStages) => void
}
stages: {
[name: string]: string
}
}
interface CToastLoader {
type: CToastType
title: string
name: string
loader: CToastLoaderData
description?: string
delay?: number | false
icon?: string
}
Methods
Methods success, warn, error
Standard functions for quickly calling toasts. At the moment there are 4 types.
type CToastWithoutMeta<T extends CToastForm> = Omit<T, 'type'>;
type CToastCreate = string | CToastWithoutMeta<CToast>;
$cToast.success(data: CToastCreate);
$cToast.warn(data: CToastCreate);
$cToast.error(data: CToastCreate);
$cToast.success({
title: 'Test Success',
delay: false
});
$cToast.warn({
title: 'Test info',
icon: 'ph:spinner',
delay: false,
name: 'test-replace'
});
$cToast.error({
title: 'Test Delete',
delay: false,
name: 'test-delete'
});
$cToast.success('Test Success');
$cToast.info('Test Info');
$cToast.error('Test Error');

To call a test with a full list of parameters, the show function is used.
Method show
$cToast.show(data: CToast)
$cToast.show({
title: 'Тест зелёного',
description: 'Вроде есть',
type: 'success',
onClick: {
func: () => console.log('click')
},
delay: 10000,
icon: 'fa:ban'
})

Method showLoader NEW
This type of toast is designed to remove spam from the website interface. It is called once with all the necessary parameters and then, as something is loaded on the page, using an additional method, the state of each of the parameters changes.
An example of calling this toast
$cToast.showLoader(data: CToastLoader) => {
success: (stage: string) => void
error: (stage: string, desc?: string) => void
};
$cToast.showLoader({
title: 'Test Loader',
description: 'A new loader toast has been released. Check out the new documentation',
name: 'test-loader',
loader: {
success: {
toast: {
title: 'Good reviews have not been received'
},
on: () => console.log('success')
},
error: {
toast: {
title: 'Thank you for support'
},
on: () => console.log('error')
},
stages: {
'test-1': 'search for an idea',
'test-2': 'implementation of the idea',
'test-3': 'good reviews'
}
}
});

To change the loading state, the editLoaderStatus method is used
Method editLoaderStatus NEW
This method works in conjunction with showLoader and nothing else.
type CToastLoaderStagesStatuses = 'load' | 'success' | 'error';
$cToast.loaderStatus({
name: string
stage: string
status: CToastLoaderStagesStatuses
desc?: string
});
$cToast.loaderStatus('loader-test', 'test-1', 'error', 'error description');
Method replace
It is also possible to make toasts immortal. To do this, just enter the false value in the delay parameters.
Such toasts can be destroyed by clicking the mouse (if deletion is enabled), reloading the page, clearing all toasts, deleting by name, but not by time (unless you have infinityDestroyDelay set to a very small value).
If you use immortal toast when loading something, then the replace function is perfect for your purposes.
The function will delete the immortal toast by its name and create a new one based on the data just passed.
$cToast.replace(name: string, toast: CToast);
$cToast.warn({ title: 'Test info', icon: 'ph:spinner', delay: false, name: 'test-replace' });
$cToast.replace('test-replace', { title: 'Replaced!', type: 'success' });

Method remove
A function that deletes a toast by its name.
$cToast.remove(name: string);
$cToast.error({ title: 'Test Delete', delay: false, name: 'test-delete' });
$cToast.remove('test-delete');

Method clear
The function deletes all existing toasts. Does not need parameters.
$cToast.clear();

Enjoy using my toasts 🤗