@cdx-ui/utils 0.0.1-beta.60 → 0.0.1-beta.62
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/README.md +38 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,14 +14,14 @@ pnpm add @cdx-ui/utils
|
|
|
14
14
|
|
|
15
15
|
### Common helpers
|
|
16
16
|
|
|
17
|
-
| Export | Description
|
|
18
|
-
| ----------------------------------- |
|
|
19
|
-
| `cn(...inputs)` | Merges class names with `clsx` + `tailwind-merge` — conditionals and conflict resolution in one call.
|
|
20
|
-
| `composeEventHandlers(...handlers)` | Chains multiple event callbacks into a single handler; skips `null`/`undefined` entries.
|
|
21
|
-
| `useControllableState(params)` | Hook that supports both controlled and uncontrolled modes for a single value.
|
|
22
|
-
| `mergeRefs(...refs)` | Combines multiple refs (callback or object) into one ref callback.
|
|
23
|
-
| `flattenChildren(children)` | Recursively flattens React `children` into a flat array
|
|
24
|
-
| `ariaAttr(condition)` | Returns `true` (boolean) or `undefined` — shorthand for boolean ARIA attribute values.
|
|
17
|
+
| Export | Description |
|
|
18
|
+
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
19
|
+
| `cn(...inputs)` | Merges class names with `clsx` + `tailwind-merge` — conditionals and conflict resolution in one call. |
|
|
20
|
+
| `composeEventHandlers(...handlers)` | Chains multiple event callbacks into a single handler; skips `null`/`undefined` entries. |
|
|
21
|
+
| `useControllableState(params)` | Hook that supports both controlled and uncontrolled modes for a single value. Derives `isControlled` from whether the prop is `undefined`. |
|
|
22
|
+
| `mergeRefs(...refs)` | Combines multiple refs (callback or object) into one ref callback. |
|
|
23
|
+
| `flattenChildren(children)` | Recursively flattens React `children` (including Fragments) into a flat array with re-keyed elements. |
|
|
24
|
+
| `ariaAttr(condition)` | Returns `true` (boolean) or `undefined` — shorthand for boolean ARIA attribute values. |
|
|
25
25
|
|
|
26
26
|
### Context
|
|
27
27
|
|
|
@@ -43,13 +43,36 @@ Used internally by `@cdx-ui/components` to propagate variant props (size, color,
|
|
|
43
43
|
|
|
44
44
|
Low-level form-field state used by the `Field` and `Input` primitives.
|
|
45
45
|
|
|
46
|
-
| Export
|
|
47
|
-
|
|
|
48
|
-
| `useFormControlRoot(props)`
|
|
49
|
-
| `useFormControl(props)`
|
|
50
|
-
| `useFormControlContext()`
|
|
51
|
-
| `useReportFormControlLabelFocus(
|
|
52
|
-
| `FormControlContext`
|
|
46
|
+
| Export | Description |
|
|
47
|
+
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `useFormControlRoot(props)` | Creates the root state object for a form field (id generation, tracks `hasFeedbackText`/`hasHelpText` for describedby assembly). |
|
|
49
|
+
| `useFormControl(props)` | Merges component-level props with inherited form-control context. Assembles `aria-describedby` from feedback/help text ids. |
|
|
50
|
+
| `useFormControlContext()` | Reads form-control state from the nearest provider. |
|
|
51
|
+
| `useReportFormControlLabelFocus(isActive)` | Reports focus/active state to the parent `FormControlContext` — used by `Input`/`Select.Trigger` to trigger `isFocused` styling on the associated label. |
|
|
52
|
+
| `FormControlContext` | The React context object for form-control state propagation. |
|
|
53
|
+
|
|
54
|
+
## Exported types
|
|
55
|
+
|
|
56
|
+
| Type | Source |
|
|
57
|
+
| ---------------------------- | ------------ |
|
|
58
|
+
| `UseControllableStateParams` | common |
|
|
59
|
+
| `FormControlContextValue` | form-control |
|
|
60
|
+
| `FormControlFieldProps` | form-control |
|
|
61
|
+
| `FormControlRootProps` | form-control |
|
|
62
|
+
| `FormControlRootReturn` | form-control |
|
|
63
|
+
| `FormControlState` | form-control |
|
|
64
|
+
| `StyleContextMap` | style |
|
|
65
|
+
| `WithStyleContextProps` | style |
|
|
66
|
+
|
|
67
|
+
## Testing
|
|
68
|
+
|
|
69
|
+
Tests are colocated next to source files (`*.test.{ts,tsx}`). Run via the `utils` Jest project:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm nx run @cdx-ui/utils:test
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
All runtime exports have test coverage using `@testing-library/react-native` (`renderHook`, `act`).
|
|
53
76
|
|
|
54
77
|
## Further reading
|
|
55
78
|
|