@arcblock/ux 3.0.25 → 3.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CodeBlock/index.js +70 -67
- package/lib/Config/config-provider.d.ts +1 -1
- package/lib/Config/config-provider.js +22 -20
- package/lib/NFTDisplay/preview.d.ts +11 -0
- package/lib/NFTDisplay/preview.js +60 -0
- package/lib/NavMenu/style.js +1 -1
- package/lib/RelativeTime/index.d.ts +2 -1
- package/lib/RelativeTime/index.js +88 -88
- package/lib/Tag/index.js +12 -12
- package/lib/Theme/theme-provider.d.ts +4 -2
- package/lib/Theme/theme-provider.js +83 -79
- package/package.json +7 -7
- package/src/CodeBlock/index.tsx +7 -4
- package/src/Config/config-provider.tsx +3 -1
- package/src/NFTDisplay/preview.tsx +84 -0
- package/src/NavMenu/style.ts +1 -1
- package/src/RelativeTime/index.tsx +43 -29
- package/src/Tag/index.jsx +1 -1
- package/src/Theme/Theme.stories.jsx +1 -0
- package/src/Theme/theme-provider.tsx +19 -12
package/lib/Tag/index.js
CHANGED
@@ -5,7 +5,7 @@ import n from "lodash/isUndefined";
|
|
5
5
|
import { mergeProps as x } from "../Util/index.js";
|
6
6
|
import e from "../Colors/themes/default.js";
|
7
7
|
import { styled as w } from "../Theme/index.js";
|
8
|
-
const
|
8
|
+
const c = {
|
9
9
|
error: {
|
10
10
|
color: e.common.white,
|
11
11
|
backgroundColor: e.error.main
|
@@ -27,18 +27,18 @@ const i = {
|
|
27
27
|
backgroundColor: "#222"
|
28
28
|
}
|
29
29
|
};
|
30
|
-
function
|
31
|
-
const o = Object.assign({},
|
30
|
+
function p({ ...s }) {
|
31
|
+
const o = Object.assign({}, s);
|
32
32
|
n(o.type) && (o.type = "primary"), n(o.content) && (o.content = ""), n(o.style) && (o.style = {}), n(o.className) && (o.className = "");
|
33
|
-
const
|
34
|
-
return
|
35
|
-
color:
|
36
|
-
backgroundColor:
|
37
|
-
}), /* @__PURE__ */ h(j, { component: "span", className: g, style:
|
33
|
+
const m = x(o, p, ["style"]), { type: t, content: l, children: y, style: f, className: g, ...d } = m, { palette: i } = b(), a = Object.assign({}, c[t] || c.primary, f);
|
34
|
+
return i[t] && Object.assign(a, {
|
35
|
+
color: i[t].contrastText || e.common.white,
|
36
|
+
backgroundColor: i[t].main
|
37
|
+
}), /* @__PURE__ */ h(j, { component: "span", className: g, style: a, ...d, children: l || y });
|
38
38
|
}
|
39
|
-
|
39
|
+
p.propTypes = {
|
40
40
|
children: r.any.isRequired,
|
41
|
-
type: r.oneOf(Object.keys(
|
41
|
+
type: r.oneOf(Object.keys(c)),
|
42
42
|
content: r.string,
|
43
43
|
className: r.string,
|
44
44
|
style: r.oneOfType([r.object, r.string])
|
@@ -53,9 +53,9 @@ const j = w(u)`
|
|
53
53
|
line-height: 20px;
|
54
54
|
font-size: 12px;
|
55
55
|
font-weight: 500;
|
56
|
-
border-radius:
|
56
|
+
border-radius: ${({ theme: s }) => s.shape.borderRadius * 0.5}px;
|
57
57
|
}
|
58
58
|
`;
|
59
59
|
export {
|
60
|
-
|
60
|
+
p as default
|
61
61
|
};
|
@@ -6,18 +6,20 @@ export interface ColorSchemeContextType {
|
|
6
6
|
changeMode: (mode: PaletteMode) => void;
|
7
7
|
prefer?: Prefer;
|
8
8
|
}
|
9
|
-
export declare const ColorSchemeContext: import('react').Context<ColorSchemeContextType>;
|
10
|
-
export declare function useColorScheme(): ColorSchemeContextType;
|
11
9
|
export type UxTheme = ThemeOptions | ((parentTheme: Theme, context?: {
|
12
10
|
mode: PaletteMode;
|
13
11
|
}) => Theme);
|
14
12
|
export type Prefer = 'light' | 'dark' | 'system';
|
13
|
+
export declare const ColorSchemeContext: import('react').Context<ColorSchemeContextType>;
|
14
|
+
export declare function useColorScheme(): ColorSchemeContextType;
|
15
15
|
interface BaseThemeProviderProps {
|
16
16
|
children?: React.ReactNode;
|
17
17
|
theme?: UxTheme;
|
18
18
|
injectFirst?: boolean;
|
19
19
|
/** 指定一个类名,DarkSchemeStyles 只会作用于带有该类的元素及其后代 */
|
20
20
|
darkSchemeClass?: string;
|
21
|
+
/** 禁用样式缓存 */
|
22
|
+
disableStyleCache?: boolean;
|
21
23
|
}
|
22
24
|
interface ColorSchemeProviderProps extends BaseThemeProviderProps {
|
23
25
|
prefer?: Prefer;
|
@@ -1,50 +1,53 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { createContext as
|
3
|
-
import { useTheme as
|
4
|
-
import { deepmerge as
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import { useDebounceFn as
|
8
|
-
import { getBlockletThemeOptions as
|
9
|
-
import { useLocationState as
|
10
|
-
import { createTheme as
|
11
|
-
const
|
12
|
-
function
|
13
|
-
return
|
1
|
+
import { jsx as a, jsxs as K } from "react/jsx-runtime";
|
2
|
+
import { createContext as O, use as V, useState as $, useRef as W, useMemo as g, useCallback as y, useEffect as f } from "react";
|
3
|
+
import { useTheme as A, CssBaseline as B, StyledEngineProvider as q, ThemeProvider as z, GlobalStyles as Y } from "@mui/material";
|
4
|
+
import { deepmerge as J } from "@mui/utils";
|
5
|
+
import M from "lodash/set";
|
6
|
+
import Q from "lodash/isUndefined";
|
7
|
+
import { useDebounceFn as X, useCreation as P } from "ahooks";
|
8
|
+
import { getBlockletThemeOptions as Z, BLOCKLET_THEME_PREFER_KEY as h, isValidThemeMode as ee, getDefaultThemePrefer as _ } from "@blocklet/theme";
|
9
|
+
import { useLocationState as te } from "../hooks/use-location-state.js";
|
10
|
+
import { createTheme as T, lazyCreateDefaultTheme as re, isUxTheme as oe, isTheme as ne } from "./theme.js";
|
11
|
+
const se = T(), N = O({});
|
12
|
+
function U() {
|
13
|
+
return V(N);
|
14
14
|
}
|
15
|
-
const
|
16
|
-
function
|
17
|
-
const
|
18
|
-
if (
|
19
|
-
const n = "transparent", s =
|
20
|
-
return /* @__PURE__ */
|
21
|
-
|
15
|
+
const D = (i) => i ? i === "system" ? _({ theme: { prefer: "system" } }) : i : _();
|
16
|
+
function L({ className: i = void 0 }) {
|
17
|
+
const r = A();
|
18
|
+
if (r.palette.mode === "dark") {
|
19
|
+
const n = "transparent", s = r.palette.grey[300], t = (i || "").trim().split(/\s+/).filter(Boolean).map((m) => m.startsWith(".") ? m : `.${m}`).join(" "), d = t ? `${t}::-webkit-scrollbar, ${t} *::-webkit-scrollbar` : "*::-webkit-scrollbar", o = t ? `${t}::-webkit-scrollbar-track, ${t} *::-webkit-scrollbar-track` : "*::-webkit-scrollbar-track", c = t ? `${t}::-webkit-scrollbar-thumb, ${t} *::-webkit-scrollbar-thumb` : "*::-webkit-scrollbar-thumb", u = t ? `${t}::-webkit-scrollbar-corner, ${t} *::-webkit-scrollbar-corner` : "*::-webkit-scrollbar-corner", k = t ? `${t}, ${t} *` : "*";
|
20
|
+
return /* @__PURE__ */ a(
|
21
|
+
Y,
|
22
22
|
{
|
23
23
|
styles: {
|
24
24
|
// Chrome, Safari, Edge
|
25
25
|
"@supports selector(::-webkit-scrollbar)": {
|
26
|
-
[
|
26
|
+
[d]: {
|
27
27
|
width: "12px",
|
28
28
|
height: "12px"
|
29
29
|
},
|
30
|
-
[
|
30
|
+
[o]: {
|
31
31
|
background: n
|
32
32
|
},
|
33
|
-
[
|
33
|
+
[c]: {
|
34
34
|
background: s,
|
35
35
|
borderRadius: "6px",
|
36
36
|
border: "2px solid",
|
37
37
|
borderColor: n,
|
38
38
|
backgroundClip: "padding-box",
|
39
39
|
"&:hover": {
|
40
|
-
background:
|
40
|
+
background: r.palette.grey[400],
|
41
41
|
backgroundClip: "padding-box"
|
42
42
|
}
|
43
|
+
},
|
44
|
+
[u]: {
|
45
|
+
background: n
|
43
46
|
}
|
44
47
|
},
|
45
48
|
// Firefox
|
46
49
|
"@supports not selector(::-webkit-scrollbar)": {
|
47
|
-
[
|
50
|
+
[k]: {
|
48
51
|
scrollbarWidth: "auto",
|
49
52
|
scrollbarColor: `${s} ${n}`
|
50
53
|
}
|
@@ -55,101 +58,102 @@ function se({ className: i = void 0 }) {
|
|
55
58
|
}
|
56
59
|
return null;
|
57
60
|
}
|
58
|
-
let
|
59
|
-
const
|
60
|
-
function
|
61
|
+
let R = !1;
|
62
|
+
const j = {};
|
63
|
+
function F({
|
61
64
|
children: i = null,
|
62
|
-
theme:
|
65
|
+
theme: r = se,
|
63
66
|
injectFirst: n = !0,
|
64
|
-
darkSchemeClass: s = ""
|
67
|
+
darkSchemeClass: s = "",
|
68
|
+
disableStyleCache: t = !1
|
65
69
|
}) {
|
66
|
-
const
|
70
|
+
const d = g(() => typeof r == "function" || ne(r) ? r : T(r), [r]), o = P(() => t ? /* @__PURE__ */ a(B, {}) : R ? null : (R = !0, /* @__PURE__ */ a(B, {})), [t]), c = P(() => t ? /* @__PURE__ */ a(L, { className: s }) : j[s] ? null : (j[s] = !0, /* @__PURE__ */ a(L, { className: s })), [s, t]);
|
67
71
|
return (
|
68
72
|
// injectFirst 会影响 makeStyles 自定义样式和 mui styles 覆盖问题
|
69
|
-
/* @__PURE__ */
|
70
|
-
|
71
|
-
|
73
|
+
/* @__PURE__ */ a(q, { injectFirst: n, children: /* @__PURE__ */ K(z, { theme: d, children: [
|
74
|
+
o,
|
75
|
+
c,
|
72
76
|
i
|
73
77
|
] }) })
|
74
78
|
);
|
75
79
|
}
|
76
80
|
function le({
|
77
81
|
children: i = null,
|
78
|
-
theme:
|
82
|
+
theme: r = void 0,
|
79
83
|
prefer: n = void 0,
|
80
84
|
disableBlockletTheme: s = !1,
|
81
|
-
...
|
85
|
+
...t
|
82
86
|
}) {
|
83
|
-
const
|
87
|
+
const d = U(), [o, c] = $(() => D(n)), [u, k] = $(null), m = A(), p = te(), b = W(null), C = Q(d.toggleMode), { run: S } = X(
|
84
88
|
(e) => {
|
85
|
-
|
89
|
+
k(e);
|
86
90
|
},
|
87
91
|
{
|
88
92
|
wait: 200
|
89
93
|
}
|
90
94
|
), v = g(() => {
|
91
95
|
let e = {};
|
92
|
-
if (
|
93
|
-
const
|
94
|
-
if (typeof
|
95
|
-
const
|
96
|
-
oe(
|
96
|
+
if (r) {
|
97
|
+
const H = re(o);
|
98
|
+
if (typeof r == "function") {
|
99
|
+
const I = H();
|
100
|
+
oe(m) ? e = { ...r(m, { mode: o }) } : e = { ...r(I, { mode: o }) };
|
97
101
|
} else
|
98
|
-
e = { ...
|
102
|
+
e = { ...r };
|
99
103
|
}
|
100
|
-
let l =
|
101
|
-
return
|
102
|
-
}, [
|
103
|
-
const e =
|
104
|
-
|
105
|
-
}, [
|
104
|
+
let l = o;
|
105
|
+
return u && (l = u.mode || "light", e = J(e, Z(l, u))), M(e, "palette.mode", l), M(e, "mode", l), e;
|
106
|
+
}, [o, r, m, u]), w = g(() => T({ ...v, disableBlockletTheme: !!u || s }), [v, s, u]), E = y(() => {
|
107
|
+
const e = o === "light" ? "dark" : "light";
|
108
|
+
c(e), sessionStorage.removeItem(h), localStorage.setItem(h, e);
|
109
|
+
}, [o, c]), x = y(
|
106
110
|
(e) => {
|
107
|
-
|
111
|
+
o !== e && (c(e), sessionStorage.removeItem(h), localStorage.setItem(h, e));
|
108
112
|
},
|
109
|
-
[
|
110
|
-
),
|
113
|
+
[o, c]
|
114
|
+
), G = g(
|
111
115
|
() => ({
|
112
|
-
mode:
|
116
|
+
mode: o,
|
113
117
|
toggleMode: E,
|
114
|
-
changeMode:
|
118
|
+
changeMode: x,
|
115
119
|
prefer: n
|
116
120
|
}),
|
117
|
-
[
|
121
|
+
[o, n, E, x]
|
118
122
|
);
|
119
|
-
return
|
120
|
-
|
121
|
-
}, [n,
|
122
|
-
const e = new URLSearchParams(
|
123
|
-
|
124
|
-
}, [
|
125
|
-
|
126
|
-
const e =
|
127
|
-
if (
|
128
|
-
|
123
|
+
return f(() => {
|
124
|
+
c(D(n));
|
125
|
+
}, [n, c, p.search]), f(() => {
|
126
|
+
const e = new URLSearchParams(p.search).get("theme");
|
127
|
+
ee(e) && sessionStorage.setItem(h, e);
|
128
|
+
}, [p.search]), f(() => {
|
129
|
+
b.current || (b.current = document.querySelector('meta[name="theme-color"]'));
|
130
|
+
const e = w.palette.background.default;
|
131
|
+
if (b.current)
|
132
|
+
b.current.setAttribute("content", e);
|
129
133
|
else {
|
130
134
|
const l = document.createElement("meta");
|
131
|
-
l.name = "theme-color", l.content = e, document.head.appendChild(l),
|
135
|
+
l.name = "theme-color", l.content = e, document.head.appendChild(l), b.current = l;
|
132
136
|
}
|
133
|
-
}, [
|
137
|
+
}, [w.palette.background.default]), f(() => {
|
134
138
|
const e = (l) => {
|
135
|
-
l.origin === window.origin && l.data.type === "THEME_BUILDER_CONFIG_CHANGED" &&
|
139
|
+
l.origin === window.origin && l.data.type === "THEME_BUILDER_CONFIG_CHANGED" && S(l.data.payload);
|
136
140
|
};
|
137
141
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
138
|
-
}, [
|
139
|
-
|
140
|
-
}, [
|
142
|
+
}, [S]), f(() => {
|
143
|
+
C && (o === "dark" ? document.documentElement.setAttribute("data-theme", "dark") : document.documentElement.removeAttribute("data-theme"));
|
144
|
+
}, [C, o]), /* @__PURE__ */ a(N, { value: G, children: /* @__PURE__ */ a(F, { theme: w, ...t, children: i }) });
|
141
145
|
}
|
142
|
-
function
|
146
|
+
function ke({
|
143
147
|
children: i = null,
|
144
|
-
prefer:
|
148
|
+
prefer: r = void 0,
|
145
149
|
enableColorScheme: n = !1,
|
146
150
|
...s
|
147
151
|
}) {
|
148
|
-
const { toggleMode:
|
149
|
-
return n ||
|
152
|
+
const { toggleMode: t } = U();
|
153
|
+
return n || r || !t ? /* @__PURE__ */ a(le, { prefer: r, ...s, children: i }) : /* @__PURE__ */ a(F, { ...s, children: i });
|
150
154
|
}
|
151
155
|
export {
|
152
|
-
|
153
|
-
|
154
|
-
|
156
|
+
N as ColorSchemeContext,
|
157
|
+
ke as default,
|
158
|
+
U as useColorScheme
|
155
159
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.27",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -60,16 +60,16 @@
|
|
60
60
|
"react": "^19.0.0",
|
61
61
|
"react-router-dom": "^6.22.3"
|
62
62
|
},
|
63
|
-
"gitHead": "
|
63
|
+
"gitHead": "b1e137e0c74f4b58af16b1d75a65166b163cf65d",
|
64
64
|
"dependencies": {
|
65
|
-
"@arcblock/bridge": "3.0.
|
65
|
+
"@arcblock/bridge": "3.0.27",
|
66
66
|
"@arcblock/did": "^1.20.15",
|
67
67
|
"@arcblock/did-motif": "^1.1.14",
|
68
|
-
"@arcblock/icons": "3.0.
|
69
|
-
"@arcblock/nft-display": "3.0.
|
70
|
-
"@arcblock/react-hooks": "3.0.
|
68
|
+
"@arcblock/icons": "3.0.27",
|
69
|
+
"@arcblock/nft-display": "3.0.27",
|
70
|
+
"@arcblock/react-hooks": "3.0.27",
|
71
71
|
"@blocklet/js-sdk": "^1.16.46",
|
72
|
-
"@blocklet/theme": "3.0.
|
72
|
+
"@blocklet/theme": "3.0.27",
|
73
73
|
"@fontsource/roboto": "~5.1.1",
|
74
74
|
"@fontsource/ubuntu-mono": "^5.2.6",
|
75
75
|
"@iconify-icons/logos": "^1.2.36",
|
package/src/CodeBlock/index.tsx
CHANGED
@@ -120,7 +120,9 @@ export default function CodeBlock({
|
|
120
120
|
}
|
121
121
|
|
122
122
|
const fontFamily = 'source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace !important';
|
123
|
-
const Pre = styled('pre'
|
123
|
+
const Pre = styled('pre', {
|
124
|
+
shouldForwardProp: (prop) => prop !== 'sx',
|
125
|
+
})`
|
124
126
|
font-family: ${fontFamily};
|
125
127
|
display: block;
|
126
128
|
font-size: 14px;
|
@@ -130,9 +132,10 @@ const Pre = styled('pre')`
|
|
130
132
|
word-wrap: break-word;
|
131
133
|
text-align: left;
|
132
134
|
border-radius: 5px;
|
133
|
-
border: 1px solid
|
134
|
-
|
135
|
-
|
135
|
+
border: 1px solid;
|
136
|
+
border-color: ${({ theme }) => theme.palette.divider};
|
137
|
+
background: ${({ theme }) => theme.palette.background.default};
|
138
|
+
color: ${({ theme }) => theme.palette.common.white};
|
136
139
|
position: relative;
|
137
140
|
|
138
141
|
.codeblock__inner {
|
@@ -20,6 +20,7 @@ export function ConfigProvider({
|
|
20
20
|
prefer,
|
21
21
|
disableBlockletTheme = false,
|
22
22
|
enableColorScheme,
|
23
|
+
disableStyleCache,
|
23
24
|
// locale provider
|
24
25
|
locale,
|
25
26
|
fallbackLocale,
|
@@ -34,7 +35,8 @@ export function ConfigProvider({
|
|
34
35
|
darkSchemeClass={darkSchemeClass}
|
35
36
|
prefer={prefer}
|
36
37
|
disableBlockletTheme={disableBlockletTheme}
|
37
|
-
enableColorScheme={enableColorScheme}
|
38
|
+
enableColorScheme={enableColorScheme}
|
39
|
+
disableStyleCache={disableStyleCache}>
|
38
40
|
<LocaleProvider
|
39
41
|
locale={locale}
|
40
42
|
fallbackLocale={fallbackLocale}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import Modal from '@mui/material/Modal';
|
2
|
+
import styled from '@emotion/styled';
|
3
|
+
import NFTDisplay, { getNFTData } from '.';
|
4
|
+
|
5
|
+
export interface NftInfo {
|
6
|
+
address: string;
|
7
|
+
data: Record<string, any>;
|
8
|
+
display: Record<string, any>;
|
9
|
+
issuer: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export default function NftPreview({
|
13
|
+
visible,
|
14
|
+
onClose,
|
15
|
+
nft,
|
16
|
+
}: {
|
17
|
+
visible: boolean;
|
18
|
+
onClose: () => void;
|
19
|
+
nft: NftInfo | null;
|
20
|
+
}) {
|
21
|
+
if (!visible || !nft) {
|
22
|
+
return null;
|
23
|
+
}
|
24
|
+
|
25
|
+
return (
|
26
|
+
<NftPreviewRoot>
|
27
|
+
{/* Preview Modal */}
|
28
|
+
<Modal open={visible} onClose={onClose}>
|
29
|
+
<ModalRoot onClick={onClose}>
|
30
|
+
<NFTDisplay data={getNFTData(nft)} address={nft.address} inset />
|
31
|
+
</ModalRoot>
|
32
|
+
</Modal>
|
33
|
+
</NftPreviewRoot>
|
34
|
+
);
|
35
|
+
}
|
36
|
+
|
37
|
+
const NftPreviewRoot = styled.div`
|
38
|
+
position: relative;
|
39
|
+
width: 100%;
|
40
|
+
height: 100%;
|
41
|
+
cursor: pointer;
|
42
|
+
|
43
|
+
&:hover {
|
44
|
+
.mask {
|
45
|
+
opacity: 1;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
.mask {
|
50
|
+
position: absolute;
|
51
|
+
top: 0;
|
52
|
+
left: 0;
|
53
|
+
display: flex;
|
54
|
+
align-items: center;
|
55
|
+
justify-content: center;
|
56
|
+
width: 100%;
|
57
|
+
height: 100%;
|
58
|
+
background: rgba(0, 0, 0, 0.6);
|
59
|
+
opacity: 0;
|
60
|
+
transition: opacity 0.2s;
|
61
|
+
}
|
62
|
+
`;
|
63
|
+
|
64
|
+
const ModalRoot = styled.div`
|
65
|
+
display: flex;
|
66
|
+
justify-content: center;
|
67
|
+
align-items: center;
|
68
|
+
height: 100vh;
|
69
|
+
width: 100vw;
|
70
|
+
|
71
|
+
img,
|
72
|
+
object {
|
73
|
+
max-width: 90vw;
|
74
|
+
max-height: 75vh;
|
75
|
+
}
|
76
|
+
|
77
|
+
.nft-display--inset {
|
78
|
+
> .MuiBox-root,
|
79
|
+
.nft-display__loading {
|
80
|
+
width: 75vmin;
|
81
|
+
height: 75vmin;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
`;
|
package/src/NavMenu/style.ts
CHANGED
@@ -141,7 +141,7 @@ export const NavMenuItem = styled('li', {
|
|
141
141
|
'.navmenu-item__desc': {
|
142
142
|
fontSize: '12px',
|
143
143
|
lineHeight: 1,
|
144
|
-
color: theme.palette.
|
144
|
+
color: theme.palette.text.secondary,
|
145
145
|
},
|
146
146
|
'&:hover': {
|
147
147
|
background: theme.palette.action.hover,
|
@@ -73,6 +73,7 @@ export interface RelativeTimeProps {
|
|
73
73
|
placement?: TooltipProps['placement'];
|
74
74
|
sx?: SxProps;
|
75
75
|
format?: string;
|
76
|
+
mode?: 'all' | 'daysLeft'; // all: 显示所有内容,daysLeft: 只显示剩余天数
|
76
77
|
}
|
77
78
|
|
78
79
|
function useRelativeTime({
|
@@ -194,7 +195,6 @@ function UTCChip({
|
|
194
195
|
color: 'inherit',
|
195
196
|
cursor: 'pointer',
|
196
197
|
border: '1px solid',
|
197
|
-
fontSize: '0.8rem',
|
198
198
|
borderColor: 'divider',
|
199
199
|
borderRadius: '20px',
|
200
200
|
padding: '4px 8px',
|
@@ -220,6 +220,7 @@ export default function RelativeTime({
|
|
220
220
|
disableTimezone = false,
|
221
221
|
placement = 'top-end',
|
222
222
|
format = 'lll',
|
223
|
+
mode = 'all',
|
223
224
|
...rest
|
224
225
|
}: RelativeTimeProps) {
|
225
226
|
const { innerContent, popContent, isUtc, setIsUtc, relativeString } = useRelativeTime({
|
@@ -234,41 +235,54 @@ export default function RelativeTime({
|
|
234
235
|
format,
|
235
236
|
});
|
236
237
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
238
|
+
const allContent = (
|
239
|
+
<Box
|
240
|
+
{...rest}
|
241
|
+
sx={[
|
242
|
+
{
|
243
|
+
display: 'inline-flex',
|
244
|
+
alignItems: 'center',
|
245
|
+
gap: 0.5,
|
246
|
+
},
|
247
|
+
...(Array.isArray(rest.sx) ? rest.sx : [rest.sx]),
|
248
|
+
]}>
|
249
|
+
<Box component="span" {...rest} sx={{}}>
|
250
|
+
{innerContent}
|
251
|
+
</Box>
|
252
|
+
|
253
|
+
<Box component="span" sx={{ color: 'inherit' }}>
|
254
|
+
·
|
255
|
+
</Box>
|
256
|
+
|
257
|
+
<Box component="span" sx={{ color: 'inherit' }}>
|
258
|
+
{relativeString}
|
259
|
+
</Box>
|
253
260
|
|
261
|
+
{!disableTimezone && (
|
262
|
+
<>
|
254
263
|
<Box component="span" sx={{ color: 'inherit' }}>
|
255
264
|
·
|
256
265
|
</Box>
|
257
266
|
|
258
|
-
<
|
259
|
-
|
260
|
-
|
267
|
+
<UTCChip locale={locale} isUtc={isUtc} setIsUtc={setIsUtc} useShortTimezone={useShortTimezone} />
|
268
|
+
</>
|
269
|
+
)}
|
270
|
+
</Box>
|
271
|
+
);
|
261
272
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
273
|
+
// 优先通过 mode 来决定显示什么内容
|
274
|
+
if (mode === 'daysLeft') {
|
275
|
+
return (
|
276
|
+
<Tooltip title={allContent} placement={placement} enterTouchDelay={0}>
|
277
|
+
<Box component="span">{relativeString}</Box>
|
278
|
+
</Tooltip>
|
279
|
+
);
|
280
|
+
}
|
267
281
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
282
|
+
if (type === 'all' && mode === 'all') {
|
283
|
+
return (
|
284
|
+
<Tooltip title={undefined} placement={placement} enterTouchDelay={0}>
|
285
|
+
{allContent}
|
272
286
|
</Tooltip>
|
273
287
|
);
|
274
288
|
}
|
package/src/Tag/index.jsx
CHANGED
@@ -4,6 +4,7 @@ export { default as Shadows } from './demo/shadows';
|
|
4
4
|
export { default as WithCustomKey } from './demo/with-custom-key';
|
5
5
|
export { default as CustomFonts } from './demo/custom-fonts';
|
6
6
|
export { default as UrlTheme } from './demo/url-theme';
|
7
|
+
export { default as CodeBlock } from './demo/code-block';
|
7
8
|
|
8
9
|
export default {
|
9
10
|
title: 'Theme/Theme',
|