@@ -6,12 +6,11 @@ import {
66 DismissCircle20Regular ,
77 Dismiss20Regular ,
88} from "@fluentui/react-icons" ;
9- import { Body1 , Spinner } from "@fluentui/react-components" ;
9+ import { Body1 , Button , Spinner } from "@fluentui/react-components" ;
1010
1111// Toast type
1212export type ToastIntent = "info" | "success" | "warning" | "error" | "progress" ;
1313
14- // Toast data structure
1514type Toast = {
1615 id : number ;
1716 content : React . ReactNode ;
@@ -20,10 +19,8 @@ type Toast = {
2019 dismissible ?: boolean ;
2120} ;
2221
23- // Internal state setter reference
2422let _setToasts : React . Dispatch < React . SetStateAction < Toast [ ] > > | null = null ;
2523
26- // Hook for triggering toasts
2724export const useInlineToaster = ( ) => {
2825 const showToast = (
2926 content : React . ReactNode ,
@@ -82,7 +79,6 @@ export const useInlineToaster = () => {
8279 return { showToast, dismissToast } ;
8380} ;
8481
85- // Icon mapping
8682const getIconForIntent = ( intent : ToastIntent ) => {
8783 switch ( intent ) {
8884 case "success" :
@@ -100,7 +96,6 @@ const getIconForIntent = (intent: ToastIntent) => {
10096 }
10197} ;
10298
103- // Toaster render mount
10499const InlineToaster : React . FC = ( ) => {
105100 const [ toasts , setToasts ] = useState < Toast [ ] > ( [ ] ) ;
106101
@@ -123,6 +118,7 @@ const InlineToaster: React.FC = () => {
123118 gap : 8 ,
124119 zIndex : 1000 ,
125120 pointerEvents : "none" ,
121+ alignContent :'center'
126122 } }
127123 >
128124 { toasts . map ( ( toast ) => (
@@ -131,49 +127,64 @@ const InlineToaster: React.FC = () => {
131127 style = { {
132128 background : "var(--colorNeutralBackground3)" ,
133129 border : "1px solid var(--colorNeutralStroke1)" ,
134- padding : "16px" ,
130+ padding : "12px 16px" ,
135131 borderRadius : 9999 ,
136132 color : "var(--colorNeutralForeground1)" ,
137133 boxShadow : "0 4px 12px rgba(0,0,0,0.1)" ,
138- minWidth : 160 ,
139- textAlign : "left" ,
140- fontSize : 14 ,
141134 display : "flex" ,
142135 alignItems : "center" ,
136+ fontSize : 14 ,
143137 gap : 8 ,
144138 opacity : toast . visible ? 1 : 0 ,
145139 transform : toast . visible ? "translateY(0px)" : "translateY(20px)" ,
146140 transition : "opacity 0.3s ease, transform 0.3s ease" ,
147141 pointerEvents : "auto" ,
148- position : "relative" ,
142+ maxWidth : "calc(100vw - 48px)" ,
143+ whiteSpace : "nowrap" ,
144+ overflow : "hidden" ,
145+ textOverflow : "ellipsis" ,
146+ justifyContent :'center' ,
147+ alignContent :'center' ,
148+ height :'54px' ,
149+ boxSizing :'border-box'
149150 } }
150151 >
151- < span style = { { display : "flex" , alignItems : "center" } } >
152- { getIconForIntent ( toast . intent ) }
153- </ span >
154- < Body1 > { toast . content } </ Body1 >
152+ < span style = { { flexShrink : 0 } } > { getIconForIntent ( toast . intent ) } </ span >
153+
154+ < Body1
155+ style = { {
156+ overflow : "hidden" ,
157+ textOverflow : "ellipsis" ,
158+ whiteSpace : "nowrap" ,
159+ flexGrow : 1 ,
160+ } }
161+ >
162+ { toast . content }
163+ </ Body1 >
164+
155165 { ( toast . dismissible || toast . intent === "progress" ) && (
156- < button
166+ < Button
157167 onClick = { ( ) =>
158168 _setToasts ?.( ( prev ) => prev . filter ( ( t ) => t . id !== toast . id ) )
159169 }
160170 style = { {
161- position : "absolute" ,
162- top : "50%" ,
163- right : 8 ,
164- transform : "translateY(-50%)" ,
165171 background : "transparent" ,
166172 border : "none" ,
167173 cursor : "pointer" ,
168174 color : "var(--colorNeutralForeground1)" ,
169175 display : "flex" ,
170176 alignItems : "center" ,
171177 justifyContent : "center" ,
178+ flexShrink : 0 ,
172179 } }
173180 aria-label = "Dismiss"
181+ icon = { < Dismiss20Regular /> }
182+ appearance = "subtle"
183+ shape = "circular"
174184 >
175- < Dismiss20Regular />
176- </ button >
185+
186+
187+ </ Button >
177188 ) }
178189 </ div >
179190 ) ) }
0 commit comments