@octohirono/stitch-design-system 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 +7 -0
- package/dist/components/Accordion/Accordion.d.ts +45 -0
- package/dist/components/Accordion/Accordion.js +26 -0
- package/dist/components/Accordion/accordion.module.js +4 -0
- package/dist/components/Accordion/index.d.ts +2 -0
- package/dist/components/AlertDialog/AlertDialog.d.ts +45 -0
- package/dist/components/AlertDialog/AlertDialog.js +32 -0
- package/dist/components/AlertDialog/alert-dialog.module.js +4 -0
- package/dist/components/AlertDialog/index.d.ts +2 -0
- package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
- package/dist/components/AspectRatio/AspectRatio.js +15 -0
- package/dist/components/AspectRatio/aspect-ratio.module.js +4 -0
- package/dist/components/AspectRatio/index.d.ts +2 -0
- package/dist/components/Avatar/Avatar.d.ts +42 -0
- package/dist/components/Avatar/Avatar.js +21 -0
- package/dist/components/Avatar/avatar.module.js +13 -0
- package/dist/components/Avatar/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +60 -0
- package/dist/components/Button/Button.js +22 -0
- package/dist/components/Button/button.module.js +19 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Card/Card.d.ts +50 -0
- package/dist/components/Card/Card.js +21 -0
- package/dist/components/Card/card.module.js +22 -0
- package/dist/components/Card/index.d.ts +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +45 -0
- package/dist/components/Checkbox/Checkbox.js +56 -0
- package/dist/components/Checkbox/checkbox.module.js +17 -0
- package/dist/components/Checkbox/index.d.ts +2 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +10 -0
- package/dist/components/CodeBlock/CodeBlock.js +50 -0
- package/dist/components/CodeBlock/codeblock.module.js +17 -0
- package/dist/components/CodeBlock/index.d.ts +2 -0
- package/dist/components/Collapse/Collapse.d.ts +38 -0
- package/dist/components/Collapse/Collapse.js +50 -0
- package/dist/components/Collapse/collapse.module.js +13 -0
- package/dist/components/Collapse/index.d.ts +2 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +47 -0
- package/dist/components/ContextMenu/ContextMenu.js +50 -0
- package/dist/components/ContextMenu/context-menu.module.js +13 -0
- package/dist/components/ContextMenu/index.d.ts +2 -0
- package/dist/components/Divider/Divider.d.ts +50 -0
- package/dist/components/Divider/Divider.js +23 -0
- package/dist/components/Divider/divider.module.js +14 -0
- package/dist/components/Divider/index.d.ts +2 -0
- package/dist/components/Drawer/Drawer.d.ts +36 -0
- package/dist/components/Drawer/Drawer.js +76 -0
- package/dist/components/Drawer/drawer.module.js +21 -0
- package/dist/components/Drawer/index.d.ts +2 -0
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +55 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +54 -0
- package/dist/components/DropdownMenu/dropdown-menu.module.js +13 -0
- package/dist/components/DropdownMenu/index.d.ts +2 -0
- package/dist/components/Form/Form.d.ts +20 -0
- package/dist/components/Form/Form.js +105 -0
- package/dist/components/Form/FormItem.d.ts +3 -0
- package/dist/components/Form/FormItem.js +96 -0
- package/dist/components/Form/context.d.ts +22 -0
- package/dist/components/Form/context.js +5 -0
- package/dist/components/Form/form.module.js +25 -0
- package/dist/components/Form/index.d.ts +7 -0
- package/dist/components/Form/types.d.ts +164 -0
- package/dist/components/Form/types.js +6 -0
- package/dist/components/Form/useForm.d.ts +15 -0
- package/dist/components/Form/useForm.js +188 -0
- package/dist/components/Form/validators.d.ts +3 -0
- package/dist/components/Form/validators.js +73 -0
- package/dist/components/HoverCard/HoverCard.d.ts +47 -0
- package/dist/components/HoverCard/HoverCard.js +26 -0
- package/dist/components/HoverCard/hover-card.module.js +9 -0
- package/dist/components/HoverCard/index.d.ts +2 -0
- package/dist/components/Icon/Icon.d.ts +100 -0
- package/dist/components/Icon/Icon.js +150 -0
- package/dist/components/Icon/icon.module.js +7 -0
- package/dist/components/Icon/index.d.ts +2 -0
- package/dist/components/Image/Image.d.ts +50 -0
- package/dist/components/Image/Image.js +95 -0
- package/dist/components/Image/image.module.js +27 -0
- package/dist/components/Image/index.d.ts +2 -0
- package/dist/components/Input/Input.d.ts +41 -0
- package/dist/components/Input/Input.js +62 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/input.module.js +17 -0
- package/dist/components/Label/Label.d.ts +28 -0
- package/dist/components/Label/Label.js +15 -0
- package/dist/components/Label/index.d.ts +2 -0
- package/dist/components/Label/label.module.js +4 -0
- package/dist/components/Loading/Loading.d.ts +22 -0
- package/dist/components/Loading/Loading.js +32 -0
- package/dist/components/Loading/index.d.ts +2 -0
- package/dist/components/Loading/loading.module.js +14 -0
- package/dist/components/Menubar/Menubar.d.ts +64 -0
- package/dist/components/Menubar/Menubar.js +70 -0
- package/dist/components/Menubar/index.d.ts +2 -0
- package/dist/components/Menubar/menubar.module.js +15 -0
- package/dist/components/Modal/Modal.d.ts +38 -0
- package/dist/components/Modal/Modal.js +68 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/modal.module.js +13 -0
- package/dist/components/NavigationMenu/NavigationMenu.d.ts +47 -0
- package/dist/components/NavigationMenu/NavigationMenu.js +47 -0
- package/dist/components/NavigationMenu/index.d.ts +2 -0
- package/dist/components/NavigationMenu/navigation-menu.module.js +16 -0
- package/dist/components/Notification/Notification.d.ts +14 -0
- package/dist/components/Notification/Notification.js +87 -0
- package/dist/components/Notification/NotificationPortal.d.ts +29 -0
- package/dist/components/Notification/NotificationPortal.js +90 -0
- package/dist/components/Notification/index.d.ts +4 -0
- package/dist/components/Notification/notification.module.js +31 -0
- package/dist/components/Notification/types.d.ts +44 -0
- package/dist/components/OtpField/OtpField.d.ts +40 -0
- package/dist/components/OtpField/OtpField.js +20 -0
- package/dist/components/OtpField/index.d.ts +2 -0
- package/dist/components/OtpField/otp-field.module.js +7 -0
- package/dist/components/PasswordInput/PasswordInput.d.ts +36 -0
- package/dist/components/PasswordInput/PasswordInput.js +28 -0
- package/dist/components/PasswordInput/index.d.ts +2 -0
- package/dist/components/PasswordInput/password-input.module.js +4 -0
- package/dist/components/Popover/Popover.d.ts +42 -0
- package/dist/components/Popover/Popover.js +24 -0
- package/dist/components/Popover/index.d.ts +2 -0
- package/dist/components/Popover/popover.module.js +9 -0
- package/dist/components/Progress/Progress.d.ts +44 -0
- package/dist/components/Progress/Progress.js +55 -0
- package/dist/components/Progress/index.d.ts +2 -0
- package/dist/components/Progress/progress.module.js +21 -0
- package/dist/components/Radio/Radio.d.ts +47 -0
- package/dist/components/Radio/Radio.js +102 -0
- package/dist/components/Radio/index.d.ts +2 -0
- package/dist/components/Radio/radio.module.js +17 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +34 -0
- package/dist/components/ScrollArea/ScrollArea.js +34 -0
- package/dist/components/ScrollArea/index.d.ts +2 -0
- package/dist/components/ScrollArea/scroll-area.module.js +10 -0
- package/dist/components/Select/Select.d.ts +54 -0
- package/dist/components/Select/Select.js +118 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/Select/select.module.js +24 -0
- package/dist/components/Skeleton/Skeleton.d.ts +71 -0
- package/dist/components/Skeleton/Skeleton.js +147 -0
- package/dist/components/Skeleton/index.d.ts +2 -0
- package/dist/components/Skeleton/skeleton.module.js +16 -0
- package/dist/components/Slider/Slider.d.ts +58 -0
- package/dist/components/Slider/Slider.js +33 -0
- package/dist/components/Slider/index.d.ts +2 -0
- package/dist/components/Slider/slider.module.js +9 -0
- package/dist/components/Switch/Switch.d.ts +50 -0
- package/dist/components/Switch/Switch.js +43 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/switch.module.js +15 -0
- package/dist/components/Table/Table.d.ts +65 -0
- package/dist/components/Table/Table.js +75 -0
- package/dist/components/Table/index.d.ts +2 -0
- package/dist/components/Table/table.module.js +21 -0
- package/dist/components/Tabs/Tabs.d.ts +37 -0
- package/dist/components/Tabs/Tabs.js +68 -0
- package/dist/components/Tabs/index.d.ts +2 -0
- package/dist/components/Tabs/tabs.module.js +13 -0
- package/dist/components/Tag/Tag.d.ts +67 -0
- package/dist/components/Tag/Tag.js +54 -0
- package/dist/components/Tag/index.d.ts +2 -0
- package/dist/components/Tag/tag.module.js +28 -0
- package/dist/components/Toggle/Toggle.d.ts +39 -0
- package/dist/components/Toggle/Toggle.js +29 -0
- package/dist/components/Toggle/index.d.ts +2 -0
- package/dist/components/Toggle/toggle.module.js +7 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +88 -0
- package/dist/components/ToggleGroup/ToggleGroup.js +42 -0
- package/dist/components/ToggleGroup/index.d.ts +2 -0
- package/dist/components/ToggleGroup/toggle-group.module.js +8 -0
- package/dist/components/Toolbar/Toolbar.d.ts +116 -0
- package/dist/components/Toolbar/Toolbar.js +72 -0
- package/dist/components/Toolbar/index.d.ts +2 -0
- package/dist/components/Toolbar/toolbar.module.js +14 -0
- package/dist/components/Tooltip/Tooltip.d.ts +41 -0
- package/dist/components/Tooltip/Tooltip.js +38 -0
- package/dist/components/Tooltip/index.d.ts +2 -0
- package/dist/components/Tooltip/tooltip.module.js +21 -0
- package/dist/components/_internal/useOverlay.d.ts +15 -0
- package/dist/components/_internal/useOverlay.js +55 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +43 -0
- package/dist/style.css +3693 -0
- package/package.json +36 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { runRule as e } from "./validators.js";
|
|
2
|
+
import { stringifyNamePath as t } from "./types.js";
|
|
3
|
+
import { useRef as n } from "react";
|
|
4
|
+
//#region packages/react/src/components/Form/useForm.ts
|
|
5
|
+
function r() {
|
|
6
|
+
let e = /* @__PURE__ */ new Map();
|
|
7
|
+
return {
|
|
8
|
+
registerField(n, r, i, a) {
|
|
9
|
+
let o = t(n);
|
|
10
|
+
if (!e.has(o)) e.set(o, {
|
|
11
|
+
key: o,
|
|
12
|
+
rules: r,
|
|
13
|
+
initialValue: i,
|
|
14
|
+
initialSet: i !== void 0,
|
|
15
|
+
currentValue: i,
|
|
16
|
+
notify: a
|
|
17
|
+
});
|
|
18
|
+
else {
|
|
19
|
+
let t = e.get(o);
|
|
20
|
+
t && (t.rules = r, t.notify = a);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
unregisterField(n) {
|
|
24
|
+
e.delete(t(n));
|
|
25
|
+
},
|
|
26
|
+
hasField(n) {
|
|
27
|
+
return e.has(t(n));
|
|
28
|
+
},
|
|
29
|
+
updateRules(n, r) {
|
|
30
|
+
let i = t(n), a = e.get(i);
|
|
31
|
+
a && (a.rules = r);
|
|
32
|
+
},
|
|
33
|
+
notifyAll: () => {
|
|
34
|
+
e.forEach((e) => {
|
|
35
|
+
try {
|
|
36
|
+
e.notify();
|
|
37
|
+
} catch {}
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
forEachField: (t) => {
|
|
41
|
+
e.forEach((e) => {
|
|
42
|
+
t({
|
|
43
|
+
key: e.key,
|
|
44
|
+
rules: e.rules,
|
|
45
|
+
notify: e.notify
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function i(e, t = "", n = {}) {
|
|
52
|
+
for (let r of Object.keys(e)) {
|
|
53
|
+
let a = t ? `${t}.${r}` : r, o = e[r];
|
|
54
|
+
typeof o == "object" && o && !Array.isArray(o) ? i(o, a, n) : n[a] = o;
|
|
55
|
+
}
|
|
56
|
+
return n;
|
|
57
|
+
}
|
|
58
|
+
function a(n) {
|
|
59
|
+
let a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = r();
|
|
60
|
+
if (n.initialValues) {
|
|
61
|
+
let e = i(n.initialValues);
|
|
62
|
+
Object.keys(e).forEach((t) => {
|
|
63
|
+
a.set(t, e[t]), o.set(t, e[t]);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function d(e) {
|
|
67
|
+
return a.get(t(e));
|
|
68
|
+
}
|
|
69
|
+
function f(e) {
|
|
70
|
+
let n = {};
|
|
71
|
+
return e === !0 || !e ? a.forEach((e, t) => {
|
|
72
|
+
n[t] = e;
|
|
73
|
+
}) : e.forEach((e) => {
|
|
74
|
+
let r = t(e);
|
|
75
|
+
a.has(r) && (n[r] = a.get(r));
|
|
76
|
+
}), n;
|
|
77
|
+
}
|
|
78
|
+
function p(e, r) {
|
|
79
|
+
let i = t(e), o = a.get(i);
|
|
80
|
+
a.set(i, r), c.add(i), u.forEachField((e) => {
|
|
81
|
+
e.key === i && e.notify();
|
|
82
|
+
}), o !== r && n.onValuesChange?.({ [i]: r }, f(!0));
|
|
83
|
+
}
|
|
84
|
+
function m(e) {
|
|
85
|
+
let t = i(e);
|
|
86
|
+
Object.keys(t).forEach((e) => {
|
|
87
|
+
a.set(e, t[e]), o.has(e) || o.set(e, t[e]);
|
|
88
|
+
}), u.notifyAll();
|
|
89
|
+
}
|
|
90
|
+
function h(e) {
|
|
91
|
+
(e ? e.map(t) : Array.from(a.keys())).forEach((e) => {
|
|
92
|
+
a.set(e, o.get(e)), s.delete(e), c.delete(e);
|
|
93
|
+
}), u.notifyAll();
|
|
94
|
+
}
|
|
95
|
+
function g(e) {
|
|
96
|
+
return c.has(t(e));
|
|
97
|
+
}
|
|
98
|
+
function _(e) {
|
|
99
|
+
return l.has(t(e));
|
|
100
|
+
}
|
|
101
|
+
function v(e) {
|
|
102
|
+
return s.get(t(e));
|
|
103
|
+
}
|
|
104
|
+
function y(e) {
|
|
105
|
+
e.forEach((e) => {
|
|
106
|
+
let n = t(e.name);
|
|
107
|
+
e.value !== void 0 && a.set(n, e.value), e.errors !== void 0 && (e.errors.length === 0 ? s.delete(n) : s.set(n, e.errors)), e.touched && c.add(n), e.validating ? l.add(n) : l.delete(n);
|
|
108
|
+
}), u.notifyAll();
|
|
109
|
+
}
|
|
110
|
+
async function b(n) {
|
|
111
|
+
let r = [];
|
|
112
|
+
u.forEachField((e) => {
|
|
113
|
+
(!n || n.some((n) => t(n) === e.key)) && r.push({
|
|
114
|
+
key: e.key,
|
|
115
|
+
rules: e.rules
|
|
116
|
+
});
|
|
117
|
+
}), r.forEach((e) => l.add(e.key)), u.notifyAll();
|
|
118
|
+
let i = [];
|
|
119
|
+
if (await Promise.all(r.map(async (t) => {
|
|
120
|
+
let n = a.get(t.key), r = t.rules, o = [];
|
|
121
|
+
for (let t of r) {
|
|
122
|
+
let r = typeof t == "function" ? t(w) : t;
|
|
123
|
+
try {
|
|
124
|
+
await e(r, n);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
o.push(e instanceof Error ? e.message : String(e));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
o.length > 0 ? (s.set(t.key, o), c.add(t.key), i.push({
|
|
130
|
+
name: t.key,
|
|
131
|
+
errors: o
|
|
132
|
+
})) : s.delete(t.key);
|
|
133
|
+
})), r.forEach((e) => l.delete(e.key)), u.notifyAll(), i.length > 0) {
|
|
134
|
+
let e = /* @__PURE__ */ Error("Validation failed");
|
|
135
|
+
throw e.errorFields = i, e.values = f(!0), e;
|
|
136
|
+
}
|
|
137
|
+
return f(!0);
|
|
138
|
+
}
|
|
139
|
+
function x() {
|
|
140
|
+
b().then((e) => {
|
|
141
|
+
n.onFinish?.(e);
|
|
142
|
+
}).catch((e) => {
|
|
143
|
+
e && e.errorFields && e.values !== void 0 && n.onFinishFailed?.({
|
|
144
|
+
values: e.values,
|
|
145
|
+
errorFields: e.errorFields,
|
|
146
|
+
outOfDate: !1
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function S(e) {
|
|
151
|
+
e.onFinish && (n.onFinish = e.onFinish), e.onFinishFailed && (n.onFinishFailed = e.onFinishFailed), e.onValuesChange && (n.onValuesChange = e.onValuesChange);
|
|
152
|
+
}
|
|
153
|
+
function C(e, n) {
|
|
154
|
+
let r = t(e);
|
|
155
|
+
typeof document < "u" && document.querySelector(`[data-field-name="${r}"]`)?.scrollIntoView({
|
|
156
|
+
behavior: "smooth",
|
|
157
|
+
block: "center"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
let w = {
|
|
161
|
+
getFieldValue: d,
|
|
162
|
+
getFieldsValue: f,
|
|
163
|
+
setFieldValue: p,
|
|
164
|
+
setFieldsValue: m,
|
|
165
|
+
resetFields: h,
|
|
166
|
+
validateFields: b,
|
|
167
|
+
submit: x,
|
|
168
|
+
setFields: y,
|
|
169
|
+
isFieldTouched: g,
|
|
170
|
+
isFieldValidating: _,
|
|
171
|
+
getFieldError: v,
|
|
172
|
+
scrollToField: C
|
|
173
|
+
};
|
|
174
|
+
return w.__store = u, w.__bindCallbacks = S, w;
|
|
175
|
+
}
|
|
176
|
+
function o(e) {
|
|
177
|
+
let t = n(null);
|
|
178
|
+
if (!t.current) {
|
|
179
|
+
let n = a({
|
|
180
|
+
...e,
|
|
181
|
+
submit: () => n.submit()
|
|
182
|
+
});
|
|
183
|
+
t.current = n;
|
|
184
|
+
}
|
|
185
|
+
return [t.current];
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
export { o as useForm };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region packages/react/src/components/Form/validators.ts
|
|
2
|
+
var e = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, t = /^(https?:\/\/)[^\s/$.?#].[^\s]*$/i;
|
|
3
|
+
function n(n, r) {
|
|
4
|
+
switch (r) {
|
|
5
|
+
case "string": return typeof n == "string";
|
|
6
|
+
case "number":
|
|
7
|
+
if (typeof n == "number") return !Number.isNaN(n);
|
|
8
|
+
if (typeof n == "string") {
|
|
9
|
+
let e = Number(n);
|
|
10
|
+
return n.trim() !== "" && !Number.isNaN(e);
|
|
11
|
+
}
|
|
12
|
+
return !1;
|
|
13
|
+
case "boolean": return typeof n == "boolean";
|
|
14
|
+
case "integer":
|
|
15
|
+
if (typeof n == "number") return Number.isInteger(n);
|
|
16
|
+
if (typeof n == "string") {
|
|
17
|
+
if (n.trim() === "") return !1;
|
|
18
|
+
let e = Number(n);
|
|
19
|
+
return !Number.isNaN(e) && Number.isInteger(e);
|
|
20
|
+
}
|
|
21
|
+
return !1;
|
|
22
|
+
case "float":
|
|
23
|
+
if (typeof n == "number") return !Number.isInteger(n);
|
|
24
|
+
if (typeof n == "string") {
|
|
25
|
+
let e = Number(n);
|
|
26
|
+
return !Number.isNaN(e) && !Number.isInteger(e);
|
|
27
|
+
}
|
|
28
|
+
return !1;
|
|
29
|
+
case "array": return Array.isArray(n);
|
|
30
|
+
case "object": return typeof n == "object" && !!n && !Array.isArray(n) && !(n instanceof Date) && !(n instanceof RegExp);
|
|
31
|
+
case "email": return typeof n == "string" && e.test(n);
|
|
32
|
+
case "url": return typeof n == "string" && t.test(n);
|
|
33
|
+
case "date": return n instanceof Date && !Number.isNaN(n.getTime());
|
|
34
|
+
default: return !0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function r(e, t) {
|
|
38
|
+
if (typeof e == "number") return e;
|
|
39
|
+
if (typeof e == "string" && (t === "number" || t === "integer" || t === "float")) {
|
|
40
|
+
let t = Number(e);
|
|
41
|
+
if (!Number.isNaN(t)) return t;
|
|
42
|
+
}
|
|
43
|
+
return e;
|
|
44
|
+
}
|
|
45
|
+
function i(e, t = !1) {
|
|
46
|
+
return e == null ? !0 : typeof e == "string" ? !!(e === "" || t && /^\s+$/.test(e)) : Array.isArray(e) ? e.length === 0 : !1;
|
|
47
|
+
}
|
|
48
|
+
async function a(e, t) {
|
|
49
|
+
let a = i(t, e.whitespace);
|
|
50
|
+
if (e.required && a) throw Error(e.message ?? "此项为必填");
|
|
51
|
+
if (!a) {
|
|
52
|
+
if (e.type && !n(t, e.type)) throw Error(e.message ?? `类型应为 ${e.type}`);
|
|
53
|
+
if (typeof e.min == "number") {
|
|
54
|
+
let n = r(t, e.type), i = typeof n == "number" ? n : n.length;
|
|
55
|
+
if (typeof i == "number" && i < e.min) throw Error(e.message ?? `不能少于 ${e.min}`);
|
|
56
|
+
}
|
|
57
|
+
if (typeof e.max == "number") {
|
|
58
|
+
let n = r(t, e.type), i = typeof n == "number" ? n : n.length;
|
|
59
|
+
if (typeof i == "number" && i > e.max) throw Error(e.message ?? `不能多于 ${e.max}`);
|
|
60
|
+
}
|
|
61
|
+
if (typeof e.len == "number") {
|
|
62
|
+
let n = r(t, e.type), i = typeof n == "number" ? n : n.length;
|
|
63
|
+
if (typeof i == "number" && i !== e.len) throw Error(e.message ?? `长度必须为 ${e.len}`);
|
|
64
|
+
}
|
|
65
|
+
if (e.pattern instanceof RegExp && (typeof t != "string" || !e.pattern.test(t))) throw Error(e.message ?? "格式不正确");
|
|
66
|
+
if (typeof e.validator == "function") {
|
|
67
|
+
let n = await e.validator(e, t);
|
|
68
|
+
if (typeof n == "string" && n.length > 0) throw Error(n);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { a as runRule };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 悬浮富信息卡:`trigger` 触发器 + `children` 富内容(头像 / 简介 / 预览之类)+ 延时控制
|
|
4
|
+
* `openDelay` / `closeDelay` + 受控 `open` / 非受控 `defaultOpen` / `onOpenChange`。**hover 触发**、
|
|
5
|
+
* 延时弹出,不抢焦点。
|
|
6
|
+
*
|
|
7
|
+
* 跨-prop 注意事项(三件浮层划清,别混用):
|
|
8
|
+
* - **vs Tooltip**:Tooltip 是短**文字**提示、`role="tooltip"`、快速出现、不含交互;HoverCard 是
|
|
9
|
+
* **hover 触发的富内容卡**(可放头像 / 链接 / 预览),非 tooltip 语义、延时弹出。
|
|
10
|
+
* - **vs Popover**:Popover 是 **click** 触发的可交互浮层、`role="dialog"`、点开后**抢焦点**并做焦点陷阱;
|
|
11
|
+
* HoverCard 是 **hover** 触发、**不抢焦点**(鼠标移走即收),供「顺带一瞥」的补充信息,不是主操作面。
|
|
12
|
+
* - **延时是本组件的核心手感**:`openDelay`(默认 700ms)避免鼠标划过误触,`closeDelay`(默认 300ms)
|
|
13
|
+
* 让指针能移到卡上而不立即消失;两者与底层同名,直接透传。
|
|
14
|
+
* - **面 = 浮起层**(同 Popover 浮层族):卡面走 `--stitch-bg-elevated`(浮起面)+ 深字
|
|
15
|
+
* `--stitch-text-primary`,边框 `--stitch-border`、圆角 `--stitch-radius-card`、阴影
|
|
16
|
+
* `--stitch-shadow-base`;开合态由底层挂的 `data-state` 描(`open` 时淡入),组件不自持显隐 state。
|
|
17
|
+
* - **键盘 / 焦点 / ARIA**(hover / focus 触发、Esc 收、指针出入时序)由底层保证,组件不重复实现。
|
|
18
|
+
*/
|
|
19
|
+
export interface HoverCardProps {
|
|
20
|
+
/** 触发器:任意可承载 hover / focus 的元素(如头像、链接、姓名),卡片锚定其上 */
|
|
21
|
+
trigger: React.ReactNode;
|
|
22
|
+
/** 卡片富内容,可含头像 / 简介 / 链接 / 预览等 */
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
/** 受控显隐(气泡浮层约定:Ant v5 `open`) */
|
|
25
|
+
open?: boolean;
|
|
26
|
+
/** 非受控初始显隐 @default false */
|
|
27
|
+
defaultOpen?: boolean;
|
|
28
|
+
/** 显隐变化回调(气泡浮层约定:Ant v5 `onOpenChange`) */
|
|
29
|
+
onOpenChange?: (open: boolean) => void;
|
|
30
|
+
/** 指针进入触发器到弹出的延时(ms) @default 700 */
|
|
31
|
+
openDelay?: number;
|
|
32
|
+
/** 指针离开到收起的延时(ms) @default 300 */
|
|
33
|
+
closeDelay?: number;
|
|
34
|
+
/** 触发器与卡片的间距(px) @default 8 */
|
|
35
|
+
sideOffset?: number;
|
|
36
|
+
/** 卡片的可及名——无可见标题时用它 */
|
|
37
|
+
'aria-label'?: string;
|
|
38
|
+
/** 卡片的可及名来源:指向卡内标题元素的 id */
|
|
39
|
+
'aria-labelledby'?: string;
|
|
40
|
+
/** 自定义类名(挂到卡面上) */
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 悬浮富信息卡:hover 触发、延时弹出的富内容卡,不抢焦点;
|
|
45
|
+
* 受控(`open`/`onOpenChange`)与非受控(`defaultOpen`)双模式,延时由 `openDelay`/`closeDelay` 调。
|
|
46
|
+
*/
|
|
47
|
+
export declare const HoverCard: React.FC<HoverCardProps>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import e from "./hover-card.module.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import t from "clsx";
|
|
4
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
|
+
import { HoverCard as i } from "radix-ui";
|
|
6
|
+
//#region packages/react/src/components/HoverCard/HoverCard.tsx
|
|
7
|
+
var a = ({ trigger: a, children: o, open: s, defaultOpen: c, onOpenChange: l, openDelay: u, closeDelay: d, sideOffset: f = 8, className: p, "aria-label": m, "aria-labelledby": h }) => /* @__PURE__ */ r(i.Root, {
|
|
8
|
+
open: s,
|
|
9
|
+
defaultOpen: c,
|
|
10
|
+
onOpenChange: l,
|
|
11
|
+
openDelay: u,
|
|
12
|
+
closeDelay: d,
|
|
13
|
+
children: [/* @__PURE__ */ n(i.Trigger, {
|
|
14
|
+
asChild: !0,
|
|
15
|
+
children: a
|
|
16
|
+
}), /* @__PURE__ */ n(i.Portal, { children: /* @__PURE__ */ r(i.Content, {
|
|
17
|
+
className: t(e.content, p),
|
|
18
|
+
sideOffset: f,
|
|
19
|
+
"aria-label": m,
|
|
20
|
+
"aria-labelledby": h,
|
|
21
|
+
children: [o, /* @__PURE__ */ n(i.Arrow, { className: e.arrow })]
|
|
22
|
+
}) })]
|
|
23
|
+
});
|
|
24
|
+
a.displayName = "HoverCard";
|
|
25
|
+
//#endregion
|
|
26
|
+
export { a as HoverCard };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region packages/react/src/components/HoverCard/hover-card.module.less
|
|
2
|
+
var e = "_content_1k47g_1", t = "_arrow_1k47g_22", n = {
|
|
3
|
+
content: e,
|
|
4
|
+
"stitch-hover-card-in": "_stitch-hover-card-in_1k47g_1",
|
|
5
|
+
"stitch-hover-card-out": "_stitch-hover-card-out_1k47g_1",
|
|
6
|
+
arrow: t
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as arrow, e as content, n as default };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare const ICON_PATHS: {
|
|
3
|
+
readonly check: readonly ["M4 12.5l5 5 11-11"];
|
|
4
|
+
readonly close: readonly ["M6 6l12 12", "M18 6L6 18"];
|
|
5
|
+
readonly 'chevron-down': readonly ["M5 9l7 7 7-7"];
|
|
6
|
+
readonly 'chevron-right': readonly ["M9 5l7 7-7 7"];
|
|
7
|
+
readonly search: readonly ["M4 11a7 7 0 1 0 14 0a7 7 0 1 0 -14 0z", "M16.5 16.5L21 21"];
|
|
8
|
+
readonly menu: readonly ["M4 7h16", "M4 12h16", "M4 17h16"];
|
|
9
|
+
readonly info: readonly ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z", "M12 11v5", "M12 7.5h0.01"];
|
|
10
|
+
readonly success: readonly ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z", "M8 12l3 3 5-6"];
|
|
11
|
+
readonly warning: readonly ["M12 3.5L21.5 20H2.5z", "M12 10v4", "M12 17.5h0.01"];
|
|
12
|
+
readonly error: readonly ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z", "M9 9l6 6", "M15 9l-6 6"];
|
|
13
|
+
readonly dot: readonly ["M12 6a6 6 0 1 0 0 12a6 6 0 1 0 0-12z"];
|
|
14
|
+
readonly eye: readonly ["M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z", "M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0z"];
|
|
15
|
+
readonly 'eye-off': readonly ["M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94", "M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19", "M14.12 14.12a3 3 0 1 1-4.24-4.24", "M1 1l22 22"];
|
|
16
|
+
readonly bold: readonly ["M7 5h6a3.5 3.5 0 0 1 0 7H7z", "M7 12h7a3.5 3.5 0 0 1 0 7H7z"];
|
|
17
|
+
readonly italic: readonly ["M10 5h8", "M6 19h8", "M15 5l-6 14"];
|
|
18
|
+
readonly underline: readonly ["M7 5v6a5 5 0 0 0 10 0V5", "M6 20h12"];
|
|
19
|
+
readonly 'align-left': readonly ["M4 6h16", "M4 12h10", "M4 18h13"];
|
|
20
|
+
readonly 'align-center': readonly ["M4 6h16", "M7 12h10", "M6 18h12"];
|
|
21
|
+
readonly 'align-right': readonly ["M4 6h16", "M10 12h10", "M7 18h13"];
|
|
22
|
+
};
|
|
23
|
+
export type IconName = keyof typeof ICON_PATHS;
|
|
24
|
+
/**
|
|
25
|
+
* 图标基元:内置具名图标 `name`(或自定义 `src`)+ `size` + `label`(可访问名)+
|
|
26
|
+
* `strokeWidth`。`extends HTMLAttributes<span>`,`...rest` 透传到根 `<span>`。
|
|
27
|
+
*
|
|
28
|
+
* 跨-prop 注意事项:
|
|
29
|
+
* - **纯呈现基元**——不是交互控件(要当按钮用请自挂 handler/role)。
|
|
30
|
+
* - **`name` 与 `src` 二选一**:同时给出时 `name`(内置字形)优先。
|
|
31
|
+
* - **内置字形**是内联 `<svg>`、描边走 `currentColor`,随 `color` 换色——设
|
|
32
|
+
* `style={{ color: 'var(--stitch-accent)' }}`(或任一角色变量)换肤;默认
|
|
33
|
+
* `var(--stitch-text-secondary)`。
|
|
34
|
+
* - **Accessibility**:有意义图标传 `label`(`role="img"` + `aria-label`);纯装饰图标省略
|
|
35
|
+
* (`aria-hidden`)。
|
|
36
|
+
* - **Do NOT** 在消费代码里传 emoji / Unicode 符号 / 手搓 `<svg>`——一律经 `<Icon>`。
|
|
37
|
+
*/
|
|
38
|
+
export interface IconProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
39
|
+
/** 内置具名图标。与 src 二选一(同时给以 name 优先) */
|
|
40
|
+
name?: IconName;
|
|
41
|
+
/** 自定义图标资源 URL(大图 / 光栅)。与 name 二选一 */
|
|
42
|
+
src?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 尺寸:数字按 px,字符串原样(如 '1em' / '100%')。
|
|
45
|
+
* @default 24
|
|
46
|
+
*/
|
|
47
|
+
size?: number | string;
|
|
48
|
+
/**
|
|
49
|
+
* 可访问名。给出 → `role="img"` + `aria-label`(有意义图标,被屏幕阅读器读出);
|
|
50
|
+
* 缺省 → `aria-hidden`(纯装饰,不进可及性树)。
|
|
51
|
+
*/
|
|
52
|
+
label?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 一次性覆盖描边粗细(仅 name 内联图标)。默认走角色变量
|
|
55
|
+
* `--stitch-icon-stroke-width`(每站 adapter 定,non-scaling 恒定像素)。
|
|
56
|
+
*/
|
|
57
|
+
strokeWidth?: number | string;
|
|
58
|
+
}
|
|
59
|
+
export declare const Icon: React.FC<IconProps>;
|
|
60
|
+
export declare const ICON_LIST: readonly [{
|
|
61
|
+
readonly name: 'check';
|
|
62
|
+
readonly label: 'Check';
|
|
63
|
+
}, {
|
|
64
|
+
readonly name: 'close';
|
|
65
|
+
readonly label: 'Close';
|
|
66
|
+
}, {
|
|
67
|
+
readonly name: 'chevron-down';
|
|
68
|
+
readonly label: 'Chevron down';
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: 'chevron-right';
|
|
71
|
+
readonly label: 'Chevron right';
|
|
72
|
+
}, {
|
|
73
|
+
readonly name: 'search';
|
|
74
|
+
readonly label: 'Search';
|
|
75
|
+
}, {
|
|
76
|
+
readonly name: 'menu';
|
|
77
|
+
readonly label: 'Menu';
|
|
78
|
+
}, {
|
|
79
|
+
readonly name: 'info';
|
|
80
|
+
readonly label: 'Info';
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: 'success';
|
|
83
|
+
readonly label: 'Success';
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: 'warning';
|
|
86
|
+
readonly label: 'Warning';
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: 'error';
|
|
89
|
+
readonly label: 'Error';
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: 'dot';
|
|
92
|
+
readonly label: 'Dot';
|
|
93
|
+
}, {
|
|
94
|
+
readonly name: 'eye';
|
|
95
|
+
readonly label: 'Eye';
|
|
96
|
+
}, {
|
|
97
|
+
readonly name: 'eye-off';
|
|
98
|
+
readonly label: 'Eye off';
|
|
99
|
+
}];
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import e from "./icon.module.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import t from "clsx";
|
|
4
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
5
|
+
//#region packages/react/src/components/Icon/Icon.tsx
|
|
6
|
+
var r = {
|
|
7
|
+
check: ["M4 12.5l5 5 11-11"],
|
|
8
|
+
close: ["M6 6l12 12", "M18 6L6 18"],
|
|
9
|
+
"chevron-down": ["M5 9l7 7 7-7"],
|
|
10
|
+
"chevron-right": ["M9 5l7 7-7 7"],
|
|
11
|
+
search: ["M4 11a7 7 0 1 0 14 0a7 7 0 1 0 -14 0z", "M16.5 16.5L21 21"],
|
|
12
|
+
menu: [
|
|
13
|
+
"M4 7h16",
|
|
14
|
+
"M4 12h16",
|
|
15
|
+
"M4 17h16"
|
|
16
|
+
],
|
|
17
|
+
info: [
|
|
18
|
+
"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z",
|
|
19
|
+
"M12 11v5",
|
|
20
|
+
"M12 7.5h0.01"
|
|
21
|
+
],
|
|
22
|
+
success: ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z", "M8 12l3 3 5-6"],
|
|
23
|
+
warning: [
|
|
24
|
+
"M12 3.5L21.5 20H2.5z",
|
|
25
|
+
"M12 10v4",
|
|
26
|
+
"M12 17.5h0.01"
|
|
27
|
+
],
|
|
28
|
+
error: [
|
|
29
|
+
"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0z",
|
|
30
|
+
"M9 9l6 6",
|
|
31
|
+
"M15 9l-6 6"
|
|
32
|
+
],
|
|
33
|
+
dot: ["M12 6a6 6 0 1 0 0 12a6 6 0 1 0 0-12z"],
|
|
34
|
+
eye: ["M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z", "M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0z"],
|
|
35
|
+
"eye-off": [
|
|
36
|
+
"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94",
|
|
37
|
+
"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19",
|
|
38
|
+
"M14.12 14.12a3 3 0 1 1-4.24-4.24",
|
|
39
|
+
"M1 1l22 22"
|
|
40
|
+
],
|
|
41
|
+
bold: ["M7 5h6a3.5 3.5 0 0 1 0 7H7z", "M7 12h7a3.5 3.5 0 0 1 0 7H7z"],
|
|
42
|
+
italic: [
|
|
43
|
+
"M10 5h8",
|
|
44
|
+
"M6 19h8",
|
|
45
|
+
"M15 5l-6 14"
|
|
46
|
+
],
|
|
47
|
+
underline: ["M7 5v6a5 5 0 0 0 10 0V5", "M6 20h12"],
|
|
48
|
+
"align-left": [
|
|
49
|
+
"M4 6h16",
|
|
50
|
+
"M4 12h10",
|
|
51
|
+
"M4 18h13"
|
|
52
|
+
],
|
|
53
|
+
"align-center": [
|
|
54
|
+
"M4 6h16",
|
|
55
|
+
"M7 12h10",
|
|
56
|
+
"M6 18h12"
|
|
57
|
+
],
|
|
58
|
+
"align-right": [
|
|
59
|
+
"M4 6h16",
|
|
60
|
+
"M10 12h10",
|
|
61
|
+
"M7 18h13"
|
|
62
|
+
]
|
|
63
|
+
}, i = /* @__PURE__ */ new Set(["dot"]), a = ({ name: a, src: o, size: s = 24, label: c, strokeWidth: l, className: u, style: d, ...f }) => {
|
|
64
|
+
let p = t(e.icon, u), m = c == null ? { "aria-hidden": !0 } : {
|
|
65
|
+
role: "img",
|
|
66
|
+
"aria-label": c
|
|
67
|
+
}, h = a ? r[a] : void 0, g = a != null && i.has(a);
|
|
68
|
+
return /* @__PURE__ */ n("span", {
|
|
69
|
+
className: p,
|
|
70
|
+
"data-icon": a,
|
|
71
|
+
style: {
|
|
72
|
+
width: s,
|
|
73
|
+
height: s,
|
|
74
|
+
...h ? null : o ? { backgroundImage: `url(${o})` } : null,
|
|
75
|
+
...d
|
|
76
|
+
},
|
|
77
|
+
...m,
|
|
78
|
+
...f,
|
|
79
|
+
children: h ? /* @__PURE__ */ n("svg", {
|
|
80
|
+
className: e["icon-svg"],
|
|
81
|
+
viewBox: "0 0 24 24",
|
|
82
|
+
fill: g ? "currentColor" : "none",
|
|
83
|
+
stroke: g ? "none" : "currentColor",
|
|
84
|
+
strokeWidth: 2,
|
|
85
|
+
strokeLinecap: "round",
|
|
86
|
+
strokeLinejoin: "round",
|
|
87
|
+
"aria-hidden": "true",
|
|
88
|
+
focusable: "false",
|
|
89
|
+
style: l == null ? void 0 : { strokeWidth: l },
|
|
90
|
+
children: h.map((e) => /* @__PURE__ */ n("path", { d: e }, e))
|
|
91
|
+
}) : null
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
a.displayName = "Icon";
|
|
95
|
+
var o = [
|
|
96
|
+
{
|
|
97
|
+
name: "check",
|
|
98
|
+
label: "Check"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "close",
|
|
102
|
+
label: "Close"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "chevron-down",
|
|
106
|
+
label: "Chevron down"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "chevron-right",
|
|
110
|
+
label: "Chevron right"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "search",
|
|
114
|
+
label: "Search"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "menu",
|
|
118
|
+
label: "Menu"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "info",
|
|
122
|
+
label: "Info"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "success",
|
|
126
|
+
label: "Success"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "warning",
|
|
130
|
+
label: "Warning"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "error",
|
|
134
|
+
label: "Error"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "dot",
|
|
138
|
+
label: "Dot"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "eye",
|
|
142
|
+
label: "Eye"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "eye-off",
|
|
146
|
+
label: "Eye off"
|
|
147
|
+
}
|
|
148
|
+
];
|
|
149
|
+
//#endregion
|
|
150
|
+
export { o as ICON_LIST, a as Icon };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type ImageColor = 'default' | 'accent' | 'danger' | 'success' | 'warning' | 'info' | 'cat-1' | 'cat-2' | 'cat-3' | 'cat-4' | 'cat-5' | 'cat-6';
|
|
3
|
+
/**
|
|
4
|
+
* 衬板相框(Ant `Image` `preview` 语义):`src`(必填)+ `alt` + `width` / `height` +
|
|
5
|
+
* `color`(matte 底,语义 + 抽象分类,与同源 Card 对齐)+ `lazy`(原生 `loading="lazy"`)+
|
|
6
|
+
* `preview`(默认 true,点击开大图)+ `onLoad` / `onError`。加载淡入 + 加载失败错误占位 +
|
|
7
|
+
* Portal 大图预览。
|
|
8
|
+
*
|
|
9
|
+
* 跨-prop 注意事项:
|
|
10
|
+
* - **`extends ImgHTMLAttributes<img>`**(`Omit` 掉受控的 `src`/`alt`/`width`/`height`/
|
|
11
|
+
* `onLoad`/`onError`),`...rest` 透传到内层 `<img>`。`color` enum 与 Card 对齐
|
|
12
|
+
* (`default` | `accent` | 语义 | `cat-1…6`);`default` 为中性白面。
|
|
13
|
+
* - **预览键盘 + 焦点管理**:`preview` 开启时相框升格为原生 `<button>`(Enter/Space 开预览);
|
|
14
|
+
* 预览弹层焦点自动落关闭按钮、Tab 圈定在遮罩内、ESC 关闭、关闭后焦点归还触发元素。
|
|
15
|
+
* - **图标走 `<Icon>`**:错误占位 `<Icon name="error">`、关闭按钮 `<Icon name="close">`,非裸
|
|
16
|
+
* `<svg>` / 伪元素叉号;错误占位图标装饰性 `aria-hidden`。
|
|
17
|
+
* - **随 `src` 改 state 用渲染期写法**(`useState` 记 `prevSrc` 立即 bail-out),不在 effect 里
|
|
18
|
+
* `setState`,避级联渲染。
|
|
19
|
+
*/
|
|
20
|
+
export interface ImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'width' | 'height' | 'onLoad' | 'onError'> {
|
|
21
|
+
/** 图片地址(必填) */
|
|
22
|
+
src: string;
|
|
23
|
+
/** 图片替代文本(无障碍);留空表示装饰性图片 */
|
|
24
|
+
alt?: string;
|
|
25
|
+
/** 图片宽度(数字按 px,字符串原样) */
|
|
26
|
+
width?: number | string;
|
|
27
|
+
/** 图片高度(数字按 px,字符串原样) */
|
|
28
|
+
height?: number | string;
|
|
29
|
+
/**
|
|
30
|
+
* 相框底色(matte):`default` 中性白面;语义态 `danger/success/warning/info`;
|
|
31
|
+
* `accent` 强调面;`cat-1…6` 分类色槽(只为「互相区分」,非表状态)。
|
|
32
|
+
* @default 'default'
|
|
33
|
+
*/
|
|
34
|
+
color?: ImageColor;
|
|
35
|
+
/**
|
|
36
|
+
* 是否启用原生懒加载(`loading="lazy"`)
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
lazy?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 点击图片弹出大图预览(Ant Image `preview` 语义)
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
preview?: boolean;
|
|
45
|
+
/** 图片加载完成回调 */
|
|
46
|
+
onLoad?: (e: React.SyntheticEvent<HTMLImageElement>) => void;
|
|
47
|
+
/** 图片加载失败回调 */
|
|
48
|
+
onError?: (e: React.SyntheticEvent<HTMLImageElement>) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare const Image: React.FC<ImageProps>;
|