Skip to content

Commit d5fab43

Browse files
feat: make toast position configurable (#14405)
### What? Extends the toast configuration introduced with #13609 to also allow to configure the toast's positioning. ### Why? Different users of Payload might prefer different positions. E.g. for our own implementation we'd prefer a top (central) position, because we've been having users overlook the toasts in the bottom right due to usage of large screens, and saving / publishing buttons usually triggering toasts being placed at the top (meaning the user looks at the top). ### How? The `position` configuration is a 1:1 pass-through of the https://sonner.emilkowal.ski `position` configuration option. The default remains unchanged compared to the status-quo, at `'bottom-right'`. ### Screenshots *`bottom-right`:* Unchanged to current placement. *`bottom-center`:* <img width="1283" height="1373" alt="image" src="https://github.com/user-attachments/assets/ad2716d4-3a8b-467e-be03-80abf0e1233f" /> *`bottom-left`:* <img width="1283" height="1375" alt="image" src="https://github.com/user-attachments/assets/4f7b1efe-de1a-4a48-be5d-9746ba4e7296" /> *`top-left` - questionable, but IMHO that's fine because it's an opt-in choice.*: <img width="1276" height="1371" alt="image" src="https://github.com/user-attachments/assets/ff11e2f5-0aa0-411a-9bcf-01083184a531" /> *`top-center`:* <img width="1285" height="1384" alt="image" src="https://github.com/user-attachments/assets/603e735f-36f5-4b5a-8e9f-b1c80b2a2907" /> *`top-left` - also covers interactive UI, but is therefore very hard to overlook:* <img width="1283" height="1370" alt="image" src="https://github.com/user-attachments/assets/40ecdd57-a9d2-4d47-b8d9-26e64164e1ee" />
1 parent 36bb188 commit d5fab43

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

docs/admin/overview.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ The `admin.toast` configuration allows you to customize the handling of toast me
341341

342342
The following options are available for the `admin.toast` configuration:
343343

344-
| Option | Description | Default |
345-
| ---------- | ---------------------------------------------------------------------------------------------------------------- | ------- |
346-
| `duration` | The length of time (in milliseconds) that a toast message is displayed. | `4000` |
347-
| `expand` | If `true`, will expand the message stack so that all messages are shown simultaneously without user interaction. | `false` |
348-
| `limit` | The maximum number of toasts that can be visible on the screen at once. | `5` |
344+
| Option | Description | Default |
345+
| ---------- | ---------------------------------------------------------------------------------------------------------------- | -------------- |
346+
| `duration` | The length of time (in milliseconds) that a toast message is displayed. | `4000` |
347+
| `expand` | If `true`, will expand the message stack so that all messages are shown simultaneously without user interaction. | `false` |
348+
| `limit` | The maximum number of toasts that can be visible on the screen at once. | `5` |
349+
| `position` | The position of the toast on the screen. | `bottom-right` |

packages/payload/src/config/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,17 @@ export type Config = {
987987
* @default 5
988988
*/
989989
limit?: number
990+
/**
991+
* The position of the toast on the screen.
992+
* @default 'bottom-right'
993+
*/
994+
position?:
995+
| 'bottom-center'
996+
| 'bottom-left'
997+
| 'bottom-right'
998+
| 'top-center'
999+
| 'top-left'
1000+
| 'top-right'
9901001
}
9911002
/** The slug of a Collection that you want to be used to log in to the Admin dashboard. */
9921003
user?: string

packages/ui/src/providers/ToastContainer/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Warning } from './icons/Warning.js'
1212
export const ToastContainer: React.FC<{
1313
config: ClientConfig
1414
}> = ({ config }) => {
15-
const { admin: { toast: { duration, expand, limit } = {} } = {} } = config
15+
const { admin: { toast: { duration, expand, limit, position } = {} } = {} } = config
1616

1717
return (
1818
<Toaster
@@ -30,6 +30,7 @@ export const ToastContainer: React.FC<{
3030
warning: <Warning />,
3131
}}
3232
offset="calc(var(--gutter-h) / 2)"
33+
position={position ?? 'bottom-right'}
3334
toastOptions={{
3435
classNames: {
3536
closeButton: 'payload-toast-close-button',

0 commit comments

Comments
 (0)