@blocklet/ui-react
Version:
Some useful front-end web components that can be used in Blocklets.
71 lines (70 loc) • 2.37 kB
JavaScript
import { jsx as p } from "react/jsx-runtime";
import { useMemo as s } from "react";
import $ from "prop-types";
import { styled as F, useTheme as x, deepmerge as T, ThemeProvider as B } from "@arcblock/ux/lib/Theme";
import { withErrorBoundary as M } from "react-error-boundary";
import { useLocaleContext as N } from "@arcblock/ux/lib/Locale/context";
import { ErrorFallback as w } from "@arcblock/ux/lib/ErrorBoundary";
import L from "@arcblock/ux/lib/hooks/use-blocklet-logo";
import j from "lodash/omit";
import C from "./internal-footer.js";
import { mapRecursive as E } from "../utils.js";
import { formatBlockletInfo as I, getLocalizedNavigation as a } from "../blocklets.js";
import { BlockletMetaProps as P } from "../types.js";
import z from "../libs/with-hide-when-embed.js";
function d({ meta: o = {}, theme: t = null, ...n }) {
const { locale: l } = N() || {}, c = x(), r = s(() => {
const e = Object.assign({}, window.blocklet, o);
try {
return I(e);
} catch (v) {
return console.error("Failed to format blocklet info", v, e), e;
}
}, [o]), m = s(() => T(c, t), [c, t]), f = L({
key: "xs",
// 始终优先长 logo
meta: o,
theme: t
});
if (!r.appName)
return null;
const { appName: b, appDescription: k, description: u, copyright: g } = r, h = m.palette.background.default, i = {
footerNav: a(r?.navigation?.footer, l) || [],
socialMedia: a(r?.navigation?.social, l) || [],
links: a(r?.navigation?.bottom, l) || []
}, y = {
brand: {
name: b,
description: k || u,
logo: f
},
navigation: E(
i.footerNav,
(e) => ({
...e,
label: e.title,
link: e.link
}),
"items"
),
copyright: g,
socialMedia: i.socialMedia,
links: i.links.map((e) => ({ ...e, label: e.title }))
};
return /* @__PURE__ */ p(B, { theme: m, children: /* @__PURE__ */ p(D, { ...y, ...j(n, ["bordered"]), $bordered: n?.bordered, $bgcolor: h }) });
}
d.propTypes = {
meta: P,
// 允许覆盖 footer 内置的 theme
theme: $.object
};
const D = F(C)`
${({ $bordered: o, theme: t }) => `border-top: 1px solid ${o && t.palette.divider};`}
color: ${({ theme: o }) => o.palette.text.secondary};
${({ $bgcolor: o }) => o && `background-color: ${o};`}
`, Z = M(z(d), {
FallbackComponent: w
});
export {
Z as default
};