@blocklet/ui-react
Version:
Some useful front-end web components that can be used in Blocklets.
49 lines (48 loc) • 1.79 kB
JavaScript
import { jsx as a } from "react/jsx-runtime";
import f from "dayjs";
import l from "dayjs/plugin/relativeTime";
import s from "dayjs/plugin/localizedFormat";
import "dayjs/locale/zh";
import "dayjs/locale/zh-tw";
import "dayjs/locale/ja";
import { useLocaleContext as c } from "@arcblock/ux/lib/Locale/context";
import { AppBadgeDefault as m } from "./badges/app-badge-default.js";
import { AppBadgeSwitch as d } from "./badges/app-badge-switch.js";
import { AppBadgeVersion as p } from "./badges/app-badge-version.js";
import { AppBadgeState as u } from "./badges/app-badge-state.js";
import { AppBadgeDID as v } from "./badges/app-badge-did.js";
f.extend(l);
f.extend(s);
const g = (e, i = 0) => {
if (typeof e != "number") return "";
const r = Math.abs(e);
let t, o = "";
return r >= 1e12 ? (o = "T", t = `${(e / 1e12).toFixed(i)}`) : r >= 1e9 ? (o = "B", t = `${(e / 1e9).toFixed(i)}`) : r >= 1e6 ? (o = "M", t = `${(e / 1e6).toFixed(i)}`) : r >= 1e3 ? (o = "K", t = `${(e / 1e3).toFixed(i)}`) : t = e.toString(), i > 0 && (t = t.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "")), `${t}${o}`;
}, x = (e, i = "en") => e ? f(e).locale(i).fromNow() : "", B = {
switch: d,
version: p,
state: u,
did: v
};
function V(e) {
const { locale: i = "en" } = c() || {};
if (e.variant === "number") {
const { value: r, round: t = 0, ...o } = e, n = g(Number(r), t);
return /* @__PURE__ */ a(m, { value: n, ...o });
}
if (e.variant === "time") {
const { value: r, ...t } = e, o = x(r, i);
return /* @__PURE__ */ a(m, { value: o, ...t });
}
if (e.variant) {
const r = B[e.variant];
if (r)
return /* @__PURE__ */ a(r, { ...e });
}
return /* @__PURE__ */ a(m, { ...e });
}
export {
V as default,
g as formatNumber,
x as formatTime
};