@cdx-ui/primitives 0.0.1-alpha.35 → 0.0.1-alpha.37
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/lib/commonjs/{form-control/createFormError.js → field/createFieldError.js} +4 -4
- package/lib/commonjs/field/createFieldError.js.map +1 -0
- package/lib/commonjs/{form-control/createFormErrorIcon.js → field/createFieldErrorIcon.js} +4 -4
- package/lib/commonjs/field/createFieldErrorIcon.js.map +1 -0
- package/lib/commonjs/{form-control/createFormErrorText.js → field/createFieldErrorText.js} +4 -4
- package/lib/commonjs/field/createFieldErrorText.js.map +1 -0
- package/lib/commonjs/{form-control/createFormHelper.js → field/createFieldHelper.js} +4 -4
- package/lib/commonjs/field/createFieldHelper.js.map +1 -0
- package/lib/commonjs/{form-control/createFormHelperText.js → field/createFieldHelperText.js} +4 -4
- package/lib/commonjs/field/createFieldHelperText.js.map +1 -0
- package/lib/commonjs/{form-control/createFormLabel.js → field/createFieldLabel.js} +4 -6
- package/lib/commonjs/field/createFieldLabel.js.map +1 -0
- package/lib/commonjs/{form-control/createFormField.js → field/createFieldRoot.js} +4 -4
- package/lib/commonjs/field/createFieldRoot.js.map +1 -0
- package/lib/commonjs/field/index.js +46 -0
- package/lib/commonjs/field/index.js.map +1 -0
- package/lib/commonjs/{form-control → field}/types.js.map +1 -1
- package/lib/commonjs/form/createFormRoot.js.map +1 -0
- package/lib/commonjs/form/index.js +15 -0
- package/lib/commonjs/form/index.js.map +1 -0
- package/lib/commonjs/form/types.js +6 -0
- package/lib/{module/form-control → commonjs/form}/types.js.map +1 -1
- package/lib/commonjs/index.js +28 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/otp-input/context.js +14 -0
- package/lib/commonjs/otp-input/context.js.map +1 -0
- package/lib/commonjs/otp-input/createOtpInputCell.js +29 -0
- package/lib/commonjs/otp-input/createOtpInputCell.js.map +1 -0
- package/lib/commonjs/otp-input/createOtpInputField.js +104 -0
- package/lib/commonjs/otp-input/createOtpInputField.js.map +1 -0
- package/lib/commonjs/otp-input/createOtpInputRoot.js +136 -0
- package/lib/commonjs/otp-input/createOtpInputRoot.js.map +1 -0
- package/lib/commonjs/otp-input/index.js +48 -0
- package/lib/commonjs/otp-input/index.js.map +1 -0
- package/lib/commonjs/otp-input/types.js +6 -0
- package/lib/commonjs/otp-input/types.js.map +1 -0
- package/lib/commonjs/otp-input/utils/applyValueChange.js +73 -0
- package/lib/commonjs/otp-input/utils/applyValueChange.js.map +1 -0
- package/lib/commonjs/otp-input/utils/filterValue.js +46 -0
- package/lib/commonjs/otp-input/utils/filterValue.js.map +1 -0
- package/lib/module/{form-control/createFormError.js → field/createFieldError.js} +2 -2
- package/lib/module/field/createFieldError.js.map +1 -0
- package/lib/module/{form-control/createFormErrorIcon.js → field/createFieldErrorIcon.js} +2 -2
- package/lib/module/field/createFieldErrorIcon.js.map +1 -0
- package/lib/module/{form-control/createFormErrorText.js → field/createFieldErrorText.js} +2 -2
- package/lib/module/field/createFieldErrorText.js.map +1 -0
- package/lib/module/{form-control/createFormHelper.js → field/createFieldHelper.js} +2 -2
- package/lib/module/field/createFieldHelper.js.map +1 -0
- package/lib/module/{form-control/createFormHelperText.js → field/createFieldHelperText.js} +2 -2
- package/lib/module/field/createFieldHelperText.js.map +1 -0
- package/lib/module/{form-control/createFormLabel.js → field/createFieldLabel.js} +2 -4
- package/lib/module/field/createFieldLabel.js.map +1 -0
- package/lib/module/{form-control/createFormField.js → field/createFieldRoot.js} +2 -2
- package/lib/module/field/createFieldRoot.js.map +1 -0
- package/lib/module/field/index.js +42 -0
- package/lib/module/field/index.js.map +1 -0
- package/lib/module/field/types.js.map +1 -0
- package/lib/module/form/createFormRoot.js.map +1 -0
- package/lib/module/form/index.js +11 -0
- package/lib/module/form/index.js.map +1 -0
- package/lib/module/form/types.js +4 -0
- package/lib/module/form/types.js.map +1 -0
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/otp-input/context.js +6 -0
- package/lib/module/otp-input/context.js.map +1 -0
- package/lib/module/otp-input/createOtpInputCell.js +24 -0
- package/lib/module/otp-input/createOtpInputCell.js.map +1 -0
- package/lib/module/otp-input/createOtpInputField.js +99 -0
- package/lib/module/otp-input/createOtpInputField.js.map +1 -0
- package/lib/module/otp-input/createOtpInputRoot.js +131 -0
- package/lib/module/otp-input/createOtpInputRoot.js.map +1 -0
- package/lib/module/otp-input/index.js +20 -0
- package/lib/module/otp-input/index.js.map +1 -0
- package/lib/module/otp-input/types.js +4 -0
- package/lib/module/otp-input/types.js.map +1 -0
- package/lib/module/otp-input/utils/applyValueChange.js +69 -0
- package/lib/module/otp-input/utils/applyValueChange.js.map +1 -0
- package/lib/module/otp-input/utils/filterValue.js +40 -0
- package/lib/module/otp-input/utils/filterValue.js.map +1 -0
- package/lib/typescript/field/createFieldError.d.ts +5 -0
- package/lib/typescript/field/createFieldError.d.ts.map +1 -0
- package/lib/typescript/field/createFieldErrorIcon.d.ts +5 -0
- package/lib/typescript/field/createFieldErrorIcon.d.ts.map +1 -0
- package/lib/typescript/field/createFieldErrorText.d.ts +5 -0
- package/lib/typescript/field/createFieldErrorText.d.ts.map +1 -0
- package/lib/typescript/field/createFieldHelper.d.ts +5 -0
- package/lib/typescript/field/createFieldHelper.d.ts.map +1 -0
- package/lib/typescript/field/createFieldHelperText.d.ts +5 -0
- package/lib/typescript/field/createFieldHelperText.d.ts.map +1 -0
- package/lib/typescript/field/createFieldLabel.d.ts +6 -0
- package/lib/typescript/field/createFieldLabel.d.ts.map +1 -0
- package/lib/typescript/field/createFieldRoot.d.ts +6 -0
- package/lib/typescript/field/createFieldRoot.d.ts.map +1 -0
- package/lib/typescript/field/index.d.ts +13 -0
- package/lib/typescript/field/index.d.ts.map +1 -0
- package/lib/typescript/{form-control → field}/types.d.ts +14 -24
- package/lib/typescript/field/types.d.ts.map +1 -0
- package/lib/typescript/form/createFormRoot.d.ts +4 -0
- package/lib/typescript/form/createFormRoot.d.ts.map +1 -0
- package/lib/typescript/form/index.d.ts +6 -0
- package/lib/typescript/form/index.d.ts.map +1 -0
- package/lib/typescript/form/types.d.ts +14 -0
- package/lib/typescript/form/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/otp-input/context.d.ts +10 -0
- package/lib/typescript/otp-input/context.d.ts.map +1 -0
- package/lib/typescript/otp-input/createOtpInputCell.d.ts +4 -0
- package/lib/typescript/otp-input/createOtpInputCell.d.ts.map +1 -0
- package/lib/typescript/otp-input/createOtpInputField.d.ts +4 -0
- package/lib/typescript/otp-input/createOtpInputField.d.ts.map +1 -0
- package/lib/typescript/otp-input/createOtpInputRoot.d.ts +4 -0
- package/lib/typescript/otp-input/createOtpInputRoot.d.ts.map +1 -0
- package/lib/typescript/otp-input/index.d.ts +11 -0
- package/lib/typescript/otp-input/index.d.ts.map +1 -0
- package/lib/typescript/otp-input/types.d.ts +75 -0
- package/lib/typescript/otp-input/types.d.ts.map +1 -0
- package/lib/typescript/otp-input/utils/applyValueChange.d.ts +10 -0
- package/lib/typescript/otp-input/utils/applyValueChange.d.ts.map +1 -0
- package/lib/typescript/otp-input/utils/filterValue.d.ts +7 -0
- package/lib/typescript/otp-input/utils/filterValue.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/{form-control/createFormError.tsx → field/createFieldError.tsx} +1 -1
- package/src/{form-control/createFormErrorIcon.tsx → field/createFieldErrorIcon.tsx} +1 -1
- package/src/{form-control/createFormErrorText.tsx → field/createFieldErrorText.tsx} +1 -1
- package/src/{form-control/createFormHelper.tsx → field/createFieldHelper.tsx} +1 -1
- package/src/{form-control/createFormHelperText.tsx → field/createFieldHelperText.tsx} +1 -1
- package/src/{form-control/createFormLabel.tsx → field/createFieldLabel.tsx} +3 -3
- package/src/{form-control/createFormField.tsx → field/createFieldRoot.tsx} +3 -3
- package/src/field/index.tsx +68 -0
- package/src/{form-control → field}/types.tsx +28 -42
- package/src/{form-control → form}/createFormRoot.tsx +3 -3
- package/src/form/index.tsx +12 -0
- package/src/form/types.tsx +16 -0
- package/src/index.ts +3 -1
- package/src/otp-input/context.tsx +8 -0
- package/src/otp-input/createOtpInputCell.tsx +22 -0
- package/src/otp-input/createOtpInputField.tsx +98 -0
- package/src/otp-input/createOtpInputRoot.tsx +179 -0
- package/src/otp-input/index.tsx +34 -0
- package/src/otp-input/types.ts +92 -0
- package/src/otp-input/utils/applyValueChange.ts +56 -0
- package/src/otp-input/utils/filterValue.ts +37 -0
- package/lib/commonjs/form-control/createFormError.js.map +0 -1
- package/lib/commonjs/form-control/createFormErrorIcon.js.map +0 -1
- package/lib/commonjs/form-control/createFormErrorText.js.map +0 -1
- package/lib/commonjs/form-control/createFormField.js.map +0 -1
- package/lib/commonjs/form-control/createFormHelper.js.map +0 -1
- package/lib/commonjs/form-control/createFormHelperText.js.map +0 -1
- package/lib/commonjs/form-control/createFormLabel.js.map +0 -1
- package/lib/commonjs/form-control/createFormRoot.js.map +0 -1
- package/lib/commonjs/form-control/index.js +0 -53
- package/lib/commonjs/form-control/index.js.map +0 -1
- package/lib/module/form-control/createFormError.js.map +0 -1
- package/lib/module/form-control/createFormErrorIcon.js.map +0 -1
- package/lib/module/form-control/createFormErrorText.js.map +0 -1
- package/lib/module/form-control/createFormField.js.map +0 -1
- package/lib/module/form-control/createFormHelper.js.map +0 -1
- package/lib/module/form-control/createFormHelperText.js.map +0 -1
- package/lib/module/form-control/createFormLabel.js.map +0 -1
- package/lib/module/form-control/createFormRoot.js.map +0 -1
- package/lib/module/form-control/index.js +0 -49
- package/lib/module/form-control/index.js.map +0 -1
- package/lib/typescript/form-control/createFormError.d.ts +0 -5
- package/lib/typescript/form-control/createFormError.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormErrorIcon.d.ts +0 -5
- package/lib/typescript/form-control/createFormErrorIcon.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormErrorText.d.ts +0 -5
- package/lib/typescript/form-control/createFormErrorText.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormField.d.ts +0 -6
- package/lib/typescript/form-control/createFormField.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormHelper.d.ts +0 -5
- package/lib/typescript/form-control/createFormHelper.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormHelperText.d.ts +0 -5
- package/lib/typescript/form-control/createFormHelperText.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormLabel.d.ts +0 -8
- package/lib/typescript/form-control/createFormLabel.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormRoot.d.ts +0 -6
- package/lib/typescript/form-control/createFormRoot.d.ts.map +0 -1
- package/lib/typescript/form-control/index.d.ts +0 -14
- package/lib/typescript/form-control/index.d.ts.map +0 -1
- package/lib/typescript/form-control/types.d.ts.map +0 -1
- package/src/form-control/index.tsx +0 -71
- /package/lib/commonjs/{form-control → field}/types.js +0 -0
- /package/lib/commonjs/{form-control → form}/createFormRoot.js +0 -0
- /package/lib/module/{form-control → field}/types.js +0 -0
- /package/lib/module/{form-control → form}/createFormRoot.js +0 -0
|
@@ -2,8 +2,10 @@ export * from './avatar';
|
|
|
2
2
|
export * from './button';
|
|
3
3
|
export * from './checkbox';
|
|
4
4
|
export * from './dialog';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './field';
|
|
6
|
+
export * from './form';
|
|
6
7
|
export * from './input';
|
|
8
|
+
export * from './otp-input';
|
|
7
9
|
export * from './link';
|
|
8
10
|
export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
|
|
9
11
|
export * from './select';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OtpInputCellIndexContextValue, OtpInputContextValue } from './types';
|
|
2
|
+
export declare const OtpInputProvider: import("react").FunctionComponent<{
|
|
3
|
+
children: import("react").ReactNode;
|
|
4
|
+
value: OtpInputContextValue;
|
|
5
|
+
}>, useOtpInputContext: () => OtpInputContextValue;
|
|
6
|
+
export declare const OtpCellIndexProvider: import("react").FunctionComponent<{
|
|
7
|
+
children: import("react").ReactNode;
|
|
8
|
+
value: OtpInputCellIndexContextValue;
|
|
9
|
+
}>, useOtpCellIndexContext: () => OtpInputCellIndexContextValue;
|
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/otp-input/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEnF,eAAO,MAAO,gBAAgB;;;IAAE,kBAAkB,4BACM,CAAC;AAEzD,eAAO,MAAO,oBAAoB;;;IAAE,sBAAsB,qCACW,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IOtpInputCellProps } from './types';
|
|
3
|
+
export declare const createOtpInputCell: <T>(BaseCell: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithChildren<IOtpInputCellProps & T>> & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createOtpInputCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOtpInputCell.d.ts","sourceRoot":"","sources":["../../../src/otp-input/createOtpInputCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAG,UAAU,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,2IAenE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { type TextInput } from 'react-native';
|
|
3
|
+
export declare const createOtpInputField: <T>(BaseField: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<import("react-native").TextInputProps & Omit<T, keyof import("react-native").TextInputProps>> & React.RefAttributes<TextInput>>;
|
|
4
|
+
//# sourceMappingURL=createOtpInputField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOtpInputField.d.ts","sourceRoot":"","sources":["../../../src/otp-input/createOtpInputField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAY,KAAK,SAAS,EAA+B,MAAM,cAAc,CAAC;AAKrF,eAAO,MAAM,mBAAmB,GAAI,CAAC,EAAG,WAAW,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,0LA0FrE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IOtpInputRootProps } from './types';
|
|
3
|
+
export declare const createOtpInputRoot: <RootProps>(BaseRoot: React.ComponentType<RootProps>, OtpCell: React.ComponentType<any>, OtpField: React.ComponentType<any>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<IOtpInputRootProps & RootProps> & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createOtpInputRoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOtpInputRoot.d.ts","sourceRoot":"","sources":["../../../src/otp-input/createOtpInputRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,kBAAkB,GAAI,SAAS,EAC1C,UAAU,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,EAExC,SAAS,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EAEjC,UAAU,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,0HAoKjC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IOtpInputComponentType } from './types';
|
|
3
|
+
export { applyOtpInputChange } from './utils/applyValueChange';
|
|
4
|
+
export { filterAllowedCharacters, filterByRegExp, filterDigits } from './utils/filterValue';
|
|
5
|
+
export type * from './types';
|
|
6
|
+
export declare function createOtpInput<RootProps, CellProps, FieldProps, RootRef = unknown, FieldRef = unknown>(BaseComponents: {
|
|
7
|
+
Root: React.ComponentType<RootProps>;
|
|
8
|
+
Cell: React.ComponentType<CellProps>;
|
|
9
|
+
Field: React.ComponentType<FieldProps>;
|
|
10
|
+
}): IOtpInputComponentType<RootProps, CellProps, FieldProps, RootRef, FieldRef>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/otp-input/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,mBAAmB,SAAS,CAAC;AAE7B,wBAAgB,cAAc,CAC5B,SAAS,EACT,SAAS,EACT,UAAU,EACV,OAAO,GAAG,OAAO,EACjB,QAAQ,GAAG,OAAO,EAClB,cAAc,EAAE;IAChB,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;CACxC,GAYO,sBAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAClF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { TextInputProps, ViewProps } from 'react-native';
|
|
4
|
+
export interface IOtpInputRootProps extends ViewProps {
|
|
5
|
+
/** Number of OTP cells (fixed). */
|
|
6
|
+
cellCount: number;
|
|
7
|
+
/** Controlled value: characters in order, length 0..`cellCount` (prefix fill). */
|
|
8
|
+
value: string;
|
|
9
|
+
onChangeText: (value: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Called when the code is ready to verify again:
|
|
12
|
+
* - `value` becomes full (`length === cellCount`) after being shorter, or
|
|
13
|
+
* - `value` stays full but the string changes (user corrected a digit without dropping below full length).
|
|
14
|
+
* Does not fire on mount when `value` is already full and unchanged, nor on re-renders with the same full `value`.
|
|
15
|
+
*/
|
|
16
|
+
onComplete?: () => void;
|
|
17
|
+
isDisabled?: boolean;
|
|
18
|
+
isInvalid?: boolean;
|
|
19
|
+
isReadOnly?: boolean;
|
|
20
|
+
/** When false, no SMS / Web OTP autofill hints on the first cell. @default true */
|
|
21
|
+
smsOtpAutofill?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Override default digit-only filtering.
|
|
24
|
+
* Takes priority over `allowedCharacters` and `characterPattern` when truthy.
|
|
25
|
+
* Does not change the default `keyboardType` (`number-pad`); use `getCellProps` if the allowed
|
|
26
|
+
* character set needs a different keyboard.
|
|
27
|
+
*/
|
|
28
|
+
filterInput?: (input: string) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Keep only characters present in this string (treated as a set of code units).
|
|
31
|
+
* Used when `filterInput` is not provided. Takes priority over `characterPattern`.
|
|
32
|
+
* Default keyboard remains numeric; use `getCellProps` to set `keyboardType` when allowing letters/symbols.
|
|
33
|
+
*/
|
|
34
|
+
allowedCharacters?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Keep only characters matching this pattern (tested per code unit).
|
|
37
|
+
* Used when neither `filterInput` nor `allowedCharacters` is provided.
|
|
38
|
+
* Default keyboard remains numeric; use `getCellProps` to set `keyboardType` for non-digit input.
|
|
39
|
+
*/
|
|
40
|
+
characterPattern?: RegExp;
|
|
41
|
+
/**
|
|
42
|
+
* Spread onto each cell after built-in field props (including `keyboardType="number-pad"`),
|
|
43
|
+
* so consumers can override `keyboardType`, `autoCapitalize`, etc. for non-digit OTPs.
|
|
44
|
+
*/
|
|
45
|
+
getCellProps?: (index: number) => Partial<TextInputProps>;
|
|
46
|
+
/** Optional prefix for `testID` on each field: `${cellTestIdPrefix}:${index}:...` */
|
|
47
|
+
cellTestIdPrefix?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface IOtpInputCellProps extends ViewProps {
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
export type IOtpInputFieldProps = TextInputProps;
|
|
53
|
+
export interface OtpInputCellIndexContextValue {
|
|
54
|
+
cellIndex: number;
|
|
55
|
+
}
|
|
56
|
+
export interface OtpInputContextValue {
|
|
57
|
+
cellCount: number;
|
|
58
|
+
value: string;
|
|
59
|
+
isDisabled: boolean;
|
|
60
|
+
isInvalid: boolean;
|
|
61
|
+
isReadOnly: boolean;
|
|
62
|
+
smsOtpAutofill: boolean;
|
|
63
|
+
filter: (input: string) => string;
|
|
64
|
+
getCellProps?: (index: number) => Partial<TextInputProps>;
|
|
65
|
+
cellTestIdPrefix?: string;
|
|
66
|
+
rootAccessibilityLabel?: string;
|
|
67
|
+
setFieldRef: (index: number, el: import('react-native').TextInput | null) => void;
|
|
68
|
+
handleFieldChange: (index: number, text: string) => void;
|
|
69
|
+
handleFieldKeyPress: (index: number, key: string) => void;
|
|
70
|
+
}
|
|
71
|
+
export type IOtpInputComponentType<RootProps, CellProps, FieldProps, RootRef = unknown, FieldRef = unknown> = React.ForwardRefExoticComponent<React.PropsWithoutRef<RootProps & IOtpInputRootProps> & React.RefAttributes<RootRef>> & {
|
|
72
|
+
Cell: React.ForwardRefExoticComponent<React.PropsWithoutRef<CellProps & IOtpInputCellProps> & React.RefAttributes<unknown>>;
|
|
73
|
+
Field: React.ForwardRefExoticComponent<React.PropsWithoutRef<FieldProps & IOtpInputFieldProps> & React.RefAttributes<FieldRef>>;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/otp-input/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure OTP value transition for a controlled prefix string (no explicit empty slots).
|
|
3
|
+
* - Single-character edits use index-based replace/append (no reorder).
|
|
4
|
+
* - Multi-character input (paste/autofill) writes at `index` forward, then packs left.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyOtpInputChange(value: string, index: number, rawText: string, cellCount: number, filter: (input: string) => string): {
|
|
7
|
+
nextValue: string;
|
|
8
|
+
focusIndex: number;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=applyValueChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyValueChange.d.ts","sourceRoot":"","sources":["../../../../src/otp-input/utils/applyValueChange.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAChC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CA4C3C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Strip to digits (default OTP behavior). */
|
|
2
|
+
export declare function filterDigits(input: string): string;
|
|
3
|
+
/** Keep only characters present in `allowed` (treat as a set of UTF-16 code units). */
|
|
4
|
+
export declare function filterAllowedCharacters(allowed: string): (input: string) => string;
|
|
5
|
+
/** Keep only characters matching `re` (tested per UTF-16 code unit). */
|
|
6
|
+
export declare function filterByRegExp(re: RegExp): (input: string) => string;
|
|
7
|
+
//# sourceMappingURL=filterValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterValue.d.ts","sourceRoot":"","sources":["../../../../src/otp-input/utils/filterValue.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,IAK7C,OAAO,MAAM,YAUtB;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAC/B,OAAO,MAAM,YAWtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/primitives",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.37",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"module": "lib/module/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@react-native-aria/interactions": "^0.2.16",
|
|
58
58
|
"@react-stately/checkbox": "3.7.4",
|
|
59
59
|
"@react-stately/toggle": "3.9.4",
|
|
60
|
-
"@cdx-ui/utils": "0.0.1-alpha.
|
|
60
|
+
"@cdx-ui/utils": "0.0.1-alpha.37"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/react": "*",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldError = <T,>(BaseFormError: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => {
|
|
6
6
|
const { isInvalid, feedbackId, setHasFeedbackText } = useFormControlContext();
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldErrorIcon = <T,>(BaseFormErrorIcon: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormErrorIcon ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldErrorText = <T,>(BaseFormErrorText: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormErrorText ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldHelper = <T,>(BaseFormHelper: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => {
|
|
6
6
|
const { helpTextId, setHasHelpText, isInvalid } = useFormControlContext();
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldHelperText = <T,>(BaseFormHelperText: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormHelperText ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -2,10 +2,10 @@ import type React from 'react';
|
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
4
4
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
5
|
-
import type {
|
|
5
|
+
import type { IFieldLabelProps } from './types';
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
forwardRef<unknown,
|
|
7
|
+
export const createFieldLabel = <T,>(BaseFormLabel: React.ComponentType<T>) =>
|
|
8
|
+
forwardRef<unknown, IFieldLabelProps & { children?: React.ReactNode }>(
|
|
9
9
|
({ children, htmlFor: htmlForProp, requiredIndicator, ...props }, ref) => {
|
|
10
10
|
const field = useFormControlContext();
|
|
11
11
|
const fieldId = field.id;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlRoot, FormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
4
|
-
import type {
|
|
4
|
+
import type { IFieldRootProps } from './types';
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const createFieldRoot = <T,>(BaseFormField: React.ComponentType<T>) =>
|
|
7
7
|
forwardRef(
|
|
8
|
-
({ children, ...props }:
|
|
8
|
+
({ children, ...props }: IFieldRootProps & { children?: React.ReactNode }, ref?: unknown) => {
|
|
9
9
|
const { htmlProps, ...context } = useFormControlRoot(props);
|
|
10
10
|
|
|
11
11
|
return (
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createFieldError } from './createFieldError';
|
|
3
|
+
import { createFieldErrorIcon } from './createFieldErrorIcon';
|
|
4
|
+
import { createFieldErrorText } from './createFieldErrorText';
|
|
5
|
+
import { createFieldRoot } from './createFieldRoot';
|
|
6
|
+
import { createFieldHelper } from './createFieldHelper';
|
|
7
|
+
import { createFieldHelperText } from './createFieldHelperText';
|
|
8
|
+
import { createFieldLabel } from './createFieldLabel';
|
|
9
|
+
import type { IFieldComponentType } from './types';
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
IFieldRootProps,
|
|
13
|
+
IFieldLabelProps,
|
|
14
|
+
IFieldHelperProps,
|
|
15
|
+
IFieldHelperTextProps,
|
|
16
|
+
IFieldErrorProps,
|
|
17
|
+
IFieldErrorTextProps,
|
|
18
|
+
IFieldErrorIconProps,
|
|
19
|
+
IFieldComponentType,
|
|
20
|
+
} from './types';
|
|
21
|
+
|
|
22
|
+
export function createField<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon>({
|
|
23
|
+
Root,
|
|
24
|
+
Label,
|
|
25
|
+
Helper,
|
|
26
|
+
HelperText,
|
|
27
|
+
Error,
|
|
28
|
+
ErrorText,
|
|
29
|
+
ErrorIcon,
|
|
30
|
+
}: {
|
|
31
|
+
Root: React.ComponentType<Root>;
|
|
32
|
+
Label: React.ComponentType<Label>;
|
|
33
|
+
Helper: React.ComponentType<Helper>;
|
|
34
|
+
HelperText: React.ComponentType<HelperText>;
|
|
35
|
+
Error: React.ComponentType<Error>;
|
|
36
|
+
ErrorText: React.ComponentType<ErrorText>;
|
|
37
|
+
ErrorIcon: React.ComponentType<ErrorIcon>;
|
|
38
|
+
}) {
|
|
39
|
+
const FieldRoot = createFieldRoot(Root);
|
|
40
|
+
FieldRoot.displayName = 'FieldPrimitive';
|
|
41
|
+
|
|
42
|
+
const FieldLabel = createFieldLabel(Label);
|
|
43
|
+
FieldLabel.displayName = 'FieldPrimitive.Label';
|
|
44
|
+
|
|
45
|
+
const FieldHelper = createFieldHelper(Helper);
|
|
46
|
+
FieldHelper.displayName = 'FieldPrimitive.Helper';
|
|
47
|
+
|
|
48
|
+
const FieldHelperText = createFieldHelperText(HelperText);
|
|
49
|
+
FieldHelperText.displayName = 'FieldPrimitive.HelperText';
|
|
50
|
+
|
|
51
|
+
const FieldError = createFieldError(Error);
|
|
52
|
+
FieldError.displayName = 'FieldPrimitive.Error';
|
|
53
|
+
|
|
54
|
+
const FieldErrorText = createFieldErrorText(ErrorText);
|
|
55
|
+
FieldErrorText.displayName = 'FieldPrimitive.ErrorText';
|
|
56
|
+
|
|
57
|
+
const FieldErrorIcon = createFieldErrorIcon(ErrorIcon);
|
|
58
|
+
FieldErrorIcon.displayName = 'FieldPrimitive.ErrorIcon';
|
|
59
|
+
|
|
60
|
+
return Object.assign(FieldRoot, {
|
|
61
|
+
Label: FieldLabel,
|
|
62
|
+
Helper: FieldHelper,
|
|
63
|
+
HelperText: FieldHelperText,
|
|
64
|
+
Error: FieldError,
|
|
65
|
+
ErrorText: FieldErrorText,
|
|
66
|
+
ErrorIcon: FieldErrorIcon,
|
|
67
|
+
}) as IFieldComponentType<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon>;
|
|
68
|
+
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { TextProps, ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Props for the Form container (`<form>` on web, `<View>` on RN).
|
|
6
|
-
* Does NOT provide field-level context — use `Form.Field` for that.
|
|
7
|
-
*
|
|
8
|
-
* Web-only submit props (`onSubmit`, `action`, `method`) belong in the
|
|
9
|
-
* platform-specific base component (`FormRoot.web.tsx`), not here.
|
|
10
|
-
*/
|
|
11
|
-
export interface IFormProps {}
|
|
12
|
-
|
|
13
4
|
/**
|
|
14
5
|
* Props for a single form field (`Form.Field`).
|
|
15
6
|
* Provides field-level context (name, validation state, ids) to children.
|
|
@@ -20,7 +11,7 @@ export interface IFormProps {}
|
|
|
20
11
|
*
|
|
21
12
|
* **Submit UX:** "focus first invalid on error" needs form-level validation state; not built in yet.
|
|
22
13
|
*/
|
|
23
|
-
export interface
|
|
14
|
+
export interface IFieldRootProps extends ViewProps {
|
|
24
15
|
/** Unique id for this field. Auto-generated if not provided. */
|
|
25
16
|
readonly id?: string;
|
|
26
17
|
/**
|
|
@@ -38,7 +29,7 @@ export interface IFormFieldProps extends ViewProps {
|
|
|
38
29
|
readonly isReadOnly?: boolean;
|
|
39
30
|
}
|
|
40
31
|
|
|
41
|
-
export interface
|
|
32
|
+
export interface IFieldLabelProps extends TextProps {
|
|
42
33
|
/**
|
|
43
34
|
* Associates the label with a control `id` on web (`<label htmlFor>`).
|
|
44
35
|
* If omitted, defaults to the same id `Input.Field` gets from form context: `fieldId + "-input"`.
|
|
@@ -52,41 +43,36 @@ export interface IFormLabelProps extends TextProps {
|
|
|
52
43
|
readonly requiredIndicator?: React.ReactNode;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
export interface
|
|
46
|
+
export interface IFieldHelperProps extends ViewProps {}
|
|
56
47
|
|
|
57
|
-
export interface
|
|
48
|
+
export interface IFieldHelperTextProps extends TextProps {}
|
|
58
49
|
|
|
59
|
-
export interface
|
|
50
|
+
export interface IFieldErrorProps extends ViewProps {}
|
|
60
51
|
|
|
61
|
-
export interface
|
|
52
|
+
export interface IFieldErrorTextProps extends TextProps {}
|
|
62
53
|
|
|
63
|
-
export interface
|
|
54
|
+
export interface IFieldErrorIconProps extends ViewProps {}
|
|
64
55
|
|
|
65
|
-
export type
|
|
66
|
-
Root
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
>;
|
|
87
|
-
ErrorIcon: React.ForwardRefExoticComponent<
|
|
88
|
-
InnerForwardRefExoticComponent<ErrorIcon> & IFormErrorIconProps
|
|
89
|
-
>;
|
|
90
|
-
};
|
|
56
|
+
export type IFieldComponentType<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon> =
|
|
57
|
+
React.ForwardRefExoticComponent<InnerForwardRefExoticComponent<Root> & IFieldRootProps> & {
|
|
58
|
+
Label: React.ForwardRefExoticComponent<
|
|
59
|
+
InnerForwardRefExoticComponent<Label> & IFieldLabelProps
|
|
60
|
+
>;
|
|
61
|
+
Helper: React.ForwardRefExoticComponent<
|
|
62
|
+
InnerForwardRefExoticComponent<Helper> & IFieldHelperProps
|
|
63
|
+
>;
|
|
64
|
+
HelperText: React.ForwardRefExoticComponent<
|
|
65
|
+
InnerForwardRefExoticComponent<HelperText> & IFieldHelperTextProps
|
|
66
|
+
>;
|
|
67
|
+
Error: React.ForwardRefExoticComponent<
|
|
68
|
+
InnerForwardRefExoticComponent<Error> & IFieldErrorProps
|
|
69
|
+
>;
|
|
70
|
+
ErrorText: React.ForwardRefExoticComponent<
|
|
71
|
+
InnerForwardRefExoticComponent<ErrorText> & IFieldErrorTextProps
|
|
72
|
+
>;
|
|
73
|
+
ErrorIcon: React.ForwardRefExoticComponent<
|
|
74
|
+
InnerForwardRefExoticComponent<ErrorIcon> & IFieldErrorIconProps
|
|
75
|
+
>;
|
|
76
|
+
};
|
|
91
77
|
|
|
92
78
|
type InnerForwardRefExoticComponent<T> = React.PropsWithoutRef<T> & React.RefAttributes<unknown>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IFormRootProps, IFormComponentType } from './types';
|
|
3
3
|
|
|
4
4
|
// TODO: Handle web submission (button type submit)
|
|
5
5
|
|
|
6
|
-
export const createFormRoot = <T,>(BaseFormRoot: React.ComponentType<T>) =>
|
|
6
|
+
export const createFormRoot = <T,>(BaseFormRoot: React.ComponentType<T>): IFormComponentType<T> =>
|
|
7
7
|
forwardRef(
|
|
8
|
-
({ children, ...props }:
|
|
8
|
+
({ children, ...props }: IFormRootProps & { children?: React.ReactNode }, ref?: unknown) => (
|
|
9
9
|
<BaseFormRoot ref={ref} {...(props as T)}>
|
|
10
10
|
{children}
|
|
11
11
|
</BaseFormRoot>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createFormRoot } from './createFormRoot';
|
|
3
|
+
|
|
4
|
+
export type { IFormRootProps, IFormComponentType } from './types';
|
|
5
|
+
|
|
6
|
+
export function createForm<Root>({ Root }: { Root: React.ComponentType<Root> }) {
|
|
7
|
+
const FormRoot = createFormRoot(Root);
|
|
8
|
+
|
|
9
|
+
FormRoot.displayName = 'FormPrimitive';
|
|
10
|
+
|
|
11
|
+
return FormRoot;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for the Form container (`<form>` on web, `<View>` on RN).
|
|
5
|
+
* Does NOT provide field-level context — use `Form.Field` for that.
|
|
6
|
+
*
|
|
7
|
+
* Web-only submit props (`onSubmit`, `action`, `method`) belong in the
|
|
8
|
+
* platform-specific base component (`FormRoot.web.tsx`), not here.
|
|
9
|
+
*/
|
|
10
|
+
export interface IFormRootProps {}
|
|
11
|
+
|
|
12
|
+
export type IFormComponentType<Root> = React.ForwardRefExoticComponent<
|
|
13
|
+
InnerForwardRefExoticComponent<Root> & IFormRootProps
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
type InnerForwardRefExoticComponent<T> = React.PropsWithoutRef<T> & React.RefAttributes<unknown>;
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,10 @@ export * from './avatar';
|
|
|
2
2
|
export * from './button';
|
|
3
3
|
export * from './checkbox';
|
|
4
4
|
export * from './dialog';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './field';
|
|
6
|
+
export * from './form';
|
|
6
7
|
export * from './input';
|
|
8
|
+
export * from './otp-input';
|
|
7
9
|
export * from './link';
|
|
8
10
|
export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
|
|
9
11
|
export * from './select';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext } from '@cdx-ui/utils';
|
|
2
|
+
import type { OtpInputCellIndexContextValue, OtpInputContextValue } from './types';
|
|
3
|
+
|
|
4
|
+
export const [OtpInputProvider, useOtpInputContext] =
|
|
5
|
+
createContext<OtpInputContextValue>('OtpInputContext');
|
|
6
|
+
|
|
7
|
+
export const [OtpCellIndexProvider, useOtpCellIndexContext] =
|
|
8
|
+
createContext<OtpInputCellIndexContextValue>('OtpCellIndexContext');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { useOtpInputContext } from './context';
|
|
5
|
+
import type { IOtpInputCellProps } from './types';
|
|
6
|
+
|
|
7
|
+
export const createOtpInputCell = <T,>(BaseCell: React.ComponentType<T>) =>
|
|
8
|
+
forwardRef<unknown, PropsWithChildren<IOtpInputCellProps & T>>(({ children, ...props }, ref) => {
|
|
9
|
+
const { isDisabled, isInvalid, isReadOnly } = useOtpInputContext();
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<BaseCell
|
|
13
|
+
ref={ref}
|
|
14
|
+
isDisabled={isDisabled}
|
|
15
|
+
isInvalid={isInvalid}
|
|
16
|
+
isReadOnly={isReadOnly}
|
|
17
|
+
{...(props as T)}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</BaseCell>
|
|
21
|
+
);
|
|
22
|
+
});
|