|
| 1 | +open Mui |
| 2 | + |
| 3 | +@react.component |
| 4 | +let make = () => { |
| 5 | + let (loading, setLoading) = React.useState(_ => false) |
| 6 | + |
| 7 | + let handleClick = _ => { |
| 8 | + setLoading(_ => true) |
| 9 | + // Simulate async operation |
| 10 | + let _ = Js.Global.setTimeout(() => setLoading(_ => false), 2000) |
| 11 | + } |
| 12 | + |
| 13 | + <div> |
| 14 | + <Typography variant=H6> {"Button Loading Examples:"->React.string} </Typography> |
| 15 | + <Box sx={Sx.obj({display: String("flex"), flexDirection: String("column"), gap: String("16px"), maxWidth: String("300px")})}> |
| 16 | + // Basic loading button |
| 17 | + <Button |
| 18 | + id="button-loading-basic" |
| 19 | + variant=Contained |
| 20 | + loading={loading ? True : False} |
| 21 | + onClick=handleClick> |
| 22 | + {"Click to Load"->React.string} |
| 23 | + </Button> |
| 24 | + // Loading with different positions |
| 25 | + <Typography variant=Subtitle2> {"Loading Positions:"->React.string} </Typography> |
| 26 | + <Button |
| 27 | + id="button-loading-center" |
| 28 | + variant=Contained |
| 29 | + loading=True |
| 30 | + loadingPosition=Center> |
| 31 | + {"Center (default)"->React.string} |
| 32 | + </Button> |
| 33 | + <Button |
| 34 | + id="button-loading-start" |
| 35 | + variant=Contained |
| 36 | + loading=True |
| 37 | + loadingPosition=Start |
| 38 | + startIcon={<span> {">"->React.string} </span>}> |
| 39 | + {"Start Position"->React.string} |
| 40 | + </Button> |
| 41 | + <Button |
| 42 | + id="button-loading-end" |
| 43 | + variant=Contained |
| 44 | + loading=True |
| 45 | + loadingPosition=End |
| 46 | + endIcon={<span> {">"->React.string} </span>}> |
| 47 | + {"End Position"->React.string} |
| 48 | + </Button> |
| 49 | + // Custom loading indicator |
| 50 | + <Typography variant=Subtitle2> {"Custom Loading Indicator:"->React.string} </Typography> |
| 51 | + <Button |
| 52 | + id="button-loading-custom" |
| 53 | + variant=Outlined |
| 54 | + loading=True |
| 55 | + loadingIndicator={<span> {"Loading..."->React.string} </span>}> |
| 56 | + {"Submit"->React.string} |
| 57 | + </Button> |
| 58 | + // Loading with different variants |
| 59 | + <Typography variant=Subtitle2> {"Loading with Variants:"->React.string} </Typography> |
| 60 | + <Button id="button-loading-text" variant=Text loading=True> |
| 61 | + {"Text"->React.string} |
| 62 | + </Button> |
| 63 | + <Button id="button-loading-outlined" variant=Outlined loading=True> |
| 64 | + {"Outlined"->React.string} |
| 65 | + </Button> |
| 66 | + <Button id="button-loading-contained" variant=Contained loading=True> |
| 67 | + {"Contained"->React.string} |
| 68 | + </Button> |
| 69 | + // Loading with colors |
| 70 | + <Typography variant=Subtitle2> {"Loading with Colors:"->React.string} </Typography> |
| 71 | + <Button id="button-loading-primary" variant=Contained color=Primary loading=True> |
| 72 | + {"Primary"->React.string} |
| 73 | + </Button> |
| 74 | + <Button id="button-loading-secondary" variant=Contained color=Secondary loading=True> |
| 75 | + {"Secondary"->React.string} |
| 76 | + </Button> |
| 77 | + <Button id="button-loading-success" variant=Contained color=Success loading=True> |
| 78 | + {"Success"->React.string} |
| 79 | + </Button> |
| 80 | + </Box> |
| 81 | + </div> |
| 82 | +} |
0 commit comments