Skip to content

Commit eba85c6

Browse files
feat(sonner): add sonner component (#301)
1 parent f9ab01e commit eba85c6

File tree

16 files changed

+224
-0
lines changed

16 files changed

+224
-0
lines changed

apps/www/.vitepress/theme/config/docs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ export const docsConfig: DocsConfig = {
299299
href: '/docs/components/slider',
300300
items: [],
301301
},
302+
{
303+
title: 'Sonner',
304+
href: '/docs/components/sonner',
305+
label: 'New',
306+
items: [],
307+
},
302308
{
303309
title: 'Switch',
304310
href: '/docs/components/switch',

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import EditLink from '../components/EditLink.vue'
66
import { ScrollArea } from '@/lib/registry/default/ui/scroll-area'
77
import { Badge } from '@/lib/registry/default/ui/badge'
88
import RadixIconsCode from '~icons/radix-icons/code'
9+
import RadixIconsExternalLink from '~icons/radix-icons/external-link'
910
import ChevronRightIcon from '~icons/lucide/chevron-right'
1011
1112
const $route = useRoute()
@@ -81,6 +82,10 @@ const sourceLink = 'https://github.com/radix-vue/shadcn-vue/tree/dev/'
8182
</div>
8283

8384
<div class="flex items-center space-x-2 pt-4">
85+
<a v-if="frontmatter.docs" :href="frontmatter.docs" target="_blank" class="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 select-none border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80">
86+
<RadixIconsExternalLink class="mr-1" />
87+
Docs
88+
</a>
8489
<a v-if="frontmatter.source" :href="sourceLink + frontmatter.source" target="_blank" class="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 select-none border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80">
8590
<RadixIconsCode class="mr-1" />
8691
Component Source

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import RadixIconsSun from '~icons/radix-icons/sun'
1717
import { useConfigStore } from '@/stores/config'
1818
import { Dialog, DialogContent } from '@/lib/registry/default/ui/dialog'
1919
import { Toaster as DefaultToaster } from '@/lib/registry/default/ui/toast'
20+
import { Toaster as NewYorkSonner } from '@/lib/registry/new-york/ui/sonner'
2021
import { Toaster as NewYorkToaster } from '@/lib/registry/new-york/ui/toast'
2122
2223
import File from '~icons/radix-icons/file'
@@ -287,6 +288,7 @@ watch(() => $route.path, (n) => {
287288
</DialogContent>
288289
</Dialog>
289290
<DefaultToaster />
291+
<NewYorkSonner :theme="isDark ? 'dark' : 'light'" />
290292
<NewYorkToaster />
291293
</div>
292294
</template>

apps/www/__registry__/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,13 @@ export const Index = {
576576
component: () => import('../src/lib/registry/default/example/SliderDemo.vue').then(m => m.default),
577577
files: ['../src/lib/registry/default/example/SliderDemo.vue'],
578578
},
579+
SonnerDemo: {
580+
name: 'SonnerDemo',
581+
type: 'components:example',
582+
registryDependencies: ['button'],
583+
component: () => import('../src/lib/registry/default/example/SonnerDemo.vue').then(m => m.default),
584+
files: ['../src/lib/registry/default/example/SonnerDemo.vue'],
585+
},
579586
SwitchDemo: {
580587
name: 'SwitchDemo',
581588
type: 'components:example',
@@ -1467,6 +1474,13 @@ export const Index = {
14671474
component: () => import('../src/lib/registry/new-york/example/SliderDemo.vue').then(m => m.default),
14681475
files: ['../src/lib/registry/new-york/example/SliderDemo.vue'],
14691476
},
1477+
SonnerDemo: {
1478+
name: 'SonnerDemo',
1479+
type: 'components:example',
1480+
registryDependencies: ['button'],
1481+
component: () => import('../src/lib/registry/new-york/example/SonnerDemo.vue').then(m => m.default),
1482+
files: ['../src/lib/registry/new-york/example/SonnerDemo.vue'],
1483+
},
14701484
SwitchDemo: {
14711485
name: 'SwitchDemo',
14721486
type: 'components:example',

apps/www/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"v-calendar": "^3.1.2",
3838
"vee-validate": "4.12.4",
3939
"vue": "^3.4.15",
40+
"vue-sonner": "^1.0.2",
4041
"vue-wrap-balancer": "^1.1.3",
4142
"zod": "^3.22.4"
4243
},
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Sonner
3+
description: An opinionated toast component for Vue.
4+
docs: https://vue-sonner.vercel.app
5+
source: apps/www/src/lib/registry/default/ui/sonner
6+
---
7+
8+
<ComponentPreview name="SonnerDemo" />
9+
10+
## About
11+
12+
The Sonner component is provided by [vue-sonner](https://vue-sonner.vercel.app/), which is a Vue port of Sonner, originally created by [Emil Kowalski](https://twitter.com/emilkowalski_) for React.
13+
14+
## Installation
15+
16+
<Steps>
17+
18+
### Run the following command
19+
20+
```bash
21+
npx shadcn-vue@latest add sonner
22+
```
23+
24+
### Add the Toaster component
25+
26+
Add the following `Toaster` component to your `App.vue` file:
27+
28+
```vue title="App.vue" {2,6}
29+
<script setup lang="ts">
30+
import { Toaster } from '@/components/ui/sonner'
31+
</script>
32+
33+
<template>
34+
<Toaster />
35+
</template>
36+
```
37+
38+
</Steps>
39+
40+
## Usage
41+
42+
```vue
43+
<script setup lang="ts">
44+
import { toast } from 'vue-sonner'
45+
import { Button } from '@/components/ui/button'
46+
</script>
47+
48+
<template>
49+
<Button
50+
variant="outline" @click="() => {
51+
toast('Event has been created', {
52+
description: 'Sunday, December 03, 2023 at 9:00 AM',
53+
action: {
54+
label: 'Undo',
55+
onClick: () => console.log('Undo'),
56+
},
57+
})
58+
}"
59+
>
60+
Add to calander
61+
</Button>
62+
</template>
63+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import { toast } from 'vue-sonner'
3+
import { Button } from '@/lib/registry/default/ui/button'
4+
</script>
5+
6+
<template>
7+
<Button
8+
variant="outline" @click="() => {
9+
toast('Event has been created', {
10+
description: 'Sunday, December 03, 2023 at 9:00 AM',
11+
action: {
12+
label: 'Undo',
13+
onClick: () => console.log('Undo'),
14+
},
15+
})
16+
}"
17+
>
18+
Add to calander
19+
</Button>
20+
</template>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts" setup>
2+
import { Toaster as Sonner, type ToasterProps } from 'vue-sonner'
3+
4+
const props = defineProps<ToasterProps>()
5+
</script>
6+
7+
<template>
8+
<Sonner
9+
class="toaster group"
10+
:class-names="{
11+
toast:
12+
'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',
13+
description: 'group-[.toast]:text-muted-foreground',
14+
actionButton:
15+
'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
16+
cancelButton:
17+
'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
18+
}"
19+
v-bind="props"
20+
/>
21+
</template>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Toaster } from './Sonner.vue'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import { toast } from 'vue-sonner'
3+
import { Button } from '@/lib/registry/new-york/ui/button'
4+
</script>
5+
6+
<template>
7+
<Button
8+
variant="outline" @click="() => {
9+
toast('Event has been created', {
10+
description: 'Sunday, December 03, 2023 at 9:00 AM',
11+
action: {
12+
label: 'Undo',
13+
onClick: () => console.log('Undo'),
14+
},
15+
})
16+
}"
17+
>
18+
Add to calander
19+
</Button>
20+
</template>

0 commit comments

Comments
 (0)