@strictly/react-form 0.0.32 → 0.0.34

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { observer } from 'mobx-react';
2
+ import { Observer } from 'mobx-react';
3
3
  import { forwardRef, useMemo, } from 'react';
4
4
  export function createSimplePartialComponent(Component, curriedProps) {
5
5
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -65,7 +65,7 @@ export function createPartialObserverComponent(Component, curriedPropsSource, ad
65
65
  }
66
66
  export function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
67
67
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
68
- return observer(forwardRef(function (props, ref) {
68
+ return forwardRef(function (props, ref) {
69
69
  // forward ref types are really difficult to work with
70
70
  // still needs a cast as `extends ComponentType<any>` != `ComponentType<any>`
71
71
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion
@@ -90,10 +90,12 @@ export function createUnsafePartialObserverComponent(Component, curriedPropsSour
90
90
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
91
91
  Object.assign({}, props),
92
92
  ]);
93
- // TODO is there any way we can memoize this transformation?
94
- const curriedProps = curriedPropsSource(additionalProps);
95
- return (_jsx(C, Object.assign({ ref: ref }, curriedProps, exposedProps)));
96
- }));
93
+ return (_jsx(Observer, { children: () => {
94
+ // TODO is there any way we can memoize this transformation?
95
+ const curriedProps = curriedPropsSource(additionalProps);
96
+ return (_jsx(C, Object.assign({ ref: ref }, curriedProps, exposedProps)));
97
+ } }));
98
+ });
97
99
  }
98
100
  export function usePartialObserverComponent(
99
101
  // has to be first so eslint react-hooks/exhaustive-deps can find the callback
@@ -7,12 +7,12 @@ $ tsup
7
7
  CLI Target: es6
8
8
  CJS Build start
9
9
  ESM Build start
10
- CJS dist/index.cjs 64.18 KB
11
- CJS ⚡️ Build success in 121ms
12
- ESM dist/index.js 60.02 KB
13
- ESM ⚡️ Build success in 126ms
10
+ ESM dist/index.js 60.01 KB
11
+ ESM ⚡️ Build success in 127ms
12
+ CJS dist/index.cjs 64.19 KB
13
+ CJS ⚡️ Build success in 158ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 6938ms
16
- DTS dist/index.d.cts 38.43 KB
17
- DTS dist/index.d.ts 38.43 KB
18
- Done in 8.16s.
15
+ DTS ⚡️ Build success in 6824ms
16
+ DTS dist/index.d.cts 38.69 KB
17
+ DTS dist/index.d.ts 38.69 KB
18
+ Done in 8.27s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc -b
3
- Done in 0.37s.
3
+ Done in 0.41s.
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  type ReadonlyTypeOfType,
3
+ type Type,
3
4
  type ValueOfType,
4
5
  } from '@strictly/define'
5
6
  import {
@@ -13,13 +14,25 @@ import {
13
14
  import { peek } from './peek'
14
15
 
15
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- type ValueOfModel<M extends FormModel<any, any, any, any, any>> = M extends FormModel<infer T, any, any, any, any>
17
+ type FormModelInterface<T extends Type = any> = Pick<
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ FormModel<T, any, any, any, any>,
20
+ | 'fields'
21
+ | 'value'
22
+ | 'getValidation'
23
+ | 'validateField'
24
+ | 'setFieldValue'
25
+ | 'validateSubmit'
26
+ | 'isFieldDirty'
27
+ | 'isValuePathActive'
28
+ >
29
+
30
+ type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T>
17
31
  ? ValueOfType<ReadonlyTypeOfType<T>>
18
32
  : never
19
33
 
20
34
  export function useDefaultMobxFormHooks<
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- M extends FormModel<any, any, any, any, any>,
35
+ M extends FormModelInterface,
23
36
  F extends M['fields'] = M['fields'],
24
37
  >(
25
38
  model: M,
package/dist/index.cjs CHANGED
@@ -1306,36 +1306,36 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
1306
1306
  );
1307
1307
  }
1308
1308
  function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
1309
- return (0, import_mobx_react.observer)(
1310
- (0, import_react2.forwardRef)(
1311
- function(props, ref) {
1312
- const C = Component;
1313
- const [
1314
- additionalProps,
1315
- exposedProps
1316
- ] = additionalPropKeys.reduce(
1317
- function([
1309
+ return (0, import_react2.forwardRef)(
1310
+ function(props, ref) {
1311
+ const C = Component;
1312
+ const [
1313
+ additionalProps,
1314
+ exposedProps
1315
+ ] = additionalPropKeys.reduce(
1316
+ function([
1317
+ additionalProps2,
1318
+ exposedProps2
1319
+ ], key) {
1320
+ const value = props[
1321
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1322
+ key
1323
+ ];
1324
+ delete exposedProps2[key];
1325
+ additionalProps2[key] = value;
1326
+ return [
1318
1327
  additionalProps2,
1319
1328
  exposedProps2
1320
- ], key) {
1321
- const value = props[
1322
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1323
- key
1324
- ];
1325
- delete exposedProps2[key];
1326
- additionalProps2[key] = value;
1327
- return [
1328
- additionalProps2,
1329
- exposedProps2
1330
- ];
1331
- },
1332
- [
1333
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1334
- {},
1335
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1336
- __spreadValues({}, props)
1337
- ]
1338
- );
1329
+ ];
1330
+ },
1331
+ [
1332
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1333
+ {},
1334
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1335
+ __spreadValues({}, props)
1336
+ ]
1337
+ );
1338
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mobx_react.Observer, { children: () => {
1339
1339
  const curriedProps = curriedPropsSource(additionalProps);
1340
1340
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1341
1341
  C,
@@ -1343,8 +1343,8 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
1343
1343
  ref
1344
1344
  }, curriedProps), exposedProps)
1345
1345
  );
1346
- }
1347
- )
1346
+ } });
1347
+ }
1348
1348
  );
1349
1349
  }
1350
1350
  function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
@@ -1977,7 +1977,7 @@ var MantineFormImpl = class {
1977
1977
  this
1978
1978
  );
1979
1979
  }
1980
- // TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
1980
+ // TODO have an option to bind to a Text/(value: T) => ReactNode for viewing form fields
1981
1981
  };
1982
1982
  _init2 = __decoratorStart(null);
1983
1983
  _fields = new WeakMap();
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf,
4
4
  import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
+ import { Observer } from 'mobx-react';
7
8
 
8
9
  declare enum UnreliableFieldConversionType {
9
10
  Success = 0,
@@ -180,8 +181,9 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
180
181
  validateSubmit(): boolean;
181
182
  }
182
183
 
183
- type ValueOfModel<M extends FormModel<any, any, any, any, any>> = M extends FormModel<infer T, any, any, any, any> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
184
- declare function useDefaultMobxFormHooks<M extends FormModel<any, any, any, any, any>, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
184
+ type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
185
+ type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
186
+ declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
185
187
  onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
186
188
  onValidFormSubmit?: (value: ValueOfModel<M>) => void;
187
189
  }): {
@@ -376,7 +378,7 @@ type FieldViewProps<F extends Fields, K extends keyof F> = {
376
378
  onBlur: () => void;
377
379
  onValueChange: (v: ValueTypeOfField<F[K]>) => void;
378
380
  onSubmit: () => void;
379
- }) => JSX.Element;
381
+ }) => ReturnType<NonNullable<ComponentProps<typeof Observer>['render']>>;
380
382
  };
381
383
 
382
384
  type SuppliedListProps<Value = any, ListPath extends string = string> = {
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf,
4
4
  import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
+ import { Observer } from 'mobx-react';
7
8
 
8
9
  declare enum UnreliableFieldConversionType {
9
10
  Success = 0,
@@ -180,8 +181,9 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
180
181
  validateSubmit(): boolean;
181
182
  }
182
183
 
183
- type ValueOfModel<M extends FormModel<any, any, any, any, any>> = M extends FormModel<infer T, any, any, any, any> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
184
- declare function useDefaultMobxFormHooks<M extends FormModel<any, any, any, any, any>, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
184
+ type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
185
+ type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
186
+ declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
185
187
  onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
186
188
  onValidFormSubmit?: (value: ValueOfModel<M>) => void;
187
189
  }): {
@@ -376,7 +378,7 @@ type FieldViewProps<F extends Fields, K extends keyof F> = {
376
378
  onBlur: () => void;
377
379
  onValueChange: (v: ValueTypeOfField<F[K]>) => void;
378
380
  onSubmit: () => void;
379
- }) => JSX.Element;
381
+ }) => ReturnType<NonNullable<ComponentProps<typeof Observer>['render']>>;
380
382
  };
381
383
 
382
384
  type SuppliedListProps<Value = any, ListPath extends string = string> = {
package/dist/index.js CHANGED
@@ -1220,7 +1220,7 @@ import {
1220
1220
  } from "react";
1221
1221
 
1222
1222
  // util/Partial.tsx
1223
- import { observer } from "mobx-react";
1223
+ import { Observer } from "mobx-react";
1224
1224
  import {
1225
1225
  forwardRef,
1226
1226
  useMemo
@@ -1306,36 +1306,36 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
1306
1306
  );
1307
1307
  }
1308
1308
  function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
1309
- return observer(
1310
- forwardRef(
1311
- function(props, ref) {
1312
- const C = Component;
1313
- const [
1314
- additionalProps,
1315
- exposedProps
1316
- ] = additionalPropKeys.reduce(
1317
- function([
1309
+ return forwardRef(
1310
+ function(props, ref) {
1311
+ const C = Component;
1312
+ const [
1313
+ additionalProps,
1314
+ exposedProps
1315
+ ] = additionalPropKeys.reduce(
1316
+ function([
1317
+ additionalProps2,
1318
+ exposedProps2
1319
+ ], key) {
1320
+ const value = props[
1321
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1322
+ key
1323
+ ];
1324
+ delete exposedProps2[key];
1325
+ additionalProps2[key] = value;
1326
+ return [
1318
1327
  additionalProps2,
1319
1328
  exposedProps2
1320
- ], key) {
1321
- const value = props[
1322
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1323
- key
1324
- ];
1325
- delete exposedProps2[key];
1326
- additionalProps2[key] = value;
1327
- return [
1328
- additionalProps2,
1329
- exposedProps2
1330
- ];
1331
- },
1332
- [
1333
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1334
- {},
1335
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1336
- __spreadValues({}, props)
1337
- ]
1338
- );
1329
+ ];
1330
+ },
1331
+ [
1332
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1333
+ {},
1334
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1335
+ __spreadValues({}, props)
1336
+ ]
1337
+ );
1338
+ return /* @__PURE__ */ jsx(Observer, { children: () => {
1339
1339
  const curriedProps = curriedPropsSource(additionalProps);
1340
1340
  return /* @__PURE__ */ jsx(
1341
1341
  C,
@@ -1343,8 +1343,8 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
1343
1343
  ref
1344
1344
  }, curriedProps), exposedProps)
1345
1345
  );
1346
- }
1347
- )
1346
+ } });
1347
+ }
1348
1348
  );
1349
1349
  }
1350
1350
  function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
@@ -1424,7 +1424,7 @@ import {
1424
1424
  jsonPathPrefix,
1425
1425
  jsonPathUnprefix
1426
1426
  } from "@strictly/define";
1427
- import { observer as observer2 } from "mobx-react";
1427
+ import { observer } from "mobx-react";
1428
1428
  import { jsx as jsx3 } from "react/jsx-runtime";
1429
1429
  function createFieldsView(valuePath, FieldsView, observableProps) {
1430
1430
  function toKey(subKey) {
@@ -1448,7 +1448,7 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1448
1448
  var _a;
1449
1449
  (_a = observableProps.onFieldSubmit) == null ? void 0 : _a.call(observableProps, toKey(subKey));
1450
1450
  }
1451
- const Component = observer2(
1451
+ const Component = observer(
1452
1452
  function(props) {
1453
1453
  const subFields = Object.entries(observableProps.fields).reduce(
1454
1454
  (acc, [
@@ -1488,7 +1488,7 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1488
1488
  }
1489
1489
 
1490
1490
  // mantine/createFieldView.tsx
1491
- import { Observer } from "mobx-react";
1491
+ import { Observer as Observer2 } from "mobx-react";
1492
1492
  import {
1493
1493
  useCallback as useCallback2
1494
1494
  } from "react";
@@ -1533,7 +1533,7 @@ function FieldView({
1533
1533
  form,
1534
1534
  valuePath
1535
1535
  ]);
1536
- return /* @__PURE__ */ jsx4(Observer, { children: () => {
1536
+ return /* @__PURE__ */ jsx4(Observer2, { children: () => {
1537
1537
  const {
1538
1538
  value,
1539
1539
  error
@@ -1562,13 +1562,13 @@ function createFieldView(valuePath) {
1562
1562
  }
1563
1563
 
1564
1564
  // mantine/createForm.tsx
1565
- import { observer as observer3 } from "mobx-react";
1565
+ import { observer as observer2 } from "mobx-react";
1566
1566
  import {
1567
1567
  useCallback as useCallback3
1568
1568
  } from "react";
1569
1569
  import { jsx as jsx5 } from "react/jsx-runtime";
1570
1570
  function createForm(valuePath, Form, observableProps) {
1571
- return observer3((props) => {
1571
+ return observer2((props) => {
1572
1572
  const { value } = observableProps.fields[valuePath];
1573
1573
  const onValueChange = useCallback3((value2) => {
1574
1574
  observableProps.onFieldValueChange(valuePath, value2);
@@ -1988,7 +1988,7 @@ var MantineFormImpl = class {
1988
1988
  this
1989
1989
  );
1990
1990
  }
1991
- // TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
1991
+ // TODO have an option to bind to a Text/(value: T) => ReactNode for viewing form fields
1992
1992
  };
1993
1993
  _init2 = __decoratorStart(null);
1994
1994
  _fields = new WeakMap();
@@ -1,5 +1,6 @@
1
1
  import { Observer } from 'mobx-react'
2
2
  import {
3
+ type ComponentProps,
3
4
  type ComponentType,
4
5
  useCallback,
5
6
  } from 'react'
@@ -19,7 +20,7 @@ export type FieldViewProps<F extends Fields, K extends keyof F> = {
19
20
  onBlur: () => void,
20
21
  onValueChange: (v: ValueTypeOfField<F[K]>) => void,
21
22
  onSubmit: () => void,
22
- }) => JSX.Element,
23
+ }) => ReturnType<NonNullable<ComponentProps<typeof Observer>['render']>>,
23
24
  }
24
25
 
25
26
  /**
package/mantine/hooks.tsx CHANGED
@@ -457,5 +457,5 @@ class MantineFormImpl<
457
457
  ) as unknown as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>
458
458
  }
459
459
 
460
- // TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
460
+ // TODO have an option to bind to a Text/(value: T) => ReactNode for viewing form fields
461
461
  }
package/package.json CHANGED
@@ -1,10 +1,6 @@
1
1
  {
2
2
  "author": "Chris <chris.glover@gmail.com> (@madmaw)",
3
- "dependencies": {
4
- "@types/react": "^18.3.12",
5
- "@types/react-dom": "^18.3.1",
6
- "type-fest": "^4.27.0"
7
- },
3
+ "dependencies": {},
8
4
  "description": "Types and utilities for creating React forms",
9
5
  "devDependencies": {
10
6
  "@babel/plugin-proposal-decorators": "^7.25.9",
@@ -22,11 +18,14 @@
22
18
  "@strictly/support-vite": "*",
23
19
  "@testing-library/dom": "^10.4.0",
24
20
  "@testing-library/react": "^16.0.1",
21
+ "@types/react": "^18.3.12",
22
+ "@types/react-dom": "^18.3.1",
25
23
  "@vitejs/plugin-react": "^4.3.3",
26
24
  "concurrently": "^9.1.2",
27
25
  "jsdom": "^25.0.1",
28
26
  "resize-observer-polyfill": "^1.5.1",
29
27
  "storybook": "^8.4.5",
28
+ "type-fest": "^4.27.0",
30
29
  "vite": "^6.0.5",
31
30
  "vitest-matchmedia-mock": "^1.0.6"
32
31
  },
@@ -43,6 +42,8 @@
43
42
  "@mantine/hooks": "^7.0.0 || ^8.0.0",
44
43
  "@strictly/base": "*",
45
44
  "@strictly/define": "*",
45
+ "@types/react": "^19.0.0 || ^18.0.0",
46
+ "@types/react-dom": "^19.0.0 || ^18.0.0",
46
47
  "mobx": "^6.0.0",
47
48
  "mobx-react": "^9.1.1",
48
49
  "react": "^19.0.0 || ^18.0.0",
@@ -72,7 +73,7 @@
72
73
  "test:watch": "vitest"
73
74
  },
74
75
  "type": "module",
75
- "version": "0.0.32",
76
+ "version": "0.0.34",
76
77
  "exports": {
77
78
  ".": {
78
79
  "import": {
package/util/Partial.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type FriendlyExhaustiveArrayOfUnion } from '@strictly/base'
2
- import { observer } from 'mobx-react'
2
+ import { Observer } from 'mobx-react'
3
3
  import {
4
4
  type ComponentProps,
5
5
  type ComponentType,
@@ -274,62 +274,65 @@ export function createUnsafePartialObserverComponent<
274
274
  additionalPropKeys: readonly (keyof AdditionalProps)[] = [],
275
275
  ): UnsafePartialComponent<Component, CurriedProps, AdditionalProps> {
276
276
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
277
- return observer(
278
- forwardRef(
279
- function (
280
- props: PropsWithoutRef<RemainingComponentProps<Component, CurriedProps> & AdditionalProps>,
281
- ref: ForwardedRef<typeof Component>,
282
- ) {
283
- // forward ref types are really difficult to work with
284
- // still needs a cast as `extends ComponentType<any>` != `ComponentType<any>`
285
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion
286
- const C = Component as ComponentType<any>
287
- // remove the additional props from the exposed props that get passed in to the component
288
- // as this generates react warnings
289
- const [
290
- additionalProps,
291
- exposedProps,
292
- ] = additionalPropKeys.reduce<[AdditionalProps, RemainingComponentProps<Component, CurriedProps>]>(
293
- function (
294
- [
295
- additionalProps,
296
- exposedProps,
297
- ],
298
- key,
299
- ) {
300
- const value = props[
301
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
302
- key as keyof PropsWithoutRef<RemainingComponentProps<Component, CurriedProps> & AdditionalProps>
303
- ]
304
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
305
- delete exposedProps[key as keyof RemainingComponentProps<Component, CurriedProps>]
306
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
307
- additionalProps[key] = value as any
308
- return [
309
- additionalProps,
310
- exposedProps,
311
- ]
312
- },
277
+ return forwardRef(
278
+ function (
279
+ props: PropsWithoutRef<RemainingComponentProps<Component, CurriedProps> & AdditionalProps>,
280
+ ref: ForwardedRef<typeof Component>,
281
+ ) {
282
+ // forward ref types are really difficult to work with
283
+ // still needs a cast as `extends ComponentType<any>` != `ComponentType<any>`
284
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion
285
+ const C = Component as ComponentType<any>
286
+ // remove the additional props from the exposed props that get passed in to the component
287
+ // as this generates react warnings
288
+ const [
289
+ additionalProps,
290
+ exposedProps,
291
+ ] = additionalPropKeys.reduce<[AdditionalProps, RemainingComponentProps<Component, CurriedProps>]>(
292
+ function (
313
293
  [
314
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
315
- {} as AdditionalProps,
316
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
317
- { ...props } as RemainingComponentProps<Component, CurriedProps>,
294
+ additionalProps,
295
+ exposedProps,
318
296
  ],
319
- )
320
-
321
- // TODO is there any way we can memoize this transformation?
322
- const curriedProps = curriedPropsSource(additionalProps)
297
+ key,
298
+ ) {
299
+ const value = props[
300
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
301
+ key as keyof PropsWithoutRef<RemainingComponentProps<Component, CurriedProps> & AdditionalProps>
302
+ ]
303
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
304
+ delete exposedProps[key as keyof RemainingComponentProps<Component, CurriedProps>]
305
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
306
+ additionalProps[key] = value as any
307
+ return [
308
+ additionalProps,
309
+ exposedProps,
310
+ ]
311
+ },
312
+ [
313
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
314
+ {} as AdditionalProps,
315
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
316
+ { ...props } as RemainingComponentProps<Component, CurriedProps>,
317
+ ],
318
+ )
319
+ return (
320
+ <Observer>
321
+ {() => {
322
+ // TODO is there any way we can memoize this transformation?
323
+ const curriedProps = curriedPropsSource(additionalProps)
323
324
 
324
- return (
325
- <C
326
- ref={ref}
327
- {...curriedProps}
328
- {...exposedProps}
329
- />
330
- )
331
- },
332
- ),
325
+ return (
326
+ <C
327
+ ref={ref}
328
+ {...curriedProps}
329
+ {...exposedProps}
330
+ />
331
+ )
332
+ }}
333
+ </Observer>
334
+ )
335
+ },
333
336
  ) as UnsafePartialComponent<Component, CurriedProps, AdditionalProps>
334
337
  }
335
338