@manohub/ui 1.2.13 → 1.2.14
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 +1 -1
- package/dist/components/button/index.d.ts +12 -98
- package/dist/components/button/index.js +17 -41
- package/dist/components/dropdown/dropdown-item.d.ts +88 -0
- package/dist/components/dropdown/dropdown-item.js +84 -0
- package/dist/components/dropdown/dropdown-panel.d.ts +129 -0
- package/dist/components/dropdown/dropdown-panel.js +89 -0
- package/dist/components/dropdown/dropdown-separator.d.ts +1 -0
- package/dist/components/dropdown/dropdown-separator.js +17 -0
- package/dist/components/dropdown/dropdown-shared.d.ts +33 -0
- package/dist/components/dropdown/dropdown-shared.js +8 -0
- package/dist/components/dropdown/index.d.ts +372 -0
- package/dist/components/dropdown/index.js +282 -0
- package/dist/components/select/index.js +2 -1
- package/dist/components/select/select-shared.d.ts +2 -7
- package/dist/components/select/select-shared.js +3 -3
- package/dist/components/select/select-tree.js +2 -1
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/styles/components/button.css +6 -59
- package/dist/styles/components/button.tokens.css +4 -4
- package/dist/styles/components/dropdown.css +124 -0
- package/dist/styles/components/dropdown.tokens.css +16 -0
- package/dist/styles/index.css +2 -0
- package/dist/utils/popover.d.ts +14 -0
- package/dist/utils/popover.js +8 -0
- package/package.json +2 -2
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, watch, onMounted, provide, toRef, createVNode, mergeProps, nextTick } from "vue";
|
|
2
|
+
import { Icon } from "@manohub/icon";
|
|
3
|
+
import { showPanel, hidePanel } from "../../utils/popover.js";
|
|
4
|
+
import { Button } from "../button/index.js";
|
|
5
|
+
import { DropdownItem } from "./dropdown-item.js";
|
|
6
|
+
import { DropdownPanel } from "./dropdown-panel.js";
|
|
7
|
+
import { DropdownSeparator } from "./dropdown-separator.js";
|
|
8
|
+
import { createDropdownPanelId, DROPDOWN_CONTEXT } from "./dropdown-shared.js";
|
|
9
|
+
const dropdownProps = {
|
|
10
|
+
/** 受控开合;给了就是受控(必须接 `update:open` / `v-model:open`) */
|
|
11
|
+
open: {
|
|
12
|
+
type: Boolean,
|
|
13
|
+
default: void 0
|
|
14
|
+
},
|
|
15
|
+
/** 非受控初始开合 */
|
|
16
|
+
defaultOpen: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
20
|
+
/** 内建触发器文案(给 `#trigger` 时不生效) */
|
|
21
|
+
label: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: "更多"
|
|
24
|
+
},
|
|
25
|
+
/** 内建触发器的按钮型 */
|
|
26
|
+
variant: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: "secondary"
|
|
29
|
+
},
|
|
30
|
+
/** 内建触发器尺寸 + 菜单项密度(`sm` 24 / `md` 32 / `lg` 40) */
|
|
31
|
+
size: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: "md"
|
|
34
|
+
},
|
|
35
|
+
/** 整个菜单禁用(触发器不可开、菜单项不响应) */
|
|
36
|
+
disabled: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
/** 面板落在锚点哪一侧 */
|
|
41
|
+
side: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: "bottom"
|
|
44
|
+
},
|
|
45
|
+
/** 两侧对齐;`center` 不写 `data-align` */
|
|
46
|
+
align: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: "start"
|
|
49
|
+
},
|
|
50
|
+
/** 面板最小宽度是否对齐触发器 */
|
|
51
|
+
matchWidth: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false
|
|
54
|
+
},
|
|
55
|
+
/** 选中后是否收起 */
|
|
56
|
+
closeOnSelect: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
default: true
|
|
59
|
+
},
|
|
60
|
+
/** 菜单的可访问名;不给则由触发器的 id 反推 `aria-labelledby` */
|
|
61
|
+
ariaLabel: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: void 0
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const DropdownBase = /* @__PURE__ */ defineComponent({
|
|
67
|
+
name: "Dropdown",
|
|
68
|
+
inheritAttrs: false,
|
|
69
|
+
props: dropdownProps,
|
|
70
|
+
emits: {
|
|
71
|
+
"update:open": (_open) => true,
|
|
72
|
+
openChange: (_open) => true
|
|
73
|
+
},
|
|
74
|
+
slots: Object,
|
|
75
|
+
setup(props, {
|
|
76
|
+
slots,
|
|
77
|
+
attrs,
|
|
78
|
+
emit
|
|
79
|
+
}) {
|
|
80
|
+
const panelId = createDropdownPanelId();
|
|
81
|
+
const triggerId = `${panelId}-trigger`;
|
|
82
|
+
const rootRef = ref(null);
|
|
83
|
+
const panelRef = ref(null);
|
|
84
|
+
const innerOpen = ref(props.defaultOpen);
|
|
85
|
+
const nativeOpen = ref(false);
|
|
86
|
+
const restoreFocus = ref(false);
|
|
87
|
+
const pendingFocus = ref(null);
|
|
88
|
+
const isControlled = computed(() => props.open !== void 0);
|
|
89
|
+
const open = computed(() => props.open ?? innerOpen.value);
|
|
90
|
+
const syncPanel = (next) => {
|
|
91
|
+
if (next === nativeOpen.value) return;
|
|
92
|
+
nativeOpen.value = next;
|
|
93
|
+
try {
|
|
94
|
+
if (next) showPanel(panelRef.value);
|
|
95
|
+
else hidePanel(panelRef.value);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const itemElements = () => [...panelRef.value?.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])') ?? []];
|
|
100
|
+
const focusInitial = () => {
|
|
101
|
+
if (!nativeOpen.value) return;
|
|
102
|
+
const target = pendingFocus.value;
|
|
103
|
+
pendingFocus.value = null;
|
|
104
|
+
const items = itemElements();
|
|
105
|
+
if (!items.length) {
|
|
106
|
+
panelRef.value?.focus({
|
|
107
|
+
preventScroll: true
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const el = target === "last" ? items[items.length - 1] : items[0];
|
|
112
|
+
el.focus({
|
|
113
|
+
preventScroll: true
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const triggerEl = () => rootRef.value?.querySelector("[popovertarget]") ?? rootRef.value?.firstElementChild ?? null;
|
|
117
|
+
const shouldRestoreFocus = () => {
|
|
118
|
+
const active = document.activeElement;
|
|
119
|
+
if (!active || active === document.body) return true;
|
|
120
|
+
if (panelRef.value?.contains(active)) return true;
|
|
121
|
+
return active === triggerEl();
|
|
122
|
+
};
|
|
123
|
+
const close = (reason) => {
|
|
124
|
+
if (reason === "select" || reason === "escape") restoreFocus.value = true;
|
|
125
|
+
if (isControlled.value) {
|
|
126
|
+
emit("update:open", false);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
innerOpen.value = false;
|
|
130
|
+
syncPanel(false);
|
|
131
|
+
};
|
|
132
|
+
const openPanel = (position) => {
|
|
133
|
+
if (props.disabled) return;
|
|
134
|
+
pendingFocus.value = position;
|
|
135
|
+
if (open.value && nativeOpen.value) {
|
|
136
|
+
focusInitial();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isControlled.value) {
|
|
140
|
+
emit("update:open", true);
|
|
141
|
+
if (open.value && !nativeOpen.value) syncPanel(true);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
innerOpen.value = true;
|
|
145
|
+
syncPanel(true);
|
|
146
|
+
};
|
|
147
|
+
const onTriggerKeydown = (event) => {
|
|
148
|
+
if (props.disabled) return;
|
|
149
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
openPanel(event.key === "ArrowDown" ? "first" : "last");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const onPanelKeydown = (event) => {
|
|
155
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
const items = itemElements();
|
|
158
|
+
if (!items.length) return;
|
|
159
|
+
const current = items.indexOf(document.activeElement);
|
|
160
|
+
const dir = event.key === "ArrowDown" ? 1 : -1;
|
|
161
|
+
const next = current < 0 ? dir > 0 ? 0 : items.length - 1 : (current + dir + items.length) % items.length;
|
|
162
|
+
items[next]?.focus();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (event.key === "Home" || event.key === "End") {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
const items = itemElements();
|
|
168
|
+
items[event.key === "Home" ? 0 : items.length - 1]?.focus();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (event.key === "Escape") {
|
|
172
|
+
restoreFocus.value = true;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (event.key === "Tab") {
|
|
176
|
+
requestAnimationFrame(() => {
|
|
177
|
+
if (panelRef.value) close("tab");
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const onPanelFocusout = (event) => {
|
|
182
|
+
const next = event.relatedTarget;
|
|
183
|
+
if (!next) return;
|
|
184
|
+
if (rootRef.value?.contains(next)) return;
|
|
185
|
+
if (!nativeOpen.value) return;
|
|
186
|
+
close("outside");
|
|
187
|
+
};
|
|
188
|
+
const onToggle = (event) => {
|
|
189
|
+
const opening = event.newState === "open";
|
|
190
|
+
nativeOpen.value = opening;
|
|
191
|
+
if (!isControlled.value) innerOpen.value = opening;
|
|
192
|
+
emit("update:open", opening);
|
|
193
|
+
emit("openChange", opening);
|
|
194
|
+
if (opening) {
|
|
195
|
+
restoreFocus.value = false;
|
|
196
|
+
nextTick(focusInitial);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (restoreFocus.value) {
|
|
200
|
+
restoreFocus.value = false;
|
|
201
|
+
nextTick(() => {
|
|
202
|
+
if (shouldRestoreFocus()) triggerEl()?.focus();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
pendingFocus.value = null;
|
|
206
|
+
};
|
|
207
|
+
const triggerProps = () => ({
|
|
208
|
+
id: triggerId,
|
|
209
|
+
popoverTarget: props.disabled ? void 0 : panelId,
|
|
210
|
+
"aria-haspopup": "menu",
|
|
211
|
+
"aria-expanded": open.value ? "true" : "false",
|
|
212
|
+
"aria-controls": panelId,
|
|
213
|
+
onKeydown: onTriggerKeydown,
|
|
214
|
+
disabled: props.disabled || void 0,
|
|
215
|
+
"aria-disabled": props.disabled ? "true" : void 0
|
|
216
|
+
});
|
|
217
|
+
watch(() => props.open, (value) => {
|
|
218
|
+
if (value !== void 0) syncPanel(value);
|
|
219
|
+
}, {
|
|
220
|
+
flush: "post"
|
|
221
|
+
});
|
|
222
|
+
onMounted(() => {
|
|
223
|
+
if (open.value) syncPanel(true);
|
|
224
|
+
});
|
|
225
|
+
provide(DROPDOWN_CONTEXT, {
|
|
226
|
+
close,
|
|
227
|
+
closeOnSelect: toRef(props, "closeOnSelect"),
|
|
228
|
+
disabled: toRef(props, "disabled")
|
|
229
|
+
});
|
|
230
|
+
return () => {
|
|
231
|
+
const trigger = slots.trigger ? slots.trigger({
|
|
232
|
+
triggerProps: triggerProps(),
|
|
233
|
+
open: open.value,
|
|
234
|
+
panelId
|
|
235
|
+
}) : createVNode(Button, mergeProps({
|
|
236
|
+
"variant": props.variant,
|
|
237
|
+
"size": props.size,
|
|
238
|
+
"disabled": props.disabled
|
|
239
|
+
}, {
|
|
240
|
+
id: triggerId,
|
|
241
|
+
popovertarget: props.disabled ? void 0 : panelId,
|
|
242
|
+
"aria-haspopup": "menu",
|
|
243
|
+
"aria-expanded": open.value ? "true" : "false",
|
|
244
|
+
"aria-controls": panelId,
|
|
245
|
+
onKeydown: onTriggerKeydown
|
|
246
|
+
}), {
|
|
247
|
+
default: () => [props.label, createVNode(Icon, {
|
|
248
|
+
"name": "chevron-down",
|
|
249
|
+
"class": "mh-button__caret mh-popup-caret"
|
|
250
|
+
}, null)]
|
|
251
|
+
});
|
|
252
|
+
return createVNode("span", mergeProps({
|
|
253
|
+
"ref": rootRef
|
|
254
|
+
}, attrs, {
|
|
255
|
+
"class": ["mh-dropdown", "mh-popup-host", props.size === "md" ? "" : `mh-dropdown--${props.size}`, attrs.class].filter(Boolean).join(" "),
|
|
256
|
+
"style": attrs.style
|
|
257
|
+
}), [createVNode("span", {
|
|
258
|
+
"class": "mh-popup-anchor"
|
|
259
|
+
}, [trigger]), createVNode(DropdownPanel, {
|
|
260
|
+
"id": panelId,
|
|
261
|
+
"panelRef": panelRef,
|
|
262
|
+
"side": props.side,
|
|
263
|
+
"align": props.align,
|
|
264
|
+
"matchWidth": props.matchWidth,
|
|
265
|
+
"ariaLabel": props.ariaLabel,
|
|
266
|
+
"labelledby": triggerId,
|
|
267
|
+
"onToggle": onToggle,
|
|
268
|
+
"onKeydown": onPanelKeydown,
|
|
269
|
+
"onFocusout": onPanelFocusout
|
|
270
|
+
}, {
|
|
271
|
+
default: () => slots.default?.()
|
|
272
|
+
})]);
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const Dropdown = Object.assign(DropdownBase, {
|
|
277
|
+
Item: DropdownItem,
|
|
278
|
+
Separator: DropdownSeparator
|
|
279
|
+
});
|
|
280
|
+
export {
|
|
281
|
+
Dropdown
|
|
282
|
+
};
|
|
@@ -2,7 +2,8 @@ import { defineComponent, ref, computed, watch, createVNode, Fragment } from "vu
|
|
|
2
2
|
import { SelectList } from "./select-list.js";
|
|
3
3
|
import { SelectPanel } from "./select-panel.js";
|
|
4
4
|
import { SelectTrigger } from "./select-trigger.js";
|
|
5
|
-
import { createSelectPanelId, isGroup, activatableOptions, activatableCount, createTriggerKeydown, optionDomId
|
|
5
|
+
import { createSelectPanelId, isGroup, activatableOptions, activatableCount, createTriggerKeydown, optionDomId } from "./select-shared.js";
|
|
6
|
+
import { showPanel, hidePanel } from "../../utils/popover.js";
|
|
6
7
|
const Select = /* @__PURE__ */ defineComponent({
|
|
7
8
|
name: "Select",
|
|
8
9
|
inheritAttrs: false,
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* 全页唯一)、popover 开合、触发器键盘契约、可激活项的摊平顺序(两件必须同一份)。
|
|
8
8
|
*/
|
|
9
9
|
import type { Ref } from 'vue';
|
|
10
|
+
import { hidePanel, showPanel } from '../../utils/popover';
|
|
11
|
+
export { hidePanel, showPanel };
|
|
10
12
|
/** 选项(平铺项与分组内选项同构) */
|
|
11
13
|
export interface SelectOption {
|
|
12
14
|
label: string;
|
|
@@ -38,13 +40,6 @@ export declare const activatableCount: (items: SelectItem[], creatable: boolean)
|
|
|
38
40
|
export declare const optionDomId: (panelId: string, index: number) => string;
|
|
39
41
|
/** 生成全页唯一的面板 id(随机段与全库其它随机 id 同法) */
|
|
40
42
|
export declare const createSelectPanelId: () => string;
|
|
41
|
-
/**
|
|
42
|
-
* 开 / 收面板 —— 调**原生** `showPopover()` / `hidePopover()`,不是自建浮层逻辑(开合、Esc、点外部关闭、顶层渲染全归
|
|
43
|
-
* 浏览器与 `styles/operations/popup.css`)。先探存在性再调用:jsdom 至今没实现这套 API,直接 `?.()` 会在测试里抛
|
|
44
|
-
* 「不是函数」。
|
|
45
|
-
*/
|
|
46
|
-
export declare const showPanel: (element: HTMLElement | null) => void;
|
|
47
|
-
export declare const hidePanel: (element: HTMLElement | null) => void;
|
|
48
43
|
/** 触发器键盘契约的输入 */
|
|
49
44
|
export interface TriggerKeydownOptions {
|
|
50
45
|
/** 有清除位时才接 `Delete` 清值(与输入框的键盘清除同款) */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { createPanelId } from "../../utils/popover.js";
|
|
2
|
+
import { hidePanel, showPanel } from "../../utils/popover.js";
|
|
1
3
|
const isGroup = (item) => Array.isArray(item.options);
|
|
2
4
|
const activatableOptions = (items) => items.flatMap((item) => isGroup(item) ? item.options : [item]).filter((option) => !option.disabled);
|
|
3
5
|
const activatableCount = (items, creatable) => activatableOptions(items).length + (creatable ? 1 : 0);
|
|
4
6
|
const optionDomId = (panelId, index) => `${panelId}-opt-${index}`;
|
|
5
7
|
const PANEL_ID_PREFIX = "mh-select-";
|
|
6
|
-
const createSelectPanelId = () =>
|
|
7
|
-
const showPanel = (element) => element?.showPopover?.();
|
|
8
|
-
const hidePanel = (element) => element?.hidePopover?.();
|
|
8
|
+
const createSelectPanelId = () => createPanelId(PANEL_ID_PREFIX);
|
|
9
9
|
function createTriggerKeydown(options) {
|
|
10
10
|
return (event) => {
|
|
11
11
|
if (options.readonly) return;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { defineComponent, ref, computed, watch, createVNode, createTextVNode, Fragment } from "vue";
|
|
2
2
|
import { SelectPanel } from "./select-panel.js";
|
|
3
3
|
import { SelectTrigger } from "./select-trigger.js";
|
|
4
|
-
import { createSelectPanelId, createTriggerKeydown
|
|
4
|
+
import { createSelectPanelId, createTriggerKeydown } from "./select-shared.js";
|
|
5
5
|
import { filterTreeNodes, findTreeNode, treeLabel, splitHighlight, treeChildren, treeNodeKey } from "./select-tree-filter.js";
|
|
6
6
|
import { Tree } from "../list/tree.js";
|
|
7
|
+
import { showPanel, hidePanel } from "../../utils/popover.js";
|
|
7
8
|
const SelectTree = /* @__PURE__ */ defineComponent({
|
|
8
9
|
name: "SelectTree",
|
|
9
10
|
inheritAttrs: false,
|
|
@@ -103,9 +103,9 @@ export declare const Tooltip: import("vue").DefineComponent<import("vue").Extrac
|
|
|
103
103
|
content: string;
|
|
104
104
|
title: string;
|
|
105
105
|
align: TooltipAlign;
|
|
106
|
-
action: string;
|
|
107
106
|
side: TooltipSide;
|
|
108
107
|
trigger: TooltipTrigger;
|
|
108
|
+
action: string;
|
|
109
109
|
guide: boolean;
|
|
110
110
|
onAction: () => void;
|
|
111
111
|
}, SlotsType<{
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { List, Tree, type ListNode } from './components/list';
|
|
|
31
31
|
export { ListView, type ListViewProps, type ListViewStatus, type ListViewStatusTone, type ListViewCardItemProps, type ListViewCompound, } from './components/list-view';
|
|
32
32
|
export { Badge, type BadgeTone, type BadgeShape, type BadgeSize, type BadgeDot, type BadgeStatus, } from './components/badge';
|
|
33
33
|
export { Button, Segmented, type ButtonVariant, type ButtonCompound, type ButtonCompoundType, type SegmentedOption, type SegmentedValue, } from './components/button';
|
|
34
|
+
export { Dropdown, type DropdownProps, type DropdownItemProps, type DropdownSide, type DropdownAlign, type DropdownCompound, } from './components/dropdown';
|
|
34
35
|
export { Input, Textarea, NumberInput, type TextareaProps, type NumberInputProps, type InputCompound, type InputCompoundType, } from './components/input';
|
|
35
36
|
export { Search, type SearchProps } from './components/search';
|
|
36
37
|
export { Select, SelectTree, type SelectOption, type SelectValue } from './components/select';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { Text } from "./components/text/index.js";
|
|
|
13
13
|
import { ListView } from "./components/list-view/index.js";
|
|
14
14
|
import { Badge } from "./components/badge/index.js";
|
|
15
15
|
import { Button } from "./components/button/index.js";
|
|
16
|
+
import { Dropdown } from "./components/dropdown/index.js";
|
|
16
17
|
import { Input, Textarea } from "./components/input/index.js";
|
|
17
18
|
import { Search } from "./components/search/index.js";
|
|
18
19
|
import { Select } from "./components/select/index.js";
|
|
@@ -61,6 +62,7 @@ export {
|
|
|
61
62
|
Dialog,
|
|
62
63
|
Divider,
|
|
63
64
|
Drawer,
|
|
65
|
+
Dropdown,
|
|
64
66
|
FILTER_ALL,
|
|
65
67
|
Filter,
|
|
66
68
|
FilterItem,
|
|
@@ -93,15 +93,7 @@
|
|
|
93
93
|
width: var(--ui-button-icon-size-lg);
|
|
94
94
|
height: var(--ui-button-icon-size-lg);
|
|
95
95
|
}
|
|
96
|
-
/*
|
|
97
|
-
`.mh-button--menu` 的 md 缺省值)。
|
|
98
|
-
(原先还有「分割线高度跟档位」两条 —— 菜单按钮自 2026-10-12 起不再渲染分割线,那两条随之撤掉) */
|
|
99
|
-
.mh-button--sm.mh-button--menu {
|
|
100
|
-
padding: 0 var(--ui-button-padding-x-sm);
|
|
101
|
-
}
|
|
102
|
-
.mh-button--lg.mh-button--menu {
|
|
103
|
-
padding: 0 var(--ui-button-padding-x-lg);
|
|
104
|
-
}
|
|
96
|
+
/* 尺寸档的图标槽在上面的 `.mh-button--sm/lg .mh-button__icon, .mh-button__caret` 已统一处理 */
|
|
105
97
|
|
|
106
98
|
/* ===== 外形修饰(与型正交) ===== */
|
|
107
99
|
.mh-button--round {
|
|
@@ -346,7 +338,7 @@
|
|
|
346
338
|
}
|
|
347
339
|
}
|
|
348
340
|
|
|
349
|
-
/* =====
|
|
341
|
+
/* ===== 尾部方向图标槽(Dropdown 的内建触发器 / Button.Group 的「更多」共用) =====
|
|
350
342
|
* **只给槽位尺寸,不给字形**:字形由 `@manohub/icon` 的 `<Icon name="chevron-down">` 画,展开时的转向
|
|
351
343
|
* 由操作层 `popup.css` 的 `.mh-popup-caret` 承担(本件不定义第二份 mask / 第二处转向)。 */
|
|
352
344
|
.mh-button__caret {
|
|
@@ -355,25 +347,6 @@
|
|
|
355
347
|
height: var(--ui-button-icon-size);
|
|
356
348
|
}
|
|
357
349
|
|
|
358
|
-
/* ===== 菜单按钮(文字区 + 箭头区;**不画竖分割线**,色调随修饰符) =====
|
|
359
|
-
分割线原属「文本区 ‖ 分割线 ‖ 箭头区」的三段结构,2026-10-12 按设计口径撤掉:
|
|
360
|
-
线压在实心主色底上太重,把一颗按钮切成两半。两区之间现在靠白空分开。
|
|
361
|
-
|
|
362
|
-
**内距与两区间隔都归容器**(`.mh-button--menu` 自己吃左右内距、用 `gap` 给间隔),
|
|
363
|
-
`label` 与 `caret` 都不再自带内距 / margin —— 间距只由一处拥有,否则「文字 → 箭头」会空出双份
|
|
364
|
-
(与组容器那条 `.mh-button__group > .mh-button--text { padding-inline: 0 }` 同一口径)。 */
|
|
365
|
-
.mh-button--menu {
|
|
366
|
-
padding: 0 var(--ui-button-padding-x);
|
|
367
|
-
gap: var(--ui-button-gap);
|
|
368
|
-
}
|
|
369
|
-
/* 文字区只是文字容器:内距全归 `.mh-button--menu`(这条留着是为了「不吃内距」有据可查) */
|
|
370
|
-
.mh-button__label {
|
|
371
|
-
padding: 0;
|
|
372
|
-
}
|
|
373
|
-
.mh-button--menu .mh-button__caret {
|
|
374
|
-
margin: 0;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
350
|
/* 竖分割线(1px,跟按钮同高)—— 现在只服务 `Button.Divider`(组内分割线),菜单按钮不再渲染它 */
|
|
378
351
|
.mh-button__divider {
|
|
379
352
|
flex: none;
|
|
@@ -494,42 +467,16 @@
|
|
|
494
467
|
outline-offset: -2px;
|
|
495
468
|
}
|
|
496
469
|
|
|
497
|
-
/* ===== 子菜单浮层皮肤(与操作层并列组合:`class="mh-popup mh-button__menu"`) =====
|
|
498
|
-
* 只给面(底 / 圆角 / 内距 / 阴影 / 选项行),开合、Esc、点外部关闭、顶层渲染、定位档全在 popup.css。 */
|
|
499
|
-
.mh-button__menu {
|
|
500
|
-
width: 130px;
|
|
501
|
-
padding: var(--ui-space-1) 6px;
|
|
502
|
-
/* 圆角取容器档(不写硬编码 px,改版时才会跟随);投影取锚定浮层档,不是居中浮层档 */
|
|
503
|
-
border-radius: var(--ui-radius-md);
|
|
504
|
-
background: var(--ui-base-100);
|
|
505
|
-
box-shadow: var(--ui-shadow-popover);
|
|
506
|
-
}
|
|
507
|
-
.mh-button__menu-item {
|
|
508
|
-
height: 30px;
|
|
509
|
-
padding: 0 var(--ui-space-2);
|
|
510
|
-
border-radius: var(--ui-button-radius);
|
|
511
|
-
font-size: var(--ui-button-font-size);
|
|
512
|
-
line-height: 30px;
|
|
513
|
-
color: var(--ui-base-content);
|
|
514
|
-
cursor: pointer;
|
|
515
|
-
}
|
|
516
|
-
.mh-button__menu-item:hover,
|
|
517
|
-
.mh-button__menu-item.is-hover {
|
|
518
|
-
background: var(--ui-base-200);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
470
|
/* ===== 按钮组的收纳面板皮肤(`Button.Group maxVisible` 用)=====
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
* 内距 / 投影),版式不同:这里宽度随内容、每颗按钮独立成行。
|
|
526
|
-
* 开合、Esc、点外部关闭、顶层渲染、定位档仍全在 `operations/popup.css`。 */
|
|
471
|
+
* 这里装的是**原样的 Button**(原 `variant` / `danger` 全保留 —— 「保存是主色、删除是危险色」
|
|
472
|
+
* 这类语义不该因为被收进抽屉就丢掉),要的是**竖排一列按钮**;与动作菜单的 `.mh-dropdown__panel`
|
|
473
|
+
* 是两种面(那边装菜单项)。开合、Esc、点外部关闭、顶层渲染、定位档仍全在 `operations/popup.css`。 */
|
|
527
474
|
.mh-button__group-menu {
|
|
528
475
|
display: flex;
|
|
529
476
|
flex-direction: column;
|
|
530
477
|
align-items: stretch;
|
|
531
478
|
gap: var(--ui-space-1);
|
|
532
|
-
/*
|
|
479
|
+
/* 宽度随最宽那颗按钮(按钮文案可能很长,不能像菜单那样定宽) */
|
|
533
480
|
width: max-content;
|
|
534
481
|
padding: var(--ui-space-1) 6px;
|
|
535
482
|
border-radius: var(--ui-radius-md);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 单件令牌(只服务本件,故不进 `@manohub/theme`)。
|
|
3
3
|
*
|
|
4
|
-
* **本件有一批令牌是「跨分件消费」的**:`--ui-button-group-gap` 归组容器 `.mh-button__group
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* **本件有一批令牌是「跨分件消费」的**:`--ui-button-group-gap` 归组容器 `.mh-button__group`、
|
|
5
|
+
* `--ui-button-height` 归组内分割线 `.mh-button__divider` —— 自定义属性只向下继承,声明在 `.mh-button`
|
|
6
|
+
* 上这类分件取不到值(声明作废且不报错)。锚到容器后**容器是每个分件的祖先**,「把令牌同时声明在
|
|
7
|
+
* 4 个外层类上」那类 workaround 整块撤掉 —— 这正是本文件抽出来的原因。
|
|
8
8
|
* ⚠️ `.mh-<件>--<档>` 这类**档位改写**留在面文件的修饰符块里(拆开会让档位失效)。
|
|
9
9
|
*/
|
|
10
10
|
[data-manohub-ui] {
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dropdown —— 动作菜单皮肤(与操作层并列组合)。
|
|
3
|
+
*
|
|
4
|
+
* 组合方式与选择器同一套:面板根 `class="mh-popup mh-dropdown__panel"`、`popover="auto"`、
|
|
5
|
+
* `data-side` / `data-align` 交给 `popup.css`。**开合 / 定位 / 翻面 / 动画一行都不在这里**:
|
|
6
|
+
* 作者源压过 UA,面板也不写 `display`(否则收起态会被皮肤顶掉,`popup.css` 已有兜底但那是以防万一)。
|
|
7
|
+
*
|
|
8
|
+
* 菜单项是原生 `<button role="menuitem">`(键盘 / 点击语义归原生),故必须自带
|
|
9
|
+
* `border` / `background` / `padding` —— 本包 reset 不替裸按钮归零(`contract-reset` 会按标签扫源码)。
|
|
10
|
+
*
|
|
11
|
+
* 类名与令牌同根:`.mh-dropdown__*` ↔ `--ui-dropdown-*`,与 `button` / `select` 的口径一致。
|
|
12
|
+
*/
|
|
13
|
+
.mh-dropdown {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* 密度档:只改写「项高」这一枚令牌,档位靠同一元素上的变量覆盖生效 */
|
|
18
|
+
.mh-dropdown--sm {
|
|
19
|
+
--ui-dropdown-item-height: var(--ui-control-height-sm);
|
|
20
|
+
}
|
|
21
|
+
.mh-dropdown--lg {
|
|
22
|
+
--ui-dropdown-item-height: var(--ui-control-height-lg);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* ===== 面板(只给面) ===== */
|
|
26
|
+
.mh-dropdown__panel {
|
|
27
|
+
min-width: var(--ui-dropdown-panel-min-width);
|
|
28
|
+
/* 先给固定上限兜底;支持时再按视口收一步(不支持的浏览器会丢掉第二条,保留第一条) */
|
|
29
|
+
max-width: var(--ui-dropdown-panel-max-width);
|
|
30
|
+
max-width: min(var(--ui-dropdown-panel-max-width), calc(100vw - var(--ui-space-4)));
|
|
31
|
+
max-height: var(--ui-dropdown-panel-max-height);
|
|
32
|
+
max-height: min(var(--ui-dropdown-panel-max-height), calc(100dvh - var(--ui-space-4)));
|
|
33
|
+
padding: var(--ui-space-1);
|
|
34
|
+
overflow-y: auto;
|
|
35
|
+
/* 滚到菜单尽头不要接着滚页面(否则面板还开着、页面已经跑远) */
|
|
36
|
+
overscroll-behavior: contain;
|
|
37
|
+
border-radius: var(--ui-radius-md);
|
|
38
|
+
background: var(--ui-base-100);
|
|
39
|
+
box-shadow: var(--ui-shadow-popover);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* 与触发器同宽:`anchor-size` 不支持时整条声明作废,退回上面的令牌最小宽 */
|
|
43
|
+
.mh-dropdown__panel--match-trigger {
|
|
44
|
+
min-width: max(var(--ui-dropdown-panel-min-width), anchor-size(width));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* ===== 菜单项(原生 button;整块可点) ===== */
|
|
48
|
+
.mh-dropdown__item {
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
gap: var(--ui-space-2);
|
|
52
|
+
width: 100%;
|
|
53
|
+
height: var(--ui-dropdown-item-height);
|
|
54
|
+
padding: 0 var(--ui-space-2);
|
|
55
|
+
border: 0;
|
|
56
|
+
border-radius: var(--ui-radius-control);
|
|
57
|
+
background: transparent;
|
|
58
|
+
color: var(--ui-base-content);
|
|
59
|
+
font-family: inherit;
|
|
60
|
+
font-size: var(--ui-font-body);
|
|
61
|
+
line-height: 1;
|
|
62
|
+
text-align: start;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
appearance: none;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* 键盘焦点环;鼠标路径的「高亮」由下面的 :focus 底给出(不另设 data-active) */
|
|
68
|
+
.mh-dropdown__item:focus-visible {
|
|
69
|
+
outline: 2px solid var(--ui-primary);
|
|
70
|
+
outline-offset: -2px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.mh-dropdown__item:not([aria-disabled='true']):hover,
|
|
74
|
+
.mh-dropdown__item:not([aria-disabled='true']):focus {
|
|
75
|
+
background: var(--ui-base-200);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.mh-dropdown__item--danger {
|
|
79
|
+
color: var(--ui-error);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.mh-dropdown__item--danger:not([aria-disabled='true']):hover,
|
|
83
|
+
.mh-dropdown__item--danger:not([aria-disabled='true']):focus {
|
|
84
|
+
background: var(--ui-error-weak);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.mh-dropdown__item[aria-disabled='true'] {
|
|
88
|
+
color: var(--ui-base-content-subtle);
|
|
89
|
+
cursor: not-allowed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* 禁用项即使被点到 / 聚焦也不点亮(语义真假只看 aria-disabled) */
|
|
93
|
+
.mh-dropdown__item[aria-disabled='true']:hover,
|
|
94
|
+
.mh-dropdown__item[aria-disabled='true']:focus {
|
|
95
|
+
background: transparent;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* 文字区:占满剩余宽、超出省略;`title` 由组件按 label 补 */
|
|
99
|
+
.mh-dropdown__label {
|
|
100
|
+
flex: 1;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
overflow: hidden;
|
|
103
|
+
text-overflow: ellipsis;
|
|
104
|
+
white-space: nowrap;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.mh-dropdown__shortcut {
|
|
108
|
+
flex: none;
|
|
109
|
+
color: var(--ui-base-content-subtle);
|
|
110
|
+
font-size: var(--ui-font-caption);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.mh-dropdown__icon {
|
|
114
|
+
flex: none;
|
|
115
|
+
width: var(--ui-font-icon);
|
|
116
|
+
height: var(--ui-font-icon);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ===== 分隔线(声明式 `Dropdown.Separator`) ===== */
|
|
120
|
+
.mh-dropdown__separator {
|
|
121
|
+
height: 1px;
|
|
122
|
+
margin: var(--ui-space-1) 0;
|
|
123
|
+
background: var(--ui-base-300);
|
|
124
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dropdown —— 动作菜单的单件令牌(**基础值**)。
|
|
3
|
+
*
|
|
4
|
+
* 只服务本件,故不随主题进 `@manohub/theme`;锚 `[data-manohub-ui]`(容器是面板与项的祖先)。
|
|
5
|
+
* 面板与项都可能在 top layer,但 DOM 仍在应用容器里 ⇒ 令牌与主题色全程有效
|
|
6
|
+
* (把浮层 portal 到 body 的旧做法拿不到这组值,才会逼着面板写死色值)。
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ `.mh-dropdown--sm` / `--lg` 的档位改写留在面文件:那里靠「同一元素上两个选择器改写同一枚令牌」
|
|
9
|
+
* 生效,搬到本文件就断链。
|
|
10
|
+
*/
|
|
11
|
+
[data-manohub-ui] {
|
|
12
|
+
--ui-dropdown-panel-min-width: 160px;
|
|
13
|
+
--ui-dropdown-panel-max-width: 320px;
|
|
14
|
+
--ui-dropdown-panel-max-height: 320px;
|
|
15
|
+
--ui-dropdown-item-height: 32px;
|
|
16
|
+
}
|
package/dist/styles/index.css
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
/* 表单与选择控件 */
|
|
47
47
|
@import './components/button.tokens.css';
|
|
48
|
+
@import './components/dropdown.tokens.css';
|
|
48
49
|
@import './components/input.tokens.css';
|
|
49
50
|
@import './components/select.tokens.css';
|
|
50
51
|
@import './components/date-picker.tokens.css';
|
|
@@ -103,6 +104,7 @@
|
|
|
103
104
|
|
|
104
105
|
/* 表单与选择控件(按钮 → 输入 → 选择 → 开关 → 勾选 → 单选 → 胶囊) */
|
|
105
106
|
@import './components/button.css';
|
|
107
|
+
@import './components/dropdown.css'; /* 动作菜单:面板皮肤独立,触发器仍复用按钮族 */
|
|
106
108
|
@import './components/input.css';
|
|
107
109
|
@import './components/search.css'; /* 只有「一行里怎么摆」,输入框与按钮的面各自归族(故排在 input.css 之后) */
|
|
108
110
|
@import './components/select.css';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 原生 popover 的三只极简工具(`Select` / `Dropdown` 共用)。
|
|
3
|
+
*
|
|
4
|
+
* 开合、Esc、点外部关闭、顶层渲染全归浏览器;这里只做「先探存在性再调用」——
|
|
5
|
+
* jsdom 至今没实现 `showPopover` / `hidePopover`,直接调用会在测试里抛「不是函数」。
|
|
6
|
+
*/
|
|
7
|
+
export type PopoverHost = HTMLElement & {
|
|
8
|
+
showPopover?: () => void;
|
|
9
|
+
hidePopover?: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** 全页唯一的面板 id(`popovertarget` 按 id 找面板;前缀由调用方给,便于排查) */
|
|
12
|
+
export declare const createPanelId: (prefix: string) => string;
|
|
13
|
+
export declare const showPanel: (element: HTMLElement | null) => void;
|
|
14
|
+
export declare const hidePanel: (element: HTMLElement | null) => void;
|