Skip to content

Commit

Permalink
feat: add center-center position
Browse files Browse the repository at this point in the history
  • Loading branch information
multivoltage committed Dec 10, 2024
1 parent edc615f commit 0c22b14
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
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

0 comments on commit 0c22b14

Please sign in to comment.