-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add
notification
component
- Loading branch information
Showing
58 changed files
with
1,821 additions
and
695 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
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
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,84 @@ | ||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
import { useAsync } from '../../hooks'; | ||
|
||
export interface DAlertDialogProps extends React.HTMLAttributes<HTMLDivElement> { | ||
dHidden: boolean; | ||
dDuration: number; | ||
dDialogRef?: React.LegacyRef<HTMLDivElement>; | ||
onClose?: () => void; | ||
} | ||
|
||
export function DAlertDialog(props: DAlertDialogProps) { | ||
const { dHidden, dDuration, dDialogRef, onClose, children, onKeyDown, onMouseEnter, onMouseLeave, ...restProps } = props; | ||
|
||
const dataRef = useRef<{ clearTid: (() => void) | null }>({ | ||
clearTid: null, | ||
}); | ||
|
||
const asyncCapture = useAsync(); | ||
|
||
const handleKeyDown = useCallback<React.KeyboardEventHandler<HTMLDivElement>>( | ||
(e) => { | ||
onKeyDown?.(e); | ||
|
||
if (e.code === 'Escape') { | ||
dataRef.current.clearTid && dataRef.current.clearTid(); | ||
onClose?.(); | ||
} | ||
}, | ||
[onClose, onKeyDown] | ||
); | ||
|
||
const handleMouseEnter = useCallback<React.MouseEventHandler<HTMLDivElement>>( | ||
(e) => { | ||
onMouseEnter?.(e); | ||
|
||
dataRef.current.clearTid && dataRef.current.clearTid(); | ||
}, | ||
[onMouseEnter] | ||
); | ||
|
||
const handleMouseLeave = useCallback<React.MouseEventHandler<HTMLDivElement>>( | ||
(e) => { | ||
onMouseLeave?.(e); | ||
|
||
if (dDuration > 0) { | ||
dataRef.current.clearTid && dataRef.current.clearTid(); | ||
dataRef.current.clearTid = asyncCapture.setTimeout(() => { | ||
onClose?.(); | ||
}, dDuration * 1000); | ||
} | ||
}, | ||
[asyncCapture, dDuration, onClose, onMouseLeave] | ||
); | ||
|
||
useEffect(() => { | ||
if (dDuration > 0) { | ||
dataRef.current.clearTid && dataRef.current.clearTid(); | ||
dataRef.current.clearTid = asyncCapture.setTimeout(() => { | ||
onClose?.(); | ||
}, dDuration * 1000); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
<> | ||
{!dHidden && ( | ||
<div | ||
{...restProps} | ||
ref={dDialogRef} | ||
role="alertdialog" | ||
aria-modal="true" | ||
onKeyDown={handleKeyDown} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
{children} | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
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 @@ | ||
export * from './AlertDialog'; |
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.