-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdb40c1
commit fe553b2
Showing
15 changed files
with
267 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
AlertTitle, | ||
Alert, | ||
Snackbar, | ||
Box, | ||
} from '@mui/material' | ||
|
||
import { | ||
TipMessagesProps, | ||
MsgsProps, | ||
} from '@/shared/global/context/config' | ||
|
||
interface B3TipProps extends TipMessagesProps { | ||
handleItemClose?: (id: number | string) => void, | ||
handleAllClose: () => void, | ||
} | ||
|
||
export const B3Tip = ({ | ||
autoHideDuration = 3000, | ||
handleItemClose, | ||
vertical = 'bottom', | ||
horizontal = 'right', | ||
msgs = [], | ||
handleAllClose, | ||
}: B3TipProps) => { | ||
if (!msgs || !msgs.length) return null | ||
return ( | ||
<Snackbar | ||
open={!!msgs.length} | ||
autoHideDuration={autoHideDuration} | ||
onClose={handleAllClose} | ||
anchorOrigin={{ | ||
vertical, horizontal, | ||
}} | ||
> | ||
<Box> | ||
{ | ||
msgs.length && msgs.map((msg: MsgsProps) => ( | ||
<Alert | ||
sx={{ | ||
width: '100%', | ||
'& button[title="Close"]': { | ||
display: `${handleItemClose ? 'block' : 'none'}`, | ||
}, | ||
}} | ||
key={msg.id} | ||
severity={msg.type} | ||
onClose={() => handleItemClose && handleItemClose(msg.id)} | ||
> | ||
{msg?.title && <AlertTitle>{msg.title}</AlertTitle>} | ||
{msg.msg} | ||
</Alert> | ||
)) | ||
} | ||
</Box> | ||
</Snackbar> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,7 @@ export { | |
export { | ||
B3Dialog, | ||
} from './B3Dialog' | ||
|
||
export { | ||
B3Tip, | ||
} from './B3Tip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
useContext, | ||
useEffect, | ||
} from 'react' | ||
|
||
import { | ||
GlobaledContext, | ||
} from '@/shared/global' | ||
|
||
import { | ||
B3Tip, | ||
} from '@/components' | ||
|
||
import { | ||
useMobile, | ||
} from '@/hooks' | ||
|
||
import { | ||
MsgsProps, | ||
} from '@/shared/global/context/config' | ||
|
||
const B3LayoutTip = () => { | ||
const { | ||
state: { | ||
tipMessage, | ||
}, | ||
dispatch, | ||
} = useContext(GlobaledContext) | ||
|
||
const [isMobile] = useMobile() | ||
|
||
useEffect(() => { | ||
window.tipDispatch = dispatch | ||
}, []) | ||
|
||
const setMsgs = (msgs: [] | Array<MsgsProps> = []) => { | ||
dispatch({ | ||
type: 'common', | ||
payload: { | ||
tipMessage: { | ||
...tipMessage, | ||
msgs, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const handleClose = (id: number | string) => { | ||
const msgs = tipMessage?.msgs || [] | ||
const newMsgs = msgs.filter((msg) => msg.id !== id) | ||
setMsgs(newMsgs) | ||
} | ||
|
||
const { | ||
msgs = [], | ||
autoHideDuration = 13000, | ||
vertical = `${isMobile ? 'bottom' : 'bottom'}`, | ||
horizontal = 'right', | ||
isClose = false, | ||
} = tipMessage | ||
|
||
return ( | ||
<> | ||
<B3Tip | ||
msgs={msgs} | ||
handleAllClose={setMsgs} | ||
autoHideDuration={autoHideDuration} | ||
handleItemClose={isClose ? handleClose : undefined} | ||
vertical={vertical} | ||
horizontal={horizontal} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default B3LayoutTip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/// <reference types="./shared/global/context/config.ts" | ||
declare interface CustomFieldItems { | ||
[key: string]: any | ||
} | ||
declare interface Window { | ||
tipDispatch: DispatchProps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.