Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lift-position-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
timolins committed Jan 21, 2021
2 parents b43caa1 + 1aa0596 commit 802fe9e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 30 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<a href="https://twitter.com/timolins">Twitter</a>
</div>

<br />
<div align="center">
<sub>Cooked by <a href="https://twitter.com/timolins">Timo Lins</a> 👨‍🍳</sub>
</div>

<br />

## Features
Expand Down Expand Up @@ -65,7 +70,3 @@ const App = () => {
## Documentation

Find the full API reference on [official documentation](https://react-hot-toast.com/docs).

## Credits

**react-hot-toast** was cooked by [Timo Lins](https://timo.sh) 👨‍🍳
8 changes: 8 additions & 0 deletions site/components/sections/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export function Footer() {
</a>
</span>
</div>
<div>
<a href="https://splitbee.io">
<img
src="https://splitbee.io/splitbee-badge.svg"
alt="Splitbee Analytics"
/>
</a>
</div>
</footer>
);
}
2 changes: 1 addition & 1 deletion site/components/sections/toast-example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const examples: Array<{
saveSettings(settings),
{
loading: 'Saving...',
success: <b>Settings saved!</b>,,
success: <b>Settings saved!</b>,
error: <b>Could not save.</b>,
}
);`,
Expand Down
4 changes: 0 additions & 4 deletions site/components/sections/toaster-example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ export const ToasterExample: React.FC<{
}
);

(window as any).splitbee?.track('Change Position', {
position: p,
});

onPosition(p);
}}
>
Expand Down
2 changes: 1 addition & 1 deletion site/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<script async data-api="/_hive" src="/bee.js"></script>
<script async data-no-cookie data-api="/_hive" src="/bee.js"></script>
<link rel="shortcut icon" href="/favicon.png" type="image/x-icon" />
</Head>
<MDXProvider components={components}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/toast-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ export const ToastBar: React.FC<ToastBarProps> = React.memo(
({ toast, position, onHeight }) => {
const ref = useCallback((el: HTMLElement | null) => {
if (el) {
const boundingRect = el.getBoundingClientRect();
onHeight(boundingRect.height);
setTimeout(() => {
const boundingRect = el.getBoundingClientRect();
onHeight(boundingRect.height);
});
}
}, []);

Expand Down
1 change: 0 additions & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export enum ActionType {
UPSERT_TOAST,
DISMISS_TOAST,
REMOVE_TOAST,
TOAST,
START_PAUSE,
END_PAUSE,
}
Expand Down
15 changes: 13 additions & 2 deletions src/core/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ toast.error = createHandler('error');
toast.success = createHandler('success');
toast.loading = createHandler('loading');

toast.dismiss = (toastId?: string) =>
dispatch({ type: ActionType.DISMISS_TOAST, toastId });
toast.dismiss = (toastId?: string) => {
dispatch({
type: ActionType.DISMISS_TOAST,
toastId,
});
setTimeout(() => {
dispatch({
type: ActionType.REMOVE_TOAST,
toastId,
});
}, 1000);
};

toast.remove = (toastId?: string) =>
dispatch({ type: ActionType.REMOVE_TOAST, toastId });

Expand Down
18 changes: 3 additions & 15 deletions src/core/use-toaster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useMemo } from 'react';
import { dispatch, ActionType, useStore } from './store';
import { toast } from './toast';
import { DefaultToastOptions } from './types';

export const useToaster = (toastOptions?: DefaultToastOptions) => {
Expand All @@ -16,26 +17,13 @@ export const useToaster = (toastOptions?: DefaultToastOptions) => {
const durationLeft =
(t.duration || 0) + t.pauseDuration - (now - t.createdAt);

const dismiss = () => {
dispatch({
type: ActionType.DISMISS_TOAST,
toastId: t.id,
});
setTimeout(() => {
dispatch({
type: ActionType.REMOVE_TOAST,
toastId: t.id,
});
}, 1000);
};

if (durationLeft < 0) {
if (t.visible) {
dismiss();
toast.dismiss(t.id);
}
return;
}
return setTimeout(dismiss, durationLeft);
return setTimeout(() => toast.dismiss(t.id), durationLeft);
});

return () => {
Expand Down

0 comments on commit 802fe9e

Please sign in to comment.