Skip to content
                  Sponsored by

                  MagicToast

                  MagicToast let’s you trigger and display toasts from anywhere.

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-demo" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add } = useMagicToast('magic-toast-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    const props = {
                      message: count.value % 2 ? 'Magic as a Service™' : 'Vue Equipment',
                    }
                  
                    add({ component, props })
                  }
                  </script>

                  Overview

                  Anatomy

                  vue
                  <template>
                    <magic-toast-provider id="your-toast-id" />
                  </template>
                  
                  <script>
                  import { defineAsyncComponent } from 'vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const component = defineAsyncComponent(() => import('./YourToast.vue'))
                  const { add } = useMagicToast('your-toast-id')
                  
                  function handleClick() {
                    add({ component })
                  }
                  </script>

                  Installation

                  CLI

                  Add @maas/vue-equipment to your dependencies.

                  sh
                  pnpm install @maas/vue-equipment
                  sh
                  npm install @maas/vue-equipment
                  sh
                  yarn add @maas/vue-equipment
                  sh
                  bun install @maas/vue-equipment

                  Vue

                  If you are using Vue, import and add MagicToastPlugin to your app.

                  js
                  import { createApp } from 'vue'
                  import { MagicToastPlugin } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const app = createApp({})
                  
                  app.use(MagicToastPlugin)

                  Nuxt

                  The toaster is available as a Nuxt module. In your Nuxt config file add @maas/vue-equipment/nuxt to your modules and add MagicToast to the plugins in your configuration.

                  js
                  export default defineNuxtConfig({
                    modules: ['@maas/vue-equipment/nuxt'],
                    vueEquipment: {
                      plugins: ['MagicToast'],
                    },
                  })

                  Composable

                  In order to interact with the toaster from anywhere within your app, we provide a useMagicToaster composable. Import it directly when needed.

                  js
                  const component = defineAsyncComponent(() => import('./YourToast.vue'))
                  const { add } = useMagicToast('your-toast-id')
                  
                  function handleClick() {
                    add({ component })
                  }

                  TIP

                  If you have installed the toaster as a Nuxt module, the composable will be auto-imported and is automatically available in your Nuxt app.

                  Peer Dependencies

                  If you haven’t installed the required peer dependencies automatically, you’ll need to install the following packages manually.

                  Installation

                  sh
                  pnpm install @nuxt/kit @vueuse/core defu
                  sh
                  npm install @nuxt/kit @vueuse/core defu
                  sh
                  yarn add @nuxt/kit @vueuse/core defu
                  sh
                  bun install @nuxt/kit @vueuse/core defu

                  API Reference

                  MagicToastProvider

                  The MagicToastProvider wraps the toaster and configures it according to the provided options.

                  Props

                  PropTypeRequired
                  id
                  MaybeRef<string>true
                  options
                  MagicMenuOptionsfalse

                  Options

                  OptionTypeDefault
                  debug
                  booleanfalse
                  position
                  Positionbottom
                  duration
                  number0
                  scrollLock
                  boolean | objectobject
                  scrollLock.padding
                  booleantrue
                  teleport.target
                  stringbody
                  teleport.disabled
                  booleanfalse
                  transition
                  stringmagic-toast
                  layout.expand
                  string | false
                  click
                  layout.max
                  number3
                  animation.snap.duration
                  number300
                  animation.snap.easing
                  function
                  initial.expanded
                  booleanfalse
                  threshold.lock
                  number8
                  threshold.distancenumber32
                  threshold.momentum
                  number1

                  CSS Variables

                  VariableDefault
                  --magic-toast-padding-y1rem
                  --magic-toast-padding-x1rem
                  --magic-toast-gap0.75rem
                  --magic-toast-animation-duration175ms
                  --magic-toast-scale-factor0.05
                  --magic-toast-overlap-y1rem
                  --magic-toast-positionfixed
                  --magic-toast-inset0
                  --magic-toast-width100%
                  --magic-toast-height100%
                  --magic-toast-z-index999

                  MagicToastView

                  MagicToastView is used internally. Some CSS is configurable.

                  VariableDefault
                  --magic-toast-view-transitionall var(--magic-toast-animation-duration) var(--ease-in-out)
                  --magic-toast-view-cursorgrab
                  --magic-toast-view-cursor-dragginggrabbing

                  Errors

                  SourceError CodeMessage
                  MagicToastViewmissing_instance_idMagicToastView must be used within a MagicToastProvider

                  Examples

                  Position

                  <template>
                    <div class="w-full flex gap-2">
                      <m-button @click="onClick">Add Toast</m-button>
                      <m-select
                        v-model="position"
                        :options="options"
                        label="Position"
                        placeholder="Position"
                      />
                    </div>
                    <magic-toast-provider
                      id="magic-toast-position-demo"
                      :options="{
                        position,
                      }"
                    />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton, MSelect } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add } = useMagicToast('magic-toast-position-demo')
                  
                  const position = ref('bottom-right')
                  
                  const options = [
                    { value: 'top-right', label: 'Top Right' },
                    { value: 'top', label: 'Top' },
                    { value: 'top-left', label: 'Top Left' },
                    { value: 'left', label: 'Left' },
                    { value: 'bottom-left', label: 'Bottom Left' },
                    { value: 'bottom', label: 'Bottom' },
                    { value: 'bottom-right', label: 'Bottom Right' },
                    { value: 'right', label: 'Right' },
                  ]
                  
                  function onClick() {
                    const props = {
                      message: options.find((p) => p.value === position.value)?.label,
                    }
                  
                    add({ component, props })
                  }
                  </script>

                  Expanded

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-expanded-demo" :options="options" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add } = useMagicToast('magic-toast-expanded-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    const props = {
                      message: count.value % 2 ? 'Magic as a Service™' : 'Vue Equipment',
                    }
                  
                    add({ component, props })
                  }
                  
                  const options = {
                    layout: {
                      expand: false,
                    },
                    initial: {
                      expanded: true,
                    },
                  }
                  </script>

                  Collapsed

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-collapsed-demo" :options="options" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add } = useMagicToast('magic-toast-collapsed-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    const props = {
                      message: count.value % 2 ? 'Magic as a Service™' : 'Vue Equipment',
                    }
                  
                    add({ component, props })
                  }
                  
                  const options = {
                    layout: {
                      expand: false,
                    },
                  }
                  </script>

                  Hover

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-hover-demo" :options="options" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add } = useMagicToast('magic-toast-hover-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    const props = {
                      message: count.value % 2 ? 'Magic as a Service™' : 'Vue Equipment',
                    }
                  
                    add({ component, props })
                  }
                  
                  const options = {
                    layout: {
                      expand: 'hover',
                    },
                  }
                  </script>

                  Clear All

                  <template>
                    <div class="flex gap-2">
                      <m-button @click="onClick">Add Toast</m-button>
                      <m-button @click="clear">Clear All</m-button>
                    </div>
                    <magic-toast-provider id="magic-toast-clear-all-demo" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  const { add, clear } = useMagicToast('magic-toast-clear-all-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    const props = {
                      message: count.value % 2 ? 'Magic as a Service™' : 'Vue Equipment',
                    }
                  
                    add({ component, props })
                  }
                  </script>

                  Slot

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-slot-demo" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref, h, type Slots } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  
                  const { add } = useMagicToast('magic-toast-slot-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    // Break reactivity for count
                    const mappedCount = count.value
                  
                    const slots: Slots = {
                      default: () => [h('span', `Message #${mappedCount}`)],
                    }
                  
                    add({ component, slots })
                  }
                  </script>

                  Slotted Component

                  <template>
                    <m-button @click="onClick">Add Toast</m-button>
                    <magic-toast-provider id="magic-toast-nested-slot-demo" />
                  </template>
                  
                  <script lang="ts" setup>
                  import { defineAsyncComponent, ref, h, type Slots } from 'vue'
                  import { MButton } from '@maas/mirror/vue'
                  import { useMagicToast } from '@maas/vue-equipment/plugins/MagicToast'
                  
                  const count = ref(0)
                  
                  const component = defineAsyncComponent(
                    () => import('./components/DemoToast.vue')
                  )
                  
                  const slot = defineAsyncComponent(() => import('./components/DemoSlot.vue'))
                  
                  const { add } = useMagicToast('magic-toast-nested-slot-demo')
                  
                  function onClick() {
                    count.value += 1
                  
                    // Break reactivity for count
                    const mappedCount = count.value
                  
                    const slots: Slots = {
                      default: () => [h(slot, { message: `Component #${mappedCount}` })],
                    }
                  
                    add({ component, slots })
                  }
                  </script>