mirror of
https://ghproxy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-07-22 12:27:13 +08:00
* APP-2894 One Migration flow: Move Accessibillity to One * Added mixpanel events for one_migration_popup_displayed and one_migration_button_clicked actions
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { useState, createContext, useContext } from '@wordpress/element';
|
|
|
|
const NotificationsContext = createContext(undefined);
|
|
|
|
export function useNotificationSettings() {
|
|
return useContext(NotificationsContext);
|
|
}
|
|
|
|
export const NotificationsProvider = ({ children }) => {
|
|
const [showNotification, setShowNotification] = useState(false);
|
|
const [notificationMessage, setNotificationMessage] = useState('');
|
|
const [notificationType, setNotificationType] = useState('');
|
|
|
|
return (
|
|
<NotificationsContext.Provider
|
|
value={{
|
|
showNotification,
|
|
setShowNotification,
|
|
notificationMessage,
|
|
setNotificationMessage,
|
|
notificationType,
|
|
setNotificationType,
|
|
}}
|
|
>
|
|
{children}
|
|
</NotificationsContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useToastNotification = () => {
|
|
const { setNotificationMessage, setNotificationType, setShowNotification } =
|
|
useContext(NotificationsContext);
|
|
|
|
const error = (message) => {
|
|
setNotificationMessage(message);
|
|
setNotificationType('error');
|
|
setShowNotification(true);
|
|
};
|
|
|
|
const success = (message) => {
|
|
setNotificationMessage(message);
|
|
setNotificationType('success');
|
|
setShowNotification(true);
|
|
};
|
|
|
|
const hint = (message) => {
|
|
setNotificationMessage(message);
|
|
setNotificationType('hint');
|
|
setShowNotification(true);
|
|
};
|
|
|
|
return {
|
|
success,
|
|
error,
|
|
hint,
|
|
};
|
|
};
|