@kwiz/fluentui
Version:
KWIZ common controls for FluentUI
17 lines • 1.2 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Link, 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 } = useToastController(toasterId);
return {
control: _jsx(Toaster, { mountNode: ctx.mountNode, toasterId: toasterId }),
dispatch: (info) => {
dispatchToast(_jsxs(Toast, { children: [info.title && _jsx(ToastTitle, { 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}`)) })] }), { intent: info.intent || "info" });
}
};
}
//# sourceMappingURL=use-toast.js.map