Skip to content

Commit

Permalink
feat: 정규식 입력 시 해당 정규식을 만족하는 아이디를 가진 토스트만 보여주기
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Sep 26, 2024
1 parent 1018668 commit 66382cb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/wow-ui/src/components/Toast/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import type { ToastProps } from ".";
import Toast from ".";
import { ToastContext } from "./ToastContext";

const ToastProvider = ({ children }: { children: ReactNode }) => {
interface ToastProviderProps {
children: ReactNode;
idPattern?: RegExp;
}

const ToastProvider = ({ children, idPattern }: ToastProviderProps) => {
const [toasts, setToasts] = useState<ToastProps[]>([]);

const addToast = (
Expand All @@ -19,14 +24,18 @@ const ToastProvider = ({ children }: { children: ReactNode }) => {
...props,
id: props.id || uuidv4(),
};
console.log(newToast.id);

setToasts((prev) => [...prev, newToast]);
};

const removeToast = (id: string) => {
setToasts((prev) => prev.filter((toast) => toast.id !== id));
};

const filteredToasts = idPattern
? toasts.filter((toast) => idPattern.test(toast.id))
: toasts;

return (
<ToastContext.Provider value={{ toasts, addToast, removeToast }}>
{toasts.length > 0 && (
Expand All @@ -41,7 +50,7 @@ const ToastProvider = ({ children }: { children: ReactNode }) => {
width="100vw"
zIndex="overlay"
>
{toasts?.map((toast: ToastProps) => (
{filteredToasts?.map((toast: ToastProps) => (
<Toast key={toast.id} {...toast} />
))}
</Flex>
Expand Down

0 comments on commit 66382cb

Please sign in to comment.