feat: add other props in Toaster

This commit is contained in:
p-sw 2024-06-03 14:46:48 +09:00
parent 142adc0852
commit b6a1555397

View File

@ -256,11 +256,23 @@ const ToastTemplate = ({
); );
}; };
const Toaster = ({ const [toasterVariant, resolveToasterVariantProps] = vcn({
defaultOption, base: "fixed p-4 flex flex-col gap-4 top-0 right-0 w-full md:max-w-md md:bottom-0 md:top-auto pointer-events-none z-40",
}: { variants: {},
defaults: {},
});
interface ToasterProps
extends React.ComponentPropsWithoutRef<"div">,
VariantProps<typeof toasterVariant> {
defaultOption?: Partial<ToastOption>; defaultOption?: Partial<ToastOption>;
}) => { }
const Toaster = React.forwardRef<HTMLDivElement, ToasterProps>((props, ref) => {
const [variantProps, otherPropsCompressed] =
resolveToasterVariantProps(props);
const { defaultOption, ...otherPropsExtracted } = otherPropsCompressed;
const [toastList, setToastList] = React.useState<typeof toasts>(toasts); const [toastList, setToastList] = React.useState<typeof toasts>(toasts);
useEffect(() => { useEffect(() => {
@ -280,7 +292,11 @@ const Toaster = ({
return ( return (
<> <>
{ReactDOM.createPortal( {ReactDOM.createPortal(
<div className="fixed p-4 flex flex-col gap-4 top-0 right-0 w-full md:max-w-md md:bottom-0 md:top-auto pointer-events-none z-40"> <div
{...otherPropsExtracted}
className={toasterVariant(variantProps)}
ref={ref}
>
{Object.entries(toastList).map(([id]) => ( {Object.entries(toastList).map(([id]) => (
<ToastTemplate <ToastTemplate
key={id} key={id}
@ -293,6 +309,6 @@ const Toaster = ({
)} )}
</> </>
); );
}; });
export { Toaster, useToast }; export { Toaster, useToast };