@taicode/common-web 3.7.7 → 3.7.10
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/output/components/alert-dialog.d.ts +20 -0
- package/output/components/alert-dialog.d.ts.map +1 -0
- package/output/components/alert-dialog.js +65 -0
- package/output/components/alert.d.ts +11 -0
- package/output/components/alert.d.ts.map +1 -0
- package/output/components/alert.js +38 -0
- package/output/components/avatar.d.ts +13 -0
- package/output/components/avatar.d.ts.map +1 -0
- package/output/components/avatar.js +40 -0
- package/output/components/badge.d.ts +11 -0
- package/output/components/badge.d.ts.map +1 -0
- package/output/components/badge.js +39 -0
- package/output/components/button.d.ts +12 -0
- package/output/components/button.d.ts.map +1 -0
- package/output/components/button.js +48 -0
- package/output/components/calendar.d.ts +13 -0
- package/output/components/calendar.d.ts.map +1 -0
- package/output/components/calendar.js +57 -0
- package/output/components/card.d.ts +13 -0
- package/output/components/card.d.ts.map +1 -0
- package/output/components/card.js +43 -0
- package/output/components/chart.d.ts +56 -0
- package/output/components/chart.d.ts.map +1 -0
- package/output/components/chart.js +127 -0
- package/output/components/checkbox.d.ts +5 -0
- package/output/components/checkbox.d.ts.map +1 -0
- package/output/components/checkbox.js +21 -0
- package/output/components/command.d.ts +20 -0
- package/output/components/command.d.ts.map +1 -0
- package/output/components/command.js +55 -0
- package/output/components/dialog.d.ts +20 -0
- package/output/components/dialog.d.ts.map +1 -0
- package/output/components/dialog.js +58 -0
- package/output/components/direction.d.ts +9 -0
- package/output/components/direction.d.ts.map +1 -0
- package/output/components/direction.js +10 -0
- package/output/components/drawer.d.ts +14 -0
- package/output/components/drawer.d.ts.map +1 -0
- package/output/components/drawer.js +56 -0
- package/output/components/dropdown-menu.d.ts +29 -0
- package/output/components/dropdown-menu.d.ts.map +1 -0
- package/output/components/dropdown-menu.js +78 -0
- package/output/components/field.d.ts +39 -0
- package/output/components/field.d.ts.map +1 -0
- package/output/components/field.js +102 -0
- package/output/components/footer/index.d.ts +27 -0
- package/output/components/footer/index.d.ts.map +1 -0
- package/output/components/footer/index.js +17 -0
- package/output/components/form.d.ts +26 -0
- package/output/components/form.d.ts.map +1 -0
- package/output/components/form.js +69 -0
- package/output/components/index.d.ts +46 -0
- package/output/components/index.d.ts.map +1 -0
- package/output/components/index.js +45 -0
- package/output/components/input-group.d.ts +17 -0
- package/output/components/input-group.d.ts.map +1 -0
- package/output/components/input-group.js +75 -0
- package/output/components/input.d.ts +4 -0
- package/output/components/input.d.ts.map +1 -0
- package/output/components/input.js +19 -0
- package/output/components/item.d.ts +25 -0
- package/output/components/item.d.ts.map +1 -0
- package/output/components/item.js +89 -0
- package/output/components/json-view/index.d.ts +11 -0
- package/output/components/json-view/index.d.ts.map +1 -0
- package/output/components/json-view/index.js +52 -0
- package/output/components/json-view/lazy/index.d.ts +18 -0
- package/output/components/json-view/lazy/index.d.ts.map +1 -0
- package/output/components/json-view/lazy/index.js +22 -0
- package/output/components/kbd.d.ts +4 -0
- package/output/components/kbd.d.ts.map +1 -0
- package/output/components/kbd.js +22 -0
- package/output/components/label.d.ts +5 -0
- package/output/components/label.d.ts.map +1 -0
- package/output/components/label.js +20 -0
- package/output/components/list-actions/index.d.ts +23 -0
- package/output/components/list-actions/index.d.ts.map +1 -0
- package/output/components/list-actions/index.js +15 -0
- package/output/components/loading-button/index.d.ts +44 -0
- package/output/components/loading-button/index.d.ts.map +1 -0
- package/output/components/loading-button/index.js +75 -0
- package/output/components/loading-button/index.test.d.ts +2 -0
- package/output/components/loading-button/index.test.d.ts.map +1 -0
- package/output/components/loading-button/index.test.js +203 -0
- package/output/components/native-select.d.ts +9 -0
- package/output/components/native-select.d.ts.map +1 -0
- package/output/components/native-select.js +28 -0
- package/output/components/page-back-button/index.d.ts +8 -0
- package/output/components/page-back-button/index.d.ts.map +1 -0
- package/output/components/page-back-button/index.js +7 -0
- package/output/components/page-state.d.ts +19 -0
- package/output/components/page-state.d.ts.map +1 -0
- package/output/components/page-state.js +13 -0
- package/output/components/pagination/index.d.ts +34 -0
- package/output/components/pagination/index.d.ts.map +1 -0
- package/output/components/pagination/index.js +75 -0
- package/output/components/popover.d.ts +11 -0
- package/output/components/popover.d.ts.map +1 -0
- package/output/components/popover.js +44 -0
- package/output/components/progress.d.ts +5 -0
- package/output/components/progress.d.ts.map +1 -0
- package/output/components/progress.js +21 -0
- package/output/components/radio-group.d.ts +6 -0
- package/output/components/radio-group.d.ts.map +1 -0
- package/output/components/radio-group.js +25 -0
- package/output/components/route-pending-indicator/index.d.ts +20 -0
- package/output/components/route-pending-indicator/index.d.ts.map +1 -0
- package/output/components/route-pending-indicator/index.js +17 -0
- package/output/components/scroll-area.d.ts +6 -0
- package/output/components/scroll-area.d.ts.map +1 -0
- package/output/components/scroll-area.js +24 -0
- package/output/components/searchable-select/index.d.ts +41 -0
- package/output/components/searchable-select/index.d.ts.map +1 -0
- package/output/components/searchable-select/index.js +46 -0
- package/output/components/select.d.ts +17 -0
- package/output/components/select.d.ts.map +1 -0
- package/output/components/select.js +58 -0
- package/output/components/separator.d.ts +5 -0
- package/output/components/separator.d.ts.map +1 -0
- package/output/components/separator.js +20 -0
- package/output/components/sheet.d.ts +16 -0
- package/output/components/sheet.d.ts.map +1 -0
- package/output/components/sheet.js +58 -0
- package/output/components/sidebar.d.ts +78 -0
- package/output/components/sidebar.d.ts.map +1 -0
- package/output/components/sidebar.js +233 -0
- package/output/components/size-provider/index.d.ts +2 -0
- package/output/components/size-provider/index.d.ts.map +1 -0
- package/output/components/size-provider/index.js +1 -0
- package/output/components/size-provider/size-provider.d.ts +9 -0
- package/output/components/size-provider/size-provider.d.ts.map +1 -0
- package/output/components/size-provider/size-provider.js +29 -0
- package/output/components/skeleton.d.ts +3 -0
- package/output/components/skeleton.d.ts.map +1 -0
- package/output/components/skeleton.js +18 -0
- package/output/components/sonner.d.ts +8 -0
- package/output/components/sonner.d.ts.map +1 -0
- package/output/components/sonner.js +34 -0
- package/output/components/spinner.d.ts +3 -0
- package/output/components/spinner.d.ts.map +1 -0
- package/output/components/spinner.js +19 -0
- package/output/components/switch.d.ts +8 -0
- package/output/components/switch.d.ts.map +1 -0
- package/output/components/switch.js +20 -0
- package/output/components/table.d.ts +11 -0
- package/output/components/table.d.ts.map +1 -0
- package/output/components/table.js +47 -0
- package/output/components/tabs.d.ts +12 -0
- package/output/components/tabs.d.ts.map +1 -0
- package/output/components/tabs.js +45 -0
- package/output/components/textarea.d.ts +4 -0
- package/output/components/textarea.d.ts.map +1 -0
- package/output/components/textarea.js +19 -0
- package/output/components/theme-switcher.d.ts +6 -0
- package/output/components/theme-switcher.d.ts.map +1 -0
- package/output/components/theme-switcher.js +19 -0
- package/output/components/toaster/index.d.ts +16 -0
- package/output/components/toaster/index.d.ts.map +1 -0
- package/output/components/toaster/index.js +70 -0
- package/output/components/toggle-group.d.ts +12 -0
- package/output/components/toggle-group.d.ts.map +1 -0
- package/output/components/toggle-group.js +38 -0
- package/output/components/toggle.d.ts +10 -0
- package/output/components/toggle.d.ts.map +1 -0
- package/output/components/toggle.js +38 -0
- package/output/components/tooltip.d.ts +8 -0
- package/output/components/tooltip.d.ts.map +1 -0
- package/output/components/tooltip.js +33 -0
- package/output/features/confirm-dialog/index.d.ts +41 -0
- package/output/features/confirm-dialog/index.d.ts.map +1 -0
- package/output/features/confirm-dialog/index.js +19 -0
- package/output/features/input-confirm/index.d.ts +26 -0
- package/output/features/input-confirm/index.d.ts.map +1 -0
- package/output/features/input-confirm/index.js +59 -0
- package/output/features/signin/context.d.ts +14 -0
- package/output/features/signin/context.d.ts.map +1 -0
- package/output/features/signin/context.js +13 -0
- package/output/features/signin/index.d.ts +58 -0
- package/output/features/signin/index.d.ts.map +1 -0
- package/output/features/signin/index.js +137 -0
- package/output/features/signin/service.d.ts +92 -0
- package/output/features/signin/service.d.ts.map +1 -0
- package/output/features/signin/service.js +519 -0
- package/output/features/signin/service.test.d.ts +2 -0
- package/output/features/signin/service.test.d.ts.map +1 -0
- package/output/features/signin/service.test.js +211 -0
- package/output/features/signin/types.d.ts +63 -0
- package/output/features/signin/types.d.ts.map +1 -0
- package/output/features/signin/types.js +1 -0
- package/output/hooks/use-loading/index.d.ts +6 -0
- package/output/hooks/use-loading/index.d.ts.map +1 -0
- package/output/hooks/use-loading/index.js +14 -0
- package/output/hooks/use-loading/index.test.d.ts +2 -0
- package/output/hooks/use-loading/index.test.d.ts.map +1 -0
- package/output/hooks/use-loading/index.test.js +24 -0
- package/output/hooks/use-mobile/index.d.ts +2 -0
- package/output/hooks/use-mobile/index.d.ts.map +1 -0
- package/output/hooks/use-mobile/index.js +16 -0
- package/output/hooks/use-observer/index.d.ts +2 -0
- package/output/hooks/use-observer/index.d.ts.map +1 -0
- package/output/hooks/use-observer/index.js +1 -0
- package/output/hooks/use-observer/use-observer.d.ts +3 -0
- package/output/hooks/use-observer/use-observer.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.js +16 -0
- package/output/hooks/use-observer/use-observer.test.d.ts +2 -0
- package/output/hooks/use-observer/use-observer.test.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.test.js +134 -0
- package/output/hooks/use-offline/index.d.ts +6 -0
- package/output/hooks/use-offline/index.d.ts.map +1 -0
- package/output/hooks/use-offline/index.js +19 -0
- package/output/layout/app/index.d.ts +34 -0
- package/output/layout/app/index.d.ts.map +1 -0
- package/output/layout/app/index.js +34 -0
- package/output/layout/dashboard/index.d.ts +76 -0
- package/output/layout/dashboard/index.d.ts.map +1 -0
- package/output/layout/dashboard/index.js +84 -0
- package/output/layout/index.d.ts +3 -0
- package/output/layout/index.d.ts.map +1 -0
- package/output/layout/index.js +2 -0
- package/output/services/cache-api/cache-api.d.ts +23 -0
- package/output/services/cache-api/cache-api.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.js +145 -0
- package/output/services/cache-api/cache-api.test.d.ts +2 -0
- package/output/services/cache-api/cache-api.test.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.test.js +610 -0
- package/output/services/cache-api/index.d.ts +2 -0
- package/output/services/cache-api/index.d.ts.map +1 -0
- package/output/services/cache-api/index.js +1 -0
- package/output/services/cached-fetch/index.d.ts +50 -0
- package/output/services/cached-fetch/index.d.ts.map +1 -0
- package/output/services/cached-fetch/index.js +196 -0
- package/output/services/service/index.d.ts +2 -0
- package/output/services/service/index.d.ts.map +1 -0
- package/output/services/service/index.js +1 -0
- package/output/services/service/service.d.ts +135 -0
- package/output/services/service/service.d.ts.map +1 -0
- package/output/services/service/service.js +276 -0
- package/output/services/service/service.test.d.ts +2 -0
- package/output/services/service/service.test.d.ts.map +1 -0
- package/output/services/service/service.test.js +1399 -0
- package/output/services/side-cache/index.d.ts +2 -0
- package/output/services/side-cache/index.d.ts.map +1 -0
- package/output/services/side-cache/index.js +1 -0
- package/output/services/side-cache/side-cache.d.ts +11 -0
- package/output/services/side-cache/side-cache.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.js +161 -0
- package/output/services/side-cache/side-cache.test.d.ts +2 -0
- package/output/services/side-cache/side-cache.test.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.test.js +271 -0
- package/output/utils/avatar/index.d.ts +28 -0
- package/output/utils/avatar/index.d.ts.map +1 -0
- package/output/utils/avatar/index.js +35 -0
- package/output/utils/delay/index.d.ts +2 -0
- package/output/utils/delay/index.d.ts.map +1 -0
- package/output/utils/delay/index.js +5 -0
- package/output/utils/form/index.d.ts +3 -0
- package/output/utils/form/index.d.ts.map +1 -0
- package/output/utils/form/index.js +1 -0
- package/output/utils/merge-class-names/index.d.ts +3 -0
- package/output/utils/merge-class-names/index.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.js +5 -0
- package/output/utils/merge-class-names/index.test.d.ts +2 -0
- package/output/utils/merge-class-names/index.test.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.test.js +7 -0
- package/output/utils/performance/index.d.ts +82 -0
- package/output/utils/performance/index.d.ts.map +1 -0
- package/output/utils/performance/index.js +129 -0
- package/output/utils/redirect/index.d.ts +6 -0
- package/output/utils/redirect/index.d.ts.map +1 -0
- package/output/utils/redirect/index.js +32 -0
- package/package.json +8 -5
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import 'jsoneditor/dist/jsoneditor.css';
|
|
3
|
+
import JSONEditor from 'jsoneditor';
|
|
4
|
+
import { observer } from 'mobx-react-lite';
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
|
+
import { mergeClassNames } from '../../utils/merge-class-names/index.js';
|
|
7
|
+
export const JsonView = observer((props) => {
|
|
8
|
+
const { value, onChange, readonly = false, className } = props;
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const editorRef = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!containerRef.current)
|
|
13
|
+
return;
|
|
14
|
+
const options = {
|
|
15
|
+
mode: 'code',
|
|
16
|
+
modes: readonly ? ['view', 'code'] : ['tree', 'code', 'form', 'view'],
|
|
17
|
+
onChange: () => {
|
|
18
|
+
if (onChange && editorRef.current && !readonly) {
|
|
19
|
+
try {
|
|
20
|
+
const json = editorRef.current.get();
|
|
21
|
+
onChange(json);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Invalid JSON', error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const EditorCtor = JSONEditor;
|
|
30
|
+
editorRef.current = new EditorCtor(containerRef.current, options);
|
|
31
|
+
editorRef.current.set(value || {});
|
|
32
|
+
return () => {
|
|
33
|
+
var _a;
|
|
34
|
+
(_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
35
|
+
};
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (editorRef.current) {
|
|
40
|
+
try {
|
|
41
|
+
const currentValue = editorRef.current.get();
|
|
42
|
+
if (JSON.stringify(currentValue) !== JSON.stringify(value)) {
|
|
43
|
+
editorRef.current.set(value || {});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (_a) {
|
|
47
|
+
editorRef.current.set(value || {});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, [value]);
|
|
51
|
+
return _jsx("div", { ref: containerRef, className: mergeClassNames('h-96 w-full', className) });
|
|
52
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonViewProps } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* JsonView 的 Lazy Loading Wrapper
|
|
4
|
+
*
|
|
5
|
+
* 优化原因:
|
|
6
|
+
* - jsoneditor 库体积很大(~200-300 KB)
|
|
7
|
+
* - 不是所有页面都需要 JSON 编辑器
|
|
8
|
+
* - 使用 lazy loading 减少首屏加载体积
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { JsonView } from '@taicode/common-web/components/json-view/lazy'
|
|
13
|
+
*
|
|
14
|
+
* <JsonView value={data} onChange={handleChange} />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function JsonView(props: JsonViewProps): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../source/components/json-view/lazy/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKhD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAY5C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { lazy, Suspense } from 'react';
|
|
3
|
+
// Lazy load JsonView 组件(包含大型 jsoneditor 库)
|
|
4
|
+
const JsonViewLazy = lazy(() => import('../index.js').then(m => ({ default: m.JsonView })));
|
|
5
|
+
/**
|
|
6
|
+
* JsonView 的 Lazy Loading Wrapper
|
|
7
|
+
*
|
|
8
|
+
* 优化原因:
|
|
9
|
+
* - jsoneditor 库体积很大(~200-300 KB)
|
|
10
|
+
* - 不是所有页面都需要 JSON 编辑器
|
|
11
|
+
* - 使用 lazy loading 减少首屏加载体积
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { JsonView } from '@taicode/common-web/components/json-view/lazy'
|
|
16
|
+
*
|
|
17
|
+
* <JsonView value={data} onChange={handleChange} />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function JsonView(props) {
|
|
21
|
+
return (_jsx(Suspense, { fallback: _jsx("div", { className: "flex h-48 items-center justify-center rounded-md border border-zinc-200 dark:border-zinc-800", children: _jsx("div", { className: "text-sm text-zinc-500 dark:text-zinc-400", children: "Loading JSON Editor..." }) }), children: _jsx(JsonViewLazy, Object.assign({}, props)) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kbd.d.ts","sourceRoot":"","sources":["../../source/components/kbd.tsx"],"names":[],"mappings":"AAEA,iBAAS,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,+BAY/C;AAED,iBAAS,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,+BASpD;AAED,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { mergeClassNames } from "../utils/merge-class-names/index.js";
|
|
14
|
+
function Kbd(params) {
|
|
15
|
+
const { className } = params, props = __rest(params, ["className"]);
|
|
16
|
+
return (_jsx("kbd", Object.assign({ "data-slot": "kbd", className: mergeClassNames("bg-muted text-muted-foreground [[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10 h-5 w-fit min-w-5 gap-1 rounded-sm px-1 font-sans text-xs font-medium [&_svg:not([class*='size-'])]:size-3 pointer-events-none inline-flex items-center justify-center select-none", className) }, props)));
|
|
17
|
+
}
|
|
18
|
+
function KbdGroup(params) {
|
|
19
|
+
const { className } = params, props = __rest(params, ["className"]);
|
|
20
|
+
return (_jsx("kbd", Object.assign({ "data-slot": "kbd-group", className: mergeClassNames("gap-1 inline-flex items-center", className) }, props)));
|
|
21
|
+
}
|
|
22
|
+
export { Kbd, KbdGroup };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../source/components/label.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,UAAU,CAAA;AAIlD,iBAAS,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,cAAc,CAAC,IAAI,CAAC,qBAYtE;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { Label as LabelPrimitive } from 'radix-ui';
|
|
15
|
+
import { mergeClassNames } from '../utils/merge-class-names/index.js';
|
|
16
|
+
function Label(params) {
|
|
17
|
+
const { className } = params, props = __rest(params, ["className"]);
|
|
18
|
+
return (_jsx(LabelPrimitive.Root, Object.assign({ "data-slot": "label", className: mergeClassNames('gap-2 text-sm leading-none font-medium group-data-[disabled=true]:opacity-50 peer-disabled:opacity-50 flex items-center select-none group-data-[disabled=true]:pointer-events-none peer-disabled:cursor-not-allowed', className) }, props)));
|
|
19
|
+
}
|
|
20
|
+
export { Label };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type RefreshButtonProps = {
|
|
2
|
+
onClick: () => void;
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function RefreshButton(props: RefreshButtonProps): import("react").JSX.Element;
|
|
7
|
+
type ResetButtonProps = {
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
label?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function ResetButton(props: ResetButtonProps): import("react").JSX.Element;
|
|
12
|
+
type FilterActionsProps = {
|
|
13
|
+
onApply: () => void;
|
|
14
|
+
onReset: () => void;
|
|
15
|
+
onRefresh?: () => void;
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
applyLabel?: string;
|
|
18
|
+
resetLabel?: string;
|
|
19
|
+
refreshLabel?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function FilterActions(props: FilterActionsProps): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/components/list-actions/index.tsx"],"names":[],"mappings":"AAIA,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BAQtD;AAED,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,+BAQlD;AAED,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BAatD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RefreshCwIcon, XIcon, SearchIcon } from 'lucide-react';
|
|
3
|
+
import { Button } from '../button.js';
|
|
4
|
+
export function RefreshButton(props) {
|
|
5
|
+
const { onClick, loading = false, label = 'Refresh' } = props;
|
|
6
|
+
return (_jsx(Button, { variant: "outline", size: "icon", className: "size-9", onClick: onClick, disabled: loading, "aria-label": label, title: label, children: _jsx(RefreshCwIcon, { className: loading ? 'size-4 animate-spin' : 'size-4' }) }));
|
|
7
|
+
}
|
|
8
|
+
export function ResetButton(props) {
|
|
9
|
+
const { onClick, label = 'Reset' } = props;
|
|
10
|
+
return (_jsx(Button, { onClick: onClick, variant: "outline", size: "icon", className: "size-9", "aria-label": label, title: label, children: _jsx(XIcon, { className: "size-4" }) }));
|
|
11
|
+
}
|
|
12
|
+
export function FilterActions(props) {
|
|
13
|
+
const { onApply, onReset, onRefresh, loading = false, applyLabel = '应用筛选', resetLabel = '重置', refreshLabel = '刷新' } = props;
|
|
14
|
+
return (_jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [_jsxs(Button, { onClick: onApply, className: "h-9", children: [_jsx(SearchIcon, { className: "size-4" }), applyLabel] }), _jsx(ResetButton, { onClick: onReset, label: resetLabel }), onRefresh && _jsx(RefreshButton, { onClick: onRefresh, loading: loading, label: refreshLabel })] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { type ComponentPropsWithoutRef, type ElementType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 多态组件的 Props 类型
|
|
4
|
+
*/
|
|
5
|
+
type PolymorphicProps<T extends ElementType> = {
|
|
6
|
+
as?: T;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
loadingText?: string;
|
|
9
|
+
loadingIcon?: React.ReactNode;
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
} & Omit<ComponentPropsWithoutRef<T>, 'as' | 'loading' | 'loadingText' | 'loadingIcon' | 'onClick'>;
|
|
14
|
+
/**
|
|
15
|
+
* LoadingButton 组件
|
|
16
|
+
*
|
|
17
|
+
* 支持任意组件作为基础按钮,在异步操作时自动显示 loading 状态
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* // 使用默认 button
|
|
22
|
+
* <LoadingButton onClick={async () => await save()}>
|
|
23
|
+
* 保存
|
|
24
|
+
* </LoadingButton>
|
|
25
|
+
*
|
|
26
|
+
* // 使用自定义组件
|
|
27
|
+
* <LoadingButton as={MyButton} onClick={async () => await save()}>
|
|
28
|
+
* 保存
|
|
29
|
+
* </LoadingButton>
|
|
30
|
+
*
|
|
31
|
+
* // 自定义 loading 图标
|
|
32
|
+
* <LoadingButton loadingIcon={<MySpinner />} onClick={async () => await save()}>
|
|
33
|
+
* 保存
|
|
34
|
+
* </LoadingButton>
|
|
35
|
+
*
|
|
36
|
+
* // 手动控制 loading 状态
|
|
37
|
+
* <LoadingButton loading={isLoading}>
|
|
38
|
+
* 保存
|
|
39
|
+
* </LoadingButton>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const LoadingButton: React.ForwardRefExoticComponent<Omit<PolymorphicProps<React.ElementType>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/components/loading-button/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAqC,KAAK,wBAAwB,EAAE,KAAK,WAAW,EAAE,MAAM,OAAO,CAAA;AAkCjH;;GAEG;AACH,KAAK,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI;IAC7C,EAAE,CAAC,EAAE,CAAC,CAAA;IACN,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,SAAS,GAAG,aAAa,GAAG,aAAa,GAAG,SAAS,CAAC,CAAA;AAEnG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,4HAkEzB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import React, { useState, useCallback, forwardRef } from 'react';
|
|
14
|
+
function isPromiseLike(value) {
|
|
15
|
+
return value != null && typeof value === 'object' && 'then' in value && typeof value.then === 'function';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Loading 指示器组件
|
|
19
|
+
*/
|
|
20
|
+
function LoadingSpinner({ className = '' }) {
|
|
21
|
+
return (_jsxs("svg", { className: `animate-spin ${className}`, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* LoadingButton 组件
|
|
25
|
+
*
|
|
26
|
+
* 支持任意组件作为基础按钮,在异步操作时自动显示 loading 状态
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* // 使用默认 button
|
|
31
|
+
* <LoadingButton onClick={async () => await save()}>
|
|
32
|
+
* 保存
|
|
33
|
+
* </LoadingButton>
|
|
34
|
+
*
|
|
35
|
+
* // 使用自定义组件
|
|
36
|
+
* <LoadingButton as={MyButton} onClick={async () => await save()}>
|
|
37
|
+
* 保存
|
|
38
|
+
* </LoadingButton>
|
|
39
|
+
*
|
|
40
|
+
* // 自定义 loading 图标
|
|
41
|
+
* <LoadingButton loadingIcon={<MySpinner />} onClick={async () => await save()}>
|
|
42
|
+
* 保存
|
|
43
|
+
* </LoadingButton>
|
|
44
|
+
*
|
|
45
|
+
* // 手动控制 loading 状态
|
|
46
|
+
* <LoadingButton loading={isLoading}>
|
|
47
|
+
* 保存
|
|
48
|
+
* </LoadingButton>
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const LoadingButton = forwardRef(function LoadingButton(_a, ref) {
|
|
52
|
+
var { as, loading: externalLoading, loadingText, loadingIcon, onClick, disabled, children, className = '' } = _a, props = __rest(_a, ["as", "loading", "loadingText", "loadingIcon", "onClick", "disabled", "children", "className"]);
|
|
53
|
+
const [internalLoading, setInternalLoading] = useState(false);
|
|
54
|
+
const loading = externalLoading !== null && externalLoading !== void 0 ? externalLoading : internalLoading;
|
|
55
|
+
const handleClick = useCallback((event) => {
|
|
56
|
+
if (!onClick || loading || disabled)
|
|
57
|
+
return;
|
|
58
|
+
const result = onClick(event);
|
|
59
|
+
// 如果返回 Promise-like,自动管理 loading 状态
|
|
60
|
+
// 使用 then 而不是 finally,因为 PromiseLike 不保证有 finally 方法
|
|
61
|
+
if (isPromiseLike(result)) {
|
|
62
|
+
setInternalLoading(true);
|
|
63
|
+
result.then(() => setInternalLoading(false), () => setInternalLoading(false));
|
|
64
|
+
}
|
|
65
|
+
}, [onClick, loading, disabled]);
|
|
66
|
+
// 使用 as prop 或默认 button
|
|
67
|
+
const Component = as || 'button';
|
|
68
|
+
// 默认 button 样式(仅当使用默认 button 时应用)
|
|
69
|
+
const defaultButtonClass = !as
|
|
70
|
+
? 'inline-flex items-center justify-center gap-2 rounded-[var(--radius)] bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--primary-foreground)] shadow-sm transition-opacity hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-[var(--ring)] focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed'
|
|
71
|
+
: '';
|
|
72
|
+
const finalClassName = `${defaultButtonClass} ${className}`.trim();
|
|
73
|
+
return (_jsx(Component, Object.assign({ ref: ref, onClick: handleClick, disabled: disabled || loading, className: finalClassName }, props, { children: loading ? (_jsxs(_Fragment, { children: [loadingIcon || _jsx(LoadingSpinner, { className: "size-4" }), loadingText || children] })) : (children) })));
|
|
74
|
+
});
|
|
75
|
+
LoadingButton.displayName = 'LoadingButton';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../source/components/loading-button/index.test.tsx"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import '@testing-library/jest-dom/vitest';
|
|
14
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
15
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
16
|
+
import { LoadingButton } from './index.js';
|
|
17
|
+
describe('LoadingButton', () => {
|
|
18
|
+
describe('基础功能', () => {
|
|
19
|
+
it('应该渲染按钮和子元素', () => {
|
|
20
|
+
render(_jsx(LoadingButton, { children: "\u70B9\u51FB\u6211" }));
|
|
21
|
+
expect(screen.getByRole('button')).toHaveTextContent('点击我');
|
|
22
|
+
});
|
|
23
|
+
it('应该支持 disabled 属性', () => {
|
|
24
|
+
render(_jsx(LoadingButton, { disabled: true, children: "\u70B9\u51FB\u6211" }));
|
|
25
|
+
expect(screen.getByRole('button')).toBeDisabled();
|
|
26
|
+
});
|
|
27
|
+
it('应该应用自定义 className', () => {
|
|
28
|
+
render(_jsx(LoadingButton, { className: "custom-class", children: "\u70B9\u51FB\u6211" }));
|
|
29
|
+
expect(screen.getByRole('button')).toHaveClass('custom-class');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('同步点击', () => {
|
|
33
|
+
it('应该处理同步点击事件', () => {
|
|
34
|
+
const handleClick = vi.fn();
|
|
35
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
36
|
+
fireEvent.click(screen.getByRole('button'));
|
|
37
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
it('同步操作不应该显示 loading', () => {
|
|
40
|
+
const handleClick = vi.fn();
|
|
41
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
42
|
+
fireEvent.click(screen.getByRole('button'));
|
|
43
|
+
expect(screen.queryByRole('button')).toHaveTextContent('点击我');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('异步点击', () => {
|
|
47
|
+
it('应该在异步操作期间显示 loading', async () => {
|
|
48
|
+
const handleClick = vi.fn(async () => {
|
|
49
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
50
|
+
});
|
|
51
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
52
|
+
const button = screen.getByRole('button');
|
|
53
|
+
fireEvent.click(button);
|
|
54
|
+
// 应该立即显示 loading
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(button).toBeDisabled();
|
|
57
|
+
});
|
|
58
|
+
// 等待异步操作完成
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
expect(button).not.toBeDisabled();
|
|
61
|
+
}, { timeout: 200 });
|
|
62
|
+
});
|
|
63
|
+
it('异步操作完成后应该恢复正常状态', async () => {
|
|
64
|
+
let resolve;
|
|
65
|
+
const promise = new Promise(r => { resolve = r; });
|
|
66
|
+
const handleClick = vi.fn(() => promise);
|
|
67
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
68
|
+
const button = screen.getByRole('button');
|
|
69
|
+
fireEvent.click(button);
|
|
70
|
+
// loading 状态
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(button).toBeDisabled();
|
|
73
|
+
});
|
|
74
|
+
// 完成异步操作
|
|
75
|
+
resolve();
|
|
76
|
+
// 恢复正常
|
|
77
|
+
await waitFor(() => {
|
|
78
|
+
expect(button).not.toBeDisabled();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it('异步操作失败后应该恢复正常状态', async () => {
|
|
82
|
+
const handleClick = vi.fn(async () => {
|
|
83
|
+
await new Promise((_, reject) => setTimeout(() => reject(new Error('失败')), 50));
|
|
84
|
+
});
|
|
85
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
86
|
+
const button = screen.getByRole('button');
|
|
87
|
+
fireEvent.click(button);
|
|
88
|
+
// loading 状态
|
|
89
|
+
await waitFor(() => {
|
|
90
|
+
expect(button).toBeDisabled();
|
|
91
|
+
});
|
|
92
|
+
// 等待失败并恢复
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(button).not.toBeDisabled();
|
|
95
|
+
}, { timeout: 100 });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe('手动控制 loading', () => {
|
|
99
|
+
it('应该支持外部控制 loading 状态', () => {
|
|
100
|
+
const { rerender } = render(_jsx(LoadingButton, { loading: false, children: "\u4FDD\u5B58" }));
|
|
101
|
+
expect(screen.getByRole('button')).not.toBeDisabled();
|
|
102
|
+
rerender(_jsx(LoadingButton, { loading: true, children: "\u4FDD\u5B58" }));
|
|
103
|
+
expect(screen.getByRole('button')).toBeDisabled();
|
|
104
|
+
});
|
|
105
|
+
it('外部 loading 状态应该优先于内部状态', async () => {
|
|
106
|
+
const handleClick = vi.fn(async () => {
|
|
107
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
108
|
+
});
|
|
109
|
+
render(_jsx(LoadingButton, { loading: true, onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
110
|
+
const button = screen.getByRole('button');
|
|
111
|
+
// 外部 loading 为 true,应该禁用
|
|
112
|
+
expect(button).toBeDisabled();
|
|
113
|
+
// 点击不应该触发
|
|
114
|
+
fireEvent.click(button);
|
|
115
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe('loading 显示定制', () => {
|
|
119
|
+
it('应该显示自定义 loadingText', async () => {
|
|
120
|
+
const handleClick = vi.fn(async () => {
|
|
121
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
122
|
+
});
|
|
123
|
+
render(_jsx(LoadingButton, { loadingText: "\u5904\u7406\u4E2D...", onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
124
|
+
fireEvent.click(screen.getByRole('button'));
|
|
125
|
+
await waitFor(() => {
|
|
126
|
+
expect(screen.getByText('处理中...')).toBeInTheDocument();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it('应该显示自定义 loadingIcon', async () => {
|
|
130
|
+
const handleClick = vi.fn(async () => {
|
|
131
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
132
|
+
});
|
|
133
|
+
render(_jsx(LoadingButton, { loadingIcon: _jsx("span", { "data-testid": "custom-icon", children: "\u23F3" }), onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
134
|
+
fireEvent.click(screen.getByRole('button'));
|
|
135
|
+
await waitFor(() => {
|
|
136
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('多态组件 (as prop)', () => {
|
|
141
|
+
it('应该渲染为自定义组件', () => {
|
|
142
|
+
const CustomButton = (_a) => {
|
|
143
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
144
|
+
return (_jsx("button", Object.assign({ "data-testid": "custom-button" }, props, { children: children })));
|
|
145
|
+
};
|
|
146
|
+
render(_jsx(LoadingButton, { as: CustomButton, children: "\u70B9\u51FB\u6211" }));
|
|
147
|
+
expect(screen.getByTestId('custom-button')).toBeInTheDocument();
|
|
148
|
+
});
|
|
149
|
+
it('应该渲染为 anchor 标签', () => {
|
|
150
|
+
render(_jsx(LoadingButton, { as: "a", href: "#", children: "\u94FE\u63A5" }));
|
|
151
|
+
const link = screen.getByText('链接');
|
|
152
|
+
expect(link.tagName).toBe('A');
|
|
153
|
+
});
|
|
154
|
+
it('自定义组件应该保留其 props', () => {
|
|
155
|
+
render(_jsx(LoadingButton, { as: "a", href: "https://example.com", target: "_blank", children: "\u94FE\u63A5" }));
|
|
156
|
+
const link = screen.getByText('链接');
|
|
157
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
158
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('禁用状态', () => {
|
|
162
|
+
it('禁用时不应该触发点击', () => {
|
|
163
|
+
const handleClick = vi.fn();
|
|
164
|
+
render(_jsx(LoadingButton, { disabled: true, onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
165
|
+
fireEvent.click(screen.getByRole('button'));
|
|
166
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
it('loading 时不应该触发点击', async () => {
|
|
169
|
+
const handleClick = vi.fn(async () => {
|
|
170
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
171
|
+
});
|
|
172
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
173
|
+
const button = screen.getByRole('button');
|
|
174
|
+
// 第一次点击
|
|
175
|
+
fireEvent.click(button);
|
|
176
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
177
|
+
// loading 期间再次点击
|
|
178
|
+
fireEvent.click(button);
|
|
179
|
+
fireEvent.click(button);
|
|
180
|
+
// 不应该再次触发
|
|
181
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
182
|
+
// 等待完成
|
|
183
|
+
await waitFor(() => {
|
|
184
|
+
expect(button).not.toBeDisabled();
|
|
185
|
+
}, { timeout: 150 });
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('默认样式', () => {
|
|
189
|
+
it('使用默认 button 时应该应用默认样式', () => {
|
|
190
|
+
render(_jsx(LoadingButton, { children: "\u70B9\u51FB\u6211" }));
|
|
191
|
+
const button = screen.getByRole('button');
|
|
192
|
+
// 检查是否包含默认样式类
|
|
193
|
+
expect(button.className).toContain('inline-flex');
|
|
194
|
+
expect(button.className).toContain('bg-[var(--primary)]');
|
|
195
|
+
});
|
|
196
|
+
it('使用 as prop 时不应该应用默认样式', () => {
|
|
197
|
+
render(_jsx(LoadingButton, { as: "a", children: "\u94FE\u63A5" }));
|
|
198
|
+
const link = screen.getByText('链接');
|
|
199
|
+
// 不应该包含默认 button 样式
|
|
200
|
+
expect(link.className).not.toContain('bg-[var(--primary)]');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type NativeSelectProps = Omit<React.ComponentProps<"select">, "size"> & {
|
|
3
|
+
size?: "sm" | "default";
|
|
4
|
+
};
|
|
5
|
+
declare function NativeSelect(params: NativeSelectProps): React.JSX.Element;
|
|
6
|
+
declare function NativeSelectOption(params: React.ComponentProps<"option">): React.JSX.Element;
|
|
7
|
+
declare function NativeSelectOptGroup(params: React.ComponentProps<"optgroup">): React.JSX.Element;
|
|
8
|
+
export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };
|
|
9
|
+
//# sourceMappingURL=native-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-select.d.ts","sourceRoot":"","sources":["../../source/components/native-select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,KAAK,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;CACxB,CAAA;AAED,iBAAS,YAAY,CAAC,MAAM,EAAE,iBAAiB,qBAwB9C;AAED,iBAAS,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,qBAGjE;AAED,iBAAS,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,qBAYrE;AAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { mergeClassNames } from "../utils/merge-class-names/index.js";
|
|
15
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
16
|
+
function NativeSelect(params) {
|
|
17
|
+
const { className, size = "default" } = params, props = __rest(params, ["className", "size"]);
|
|
18
|
+
return (_jsxs("div", { className: mergeClassNames("group/native-select relative w-fit has-[select:disabled]:opacity-50", className), "data-slot": "native-select-wrapper", "data-size": size, children: [_jsx("select", Object.assign({ "data-slot": "native-select", "data-size": size, className: "border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent py-1 pr-8 pl-2.5 text-sm shadow-xs transition-[color,box-shadow] select-none focus-visible:ring-[3px] aria-invalid:ring-[3px] data-[size=sm]:h-8 outline-none disabled:pointer-events-none disabled:cursor-not-allowed" }, props)), _jsx(ChevronDownIcon, { className: "text-muted-foreground top-1/2 right-2.5 size-4 -translate-y-1/2 pointer-events-none absolute select-none", "aria-hidden": "true", "data-slot": "native-select-icon" })] }));
|
|
19
|
+
}
|
|
20
|
+
function NativeSelectOption(params) {
|
|
21
|
+
const props = __rest(params, []);
|
|
22
|
+
return _jsx("option", Object.assign({ "data-slot": "native-select-option" }, props));
|
|
23
|
+
}
|
|
24
|
+
function NativeSelectOptGroup(params) {
|
|
25
|
+
const { className } = params, props = __rest(params, ["className"]);
|
|
26
|
+
return (_jsx("optgroup", Object.assign({ "data-slot": "native-select-optgroup", className: mergeClassNames(className) }, props)));
|
|
27
|
+
}
|
|
28
|
+
export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/components/page-back-button/index.tsx"],"names":[],"mappings":"AAIA,KAAK,mBAAmB,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,+BAYxD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowLeftIcon } from 'lucide-react';
|
|
3
|
+
import { Button } from '../button.js';
|
|
4
|
+
export function PageBackButton(props) {
|
|
5
|
+
const { label = 'Back', context, onClick } = props;
|
|
6
|
+
return (_jsxs("div", { className: "flex min-h-9 min-w-0 items-center gap-2", children: [_jsxs(Button, { variant: "ghost", size: "sm", onClick: onClick, className: "-ml-2 shrink-0 gap-1.5 px-2", children: [_jsx(ArrowLeftIcon, { className: "size-4" }), _jsx("span", { children: label })] }), context && _jsx("span", { className: "truncate text-sm text-muted-foreground", children: context })] }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface EmptyProps {
|
|
3
|
+
icon?: ReactNode;
|
|
4
|
+
title: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
action?: {
|
|
7
|
+
label: string;
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface LoadingStateProps {
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
fullscreen?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function LoadingState(props: LoadingStateProps): import("react").JSX.Element;
|
|
18
|
+
export declare function Empty(props: EmptyProps): import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=page-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-state.d.ts","sourceRoot":"","sources":["../../source/components/page-state.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE;QACP,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,IAAI,CAAA;QACnB,IAAI,CAAC,EAAE,SAAS,CAAA;KACjB,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,+BAmBpD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BAsBtC"}
|