@blocklet/ui-react
Version:
Some useful front-end web components that can be used in Blocklets.
67 lines (66 loc) • 1.89 kB
JavaScript
import { jsxs as C, Fragment as x, jsx as a } from "react/jsx-runtime";
import { use as b } from "react";
import w from "@arcblock/ux/lib/Button";
import { useLocaleContext as L } from "@arcblock/ux/lib/Locale/context";
import { BLOCKLET_SERVICE_PATH_PREFIX as v } from "@arcblock/ux/lib/Util/constant";
import { useMemoizedFn as e, useReactive as D } from "ahooks";
import { translate as E } from "@arcblock/ux/lib/Locale/util";
import { SessionContext as P } from "@arcblock/did-connect/lib/Session";
import m from "@arcblock/ux/lib/Toast";
import F from "./resource-dialog.js";
import { translations as R } from "../libs/locales.js";
function A({
componentDid: t,
grantedRoles: n = void 0,
onClose: u,
render: i = void 0
}) {
const { session: s } = b(P), { locale: c } = L(), r = e((p, h = {}) => E(R, p, c, "en", h)), o = D({
showDialog: !1,
loading: !1
}), d = `${v}/embed/resources/${t}/publish?mode=dialog`, f = e(() => {
o.showDialog = !1, u?.();
}), g = e(() => {
o.loading = !1;
}), l = e(() => {
if (!s.user) {
m.warning(r("needLogin"));
return;
}
if (n && n.length > 0 && !n?.includes(s.user?.role)) {
m.warning(r("noPermission"));
return;
}
o.loading = !0, o.showDialog = !0;
});
return /* @__PURE__ */ C(x, { children: [
i ? i({ onClick: l, loading: o.loading }) : /* @__PURE__ */ a(
w,
{
variant: "outlined",
color: "secondary",
type: "button",
className: "submit",
loading: o.loading,
onClick: l,
sx: { mr: 1, ml: 1 },
children: r("exportResource")
},
"button"
),
o.showDialog && /* @__PURE__ */ a(
F,
{
src: d,
open: !0,
onClose: f,
onLoad: g,
componentDid: t,
loading: o.loading
}
)
] });
}
export {
A as default
};