An opinionated toast component for React.
Add gap prop (#181)
Emil Kowalski74233736b244
diff --git a/src/index.tsx b/src/index.tsxindex 4de4d07..bea0219 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -36,6 +36,7 @@ interface ToastProps {heights: HeightT[];setHeights: React.Dispatch<React.SetStateAction<HeightT[]>>;removeToast: (toast: ToastT) => void;+ gap?: number;position: Position;visibleToasts: number;expandByDefault: boolean;@@ -65,6 +66,7 @@ const Toast = (props: ToastProps) => {descriptionClassName = '',duration: durationFromToaster,position,+ gap = GAP,expandByDefault,} = props;const [mounted, setMounted] = React.useState(false);@@ -110,7 +112,7 @@ const Toast = (props: ToastProps) => {const invert = toast.invert || ToasterInvert;const disabled = toastType === 'loading';- offset.current = React.useMemo(() => heightIndex * GAP + toastsHeightBefore, [heightIndex, toastsHeightBefore]);+ offset.current = React.useMemo(() => heightIndex * gap + toastsHeightBefore, [heightIndex, toastsHeightBefore]);React.useEffect(() => {// Trigger enter animation without using CSS animation@@ -399,6 +401,7 @@ const Toaster = (props: ToasterProps) => {visibleToasts = VISIBLE_TOASTS_AMOUNT,toastOptions,dir = getDocumentDirection(),+ gap,} = props;const [toasts, setToasts] = React.useState<ToastT[]>([]);const possiblePositions = React.useMemo(() => {@@ -612,6 +615,7 @@ const Toaster = (props: ToasterProps) => {heights={heights}setHeights={setHeights}expandByDefault={expand}+ gap={gap}expanded={expanded}/>))}diff --git a/src/types.ts b/src/types.tsindex 8d9ff75..97a61e4 100644--- a/src/types.ts+++ b/src/types.ts@@ -61,6 +61,7 @@ export interface ToasterProps {richColors?: boolean;expand?: boolean;duration?: number;+ gap?: number;visibleToasts?: number;closeButton?: boolean;toastOptions?: ToastOptions;diff --git a/website/src/pages/toaster.mdx b/website/src/pages/toaster.mdxindex e3d6742..a1e43bc 100644--- a/website/src/pages/toaster.mdx+++ b/website/src/pages/toaster.mdx@@ -62,3 +62,4 @@ Changes the directionality of the toast's text.| hotkey | Keyboard shortcut that will move focus to the toaster area. | `⌥/alt + T` || invert | Dark toasts in light mode and vice versa. | `false` || toastOptions | These will act as default options for all toasts. See [toast()](/toast) for all available options. | `4000` |+| gap | Gap between toasts when expanded | `14` |