@yuku123/z-oss-frontend-component 0.1.0

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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @yuku123/z-oss-frontend-component
2
+
3
+ > ��抽自 z-opc 对应 _frontend)
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @yuku123/z-oss-frontend-component
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```jsx
14
+ import { FileSizeFormatter } from '@yuku123/z-oss-frontend-component'
15
+
16
+ <FileSizeFormatter prop="value"/>
17
+ ```
18
+
19
+ ## 仓库
20
+
21
+ https://github.com/yuku123/z-opc-frontend/tree/main/packages/z-oss-frontend-component
22
+
23
+ ## License
24
+
25
+ MIT
@@ -0,0 +1,295 @@
1
+ import re from "react";
2
+ import { Tag as te } from "antd";
3
+ var v = { exports: {} }, _ = {};
4
+ /**
5
+ * @license React
6
+ * react-jsx-runtime.production.js
7
+ *
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ var $;
14
+ function ne() {
15
+ if ($) return _;
16
+ $ = 1;
17
+ var s = Symbol.for("react.transitional.element"), c = Symbol.for("react.fragment");
18
+ function u(i, a, l) {
19
+ var d = null;
20
+ if (l !== void 0 && (d = "" + l), a.key !== void 0 && (d = "" + a.key), "key" in a) {
21
+ l = {};
22
+ for (var m in a)
23
+ m !== "key" && (l[m] = a[m]);
24
+ } else l = a;
25
+ return a = l.ref, {
26
+ $$typeof: s,
27
+ type: i,
28
+ key: d,
29
+ ref: a !== void 0 ? a : null,
30
+ props: l
31
+ };
32
+ }
33
+ return _.Fragment = c, _.jsx = u, _.jsxs = u, _;
34
+ }
35
+ var E = {};
36
+ /**
37
+ * @license React
38
+ * react-jsx-runtime.development.js
39
+ *
40
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
41
+ *
42
+ * This source code is licensed under the MIT license found in the
43
+ * LICENSE file in the root directory of this source tree.
44
+ */
45
+ var F;
46
+ function oe() {
47
+ return F || (F = 1, process.env.NODE_ENV !== "production" && (function() {
48
+ function s(e) {
49
+ if (e == null) return null;
50
+ if (typeof e == "function")
51
+ return e.$$typeof === Q ? null : e.displayName || e.name || null;
52
+ if (typeof e == "string") return e;
53
+ switch (e) {
54
+ case b:
55
+ return "Fragment";
56
+ case B:
57
+ return "Profiler";
58
+ case U:
59
+ return "StrictMode";
60
+ case G:
61
+ return "Suspense";
62
+ case X:
63
+ return "SuspenseList";
64
+ case Z:
65
+ return "Activity";
66
+ }
67
+ if (typeof e == "object")
68
+ switch (typeof e.tag == "number" && console.error(
69
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
70
+ ), e.$$typeof) {
71
+ case z:
72
+ return "Portal";
73
+ case J:
74
+ return e.displayName || "Context";
75
+ case q:
76
+ return (e._context.displayName || "Context") + ".Consumer";
77
+ case V:
78
+ var r = e.render;
79
+ return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
80
+ case H:
81
+ return r = e.displayName || null, r !== null ? r : s(e.type) || "Memo";
82
+ case T:
83
+ r = e._payload, e = e._init;
84
+ try {
85
+ return s(e(r));
86
+ } catch {
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ function c(e) {
92
+ return "" + e;
93
+ }
94
+ function u(e) {
95
+ try {
96
+ c(e);
97
+ var r = !1;
98
+ } catch {
99
+ r = !0;
100
+ }
101
+ if (r) {
102
+ r = console;
103
+ var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
+ return t.call(
105
+ r,
106
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
107
+ n
108
+ ), c(e);
109
+ }
110
+ }
111
+ function i(e) {
112
+ if (e === b) return "<>";
113
+ if (typeof e == "object" && e !== null && e.$$typeof === T)
114
+ return "<...>";
115
+ try {
116
+ var r = s(e);
117
+ return r ? "<" + r + ">" : "<...>";
118
+ } catch {
119
+ return "<...>";
120
+ }
121
+ }
122
+ function a() {
123
+ var e = k.A;
124
+ return e === null ? null : e.getOwner();
125
+ }
126
+ function l() {
127
+ return Error("react-stack-top-frame");
128
+ }
129
+ function d(e) {
130
+ if (w.call(e, "key")) {
131
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
132
+ if (r && r.isReactWarning) return !1;
133
+ }
134
+ return e.key !== void 0;
135
+ }
136
+ function m(e, r) {
137
+ function t() {
138
+ j || (j = !0, console.error(
139
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
140
+ r
141
+ ));
142
+ }
143
+ t.isReactWarning = !0, Object.defineProperty(e, "key", {
144
+ get: t,
145
+ configurable: !0
146
+ });
147
+ }
148
+ function L() {
149
+ var e = s(this.type);
150
+ return y[e] || (y[e] = !0, console.error(
151
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
152
+ )), e = this.props.ref, e !== void 0 ? e : null;
153
+ }
154
+ function W(e, r, t, n, p, S) {
155
+ var o = t.ref;
156
+ return e = {
157
+ $$typeof: x,
158
+ type: e,
159
+ key: r,
160
+ props: t,
161
+ _owner: n
162
+ }, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
163
+ enumerable: !1,
164
+ get: L
165
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
166
+ configurable: !1,
167
+ enumerable: !1,
168
+ writable: !0,
169
+ value: 0
170
+ }), Object.defineProperty(e, "_debugInfo", {
171
+ configurable: !1,
172
+ enumerable: !1,
173
+ writable: !0,
174
+ value: null
175
+ }), Object.defineProperty(e, "_debugStack", {
176
+ configurable: !1,
177
+ enumerable: !1,
178
+ writable: !0,
179
+ value: p
180
+ }), Object.defineProperty(e, "_debugTask", {
181
+ configurable: !1,
182
+ enumerable: !1,
183
+ writable: !0,
184
+ value: S
185
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
186
+ }
187
+ function P(e, r, t, n, p, S) {
188
+ var o = r.children;
189
+ if (o !== void 0)
190
+ if (n)
191
+ if (K(o)) {
192
+ for (n = 0; n < o.length; n++)
193
+ g(o[n]);
194
+ Object.freeze && Object.freeze(o);
195
+ } else
196
+ console.error(
197
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
198
+ );
199
+ else g(o);
200
+ if (w.call(r, "key")) {
201
+ o = s(e);
202
+ var f = Object.keys(r).filter(function(ee) {
203
+ return ee !== "key";
204
+ });
205
+ n = 0 < f.length ? "{key: someKey, " + f.join(": ..., ") + ": ...}" : "{key: someKey}", Y[o + n] || (f = 0 < f.length ? "{" + f.join(": ..., ") + ": ...}" : "{}", console.error(
206
+ `A props object containing a "key" prop is being spread into JSX:
207
+ let props = %s;
208
+ <%s {...props} />
209
+ React keys must be passed directly to JSX without using spread:
210
+ let props = %s;
211
+ <%s key={someKey} {...props} />`,
212
+ n,
213
+ o,
214
+ f,
215
+ o
216
+ ), Y[o + n] = !0);
217
+ }
218
+ if (o = null, t !== void 0 && (u(t), o = "" + t), d(r) && (u(r.key), o = "" + r.key), "key" in r) {
219
+ t = {};
220
+ for (var A in r)
221
+ A !== "key" && (t[A] = r[A]);
222
+ } else t = r;
223
+ return o && m(
224
+ t,
225
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
226
+ ), W(
227
+ e,
228
+ o,
229
+ t,
230
+ a(),
231
+ p,
232
+ S
233
+ );
234
+ }
235
+ function g(e) {
236
+ h(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === T && (e._payload.status === "fulfilled" ? h(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
237
+ }
238
+ function h(e) {
239
+ return typeof e == "object" && e !== null && e.$$typeof === x;
240
+ }
241
+ var R = re, x = Symbol.for("react.transitional.element"), z = Symbol.for("react.portal"), b = Symbol.for("react.fragment"), U = Symbol.for("react.strict_mode"), B = Symbol.for("react.profiler"), q = Symbol.for("react.consumer"), J = Symbol.for("react.context"), V = Symbol.for("react.forward_ref"), G = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), k = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, w = Object.prototype.hasOwnProperty, K = Array.isArray, O = console.createTask ? console.createTask : function() {
242
+ return null;
243
+ };
244
+ R = {
245
+ react_stack_bottom_frame: function(e) {
246
+ return e();
247
+ }
248
+ };
249
+ var j, y = {}, N = R.react_stack_bottom_frame.bind(
250
+ R,
251
+ l
252
+ )(), C = O(i(l)), Y = {};
253
+ E.Fragment = b, E.jsx = function(e, r, t) {
254
+ var n = 1e4 > k.recentlyCreatedOwnerStacks++;
255
+ return P(
256
+ e,
257
+ r,
258
+ t,
259
+ !1,
260
+ n ? Error("react-stack-top-frame") : N,
261
+ n ? O(i(e)) : C
262
+ );
263
+ }, E.jsxs = function(e, r, t) {
264
+ var n = 1e4 > k.recentlyCreatedOwnerStacks++;
265
+ return P(
266
+ e,
267
+ r,
268
+ t,
269
+ !0,
270
+ n ? Error("react-stack-top-frame") : N,
271
+ n ? O(i(e)) : C
272
+ );
273
+ };
274
+ })()), E;
275
+ }
276
+ var M;
277
+ function ae() {
278
+ return M || (M = 1, process.env.NODE_ENV === "production" ? v.exports = ne() : v.exports = oe()), v.exports;
279
+ }
280
+ var I = ae();
281
+ function D(s, c = 2) {
282
+ if (!s || s === 0) return "0 B";
283
+ const u = 1024, i = ["B", "KB", "MB", "GB", "TB", "PB"], a = Math.floor(Math.log(s) / Math.log(u));
284
+ return `${parseFloat((s / Math.pow(u, a)).toFixed(c))} ${i[a]}`;
285
+ }
286
+ function ue({ bytes: s, decimals: c = 2, colored: u = !0 }) {
287
+ if (!u) return /* @__PURE__ */ I.jsx("span", { children: D(s, c) });
288
+ const a = s / 1024 / 1024;
289
+ let l = "blue";
290
+ return a >= 100 ? l = "red" : a >= 10 ? l = "orange" : a >= 1 && (l = "gold"), /* @__PURE__ */ I.jsx(te, { color: l, children: D(s, c) });
291
+ }
292
+ export {
293
+ ue as FileSizeFormatter,
294
+ D as formatSize
295
+ };
@@ -0,0 +1,22 @@
1
+ (function(i,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("antd")):typeof define=="function"&&define.amd?define(["exports","react","antd"],m):(i=typeof globalThis<"u"?globalThis:i||self,m(i.z_oss_frontend_component={},i.React,i.antd))})(this,(function(i,m,W){"use strict";var v={exports:{}},_={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var j;function U(){if(j)return _;j=1;var s=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function l(f,a,u){var p=null;if(u!==void 0&&(p=""+u),a.key!==void 0&&(p=""+a.key),"key"in a){u={};for(var R in a)R!=="key"&&(u[R]=a[R])}else u=a;return a=u.ref,{$$typeof:s,type:f,key:p,ref:a!==void 0?a:null,props:u}}return _.Fragment=c,_.jsx=l,_.jsxs=l,_}var E={};/**
10
+ * @license React
11
+ * react-jsx-runtime.development.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var x;function q(){return x||(x=1,process.env.NODE_ENV!=="production"&&(function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ae?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case Z:return"Profiler";case H:return"StrictMode";case re:return"Suspense";case te:return"SuspenseList";case oe:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case X:return"Portal";case K:return e.displayName||"Context";case Q:return(e._context.displayName||"Context")+".Consumer";case ee:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ne:return r=e.displayName||null,r!==null?r:s(e.type)||"Memo";case O:r=e._payload,e=e._init;try{return s(e(r))}catch{}}return null}function c(e){return""+e}function l(e){try{c(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),c(e)}}function f(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===O)return"<...>";try{var r=s(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=h.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function p(e){if(M.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function R(e,r){function t(){$||($=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function V(){var e=s(this.type);return I[e]||(I[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function G(e,r,t,n,T,P){var o=t.ref;return e={$$typeof:Y,type:e,key:r,props:t,_owner:n},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:V}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:T}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:P}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function N(e,r,t,n,T,P){var o=r.children;if(o!==void 0)if(n)if(se(o)){for(n=0;n<o.length;n++)C(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else C(o);if(M.call(r,"key")){o=s(e);var d=Object.keys(r).filter(function(ue){return ue!=="key"});n=0<d.length?"{key: someKey, "+d.join(": ..., ")+": ...}":"{key: someKey}",L[o+n]||(d=0<d.length?"{"+d.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
+ let props = %s;
19
+ <%s {...props} />
20
+ React keys must be passed directly to JSX without using spread:
21
+ let props = %s;
22
+ <%s key={someKey} {...props} />`,n,o,d,o),L[o+n]=!0)}if(o=null,t!==void 0&&(l(t),o=""+t),p(r)&&(l(r.key),o=""+r.key),"key"in r){t={};for(var g in r)g!=="key"&&(t[g]=r[g])}else t=r;return o&&R(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),G(e,o,t,a(),T,P)}function C(e){F(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===O&&(e._payload.status==="fulfilled"?F(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function F(e){return typeof e=="object"&&e!==null&&e.$$typeof===Y}var b=m,Y=Symbol.for("react.transitional.element"),X=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),H=Symbol.for("react.strict_mode"),Z=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ee=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),te=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),oe=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),h=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,se=Array.isArray,A=console.createTask?console.createTask:function(){return null};b={react_stack_bottom_frame:function(e){return e()}};var $,I={},z=b.react_stack_bottom_frame.bind(b,u)(),D=A(f(u)),L={};E.Fragment=S,E.jsx=function(e,r,t){var n=1e4>h.recentlyCreatedOwnerStacks++;return N(e,r,t,!1,n?Error("react-stack-top-frame"):z,n?A(f(e)):D)},E.jsxs=function(e,r,t){var n=1e4>h.recentlyCreatedOwnerStacks++;return N(e,r,t,!0,n?Error("react-stack-top-frame"):z,n?A(f(e)):D)}})()),E}var w;function B(){return w||(w=1,process.env.NODE_ENV==="production"?v.exports=U():v.exports=q()),v.exports}var y=B();function k(s,c=2){if(!s||s===0)return"0 B";const l=1024,f=["B","KB","MB","GB","TB","PB"],a=Math.floor(Math.log(s)/Math.log(l));return`${parseFloat((s/Math.pow(l,a)).toFixed(c))} ${f[a]}`}function J({bytes:s,decimals:c=2,colored:l=!0}){if(!l)return y.jsx("span",{children:k(s,c)});const a=s/1024/1024;let u="blue";return a>=100?u="red":a>=10?u="orange":a>=1&&(u="gold"),y.jsx(W.Tag,{color:u,children:k(s,c)})}i.FileSizeFormatter=J,i.formatSize=k,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@yuku123/z-oss-frontend-component",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "z-oss 模块共享前端组件(抽自 z-opc/z-oss/_frontend)",
6
+ "keywords": ["react", "antd", "oss", "z-opc"],
7
+ "license": "MIT",
8
+ "author": { "name": "zifang", "email": "1340947819@qq.com" },
9
+ "homepage": "https://github.com/yuku123/z-opc-frontend/tree/main/packages/z-oss-frontend-component#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/yuku123/z-opc-frontend.git",
13
+ "directory": "packages/z-oss-frontend-component"
14
+ },
15
+ "bugs": { "url": "https://github.com/yuku123/z-opc-frontend/issues" },
16
+ "main": "./dist/z-oss-frontend-component.umd.js",
17
+ "module": "./dist/z-oss-frontend-component.es.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/z-oss-frontend-component.es.js",
22
+ "require": "./dist/z-oss-frontend-component.umd.js"
23
+ }
24
+ },
25
+ "files": ["dist", "src", "README.md"],
26
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
27
+ "scripts": {
28
+ "dev": "vite --port 3091",
29
+ "build": "vite build",
30
+ "preview": "vite preview"
31
+ },
32
+ "peerDependencies": {
33
+ "react": "^19.2.0",
34
+ "react-dom": "^19.2.0",
35
+ "antd": "^6.3.3"
36
+ },
37
+ "devDependencies": {
38
+ "@vitejs/plugin-react": "^4.2.1",
39
+ "vite": "^6.2.0"
40
+ }
41
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react'
2
+ import {Tag} from 'antd'
3
+
4
+ /**
5
+ * 文件大小格式化(B / KB / MB / GB / TB)
6
+ * <p>
7
+ * 抽自 z-oss/_frontend/src/pages/ObjectList.jsx
8
+ *
9
+ * @param {number} bytes
10
+ * @param {number} decimals - 保留小数位(默认 2)
11
+ */
12
+ function formatSize(bytes, decimals = 2) {
13
+ if (!bytes || bytes === 0) return '0 B'
14
+ const k = 1024
15
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
16
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
17
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`
18
+ }
19
+
20
+ export default function FileSizeFormatter({bytes, decimals = 2, colored = true}) {
21
+ if (!colored) return <span>{formatSize(bytes, decimals)}</span>
22
+
23
+ const kb = bytes / 1024
24
+ const mb = kb / 1024
25
+ let color = 'blue'
26
+ if (mb >= 100) color = 'red'
27
+ else if (mb >= 10) color = 'orange'
28
+ else if (mb >= 1) color = 'gold'
29
+
30
+ return <Tag color={color}>{formatSize(bytes, decimals)}</Tag>
31
+ }
32
+
33
+ // 命名导出:纯函数版本(不依赖 antd)
34
+ export {formatSize}
package/src/dev.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom/client'
3
+ import FileSizeFormatter from './FileSizeFormatter'
4
+
5
+ const root = ReactDOM.createRoot(document.getElementById('root'))
6
+ root.render(
7
+ <div style={{padding: 40, display: 'flex', flexDirection: 'column', gap: 8}}>
8
+ <FileSizeFormatter bytes={512}/>
9
+ <FileSizeFormatter bytes={1024 * 50}/>
10
+ <FileSizeFormatter bytes={1024 * 1024 * 5}/>
11
+ <FileSizeFormatter bytes={1024 * 1024 * 50}/>
12
+ <FileSizeFormatter bytes={1024 * 1024 * 1024 * 2}/>
13
+ </div>
14
+ )
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export {default as FileSizeFormatter, formatSize} from './FileSizeFormatter'