@fiscozen/composables

中文文档
1.2.0发布于 2026/10/23ISCES Module近 30 天下载 4841

Design System utility composables

原始使用文档
文档目录16 节
  1. Development
  2. Setup
  3. Code Organization
  4. Composables
  5. useFloating
  6. useMediaQuery
  7. useBreakpoints
  8. useClickOutside
  9. useKeyDown
  10. useKeyUp
  11. useCurrency
  12. Testing
  13. Running Tests
  14. Test Structure
  15. Dependencies
  16. Build

@fiscozen/composables

For usage documentation, see Storybook Documentation

Development

Setup

pnpm install
pnpm --filter @fiscozen/composables build

Code Organization

src/
  index.ts                        Re-exports everything (composables, types, utils, FzFloating)
  types.ts                        Shared types (FzFloatingPosition, FzRect, FzUseCurrencyOptions, etc.)
  utils/
    index.ts                      Barrel file for utilities
    number/
      index.ts                    Currency format/parse helpers
    position/
      index.ts                    Floating position calculation helpers
  FzFloating.vue                  Component wrapper for useFloating
  composables/
    index.ts                      Barrel file for all composables
    useFloating.ts                Floating element positioning
    useMediaQuery.ts              Reactive CSS media query matching
    useBreakpoints.ts             Responsive breakpoint detection (wraps useMediaQuery)
    useClickOutside.ts            Click-outside detection
    useKeyDown.ts                 Keydown event listener
    useKeyUp.ts                   Keyup event listener
    useCurrency.ts                Currency formatting (deprecated)
  __tests__/
    useFloating.spec.ts           useFloating unit tests
    FzFloating.spec.ts            FzFloating component tests
    number.spec.ts                Currency/number utility tests

Composables

useFloating

Positioning logic for floating/popover elements (tooltips, dropdowns, popovers).

Architecture:

  • Lookup tables: positionCalculators (with opener) and containerPositionCalculators (without opener) provide O(1) position resolution for all 12 explicit positions (top/bottom/left/right + -start/-end variants).
  • Auto-position resolution: resolveAutoPosition delegates to getHighestAvailableSpacePos for auto, auto-vertical, auto-start, auto-end, and their combinations.
  • Boundary corrections: applyBoundaryCorrections clamps the final position within the container bounds, resetting transforms when the element would overflow.
  • Layout shift prevention: The element is set to position: fixed immediately before rect calculations.
  • Reactive repositioning: Uses IntersectionObserver to track visibility changes.

The FzFloating component (src/FzFloating.vue) is the default wrapper that exposes useFloating through a declarative template API.

useMediaQuery

Reactive wrapper around window.matchMedia. Returns a computed Ref<boolean> that updates when the media query match state changes. Lifecycle-aware: adds listener on mount, removes on unmount.

useBreakpoints

Higher-level abstraction over useMediaQuery for responsive design. Accepts a typed breakpoint map (Record<T, '${number}px'>) and returns isGreater(bp), isSmaller(bp), and isInBetween(min, max).

useClickOutside

Detects clicks outside a target element. Accepts a component ref, a callback, and an optional element to scope the listener to (defaults to document). Supports dynamic listener re-attachment via watch when the scoped element changes.

useKeyDown

Attaches a keydown listener to a component ref. Lifecycle-managed (mount/unmount). Throws if component or callback is missing.

useKeyUp

Attaches a keyup listener to a component ref or to document when no component is provided. Argument order differs from useKeyDown: (callback, component?) — the component is optional.

useCurrency

Deprecated. Wraps format and parse from src/utils/number. Consumers should import those functions directly instead.

Testing

Running Tests

pnpm --filter @fiscozen/composables test:unit
pnpm --filter @fiscozen/composables coverage

Test Structure

  • useFloating.spec.ts / FzFloating.spec.ts: Position calculation and component rendering.
  • number.spec.ts: Currency format/parse utilities.

Tests mock window.matchMedia in beforeEach. Coverage target: >90%.

Dependencies

  • @fiscozen/style (workspace) — breakpoint tokens used by useBreakpoints / useMediaQuery

Build

pnpm --filter @fiscozen/composables build

Runs Vite library build. Output goes to dist/.

版本与发布记录

@fiscozen/composables 共发布 62 个版本,首次发布于 2024/05/14;过去 12 个月发布了 16 个版本。

版本发布日期距今
1.2.0latest2026/10/2322 天前
1.1.62026/10/2025 天前
1.1.52026/09/142 个月前
1.1.42026/09/072 个月前
1.1.32026/08/043 个月前
1.1.22026/08/033 个月前

其他发布通道:beta → 0.1.20-autovertical.2,next → 0.1.39-next.0。

关于 @fiscozen/composables 的常见问题

@fiscozen/composables 是什么?

Design System utility composables

如何安装 @fiscozen/composables?

在项目目录运行 npm install @fiscozen/composables,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.4.13)、tailwindcss(^3.4.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fiscozen/composables 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fiscozen__composables 是否存在。

@fiscozen/composables 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fiscozen/composables 可以商用吗?

@fiscozen/composables 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fiscozen/composables 的下载量有多少?

根据 npm 官方下载统计,@fiscozen/composables 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,841 次,日均约 161 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fiscozen/composables 还在维护吗?

最新版本 1.2.0 发布于 2026/10/23(22 天前);至今共发布 62 个版本,其中过去 12 个月发布了 16 个;首次发布于 2024/05/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。