-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Showing
13 changed files
with
242 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.rcb-toast-prompt-text { | ||
padding: 6px 12px; | ||
border-radius: 5px; | ||
color: #7a7a7a; | ||
font-size: 12px; | ||
text-align: center; | ||
background-color: #fff; | ||
border: 0.5px solid #7a7a7a; | ||
cursor: pointer; | ||
transition: color 0.3s ease, border-color 0.3s ease; | ||
z-index: 9999; | ||
width: 100%; | ||
margin-top: 6px; | ||
} | ||
|
||
@keyframes popIn { | ||
0% { | ||
transform: scale(0.8); | ||
opacity: 0; | ||
} | ||
70% { | ||
transform: scale(1.1); | ||
opacity: 1; | ||
} | ||
100% { | ||
transform: scale(1); | ||
} | ||
} |
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,92 @@ | ||
import { useEffect, useState, MouseEvent } from "react"; | ||
|
||
import { useSettings } from "../../../context/SettingsContext"; | ||
import { useStyles } from "../../../context/StylesContext"; | ||
|
||
import "./ToastPrompt.css"; | ||
|
||
/** | ||
* Provides toast message prompt with information. | ||
* | ||
* @param id id of the toast | ||
* @param content content of the toast | ||
* @param removeToast removes a toast by id | ||
* @param timeout timeout in milliseconds (optional) for removing toast | ||
*/ | ||
const Toast = ({ | ||
id, | ||
content, | ||
removeToast, | ||
timeout, | ||
}: { | ||
id: string; | ||
content: string | JSX.Element; | ||
removeToast: (id: string) => void; | ||
timeout?: number; | ||
}) => { | ||
|
||
// handles settings for bot | ||
const { settings } = useSettings(); | ||
|
||
// handles styles for bot | ||
const { styles } = useStyles(); | ||
|
||
// tracks if toast prompt is hovered | ||
const [isHovered, setIsHovered] = useState<boolean>(false); | ||
|
||
// styles for toast prompt hovered | ||
const toastPromptHoveredStyle: React.CSSProperties = { | ||
color: settings.general?.primaryColor, | ||
borderColor: settings.general?.primaryColor, | ||
...styles.toastPromptHoveredStyle | ||
}; | ||
|
||
useEffect(() => { | ||
// if timeout is set, dismiss toast after specified period | ||
if (timeout) { | ||
const timer = setTimeout(() => { | ||
removeToast(id); | ||
}, timeout); | ||
return () => clearTimeout(timer); | ||
} | ||
}, [id, removeToast, timeout]); | ||
|
||
/** | ||
* Handles mouse enter event on toast prompt. | ||
*/ | ||
const handleMouseEnter = () => { | ||
setIsHovered(true); | ||
}; | ||
|
||
/** | ||
* Handles mouse leave event on toast prompt. | ||
*/ | ||
const handleMouseLeave = () => { | ||
setIsHovered(false); | ||
}; | ||
|
||
return ( | ||
typeof content === "string" ? ( | ||
<div | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
style={isHovered ? toastPromptHoveredStyle : styles.toastPromptStyle} | ||
onMouseDown={(event: MouseEvent) => { | ||
if (settings.toast?.dismissOnClick) { | ||
event.preventDefault(); | ||
removeToast(id); | ||
} | ||
}} | ||
className="rcb-toast-prompt-text" | ||
> | ||
{content} | ||
</div> | ||
) : ( | ||
<> | ||
{content} | ||
</> | ||
) | ||
); | ||
}; | ||
|
||
export default Toast; |
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.