@kwiz/fluentui
Version:
KWIZ common controls for FluentUI
26 lines • 1.77 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Link, Spinner, Toast, ToastBody, Toaster, ToastFooter, ToastTitle, useId, useToastController } from "@fluentui/react-components";
import { isNotEmptyArray } from "@kwiz/common";
import { useKWIZFluentContext } from "./context-internal";
export function useToast() {
const ctx = useKWIZFluentContext();
const toasterId = useId("toaster");
const { dispatchToast, dismissToast, dismissAllToasts, updateToast } = useToastController(toasterId);
return {
control: _jsx(Toaster, { mountNode: ctx.mountNode, toasterId: toasterId }),
dispatch: (info) => {
dispatchToast(_jsxs(Toast, { appearance: info.inverted ? "inverted" : undefined, children: [info.title && _jsx(ToastTitle, { media: info.media
? info.media
: info.intent === "progress"
? _jsx(Spinner, { size: "tiny" })
: undefined, action: info.titleAction ? _jsx(Link, { onClick: info.titleAction.onClick, children: info.titleAction.text }) : undefined, children: info.title }), info.body && _jsx(ToastBody, { subtitle: info.subtitle, children: info.body }), isNotEmptyArray(info.footerActions) &&
_jsx(ToastFooter, { children: info.footerActions.map((a, i) => _jsx(Link, { onClick: a.onClick, children: a.text }, `l${i}`)) })] }), Object.assign(Object.assign({}, (info || {})), { intent: info.intent === "progress"
? "info"
: info.intent || "info" }));
},
dismiss: dismissToast,
dismissAll: dismissAllToasts,
update: info => updateToast(info)
};
}
//# sourceMappingURL=use-toast.js.map