Skip to content

Commit cb3355b

Browse files
AlessioGrpaulpopus
andauthored
feat!: move from react-toastify to sonner (#6682)
**BREAKING:** We now export toast from `sonner` instead of `react-toastify`. If you send out toasts from your own projects, make sure to use our `toast` export, or install `sonner`. React-toastify toasts will no longer work anymore. The Toast APIs are mostly similar, but there are some differences if you provide options to your toast CSS styles have been changed from Toastify ```css /* before */ .Toastify /* current */ .payload-toast-container .payload-toast-item .payload-toast-close-button /* individual toast items will also have these classes depending on the state */ .toast-info .toast-warning .toast-success .toast-error ``` https://github.com/payloadcms/payload/assets/70709113/da3e732e-aafc-4008-9469-b10f4eb06b35 --------- Co-authored-by: Paul Popus <paul@nouance.io>
1 parent 10c6ffa commit cb3355b

File tree

87 files changed

+747
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+747
-353
lines changed

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"path-to-regexp": "^6.2.1",
5555
"qs": "6.11.2",
5656
"react-diff-viewer-continued": "3.2.6",
57-
"react-toastify": "10.0.5",
5857
"sass": "1.77.4",
58+
"sonner": "^1.5.0",
5959
"ws": "^8.16.0"
6060
},
6161
"devDependencies": {

packages/next/src/layouts/Root/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { headers as getHeaders, cookies as nextCookies } from 'next/headers.js'
1111
import { parseCookies } from 'payload/auth'
1212
import { createClientConfig } from 'payload/config'
1313
import React from 'react'
14-
import 'react-toastify/dist/ReactToastify.css'
1514

1615
import { getPayloadHMR } from '../../utilities/getPayloadHMR.js'
1716
import { getRequestLanguage } from '../../utilities/getRequestLanguage.js'

packages/next/src/scss/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@import './styles.scss';
2-
@import './toastify.scss';
2+
@import './toasts.scss';
33
@import './colors.scss';
44

55
:root {

packages/next/src/scss/toastify.scss

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/next/src/scss/toasts.scss

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
.payload-toast-container {
2+
.payload-toast-close-button {
3+
left: unset;
4+
right: 0.5rem;
5+
top: 1.5rem;
6+
color: var(--theme-elevation-400);
7+
background: unset;
8+
border: none;
9+
display: flex;
10+
width: 1.25rem;
11+
height: 1.25rem;
12+
justify-content: center;
13+
align-items: center;
14+
15+
&:hover {
16+
background: none;
17+
}
18+
19+
svg {
20+
width: 2rem;
21+
height: 2rem;
22+
}
23+
24+
[dir='RTL'] & {
25+
right: unset;
26+
left: 0.5rem;
27+
}
28+
}
29+
30+
.payload-toast-item {
31+
padding: 1rem;
32+
color: var(--theme-text);
33+
font-style: normal;
34+
font-weight: 600;
35+
display: flex;
36+
gap: 1rem;
37+
align-items: center;
38+
width: 100%;
39+
border-radius: 0.15rem;
40+
border: 1px solid var(--theme-border-color);
41+
background: var(--theme-input-bg);
42+
box-shadow:
43+
0px 10px 4px -8px rgba(0, 2, 4, 0.02),
44+
0px 2px 3px 0px rgba(0, 2, 4, 0.05);
45+
46+
.toast-content {
47+
transition: opacity 100ms cubic-bezier(0.55, 0.055, 0.675, 0.19);
48+
}
49+
50+
&[data-front='false'] {
51+
.toast-content {
52+
opacity: 0;
53+
}
54+
}
55+
56+
&[data-expanded='true'] {
57+
.toast-content {
58+
opacity: 1;
59+
}
60+
}
61+
62+
.toast-icon {
63+
svg {
64+
width: 2.4rem;
65+
height: 2.4rem;
66+
}
67+
}
68+
69+
&.toast-warning {
70+
border-color: var(--theme-warning-200);
71+
background-color: var(--theme-warning-100);
72+
}
73+
74+
&.toast-error {
75+
border-color: var(--theme-error-300);
76+
background-color: var(--theme-error-150);
77+
}
78+
79+
&.toast-success {
80+
border-color: var(--theme-success-200);
81+
background-color: var(--theme-success-100);
82+
}
83+
84+
&.toast-info {
85+
border-color: var(--theme-elevation-250);
86+
background-color: var(--theme-elevation-100);
87+
}
88+
89+
[data-theme='light'] & {
90+
&.toast-warning {
91+
border-color: var(--theme-warning-550);
92+
background-color: var(--theme-warning-100);
93+
}
94+
95+
&.toast-error {
96+
border-color: var(--theme-error-200);
97+
background-color: var(--theme-error-50);
98+
}
99+
100+
&.toast-success {
101+
border-color: var(--theme-success-550);
102+
background-color: var(--theme-success-50);
103+
}
104+
105+
&.toast-info {
106+
border-color: var(--theme-border-color);
107+
background-color: var(--theme-elevation-50);
108+
}
109+
}
110+
}
111+
}

packages/next/src/views/API/index.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useTranslation } from '@payloadcms/ui/providers/Translation'
1515
import { useSearchParams } from 'next/navigation.js'
1616
import qs from 'qs'
1717
import * as React from 'react'
18-
import { toast } from 'react-toastify'
18+
import { toast } from 'sonner'
1919

2020
import { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js'
2121
import { LocaleSelector } from './LocaleSelector/index.js'

packages/next/src/views/Edit/Default/Auth/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useConfig } from '@payloadcms/ui/providers/Config'
1010
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'
1111
import { useTranslation } from '@payloadcms/ui/providers/Translation'
1212
import React, { useCallback, useEffect, useState } from 'react'
13-
import { toast } from 'react-toastify'
13+
import { toast } from 'sonner'
1414

1515
import type { Props } from './types.js'
1616

@@ -71,7 +71,7 @@ export const Auth: React.FC<Props> = (props) => {
7171
})
7272

7373
if (response.status === 200) {
74-
toast.success(t('authentication:successfullyUnlocked'), { autoClose: 3000 })
74+
toast.success(t('authentication:successfullyUnlocked'))
7575
} else {
7676
toast.error(t('authentication:failedToUnlock'))
7777
}

packages/next/src/views/ForgotPassword/ForgotPasswordForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useConfig } from '@payloadcms/ui/providers/Config'
99
import { useTranslation } from '@payloadcms/ui/providers/Translation'
1010
import { email } from 'payload/fields/validations'
1111
import React, { Fragment, useState } from 'react'
12-
import { toast } from 'react-toastify'
12+
import { toast } from 'sonner'
1313

1414
export const ForgotPasswordForm: React.FC = () => {
1515
const config = useConfig()

packages/next/src/views/ResetPassword/index.client.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useConfig } from '@payloadcms/ui/providers/Config'
1111
import { useTranslation } from '@payloadcms/ui/providers/Translation'
1212
import { useRouter } from 'next/navigation.js'
1313
import React from 'react'
14-
import { toast } from 'react-toastify'
14+
import { toast } from 'sonner'
1515

1616
type Args = {
1717
token: string
@@ -49,7 +49,7 @@ export const ResetPasswordClient: React.FC<Args> = ({ token }) => {
4949
history.push(`${admin}`)
5050
} else {
5151
history.push(`${admin}/login`)
52-
toast.success(i18n.t('general:updatedSuccessfully'), { autoClose: 3000 })
52+
toast.success(i18n.t('general:updatedSuccessfully'))
5353
}
5454
},
5555
[fetchFullUser, history, admin, i18n],

packages/next/src/views/Version/Restore/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MinimalTemplate } from '@payloadcms/ui/templates/Minimal'
99
import { requests } from '@payloadcms/ui/utilities/api'
1010
import { useRouter } from 'next/navigation.js'
1111
import React, { Fragment, useCallback, useState } from 'react'
12-
import { toast } from 'react-toastify'
12+
import { toast } from 'sonner'
1313

1414
import type { Props } from './types.js'
1515

0 commit comments

Comments
 (0)