emmanuelsw / notiwind

A headless Vue 3 notification library to use with Tailwind CSS.
https://notiwind-demo.netlify.app
MIT License
277 stars 28 forks source link

Problem with Inertia.js (Jetstream) #15

Closed killemalljustice closed 2 years ago

killemalljustice commented 2 years ago

Hi, i am trying to use this component in a Inertia.js (Jetstream) app, i import the component in app.js:

require('./bootstrap');

import { createApp, h } from 'vue';
import { createInertiaApp, Link } from '@inertiajs/inertia-vue3';
import Notifications from 'notiwind'
import { InertiaProgress } from '@inertiajs/progress';  

InertiaProgress.init({
    delay: 50,
  })

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => require(`./Pages/${name}.vue`),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .component('Link', Link)
            .component('Notifications', Notifications)
            .mixin({ methods: { route } })
            .mount(el);
    },
});

InertiaProgress.init({ color: '#4B5563' });

and in my AppLayout.vue file i added the basic example to the template:

<template>
......
.....
<NotificationGroup group="foo">
    <div
      class="fixed inset-0 flex items-start justify-end p-6 px-4 py-6 pointer-events-none"
    >
      <div class="w-full max-w-sm">
        <Notification
          v-slot="{ notifications }"
          enter="transform ease-out duration-300 transition"
          enter-from="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-4"
          enter-to="translate-y-0 opacity-100 sm:translate-x-0"
          leave="transition ease-in duration-500"
          leave-from="opacity-100"
          leave-to="opacity-0"
          move="transition duration-500"
          move-delay="delay-300"
        >
          <div
            class="flex w-full max-w-sm mx-auto mt-4 overflow-hidden bg-white rounded-lg shadow-md"
            v-for="notification in notifications"
            :key="notification.id"
          >
            <div class="flex items-center justify-center w-12 bg-green-500">
              <svg class="w-6 h-6 text-white fill-current" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
                <path d="M20 3.33331C10.8 3.33331 3.33337 10.8 3.33337 20C3.33337 29.2 10.8 36.6666 20 36.6666C29.2 36.6666 36.6667 29.2 36.6667 20C36.6667 10.8 29.2 3.33331 20 3.33331ZM16.6667 28.3333L8.33337 20L10.6834 17.65L16.6667 23.6166L29.3167 10.9666L31.6667 13.3333L16.6667 28.3333Z" />
              </svg>
            </div>

            <div class="px-4 py-2 -mx-3">
              <div class="mx-3">
                <span class="font-semibold text-green-500">{{ notification.title }}</span>
                <p class="text-sm text-gray-600">{{ notification.text }}</p>
              </div>
            </div>
          </div>
        </Notification>
      </div>
    </div>
  </NotificationGroup>
</template>

Then when loading the page i got this errors: image

Any ideas of what could be wrong??

Thanks for the help.

emmanuelsw commented 2 years ago

Hi, I think the problem is that you are registering the library as a component, here:

.component('Notifications', Notifications)

You have to install it as a plugin:

.use(Notifications)

Here is an example in the README.

killemalljustice commented 2 years ago

Hi, I think the problem is that you are registering the library as a component, here:

.component('Notifications', Notifications)

You have to install it as a plugin:

.use(Notifications)

Here is an example in the README.

Thank you, that was the problem.