Skip to content

Commit

Permalink
feat: sonner toast
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jan 29, 2025
1 parent 48ab490 commit 07a7cb8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.2"
version: '0.2'
ignorePaths: []
dictionaryDefinitions: []
dictionaries: []
Expand All @@ -18,8 +18,9 @@ words:
- ollama
- risu
- roleplay
- Seraphina
- seraphina
- sonarjs
- sonner
- sqlocal
- virtua
- xsai
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-markdown": "^9.0.3",
"react-router-dom": "^7.1.3",
"remark-gfm": "^4.0.0",
"sonner": "^1.7.3",
"sqlocal": "^0.13.0",
"uuid": "^11.0.5",
"virtua": "^0.39.3"
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Icon } from '@iconify/react'
import { Avatar, Box, Flex, IconButton, ScrollArea, Tooltip } from '@radix-ui/themes'
import { useMatch } from 'react-router-dom'
import { toast } from 'sonner'
import { v7 } from 'uuid'

import { useCharacters, useUpdateCharacters } from '../context/characters'
Expand Down Expand Up @@ -39,6 +40,8 @@ export const Sidebar = () => {
name: json.data.name,
})

toast.success(`${json.data.name} has been created`)

void updateCharacters()
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/components/ui/sonner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Icon } from '@iconify/react'
import { Toaster as SonnerToaster } from 'sonner'

import { useThemeAppearance } from '../../hooks/use-theme'

type ToasterProps = React.ComponentProps<typeof SonnerToaster>

const Toaster = ({ ...props }: ToasterProps) => {
const [theme] = useThemeAppearance()

/** @see {@link https://sonner.emilkowal.ski/styling} */
return (
<SonnerToaster
icons={{
error: <Icon icon="heroicons:exclamation-circle" inline />,
info: <Icon icon="heroicons:information-circle" inline />,
success: <Icon icon="heroicons:check-circle" inline />,
warning: <Icon icon="heroicons:exclamation-circle" inline />,
// loading
}}
theme={theme}
toastOptions={{
classNames: {
actionButton: 'rt-reset rt-BaseButton rt-r-size-2 rt-variant-solid rt-Button',
cancelButton: 'rt-reset rt-BaseButton rt-r-size-2 rt-variant-soft rt-Button',
description: 'rt-Text rt-r-size-2 rt-r-mt-2',
title: 'rt-Text rt-r-size-2 rt-r-lt-start',
toast: 'rt-BaseDialogContent rt-AlertDialogContent rt-Flex rt-r-ai-center rt-r-gap-2 rt-r-size-2 rt-r-max-w',
},
style: { overflow: 'hidden' },
unstyled: true,
}}
{...props}
/>
)
}

export { Toaster }
2 changes: 2 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Outlet } from 'react-router-dom'

import { Sidebar } from '../components/sidebar'
import { Theme } from '../components/theme'
import { Toaster } from '../components/ui/sonner'
import { Context } from '../context'

const App = () => (
<Context>
<Theme>
<Toaster />
<Flex gap="2">
<Sidebar />
<Box height="100vh" width="100%">
Expand Down

0 comments on commit 07a7cb8

Please sign in to comment.