swisnl / nuxt-lucide-icons

This Nuxt module makes working with Lucide icons a breeze!
MIT License
24 stars 3 forks source link

Auto import doesn't work in Pinia store #11

Open jimmiejackson414 opened 2 days ago

jimmiejackson414 commented 2 days ago

I'm trying to create an app-wide notification pinia store, but the auto-import doesn't appear to work in a .ts/.js file. I can verify that it does work correctly in a regular .vue file.

Here's an example of what I'm trying to do:

import { defineStore } from 'pinia';
import { useToast } from '@/components/ui/toast';

type State = {
  loading: boolean;
};

type Getters = {
  //
};

type Actions = {
  notifyPositive: (description: string, title?: string) => void;
  notifyNegative: (description: string, title?: string) => void;
  notifyInfo: (description: string, title?: string) => void;
};

export const useAppStore = defineStore<'app', State, Getters, Actions>('app', {
  state () {
    return {
      loading: false,
    };
  },

  getters: {},

  actions: {
    notifyPositive (description, title) {
      const { toast } = useToast();
      toast({
        title,
        description,
        variant: 'positive',
        icon: IconCircleCheck, <-- error on this reference
      });
    },
    notifyNegative (description, title) {
      const { toast } = useToast();
      toast({
        title,
        description,
        variant: 'destructive',
        icon: IconCircleAlert, <-- error on this reference
      });
    },
    notifyInfo (description, title) {
      const { toast } = useToast();
      toast({
        title,
        description,
        variant: 'info',
        icon: IconInfo, <-- error on this reference
      });
    },
  },
});

Apologies if it's outside of the scope of this library, but i've never really come across this issue before. Do I actually need to manually import it in cases like this from somewhere?

JaZo commented 3 hours ago

Hi Jimmie, auto-import only works in templates as far as I know. You should import it explicitly: https://nuxt.com/docs/guide/directory-structure/components#direct-imports