You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Box,}from'@tonic-ui/react';importReact,{forwardRef}from'react';constInlineToastContainer=forwardRef((inProps,ref)=>(<Boxref={ref}flexDirection="column"alignItems="center"position="absolute"top="12x"left="50%"transform="translateX(-50%)"width="max-content"maxWidth="80%"// up to 80% of the modal or drawer widthzIndex="toast"{...inProps}/>));InlineToastContainer.displayName='InlineToastContainer';exportdefaultInlineToastContainer;
InlineToasts
import{Toast,ToastController,ToastTransition,useColorStyle,}from'@tonic-ui/react';importReactfrom'react';import{TransitionGroup}from'react-transition-group';constInlineToasts=inProps=>{const[colorStyle]=useColorStyle();const{
toasts =[],
...rest}=inProps;return(<TransitionGroupcomponent={null}// Pass in `component={null}` to avoid a wrapping `<div>` element>{toasts.map(toast=>(<ToastTransitionkey={toast?.id}in={true}unmountOnExit><ToastControllerduration={toast?.duration}onClose={toast?.onClose}><Toastappearance={toast?.appearance}isClosable={toast?.isClosable}onClose={toast?.onClose}sx={{mb: '2x',minWidth: 280,// The toast has a minimum width of 280 pixelswidth: 'fit-content',boxShadow: colorStyle.shadow.thin,}}>{toast?.content}</Toast></ToastController></ToastTransition>))}</TransitionGroup>);};InlineToasts.displayName='InlineToasts';exportdefaultInlineToasts;
useInlineToasts
import{ensurePositiveInteger}from'ensure-type';import{useCallback,useMemo,useState}from'react';constuniqueId=(()=>{letid=0;return()=>{id+=1;returnString(id);};})();constuseInlineToasts=(options)=>{constmaxToasts=ensurePositiveInteger(options?.maxToasts);const[toasts,setToasts]=useState([]);constnotify=useCallback((options)=>{const{
appearance,
content,
duration =null,
isClosable =true,}={ ...options};setToasts(prevState=>{constid=uniqueId();constonClose=()=>{setToasts(toasts=>toasts.filter(x=>x.id!==id));};// You can decide how many toasts you want to show at the same time depending on your use caseconstnextState=[
...prevState.slice(maxToasts>1 ? -(maxToasts-1) : prevState.length),{
id,
appearance,
content,
duration,
isClosable,
onClose,},];returnnextState;});},[maxToasts]);constdismiss=useCallback(()=>{setToasts([]);},[]);constcontext=useMemo(()=>({
toasts,
notify,
dismiss,}),[toasts,notify,dismiss]);returncontext;};exportdefaultuseInlineToasts;
The text was updated successfully, but these errors were encountered:
cheton
changed the title
Add InlineToastContainer and useInlineToasts examples for inline, non-intrusive notifications in modals and drawer scenarios
Add InlineToasts and useInlineToasts for inline, non-intrusive notifications in modals and drawer scenarios
Sep 28, 2024
cheton
changed the title
Add InlineToasts and useInlineToasts for inline, non-intrusive notifications in modals and drawer scenarios
Add InlineToasts and useInlineToasts examples for inline, non-intrusive notifications in modals and drawer scenarios
Oct 28, 2024
Usage
Use the
useInlineToasts
hook to manage inline toast notifications:Trigger an inline toast notification:
Display inline toasts on a
Modal
:Components
InlineToastContainer
InlineToasts
useInlineToasts
The text was updated successfully, but these errors were encountered: