Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bkunyun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bkunyun
Commits
754128e9
Commit
754128e9
authored
Aug 05, 2022
by
chenshouchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 修改提示信息默认显示时间
parent
cd3761aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
129 deletions
+126
-129
MySnackbarProvider.tsx
src/components/MySnackbar/MySnackbarProvider.tsx
+126
-129
No files found.
src/components/MySnackbar/MySnackbarProvider.tsx
View file @
754128e9
...
...
@@ -5,152 +5,149 @@ import snackbarContext from "./snackbarContext";
import
{
ThemeProvider
,
createTheme
}
from
"@mui/material/styles"
;
type
MySnackbarProviderProp
=
{
vertical
?:
"bottom"
|
"top"
;
horizontal
?:
"center"
|
"left"
|
"right"
;
autoHideDuration
?:
number
;
snackerClasses
?:
object
;
ClickAwayListenerProps
?:
object
;
ContentProps
?:
object
;
disableWindowBlurListener
?:
boolean
;
resumeHideDuration
?:
number
;
snackbarSx
?:
object
;
transition
?:
"grow"
|
"fade"
;
transitionDuration
?:
number
;
TransitionProps
?:
object
;
alertClasses
?:
object
;
closeText
?:
string
;
variant
?:
"filled"
|
"outlined"
|
"standard"
;
errorIcon
?:
ReactNode
;
infoIcon
?:
ReactNode
;
successIcon
?:
ReactNode
;
warningIcon
?:
ReactNode
;
elevation
?:
number
;
alertSx
?:
object
;
children
?:
ReactNode
;
vertical
?:
"bottom"
|
"top"
;
horizontal
?:
"center"
|
"left"
|
"right"
;
autoHideDuration
?:
number
;
snackerClasses
?:
object
;
ClickAwayListenerProps
?:
object
;
ContentProps
?:
object
;
disableWindowBlurListener
?:
boolean
;
resumeHideDuration
?:
number
;
snackbarSx
?:
object
;
transition
?:
"grow"
|
"fade"
;
transitionDuration
?:
number
;
TransitionProps
?:
object
;
alertClasses
?:
object
;
closeText
?:
string
;
variant
?:
"filled"
|
"outlined"
|
"standard"
;
errorIcon
?:
ReactNode
;
infoIcon
?:
ReactNode
;
successIcon
?:
ReactNode
;
warningIcon
?:
ReactNode
;
elevation
?:
number
;
alertSx
?:
object
;
children
?:
ReactNode
;
};
const
getTransitionComponent
=
(
transition
:
"grow"
|
"fade"
)
=>
{
switch
(
transition
)
{
case
"grow"
:
return
Grow
;
case
"fade"
:
return
Fade
;
default
:
return
Grow
;
}
switch
(
transition
)
{
case
"grow"
:
return
Grow
;
case
"fade"
:
return
Fade
;
default
:
return
Grow
;
}
};
const
MySnackbarProvider
=
({
vertical
=
"top"
,
horizontal
=
"center"
,
autoHideDuration
=
890
000
,
snackerClasses
,
ClickAwayListenerProps
,
ContentProps
,
disableWindowBlurListener
=
true
,
resumeHideDuration
,
snackbarSx
,
transition
=
"grow"
,
transitionDuration
,
TransitionProps
=
{},
alertClasses
,
closeText
=
"Close"
,
variant
=
"standard"
,
errorIcon
,
infoIcon
,
successIcon
,
warningIcon
,
elevation
=
3
,
alertSx
,
children
,
vertical
=
"top"
,
horizontal
=
"center"
,
autoHideDuration
=
3
000
,
snackerClasses
,
ClickAwayListenerProps
,
ContentProps
,
disableWindowBlurListener
=
true
,
resumeHideDuration
,
snackbarSx
,
transition
=
"grow"
,
transitionDuration
,
TransitionProps
=
{},
alertClasses
,
closeText
=
"Close"
,
variant
=
"standard"
,
errorIcon
,
infoIcon
,
successIcon
,
warningIcon
,
elevation
=
3
,
alertSx
,
children
,
}:
MySnackbarProviderProp
)
=>
{
const
{
open
,
messageInfo
,
handleExited
,
success
,
error
,
warning
,
info
,
close
,
}
=
useMySnackbar
();
// .MuiAlert-filledInfo
const
{
open
,
messageInfo
,
handleExited
,
success
,
error
,
warning
,
info
,
close
,
}
=
useMySnackbar
();
// .MuiAlert-filledInfo
const
getColorStyle
=
useMemo
(()
=>
{
if
(
messageInfo
.
severity
===
'success'
)
{
return
'#02AB83'
}
if
(
messageInfo
.
severity
===
'info'
)
{
return
'#1370FF'
}
if
(
messageInfo
.
severity
===
'warning'
)
{
return
'#FFB919'
}
if
(
messageInfo
.
severity
===
'error'
)
{
return
'#FF4E4E'
}
},[
messageInfo
.
severity
])
const
getColorStyle
=
useMemo
(()
=>
{
if
(
messageInfo
.
severity
===
"success"
)
{
return
"#02AB83"
;
}
if
(
messageInfo
.
severity
===
"info"
)
{
return
"#1370FF"
;
}
if
(
messageInfo
.
severity
===
"warning"
)
{
return
"#FFB919"
;
}
if
(
messageInfo
.
severity
===
"error"
)
{
return
"#FF4E4E"
;
}
},
[
messageInfo
.
severity
]);
const
theme
=
createTheme
({
const
theme
=
createTheme
({
components
:
{
MuiAlert
:
{
styleOverrides
:
{
root
:
{
color
:
getColorStyle
,
"& .MuiAlert-icon"
:
{
color
:
getColorStyle
},
}
root
:
{
color
:
getColorStyle
,
"& .MuiAlert-icon"
:
{
color
:
getColorStyle
,
},
},
},
},
},
});
return
(
<
Fragment
>
<
ThemeProvider
theme=
{
theme
}
>
<
Snackbar
open=
{
open
}
autoHideDuration=
{
autoHideDuration
}
onClose=
{
close
}
anchorOrigin=
{
{
vertical
:
vertical
,
horizontal
:
horizontal
}
}
classes=
{
snackerClasses
}
ClickAwayListenerProps=
{
ClickAwayListenerProps
}
ContentProps=
{
ContentProps
}
disableWindowBlurListener=
{
disableWindowBlurListener
}
resumeHideDuration=
{
resumeHideDuration
}
sx=
{
snackbarSx
}
TransitionComponent=
{
getTransitionComponent
(
transition
)
}
transitionDuration=
{
transitionDuration
}
TransitionProps=
{
{
onExited
:
handleExited
,
...
TransitionProps
}
}
>
<
Alert
id=
"Alert"
classes=
{
alertClasses
}
closeText=
{
closeText
}
iconMapping=
{
{
error
:
errorIcon
,
info
:
infoIcon
,
success
:
successIcon
,
warning
:
warningIcon
,
}
}
severity=
{
messageInfo
?.
severity
}
variant=
{
variant
}
elevation=
{
elevation
}
sx=
{
{
boxShadow
:
"unset"
,
...
alertSx
}
}
>
{
messageInfo
?.
content
}
</
Alert
>
</
Snackbar
>
</
ThemeProvider
>
<
snackbarContext
.
Provider
value=
{
{
success
,
error
,
warning
,
info
}
}
>
{
children
}
</
snackbarContext
.
Provider
>
</
Fragment
>
);
return
(
<
Fragment
>
<
ThemeProvider
theme=
{
theme
}
>
<
Snackbar
open=
{
open
}
autoHideDuration=
{
autoHideDuration
}
onClose=
{
close
}
anchorOrigin=
{
{
vertical
:
vertical
,
horizontal
:
horizontal
}
}
classes=
{
snackerClasses
}
ClickAwayListenerProps=
{
ClickAwayListenerProps
}
ContentProps=
{
ContentProps
}
disableWindowBlurListener=
{
disableWindowBlurListener
}
resumeHideDuration=
{
resumeHideDuration
}
sx=
{
snackbarSx
}
TransitionComponent=
{
getTransitionComponent
(
transition
)
}
transitionDuration=
{
transitionDuration
}
TransitionProps=
{
{
onExited
:
handleExited
,
...
TransitionProps
}
}
>
<
Alert
id=
"Alert"
classes=
{
alertClasses
}
closeText=
{
closeText
}
iconMapping=
{
{
error
:
errorIcon
,
info
:
infoIcon
,
success
:
successIcon
,
warning
:
warningIcon
,
}
}
severity=
{
messageInfo
?.
severity
}
variant=
{
variant
}
elevation=
{
elevation
}
sx=
{
{
boxShadow
:
"unset"
,
...
alertSx
}
}
>
{
messageInfo
?.
content
}
</
Alert
>
</
Snackbar
>
</
ThemeProvider
>
<
snackbarContext
.
Provider
value=
{
{
success
,
error
,
warning
,
info
}
}
>
{
children
}
</
snackbarContext
.
Provider
>
</
Fragment
>
);
};
export
default
MySnackbarProvider
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment