What's new in Ding 0.0.4

A Vue package, Next.js and CSP support, and calmer toasts. No breaking changes.

Most of this release came from people using Ding. The two fixes have live demos below, so you can try them yourself.

npm i @yusufceng1z/ding@latest

Vue 3 and Nuxt New

There is a new package, @yusufceng1z/ding-vue. It has the same props as the React and Svelte ones: position, theme, labels and nonce.

npm i @yusufceng1z/ding-vue
<script setup>
import { Toaster, toast } from '@yusufceng1z/ding-vue';
</script>

<template>
  <Toaster position="top-center" theme="system" />
  <button @click="toast.success('Saved')">Save</button>
</template>

Toaster draws nothing where you put it and starts after the page has loaded, so server rendering is safe. In Nuxt, put it in app.vue and call toast from client code, like a click handler. We ran it in Vue with Vite and in Nuxt 4, in development and in a production build.

Asked for by reslear in issue 7.

Next.js without a wrapper

The React build now starts with "use client". Until now, importing Toaster in a server layout failed, so you needed your own client component around it. You don't any more.

// app/layout.tsx, a server component
import { Toaster } from '@yusufceng1z/ding-react';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Toaster />
        {children}
      </body>
    </html>
  );
}

Call toast from client components only. See the Next.js guide.

Suggested and built by Amidou Cissé, see pull request 10.

Works with a strict CSP

Ding puts its styles in one <style> element. If your style-src blocks inline styles, give it your page's nonce. Only that element needs it, because the per-toast values are set through the DOM, which CSP allows.

<Toaster nonce={nonce} />     {/* React, Svelte */}
<Toaster :nonce="nonce" />    <!-- Vue -->

mountToaster({ nonce });        // plain DOM

Suggested and built by Amidou Cissé, see pull request 11.

Progress toasts don't flicker Fixed

When a toast changed its own text while it ran, like a download with a moving percentage, the text animation played again on every update and the title looked like it was shaking. Now the animation only plays when the title really becomes something new, such as "Download complete".

Watch the title while the numbers change. It should stay still until the end.

Reported by MathiasWP in issue 5. A screen recording from IsaacHatilima helped find it.

The close button stays last Fixed

In the plain DOM renderer, which Vue and Nuxt use, an error toast has a close button. If it then turned into a toast with an action, like Undo, the close button ended up in front of the action. It now stays at the end. React and Svelte were not affected.

Open the error, then press Undo. The buttons should read Undo, then close.

Buttons: -

For contributors

The React, Svelte, Vue and plain DOM renderers now each have render tests, and CI runs them on every pull request. Thanks to Amidou Cissé for pull request 13 and the three before it.

What's new in 0.0.3