iter(g131): 新增悬浮操作按钮 floatButton

This commit is contained in:
HIsheR
2026-10-26 15:21:23 +08:00
parent 42e43c0415
commit d9559aee1d
12 changed files with 288 additions and 10 deletions
+22
View File
@@ -0,0 +1,22 @@
import { h } from '@ui-arch/frame';
import type { FloatButtonProps } from './types.js';
/*** 悬浮操作按钮:固定停靠左下 / 右下角,label 缺省为纯图标圆形;返回 fixed 包裹层,挂 body 才不被父级 overflow 裁剪 ***/
export function floatButton(props: FloatButtonProps): HTMLElement {
const cls = ['ua-fab', props.label ? 'has-label' : ''].filter(Boolean).join(' ');
const btn = h('button', {
class: cls,
type: 'button',
'aria-label': props.tooltip ?? props.label ?? '快捷操作', // 纯图标时必须有可读名称
title: props.tooltip ?? null,
},
props.icon ? h('span', { class: 'ua-fab-icon', 'aria-hidden': 'true' }, props.icon) : null,
props.label ? h('span', { class: 'ua-fab-label' }, props.label) : null,
props.badge != null ? h('span', { class: 'ua-fab-badge' }, String(props.badge)) : null);
if (props.onClick) btn.addEventListener('click', props.onClick);
const offset = `${props.offset ?? 24}px`; // 缺省离边 24px,与常见浮动件手感一致
return h('div', {
class: `ua-fab-wrap is-${props.position ?? 'right-bottom'}`,
style: `--ua-fab-offset:${offset}`,
}, btn);
}
+1
View File
@@ -62,3 +62,4 @@ export { popconfirm } from './popconfirm.js';
export { calendar } from './calendar.js';
export { typography } from './typography.js';
export { grid } from './grid.js';
export { floatButton } from './floatButton.js';
+11
View File
@@ -766,4 +766,15 @@ export interface GridProps {
dense?: boolean; // 紧凑填充:小项回填空洞(瀑布式排布);缺省 false
}
/*** 悬浮操作按钮入参 ***/
export interface FloatButtonProps {
icon?: string | Node; // 图标:字符串按字符(emoji / 符号)渲染,传 DOM 原样插入
label?: string; // 文字标签;给了就出「图标 + 文字」胶囊,缺省纯图标圆形
badge?: string | number; // 角标数字或短文案(如 3 / '新');缺省不渲染
tooltip?: string; // 悬停提示,同时用作 aria-label;缺省取 label
position?: 'right-bottom' | 'left-bottom'; // 停靠角落;缺省右下
offset?: number; // 距边距离(px);缺省 24
onClick?: () => void; // 点击回调
}
export type { ColumnDef, RowKey }; // 再导出常用内核类型,方便调用方