npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nuxt-ctoast

v2.5.14

Published

New Nuxt3 cToast version!

Downloads

38

Readme


Menu


Features

  • 🌗 Themes
  • 🪝 Config base toasts
  • 🧊 Offline icons
  • 🪟 More toast positions

Quick Setup

  1. Add ctoast dependency to your project
# Using pnpm
pnpm add nuxt-ctoast

# Using yarn
yarn add nuxt-ctoast

# Using npm
npm install nuxt-ctoast
  1. Add ctoast to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-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

  1. Transfer when adding a module
// nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    ['cToast', { args }]
  ]
});
  1. Passing parameters through the namespace
export default defineNuxtConfig({
  cToast: {
      args
  }  
});

Interfaces

ModuleOptions

interface ModuleOptions {  
	// position on the screen
	// default: 'bottom-right'
	position: CToastOptionsPosition
	// maximum number of notifications on the screen at a time
	// default: 10
	maxToasts: number
	// the delay between replacing toasts at the loader
	// default: 300
	loaderSwitchDelay: number 
	// maximum delay when delay: false
	// default: 120000
	infinityDestroyDelay: number
	// delay between deleting notifications during mass deletion
	// default: 150
	massClearDelay: number
	toast: {
		// notification lifetime
		// default: 3000
		delay: number 
		// timer status
		// default: true
		timer: boolean
		onClick: CToastOnClickConfig
	}
	icons: {
		default: { // icon names for standard notifications
			success: string // default: 'mingcute:check-fill'
			error: string // default: 'pepicons-pop:times'
			warn: string // default: 'pajamas:warning-solid'
		}
		loader: { // icon names for the notification loader
			header: string // default: 'svg-spinners:tadpole'
			status: {  
				load: string // default: 'svg-spinners:3-dots-scale'
				success: string // default: 'mingcute:check-fill'
				error: string // default: 'pepicons-pop:times'
			}  
		}  
	}  
}
type CToastOptionsPosition =  
	| 'top-left'  
	| 'top-right'  
	| 'bottom-left'  
	| 'bottom-right';
type CToastOnClickConfig = {
	// whether to delete a notification by clicking on it
	// default: true 
	delete?: boolean
};

CToast

type CToastType = 'success' | 'error' | 'warn';
type CToastOnClick = {  
	delete?: boolean // whether to delete a notification by clicking on it
	func?: (toast: CToastPrepared) => void // called function when pressed
};
interface CToast {  
	type: CToastType // notification type
	title: string // notification title
	  
	description?: string // description of the notification
	delay?: number | false // delay before deletion
	name?: string // notification name
	icon?: string // notification icon
	timer?: boolean // timer status
	onClick?: CToastOnClick
}

CToastLoader

interface CToastLoaderData {  
	success: {
		toast: CToast // successful notification
		// called successful function
		on?: (toast: CToastPrepared) => void
	}
	error: {
		toast: CToast // erroneous notification
		// called error function
		on?: (toast: CToastPrepared, stage: keyof CToastLoaderStages) => void
	}
	stages: {
		// key: title - stage
		[name: string]: string  
	}
}
interface CToastLoader {
	type: CToastType // notification type
	title: string // notification title
	name: string // notification name
	loader: CToastLoaderData
	
	description?: string // description of the notification
	delay?: number | false // delay before deletion
	icon?: string // notification icon
}

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);
// quicke toasts with parameters
$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'
});
// or quicke toasts without parameters
$cToast.success('Test Success');
$cToast.info('Test Info');
$cToast.error('Test Error');

quickToasts

To call a test with a full list of parameters, the show function is used.


Method show

// full toast form
$cToast.show(data: CToast)

$cToast.show({  
	title: 'Тест зелёного',  
	description: 'Вроде есть',  
	type: 'success',  
	onClick: {  
		func: () => console.log('click')  
	},  
	delay: 10000,  
	icon: 'fa:ban'
})

quickToasts


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

// loader toast form
$cToast.showLoader(data: CToastLoader) => {
	success: (stage: string) => void
	error: (stage: string, desc?: string) => void
};
// loader toast example
$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'  
		}  
	}  
});

loaderSuccessTest loaderErrorTest

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';
// loader change status form
$cToast.loaderStatus({  
	name: string  
	stage: string
	status: CToastLoaderStagesStatuses
	desc?: string 
});
// loader change status example success
$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);
// example
$cToast.warn({ title: 'Test info', icon: 'ph:spinner', delay: false, name: 'test-replace' });
$cToast.replace('test-replace', { title: 'Replaced!', type: 'success' });

quickToasts


Method remove

A function that deletes a toast by its name.

$cToast.remove(name: string);
// example
$cToast.error({ title: 'Test Delete', delay: false, name: 'test-delete' });
$cToast.remove('test-delete');

quickToasts


Method clear

The function deletes all existing toasts. Does not need parameters.

$cToast.clear();

quickToasts


Enjoy using my toasts 🤗