1.0.5 • Published 2 years ago

vue3-toast-single v1.0.5

Weekly downloads
24
License
MIT
Repository
github
Last release
2 years ago

vue3-toast-single

Vue 3.x

A toast plugin for vue3. Support composition API.

See the example.

Note:

Issue/PR is welcomed, I'll response as soon as possible.

If you like this plugin, can give a star.

Usage

install

npm install vue3-toast-single --save

Quickstart

// import 
import Toast from 'vue3-toast-single'
import 'vue3-toast-single/dist/toast.css'

const app = createApp(App);

app.use(Toast, { verticalPosition: "bottom", duration: 1500 });
app.mount("#app");

// Usage

{
  // ....
 methods: {
    clickHandler() {
      this.$wkToast('A toast.');
    },
  },
  // ...
}

{
  // ...
  setup() {
        const toast = Vue.inject("WKToast");
        const clickHandler = () => {
          toast("A toast.");
        };
        return {
          clickHandler,
        };
      },
  // ...
}

Config

toast or $wkToast takes 2 parameter: (message, [options])

Options

ParameterTypeDefaultDescription
classNamestring, arraySelf-defined class names to pass through. There are 3 pre-defined classes: wk-info, wk-warn,wk-alert, to toast with different background color
horizontalPositionstringcenterPosition horizontal of toast. There are 3 pre-defined positions: left, right and center
verticalPositionstringbottomPosition vertical of toast. There are 2 pre-defined positions: top and bottom
durationnumber3000The duration one toast will last, in milliseconds
closeablebooleanfalsetrue or false. If true, the toast can be closed manually
transitionstringslide-downBuilt-in transitions: fade, slide-[up/down/left/right]. See also Transitions

Styling

Besides minimum styling, vue3-toast-single try not to be opinionated about the appearance. It is a simply a div(class="wk-wrapper") wrapped a span(class="wk-content"). Apply your css freely with them or with your own classes passed in as className.

config example

// global
app.use(Toast, { verticalPosition: "bottom", duration: 1500 });

// local
this.$wkToast('A toast', {
  className: ['my-toast', 'toast-warning'],
  horizontalPosition: 'right',
  verticalPosition: 'top',
  duration: 3000,
  transition: 'transition'
})

TODO

  • Add a queue mode
  • emoji

License

MIT