@ug666/admin-react 0.0.0-stage → 0.1.0-beta.2
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/LICENSE +21 -0
- package/dist/AdminColumnSettings-09epsf86.js +80 -0
- package/dist/AdminColumnSettings-4cv6a9m2.js +125 -0
- package/dist/AdminColumnSettings-93ajawas.js +64 -0
- package/dist/AdminColumnSettings-aqqcc4wq.js +34 -0
- package/dist/AdminColumnSettings-be5c6tmr.js +43 -0
- package/dist/AdminColumnSettings-nnrtybx5.js +88 -0
- package/dist/AdminColumnSettings-sz4q6vza.js +177 -0
- package/dist/AdminColumnSettings-t2b7bfqc.js +43 -0
- package/dist/AdminColumnSettings-tf48jqrt.js +132 -0
- package/dist/index.js +42 -0
- package/dist/index.ts.js +1 -0
- package/dist/patterns/AdminColumnSettings.js +8 -0
- package/dist/patterns/AdminConfirmAction.js +6 -0
- package/dist/patterns/AdminDetailPage.js +7 -0
- package/dist/patterns/AdminFormDialog.js +6 -0
- package/dist/patterns/AdminFormPage.js +7 -0
- package/dist/patterns/AdminListPage.js +7 -0
- package/dist/patterns/AdminPage.js +6 -0
- package/dist/patterns/AdminSearchForm.js +8 -0
- package/dist/patterns/AdminTabContextMenu.js +6 -0
- package/package.json +46 -4
- package/src/index.ts +11 -0
- package/src/patterns/AdminColumnSettings.tsx +168 -0
- package/src/patterns/AdminConfirmAction.tsx +44 -0
- package/src/patterns/AdminDetailPage.tsx +44 -0
- package/src/patterns/AdminFormDialog.tsx +96 -0
- package/src/patterns/AdminFormPage.tsx +113 -0
- package/src/patterns/AdminListPage.tsx +62 -0
- package/src/patterns/AdminPage.tsx +55 -0
- package/src/patterns/AdminSearchForm.tsx +124 -0
- package/src/patterns/AdminTabContextMenu.tsx +67 -0
- package/README.md +0 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { t } from "@ug666/admin-core/i18n";
|
|
2
|
+
import { UGAlert, UGAlertDescription, UGButton, UGCard, UGCardContent } from "@ug666/ui-react";
|
|
3
|
+
import { UGConfirmDialog } from "@ug666/ui-react/patterns";
|
|
4
|
+
import { ArrowLeft, Save } from "lucide-react";
|
|
5
|
+
import { type FormEvent, type ReactNode, useEffect } from "react";
|
|
6
|
+
import { useBlocker } from "react-router-dom";
|
|
7
|
+
import { AdminPage } from "./AdminPage";
|
|
8
|
+
|
|
9
|
+
export interface AdminFormPageProps {
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
error?: string;
|
|
14
|
+
isDirty?: boolean;
|
|
15
|
+
submitting?: boolean;
|
|
16
|
+
submitDisabled?: boolean;
|
|
17
|
+
submitLabel?: string;
|
|
18
|
+
submitAndReturnLabel?: string;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
onSubmit: () => void;
|
|
21
|
+
onSubmitAndReturn?: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function AdminFormPage({
|
|
25
|
+
title,
|
|
26
|
+
description,
|
|
27
|
+
children,
|
|
28
|
+
error,
|
|
29
|
+
isDirty = false,
|
|
30
|
+
submitting = false,
|
|
31
|
+
submitDisabled = false,
|
|
32
|
+
submitLabel = t("common.save"),
|
|
33
|
+
submitAndReturnLabel = t("common.saveAndReturn"),
|
|
34
|
+
onCancel,
|
|
35
|
+
onSubmit,
|
|
36
|
+
onSubmitAndReturn,
|
|
37
|
+
}: AdminFormPageProps) {
|
|
38
|
+
const blocker = useBlocker(
|
|
39
|
+
({ currentLocation, nextLocation }) =>
|
|
40
|
+
isDirty && currentLocation.pathname !== nextLocation.pathname,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
function handleBeforeUnload(event: BeforeUnloadEvent) {
|
|
45
|
+
if (!isDirty) return;
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
event.returnValue = "";
|
|
48
|
+
}
|
|
49
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
50
|
+
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
51
|
+
}, [isDirty]);
|
|
52
|
+
|
|
53
|
+
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
onSubmit();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<AdminPage description={description} title={title}>
|
|
60
|
+
<UGCard className="admin-form-panel">
|
|
61
|
+
<UGCardContent className="admin-card-content">
|
|
62
|
+
<form className="admin-form" onSubmit={handleSubmit}>
|
|
63
|
+
{error ? (
|
|
64
|
+
<UGAlert variant="destructive">
|
|
65
|
+
<UGAlertDescription>{error}</UGAlertDescription>
|
|
66
|
+
</UGAlert>
|
|
67
|
+
) : null}
|
|
68
|
+
<div className="admin-form__fields">{children}</div>
|
|
69
|
+
<div className="admin-form__actions">
|
|
70
|
+
<UGButton disabled={submitting} onClick={onCancel} type="button" variant="default">
|
|
71
|
+
<ArrowLeft aria-hidden="true" size={16} />
|
|
72
|
+
返回
|
|
73
|
+
</UGButton>
|
|
74
|
+
<UGButton
|
|
75
|
+
disabled={submitDisabled}
|
|
76
|
+
loading={submitting}
|
|
77
|
+
tone="primary"
|
|
78
|
+
type="submit"
|
|
79
|
+
variant="solid"
|
|
80
|
+
>
|
|
81
|
+
<Save aria-hidden="true" size={16} />
|
|
82
|
+
{submitLabel}
|
|
83
|
+
</UGButton>
|
|
84
|
+
{onSubmitAndReturn ? (
|
|
85
|
+
<UGButton
|
|
86
|
+
disabled={submitting || submitDisabled}
|
|
87
|
+
onClick={onSubmitAndReturn}
|
|
88
|
+
type="button"
|
|
89
|
+
variant="default"
|
|
90
|
+
>
|
|
91
|
+
{submitAndReturnLabel}
|
|
92
|
+
</UGButton>
|
|
93
|
+
) : null}
|
|
94
|
+
</div>
|
|
95
|
+
</form>
|
|
96
|
+
</UGCardContent>
|
|
97
|
+
</UGCard>
|
|
98
|
+
<UGConfirmDialog
|
|
99
|
+
closeOnConfirm={false}
|
|
100
|
+
confirmText="放弃修改"
|
|
101
|
+
description="当前页面存在尚未保存的修改,离开后这些内容将丢失。"
|
|
102
|
+
onCancel={() => blocker.reset?.()}
|
|
103
|
+
onConfirm={() => blocker.proceed?.()}
|
|
104
|
+
onOpenChange={(open) => {
|
|
105
|
+
if (!open) blocker.reset?.();
|
|
106
|
+
}}
|
|
107
|
+
open={blocker.state === "blocked"}
|
|
108
|
+
title="确认离开当前页面?"
|
|
109
|
+
variant="destructive"
|
|
110
|
+
/>
|
|
111
|
+
</AdminPage>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { AdminPage, type AdminPageProps } from "./AdminPage";
|
|
3
|
+
|
|
4
|
+
export interface AdminListPageProps extends Omit<AdminPageProps, "children"> {
|
|
5
|
+
search?: ReactNode;
|
|
6
|
+
summary?: ReactNode;
|
|
7
|
+
searchId?: string;
|
|
8
|
+
searchHidden?: boolean;
|
|
9
|
+
toolbarStart?: ReactNode;
|
|
10
|
+
toolbarEnd?: ReactNode;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
footer?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 列表页模式:筛选区独立,标题与主操作在列表卡头,工具栏、表格与分页在同一卡内。
|
|
17
|
+
* 页面级标题只保留给读屏(h1),可见标题由卡片头承担,避免与面包屑、页签重复。
|
|
18
|
+
*/
|
|
19
|
+
export function AdminListPage({
|
|
20
|
+
search,
|
|
21
|
+
summary,
|
|
22
|
+
searchId,
|
|
23
|
+
searchHidden = false,
|
|
24
|
+
toolbarStart,
|
|
25
|
+
toolbarEnd,
|
|
26
|
+
children,
|
|
27
|
+
footer,
|
|
28
|
+
...pageProps
|
|
29
|
+
}: AdminListPageProps) {
|
|
30
|
+
const { title, primaryAction, secondaryActions, ...rest } = pageProps;
|
|
31
|
+
const hasActions = Boolean(primaryAction || secondaryActions || toolbarEnd);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<AdminPage {...rest} className="admin-page--list" title={title} visuallyHiddenHeader>
|
|
35
|
+
{search ? (
|
|
36
|
+
<div className="admin-list-search-panel" hidden={searchHidden} id={searchId}>
|
|
37
|
+
<div className="admin-list-search">{search}</div>
|
|
38
|
+
</div>
|
|
39
|
+
) : null}
|
|
40
|
+
<div className="admin-list-panel">
|
|
41
|
+
<div className="admin-list-header">
|
|
42
|
+
<h2 className="admin-list-header__title">{title}</h2>
|
|
43
|
+
{hasActions ? (
|
|
44
|
+
<div className="admin-list-header__actions">
|
|
45
|
+
{secondaryActions}
|
|
46
|
+
{primaryAction}
|
|
47
|
+
{toolbarEnd ? <div className="admin-list-header__tools">{toolbarEnd}</div> : null}
|
|
48
|
+
</div>
|
|
49
|
+
) : null}
|
|
50
|
+
</div>
|
|
51
|
+
{summary}
|
|
52
|
+
{toolbarStart ? (
|
|
53
|
+
<div className="admin-list-actions">
|
|
54
|
+
<div className="admin-list-actions__start">{toolbarStart}</div>
|
|
55
|
+
</div>
|
|
56
|
+
) : null}
|
|
57
|
+
<div className="admin-list-content">{children}</div>
|
|
58
|
+
{footer ? <div className="admin-list-footer">{footer}</div> : null}
|
|
59
|
+
</div>
|
|
60
|
+
</AdminPage>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { UGPageHeader } from "@ug666/ui-react/patterns";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
export interface AdminPageProps {
|
|
5
|
+
className?: string;
|
|
6
|
+
title: ReactNode;
|
|
7
|
+
/** 页面说明文案;默认不渲染(管理台标题行只保留标题与操作),需要时显式开启 */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** 是否在页头渲染 description,默认 false */
|
|
10
|
+
showDescription?: boolean;
|
|
11
|
+
badge?: ReactNode;
|
|
12
|
+
meta?: ReactNode;
|
|
13
|
+
primaryAction?: ReactNode;
|
|
14
|
+
secondaryActions?: ReactNode;
|
|
15
|
+
visuallyHiddenHeader?: boolean;
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function AdminPage({
|
|
20
|
+
className,
|
|
21
|
+
title,
|
|
22
|
+
description,
|
|
23
|
+
showDescription = false,
|
|
24
|
+
badge,
|
|
25
|
+
meta,
|
|
26
|
+
primaryAction,
|
|
27
|
+
secondaryActions,
|
|
28
|
+
visuallyHiddenHeader = false,
|
|
29
|
+
children,
|
|
30
|
+
}: AdminPageProps) {
|
|
31
|
+
const actions =
|
|
32
|
+
secondaryActions || primaryAction ? (
|
|
33
|
+
<>
|
|
34
|
+
{secondaryActions}
|
|
35
|
+
{primaryAction}
|
|
36
|
+
</>
|
|
37
|
+
) : undefined;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className={className ? `admin-page ${className}` : "admin-page"}>
|
|
41
|
+
{visuallyHiddenHeader ? (
|
|
42
|
+
<h1 className="sr-only">{title}</h1>
|
|
43
|
+
) : (
|
|
44
|
+
<UGPageHeader
|
|
45
|
+
actions={actions}
|
|
46
|
+
badge={badge}
|
|
47
|
+
description={showDescription ? description : undefined}
|
|
48
|
+
meta={meta}
|
|
49
|
+
title={<span className="admin-page__title">{title}</span>}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
{children}
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UGButton,
|
|
3
|
+
UGForm,
|
|
4
|
+
UGFormControl,
|
|
5
|
+
UGFormField,
|
|
6
|
+
UGFormItem,
|
|
7
|
+
UGFormLabel,
|
|
8
|
+
} from "@ug666/ui-react";
|
|
9
|
+
import { ChevronDown, ChevronUp, RotateCcw, Search } from "lucide-react";
|
|
10
|
+
import {
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
type FormEvent,
|
|
13
|
+
type ReactElement,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
useId,
|
|
16
|
+
useState,
|
|
17
|
+
} from "react";
|
|
18
|
+
|
|
19
|
+
export function AdminSearchField({
|
|
20
|
+
name,
|
|
21
|
+
label,
|
|
22
|
+
labelFor,
|
|
23
|
+
className,
|
|
24
|
+
itemClassName,
|
|
25
|
+
itemStyle,
|
|
26
|
+
children,
|
|
27
|
+
}: {
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
labelFor?: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
itemClassName?: string;
|
|
33
|
+
itemStyle?: CSSProperties;
|
|
34
|
+
children: ReactElement;
|
|
35
|
+
}) {
|
|
36
|
+
return (
|
|
37
|
+
<UGFormField
|
|
38
|
+
name={name}
|
|
39
|
+
className={className ? `admin-search-field ${className}` : "admin-search-field"}
|
|
40
|
+
>
|
|
41
|
+
<UGFormItem className={itemClassName} style={itemStyle}>
|
|
42
|
+
<UGFormLabel htmlFor={labelFor}>{label}</UGFormLabel>
|
|
43
|
+
<UGFormControl>{children}</UGFormControl>
|
|
44
|
+
</UGFormItem>
|
|
45
|
+
</UGFormField>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AdminSearchFormProps {
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
expandedContent?: ReactNode;
|
|
52
|
+
labelWidth?: string | number;
|
|
53
|
+
expandLabel?: string;
|
|
54
|
+
collapseLabel?: string;
|
|
55
|
+
loading?: boolean;
|
|
56
|
+
onReset: () => void;
|
|
57
|
+
onSubmit: () => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function AdminSearchForm({
|
|
61
|
+
children,
|
|
62
|
+
expandedContent,
|
|
63
|
+
labelWidth = 0,
|
|
64
|
+
expandLabel = "展开",
|
|
65
|
+
collapseLabel = "收起",
|
|
66
|
+
loading = false,
|
|
67
|
+
onReset,
|
|
68
|
+
onSubmit,
|
|
69
|
+
}: AdminSearchFormProps) {
|
|
70
|
+
const [expanded, setExpanded] = useState(false);
|
|
71
|
+
const expandedId = useId();
|
|
72
|
+
|
|
73
|
+
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
onSubmit();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<UGForm
|
|
80
|
+
className="admin-search-form"
|
|
81
|
+
layout="horizontal"
|
|
82
|
+
labelPosition="right"
|
|
83
|
+
labelWidth={labelWidth}
|
|
84
|
+
size="default"
|
|
85
|
+
onSubmit={handleSubmit}
|
|
86
|
+
>
|
|
87
|
+
<div className="admin-search-form__fields">
|
|
88
|
+
{children}
|
|
89
|
+
{expandedContent ? (
|
|
90
|
+
<div id={expandedId} className="admin-search-form__expanded" hidden={!expanded}>
|
|
91
|
+
{expandedContent}
|
|
92
|
+
</div>
|
|
93
|
+
) : null}
|
|
94
|
+
</div>
|
|
95
|
+
<div className="admin-search-form__actions">
|
|
96
|
+
{expandedContent ? (
|
|
97
|
+
<UGButton
|
|
98
|
+
aria-expanded={expanded}
|
|
99
|
+
aria-controls={expandedId}
|
|
100
|
+
onClick={() => setExpanded((value) => !value)}
|
|
101
|
+
tone="neutral"
|
|
102
|
+
type="button"
|
|
103
|
+
variant="text"
|
|
104
|
+
>
|
|
105
|
+
{expanded ? (
|
|
106
|
+
<ChevronUp aria-hidden="true" size={16} />
|
|
107
|
+
) : (
|
|
108
|
+
<ChevronDown aria-hidden="true" size={16} />
|
|
109
|
+
)}
|
|
110
|
+
{expanded ? collapseLabel : expandLabel}
|
|
111
|
+
</UGButton>
|
|
112
|
+
) : null}
|
|
113
|
+
<UGButton loading={loading} tone="primary" type="submit" variant="outline">
|
|
114
|
+
<Search aria-hidden="true" size={16} />
|
|
115
|
+
查询
|
|
116
|
+
</UGButton>
|
|
117
|
+
<UGButton onClick={onReset} tone="neutral" type="button" variant="outline">
|
|
118
|
+
<RotateCcw aria-hidden="true" size={16} />
|
|
119
|
+
重置
|
|
120
|
+
</UGButton>
|
|
121
|
+
</div>
|
|
122
|
+
</UGForm>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** @description: 在 UG 页签条上提供关闭其他页签的菜单。 */
|
|
2
|
+
import type { AdminAppTab } from "@ug666/admin-core/routing/app-tabs";
|
|
3
|
+
import {
|
|
4
|
+
UGContextMenu,
|
|
5
|
+
UGContextMenuContent,
|
|
6
|
+
UGContextMenuItem,
|
|
7
|
+
UGContextMenuTrigger,
|
|
8
|
+
} from "@ug666/ui-react";
|
|
9
|
+
import { type ReactNode, useRef } from "react";
|
|
10
|
+
|
|
11
|
+
export function AdminTabContextMenu({
|
|
12
|
+
tabs,
|
|
13
|
+
onCloseOthers,
|
|
14
|
+
children,
|
|
15
|
+
}: {
|
|
16
|
+
tabs: readonly AdminAppTab[];
|
|
17
|
+
onCloseOthers: (tabId: string) => void;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}) {
|
|
20
|
+
const trigger = useRef<HTMLElement | null>(null);
|
|
21
|
+
const tabId = useRef<string | undefined>(undefined);
|
|
22
|
+
|
|
23
|
+
function prepare(event: React.SyntheticEvent) {
|
|
24
|
+
if (!(event.target instanceof Element)) return;
|
|
25
|
+
const item = event.target.closest<HTMLElement>('[data-ug="app-tabs"] [data-ug-slot="item"]');
|
|
26
|
+
const value = item?.dataset.value;
|
|
27
|
+
if (!value || !tabs.some((tab) => tab.id !== value && tab.closable)) {
|
|
28
|
+
event.stopPropagation();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
tabId.current = value;
|
|
32
|
+
trigger.current = item?.querySelector<HTMLElement>('[data-ug-slot="trigger"]') ?? null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function restoreFocus() {
|
|
36
|
+
const target = trigger.current;
|
|
37
|
+
requestAnimationFrame(() => target?.focus({ preventScroll: true }));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<UGContextMenu className="admin-tab-menu">
|
|
42
|
+
<UGContextMenuTrigger
|
|
43
|
+
className="admin-tab-menu__trigger"
|
|
44
|
+
onContextMenuCapture={prepare}
|
|
45
|
+
onKeyDownCapture={(event) => {
|
|
46
|
+
if (event.key === "ContextMenu" || (event.shiftKey && event.key === "F10"))
|
|
47
|
+
prepare(event);
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</UGContextMenuTrigger>
|
|
52
|
+
<UGContextMenuContent aria-label="页签操作">
|
|
53
|
+
<UGContextMenuItem
|
|
54
|
+
onClick={() => {
|
|
55
|
+
if (tabId.current) onCloseOthers(tabId.current);
|
|
56
|
+
restoreFocus();
|
|
57
|
+
}}
|
|
58
|
+
onKeyDown={(event) => {
|
|
59
|
+
if (event.key === "Escape") restoreFocus();
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
关闭其他页签
|
|
63
|
+
</UGContextMenuItem>
|
|
64
|
+
</UGContextMenuContent>
|
|
65
|
+
</UGContextMenu>
|
|
66
|
+
);
|
|
67
|
+
}
|
package/README.md
DELETED