Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globally provide custom component #66

Open
mrleblanc101 opened this issue Dec 17, 2024 · 5 comments
Open

Globally provide custom component #66

mrleblanc101 opened this issue Dec 17, 2024 · 5 comments

Comments

@mrleblanc101
Copy link
Contributor

mrleblanc101 commented Dec 17, 2024

In Render more than string, I see I can provide a custom component, the annoying part is that I need to pass the component every time I call toast(), is there a way to define it globally ?

I want to style my Toast using tailwindcss classes, so I need to provide a custom component to do this.
This would be especially usefull in a Nuxt context:

import Vue3Toastify, { toast, type ToastContainerOptions } from 'vue3-toastify';
import 'vue3-toastify/dist/index.css';

export default defineNuxtPlugin((nuxtApp) => {
    nuxtApp.vueApp.use(Vue3Toastify, {
        component: MyCustomComponent, // <-- Something like this
        autoClose: 8000,
        dangerouslyHTMLString: true,
        theme: 'auto',
        transition: toast.TRANSITIONS.BOUNCE,
        position: toast.POSITION.TOP_RIGHT,
    } as ToastContainerOptions);

    return {
        provide: { toast },
    };
});
@mrleblanc101
Copy link
Contributor Author

I guess I could provide a custom toast() function, but not sure if it's the right approach:

    return {
        provide: { toast: (...args) => toast(MyCustomComponent, { ...args }) },
    };

@jerrywu001
Copy link
Owner

you can use custom component instead, like:

image

  • Custom.vue
<template>
  <div>
    <el-button type="primary" class="bg-[#f60] text-white">
      Primary {{ name }}
    </el-button>
  </div>
</template>

<script setup lang="ts">
defineProps({
  name: {
    type: String,
    default: 'test',
  },
});
</script>
  • invoke
toast.loading(Custom, {
    contentProps: { name: 'sended' },
    expandCustomProps: true,
  });

@mrleblanc101
Copy link
Contributor Author

mrleblanc101 commented Dec 18, 2024

@jerrywu001 i don't think you understood me properly. I want to set to component globally in the plugin option instead of passing it to the toast function for every involution.

@mrleblanc101
Copy link
Contributor Author

mrleblanc101 commented Dec 18, 2024

I guess I'll just do a custom composable that wrap the toast function as state here #66 (comment)

@jerrywu001 jerrywu001 reopened this Dec 18, 2024
@jerrywu001
Copy link
Owner

got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants