Utils

Public helper functions exported from the TuffEx root entry and ./utils subpath

Since 1.0.0BETA

This component doc is in progress

This page is still being migrated. Demos and API details may change.

Utils

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

API

Z-index manager

Hands out overlay stacking levels from one source so components do not hard-code conflicting z-index values.

ExportSignatureWhen to use
nextZIndex()() => numberClaim the next incremented level for a new overlay
getZIndex()() => numberRead the current top level without incrementing
refreshZIndex(seed?, reason?)(seed?: number, reason?: string) => numberRecount from a given baseline
resetZIndex(seed?, reason?)(seed?: number, reason?: string) => numberReset to the seed after unmount / in tests
configureZIndex(options)(options) => voidConfigure the base seed and overrides globally
onZIndexEvent(listener)(listener) => () => voidSubscribe to level changes; returns an unsubscribe

Environment guards

SSR-safe checks for browser API availability so you never touch window / document / navigator blindly.

ExportSignatureWhen to use
hasWindow()() => booleanGuard before accessing window
hasDocument()() => booleanGuard before accessing document
hasNavigator()() => booleanGuard before navigator (vibrate, clipboard)

Haptics (vibrate)

Wraps navigator.vibrate with semantic patterns.

ExportSignatureWhen to use
vibrate{ light() … error(), stop, isSupported }Fire a preset directly, e.g. vibrate.success()
useVibrate(type, options?)(type: VibrateType, options?) => voidTrigger one configurable semantic vibration
stopVibrate()() => voidInterrupt an in-progress vibration
isVibrateSupported()() => booleanCapability detection

Toast

A global toast queue that does not require a per-page host (rendering still needs TxToastHost).

ExportSignatureWhen to use
toast(options)(options) => stringShow a toast; returns an id usable to dismiss it
dismissToast(id)(id: string) => voidDismiss a specific toast
clearToasts()() => voidClear every toast

Dialog manager

Serially manages global dialogs by priority with lifecycle callbacks.

ExportSignatureWhen to use
getDialogManager()() => DialogManagerGet the global singleton to queue / open dialogs

Animation

ExportSignatureWhen to use
useFlip(targetRef, opts?)(ref, opts?) => UseFlipReturnRun a FLIP transition on an element (powers TxFlipOverlay)
useAutoResize(targetRef, opts?)(ref, opts?) => UseAutoResizeReturnMeasure and transition size changes (powers TxAutoSizer)

Install helper

ExportSignatureWhen to use
withInstall(component)<T>(component: T) => T & { install }Attach install so a component works with app.use()

Source

  • Barrel: packages/tuffex/packages/components/src/utils/index.ts re-exports packages/tuffex/packages/utils/*.
  • Subpath entry: @talex-touch/tuffex/utils; the root @talex-touch/tuffex entry also folds in these exports.