组件/Utils 工具函数

Utils 工具函数

TuffEx 通过根入口与 ./utils 子路径导出的公开工具函数

自 1.0.0BETA

当前组件文档正在开发中

该页面正在持续迁移,示例与 API 可能会继续调整。

Utils 工具函数

import { nextZIndex, toast, hasWindow } from '@talex-touch/tuffex/utils'

API

z-index 管理

统一分配浮层层级,避免各组件各写各的 z-index 造成层叠错乱。

导出签名何时用
nextZIndex()() => number新建浮层时取下一个递增层级
getZIndex()() => number只读当前最高层级,不递增
refreshZIndex(seed?, reason?)(seed?: number, reason?: string) => number需要以某个基准重新计数时
resetZIndex(seed?, reason?)(seed?: number, reason?: string) => number卸载 / 测试后重置到种子值
configureZIndex(options)(options) => void全局配置基准种子与覆盖值
onZIndexEvent(listener)(listener) => () => void订阅层级变化,返回取消订阅函数

环境守卫

SSR 安全地检测浏览器 API 是否可用,避免直接访问 window / document / navigator 报错。

导出签名何时用
hasWindow()() => boolean访问 window 前判断
hasDocument()() => boolean访问 document 前判断
hasNavigator()() => boolean访问 navigator(如振动、剪贴板)前判断

触感反馈 vibrate

封装 navigator.vibrate,提供语义化的震动模式。

导出签名何时用
vibrate{ light() … error(), stop, isSupported }直接触发预设震动,如 vibrate.success()
useVibrate(type, options?)(type: VibrateType, options?) => void按语义触发一次自定义配置的震动
stopVibrate()() => void打断进行中的震动
isVibrateSupported()() => boolean能力检测

轻提示 toast

全局 toast 队列,无需在每个页面手动挂宿主(渲染仍需 TxToastHost)。

导出签名何时用
toast(options)(options) => string弹出提示,返回可用于关闭的 id
dismissToast(id)(id: string) => void关闭指定提示
clearToasts()() => void清空所有提示

对话框编排 dialog-manager

按优先级排队、并带生命周期回调地串行管理全局对话框。

导出签名何时用
getDialogManager()() => DialogManager获取全局单例以排队 / 打开对话框

动画

导出签名何时用
useFlip(targetRef, opts?)(ref, opts?) => UseFlipReturn对元素做 FLIP 过渡(TxFlipOverlay 底层)
useAutoResize(targetRef, opts?)(ref, opts?) => UseAutoResizeReturn尺寸自适应测量与过渡(TxAutoSizer 底层)

安装辅助

导出签名何时用
withInstall(component)<T>(component: T) => T & { install }给组件挂 install,支持 app.use() 全局注册

Source

  • 桶文件:packages/tuffex/packages/components/src/utils/index.ts 再导出 packages/tuffex/packages/utils/*
  • 子路径入口:@talex-touch/tuffex/utils;根入口 @talex-touch/tuffex 亦并入这些导出。