Skip to content

Commit 3080b8b

Browse files
committed
Lint
1 parent 1b7eb84 commit 3080b8b

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

packages/react/src/toast/provider/ToastProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const ToastProvider: React.FC<ToastProvider.Props> = function ToastProvider(prop
273273
});
274274

275275
return unsubscribe;
276-
}, [add, update, remove, scheduleTimer, timeout, toastManager, promise]);
276+
}, [add, update, scheduleTimer, timeout, toastManager, promise, close]);
277277

278278
const contextValue = React.useMemo(
279279
() => ({

packages/react/src/toast/root/ToastRoot.tsx

+42-21
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ const ToastRoot = React.forwardRef(function ToastRoot(
116116
);
117117

118118
useEnhancedEffect(() => {
119-
if (!rootRef.current) return;
119+
if (!rootRef.current) {
120+
return undefined;
121+
}
122+
120123
function setHeights() {
121124
const height = rootRef.current?.offsetHeight;
122125
setToasts((prev) =>
@@ -132,14 +135,18 @@ const ToastRoot = React.forwardRef(function ToastRoot(
132135
),
133136
);
134137
}
138+
135139
setHeights();
140+
136141
if (typeof ResizeObserver === 'function') {
137142
const resizeObserver = new ResizeObserver(setHeights);
138143
resizeObserver.observe(rootRef.current);
139144
return () => {
140145
resizeObserver.disconnect();
141146
};
142147
}
148+
149+
return undefined;
143150
}, [toast.id, setToasts]);
144151

145152
const offset = React.useMemo(() => {
@@ -245,7 +252,9 @@ const ToastRoot = React.forwardRef(function ToastRoot(
245252
}
246253

247254
function handlePointerMove(event: React.PointerEvent) {
248-
if (!isDragging) return;
255+
if (!isDragging) {
256+
return;
257+
}
249258

250259
const deltaX = event.clientX - dragStartPosRef.current.x;
251260
const deltaY = event.clientY - dragStartPosRef.current.y;
@@ -273,19 +282,23 @@ const ToastRoot = React.forwardRef(function ToastRoot(
273282
let candidate: 'up' | 'down' | 'left' | 'right' | undefined;
274283
if (!intendedSwipeDirectionRef.current) {
275284
if (lockedDirection === 'vertical') {
276-
candidate = deltaY > 0 ? 'down' : deltaY < 0 ? 'up' : undefined;
285+
if (deltaY > 0) {
286+
candidate = 'down';
287+
} else if (deltaY < 0) {
288+
candidate = 'up';
289+
}
277290
} else if (lockedDirection === 'horizontal') {
278-
candidate = deltaX > 0 ? 'right' : deltaX < 0 ? 'left' : undefined;
291+
if (deltaY > 0) {
292+
candidate = 'right';
293+
} else if (deltaY < 0) {
294+
candidate = 'left';
295+
}
296+
} else if (Math.abs(deltaX) >= Math.abs(deltaY)) {
297+
candidate = deltaX > 0 ? 'right' : 'left';
279298
} else {
280-
candidate =
281-
Math.abs(deltaX) >= Math.abs(deltaY)
282-
? deltaX > 0
283-
? 'right'
284-
: 'left'
285-
: deltaY > 0
286-
? 'down'
287-
: 'up';
299+
candidate = deltaY > 0 ? 'down' : 'up';
288300
}
301+
289302
if (candidate && swipeDirections.includes(candidate)) {
290303
intendedSwipeDirectionRef.current = candidate;
291304
maxSwipeDisplacementRef.current = getDisplacement(candidate, deltaX, deltaY);
@@ -359,16 +372,24 @@ const ToastRoot = React.forwardRef(function ToastRoot(
359372
for (const direction of swipeDirections) {
360373
switch (direction) {
361374
case 'right':
362-
if (deltaX > SWIPE_THRESHOLD) shouldClose = true;
375+
if (deltaX > SWIPE_THRESHOLD) {
376+
shouldClose = true;
377+
}
363378
break;
364379
case 'left':
365-
if (deltaX < -SWIPE_THRESHOLD) shouldClose = true;
380+
if (deltaX < -SWIPE_THRESHOLD) {
381+
shouldClose = true;
382+
}
366383
break;
367384
case 'down':
368-
if (deltaY > SWIPE_THRESHOLD) shouldClose = true;
385+
if (deltaY > SWIPE_THRESHOLD) {
386+
shouldClose = true;
387+
}
369388
break;
370389
case 'up':
371-
if (deltaY < -SWIPE_THRESHOLD) shouldClose = true;
390+
if (deltaY < -SWIPE_THRESHOLD) {
391+
shouldClose = true;
392+
}
372393
break;
373394
default:
374395
break;
@@ -406,7 +427,7 @@ const ToastRoot = React.forwardRef(function ToastRoot(
406427
React.useEffect(() => {
407428
const element = rootRef.current;
408429
if (!element) {
409-
return;
430+
return undefined;
410431
}
411432

412433
function preventDefaultTouchStart(event: TouchEvent) {
@@ -513,7 +534,7 @@ const ToastRoot = React.forwardRef(function ToastRoot(
513534
// of the component. We need to wait until the next tick to render the children
514535
// so that screen readers can announce the contents.
515536
children: (
516-
<>
537+
<React.Fragment>
517538
{children}
518539
{!focused && (
519540
<div
@@ -523,14 +544,14 @@ const ToastRoot = React.forwardRef(function ToastRoot(
523544
: { role: 'status', 'aria-live': 'polite' })}
524545
>
525546
{renderChildren && (
526-
<>
547+
<React.Fragment>
527548
<div>{toast.title}</div>
528549
<div>{toast.description}</div>
529-
</>
550+
</React.Fragment>
530551
)}
531552
</div>
532553
)}
533-
</>
554+
</React.Fragment>
534555
),
535556
},
536557
other,

packages/react/src/toast/root/ToastRootContext.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
2-
import type { Toast } from '../useToast';
2+
import type { ToastObject } from '../useToast';
33

44
export interface ToastRootContext {
5-
toast: Toast<any>;
5+
toast: ToastObject<any>;
66
rootRef: React.RefObject<HTMLElement | null>;
77
titleId: string | undefined;
88
setTitleId: React.Dispatch<React.SetStateAction<string | undefined>>;

0 commit comments

Comments
 (0)