@cdx-ui/utils 0.0.1-beta.18 → 0.0.1-beta.180

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -28
  3. package/coverage.svg +1 -0
  4. package/lib/commonjs/common/cva.js +13 -0
  5. package/lib/commonjs/common/cva.js.map +1 -0
  6. package/lib/commonjs/common/index.js +7 -0
  7. package/lib/commonjs/common/index.js.map +1 -1
  8. package/lib/commonjs/common/mergeRefs.js +39 -1
  9. package/lib/commonjs/common/mergeRefs.js.map +1 -1
  10. package/lib/commonjs/context/createContext.js +7 -3
  11. package/lib/commonjs/context/createContext.js.map +1 -1
  12. package/lib/commonjs/form-control/index.js +6 -0
  13. package/lib/commonjs/form-control/index.js.map +1 -1
  14. package/lib/commonjs/form-control/useFormControl.js +33 -0
  15. package/lib/commonjs/form-control/useFormControl.js.map +1 -1
  16. package/lib/commonjs/style/index.js +0 -11
  17. package/lib/commonjs/style/index.js.map +1 -1
  18. package/lib/module/common/cva.js +4 -0
  19. package/lib/module/common/cva.js.map +1 -0
  20. package/lib/module/common/index.js +1 -0
  21. package/lib/module/common/index.js.map +1 -1
  22. package/lib/module/common/mergeRefs.js +39 -1
  23. package/lib/module/common/mergeRefs.js.map +1 -1
  24. package/lib/module/context/createContext.js +7 -3
  25. package/lib/module/context/createContext.js.map +1 -1
  26. package/lib/module/form-control/index.js +1 -1
  27. package/lib/module/form-control/index.js.map +1 -1
  28. package/lib/module/form-control/useFormControl.js +33 -0
  29. package/lib/module/form-control/useFormControl.js.map +1 -1
  30. package/lib/module/style/index.js +0 -1
  31. package/lib/module/style/index.js.map +1 -1
  32. package/lib/typescript/common/cva.d.ts +2 -0
  33. package/lib/typescript/common/cva.d.ts.map +1 -0
  34. package/lib/typescript/common/index.d.ts +1 -0
  35. package/lib/typescript/common/index.d.ts.map +1 -1
  36. package/lib/typescript/common/mergeRefs.d.ts +8 -0
  37. package/lib/typescript/common/mergeRefs.d.ts.map +1 -1
  38. package/lib/typescript/context/createContext.d.ts +16 -1
  39. package/lib/typescript/context/createContext.d.ts.map +1 -1
  40. package/lib/typescript/form-control/index.d.ts +1 -1
  41. package/lib/typescript/form-control/index.d.ts.map +1 -1
  42. package/lib/typescript/form-control/useFormControl.d.ts +28 -3
  43. package/lib/typescript/form-control/useFormControl.d.ts.map +1 -1
  44. package/lib/typescript/style/index.d.ts +0 -1
  45. package/lib/typescript/style/index.d.ts.map +1 -1
  46. package/package.json +16 -6
  47. package/src/common/accessibilityUtils.test.ts +12 -0
  48. package/src/common/cn.test.ts +19 -0
  49. package/src/common/composeEventHandlers.test.ts +35 -0
  50. package/src/common/cva.ts +1 -0
  51. package/src/common/getSpacedChild.test.tsx +64 -0
  52. package/src/common/index.ts +1 -0
  53. package/src/common/mergeRefs.test.ts +148 -0
  54. package/src/common/mergeRefs.ts +45 -2
  55. package/src/common/useControllableState.test.tsx +90 -0
  56. package/src/context/createContext.test.tsx +31 -0
  57. package/src/context/createContext.tsx +21 -4
  58. package/src/form-control/index.ts +2 -0
  59. package/src/form-control/useFormControl.test.tsx +214 -0
  60. package/src/form-control/useFormControl.tsx +48 -4
  61. package/src/style/context/index.test.tsx +31 -0
  62. package/src/style/index.tsx +0 -1
  63. package/lib/commonjs/style/withStyleContext/index.js +0 -33
  64. package/lib/commonjs/style/withStyleContext/index.js.map +0 -1
  65. package/lib/module/style/withStyleContext/index.js +0 -28
  66. package/lib/module/style/withStyleContext/index.js.map +0 -1
  67. package/lib/typescript/style/withStyleContext/index.d.ts +0 -6
  68. package/lib/typescript/style/withStyleContext/index.d.ts.map +0 -1
  69. package/src/style/withStyleContext/index.tsx +0 -36
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2026 Digital First Holdings LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @cdx-ui/utils
2
2
 
3
- Shared utilities used across CDS packages.
3
+ ![coverage](https://unpkg.com/@cdx-ui/utils/coverage.svg)
4
+
5
+ Shared utilities used across FDS packages.
4
6
 
5
7
  Provides common helpers for styling, event handling, state management, and context propagation used by [`@cdx-ui/primitives`](../primitives/) and [`@cdx-ui/components`](../components/).
6
8
 
@@ -14,49 +16,75 @@ pnpm add @cdx-ui/utils
14
16
 
15
17
  ### Common helpers
16
18
 
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. Warns in dev if the mode switches during a component's lifetime. |
22
- | `mergeRefs(...refs)` | Combines multiple refs (callback or object) into one ref callback. |
23
- | `flattenChildren(children)` | Recursively flattens React `children` into a flat array (used internally for spaced-child layouts). |
24
- | `ariaAttr(condition)` | Returns `'true'` or `undefined` — shorthand for boolean ARIA attribute values. |
19
+ | Export | Description |
20
+ | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
21
+ | `cn(...inputs)` | Merges class names with `clsx` + `tailwind-merge` — conditionals and conflict resolution in one call. |
22
+ | `composeEventHandlers(...handlers)` | Chains multiple event callbacks into a single handler; skips `null`/`undefined` entries. |
23
+ | `useControllableState(params)` | Hook that supports both controlled and uncontrolled modes for a single value. Derives `isControlled` from whether the prop is `undefined`. |
24
+ | `mergeRefs(...refs)` | Combines multiple refs (callback or object) into one ref callback. |
25
+ | `flattenChildren(children)` | Recursively flattens React `children` (including Fragments) into a flat array with re-keyed elements. |
26
+ | `ariaAttr(condition)` | Returns `true` (boolean) or `undefined` — shorthand for boolean ARIA attribute values. |
27
+ | `cva(base, config)` | Class Variance Authority helper for authoring variant-driven `className` builders. `VariantProps<typeof fn>` derives the prop type. |
25
28
 
26
29
  ### Context
27
30
 
28
- | Export | Description |
29
- | --- | --- |
31
+ | Export | Description |
32
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
30
33
  | `createContext(displayName)` | Wrapper around React's `createContext` that returns a `[Provider, useHook]` tuple. The hook throws a descriptive error if called outside the provider — eliminates silent `undefined` bugs. |
31
34
 
32
35
  ### Style context
33
36
 
34
37
  Used internally by `@cdx-ui/components` to propagate variant props (size, color, etc.) from a compound root to its sub-components.
35
38
 
36
- | Export | Description |
37
- | --- | --- |
38
- | `withStyleContext(Component, scope?)` | HOC that adds a `context` prop and provides it to descendants via `ParentContext`. |
39
- | `useStyleContext(scope?)` | Reads the style context set by the nearest `withStyleContext` wrapper. |
40
- | `useParentContext()` | Reads the full `StyleContextMap` from the nearest provider. |
41
- | `ParentContext` | The raw React context (rarely needed directly). |
39
+ | Export | Description |
40
+ | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | `ParentContext` | React context for propagating variant props from a compound root to sub-components. Wrap children in `<ParentContext.Provider value={...}>`. |
42
+ | `useStyleContext(scope?)` | Reads the style context set by the nearest `ParentContext.Provider`. |
43
+ | `useParentContext()` | Reads the full `StyleContextMap` from the nearest provider. |
42
44
 
43
45
  ### Form control
44
46
 
45
47
  Low-level form-field state used by the `Field` and `Input` primitives.
46
48
 
47
- | Export | Description |
48
- | --- | --- |
49
- | `useFormControlRoot(props)` | Creates the root state object for a form field (id generation, `aria-describedby` wiring). |
50
- | `useFormControl(props)` | Merges component-level props with inherited form-control context. |
51
- | `useFormControlContext()` | Reads form-control state from the nearest provider. |
52
- | `FormControlContext` | The raw React context for form-control state. |
53
- | `FormControlContextValue` | Type: full context shape including field state, `id`, `labelId`, `feedbackId`, `helpTextId`, and setters. |
54
- | `FormControlState` | Type: `{ isRequired, isInvalid, isDisabled, isReadOnly }`. |
55
- | `FormControlRootProps` | Type: input props for `useFormControlRoot`. |
56
- | `FormControlRootReturn` | Type: return value of `useFormControlRoot` (`htmlProps` + context fields). |
57
- | `FormControlFieldProps` | Type: props accepted by `useFormControl` (field state flags + `id`). |
49
+ | Export | Description |
50
+ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
51
+ | `useFormControlRoot(props)` | Creates the root state object for a form field (id generation, tracks `hasFeedbackText`/`hasHelpText` for describedby assembly). |
52
+ | `useFormControl(props)` | Merges component-level props with inherited form-control context. Assembles `aria-describedby` from feedback/help text ids. |
53
+ | `useFormControlContext()` | Reads form-control state from the nearest provider. |
54
+ | `useReportFormControlLabelFocus(isActive)` | Reports focus/active state to the parent `FormControlContext` — used by `Input`/`Select.Trigger` to trigger `isFocused` styling on the associated label. |
55
+ | `FormControlContext` | The React context object for form-control state propagation. |
56
+
57
+ ## Exported types
58
+
59
+ | Type | Source |
60
+ | ---------------------------- | ------------ |
61
+ | `UseControllableStateParams` | common |
62
+ | `VariantProps` | common |
63
+ | `Focusable` | form-control |
64
+ | `FormControlContextValue` | form-control |
65
+ | `FormControlFieldProps` | form-control |
66
+ | `FormControlRootProps` | form-control |
67
+ | `FormControlRootReturn` | form-control |
68
+ | `FormControlState` | form-control |
69
+ | `StyleContextMap` | style |
70
+
71
+ ## Testing
72
+
73
+ Tests are colocated next to source files (`*.test.{ts,tsx}`). Run via the `utils` Jest project:
74
+
75
+ ```bash
76
+ pnpm nx run @cdx-ui/utils:test
77
+ ```
78
+
79
+ All runtime exports have test coverage using `@testing-library/react-native` (`renderHook`, `act`).
58
80
 
59
81
  ## Further reading
60
82
 
61
83
  - [State management practices](../../docs/internal/practices/state.md) — `useControllableState` and `composeEventHandlers` patterns
62
84
  - [Styling practices](../../docs/internal/practices/styling.md) — `cn()` and CVA variant authoring
85
+
86
+ ## License
87
+
88
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
89
+
90
+ MIT © 2026 Digital First Holdings LLC. See [LICENSE](./LICENSE) for details.
package/coverage.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="114" height="20" role="img" aria-label="coverage: 100.0%"><title>coverage: 100.0%</title><filter id="blur"><feGaussianBlur stdDeviation="16"/></filter><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#4b0"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><g transform="scale(.1)"><g aria-hidden="true" fill="#010101"><text x="315" y="150" fill-opacity=".8" filter="url(#blur)" textLength="510">coverage</text><text x="315" y="150" fill-opacity=".3" textLength="510">coverage</text></g><text x="315" y="140" textLength="510">coverage</text></g><g transform="scale(.1)"><g aria-hidden="true" fill="#010101"><text x="865" y="150" fill-opacity=".8" filter="url(#blur)" textLength="430">100.0%</text><text x="865" y="150" fill-opacity=".3" textLength="430">100.0%</text></g><text x="865" y="140" textLength="430">100.0%</text></g></g></svg>
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "cva", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _classVarianceAuthority.cva;
10
+ }
11
+ });
12
+ var _classVarianceAuthority = require("class-variance-authority");
13
+ //# sourceMappingURL=cva.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_classVarianceAuthority","require"],"sourceRoot":"../../../src","sources":["common/cva.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,uBAAA,GAAAC,OAAA","ignoreList":[]}
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "composeEventHandlers", {
21
21
  return _composeEventHandlers.composeEventHandlers;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "cva", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _cva.cva;
28
+ }
29
+ });
24
30
  Object.defineProperty(exports, "flattenChildren", {
25
31
  enumerable: true,
26
32
  get: function () {
@@ -41,6 +47,7 @@ Object.defineProperty(exports, "useControllableState", {
41
47
  });
42
48
  var _accessibilityUtils = require("./accessibilityUtils");
43
49
  var _cn = require("./cn");
50
+ var _cva = require("./cva");
44
51
  var _composeEventHandlers = require("./composeEventHandlers");
45
52
  var _getSpacedChild = require("./getSpacedChild");
46
53
  var _mergeRefs = require("./mergeRefs");
@@ -1 +1 @@
1
- {"version":3,"names":["_accessibilityUtils","require","_cn","_composeEventHandlers","_getSpacedChild","_mergeRefs","_useControllableState"],"sourceRoot":"../../../src","sources":["common/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,GAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_accessibilityUtils","require","_cn","_cva","_composeEventHandlers","_getSpacedChild","_mergeRefs","_useControllableState"],"sourceRoot":"../../../src","sources":["common/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,GAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,qBAAA,GAAAN,OAAA","ignoreList":[]}
@@ -4,15 +4,53 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mergeRefs = mergeRefs;
7
+ /**
8
+ * Merges multiple refs (object or callback) into a single callback ref.
9
+ *
10
+ * Supports React 19 ref-cleanup semantics: if an inner callback ref returns a
11
+ * cleanup function, that cleanup is captured and invoked when the merged ref is
12
+ * detached — either via the returned cleanup (React 19) or via a subsequent
13
+ * call with `null` (React 18 backward-compat path).
14
+ */
7
15
  function mergeRefs(...refs) {
8
16
  return value => {
17
+ if (value === null) {
18
+ for (const ref of refs) {
19
+ if (typeof ref === 'function') {
20
+ ref(null);
21
+ } else if (ref != null) {
22
+ ref.current = null;
23
+ }
24
+ }
25
+ return undefined;
26
+ }
27
+ const cleanups = [];
9
28
  for (const ref of refs) {
10
29
  if (typeof ref === 'function') {
11
- ref(value);
30
+ cleanups.push(ref(value));
12
31
  } else if (ref != null) {
13
32
  ref.current = value;
33
+ cleanups.push(undefined);
34
+ } else {
35
+ cleanups.push(undefined);
14
36
  }
15
37
  }
38
+ return () => {
39
+ for (let i = 0; i < refs.length; i++) {
40
+ const ref = refs[i];
41
+ if (ref == null) continue;
42
+ if (typeof ref === 'function') {
43
+ const refCleanup = cleanups[i];
44
+ if (typeof refCleanup === 'function') {
45
+ refCleanup();
46
+ } else {
47
+ ref(null);
48
+ }
49
+ } else {
50
+ ref.current = null;
51
+ }
52
+ }
53
+ };
16
54
  };
17
55
  }
18
56
  //# sourceMappingURL=mergeRefs.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["mergeRefs","refs","value","ref","current"],"sourceRoot":"../../../src","sources":["common/mergeRefs.ts"],"mappings":";;;;;;AAEO,SAASA,SAASA,CAAI,GAAGC,IAA4B,EAAkB;EAC5E,OAAQC,KAAe,IAAK;IAC1B,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;MACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;QAC7BA,GAAG,CAACD,KAAK,CAAC;MACZ,CAAC,MAAM,IAAIC,GAAG,IAAI,IAAI,EAAE;QACtBA,GAAG,CAACC,OAAO,GAAGF,KAAK;MACrB;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["mergeRefs","refs","value","ref","current","undefined","cleanups","push","i","length","refCleanup"],"sourceRoot":"../../../src","sources":["common/mergeRefs.ts"],"mappings":";;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,SAASA,CAAI,GAAGC,IAA4B,EAAkB;EAC5E,OAAQC,KAAe,IAA4B;IACjD,IAAIA,KAAK,KAAK,IAAI,EAAE;MAClB,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;QACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;UAC7BA,GAAG,CAAC,IAAI,CAAC;QACX,CAAC,MAAM,IAAIA,GAAG,IAAI,IAAI,EAAE;UACtBA,GAAG,CAACC,OAAO,GAAG,IAAI;QACpB;MACF;MACA,OAAOC,SAAS;IAClB;IAEA,MAAMC,QAAmC,GAAG,EAAE;IAC9C,KAAK,MAAMH,GAAG,IAAIF,IAAI,EAAE;MACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;QAC7BG,QAAQ,CAACC,IAAI,CAACJ,GAAG,CAACD,KAAK,CAA0B,CAAC;MACpD,CAAC,MAAM,IAAIC,GAAG,IAAI,IAAI,EAAE;QACtBA,GAAG,CAACC,OAAO,GAAGF,KAAK;QACnBI,QAAQ,CAACC,IAAI,CAACF,SAAS,CAAC;MAC1B,CAAC,MAAM;QACLC,QAAQ,CAACC,IAAI,CAACF,SAAS,CAAC;MAC1B;IACF;IAEA,OAAO,MAAM;MACX,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,IAAI,CAACQ,MAAM,EAAED,CAAC,EAAE,EAAE;QACpC,MAAML,GAAG,GAAGF,IAAI,CAACO,CAAC,CAAC;QACnB,IAAIL,GAAG,IAAI,IAAI,EAAE;QAEjB,IAAI,OAAOA,GAAG,KAAK,UAAU,EAAE;UAC7B,MAAMO,UAAU,GAAGJ,QAAQ,CAACE,CAAC,CAAC;UAC9B,IAAI,OAAOE,UAAU,KAAK,UAAU,EAAE;YACpCA,UAAU,CAAC,CAAC;UACd,CAAC,MAAM;YACLP,GAAG,CAAC,IAAI,CAAC;UACX;QACF,CAAC,MAAM;UACLA,GAAG,CAACC,OAAO,GAAG,IAAI;QACpB;MACF;IACF,CAAC;EACH,CAAC;AACH","ignoreList":[]}
@@ -6,8 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createContext = createContext;
7
7
  var _react = require("react");
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
- function createContext(displayName) {
10
- const Context = /*#__PURE__*/(0, _react.createContext)(undefined);
9
+ function createContext(displayName, options) {
10
+ const {
11
+ defaultValue,
12
+ strict = true
13
+ } = options ?? {};
14
+ const Context = /*#__PURE__*/(0, _react.createContext)(defaultValue);
11
15
  const Provider = props => {
12
16
  const {
13
17
  children,
@@ -21,7 +25,7 @@ function createContext(displayName) {
21
25
  Provider.displayName = `${displayName}Provider`;
22
26
  function useC() {
23
27
  const context = (0, _react.useContext)(Context);
24
- if (context === undefined) {
28
+ if (context === undefined && strict) {
25
29
  throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
26
30
  }
27
31
  return context;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_jsxRuntime","createContext","displayName","Context","createReactContext","undefined","Provider","props","children","value","jsx","useC","context","useContext","Error"],"sourceRoot":"../../../src","sources":["context/createContext.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKe,IAAAC,WAAA,GAAAD,OAAA;AAER,SAASE,aAAaA,CAAIC,WAAmB,EAAE;EACpD,MAAMC,OAAO,gBAAG,IAAAC,oBAAkB,EAAgBC,SAAS,CAAC;EAE5D,MAAMC,QAA0D,GAAIC,KAAK,IAAK;IAC5E,MAAM;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGF,KAAK;IACjC,oBAAO,IAAAP,WAAA,CAAAU,GAAA,EAACP,OAAO,CAACG,QAAQ;MAACG,KAAK,EAAEA,KAAM;MAAAD,QAAA,EAAEA;IAAQ,CAAmB,CAAC;EACtE,CAAC;EAEDF,QAAQ,CAACJ,WAAW,GAAG,GAAGA,WAAW,UAAU;EAE/C,SAASS,IAAIA,CAAA,EAAM;IACjB,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACV,OAAO,CAAC;IACnC,IAAIS,OAAO,KAAKP,SAAS,EAAE;MACzB,MAAM,IAAIS,KAAK,CAAC,MAAMZ,WAAW,0BAA0BA,WAAW,UAAU,CAAC;IACnF;IACA,OAAOU,OAAO;EAChB;EAEA,OAAO,CAACN,QAAQ,EAAEK,IAAI,CAAC;AACzB","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_jsxRuntime","createContext","displayName","options","defaultValue","strict","Context","createReactContext","Provider","props","children","value","jsx","useC","context","useContext","undefined","Error"],"sourceRoot":"../../../src","sources":["context/createContext.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKe,IAAAC,WAAA,GAAAD,OAAA;AAiBR,SAASE,aAAaA,CAAIC,WAAmB,EAAEC,OAAiC,EAAE;EACvF,MAAM;IAAEC,YAAY;IAAEC,MAAM,GAAG;EAAK,CAAC,GAAGF,OAAO,IAAI,CAAC,CAAC;EAErD,MAAMG,OAAO,gBAAG,IAAAC,oBAAkB,EAAgBH,YAAY,CAAC;EAE/D,MAAMI,QAA0D,GAAIC,KAAK,IAAK;IAC5E,MAAM;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGF,KAAK;IACjC,oBAAO,IAAAT,WAAA,CAAAY,GAAA,EAACN,OAAO,CAACE,QAAQ;MAACG,KAAK,EAAEA,KAAM;MAAAD,QAAA,EAAEA;IAAQ,CAAmB,CAAC;EACtE,CAAC;EAEDF,QAAQ,CAACN,WAAW,GAAG,GAAGA,WAAW,UAAU;EAE/C,SAASW,IAAIA,CAAA,EAAM;IACjB,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACT,OAAO,CAAC;IACnC,IAAIQ,OAAO,KAAKE,SAAS,IAAIX,MAAM,EAAE;MACnC,MAAM,IAAIY,KAAK,CAAC,MAAMf,WAAW,0BAA0BA,WAAW,UAAU,CAAC;IACnF;IACA,OAAOY,OAAO;EAChB;EAEA,OAAO,CAACN,QAAQ,EAAEK,IAAI,CAAC;AACzB","ignoreList":[]}
@@ -27,5 +27,11 @@ Object.defineProperty(exports, "useFormControlRoot", {
27
27
  return _useFormControl.useFormControlRoot;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "useReportFormControlLabelFocus", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _useFormControl.useReportFormControlLabelFocus;
34
+ }
35
+ });
30
36
  var _useFormControl = require("./useFormControl");
31
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_useFormControl","require"],"sourceRoot":"../../../src","sources":["form-control/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_useFormControl","require"],"sourceRoot":"../../../src","sources":["form-control/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA","ignoreList":[]}
@@ -7,10 +7,21 @@ exports.FormControlContext = void 0;
7
7
  exports.useFormControl = useFormControl;
8
8
  exports.useFormControlContext = void 0;
9
9
  exports.useFormControlRoot = useFormControlRoot;
10
+ exports.useReportFormControlLabelFocus = useReportFormControlLabelFocus;
10
11
  var _react = _interopRequireDefault(require("react"));
11
12
  var _reactNative = require("react-native");
12
13
  var _accessibilityUtils = require("../common/accessibilityUtils");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ /**
16
+ * Minimal contract for any control registered on `FormControlContextValue.inputRef`.
17
+ *
18
+ * `Field.Label` / `focusInput()` only need to call `.focus()` on the registered node;
19
+ * narrower control-specific shapes (`TextInput`, `HTMLInputElement`, custom focus
20
+ * bridges like `Select.Trigger`'s) all satisfy this contract. Consumers that need
21
+ * more (e.g. reading `.value`) should cast locally — keeping the context type
22
+ * minimal avoids a typed lie when a non-input bridge is registered.
23
+ */
24
+
14
25
  const FormControlContext = exports.FormControlContext = /*#__PURE__*/_react.default.createContext({});
15
26
 
16
27
  /** Props for the FormControl root; known fields plus passthrough to the styled root box. */
@@ -46,6 +57,7 @@ function useFormControlRoot(props) {
46
57
  * We use this to append its id the the `aria-describedby` of the `input`.
47
58
  */
48
59
  const [hasHelpText, setHasHelpText] = _react.default.useState(false);
60
+ const [isLabelFocused, setIsLabelFocused] = _react.default.useState(false);
49
61
  const inputRef = _react.default.useRef(null);
50
62
  const focusInput = _react.default.useCallback(() => {
51
63
  const node = inputRef.current;
@@ -68,6 +80,8 @@ function useFormControlRoot(props) {
68
80
  feedbackId,
69
81
  helpTextId,
70
82
  htmlProps,
83
+ isLabelFocused,
84
+ setIsLabelFocused,
71
85
  ...(_reactNative.Platform.OS !== 'web' ? {
72
86
  inputRef,
73
87
  focusInput
@@ -76,6 +90,25 @@ function useFormControlRoot(props) {
76
90
  return context;
77
91
  }
78
92
 
93
+ /**
94
+ * Reports focus/active state from `Input` / `Select.Trigger` to the parent `Field` for label styling.
95
+ * No-ops outside a `Field` (no `setIsLabelFocused` on context).
96
+ */
97
+ function useReportFormControlLabelFocus(isActive) {
98
+ const {
99
+ setIsLabelFocused
100
+ } = useFormControlContext();
101
+ _react.default.useLayoutEffect(() => {
102
+ if (typeof setIsLabelFocused !== 'function') {
103
+ return undefined;
104
+ }
105
+ setIsLabelFocused(isActive);
106
+ return () => {
107
+ setIsLabelFocused(false);
108
+ };
109
+ }, [isActive, setIsLabelFocused]);
110
+ }
111
+
79
112
  /**
80
113
  * Hook that merges local field props with the nearest form field context
81
114
  * and returns normalised HTML / ARIA attributes for input elements.
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_accessibilityUtils","e","__esModule","default","FormControlContext","exports","React","createContext","useFormControlRoot","props","id","idProp","name","isRequired","isInvalid","isDisabled","isReadOnly","htmlProps","reactId","useId","labelId","feedbackId","helpTextId","hasFeedbackText","setHasFeedbackText","useState","hasHelpText","setHasHelpText","inputRef","useRef","focusInput","useCallback","node","current","focus","context","Boolean","Platform","OS","useFormControl","field","useFormControlContext","describedBy","push","ariaDescribedBy","join","cleanProps","undefined","disabled","readOnly","required","ariaAttr","useContext"],"sourceRoot":"../../../src","sources":["form-control/useFormControl.tsx"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAAwD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA8BjD,MAAMG,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,gBAAGE,cAAK,CAACC,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AAU;IACxCkC,QAAQ,EAAEjC,UAAU,IAAIwB,KAAK,CAACxB,UAAU;IACxCkC,QAAQ,EAAErC,UAAU,IAAI2B,KAAK,CAAC3B,UAAU;IACxC,cAAc,EAAE,IAAAsC,4BAAQ,EAACrC,SAAS,IAAI0B,KAAK,CAAC1B,SAAS,CAAC;IACtD,eAAe,EAAE,IAAAqC,4BAAQ,EAACtC,UAAU,IAAI2B,KAAK,CAAC3B,UAAU,CAAC;IACzD,eAAe,EAAE,IAAAsC,4BAAQ,EAACnC,UAAU,IAAIwB,KAAK,CAACxB,UAAU,CAAC;IACzD,kBAAkB,EAAE4B,eAAe,IAAIG,SAAS;IAChD,iBAAiB,EAAEP,KAAK,CAACpB;EAC3B,CAAC;AACH;AAEO,MAAMqB,qBAAqB,GAAGA,CAAA,KAAM;EACzC,OAAOnC,cAAK,CAAC8C,UAAU,CAAChD,kBAAkB,CAAC;AAC7C,CAAC;AAACC,OAAA,CAAAoC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_accessibilityUtils","e","__esModule","default","FormControlContext","exports","React","createContext","useFormControlRoot","props","id","idProp","name","isRequired","isInvalid","isDisabled","isReadOnly","htmlProps","reactId","useId","labelId","feedbackId","helpTextId","hasFeedbackText","setHasFeedbackText","useState","hasHelpText","setHasHelpText","isLabelFocused","setIsLabelFocused","inputRef","useRef","focusInput","useCallback","node","current","focus","context","Boolean","Platform","OS","useReportFormControlLabelFocus","isActive","useFormControlContext","useLayoutEffect","undefined","useFormControl","field","describedBy","push","ariaDescribedBy","join","cleanProps","disabled","readOnly","required","ariaAttr","useContext"],"sourceRoot":"../../../src","sources":["form-control/useFormControl.tsx"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAAwD,SAAAD,uBAAAI,CAAA,WAAAA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rC,cAAK,CAACmD,UAAU,CAACrD,kBAAkB,CAAC;AAC7C,CAAC;AAACC,OAAA,CAAAsC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -14,15 +14,4 @@ Object.keys(_context).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
- var _withStyleContext = require("./withStyleContext");
18
- Object.keys(_withStyleContext).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _withStyleContext[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _withStyleContext[key];
25
- }
26
- });
27
- });
28
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_context","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_withStyleContext"],"sourceRoot":"../../../src","sources":["style/index.tsx"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,iBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,iBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,iBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,iBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_context","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../src","sources":["style/index.tsx"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { cva } from 'class-variance-authority';
4
+ //# sourceMappingURL=cva.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["cva"],"sourceRoot":"../../../src","sources":["common/cva.ts"],"mappings":";;AAAA,SAASA,GAAG,QAA2B,0BAA0B","ignoreList":[]}
@@ -2,6 +2,7 @@
2
2
 
3
3
  export { ariaAttr } from './accessibilityUtils';
4
4
  export { cn } from './cn';
5
+ export { cva } from './cva';
5
6
  export { composeEventHandlers } from './composeEventHandlers';
6
7
  export { flattenChildren } from './getSpacedChild';
7
8
  export { mergeRefs } from './mergeRefs';
@@ -1 +1 @@
1
- {"version":3,"names":["ariaAttr","cn","composeEventHandlers","flattenChildren","mergeRefs","useControllableState"],"sourceRoot":"../../../src","sources":["common/index.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,sBAAsB;AAC/C,SAASC,EAAE,QAAQ,MAAM;AACzB,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,QAAQ,kBAAkB;AAClD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAA0CC,oBAAoB,QAAQ,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["ariaAttr","cn","cva","composeEventHandlers","flattenChildren","mergeRefs","useControllableState"],"sourceRoot":"../../../src","sources":["common/index.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,sBAAsB;AAC/C,SAASC,EAAE,QAAQ,MAAM;AACzB,SAASC,GAAG,QAA2B,OAAO;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,QAAQ,kBAAkB;AAClD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAA0CC,oBAAoB,QAAQ,wBAAwB","ignoreList":[]}
@@ -1,14 +1,52 @@
1
1
  "use strict";
2
2
 
3
+ /**
4
+ * Merges multiple refs (object or callback) into a single callback ref.
5
+ *
6
+ * Supports React 19 ref-cleanup semantics: if an inner callback ref returns a
7
+ * cleanup function, that cleanup is captured and invoked when the merged ref is
8
+ * detached — either via the returned cleanup (React 19) or via a subsequent
9
+ * call with `null` (React 18 backward-compat path).
10
+ */
3
11
  export function mergeRefs(...refs) {
4
12
  return value => {
13
+ if (value === null) {
14
+ for (const ref of refs) {
15
+ if (typeof ref === 'function') {
16
+ ref(null);
17
+ } else if (ref != null) {
18
+ ref.current = null;
19
+ }
20
+ }
21
+ return undefined;
22
+ }
23
+ const cleanups = [];
5
24
  for (const ref of refs) {
6
25
  if (typeof ref === 'function') {
7
- ref(value);
26
+ cleanups.push(ref(value));
8
27
  } else if (ref != null) {
9
28
  ref.current = value;
29
+ cleanups.push(undefined);
30
+ } else {
31
+ cleanups.push(undefined);
10
32
  }
11
33
  }
34
+ return () => {
35
+ for (let i = 0; i < refs.length; i++) {
36
+ const ref = refs[i];
37
+ if (ref == null) continue;
38
+ if (typeof ref === 'function') {
39
+ const refCleanup = cleanups[i];
40
+ if (typeof refCleanup === 'function') {
41
+ refCleanup();
42
+ } else {
43
+ ref(null);
44
+ }
45
+ } else {
46
+ ref.current = null;
47
+ }
48
+ }
49
+ };
12
50
  };
13
51
  }
14
52
  //# sourceMappingURL=mergeRefs.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["mergeRefs","refs","value","ref","current"],"sourceRoot":"../../../src","sources":["common/mergeRefs.ts"],"mappings":";;AAEA,OAAO,SAASA,SAASA,CAAI,GAAGC,IAA4B,EAAkB;EAC5E,OAAQC,KAAe,IAAK;IAC1B,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;MACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;QAC7BA,GAAG,CAACD,KAAK,CAAC;MACZ,CAAC,MAAM,IAAIC,GAAG,IAAI,IAAI,EAAE;QACtBA,GAAG,CAACC,OAAO,GAAGF,KAAK;MACrB;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["mergeRefs","refs","value","ref","current","undefined","cleanups","push","i","length","refCleanup"],"sourceRoot":"../../../src","sources":["common/mergeRefs.ts"],"mappings":";;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,SAASA,CAAI,GAAGC,IAA4B,EAAkB;EAC5E,OAAQC,KAAe,IAA4B;IACjD,IAAIA,KAAK,KAAK,IAAI,EAAE;MAClB,KAAK,MAAMC,GAAG,IAAIF,IAAI,EAAE;QACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;UAC7BA,GAAG,CAAC,IAAI,CAAC;QACX,CAAC,MAAM,IAAIA,GAAG,IAAI,IAAI,EAAE;UACtBA,GAAG,CAACC,OAAO,GAAG,IAAI;QACpB;MACF;MACA,OAAOC,SAAS;IAClB;IAEA,MAAMC,QAAmC,GAAG,EAAE;IAC9C,KAAK,MAAMH,GAAG,IAAIF,IAAI,EAAE;MACtB,IAAI,OAAOE,GAAG,KAAK,UAAU,EAAE;QAC7BG,QAAQ,CAACC,IAAI,CAACJ,GAAG,CAACD,KAAK,CAA0B,CAAC;MACpD,CAAC,MAAM,IAAIC,GAAG,IAAI,IAAI,EAAE;QACtBA,GAAG,CAACC,OAAO,GAAGF,KAAK;QACnBI,QAAQ,CAACC,IAAI,CAACF,SAAS,CAAC;MAC1B,CAAC,MAAM;QACLC,QAAQ,CAACC,IAAI,CAACF,SAAS,CAAC;MAC1B;IACF;IAEA,OAAO,MAAM;MACX,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,IAAI,CAACQ,MAAM,EAAED,CAAC,EAAE,EAAE;QACpC,MAAML,GAAG,GAAGF,IAAI,CAACO,CAAC,CAAC;QACnB,IAAIL,GAAG,IAAI,IAAI,EAAE;QAEjB,IAAI,OAAOA,GAAG,KAAK,UAAU,EAAE;UAC7B,MAAMO,UAAU,GAAGJ,QAAQ,CAACE,CAAC,CAAC;UAC9B,IAAI,OAAOE,UAAU,KAAK,UAAU,EAAE;YACpCA,UAAU,CAAC,CAAC;UACd,CAAC,MAAM;YACLP,GAAG,CAAC,IAAI,CAAC;UACX;QACF,CAAC,MAAM;UACLA,GAAG,CAACC,OAAO,GAAG,IAAI;QACpB;MACF;IACF,CAAC;EACH,CAAC;AACH","ignoreList":[]}
@@ -2,8 +2,12 @@
2
2
 
3
3
  import { createContext as createReactContext, useContext } from 'react';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
- export function createContext(displayName) {
6
- const Context = /*#__PURE__*/createReactContext(undefined);
5
+ export function createContext(displayName, options) {
6
+ const {
7
+ defaultValue,
8
+ strict = true
9
+ } = options ?? {};
10
+ const Context = /*#__PURE__*/createReactContext(defaultValue);
7
11
  const Provider = props => {
8
12
  const {
9
13
  children,
@@ -17,7 +21,7 @@ export function createContext(displayName) {
17
21
  Provider.displayName = `${displayName}Provider`;
18
22
  function useC() {
19
23
  const context = useContext(Context);
20
- if (context === undefined) {
24
+ if (context === undefined && strict) {
21
25
  throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
22
26
  }
23
27
  return context;
@@ -1 +1 @@
1
- {"version":3,"names":["createContext","createReactContext","useContext","jsx","_jsx","displayName","Context","undefined","Provider","props","children","value","useC","context","Error"],"sourceRoot":"../../../src","sources":["context/createContext.tsx"],"mappings":";;AAAA,SAEEA,aAAa,IAAIC,kBAAkB,EAEnCC,UAAU,QACL,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEf,OAAO,SAASJ,aAAaA,CAAIK,WAAmB,EAAE;EACpD,MAAMC,OAAO,gBAAGL,kBAAkB,CAAgBM,SAAS,CAAC;EAE5D,MAAMC,QAA0D,GAAIC,KAAK,IAAK;IAC5E,MAAM;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGF,KAAK;IACjC,oBAAOL,IAAA,CAACE,OAAO,CAACE,QAAQ;MAACG,KAAK,EAAEA,KAAM;MAAAD,QAAA,EAAEA;IAAQ,CAAmB,CAAC;EACtE,CAAC;EAEDF,QAAQ,CAACH,WAAW,GAAG,GAAGA,WAAW,UAAU;EAE/C,SAASO,IAAIA,CAAA,EAAM;IACjB,MAAMC,OAAO,GAAGX,UAAU,CAACI,OAAO,CAAC;IACnC,IAAIO,OAAO,KAAKN,SAAS,EAAE;MACzB,MAAM,IAAIO,KAAK,CAAC,MAAMT,WAAW,0BAA0BA,WAAW,UAAU,CAAC;IACnF;IACA,OAAOQ,OAAO;EAChB;EAEA,OAAO,CAACL,QAAQ,EAAEI,IAAI,CAAC;AACzB","ignoreList":[]}
1
+ {"version":3,"names":["createContext","createReactContext","useContext","jsx","_jsx","displayName","options","defaultValue","strict","Context","Provider","props","children","value","useC","context","undefined","Error"],"sourceRoot":"../../../src","sources":["context/createContext.tsx"],"mappings":";;AAAA,SAEEA,aAAa,IAAIC,kBAAkB,EAEnCC,UAAU,QACL,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAiBf,OAAO,SAASJ,aAAaA,CAAIK,WAAmB,EAAEC,OAAiC,EAAE;EACvF,MAAM;IAAEC,YAAY;IAAEC,MAAM,GAAG;EAAK,CAAC,GAAGF,OAAO,IAAI,CAAC,CAAC;EAErD,MAAMG,OAAO,gBAAGR,kBAAkB,CAAgBM,YAAY,CAAC;EAE/D,MAAMG,QAA0D,GAAIC,KAAK,IAAK;IAC5E,MAAM;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGF,KAAK;IACjC,oBAAOP,IAAA,CAACK,OAAO,CAACC,QAAQ;MAACG,KAAK,EAAEA,KAAM;MAAAD,QAAA,EAAEA;IAAQ,CAAmB,CAAC;EACtE,CAAC;EAEDF,QAAQ,CAACL,WAAW,GAAG,GAAGA,WAAW,UAAU;EAE/C,SAASS,IAAIA,CAAA,EAAM;IACjB,MAAMC,OAAO,GAAGb,UAAU,CAACO,OAAO,CAAC;IACnC,IAAIM,OAAO,KAAKC,SAAS,IAAIR,MAAM,EAAE;MACnC,MAAM,IAAIS,KAAK,CAAC,MAAMZ,WAAW,0BAA0BA,WAAW,UAAU,CAAC;IACnF;IACA,OAAOU,OAAO;EAChB;EAEA,OAAO,CAACL,QAAQ,EAAEI,IAAI,CAAC;AACzB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
- export { FormControlContext, useFormControl, useFormControlContext, useFormControlRoot } from './useFormControl';
3
+ export { FormControlContext, useFormControl, useFormControlContext, useFormControlRoot, useReportFormControlLabelFocus } from './useFormControl';
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["FormControlContext","useFormControl","useFormControlContext","useFormControlRoot"],"sourceRoot":"../../../src","sources":["form-control/index.ts"],"mappings":";;AAAA,SAMEA,kBAAkB,EAClBC,cAAc,EACdC,qBAAqB,EACrBC,kBAAkB,QACb,kBAAkB","ignoreList":[]}
1
+ {"version":3,"names":["FormControlContext","useFormControl","useFormControlContext","useFormControlRoot","useReportFormControlLabelFocus"],"sourceRoot":"../../../src","sources":["form-control/index.ts"],"mappings":";;AAAA,SAOEA,kBAAkB,EAClBC,cAAc,EACdC,qBAAqB,EACrBC,kBAAkB,EAClBC,8BAA8B,QACzB,kBAAkB","ignoreList":[]}
@@ -3,6 +3,17 @@
3
3
  import React from 'react';
4
4
  import { Platform } from 'react-native';
5
5
  import { ariaAttr } from '../common/accessibilityUtils';
6
+
7
+ /**
8
+ * Minimal contract for any control registered on `FormControlContextValue.inputRef`.
9
+ *
10
+ * `Field.Label` / `focusInput()` only need to call `.focus()` on the registered node;
11
+ * narrower control-specific shapes (`TextInput`, `HTMLInputElement`, custom focus
12
+ * bridges like `Select.Trigger`'s) all satisfy this contract. Consumers that need
13
+ * more (e.g. reading `.value`) should cast locally — keeping the context type
14
+ * minimal avoids a typed lie when a non-input bridge is registered.
15
+ */
16
+
6
17
  export const FormControlContext = /*#__PURE__*/React.createContext({});
7
18
 
8
19
  /** Props for the FormControl root; known fields plus passthrough to the styled root box. */
@@ -38,6 +49,7 @@ export function useFormControlRoot(props) {
38
49
  * We use this to append its id the the `aria-describedby` of the `input`.
39
50
  */
40
51
  const [hasHelpText, setHasHelpText] = React.useState(false);
52
+ const [isLabelFocused, setIsLabelFocused] = React.useState(false);
41
53
  const inputRef = React.useRef(null);
42
54
  const focusInput = React.useCallback(() => {
43
55
  const node = inputRef.current;
@@ -60,6 +72,8 @@ export function useFormControlRoot(props) {
60
72
  feedbackId,
61
73
  helpTextId,
62
74
  htmlProps,
75
+ isLabelFocused,
76
+ setIsLabelFocused,
63
77
  ...(Platform.OS !== 'web' ? {
64
78
  inputRef,
65
79
  focusInput
@@ -68,6 +82,25 @@ export function useFormControlRoot(props) {
68
82
  return context;
69
83
  }
70
84
 
85
+ /**
86
+ * Reports focus/active state from `Input` / `Select.Trigger` to the parent `Field` for label styling.
87
+ * No-ops outside a `Field` (no `setIsLabelFocused` on context).
88
+ */
89
+ export function useReportFormControlLabelFocus(isActive) {
90
+ const {
91
+ setIsLabelFocused
92
+ } = useFormControlContext();
93
+ React.useLayoutEffect(() => {
94
+ if (typeof setIsLabelFocused !== 'function') {
95
+ return undefined;
96
+ }
97
+ setIsLabelFocused(isActive);
98
+ return () => {
99
+ setIsLabelFocused(false);
100
+ };
101
+ }, [isActive, setIsLabelFocused]);
102
+ }
103
+
71
104
  /**
72
105
  * Hook that merges local field props with the nearest form field context
73
106
  * and returns normalised HTML / ARIA attributes for input elements.