Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add center-center position #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getAsset = (type: ToastTypes): JSX.Element | null => {

const bars = Array(12).fill(0);

export const Loader = ({ visible, className }: { visible: boolean, className?: string }) => {
export const Loader = ({ visible, className }: { visible: boolean; className?: string }) => {
return (
<div className={['sonner-loading-wrapper', className].filter(Boolean).join(' ')} data-visible={visible}>
<div className="sonner-spinner">
Expand Down
5 changes: 5 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
bottom: max(var(--offset), env(safe-area-inset-bottom));
}

:where([data-sonner-toaster][data-x-position='center'][data-y-position='center']) {
top: calc(50% - calc(var(--front-toast-height) / 2));
left: 50%;
}

:where([data-sonner-toast]) {
--y: translateY(100%);
--lift-amount: calc(var(--lift) * var(--gap));
Expand Down
9 changes: 8 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ export function isAction(action: Action | React.ReactNode): action is Action {
return (action as Action).label !== undefined;
}

export type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
export type Position =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right'
| 'top-center'
| 'bottom-center'
| 'center-center';
export interface HeightT {
height: number;
toastId: number | string;
Expand Down
12 changes: 10 additions & 2 deletions website/src/components/Position/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { toast, useSonner } from 'sonner';
import { CodeBlock } from '../CodeBlock';
import React from 'react';

const positions = ['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'] as const;
const positions = [
'top-left',
'top-center',
'top-right',
'bottom-left',
'bottom-center',
'bottom-right',
'center-center',
] as const;

export type Position = (typeof positions)[number];

Expand Down Expand Up @@ -33,7 +41,7 @@ export const Position = ({
setPosition(position);
removeAllToasts();
}

toast('Event has been created', {
description: 'Monday, January 3rd at 6:00pm',
});
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/toast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function. It will not affect the positioning of other toasts.

```jsx
// Available positions:
// top-left, top-center, top-right, bottom-left, bottom-center, bottom-right
// top-left, top-center, top-right, bottom-left, bottom-center, bottom-right, center-center
toast('Hello World', {
position: 'top-center',
});
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/toaster.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Changes the place where all toasts will be rendered.

```jsx
// Available positions:
// top-left, top-center, top-right, bottom-left, bottom-center, bottom-right
// top-left, top-center, top-right, bottom-left, bottom-center, bottom-right, center-center
<Toaster position="top-center" />
```

Expand Down