@cdx-ui/primitives 0.0.1-alpha.9 → 0.0.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/lib/commonjs/avatar/context.js +11 -0
- package/lib/commonjs/avatar/context.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarBadge.js +20 -0
- package/lib/commonjs/avatar/createAvatarBadge.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarIcon.js +30 -0
- package/lib/commonjs/avatar/createAvatarIcon.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarImage.js +51 -0
- package/lib/commonjs/avatar/createAvatarImage.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarRoot.js +34 -0
- package/lib/commonjs/avatar/createAvatarRoot.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarText.js +42 -0
- package/lib/commonjs/avatar/createAvatarText.js.map +1 -0
- package/lib/commonjs/avatar/index.js +30 -0
- package/lib/commonjs/avatar/index.js.map +1 -0
- package/lib/commonjs/avatar/types.js +6 -0
- package/lib/commonjs/avatar/types.js.map +1 -0
- package/lib/commonjs/button/index.js +25 -19
- package/lib/commonjs/button/index.js.map +1 -1
- package/lib/commonjs/checkbox/createCheckboxIcon.js +3 -2
- package/lib/commonjs/checkbox/createCheckboxIcon.js.map +1 -1
- package/lib/commonjs/checkbox/createCheckboxRoot.web.js +2 -0
- package/lib/commonjs/checkbox/createCheckboxRoot.web.js.map +1 -1
- package/lib/commonjs/checkbox/index.js +19 -21
- package/lib/commonjs/checkbox/index.js.map +1 -1
- package/lib/commonjs/dialog/context.js +11 -0
- package/lib/commonjs/dialog/context.js.map +1 -0
- package/lib/commonjs/dialog/createDialogBody.js +21 -0
- package/lib/commonjs/dialog/createDialogBody.js.map +1 -0
- package/lib/commonjs/dialog/createDialogClose.js +37 -0
- package/lib/commonjs/dialog/createDialogClose.js.map +1 -0
- package/lib/commonjs/dialog/createDialogContent.js +141 -0
- package/lib/commonjs/dialog/createDialogContent.js.map +1 -0
- package/lib/commonjs/dialog/createDialogDescription.js +30 -0
- package/lib/commonjs/dialog/createDialogDescription.js.map +1 -0
- package/lib/commonjs/dialog/createDialogFooter.js +21 -0
- package/lib/commonjs/dialog/createDialogFooter.js.map +1 -0
- package/lib/commonjs/dialog/createDialogHeader.js +21 -0
- package/lib/commonjs/dialog/createDialogHeader.js.map +1 -0
- package/lib/commonjs/dialog/createDialogRoot.js +54 -0
- package/lib/commonjs/dialog/createDialogRoot.js.map +1 -0
- package/lib/commonjs/dialog/createDialogTitle.js +21 -0
- package/lib/commonjs/dialog/createDialogTitle.js.map +1 -0
- package/lib/commonjs/dialog/createDialogTrigger.js +37 -0
- package/lib/commonjs/dialog/createDialogTrigger.js.map +1 -0
- package/lib/commonjs/dialog/index.js +60 -0
- package/lib/commonjs/dialog/index.js.map +1 -0
- package/lib/commonjs/dialog/types.js +6 -0
- package/lib/commonjs/dialog/types.js.map +1 -0
- package/lib/commonjs/field/createFieldError.js +41 -0
- package/lib/commonjs/field/createFieldError.js.map +1 -0
- package/lib/commonjs/field/createFieldErrorIcon.js +18 -0
- package/lib/commonjs/field/createFieldErrorIcon.js.map +1 -0
- package/lib/commonjs/field/createFieldErrorText.js +18 -0
- package/lib/commonjs/field/createFieldErrorText.js.map +1 -0
- package/lib/commonjs/field/createFieldHelper.js +41 -0
- package/lib/commonjs/field/createFieldHelper.js.map +1 -0
- package/lib/commonjs/field/createFieldHelperText.js +18 -0
- package/lib/commonjs/field/createFieldHelperText.js.map +1 -0
- package/lib/commonjs/field/createFieldLabel.js +36 -0
- package/lib/commonjs/field/createFieldLabel.js.map +1 -0
- package/lib/commonjs/field/createFieldRoot.js +35 -0
- 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/field/types.js +6 -0
- package/lib/commonjs/field/types.js.map +1 -0
- package/lib/commonjs/form/createFormRoot.js +21 -0
- 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/commonjs/form/types.js.map +1 -0
- package/lib/commonjs/index.js +93 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/input/createInputField.js +7 -2
- package/lib/commonjs/input/createInputField.js.map +1 -1
- package/lib/commonjs/input/index.js +13 -19
- package/lib/commonjs/input/index.js.map +1 -1
- package/lib/commonjs/link/LinkProvider.js +28 -0
- package/lib/commonjs/link/LinkProvider.js.map +1 -0
- package/lib/commonjs/link/createLink.js +74 -0
- package/lib/commonjs/link/createLink.js.map +1 -0
- package/lib/commonjs/link/index.js +27 -0
- package/lib/commonjs/link/index.js.map +1 -0
- package/lib/commonjs/link/types.js +6 -0
- package/lib/commonjs/link/types.js.map +1 -0
- package/lib/commonjs/link/useLink.js +56 -0
- package/lib/commonjs/link/useLink.js.map +1 -0
- 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/commonjs/overlay/OverlayContainer.js +8 -11
- package/lib/commonjs/overlay/OverlayContainer.js.map +1 -1
- package/lib/commonjs/overlay/index.js +7 -0
- package/lib/commonjs/overlay/index.js.map +1 -1
- package/lib/commonjs/overlay/useEscapeKey.js +14 -0
- package/lib/commonjs/overlay/useEscapeKey.js.map +1 -0
- package/lib/commonjs/overlay/useEscapeKey.web.js +30 -0
- package/lib/commonjs/overlay/useEscapeKey.web.js.map +1 -0
- package/lib/commonjs/progress/context.js +11 -0
- package/lib/commonjs/progress/context.js.map +1 -0
- package/lib/commonjs/progress/createProgressIndicator.js +42 -0
- package/lib/commonjs/progress/createProgressIndicator.js.map +1 -0
- package/lib/commonjs/progress/createProgressRoot.js +96 -0
- package/lib/commonjs/progress/createProgressRoot.js.map +1 -0
- package/lib/commonjs/progress/index.js +25 -0
- package/lib/commonjs/progress/index.js.map +1 -0
- package/lib/commonjs/progress/types.js +6 -0
- package/lib/commonjs/progress/types.js.map +1 -0
- package/lib/commonjs/select/context.js +8 -43
- package/lib/commonjs/select/context.js.map +1 -1
- package/lib/commonjs/select/createSelectItem.js +1 -1
- package/lib/commonjs/select/createSelectItem.js.map +1 -1
- package/lib/commonjs/select/createSelectRoot.js +9 -6
- package/lib/commonjs/select/createSelectRoot.js.map +1 -1
- package/lib/commonjs/select/createSelectTrigger.js +53 -12
- package/lib/commonjs/select/createSelectTrigger.js.map +1 -1
- package/lib/commonjs/utils/createPortal.js +23 -0
- package/lib/commonjs/utils/createPortal.js.map +1 -0
- package/lib/commonjs/utils/dataAttributes.web.js +1 -4
- package/lib/commonjs/utils/dataAttributes.web.js.map +1 -1
- package/lib/module/avatar/context.js +5 -0
- package/lib/module/avatar/context.js.map +1 -0
- package/lib/module/{input/createInputIcon.js → avatar/createAvatarBadge.js} +3 -3
- package/lib/module/avatar/createAvatarBadge.js.map +1 -0
- package/lib/module/avatar/createAvatarIcon.js +25 -0
- package/lib/module/avatar/createAvatarIcon.js.map +1 -0
- package/lib/module/avatar/createAvatarImage.js +46 -0
- package/lib/module/avatar/createAvatarImage.js.map +1 -0
- package/lib/module/avatar/createAvatarRoot.js +29 -0
- package/lib/module/avatar/createAvatarRoot.js.map +1 -0
- package/lib/module/avatar/createAvatarText.js +37 -0
- package/lib/module/avatar/createAvatarText.js.map +1 -0
- package/lib/module/avatar/index.js +26 -0
- package/lib/module/avatar/index.js.map +1 -0
- package/lib/module/avatar/types.js +4 -0
- package/lib/module/avatar/types.js.map +1 -0
- package/lib/module/button/index.js +19 -19
- package/lib/module/button/index.js.map +1 -1
- package/lib/module/checkbox/createCheckboxIcon.js +3 -2
- package/lib/module/checkbox/createCheckboxIcon.js.map +1 -1
- package/lib/module/checkbox/createCheckboxRoot.web.js +2 -0
- package/lib/module/checkbox/createCheckboxRoot.web.js.map +1 -1
- package/lib/module/checkbox/index.js +18 -19
- package/lib/module/checkbox/index.js.map +1 -1
- package/lib/module/dialog/context.js +5 -0
- package/lib/module/dialog/context.js.map +1 -0
- package/lib/module/dialog/createDialogBody.js +15 -0
- package/lib/module/dialog/createDialogBody.js.map +1 -0
- package/lib/module/dialog/createDialogClose.js +31 -0
- package/lib/module/dialog/createDialogClose.js.map +1 -0
- package/lib/module/dialog/createDialogContent.js +136 -0
- package/lib/module/dialog/createDialogContent.js.map +1 -0
- package/lib/module/dialog/createDialogDescription.js +24 -0
- package/lib/module/dialog/createDialogDescription.js.map +1 -0
- package/lib/module/dialog/createDialogFooter.js +15 -0
- package/lib/module/dialog/createDialogFooter.js.map +1 -0
- package/lib/module/dialog/createDialogHeader.js +15 -0
- package/lib/module/dialog/createDialogHeader.js.map +1 -0
- package/lib/module/dialog/createDialogRoot.js +49 -0
- package/lib/module/dialog/createDialogRoot.js.map +1 -0
- package/lib/module/dialog/createDialogTitle.js +15 -0
- package/lib/module/dialog/createDialogTitle.js.map +1 -0
- package/lib/module/dialog/createDialogTrigger.js +31 -0
- package/lib/module/dialog/createDialogTrigger.js.map +1 -0
- package/lib/module/dialog/index.js +45 -0
- package/lib/module/dialog/index.js.map +1 -0
- package/lib/module/dialog/types.js +4 -0
- package/lib/module/dialog/types.js.map +1 -0
- package/lib/module/field/createFieldError.js +35 -0
- package/lib/module/field/createFieldError.js.map +1 -0
- package/lib/module/field/createFieldErrorIcon.js +13 -0
- package/lib/module/field/createFieldErrorIcon.js.map +1 -0
- package/lib/module/field/createFieldErrorText.js +13 -0
- package/lib/module/field/createFieldErrorText.js.map +1 -0
- package/lib/module/field/createFieldHelper.js +35 -0
- package/lib/module/field/createFieldHelper.js.map +1 -0
- package/lib/module/field/createFieldHelperText.js +13 -0
- package/lib/module/field/createFieldHelperText.js.map +1 -0
- package/lib/module/field/createFieldLabel.js +31 -0
- package/lib/module/field/createFieldLabel.js.map +1 -0
- package/lib/module/field/createFieldRoot.js +29 -0
- 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 +4 -0
- package/lib/module/field/types.js.map +1 -0
- package/lib/module/form/createFormRoot.js +15 -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 +8 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/input/createInputField.js +8 -3
- package/lib/module/input/createInputField.js.map +1 -1
- package/lib/module/input/index.js +12 -17
- package/lib/module/input/index.js.map +1 -1
- package/lib/module/link/LinkProvider.js +23 -0
- package/lib/module/link/LinkProvider.js.map +1 -0
- package/lib/module/link/createLink.js +68 -0
- package/lib/module/link/createLink.js.map +1 -0
- package/lib/module/link/index.js +6 -0
- package/lib/module/link/index.js.map +1 -0
- package/lib/module/link/types.js +4 -0
- package/lib/module/link/types.js.map +1 -0
- package/lib/module/link/useLink.js +52 -0
- package/lib/module/link/useLink.js.map +1 -0
- 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/module/overlay/OverlayContainer.js +8 -11
- package/lib/module/overlay/OverlayContainer.js.map +1 -1
- package/lib/module/overlay/index.js +1 -0
- package/lib/module/overlay/index.js.map +1 -1
- package/lib/module/overlay/useEscapeKey.js +10 -0
- package/lib/module/overlay/useEscapeKey.js.map +1 -0
- package/lib/module/overlay/useEscapeKey.web.js +27 -0
- package/lib/module/overlay/useEscapeKey.web.js.map +1 -0
- package/lib/module/progress/context.js +5 -0
- package/lib/module/progress/context.js.map +1 -0
- package/lib/module/progress/createProgressIndicator.js +37 -0
- package/lib/module/progress/createProgressIndicator.js.map +1 -0
- package/lib/module/progress/createProgressRoot.js +91 -0
- package/lib/module/progress/createProgressRoot.js.map +1 -0
- package/lib/module/progress/index.js +15 -0
- package/lib/module/progress/index.js.map +1 -0
- package/lib/module/progress/types.js +4 -0
- package/lib/module/progress/types.js.map +1 -0
- package/lib/module/select/context.js +4 -42
- package/lib/module/select/context.js.map +1 -1
- package/lib/module/select/createSelectItem.js +2 -2
- package/lib/module/select/createSelectItem.js.map +1 -1
- package/lib/module/select/createSelectRoot.js +10 -7
- package/lib/module/select/createSelectRoot.js.map +1 -1
- package/lib/module/select/createSelectTrigger.js +56 -15
- package/lib/module/select/createSelectTrigger.js.map +1 -1
- package/lib/module/utils/createPortal.js +19 -0
- package/lib/module/utils/createPortal.js.map +1 -0
- package/lib/module/utils/dataAttributes.web.js +1 -4
- package/lib/module/utils/dataAttributes.web.js.map +1 -1
- package/lib/typescript/avatar/context.d.ts +6 -0
- package/lib/typescript/avatar/context.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarText.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarText.d.ts.map +1 -0
- package/lib/typescript/avatar/index.d.ts +11 -0
- package/lib/typescript/avatar/index.d.ts.map +1 -0
- package/lib/typescript/avatar/types.d.ts +33 -0
- package/lib/typescript/avatar/types.d.ts.map +1 -0
- package/lib/typescript/button/index.d.ts +2 -1
- package/lib/typescript/button/index.d.ts.map +1 -1
- package/lib/typescript/checkbox/context.d.ts +2 -2
- package/lib/typescript/checkbox/createCheckboxRoot.web.d.ts.map +1 -1
- package/lib/typescript/checkbox/index.d.ts +3 -2
- package/lib/typescript/checkbox/index.d.ts.map +1 -1
- package/lib/typescript/checkbox/useCheckboxRoot.d.ts +8 -3
- package/lib/typescript/checkbox/useCheckboxRoot.d.ts.map +1 -1
- package/lib/typescript/dialog/context.d.ts +6 -0
- package/lib/typescript/dialog/context.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogBody.d.ts +4 -0
- package/lib/typescript/dialog/createDialogBody.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogClose.d.ts +4 -0
- package/lib/typescript/dialog/createDialogClose.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogContent.d.ts +4 -0
- package/lib/typescript/dialog/createDialogContent.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogDescription.d.ts +4 -0
- package/lib/typescript/dialog/createDialogDescription.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogFooter.d.ts +4 -0
- package/lib/typescript/dialog/createDialogFooter.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogHeader.d.ts +4 -0
- package/lib/typescript/dialog/createDialogHeader.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogRoot.d.ts +4 -0
- package/lib/typescript/dialog/createDialogRoot.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogTitle.d.ts +4 -0
- package/lib/typescript/dialog/createDialogTitle.d.ts.map +1 -0
- package/lib/typescript/dialog/createDialogTrigger.d.ts +4 -0
- package/lib/typescript/dialog/createDialogTrigger.d.ts.map +1 -0
- package/lib/typescript/dialog/index.d.ts +18 -0
- package/lib/typescript/dialog/index.d.ts.map +1 -0
- package/lib/typescript/dialog/types.d.ts +52 -0
- package/lib/typescript/dialog/types.d.ts.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/field/types.d.ts +63 -0
- 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 +8 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/input/createInputField.d.ts.map +1 -1
- package/lib/typescript/input/index.d.ts +3 -3
- package/lib/typescript/input/index.d.ts.map +1 -1
- package/lib/typescript/input/types.d.ts +1 -2
- package/lib/typescript/input/types.d.ts.map +1 -1
- package/lib/typescript/link/LinkProvider.d.ts +36 -0
- package/lib/typescript/link/LinkProvider.d.ts.map +1 -0
- package/lib/typescript/link/createLink.d.ts +6 -0
- package/lib/typescript/link/createLink.d.ts.map +1 -0
- package/lib/typescript/link/index.d.ts +6 -0
- package/lib/typescript/link/index.d.ts.map +1 -0
- package/lib/typescript/link/types.d.ts +45 -0
- package/lib/typescript/link/types.d.ts.map +1 -0
- package/lib/typescript/link/useLink.d.ts +9 -0
- package/lib/typescript/link/useLink.d.ts.map +1 -0
- 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/lib/typescript/overlay/OverlayContainer.d.ts +5 -1
- package/lib/typescript/overlay/OverlayContainer.d.ts.map +1 -1
- package/lib/typescript/overlay/index.d.ts +1 -0
- package/lib/typescript/overlay/index.d.ts.map +1 -1
- package/lib/typescript/overlay/useEscapeKey.d.ts +6 -0
- package/lib/typescript/overlay/useEscapeKey.d.ts.map +1 -0
- package/lib/typescript/overlay/useEscapeKey.web.d.ts +6 -0
- package/lib/typescript/overlay/useEscapeKey.web.d.ts.map +1 -0
- package/lib/typescript/progress/context.d.ts +13 -0
- package/lib/typescript/progress/context.d.ts.map +1 -0
- package/lib/typescript/progress/createProgressIndicator.d.ts +3 -0
- package/lib/typescript/progress/createProgressIndicator.d.ts.map +1 -0
- package/lib/typescript/progress/createProgressRoot.d.ts +4 -0
- package/lib/typescript/progress/createProgressRoot.d.ts.map +1 -0
- package/lib/typescript/progress/index.d.ts +10 -0
- package/lib/typescript/progress/index.d.ts.map +1 -0
- package/lib/typescript/progress/types.d.ts +25 -0
- package/lib/typescript/progress/types.d.ts.map +1 -0
- package/lib/typescript/select/context.d.ts +14 -7
- package/lib/typescript/select/context.d.ts.map +1 -1
- package/lib/typescript/select/createSelectRoot.d.ts.map +1 -1
- package/lib/typescript/select/createSelectTrigger.d.ts +2 -7
- package/lib/typescript/select/createSelectTrigger.d.ts.map +1 -1
- package/lib/typescript/select/types.d.ts +4 -1
- package/lib/typescript/select/types.d.ts.map +1 -1
- package/lib/typescript/utils/createPortal.d.ts +11 -0
- package/lib/typescript/utils/createPortal.d.ts.map +1 -0
- package/lib/typescript/utils/dataAttributes.web.d.ts.map +1 -1
- package/package.json +8 -3
- package/src/avatar/context.tsx +5 -0
- package/src/avatar/createAvatarBadge.tsx +12 -0
- package/src/avatar/createAvatarIcon.tsx +16 -0
- package/src/avatar/createAvatarImage.tsx +40 -0
- package/src/avatar/createAvatarRoot.tsx +23 -0
- package/src/avatar/createAvatarText.tsx +30 -0
- package/src/avatar/index.ts +43 -0
- package/src/avatar/types.ts +77 -0
- package/src/button/index.tsx +19 -19
- package/src/checkbox/createCheckboxIcon.tsx +2 -2
- package/src/checkbox/createCheckboxRoot.web.tsx +2 -0
- package/src/checkbox/index.ts +20 -20
- package/src/dialog/context.tsx +4 -0
- package/src/dialog/createDialogBody.tsx +11 -0
- package/src/dialog/createDialogClose.tsx +27 -0
- package/src/dialog/createDialogContent.tsx +122 -0
- package/src/dialog/createDialogDescription.tsx +20 -0
- package/src/dialog/createDialogFooter.tsx +11 -0
- package/src/dialog/createDialogHeader.tsx +11 -0
- package/src/dialog/createDialogRoot.tsx +66 -0
- package/src/dialog/createDialogTitle.tsx +11 -0
- package/src/dialog/createDialogTrigger.tsx +27 -0
- package/src/dialog/index.tsx +93 -0
- package/src/dialog/types.ts +88 -0
- package/src/field/createFieldError.tsx +32 -0
- package/src/field/createFieldErrorIcon.tsx +9 -0
- package/src/field/createFieldErrorText.tsx +9 -0
- package/src/field/createFieldHelper.tsx +28 -0
- package/src/field/createFieldHelperText.tsx +9 -0
- package/src/field/createFieldLabel.tsx +30 -0
- package/src/field/createFieldRoot.tsx +27 -0
- package/src/field/index.tsx +68 -0
- package/src/field/types.tsx +78 -0
- package/src/form/createFormRoot.tsx +13 -0
- package/src/form/index.tsx +12 -0
- package/src/form/types.tsx +16 -0
- package/src/index.ts +8 -0
- package/src/input/createInputField.tsx +13 -3
- package/src/input/index.tsx +15 -28
- package/src/input/types.ts +0 -4
- package/src/link/LinkProvider.tsx +50 -0
- package/src/link/createLink.tsx +71 -0
- package/src/link/index.tsx +5 -0
- package/src/link/types.ts +47 -0
- package/src/link/useLink.ts +54 -0
- 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/src/overlay/OverlayContainer.tsx +9 -18
- package/src/overlay/index.ts +1 -0
- package/src/overlay/useEscapeKey.ts +7 -0
- package/src/overlay/useEscapeKey.web.ts +27 -0
- package/src/progress/context.tsx +13 -0
- package/src/progress/createProgressIndicator.tsx +35 -0
- package/src/progress/createProgressRoot.tsx +109 -0
- package/src/progress/index.ts +28 -0
- package/src/progress/types.ts +37 -0
- package/src/select/context.tsx +9 -44
- package/src/select/createSelectItem.tsx +3 -3
- package/src/select/createSelectRoot.tsx +10 -6
- package/src/select/createSelectTrigger.tsx +62 -36
- package/src/select/types.ts +4 -1
- package/src/utils/createPortal.ts +20 -0
- package/src/utils/dataAttributes.web.ts +2 -4
- package/lib/commonjs/input/createInputIcon.js +0 -20
- package/lib/commonjs/input/createInputIcon.js.map +0 -1
- package/lib/module/input/createInputIcon.js.map +0 -1
- package/lib/typescript/input/createInputIcon.d.ts +0 -4
- package/lib/typescript/input/createInputIcon.d.ts.map +0 -1
- package/src/input/createInputIcon.tsx +0 -12
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
3
|
+
import { useFocusRing, useFocus } from '@react-native-aria/focus';
|
|
4
|
+
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
5
|
+
import { dataAttributes } from '../utils/dataAttributes';
|
|
6
|
+
import { useLink } from './useLink';
|
|
7
|
+
import type { ILinkProps } from './types';
|
|
8
|
+
|
|
9
|
+
export const createLink = <RootT, R = unknown>({ Root }: { Root: React.ComponentType<RootT> }) =>
|
|
10
|
+
forwardRef(
|
|
11
|
+
(
|
|
12
|
+
{
|
|
13
|
+
children,
|
|
14
|
+
isHovered: isHoveredProp,
|
|
15
|
+
isPressed: isPressedProp,
|
|
16
|
+
isFocused: isFocusedProp,
|
|
17
|
+
isFocusVisible: isFocusVisibleProp,
|
|
18
|
+
href,
|
|
19
|
+
onPress,
|
|
20
|
+
action,
|
|
21
|
+
webProps,
|
|
22
|
+
...props
|
|
23
|
+
}: ILinkProps,
|
|
24
|
+
ref: React.ForwardedRef<R>,
|
|
25
|
+
) => {
|
|
26
|
+
const { isFocused, focusProps } = useFocus();
|
|
27
|
+
const { isFocusVisible, focusProps: focusRingProps } = useFocusRing() as {
|
|
28
|
+
isFocusVisible: boolean;
|
|
29
|
+
focusProps: typeof focusProps;
|
|
30
|
+
};
|
|
31
|
+
const { pressProps, isPressed } = usePress({});
|
|
32
|
+
const { isHovered, hoverProps } = useHover();
|
|
33
|
+
|
|
34
|
+
const { linkProps } = useLink({
|
|
35
|
+
href,
|
|
36
|
+
onPress,
|
|
37
|
+
action,
|
|
38
|
+
webProps,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const interactionAttrs = dataAttributes({
|
|
42
|
+
hover: isHoveredProp || isHovered,
|
|
43
|
+
focus: isFocusedProp || isFocused,
|
|
44
|
+
active: isPressedProp || isPressed,
|
|
45
|
+
focusVisible: isFocusVisibleProp || isFocusVisible,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Root
|
|
50
|
+
ref={ref}
|
|
51
|
+
{...interactionAttrs}
|
|
52
|
+
{...linkProps}
|
|
53
|
+
{...(props as RootT)}
|
|
54
|
+
onPressIn={composeEventHandlers(props?.onPressIn, pressProps.onPressIn)}
|
|
55
|
+
onPressOut={composeEventHandlers(props?.onPressOut, pressProps.onPressOut)}
|
|
56
|
+
onHoverIn={composeEventHandlers(props?.onHoverIn, hoverProps.onHoverIn)}
|
|
57
|
+
onHoverOut={composeEventHandlers(props?.onHoverOut, hoverProps.onHoverOut)}
|
|
58
|
+
onFocus={composeEventHandlers(
|
|
59
|
+
composeEventHandlers(props?.onFocus, focusProps.onFocus),
|
|
60
|
+
focusRingProps.onFocus,
|
|
61
|
+
)}
|
|
62
|
+
onBlur={composeEventHandlers(
|
|
63
|
+
composeEventHandlers(props?.onBlur, focusProps.onBlur),
|
|
64
|
+
focusRingProps.onBlur,
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</Root>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { GestureResponderEvent, PressableProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Navigation action forwarded to the `LinkProvider.navigate` callback.
|
|
6
|
+
*
|
|
7
|
+
* - `'navigate'` — (default) Smart navigation. In React Navigation this
|
|
8
|
+
* avoids duplicating a screen that is already in the stack. In expo-router
|
|
9
|
+
* it maps to `router.navigate()`.
|
|
10
|
+
* - `'push'` — Always pushes a new screen onto the navigation stack,
|
|
11
|
+
* even if the destination is already present.
|
|
12
|
+
* - `'replace'` — Replaces the current screen without adding to the stack.
|
|
13
|
+
* Useful for post-login redirects or wizard flows.
|
|
14
|
+
*/
|
|
15
|
+
export type LinkAction = 'navigate' | 'push' | 'replace';
|
|
16
|
+
|
|
17
|
+
export interface ILinkProps extends PressableProps {
|
|
18
|
+
/**
|
|
19
|
+
* URL that should be opened on Link press
|
|
20
|
+
*/
|
|
21
|
+
href?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Callback that will be invoked on Link press
|
|
24
|
+
*/
|
|
25
|
+
onPress?: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Navigation action forwarded to the `LinkProvider`.
|
|
28
|
+
* Defaults to `'navigate'`.
|
|
29
|
+
*/
|
|
30
|
+
action?: LinkAction;
|
|
31
|
+
isPressed?: boolean;
|
|
32
|
+
isHovered?: boolean;
|
|
33
|
+
isFocused?: boolean;
|
|
34
|
+
isFocusVisible?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* HTML anchor attributes applied only on web. Ignored on native platforms.
|
|
37
|
+
* `target`, `rel`, and `download` are forwarded via react-native-web's `hrefAttrs`.
|
|
38
|
+
*/
|
|
39
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IUseLinkProp {
|
|
43
|
+
href?: string;
|
|
44
|
+
onPress: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
45
|
+
action?: LinkAction;
|
|
46
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Linking, Platform } from 'react-native';
|
|
2
|
+
import type { AccessibilityRole, GestureResponderEvent } from 'react-native';
|
|
3
|
+
import { useLinkConfig } from './LinkProvider';
|
|
4
|
+
import type { IUseLinkProp } from './types';
|
|
5
|
+
|
|
6
|
+
function defaultNavigate(href: string): void {
|
|
7
|
+
Linking.canOpenURL(href)
|
|
8
|
+
.then((supported) => {
|
|
9
|
+
if (supported) return Linking.openURL(href);
|
|
10
|
+
console.warn(`Cannot open URL: ${href}`);
|
|
11
|
+
})
|
|
12
|
+
.catch((err: unknown) => console.error('Failed to open URL', err));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useLink(props: IUseLinkProp) {
|
|
16
|
+
const { href, onPress, action = 'navigate', webProps } = props;
|
|
17
|
+
const config = useLinkConfig();
|
|
18
|
+
|
|
19
|
+
const providerHandles = !!config && !!href && (config.shouldNavigate?.(href) ?? true);
|
|
20
|
+
|
|
21
|
+
let platformLinkProps = {};
|
|
22
|
+
|
|
23
|
+
if (Platform.OS === 'web') {
|
|
24
|
+
platformLinkProps = {
|
|
25
|
+
href: providerHandles ? undefined : href,
|
|
26
|
+
hrefAttrs: webProps,
|
|
27
|
+
onPress: (event: GestureResponderEvent) => {
|
|
28
|
+
onPress?.(event);
|
|
29
|
+
if (providerHandles) void config.navigate(href, action);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
platformLinkProps = {
|
|
34
|
+
onPress: (event: GestureResponderEvent) => {
|
|
35
|
+
onPress?.(event);
|
|
36
|
+
if (href) {
|
|
37
|
+
if (providerHandles) {
|
|
38
|
+
void config.navigate(href, action);
|
|
39
|
+
} else {
|
|
40
|
+
defaultNavigate(href);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
linkProps: {
|
|
49
|
+
...platformLinkProps,
|
|
50
|
+
role: 'link' as AccessibilityRole,
|
|
51
|
+
accessible: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useMemo } from 'react';
|
|
3
|
+
import { Platform, type TextInput, type TextInputKeyPressEvent } from 'react-native';
|
|
4
|
+
import { mergeRefs } from '@cdx-ui/utils';
|
|
5
|
+
import { useOtpCellIndexContext, useOtpInputContext } from './context';
|
|
6
|
+
import type { IOtpInputFieldProps } from './types';
|
|
7
|
+
|
|
8
|
+
export const createOtpInputField = <T,>(BaseField: React.ComponentType<T>) =>
|
|
9
|
+
forwardRef<TextInput, IOtpInputFieldProps & Omit<T, keyof IOtpInputFieldProps>>((props, ref) => {
|
|
10
|
+
const { cellIndex } = useOtpCellIndexContext();
|
|
11
|
+
const {
|
|
12
|
+
value,
|
|
13
|
+
cellCount,
|
|
14
|
+
isDisabled,
|
|
15
|
+
isReadOnly,
|
|
16
|
+
smsOtpAutofill,
|
|
17
|
+
getCellProps,
|
|
18
|
+
cellTestIdPrefix,
|
|
19
|
+
rootAccessibilityLabel,
|
|
20
|
+
setFieldRef,
|
|
21
|
+
handleFieldChange,
|
|
22
|
+
handleFieldKeyPress,
|
|
23
|
+
} = useOtpInputContext();
|
|
24
|
+
|
|
25
|
+
const char = cellIndex < value.length ? (value[cellIndex] ?? '') : '';
|
|
26
|
+
const extra = getCellProps?.(cellIndex) ?? {};
|
|
27
|
+
|
|
28
|
+
const accessibilityLabel = useMemo(() => {
|
|
29
|
+
const fromExtra = extra.accessibilityLabel;
|
|
30
|
+
if (typeof fromExtra === 'string' && fromExtra !== '') {
|
|
31
|
+
return fromExtra;
|
|
32
|
+
}
|
|
33
|
+
if (rootAccessibilityLabel) {
|
|
34
|
+
return `${rootAccessibilityLabel}, ${String(cellIndex + 1)} of ${String(cellCount)}`;
|
|
35
|
+
}
|
|
36
|
+
return `OTP digit ${String(cellIndex + 1)} of ${String(cellCount)}`;
|
|
37
|
+
}, [cellCount, cellIndex, extra.accessibilityLabel, rootAccessibilityLabel]);
|
|
38
|
+
|
|
39
|
+
const autofillProps = useMemo(() => {
|
|
40
|
+
if (!smsOtpAutofill || cellIndex !== 0) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
return Platform.select<Record<string, unknown>>({
|
|
44
|
+
web: { autoComplete: 'one-time-code' },
|
|
45
|
+
ios: { textContentType: 'oneTimeCode' },
|
|
46
|
+
android: { autoComplete: 'sms-otp' },
|
|
47
|
+
default: {},
|
|
48
|
+
});
|
|
49
|
+
}, [cellIndex, smsOtpAutofill]);
|
|
50
|
+
|
|
51
|
+
const editable = !(isDisabled || isReadOnly);
|
|
52
|
+
|
|
53
|
+
const { style: extraStyle, accessibilityLabel: _omitExtraA11y, ...extraRest } = extra;
|
|
54
|
+
void _omitExtraA11y;
|
|
55
|
+
const {
|
|
56
|
+
style: incomingStyle,
|
|
57
|
+
value: _omitValue,
|
|
58
|
+
defaultValue: _omitDefault,
|
|
59
|
+
onChangeText: _omitOnChange,
|
|
60
|
+
...incomingRest
|
|
61
|
+
} = props as IOtpInputFieldProps;
|
|
62
|
+
void _omitValue;
|
|
63
|
+
void _omitDefault;
|
|
64
|
+
void _omitOnChange;
|
|
65
|
+
|
|
66
|
+
// Default digit OTP (`number-pad`). Root `getCellProps` is spread after and may override `keyboardType`.
|
|
67
|
+
return (
|
|
68
|
+
<BaseField
|
|
69
|
+
ref={mergeRefs(ref, (el: TextInput | null) => {
|
|
70
|
+
setFieldRef(cellIndex, el);
|
|
71
|
+
})}
|
|
72
|
+
accessibilityLabel={accessibilityLabel}
|
|
73
|
+
aria-label={accessibilityLabel}
|
|
74
|
+
accessible
|
|
75
|
+
autoFocus={cellIndex === 0 && editable && value.length === 0}
|
|
76
|
+
editable={editable}
|
|
77
|
+
keyboardType="number-pad"
|
|
78
|
+
returnKeyType="done"
|
|
79
|
+
selectTextOnFocus
|
|
80
|
+
testID={
|
|
81
|
+
cellTestIdPrefix
|
|
82
|
+
? `${cellTestIdPrefix}:${String(cellIndex)}:textField:changeText`
|
|
83
|
+
: undefined
|
|
84
|
+
}
|
|
85
|
+
value={char}
|
|
86
|
+
onChangeText={(text: string) => {
|
|
87
|
+
handleFieldChange(cellIndex, text);
|
|
88
|
+
}}
|
|
89
|
+
onKeyPress={(e: TextInputKeyPressEvent) => {
|
|
90
|
+
handleFieldKeyPress(cellIndex, e.nativeEvent.key);
|
|
91
|
+
}}
|
|
92
|
+
{...autofillProps}
|
|
93
|
+
{...(extraRest as object)}
|
|
94
|
+
{...(incomingRest as T)}
|
|
95
|
+
style={[extraStyle, incomingStyle]}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import type { TextInput } from 'react-native';
|
|
4
|
+
import { useFormControlContext } from '@cdx-ui/utils';
|
|
5
|
+
import { applyOtpInputChange } from './utils/applyValueChange';
|
|
6
|
+
import { OtpCellIndexProvider, OtpInputProvider } from './context';
|
|
7
|
+
import { filterAllowedCharacters, filterByRegExp, filterDigits } from './utils/filterValue';
|
|
8
|
+
import type { IOtpInputRootProps } from './types';
|
|
9
|
+
|
|
10
|
+
export const createOtpInputRoot = <RootProps,>(
|
|
11
|
+
BaseRoot: React.ComponentType<RootProps>,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- slot components are generic across design systems
|
|
13
|
+
OtpCell: React.ComponentType<any>,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
OtpField: React.ComponentType<any>,
|
|
16
|
+
) =>
|
|
17
|
+
forwardRef<unknown, IOtpInputRootProps & RootProps>(
|
|
18
|
+
(
|
|
19
|
+
{
|
|
20
|
+
cellCount,
|
|
21
|
+
value,
|
|
22
|
+
onChangeText,
|
|
23
|
+
onComplete,
|
|
24
|
+
isDisabled: isDisabledProp,
|
|
25
|
+
isInvalid: isInvalidProp,
|
|
26
|
+
isReadOnly: isReadOnlyProp,
|
|
27
|
+
smsOtpAutofill = true,
|
|
28
|
+
filterInput,
|
|
29
|
+
allowedCharacters,
|
|
30
|
+
characterPattern,
|
|
31
|
+
getCellProps,
|
|
32
|
+
cellTestIdPrefix,
|
|
33
|
+
accessibilityLabel: rootAccessibilityLabel,
|
|
34
|
+
...rest
|
|
35
|
+
},
|
|
36
|
+
ref,
|
|
37
|
+
) => {
|
|
38
|
+
const form = useFormControlContext();
|
|
39
|
+
const isDisabled = isDisabledProp ?? form.isDisabled ?? false;
|
|
40
|
+
const isInvalid = isInvalidProp ?? form.isInvalid ?? false;
|
|
41
|
+
const isReadOnly = isReadOnlyProp ?? form.isReadOnly ?? false;
|
|
42
|
+
|
|
43
|
+
const fieldRefs = useRef<(TextInput | null)[]>([]);
|
|
44
|
+
const focusAfterApply = useRef<number | null>(null);
|
|
45
|
+
const prevLenRef = useRef(value.length);
|
|
46
|
+
const prevValueRef = useRef(value);
|
|
47
|
+
|
|
48
|
+
const filter = useMemo(() => {
|
|
49
|
+
if (filterInput) {
|
|
50
|
+
return filterInput;
|
|
51
|
+
}
|
|
52
|
+
if (allowedCharacters !== undefined) {
|
|
53
|
+
return filterAllowedCharacters(allowedCharacters);
|
|
54
|
+
}
|
|
55
|
+
if (characterPattern !== undefined) {
|
|
56
|
+
return filterByRegExp(characterPattern);
|
|
57
|
+
}
|
|
58
|
+
return filterDigits;
|
|
59
|
+
}, [filterInput, allowedCharacters, characterPattern]);
|
|
60
|
+
|
|
61
|
+
const setFieldRef = useCallback((index: number, el: TextInput | null) => {
|
|
62
|
+
fieldRefs.current[index] = el;
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const focusCell = useCallback(
|
|
66
|
+
(index: number) => {
|
|
67
|
+
const safe = Math.max(0, Math.min(index, cellCount - 1));
|
|
68
|
+
fieldRefs.current[safe]?.focus();
|
|
69
|
+
},
|
|
70
|
+
[cellCount],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const handleFieldChange = useCallback(
|
|
74
|
+
(index: number, text: string) => {
|
|
75
|
+
const { nextValue, focusIndex } = applyOtpInputChange(
|
|
76
|
+
value,
|
|
77
|
+
index,
|
|
78
|
+
text,
|
|
79
|
+
cellCount,
|
|
80
|
+
filter,
|
|
81
|
+
);
|
|
82
|
+
if (nextValue !== value) {
|
|
83
|
+
onChangeText(nextValue);
|
|
84
|
+
}
|
|
85
|
+
focusAfterApply.current = focusIndex;
|
|
86
|
+
},
|
|
87
|
+
[cellCount, filter, onChangeText, value],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const handleFieldKeyPress = useCallback(
|
|
91
|
+
(index: number, key: string) => {
|
|
92
|
+
if (key !== 'Backspace') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const char = index < value.length ? value[index] : '';
|
|
96
|
+
if (!char && index > 0) {
|
|
97
|
+
focusCell(index - 1);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
[focusCell, value],
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
useLayoutEffect(() => {
|
|
104
|
+
if (focusAfterApply.current !== null) {
|
|
105
|
+
const i = focusAfterApply.current;
|
|
106
|
+
focusAfterApply.current = null;
|
|
107
|
+
fieldRefs.current[i]?.focus();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const prevLen = prevLenRef.current;
|
|
113
|
+
const prevVal = prevValueRef.current;
|
|
114
|
+
const isFull = value.length === cellCount;
|
|
115
|
+
const becameFullByLength = isFull && prevLen < cellCount;
|
|
116
|
+
const correctedWhileFull = isFull && prevLen === cellCount && prevVal !== value;
|
|
117
|
+
|
|
118
|
+
if (becameFullByLength || correctedWhileFull) {
|
|
119
|
+
onComplete?.();
|
|
120
|
+
}
|
|
121
|
+
prevLenRef.current = value.length;
|
|
122
|
+
prevValueRef.current = value;
|
|
123
|
+
}, [cellCount, onComplete, value]);
|
|
124
|
+
|
|
125
|
+
const contextValue = useMemo(
|
|
126
|
+
() => ({
|
|
127
|
+
cellCount,
|
|
128
|
+
value,
|
|
129
|
+
isDisabled,
|
|
130
|
+
isInvalid,
|
|
131
|
+
isReadOnly,
|
|
132
|
+
smsOtpAutofill,
|
|
133
|
+
filter,
|
|
134
|
+
getCellProps,
|
|
135
|
+
cellTestIdPrefix,
|
|
136
|
+
rootAccessibilityLabel,
|
|
137
|
+
setFieldRef,
|
|
138
|
+
handleFieldChange,
|
|
139
|
+
handleFieldKeyPress,
|
|
140
|
+
}),
|
|
141
|
+
[
|
|
142
|
+
cellCount,
|
|
143
|
+
value,
|
|
144
|
+
isDisabled,
|
|
145
|
+
isInvalid,
|
|
146
|
+
isReadOnly,
|
|
147
|
+
smsOtpAutofill,
|
|
148
|
+
filter,
|
|
149
|
+
getCellProps,
|
|
150
|
+
cellTestIdPrefix,
|
|
151
|
+
rootAccessibilityLabel,
|
|
152
|
+
setFieldRef,
|
|
153
|
+
handleFieldChange,
|
|
154
|
+
handleFieldKeyPress,
|
|
155
|
+
],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// Hermes drops outer-scope closure vars from its environment record when
|
|
159
|
+
// they are only referenced inside a nested callback (Array.from). Using a
|
|
160
|
+
// for-loop keeps OtpCell/OtpField references in the render function's own
|
|
161
|
+
// scope, avoiding the Hermes closure-capture bug.
|
|
162
|
+
const cells: React.ReactElement[] = [];
|
|
163
|
+
for (let i = 0; i < cellCount; i++) {
|
|
164
|
+
cells.push(
|
|
165
|
+
<OtpCellIndexProvider key={i} value={{ cellIndex: i }}>
|
|
166
|
+
<OtpCell>
|
|
167
|
+
<OtpField />
|
|
168
|
+
</OtpCell>
|
|
169
|
+
</OtpCellIndexProvider>,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<BaseRoot ref={ref as React.Ref<unknown>} {...(rest as RootProps)}>
|
|
175
|
+
<OtpInputProvider value={contextValue}>{cells}</OtpInputProvider>
|
|
176
|
+
</BaseRoot>
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createOtpInputCell } from './createOtpInputCell';
|
|
3
|
+
import { createOtpInputField } from './createOtpInputField';
|
|
4
|
+
import { createOtpInputRoot } from './createOtpInputRoot';
|
|
5
|
+
import type { IOtpInputComponentType } from './types';
|
|
6
|
+
|
|
7
|
+
export { applyOtpInputChange } from './utils/applyValueChange';
|
|
8
|
+
export { filterAllowedCharacters, filterByRegExp, filterDigits } from './utils/filterValue';
|
|
9
|
+
export type * from './types';
|
|
10
|
+
|
|
11
|
+
export function createOtpInput<
|
|
12
|
+
RootProps,
|
|
13
|
+
CellProps,
|
|
14
|
+
FieldProps,
|
|
15
|
+
RootRef = unknown,
|
|
16
|
+
FieldRef = unknown,
|
|
17
|
+
>(BaseComponents: {
|
|
18
|
+
Root: React.ComponentType<RootProps>;
|
|
19
|
+
Cell: React.ComponentType<CellProps>;
|
|
20
|
+
Field: React.ComponentType<FieldProps>;
|
|
21
|
+
}) {
|
|
22
|
+
const Cell = createOtpInputCell(BaseComponents.Cell);
|
|
23
|
+
const Field = createOtpInputField(BaseComponents.Field);
|
|
24
|
+
const Root = createOtpInputRoot(BaseComponents.Root, Cell, Field);
|
|
25
|
+
|
|
26
|
+
Root.displayName = 'OtpInputPrimitive';
|
|
27
|
+
Cell.displayName = 'OtpInputPrimitive.Cell';
|
|
28
|
+
Field.displayName = 'OtpInputPrimitive.Field';
|
|
29
|
+
|
|
30
|
+
return Object.assign(Root, {
|
|
31
|
+
Cell,
|
|
32
|
+
Field,
|
|
33
|
+
}) as IOtpInputComponentType<RootProps, CellProps, FieldProps, RootRef, FieldRef>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { TextInputProps, ViewProps } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export interface IOtpInputRootProps extends ViewProps {
|
|
6
|
+
/** Number of OTP cells (fixed). */
|
|
7
|
+
cellCount: number;
|
|
8
|
+
/** Controlled value: characters in order, length 0..`cellCount` (prefix fill). */
|
|
9
|
+
value: string;
|
|
10
|
+
onChangeText: (value: string) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Called when the code is ready to verify again:
|
|
13
|
+
* - `value` becomes full (`length === cellCount`) after being shorter, or
|
|
14
|
+
* - `value` stays full but the string changes (user corrected a digit without dropping below full length).
|
|
15
|
+
* Does not fire on mount when `value` is already full and unchanged, nor on re-renders with the same full `value`.
|
|
16
|
+
*/
|
|
17
|
+
onComplete?: () => void;
|
|
18
|
+
isDisabled?: boolean;
|
|
19
|
+
isInvalid?: boolean;
|
|
20
|
+
isReadOnly?: boolean;
|
|
21
|
+
/** When false, no SMS / Web OTP autofill hints on the first cell. @default true */
|
|
22
|
+
smsOtpAutofill?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Override default digit-only filtering.
|
|
25
|
+
* Takes priority over `allowedCharacters` and `characterPattern` when truthy.
|
|
26
|
+
* Does not change the default `keyboardType` (`number-pad`); use `getCellProps` if the allowed
|
|
27
|
+
* character set needs a different keyboard.
|
|
28
|
+
*/
|
|
29
|
+
filterInput?: (input: string) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Keep only characters present in this string (treated as a set of code units).
|
|
32
|
+
* Used when `filterInput` is not provided. Takes priority over `characterPattern`.
|
|
33
|
+
* Default keyboard remains numeric; use `getCellProps` to set `keyboardType` when allowing letters/symbols.
|
|
34
|
+
*/
|
|
35
|
+
allowedCharacters?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Keep only characters matching this pattern (tested per code unit).
|
|
38
|
+
* Used when neither `filterInput` nor `allowedCharacters` is provided.
|
|
39
|
+
* Default keyboard remains numeric; use `getCellProps` to set `keyboardType` for non-digit input.
|
|
40
|
+
*/
|
|
41
|
+
characterPattern?: RegExp;
|
|
42
|
+
/**
|
|
43
|
+
* Spread onto each cell after built-in field props (including `keyboardType="number-pad"`),
|
|
44
|
+
* so consumers can override `keyboardType`, `autoCapitalize`, etc. for non-digit OTPs.
|
|
45
|
+
*/
|
|
46
|
+
getCellProps?: (index: number) => Partial<TextInputProps>;
|
|
47
|
+
/** Optional prefix for `testID` on each field: `${cellTestIdPrefix}:${index}:...` */
|
|
48
|
+
cellTestIdPrefix?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface IOtpInputCellProps extends ViewProps {
|
|
52
|
+
children?: ReactNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type IOtpInputFieldProps = TextInputProps;
|
|
56
|
+
|
|
57
|
+
export interface OtpInputCellIndexContextValue {
|
|
58
|
+
cellIndex: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface OtpInputContextValue {
|
|
62
|
+
cellCount: number;
|
|
63
|
+
value: string;
|
|
64
|
+
isDisabled: boolean;
|
|
65
|
+
isInvalid: boolean;
|
|
66
|
+
isReadOnly: boolean;
|
|
67
|
+
smsOtpAutofill: boolean;
|
|
68
|
+
filter: (input: string) => string;
|
|
69
|
+
getCellProps?: (index: number) => Partial<TextInputProps>;
|
|
70
|
+
cellTestIdPrefix?: string;
|
|
71
|
+
rootAccessibilityLabel?: string;
|
|
72
|
+
setFieldRef: (index: number, el: import('react-native').TextInput | null) => void;
|
|
73
|
+
handleFieldChange: (index: number, text: string) => void;
|
|
74
|
+
handleFieldKeyPress: (index: number, key: string) => void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type IOtpInputComponentType<
|
|
78
|
+
RootProps,
|
|
79
|
+
CellProps,
|
|
80
|
+
FieldProps,
|
|
81
|
+
RootRef = unknown,
|
|
82
|
+
FieldRef = unknown,
|
|
83
|
+
> = React.ForwardRefExoticComponent<
|
|
84
|
+
React.PropsWithoutRef<RootProps & IOtpInputRootProps> & React.RefAttributes<RootRef>
|
|
85
|
+
> & {
|
|
86
|
+
Cell: React.ForwardRefExoticComponent<
|
|
87
|
+
React.PropsWithoutRef<CellProps & IOtpInputCellProps> & React.RefAttributes<unknown>
|
|
88
|
+
>;
|
|
89
|
+
Field: React.ForwardRefExoticComponent<
|
|
90
|
+
React.PropsWithoutRef<FieldProps & IOtpInputFieldProps> & React.RefAttributes<FieldRef>
|
|
91
|
+
>;
|
|
92
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 function applyOtpInputChange(
|
|
7
|
+
value: string,
|
|
8
|
+
index: number,
|
|
9
|
+
rawText: string,
|
|
10
|
+
cellCount: number,
|
|
11
|
+
filter: (input: string) => string,
|
|
12
|
+
): { nextValue: string; focusIndex: number } {
|
|
13
|
+
const text = filter(rawText);
|
|
14
|
+
|
|
15
|
+
if (text.length === 0) {
|
|
16
|
+
if (index < value.length) {
|
|
17
|
+
const next = (value.slice(0, index) + value.slice(index + 1)).slice(0, cellCount);
|
|
18
|
+
return { nextValue: next, focusIndex: Math.max(0, index - 1) };
|
|
19
|
+
}
|
|
20
|
+
return { nextValue: value, focusIndex: index };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (text.length === 1) {
|
|
24
|
+
if (index < value.length) {
|
|
25
|
+
const next = (value.slice(0, index) + text + value.slice(index + 1)).slice(0, cellCount);
|
|
26
|
+
return { nextValue: next, focusIndex: Math.min(index + 1, cellCount - 1) };
|
|
27
|
+
}
|
|
28
|
+
if (value.length < cellCount) {
|
|
29
|
+
if (index === value.length) {
|
|
30
|
+
const next = (value + text).slice(0, cellCount);
|
|
31
|
+
return { nextValue: next, focusIndex: Math.min(next.length, cellCount - 1) };
|
|
32
|
+
}
|
|
33
|
+
const arr = Array.from({ length: cellCount }, (_, i) => (i < value.length ? value[i] : ''));
|
|
34
|
+
arr[index] = text;
|
|
35
|
+
const next = arr
|
|
36
|
+
.filter((c) => c)
|
|
37
|
+
.join('')
|
|
38
|
+
.slice(0, cellCount);
|
|
39
|
+
return { nextValue: next, focusIndex: Math.min(index + 1, cellCount - 1) };
|
|
40
|
+
}
|
|
41
|
+
const next = (value.slice(0, index) + text + value.slice(index + 1)).slice(0, cellCount);
|
|
42
|
+
return { nextValue: next, focusIndex: Math.min(index + 1, cellCount - 1) };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const arr = Array.from({ length: cellCount }, (_, i) => (i < value.length ? value[i] : ''));
|
|
46
|
+
for (let k = 0; k < text.length && index + k < cellCount; k++) {
|
|
47
|
+
arr[index + k] = text.charAt(k);
|
|
48
|
+
}
|
|
49
|
+
const next = arr
|
|
50
|
+
.filter((c) => c)
|
|
51
|
+
.join('')
|
|
52
|
+
.slice(0, cellCount);
|
|
53
|
+
const lastWritten = Math.min(index + text.length - 1, cellCount - 1);
|
|
54
|
+
const focusIndex = Math.min(Math.max(lastWritten, next.length - 1), cellCount - 1);
|
|
55
|
+
return { nextValue: next, focusIndex: Math.max(0, focusIndex) };
|
|
56
|
+
}
|