Skip to content

Commit e2f6e6c

Browse files
authored
feat!: update to vue-sonner v2 (#1257)
* chore: update `vue-sonner` to v2 * chore(v4): update nuxt.config.ts to add vue-sonner css file * chore(www): update `vue-sonner` in www, add some docs
1 parent 0944b17 commit e2f6e6c

File tree

7 files changed

+28
-21
lines changed

7 files changed

+28
-21
lines changed

apps/v4/app.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Toaster } from '@/registry/new-york-v4/ui/sonner'
33
44
const activeTheme = useCookie<string>('active_theme', { readonly: true })
55
const isScaled = computed(() => !!activeTheme.value?.endsWith('-scaled'))
6+
const colorMode = useColorMode()
67
</script>
78

89
<template>
@@ -17,6 +18,6 @@ const isScaled = computed(() => !!activeTheme.value?.endsWith('-scaled'))
1718
<NuxtPage />
1819
</NuxtLayout>
1920

20-
<Toaster />
21+
<Toaster :theme="colorMode.preference as any || 'system'" />
2122
</Body>
2223
</template>

apps/v4/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import tailwindcss from '@tailwindcss/vite'
44
export default defineNuxtConfig({
55
compatibilityDate: '2024-11-01',
66
devtools: { enabled: true },
7-
css: ['~/assets/css/main.css'],
7+
css: ['~/assets/css/main.css', 'vue-sonner/style.css'],
88
modules: ['@nuxtjs/color-mode', '@nuxt/fonts'],
99
vite: {
1010
plugins: [

apps/v4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"vee-validate": "^4.15.0",
3131
"vue": "^3.5.14",
3232
"vue-router": "^4.5.1",
33-
"vue-sonner": "^1.3.2",
33+
"vue-sonner": "^2.0.0",
3434
"zod": "^3.24.4"
3535
},
3636
"devDependencies": {

apps/www/.vitepress/theme/layout/MainLayout.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import MoonIcon from '~icons/lucide/moon'
66
import SunIcon from '~icons/lucide/sun'
77
import Circle from '~icons/radix-icons/circle'
88
import File from '~icons/radix-icons/file'
9-
109
import GithubLogoIcon from '~icons/radix-icons/github-logo'
10+
1111
import { cn } from '@/lib/utils'
1212
import { Button } from '@/registry/default/ui/button'
13-
1413
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@/registry/default/ui/command'
14+
1515
import { Dialog, DialogContent } from '@/registry/default/ui/dialog'
1616
import { Toaster as DefaultToaster } from '@/registry/default/ui/toast'
1717
import { Toaster as NewYorkSonner } from '@/registry/new-york/ui/sonner'
@@ -21,10 +21,11 @@ import { useConfigStore } from '@/stores/config'
2121
import CodeConfigCustomizer from '../components/CodeConfigCustomizer.vue'
2222
import Kbd from '../components/Kbd.vue'
2323
import Logo from '../components/Logo.vue'
24-
2524
import MobileNav from '../components/MobileNav.vue'
25+
2626
import ThemePopover from '../components/ThemePopover.vue'
2727
import { docsConfig } from '../config/docs'
28+
import 'vue-sonner/style.css'
2829
2930
const { radius, theme } = useConfigStore()
3031
// Whenever the component is mounted, update the document class list

apps/www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"vaul-vue": "^0.4.1",
4040
"vee-validate": "4.13.2",
4141
"vue": "^3.5.14",
42-
"vue-sonner": "^1.3.2",
42+
"vue-sonner": "^2.0.0",
4343
"vue-wrap-balancer": "^1.2.1",
4444
"zod": "catalog:"
4545
},

apps/www/src/content/docs/components/sonner.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ npx shadcn-vue@latest add sonner
2525

2626
Add the following `Toaster` component to your `App.vue` file:
2727

28-
```vue title="App.vue" {2,6}
28+
```vue title="App.vue" {2-3,7}
2929
<script setup lang="ts">
3030
import { Toaster } from '@/components/ui/sonner'
31+
import 'vue-sonner/style.css' // vue-sonner v2 requires this import
3132
</script>
3233
3334
<template>
3435
<Toaster />
3536
36-
<!-- Nuxt -->
37+
<!-- Nuxt, vue-sonner v1 because inserting inline CSS with JS to the head tag -->
3738
<ClientOnly>
3839
<Toaster />
3940
</ClientOnly>
41+
42+
<!-- Nuxt, vue-sonner v2 no need to ClientOnly -->
43+
<Toaster />
4044
</template>
4145
```
4246

@@ -75,9 +79,10 @@ Related issue https://github.com/unovue/shadcn-vue/issues/462
7579

7680
Add `pointer-events-auto` class to Toaster component in your `App.vue` file:
7781

78-
```vue {6}
82+
```vue {7}
7983
<script setup lang="ts">
8084
import { Toaster } from '@/components/ui/sonner'
85+
import 'vue-sonner/style.css' // vue-sonner v2 requires this import
8186
</script>
8287
8388
<template>

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)