WlToast
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Configure the container in App.vue. Call the service here to see the result.
Example
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { useWlToast, WlButton } from "legato-ui";
const toast = useWlToast();
</script>
<template>
<div class="wl-stack" data-space="md">
<!-- Mount WlToast once in the application root. -->
<div class="wl-inline" data-space="sm">
<WlButton @click="toast.show('Material saved', { tone: 'success' })">
{{ "Success" }}
</WlButton>
<WlButton @click="toast.show('Could not save', { tone: 'danger', detail: 'Try again.' })">
{{ "Error" }}
</WlButton>
</div>
</div>
</template>Add one container in App.vue and configure motion and pt there. Each Vue application has its own service state.
Four notification types
useWlToast().show displays a semantic tone through the application's existing container; old helper methods remain supported.
Notifications shown: 0.
One application container receives all messages. Also show important errors near the affected field or action.
Vue SFC · additional example
<script setup lang="ts">
import { useWlToast, WlButton } from "legato-ui";
import { ref } from "vue";
// Install WlToastService and mount one WlToast in the application root.
const toast = useWlToast();
const shown = ref(0);
function show(tone: "success" | "info" | "warning" | "danger"): void {
const messages = {
success: "Material saved", info: "New version available",
warning: "Check available space", danger: "Could not save"
};
toast.show(messages[tone], {
tone,
detail: tone === "danger" ? "Draft saved. Try again." : "Local example notification."
});
shown.value++;
}
</script>
<template>
<div class="wl-stack" data-space="lg">
<div class="wl-inline" data-space="sm">
<WlButton variant="soft" @click="show('success')">{{ "Show success" }}</WlButton>
<WlButton @click="show('info')">{{ "Show information" }}</WlButton>
<WlButton @click="show('warning')">{{ "Show warning" }}</WlButton>
<WlButton variant="ghost" tone="danger" @click="show('danger')">{{ "Show error" }}</WlButton>
</div>
<p class="wl-text-small" role="status">{{ "Notifications shown:" }} {{ shown }}.</p>
<p class="wl-text-small wl-text-muted">{{ "One application container receives all messages. Also show important errors near the affected field or action." }}</p>
</div>
</template>Connecting the service
Register WlToastService with the Vue application and add one WlToast to App.vue. Each application has its own service state. Import styles as described in the installation section.
main.ts · service and container
import { createApp } from "vue";
import { WlToastService } from "legato-ui";
import App from "./App.vue";
const app = createApp(App);
app.use(WlToastService);
app.mount("#app");
// One container in the root App.vue: WlToast.
// import { WlToast } from "legato-ui";
// <WlToast />