@@ -15,7 +15,10 @@ import { useExampleTheme } from '..';
1515import ScreenWrapper from '../ScreenWrapper' ;
1616
1717const ChipExample = ( ) => {
18- const [ visible , setVisible ] = React . useState < boolean > ( false ) ;
18+ const [ snackbarProperties , setSnackbarProperties ] = React . useState ( {
19+ visible : false ,
20+ text : '' ,
21+ } ) ;
1922 const { isV3 } = useExampleTheme ( ) ;
2023 const customColor = isV3 ? MD3Colors . error50 : MD2Colors . purple900 ;
2124
@@ -47,7 +50,12 @@ const ChipExample = () => {
4750 ) }
4851 < Chip
4952 onPress = { ( ) => { } }
50- onClose = { ( ) => { } }
53+ onClose = { ( ) =>
54+ setSnackbarProperties ( {
55+ visible : true ,
56+ text : 'Close button pressed' ,
57+ } )
58+ }
5159 style = { styles . chip }
5260 closeIconAccessibilityLabel = "Close icon accessibility label"
5361 >
@@ -56,7 +64,12 @@ const ChipExample = () => {
5664 < Chip
5765 icon = "heart"
5866 onPress = { ( ) => { } }
59- onClose = { ( ) => { } }
67+ onClose = { ( ) =>
68+ setSnackbarProperties ( {
69+ visible : true ,
70+ text : 'Heart icon close button pressed' ,
71+ } )
72+ }
6073 style = { styles . chip }
6174 >
6275 Icon
@@ -69,7 +82,12 @@ const ChipExample = () => {
6982 />
7083 }
7184 onPress = { ( ) => { } }
72- onClose = { ( ) => { } }
85+ onClose = { ( ) =>
86+ setSnackbarProperties ( {
87+ visible : true ,
88+ text : 'Avatar close button pressed' ,
89+ } )
90+ }
7391 style = { styles . chip }
7492 >
7593 Avatar
@@ -87,7 +105,17 @@ const ChipExample = () => {
87105 >
88106 Avatar (selected)
89107 </ Chip >
90- < Chip disabled icon = "heart" onClose = { ( ) => { } } style = { styles . chip } >
108+ < Chip
109+ disabled
110+ icon = "heart"
111+ onClose = { ( ) =>
112+ setSnackbarProperties ( {
113+ visible : true ,
114+ text : 'Disabled heart icon close button pressed' ,
115+ } )
116+ }
117+ style = { styles . chip }
118+ >
91119 Icon (disabled)
92120 </ Chip >
93121 < Chip
@@ -141,7 +169,12 @@ const ChipExample = () => {
141169 < Chip
142170 mode = "outlined"
143171 onPress = { ( ) => { } }
144- onClose = { ( ) => { } }
172+ onClose = { ( ) =>
173+ setSnackbarProperties ( {
174+ visible : true ,
175+ text : 'Close button pressed' ,
176+ } )
177+ }
145178 style = { styles . chip }
146179 >
147180 Close button
@@ -150,7 +183,12 @@ const ChipExample = () => {
150183 mode = "outlined"
151184 icon = "heart"
152185 onPress = { ( ) => { } }
153- onClose = { ( ) => { } }
186+ onClose = { ( ) =>
187+ setSnackbarProperties ( {
188+ visible : true ,
189+ text : 'Heart icon close button pressed' ,
190+ } )
191+ }
154192 style = { styles . chip }
155193 >
156194 Icon
@@ -186,7 +224,12 @@ const ChipExample = () => {
186224 disabled
187225 mode = "outlined"
188226 icon = "heart"
189- onClose = { ( ) => { } }
227+ onClose = { ( ) =>
228+ setSnackbarProperties ( {
229+ visible : true ,
230+ text : 'Disabled close button pressed' ,
231+ } )
232+ }
190233 style = { styles . chip }
191234 >
192235 Icon (disabled)
@@ -243,7 +286,9 @@ const ChipExample = () => {
243286 < Chip
244287 mode = "outlined"
245288 onPress = { ( ) => { } }
246- onLongPress = { ( ) => setVisible ( true ) }
289+ onLongPress = { ( ) =>
290+ setSnackbarProperties ( { visible : true , text : '' } )
291+ }
247292 style = { styles . chip }
248293 >
249294 With onLongPress
@@ -299,7 +344,12 @@ const ChipExample = () => {
299344 </ Chip >
300345 < Chip
301346 onPress = { ( ) => { } }
302- onClose = { ( ) => { } }
347+ onClose = { ( ) =>
348+ setSnackbarProperties ( {
349+ visible : true ,
350+ text : 'Close button pressed' ,
351+ } )
352+ }
303353 style = { styles . bigTextFlex }
304354 textStyle = { styles . bigTextStyle }
305355 ellipsizeMode = "middle"
@@ -310,7 +360,12 @@ const ChipExample = () => {
310360 </ Chip >
311361 < Chip
312362 onPress = { ( ) => { } }
313- onClose = { ( ) => { } }
363+ onClose = { ( ) =>
364+ setSnackbarProperties ( {
365+ visible : true ,
366+ text : 'Custom icon close button pressed' ,
367+ } )
368+ }
314369 closeIcon = "arrow-down"
315370 style = { styles . chip }
316371 closeIconAccessibilityLabel = "Custom Close icon accessibility label"
@@ -331,11 +386,11 @@ const ChipExample = () => {
331386 </ List . Section >
332387 </ ScreenWrapper >
333388 < Snackbar
334- visible = { visible }
335- onDismiss = { ( ) => setVisible ( false ) }
389+ visible = { snackbarProperties . visible }
390+ onDismiss = { ( ) => setSnackbarProperties ( { visible : false , text : '' } ) }
336391 duration = { Snackbar . DURATION_SHORT }
337392 >
338- onLongPress activated!
393+ { snackbarProperties . text }
339394 </ Snackbar >
340395 </ >
341396 ) ;
0 commit comments