@keycloakify/keycloak-account-ui
Version:
<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a
27 lines • 1.5 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Alert, AlertActionCloseButton, AlertGroup, AlertVariant, } from "@patternfly/react-core";
import { createContext, useContext, useState } from "react";
export const AlertContext = createContext(undefined);
export const useAlerts = () => useContext(AlertContext);
export const AlertProvider = ({ children }) => {
const [alerts, setAlerts] = useState([]);
const hideAlert = (id) => {
setAlerts((alerts) => alerts.filter((alert) => alert.id !== id));
};
const addAlert = (message, variant = AlertVariant.success, description) => {
setAlerts([
{
id: Math.random() * 100,
message,
variant,
description,
},
...alerts,
]);
};
const addError = (message) => {
addAlert(message, AlertVariant.danger);
};
return (_jsxs(AlertContext.Provider, { value: { addAlert, addError }, children: [_jsx(AlertGroup, { isToast: true, "data-testid": "alerts", children: alerts.map(({ id, variant, message, description }) => (_jsx(Alert, { isLiveRegion: true, variant: AlertVariant[variant], variantLabel: "", title: message, actionClose: _jsx(AlertActionCloseButton, { title: message, onClose: () => hideAlert(id) }), timeout: true, onTimeout: () => hideAlert(id), children: description && _jsx("p", { children: description }) }, id))) }), children] }));
};
//# sourceMappingURL=Alerts.js.map