Skip to content

Commit 8d8aeae

Browse files
authored
feat(ui): move more Toast logic (#7973)
1 parent cc36077 commit 8d8aeae

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

apps/site/layouts/Base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NavigationStateProvider } from '#site/providers/navigationStateProvider
88
import styles from './layouts.module.css';
99

1010
const BaseLayout: FC<PropsWithChildren> = ({ children }) => (
11-
<NotificationProvider viewportClassName="fixed bottom-0 right-0 list-none">
11+
<NotificationProvider>
1212
<NavigationStateProvider>
1313
<div className={styles.baseLayout}>{children}</div>
1414
</NavigationStateProvider>

packages/ui-components/.storybook/preview.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as Toast from '@radix-ui/react-toast';
21
import { withThemeByDataAttribute } from '@storybook/addon-themes';
32
import type { Preview, ReactRenderer } from '@storybook/react';
43

4+
import { NotificationProvider } from '#ui/Providers/NotificationProvider';
5+
56
import { STORYBOOK_MODES, STORYBOOK_SIZES } from './constants';
67

78
import '#ui/styles/index.css';
@@ -13,10 +14,9 @@ const preview: Preview = {
1314
},
1415
decorators: [
1516
Story => (
16-
<Toast.Provider>
17+
<NotificationProvider>
1718
<Story />
18-
<Toast.Viewport />
19-
</Toast.Provider>
19+
</NotificationProvider>
2020
),
2121
withThemeByDataAttribute<ReactRenderer>({
2222
themes: { light: '', dark: 'dark' },

packages/ui-components/src/Providers/__tests__/NotificationProvider.test.jsx renamed to packages/ui-components/src/Providers/NotificationProvider/__tests__/index.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
33
import { describe, it } from 'node:test';
44
import assert from 'node:assert/strict';
55

6-
import { NotificationProvider, useNotification } from '../NotificationProvider';
6+
import { NotificationProvider, useNotification } from '..';
77

88
describe('useNotification', () => {
99
it('should return the notification dispatch function', () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@reference "../../styles/index.css";
2+
3+
.viewport {
4+
@apply fixed
5+
bottom-0
6+
right-0
7+
list-none;
8+
}

packages/ui-components/src/Providers/NotificationProvider.tsx renamed to packages/ui-components/src/Providers/NotificationProvider/index.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import type {
1010

1111
import Notification from '#ui/Common/Notification';
1212

13+
import styles from './index.module.css';
14+
1315
type NotificationContextType = {
1416
message: string | ReactNode;
1517
duration: number;
1618
} | null;
1719

18-
type NotificationProps = { viewportClassName?: string };
19-
2020
const NotificationContext = createContext<NotificationContextType>(null);
2121

2222
export const NotificationDispatch = createContext<
@@ -25,10 +25,7 @@ export const NotificationDispatch = createContext<
2525

2626
export const useNotification = () => useContext(NotificationDispatch);
2727

28-
export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
29-
viewportClassName,
30-
children,
31-
}) => {
28+
export const NotificationProvider: FC<PropsWithChildren> = ({ children }) => {
3229
const [notification, dispatch] = useState<NotificationContextType>(null);
3330

3431
useEffect(() => {
@@ -43,13 +40,13 @@ export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
4340
<Toast.Provider>
4441
{children}
4542

46-
<Toast.Viewport className={viewportClassName} />
47-
4843
{notification && (
4944
<Notification duration={notification.duration}>
5045
{notification.message}
5146
</Notification>
5247
)}
48+
49+
<Toast.Viewport className={styles.viewport} />
5350
</Toast.Provider>
5451
</NotificationDispatch.Provider>
5552
</NotificationContext.Provider>

0 commit comments

Comments
 (0)