Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/site/layouts/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NavigationStateProvider } from '#site/providers/navigationStateProvider
import styles from './layouts.module.css';

const BaseLayout: FC<PropsWithChildren> = ({ children }) => (
<NotificationProvider viewportClassName="fixed bottom-0 right-0 list-none">
<NotificationProvider>
<NavigationStateProvider>
<div className={styles.baseLayout}>{children}</div>
</NavigationStateProvider>
Expand Down
8 changes: 4 additions & 4 deletions packages/ui-components/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Toast from '@radix-ui/react-toast';
import { withThemeByDataAttribute } from '@storybook/addon-themes';
import type { Preview, ReactRenderer } from '@storybook/react';

import { NotificationProvider } from '#ui/Providers/NotificationProvider';

import { STORYBOOK_MODES, STORYBOOK_SIZES } from './constants';

import '#ui/styles/index.css';
Expand All @@ -13,10 +14,9 @@ const preview: Preview = {
},
decorators: [
Story => (
<Toast.Provider>
<NotificationProvider>
<Story />
<Toast.Viewport />
</Toast.Provider>
</NotificationProvider>
),
withThemeByDataAttribute<ReactRenderer>({
themes: { light: '', dark: 'dark' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';

import { NotificationProvider, useNotification } from '../NotificationProvider';
import { NotificationProvider, useNotification } from '..';

describe('useNotification', () => {
it('should return the notification dispatch function', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@reference "../../styles/index.css";

.viewport {
@apply fixed
bottom-0
right-0
list-none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import type {

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

import styles from './index.module.css';

type NotificationContextType = {
message: string | ReactNode;
duration: number;
} | null;

type NotificationProps = { viewportClassName?: string };

const NotificationContext = createContext<NotificationContextType>(null);

export const NotificationDispatch = createContext<
Expand All @@ -25,10 +25,7 @@ export const NotificationDispatch = createContext<

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

export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
viewportClassName,
children,
}) => {
export const NotificationProvider: FC<PropsWithChildren> = ({ children }) => {
const [notification, dispatch] = useState<NotificationContextType>(null);

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

<Toast.Viewport className={viewportClassName} />

{notification && (
<Notification duration={notification.duration}>
{notification.message}
</Notification>
)}

<Toast.Viewport className={styles.viewport} />
</Toast.Provider>
</NotificationDispatch.Provider>
</NotificationContext.Provider>
Expand Down
Loading