1.1.0 • Published 6 months ago

@shawyu/toast v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@shawyu/toast

toast.js is a lightweight plugin for JavaScript and Node.js.

Github地址

https://github.com/shawyuu/js-plugin/tree/main/toast

Getting started

Install

npm install @shawyu/toast

In browser

<script src="../toast/index.js"></script>

Usage

import Toast from '@shawyu/toast'

Toast.show('Toast Tip')

When the option is string!

Toast.show('Toast Tip')
Toast.primary('primary Tip')
Toast.success('success Tip')
Toast.warning('warning Tip')
Toast.error('error Tip')
Toast.info('info Tip')

Toast.loading('Loading...') //When this type is loading! You must manually turn it off

setTimeout(()=>{
	Toast.hideLoading()
},1000)

When the option is object!

When showClose is true! It will not automatically shut down. When you call the function(like Toast.primary(),Toast.warning(),Toast.error(),Toast.info(),Toast.loading()). the type parameter will become invalid.

Toast.show({
	title:'Toast Tip',
	showClose:true,
	type:'info',
	placement:"center"
})


Toast.success({
	title:'Toast Tip',
	placement:"top",
	type:'info'  // is invalid
})

Toast.custom({
	title:'Toast Tip',
	placement:"top",
	bgColor:"linear-gradient(45deg, #96fbc4 0%, #f9f586 100%)",
	color:"#086030",
	type:'custom'
})

Toast.loading({
	title: 'loading',
	placement: 'center',
	bgColor: 'rgba(0,0,0,0.75)',
	color: '#fff',
	mask:false,
	loadingStyle: 'circle'
})

Toast.setText('loading 90%')

setTimeout(()=>{
	Toast.hideLoading({
		delay:1000,  // delay to run callback, default value:500
		success:()=>{
			console.log('it closed')
		},
		fail:()=>{
			console.log('fail')
		}
	})				
},1000)				

All Props

PROPTYPEDEFAULTREQUIREDDESCRIPTION
titlestring""YESThe title of the Toast.
typestringdefaultNOThe type of Toast.Possible values:default,primary,success,warning,error,info,custom
placementstringcenterNOPositions the toast relative to its reference element.Possible values:top,center,bottom
bgColorstringrgba(0,0,0,0.75)YESBackground of the toast. it takes effect when the type is custom or use Toast.loading.
colorstring#fffNOThe text color of toast. , it takes effect when the type is custom or use Toast.loading
durationstring\|number1000NODelay duration for automatic shutdown.
showClosebooleanfalseNODetermines if the toast has an close btn(icon).it takes effect when the type is one of primary,success,warning,error,info,when it's true,you must handle to close it
showIconbooleantrueNODetermines if the toast has an icon.it takes effect when the type is one of primary,success,warning,error,info
maskbooleanfalseNODetermine if the toast requires a mask.
onClosefunctionnullNOcallback function
loadingStylestringcircleNOwhen type is loading, it takes effect.Possible values:circle,point ,it takes effect when use Toast.loading.

Logs

1.0.0 version\ 1.0.1 fix\ 1.0.2 optimize 1.0.3 add showIcon and onClose(callback)\ add hideLoading(when use Toast.loading,you must use Toast.hideLoading to close it)\ 1.0.4 fix parameter error\ 1.0.5 Cancel loading animation 1.0.9 add setText()

1.1.0

6 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

1 year ago