UNPKG

@blocklet/ui-react

Version:

Some useful front-end web components that can be used in Blocklets.

86 lines (85 loc) 2.65 kB
import { jsx as s } from "react/jsx-runtime"; import { useMemo as d } from "react"; import F from "prop-types"; import { styled as x, useTheme as T, deepmerge as B, ThemeProvider as L } 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 j from "@arcblock/ux/lib/hooks/use-blocklet-logo"; import C from "lodash/omit"; import E from "./internal-footer.js"; import { mapRecursive as I } from "../utils.js"; import { formatBlockletInfo as P, getLocalizedNavigation as l } from "../blocklets.js"; import { BlockletMetaProps as z } from "../types.js"; import D from "../libs/with-hide-when-embed.js"; function f({ meta: o = {}, theme: t = {}, ...c }) { const { locale: i, defaultLocale: a } = N() || {}, m = T(), r = d(() => { const e = Object.assign({}, window.blocklet, o); try { return P(e); } catch ($) { return console.error("Failed to format blocklet info", $, e), e; } }, [o]), p = d(() => B(m, t), [m, t]), b = j({ key: "xs", // 始终优先长 logo meta: o, theme: t }); if (!r.appName) return null; const { appName: g, appDescription: k, description: u, copyright: h } = r, v = p.palette.background.default, n = { footerNav: l({ navigation: r?.navigation?.footer, locale: i, defaultLocale: a, section: "footer" }) || [], socialMedia: l({ navigation: r?.navigation?.social, locale: i, defaultLocale: a, section: "footer" }) || [], links: l({ navigation: r?.navigation?.bottom, locale: i, defaultLocale: a, section: "footer" }) || [] }, y = { brand: { name: g, description: k || u, logo: b }, navigation: I( n.footerNav, (e) => ({ ...e, label: e.title, link: e.link }), "items" ), copyright: h, socialMedia: n.socialMedia, links: n.links.map((e) => ({ ...e, label: e.title })) }; return /* @__PURE__ */ s(L, { theme: p, children: /* @__PURE__ */ s(H, { ...y, ...C(c, ["bordered"]), $bordered: c?.bordered, $bgcolor: v }) }); } f.propTypes = { meta: z, // 允许覆盖 footer 内置的 theme theme: F.object }; const H = x(E)` ${({ $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};`} `, _ = M(D(f), { FallbackComponent: w }); export { _ as default };