@fiscozen/composables 1.0.3 → 1.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @fiscozen/composables
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - a243ebb: Fix mobile dropdown menu issues: tapping the icon dropdown trigger again now closes the menu (it previously only ever re-opened it), and the floating menu no longer jumps to the top-left corner when its opener becomes hidden (e.g. an accordion collapses while the menu is still open).
8
+
3
9
  ## 1.0.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,5 +1,108 @@
1
1
  # @fiscozen/composables
2
2
 
3
- ## useFloating and FzFloating
4
- This composable holds logic that can be added to a component in order to be positioned correctly as a floating window.
5
- The default "component wrapper" of the composable is `FzFloating`.
3
+ > For usage documentation, see [Storybook Documentation](../../apps/storybook/src/Composables.mdx)
4
+
5
+ ## Development
6
+
7
+ ### Setup
8
+
9
+ ```bash
10
+ pnpm install
11
+ pnpm --filter @fiscozen/composables build
12
+ ```
13
+
14
+ ### Code Organization
15
+
16
+ ```
17
+ src/
18
+ index.ts Re-exports everything (composables, types, utils, FzFloating)
19
+ types.ts Shared types (FzFloatingPosition, FzRect, FzUseCurrencyOptions, etc.)
20
+ utils/
21
+ index.ts Barrel file for utilities
22
+ number/
23
+ index.ts Currency format/parse helpers
24
+ position/
25
+ index.ts Floating position calculation helpers
26
+ FzFloating.vue Component wrapper for useFloating
27
+ composables/
28
+ index.ts Barrel file for all composables
29
+ useFloating.ts Floating element positioning
30
+ useMediaQuery.ts Reactive CSS media query matching
31
+ useBreakpoints.ts Responsive breakpoint detection (wraps useMediaQuery)
32
+ useClickOutside.ts Click-outside detection
33
+ useKeyDown.ts Keydown event listener
34
+ useKeyUp.ts Keyup event listener
35
+ useCurrency.ts Currency formatting (deprecated)
36
+ __tests__/
37
+ useFloating.spec.ts useFloating unit tests
38
+ FzFloating.spec.ts FzFloating component tests
39
+ number.spec.ts Currency/number utility tests
40
+ ```
41
+
42
+ ## Composables
43
+
44
+ ### useFloating
45
+
46
+ Positioning logic for floating/popover elements (tooltips, dropdowns, popovers).
47
+
48
+ **Architecture:**
49
+
50
+ - **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).
51
+ - **Auto-position resolution**: `resolveAutoPosition` delegates to `getHighestAvailableSpacePos` for `auto`, `auto-vertical`, `auto-start`, `auto-end`, and their combinations.
52
+ - **Boundary corrections**: `applyBoundaryCorrections` clamps the final position within the container bounds, resetting transforms when the element would overflow.
53
+ - **Layout shift prevention**: The element is set to `position: fixed` immediately before rect calculations.
54
+ - **Reactive repositioning**: Uses `IntersectionObserver` to track visibility changes.
55
+
56
+ The `FzFloating` component (`src/FzFloating.vue`) is the default wrapper that exposes `useFloating` through a declarative template API.
57
+
58
+ ### useMediaQuery
59
+
60
+ 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.
61
+
62
+ ### useBreakpoints
63
+
64
+ 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)`.
65
+
66
+ ### useClickOutside
67
+
68
+ 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.
69
+
70
+ ### useKeyDown
71
+
72
+ Attaches a `keydown` listener to a component ref. Lifecycle-managed (mount/unmount). Throws if component or callback is missing.
73
+
74
+ ### useKeyUp
75
+
76
+ 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.
77
+
78
+ ### useCurrency
79
+
80
+ **Deprecated.** Wraps `format` and `parse` from `src/utils/number`. Consumers should import those functions directly instead.
81
+
82
+ ## Testing
83
+
84
+ ### Running Tests
85
+
86
+ ```bash
87
+ pnpm --filter @fiscozen/composables test:unit
88
+ pnpm --filter @fiscozen/composables coverage
89
+ ```
90
+
91
+ ### Test Structure
92
+
93
+ - `useFloating.spec.ts` / `FzFloating.spec.ts`: Position calculation and component rendering.
94
+ - `number.spec.ts`: Currency format/parse utilities.
95
+
96
+ Tests mock `window.matchMedia` in `beforeEach`. Coverage target: >90%.
97
+
98
+ ## Dependencies
99
+
100
+ - `@fiscozen/style` (workspace) — breakpoint tokens used by `useBreakpoints` / `useMediaQuery`
101
+
102
+ ## Build
103
+
104
+ ```bash
105
+ pnpm --filter @fiscozen/composables build
106
+ ```
107
+
108
+ Runs Vite library build. Output goes to `dist/`.