Skip to content

Commit

Permalink
fixup! Feat(web-react): Add Message and Link for ToastBar #DS-1213
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed May 24, 2024
1 parent eb1971d commit ba5b9bf
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions packages/web-react/src/components/Toast/ToastContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ export interface ToastItem {
content: ReactNode;
}

type ShowPayloadOptions = {
autoCloseInterval?: number;
color?: ToastColorType;
enableAutoClose?: boolean;
hasIcon?: boolean;
iconName?: string;
isDismissible?: boolean;
};

export interface ToastContextType extends ToastState {
clear: () => void;
hide: (id: string) => void;
setQueue: (newQueue: ToastItem[]) => void;
show: (
content: ReactNode,
id: string,
options?: {
autoCloseInterval?: number;
color?: ToastColorType;
enableAutoClose?: boolean;
hasIcon?: boolean;
iconName?: string;
isDismissible?: boolean;
},
) => void;
show: (content: ReactNode, id: string, options?: ShowPayloadOptions) => void;
}

const defaultToastContext: ToastContextType = {
Expand All @@ -53,14 +51,7 @@ type ActionType =
payload: {
content: ReactNode;
toastId: string;
options?: {
autoCloseInterval?: number;
color?: ToastColorType;
enableAutoClose?: boolean;
hasIcon?: boolean;
iconName?: string;
isDismissible?: boolean;
};
options?: ShowPayloadOptions;
};
}
| { type: 'hide'; payload: { id: string } }
Expand Down Expand Up @@ -123,26 +114,12 @@ export const ToastProvider: FC<ToastProviderProps> = ({ children }) => {
dispatch({ type: 'clear', payload: null });
}, []);

const show = useCallback(
(
content: string | JSX.Element,
toastId: string,
options?: {
autoCloseInterval?: number;
color?: ToastColorType;
enableAutoClose?: boolean;
hasIcon?: boolean;
iconName?: string;
isDismissible?: boolean;
},
) => {
dispatch({ type: 'show', payload: { content, toastId, options } });

options?.enableAutoClose &&
delayedCallback(() => hide(toastId), options?.autoCloseInterval || DEFAULT_TOAST_AUTO_CLOSE_INTERVAL);
},
[],
);
const show = useCallback((content: ReactNode, toastId: string, options?: ShowPayloadOptions) => {
dispatch({ type: 'show', payload: { content, toastId, options } });

options?.enableAutoClose &&
delayedCallback(() => hide(toastId), options?.autoCloseInterval || DEFAULT_TOAST_AUTO_CLOSE_INTERVAL);
}, []);
const setQueue = useCallback((newQueue: ToastItem[]) => {
dispatch({ type: 'clear', payload: null });

Expand Down

0 comments on commit ba5b9bf

Please sign in to comment.