UNPKG

@blocklet/ui-react

Version:

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

97 lines (96 loc) 2.52 kB
import { jsx as a } from "react/jsx-runtime"; import { Box as x, Typography as d } from "@mui/material"; import w from "@arcblock/ux/lib/Switch"; import { useState as y } from "react"; import { useMemoizedFn as l } from "ahooks"; import { translate as S } from "@arcblock/ux/lib/Locale/util"; import { useLocaleContext as g } from "@arcblock/ux/lib/Locale/context"; import c from "@arcblock/ux/lib/Toast"; import { getBlockletSDK as v } from "@blocklet/js-sdk"; import { translations as b } from "../libs/locales.js"; import { formatAxiosError as k } from "../libs/utils.js"; function A({ configList: n, onSave: m }) { const u = v(), [i, p] = y(n), { locale: h } = g(), s = l((r, t = {}) => S(b, r, h, "en", t)), f = l(async (r, t) => { try { const e = await u.user.saveUserPrivacyConfig({ [r]: !t }); p( i.map((o) => ({ ...o, value: e?.[o.key] ?? o.value })) ), c.success(s("saveSuccess")), m("privacy"); } catch (e) { c.error(k(e)); } }); return /* @__PURE__ */ a( x, { sx: { display: "flex", flexDirection: "column", gap: 1, alignItems: "start", ".MuiFormControlLabel-root": { gap: 1, m: 0, flexDirection: { xs: "row-reverse", md: "row" }, width: { xs: "100%", md: "unset" } }, ".MuiSwitch-track": { borderRadius: "100vw" }, ".MuiSwitch-thumb": { borderRadius: "100%" }, ".MuiSwitch-root.MuiSwitch-sizeSmall": { height: "20px", width: "36px", ".MuiSwitch-thumb": { width: "16px", height: "16px" } } }, children: i.map((r) => r.isPrivate ? null : /* @__PURE__ */ a( w, { checked: !r.value, labelProps: { label: /* @__PURE__ */ a( d, { sx: { color: "text.primary", fontSize: 14, display: "flex", flexFlow: "wrap", columnGap: 1, flex: 1 }, children: s("toPublic", { name: r.name }) } ) }, size: "small", onChange: (t) => f(r.key, t.target.checked) }, r.key )) } ); } export { A as default };