@unif/react-native-design 0.19.0 → 0.21.0
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 +68 -12
- package/lib/module/components/business/AvatarWithRing/AvatarWithRing.js +4 -5
- package/lib/module/components/business/AvatarWithRing/AvatarWithRing.js.map +1 -1
- package/lib/module/components/business/AvatarWithRing/styles.js +10 -9
- package/lib/module/components/business/AvatarWithRing/styles.js.map +1 -1
- package/lib/module/components/business/VersionPill/VersionPill.js +32 -15
- package/lib/module/components/business/VersionPill/VersionPill.js.map +1 -1
- package/lib/module/components/business/VersionPill/content.js +30 -0
- package/lib/module/components/business/VersionPill/content.js.map +1 -0
- package/lib/module/components/business/VersionPill/styles.js +4 -0
- package/lib/module/components/business/VersionPill/styles.js.map +1 -1
- package/lib/module/components/business/useSvgId.js +17 -8
- package/lib/module/components/business/useSvgId.js.map +1 -1
- package/lib/module/components/ui/Avatar/Avatar.js +22 -29
- package/lib/module/components/ui/Avatar/Avatar.js.map +1 -1
- package/lib/module/components/ui/Button/Button.js +40 -23
- package/lib/module/components/ui/Button/Button.js.map +1 -1
- package/lib/module/components/ui/Button/ButtonBase.js +13 -13
- package/lib/module/components/ui/Button/ButtonBase.js.map +1 -1
- package/lib/module/components/ui/Carousel/Carousel.js +89 -65
- package/lib/module/components/ui/Carousel/Carousel.js.map +1 -1
- package/lib/module/components/ui/Carousel/behavior.js +60 -0
- package/lib/module/components/ui/Carousel/behavior.js.map +1 -0
- package/lib/module/components/ui/Carousel/styles.js +9 -14
- package/lib/module/components/ui/Carousel/styles.js.map +1 -1
- package/lib/module/components/ui/Cell/Cell.js +76 -65
- package/lib/module/components/ui/Cell/Cell.js.map +1 -1
- package/lib/module/components/ui/Cell/Leading.js +11 -5
- package/lib/module/components/ui/Cell/Leading.js.map +1 -1
- package/lib/module/components/ui/Cell/content.js +34 -0
- package/lib/module/components/ui/Cell/content.js.map +1 -0
- package/lib/module/components/ui/Checkbox/Checkbox.js +25 -8
- package/lib/module/components/ui/Checkbox/Checkbox.js.map +1 -1
- package/lib/module/components/ui/Confirm/ConfirmHost.js +49 -25
- package/lib/module/components/ui/Confirm/ConfirmHost.js.map +1 -1
- package/lib/module/components/ui/Confirm/confirm.js +15 -29
- package/lib/module/components/ui/Confirm/confirm.js.map +1 -1
- package/lib/module/components/ui/Confirm/labels.js +10 -0
- package/lib/module/components/ui/Confirm/labels.js.map +1 -0
- package/lib/module/components/ui/Confirm/store.js +113 -0
- package/lib/module/components/ui/Confirm/store.js.map +1 -0
- package/lib/module/components/ui/Confirm/styles.js +4 -0
- package/lib/module/components/ui/Confirm/styles.js.map +1 -1
- package/lib/module/components/ui/DrawerHeader/DrawerHeader.js +17 -25
- package/lib/module/components/ui/DrawerHeader/DrawerHeader.js.map +1 -1
- package/lib/module/components/ui/Grid/Grid.js +26 -9
- package/lib/module/components/ui/Grid/Grid.js.map +1 -1
- package/lib/module/components/ui/Grid/accessibility.js +13 -0
- package/lib/module/components/ui/Grid/accessibility.js.map +1 -0
- package/lib/module/components/ui/IconButton/IconButton.js +16 -3
- package/lib/module/components/ui/IconButton/IconButton.js.map +1 -1
- package/lib/module/components/ui/Input/Input.js +8 -5
- package/lib/module/components/ui/Input/Input.js.map +1 -1
- package/lib/module/components/ui/Logo/Logo.js +22 -4
- package/lib/module/components/ui/Logo/Logo.js.map +1 -1
- package/lib/module/components/ui/NavBar/NavBar.js +23 -14
- package/lib/module/components/ui/NavBar/NavBar.js.map +1 -1
- package/lib/module/components/ui/NavBar/isSlot.js +297 -4
- package/lib/module/components/ui/NavBar/isSlot.js.map +1 -1
- package/lib/module/components/ui/PasswordInput/PasswordInput.js +61 -66
- package/lib/module/components/ui/PasswordInput/PasswordInput.js.map +1 -1
- package/lib/module/components/ui/Pulse/Pulse.js +1 -1
- package/lib/module/components/ui/Pulse/Pulse.js.map +1 -1
- package/lib/module/components/ui/Pulse/PulseDot.js +5 -7
- package/lib/module/components/ui/Pulse/PulseDot.js.map +1 -1
- package/lib/module/components/ui/Pulse/index.js +1 -1
- package/lib/module/components/ui/Pulse/index.js.map +1 -1
- package/lib/module/components/ui/Pulse/normalizePulseOptions.js +45 -0
- package/lib/module/components/ui/Pulse/normalizePulseOptions.js.map +1 -0
- package/lib/module/components/ui/Pulse/usePulse.js +61 -24
- package/lib/module/components/ui/Pulse/usePulse.js.map +1 -1
- package/lib/module/components/ui/Pulse/usePulseDriver.js +44 -0
- package/lib/module/components/ui/Pulse/usePulseDriver.js.map +1 -0
- package/lib/module/components/ui/Pulse/usePulseDriver.web.js +67 -0
- package/lib/module/components/ui/Pulse/usePulseDriver.web.js.map +1 -0
- package/lib/module/components/ui/Radio/Radio.js +31 -14
- package/lib/module/components/ui/Radio/Radio.js.map +1 -1
- package/lib/module/components/ui/Radio/RadioGroup.js +15 -2
- package/lib/module/components/ui/Radio/RadioGroup.js.map +1 -1
- package/lib/module/components/ui/Reveal/Reveal.js +4 -3
- package/lib/module/components/ui/Reveal/Reveal.js.map +1 -1
- package/lib/module/components/ui/Reveal/Reveal.web.js +55 -32
- package/lib/module/components/ui/Reveal/Reveal.web.js.map +1 -1
- package/lib/module/components/ui/Reveal/webTransition.js +157 -0
- package/lib/module/components/ui/Reveal/webTransition.js.map +1 -0
- package/lib/module/components/ui/Search/Search.js +85 -58
- package/lib/module/components/ui/Search/Search.js.map +1 -1
- package/lib/module/components/ui/Segmented/Segmented.js +4 -2
- package/lib/module/components/ui/Segmented/Segmented.js.map +1 -1
- package/lib/module/components/ui/Skeleton/Skeleton.js +5 -7
- package/lib/module/components/ui/Skeleton/Skeleton.js.map +1 -1
- package/lib/module/components/ui/Spinner/Spinner.js +18 -11
- package/lib/module/components/ui/Spinner/Spinner.js.map +1 -1
- package/lib/module/components/ui/Spinner/Spinner.web.js +18 -14
- package/lib/module/components/ui/Spinner/Spinner.web.js.map +1 -1
- package/lib/module/components/ui/Spinner/shared.js +6 -0
- package/lib/module/components/ui/Spinner/shared.js.map +1 -1
- package/lib/module/components/ui/Stepper/Stepper.js +131 -99
- package/lib/module/components/ui/Stepper/Stepper.js.map +1 -1
- package/lib/module/components/ui/Stepper/StepperPressable.js +4 -0
- package/lib/module/components/ui/Stepper/StepperPressable.js.map +1 -0
- package/lib/module/components/ui/Stepper/StepperPressable.web.js +4 -0
- package/lib/module/components/ui/Stepper/StepperPressable.web.js.map +1 -0
- package/lib/module/components/ui/Stepper/accessibility.js +30 -0
- package/lib/module/components/ui/Stepper/accessibility.js.map +1 -0
- package/lib/module/components/ui/Stepper/accessibility.types.js +4 -0
- package/lib/module/components/ui/Stepper/accessibility.types.js.map +1 -0
- package/lib/module/components/ui/Stepper/accessibility.web.js +57 -0
- package/lib/module/components/ui/Stepper/accessibility.web.js.map +1 -0
- package/lib/module/components/ui/Stepper/layout.js +28 -0
- package/lib/module/components/ui/Stepper/layout.js.map +1 -0
- package/lib/module/components/ui/Stepper/normalizeStepper.js +53 -0
- package/lib/module/components/ui/Stepper/normalizeStepper.js.map +1 -0
- package/lib/module/components/ui/Stepper/styles.js +9 -2
- package/lib/module/components/ui/Stepper/styles.js.map +1 -1
- package/lib/module/components/ui/Switch/Switch.js +45 -19
- package/lib/module/components/ui/Switch/Switch.js.map +1 -1
- package/lib/module/components/ui/Switch/Switch.web.js +47 -20
- package/lib/module/components/ui/Switch/Switch.web.js.map +1 -1
- package/lib/module/components/ui/Switch/styles.js +12 -5
- package/lib/module/components/ui/Switch/styles.js.map +1 -1
- package/lib/module/components/ui/Tag/Tag.js +3 -2
- package/lib/module/components/ui/Tag/Tag.js.map +1 -1
- package/lib/module/components/ui/TextField/TextFieldBase.js +131 -86
- package/lib/module/components/ui/TextField/TextFieldBase.js.map +1 -1
- package/lib/module/components/ui/TextField/TextFieldSlot.js +82 -0
- package/lib/module/components/ui/TextField/TextFieldSlot.js.map +1 -0
- package/lib/module/components/ui/TextField/normalize.js +238 -0
- package/lib/module/components/ui/TextField/normalize.js.map +1 -0
- package/lib/module/components/ui/TextField/styles.js +31 -0
- package/lib/module/components/ui/TextField/styles.js.map +1 -1
- package/lib/module/components/ui/TextField/useErrorAnnouncement.js +27 -0
- package/lib/module/components/ui/TextField/useErrorAnnouncement.js.map +1 -0
- package/lib/module/components/ui/TextField/useTextFieldValue.js +66 -0
- package/lib/module/components/ui/TextField/useTextFieldValue.js.map +1 -0
- package/lib/module/components/ui/TextField/valueState.js +93 -0
- package/lib/module/components/ui/TextField/valueState.js.map +1 -0
- package/lib/module/components/ui/Textarea/Textarea.js +7 -3
- package/lib/module/components/ui/Textarea/Textarea.js.map +1 -1
- package/lib/module/components/ui/Thumbnail/Thumbnail.js +67 -48
- package/lib/module/components/ui/Thumbnail/Thumbnail.js.map +1 -1
- package/lib/module/components/ui/Thumbnail/normalize.js +58 -0
- package/lib/module/components/ui/Thumbnail/normalize.js.map +1 -0
- package/lib/module/components/ui/Thumbnail/styles.js +6 -11
- package/lib/module/components/ui/Thumbnail/styles.js.map +1 -1
- package/lib/module/components/ui/Toast/ToastHost.js +64 -21
- package/lib/module/components/ui/Toast/ToastHost.js.map +1 -1
- package/lib/module/components/ui/Toast/ToastHost.web.js +73 -24
- package/lib/module/components/ui/Toast/ToastHost.web.js.map +1 -1
- package/lib/module/components/ui/Toast/store.js +110 -0
- package/lib/module/components/ui/Toast/store.js.map +1 -0
- package/lib/module/components/ui/Toast/toast.js +17 -7
- package/lib/module/components/ui/Toast/toast.js.map +1 -1
- package/lib/module/components/ui/index.js.map +1 -1
- package/lib/module/components/ui/shared/ImageAttempt.js +28 -0
- package/lib/module/components/ui/shared/ImageAttempt.js.map +1 -0
- package/lib/module/components/ui/shared/a11y.js +21 -0
- package/lib/module/components/ui/shared/a11y.js.map +1 -0
- package/lib/module/components/ui/shared/accessibilityName.js +9 -0
- package/lib/module/components/ui/shared/accessibilityName.js.map +1 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.js +5 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.js.map +1 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js +13 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js.map +1 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.web.js +5 -0
- package/lib/module/components/ui/shared/selectImageAttemptSource.web.js.map +1 -0
- package/lib/module/icons/data.js +1 -1
- package/lib/module/icons/data.js.map +1 -1
- package/lib/module/theme/ThemeProvider.js +14 -4
- package/lib/module/theme/ThemeProvider.js.map +1 -1
- package/lib/module/theme/fontScale.js +13 -0
- package/lib/module/theme/fontScale.js.map +1 -0
- package/lib/module/theme/index.js +2 -4
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/themeContext.js +15 -0
- package/lib/module/theme/themeContext.js.map +1 -0
- package/lib/module/theme/themeDiagnostics.js +29 -0
- package/lib/module/theme/themeDiagnostics.js.map +1 -0
- package/lib/module/theme/usePrefersReducedMotion.js +11 -4
- package/lib/module/theme/usePrefersReducedMotion.js.map +1 -1
- package/lib/module/theme/usePrefersReducedMotion.web.js +5 -2
- package/lib/module/theme/usePrefersReducedMotion.web.js.map +1 -1
- package/lib/module/theme/useTheme.js +12 -25
- package/lib/module/theme/useTheme.js.map +1 -1
- package/lib/module/theme/useThemedStyles.js +9 -6
- package/lib/module/theme/useThemedStyles.js.map +1 -1
- package/lib/module/utils/imageSource.js +198 -0
- package/lib/module/utils/imageSource.js.map +1 -0
- package/lib/typescript/manual-tests/runtime-api/RuntimeApiScreen.d.ts +12 -0
- package/lib/typescript/manual-tests/runtime-api/RuntimeApiScreen.d.ts.map +1 -0
- package/lib/typescript/src/components/business/AvatarWithRing/AvatarWithRing.d.ts.map +1 -1
- package/lib/typescript/src/components/business/AvatarWithRing/styles.d.ts +8 -7
- package/lib/typescript/src/components/business/AvatarWithRing/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/business/VersionPill/VersionPill.d.ts +1 -1
- package/lib/typescript/src/components/business/VersionPill/VersionPill.d.ts.map +1 -1
- package/lib/typescript/src/components/business/VersionPill/content.d.ts +19 -0
- package/lib/typescript/src/components/business/VersionPill/content.d.ts.map +1 -0
- package/lib/typescript/src/components/business/VersionPill/index.d.ts +1 -1
- package/lib/typescript/src/components/business/VersionPill/index.d.ts.map +1 -1
- package/lib/typescript/src/components/business/VersionPill/styles.d.ts +4 -0
- package/lib/typescript/src/components/business/VersionPill/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/business/VersionPill/types.d.ts +6 -2
- package/lib/typescript/src/components/business/VersionPill/types.d.ts.map +1 -1
- package/lib/typescript/src/components/business/index.d.ts +1 -1
- package/lib/typescript/src/components/business/index.d.ts.map +1 -1
- package/lib/typescript/src/components/business/useSvgId.d.ts +6 -5
- package/lib/typescript/src/components/business/useSvgId.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Avatar/Avatar.d.ts +2 -2
- package/lib/typescript/src/components/ui/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Avatar/types.d.ts +6 -2
- package/lib/typescript/src/components/ui/Avatar/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Button/Button.d.ts +1 -1
- package/lib/typescript/src/components/ui/Button/Button.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts +5 -3
- package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Button/types.d.ts +5 -3
- package/lib/typescript/src/components/ui/Button/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Carousel/Carousel.d.ts +3 -3
- package/lib/typescript/src/components/ui/Carousel/Carousel.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Carousel/behavior.d.ts +25 -0
- package/lib/typescript/src/components/ui/Carousel/behavior.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Carousel/index.d.ts +1 -1
- package/lib/typescript/src/components/ui/Carousel/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Carousel/styles.d.ts +7 -12
- package/lib/typescript/src/components/ui/Carousel/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Carousel/types.d.ts +28 -17
- package/lib/typescript/src/components/ui/Carousel/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Cell/Cell.d.ts +1 -1
- package/lib/typescript/src/components/ui/Cell/Cell.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Cell/Leading.d.ts +2 -3
- package/lib/typescript/src/components/ui/Cell/Leading.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Cell/content.d.ts +18 -0
- package/lib/typescript/src/components/ui/Cell/content.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Cell/index.d.ts +1 -1
- package/lib/typescript/src/components/ui/Cell/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Cell/types.d.ts +66 -30
- package/lib/typescript/src/components/ui/Cell/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Checkbox/Checkbox.d.ts +1 -1
- package/lib/typescript/src/components/ui/Checkbox/Checkbox.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Checkbox/types.d.ts +12 -3
- package/lib/typescript/src/components/ui/Checkbox/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Confirm/ConfirmHost.d.ts +6 -3
- package/lib/typescript/src/components/ui/Confirm/ConfirmHost.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Confirm/confirm.d.ts +10 -4
- package/lib/typescript/src/components/ui/Confirm/confirm.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Confirm/labels.d.ts +6 -0
- package/lib/typescript/src/components/ui/Confirm/labels.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Confirm/store.d.ts +44 -0
- package/lib/typescript/src/components/ui/Confirm/store.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Confirm/styles.d.ts +3 -0
- package/lib/typescript/src/components/ui/Confirm/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Confirm/types.d.ts +0 -9
- package/lib/typescript/src/components/ui/Confirm/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/DrawerHeader/DrawerHeader.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/DrawerHeader/types.d.ts +7 -1
- package/lib/typescript/src/components/ui/DrawerHeader/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Grid/Grid.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Grid/accessibility.d.ts +5 -0
- package/lib/typescript/src/components/ui/Grid/accessibility.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Grid/types.d.ts +2 -0
- package/lib/typescript/src/components/ui/Grid/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts +1 -1
- package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/IconButton/types.d.ts +4 -2
- package/lib/typescript/src/components/ui/IconButton/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Input/Input.d.ts +5 -383
- package/lib/typescript/src/components/ui/Input/Input.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Input/index.d.ts +1 -0
- package/lib/typescript/src/components/ui/Input/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Input/types.d.ts +3 -17
- package/lib/typescript/src/components/ui/Input/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Logo/Logo.d.ts +2 -2
- package/lib/typescript/src/components/ui/Logo/Logo.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Logo/types.d.ts +2 -2
- package/lib/typescript/src/components/ui/Logo/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/NavBar/NavBar.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/NavBar/index.d.ts +1 -1
- package/lib/typescript/src/components/ui/NavBar/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/NavBar/isSlot.d.ts +24 -4
- package/lib/typescript/src/components/ui/NavBar/isSlot.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/NavBar/types.d.ts +8 -8
- package/lib/typescript/src/components/ui/NavBar/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/PasswordInput/PasswordInput.d.ts +6 -14
- package/lib/typescript/src/components/ui/PasswordInput/PasswordInput.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/PasswordInput/types.d.ts +4 -14
- package/lib/typescript/src/components/ui/PasswordInput/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Pulse/PulseDot.d.ts +1 -1
- package/lib/typescript/src/components/ui/Pulse/PulseDot.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Pulse/normalizePulseOptions.d.ts +32 -0
- package/lib/typescript/src/components/ui/Pulse/normalizePulseOptions.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Pulse/usePulse.d.ts +10 -5
- package/lib/typescript/src/components/ui/Pulse/usePulse.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Pulse/usePulseDriver.d.ts +11 -0
- package/lib/typescript/src/components/ui/Pulse/usePulseDriver.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Pulse/usePulseDriver.web.d.ts +18 -0
- package/lib/typescript/src/components/ui/Pulse/usePulseDriver.web.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Radio/Radio.d.ts +1 -1
- package/lib/typescript/src/components/ui/Radio/Radio.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Radio/RadioGroup.d.ts +2 -2
- package/lib/typescript/src/components/ui/Radio/RadioGroup.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Radio/types.d.ts +14 -3
- package/lib/typescript/src/components/ui/Radio/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Reveal/Reveal.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Reveal/Reveal.web.d.ts +2 -8
- package/lib/typescript/src/components/ui/Reveal/Reveal.web.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Reveal/types.d.ts +1 -1
- package/lib/typescript/src/components/ui/Reveal/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Reveal/webTransition.d.ts +38 -0
- package/lib/typescript/src/components/ui/Reveal/webTransition.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Search/Search.d.ts +4 -214
- package/lib/typescript/src/components/ui/Search/Search.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Search/types.d.ts +13 -6
- package/lib/typescript/src/components/ui/Search/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Segmented/Segmented.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Skeleton/Skeleton.d.ts +3 -3
- package/lib/typescript/src/components/ui/Skeleton/Skeleton.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Spinner/Spinner.d.ts +1 -1
- package/lib/typescript/src/components/ui/Spinner/Spinner.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Spinner/Spinner.web.d.ts +1 -1
- package/lib/typescript/src/components/ui/Spinner/Spinner.web.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Spinner/shared.d.ts +5 -0
- package/lib/typescript/src/components/ui/Spinner/shared.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Spinner/types.d.ts +1 -1
- package/lib/typescript/src/components/ui/Spinner/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Stepper/Stepper.d.ts +3 -3
- package/lib/typescript/src/components/ui/Stepper/Stepper.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Stepper/StepperPressable.d.ts +2 -0
- package/lib/typescript/src/components/ui/Stepper/StepperPressable.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/StepperPressable.web.d.ts +2 -0
- package/lib/typescript/src/components/ui/Stepper/StepperPressable.web.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.d.ts +3 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.types.d.ts +23 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.web.d.ts +9 -0
- package/lib/typescript/src/components/ui/Stepper/accessibility.web.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/layout.d.ts +22 -0
- package/lib/typescript/src/components/ui/Stepper/layout.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/normalizeStepper.d.ts +31 -0
- package/lib/typescript/src/components/ui/Stepper/normalizeStepper.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Stepper/styles.d.ts +9 -2
- package/lib/typescript/src/components/ui/Stepper/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Stepper/types.d.ts +3 -1
- package/lib/typescript/src/components/ui/Stepper/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Switch/Switch.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Switch/Switch.web.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Switch/styles.d.ts +9 -3
- package/lib/typescript/src/components/ui/Switch/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Switch/types.d.ts +2 -2
- package/lib/typescript/src/components/ui/Switch/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Tag/Tag.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/TextField/TextFieldBase.d.ts +4 -401
- package/lib/typescript/src/components/ui/TextField/TextFieldBase.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/TextField/TextFieldSlot.d.ts +13 -0
- package/lib/typescript/src/components/ui/TextField/TextFieldSlot.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextField/normalize.d.ts +51 -0
- package/lib/typescript/src/components/ui/TextField/normalize.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextField/styles.d.ts +30 -0
- package/lib/typescript/src/components/ui/TextField/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/TextField/types.d.ts +92 -18
- package/lib/typescript/src/components/ui/TextField/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/TextField/useErrorAnnouncement.d.ts +3 -0
- package/lib/typescript/src/components/ui/TextField/useErrorAnnouncement.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextField/useTextFieldValue.d.ts +18 -0
- package/lib/typescript/src/components/ui/TextField/useTextFieldValue.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextField/valueState.d.ts +50 -0
- package/lib/typescript/src/components/ui/TextField/valueState.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Textarea/Textarea.d.ts +4 -382
- package/lib/typescript/src/components/ui/Textarea/Textarea.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Textarea/index.d.ts +1 -0
- package/lib/typescript/src/components/ui/Textarea/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Textarea/types.d.ts +3 -14
- package/lib/typescript/src/components/ui/Textarea/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Thumbnail/Thumbnail.d.ts +5 -12
- package/lib/typescript/src/components/ui/Thumbnail/Thumbnail.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Thumbnail/index.d.ts +1 -1
- package/lib/typescript/src/components/ui/Thumbnail/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Thumbnail/normalize.d.ts +13 -0
- package/lib/typescript/src/components/ui/Thumbnail/normalize.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Thumbnail/styles.d.ts +4 -8
- package/lib/typescript/src/components/ui/Thumbnail/styles.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Thumbnail/types.d.ts +21 -13
- package/lib/typescript/src/components/ui/Thumbnail/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Toast/ToastHost.d.ts +6 -2
- package/lib/typescript/src/components/ui/Toast/ToastHost.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Toast/ToastHost.web.d.ts +6 -3
- package/lib/typescript/src/components/ui/Toast/ToastHost.web.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Toast/store.d.ts +39 -0
- package/lib/typescript/src/components/ui/Toast/store.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Toast/toast.d.ts +7 -2
- package/lib/typescript/src/components/ui/Toast/toast.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Toast/types.d.ts +5 -3
- package/lib/typescript/src/components/ui/Toast/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/index.d.ts +5 -5
- package/lib/typescript/src/components/ui/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts +13 -0
- package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/shared/a11y.d.ts +19 -0
- package/lib/typescript/src/components/ui/shared/a11y.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/shared/accessibilityName.d.ts +3 -0
- package/lib/typescript/src/components/ui/shared/accessibilityName.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.d.ts +3 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts +4 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.web.d.ts +3 -0
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.web.d.ts.map +1 -0
- package/lib/typescript/src/theme/ThemeProvider.d.ts +2 -3
- package/lib/typescript/src/theme/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theme/fontScale.d.ts +4 -0
- package/lib/typescript/src/theme/fontScale.d.ts.map +1 -0
- package/lib/typescript/src/theme/index.d.ts +2 -1
- package/lib/typescript/src/theme/index.d.ts.map +1 -1
- package/lib/typescript/src/theme/themeContext.d.ts +6 -0
- package/lib/typescript/src/theme/themeContext.d.ts.map +1 -0
- package/lib/typescript/src/theme/themeDiagnostics.d.ts +6 -0
- package/lib/typescript/src/theme/themeDiagnostics.d.ts.map +1 -0
- package/lib/typescript/src/theme/usePrefersReducedMotion.d.ts +8 -3
- package/lib/typescript/src/theme/usePrefersReducedMotion.d.ts.map +1 -1
- package/lib/typescript/src/theme/usePrefersReducedMotion.web.d.ts +5 -2
- package/lib/typescript/src/theme/usePrefersReducedMotion.web.d.ts.map +1 -1
- package/lib/typescript/src/theme/useTheme.d.ts +1 -1
- package/lib/typescript/src/theme/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/theme/useThemedStyles.d.ts +1 -1
- package/lib/typescript/src/theme/useThemedStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/imageSource.d.ts +20 -0
- package/lib/typescript/src/utils/imageSource.d.ts.map +1 -0
- package/lib/typescript/type-tests/public-api.d.ts +2 -0
- package/lib/typescript/type-tests/public-api.d.ts.map +1 -0
- package/lib/typescript/website/src/components/iconCatalogCategories.d.ts +11 -0
- package/lib/typescript/website/src/components/iconCatalogCategories.d.ts.map +1 -0
- package/package.json +31 -17
- package/src/components/business/AvatarWithRing/AvatarWithRing.tsx +11 -4
- package/src/components/business/AvatarWithRing/styles.ts +11 -9
- package/src/components/business/VersionPill/VersionPill.tsx +31 -25
- package/src/components/business/VersionPill/content.ts +47 -0
- package/src/components/business/VersionPill/index.ts +1 -1
- package/src/components/business/VersionPill/styles.ts +4 -0
- package/src/components/business/VersionPill/types.ts +7 -2
- package/src/components/business/index.ts +1 -1
- package/src/components/business/useSvgId.ts +29 -8
- package/src/components/ui/Avatar/Avatar.tsx +25 -34
- package/src/components/ui/Avatar/types.ts +6 -2
- package/src/components/ui/Button/Button.tsx +39 -20
- package/src/components/ui/Button/ButtonBase.tsx +21 -12
- package/src/components/ui/Button/types.ts +5 -3
- package/src/components/ui/Carousel/Carousel.tsx +125 -71
- package/src/components/ui/Carousel/behavior.ts +78 -0
- package/src/components/ui/Carousel/index.ts +1 -1
- package/src/components/ui/Carousel/styles.ts +8 -13
- package/src/components/ui/Carousel/types.ts +35 -17
- package/src/components/ui/Cell/Cell.tsx +85 -74
- package/src/components/ui/Cell/Leading.tsx +14 -14
- package/src/components/ui/Cell/content.ts +53 -0
- package/src/components/ui/Cell/index.ts +7 -1
- package/src/components/ui/Cell/types.ts +64 -30
- package/src/components/ui/Checkbox/Checkbox.tsx +35 -8
- package/src/components/ui/Checkbox/types.ts +15 -3
- package/src/components/ui/Confirm/ConfirmHost.tsx +51 -26
- package/src/components/ui/Confirm/confirm.ts +17 -34
- package/src/components/ui/Confirm/labels.ts +14 -0
- package/src/components/ui/Confirm/store.ts +147 -0
- package/src/components/ui/Confirm/styles.ts +4 -0
- package/src/components/ui/Confirm/types.ts +2 -10
- package/src/components/ui/DrawerHeader/DrawerHeader.tsx +22 -27
- package/src/components/ui/DrawerHeader/types.ts +7 -1
- package/src/components/ui/Grid/Grid.tsx +44 -12
- package/src/components/ui/Grid/accessibility.ts +21 -0
- package/src/components/ui/Grid/types.ts +2 -0
- package/src/components/ui/IconButton/IconButton.tsx +20 -3
- package/src/components/ui/IconButton/types.ts +4 -2
- package/src/components/ui/Input/Input.tsx +16 -6
- package/src/components/ui/Input/index.ts +5 -0
- package/src/components/ui/Input/types.ts +12 -23
- package/src/components/ui/Logo/Logo.tsx +27 -4
- package/src/components/ui/Logo/types.ts +2 -2
- package/src/components/ui/NavBar/NavBar.tsx +27 -19
- package/src/components/ui/NavBar/index.ts +1 -1
- package/src/components/ui/NavBar/isSlot.ts +372 -5
- package/src/components/ui/NavBar/types.ts +9 -8
- package/src/components/ui/PasswordInput/PasswordInput.tsx +67 -69
- package/src/components/ui/PasswordInput/types.ts +12 -14
- package/src/components/ui/Pulse/PulseDot.tsx +5 -4
- package/src/components/ui/Pulse/normalizePulseOptions.ts +76 -0
- package/src/components/ui/Pulse/usePulse.ts +80 -34
- package/src/components/ui/Pulse/usePulseDriver.ts +49 -0
- package/src/components/ui/Pulse/usePulseDriver.web.ts +66 -0
- package/src/components/ui/Radio/Radio.tsx +44 -15
- package/src/components/ui/Radio/RadioGroup.tsx +21 -3
- package/src/components/ui/Radio/types.ts +17 -3
- package/src/components/ui/Reveal/Reveal.tsx +5 -3
- package/src/components/ui/Reveal/Reveal.web.tsx +72 -29
- package/src/components/ui/Reveal/types.ts +1 -1
- package/src/components/ui/Reveal/webTransition.ts +206 -0
- package/src/components/ui/Search/Search.tsx +127 -58
- package/src/components/ui/Search/types.ts +30 -9
- package/src/components/ui/Segmented/Segmented.tsx +10 -2
- package/src/components/ui/Skeleton/Skeleton.tsx +9 -5
- package/src/components/ui/Spinner/Spinner.tsx +25 -17
- package/src/components/ui/Spinner/Spinner.web.tsx +23 -18
- package/src/components/ui/Spinner/shared.ts +7 -0
- package/src/components/ui/Spinner/types.ts +1 -1
- package/src/components/ui/Stepper/Stepper.tsx +166 -86
- package/src/components/ui/Stepper/StepperPressable.tsx +1 -0
- package/src/components/ui/Stepper/StepperPressable.web.tsx +1 -0
- package/src/components/ui/Stepper/accessibility.ts +32 -0
- package/src/components/ui/Stepper/accessibility.types.ts +22 -0
- package/src/components/ui/Stepper/accessibility.web.ts +65 -0
- package/src/components/ui/Stepper/layout.ts +44 -0
- package/src/components/ui/Stepper/normalizeStepper.ts +85 -0
- package/src/components/ui/Stepper/styles.ts +9 -2
- package/src/components/ui/Stepper/types.ts +3 -1
- package/src/components/ui/Switch/Switch.tsx +54 -15
- package/src/components/ui/Switch/Switch.web.tsx +57 -19
- package/src/components/ui/Switch/styles.ts +11 -4
- package/src/components/ui/Switch/types.ts +2 -2
- package/src/components/ui/Tag/Tag.tsx +6 -2
- package/src/components/ui/TextField/TextFieldBase.tsx +175 -70
- package/src/components/ui/TextField/TextFieldSlot.tsx +91 -0
- package/src/components/ui/TextField/normalize.ts +280 -0
- package/src/components/ui/TextField/styles.ts +31 -0
- package/src/components/ui/TextField/types.ts +118 -22
- package/src/components/ui/TextField/useErrorAnnouncement.ts +27 -0
- package/src/components/ui/TextField/useTextFieldValue.ts +94 -0
- package/src/components/ui/TextField/valueState.ts +125 -0
- package/src/components/ui/Textarea/Textarea.tsx +11 -4
- package/src/components/ui/Textarea/index.ts +5 -0
- package/src/components/ui/Textarea/types.ts +14 -22
- package/src/components/ui/Thumbnail/Thumbnail.tsx +86 -51
- package/src/components/ui/Thumbnail/index.ts +5 -1
- package/src/components/ui/Thumbnail/normalize.ts +78 -0
- package/src/components/ui/Thumbnail/styles.ts +5 -10
- package/src/components/ui/Thumbnail/types.ts +43 -13
- package/src/components/ui/Toast/ToastHost.tsx +81 -22
- package/src/components/ui/Toast/ToastHost.web.tsx +91 -29
- package/src/components/ui/Toast/store.ts +148 -0
- package/src/components/ui/Toast/toast.ts +19 -10
- package/src/components/ui/Toast/types.ts +7 -3
- package/src/components/ui/index.ts +20 -5
- package/src/components/ui/shared/ImageAttempt.tsx +30 -0
- package/src/components/ui/shared/a11y.ts +18 -0
- package/src/components/ui/shared/accessibilityName.ts +6 -0
- package/src/components/ui/shared/selectImageAttemptSource.shared.ts +17 -0
- package/src/components/ui/shared/selectImageAttemptSource.ts +3 -0
- package/src/components/ui/shared/selectImageAttemptSource.web.ts +3 -0
- package/src/icons/data.ts +1 -1
- package/src/theme/ThemeProvider.tsx +18 -7
- package/src/theme/fontScale.ts +15 -0
- package/src/theme/index.ts +2 -3
- package/src/theme/themeContext.ts +24 -0
- package/src/theme/themeDiagnostics.ts +41 -0
- package/src/theme/usePrefersReducedMotion.ts +11 -4
- package/src/theme/usePrefersReducedMotion.web.ts +5 -2
- package/src/theme/useTheme.ts +19 -27
- package/src/theme/useThemedStyles.ts +12 -7
- package/src/utils/imageSource.ts +303 -0
- package/lib/module/components/ui/PasswordInput/styles.js +0 -12
- package/lib/module/components/ui/PasswordInput/styles.js.map +0 -1
- package/lib/module/components/ui/Pulse/usePulse.web.js +0 -76
- package/lib/module/components/ui/Pulse/usePulse.web.js.map +0 -1
- package/lib/typescript/src/components/ui/PasswordInput/styles.d.ts +0 -7
- package/lib/typescript/src/components/ui/PasswordInput/styles.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/Pulse/usePulse.web.d.ts +0 -21
- package/lib/typescript/src/components/ui/Pulse/usePulse.web.d.ts.map +0 -1
- package/src/components/ui/PasswordInput/styles.ts +0 -7
- package/src/components/ui/Pulse/usePulse.web.ts +0 -74
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { fixed } from '../../../theme';
|
|
4
|
+
import { ICONS, type IconName } from '../../../icons';
|
|
5
|
+
import { normalizeNonBlankText } from '../shared/accessibilityName';
|
|
6
|
+
import type {
|
|
7
|
+
SearchFieldLayout,
|
|
8
|
+
TextFieldContainerStyle,
|
|
9
|
+
TextFieldSlot,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TextField 家族的**纯布局归一化** —— 无 React 依赖,可直接单测。
|
|
14
|
+
*
|
|
15
|
+
* 纪律与 Pulse 一致:非法值**整体回退默认值并记诊断**,不做 clamp、不做取整。
|
|
16
|
+
* 悄悄把 `height: 20` 夹成 44 会让调用方永远发现不了自己传了一个碰不到的输入框。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** slot 图标的默认与合法上界。18 是 body 字号下视觉平衡的取值;>32 会撑破 44pt frame。 */
|
|
20
|
+
const DEFAULT_SLOT_ICON_SIZE = 18;
|
|
21
|
+
const MAX_SLOT_ICON_SIZE = 32;
|
|
22
|
+
/** Textarea 默认最小高度(约 5 行)。 */
|
|
23
|
+
const DEFAULT_TEXTAREA_MIN_HEIGHT = 96;
|
|
24
|
+
const DEFAULT_SEARCH_VISIBLE_HEIGHT = 36;
|
|
25
|
+
|
|
26
|
+
/** 这六个字段会破坏 TextField 自持的最小命中框,一律从 containerStyle 剥离。 */
|
|
27
|
+
const RESERVED_CONTAINER_KEYS = [
|
|
28
|
+
'height',
|
|
29
|
+
'minHeight',
|
|
30
|
+
'maxHeight',
|
|
31
|
+
'minWidth',
|
|
32
|
+
'maxWidth',
|
|
33
|
+
'overflow',
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
const isFiniteAtLeast = (value: unknown, min: number): value is number =>
|
|
37
|
+
typeof value === 'number' && Number.isFinite(value) && value >= min;
|
|
38
|
+
|
|
39
|
+
const isFiniteWithin = (
|
|
40
|
+
value: unknown,
|
|
41
|
+
min: number,
|
|
42
|
+
max: number
|
|
43
|
+
): value is number =>
|
|
44
|
+
typeof value === 'number' &&
|
|
45
|
+
Number.isFinite(value) &&
|
|
46
|
+
value >= min &&
|
|
47
|
+
value <= max;
|
|
48
|
+
|
|
49
|
+
export type NormalizedNumber = {
|
|
50
|
+
value: number;
|
|
51
|
+
diagnostics: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** 单行高度 —— 不得低于 `fixed.hitTarget`(44pt),否则整行都碰不满一个手指。 */
|
|
55
|
+
export function normalizeInputHeight(value: unknown): NormalizedNumber {
|
|
56
|
+
return isFiniteAtLeast(value, fixed.hitTarget)
|
|
57
|
+
? { value, diagnostics: [] }
|
|
58
|
+
: { value: fixed.hitTarget, diagnostics: ['height'] };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type NormalizedTextareaHeights = {
|
|
62
|
+
minHeight: number;
|
|
63
|
+
maxHeight: number | undefined;
|
|
64
|
+
diagnostics: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** 多行高度 —— `maxHeight` 只有在有限且不小于归一化后的 `minHeight` 时才保留。 */
|
|
68
|
+
export function normalizeTextareaHeights(
|
|
69
|
+
minHeight: unknown,
|
|
70
|
+
maxHeight: unknown
|
|
71
|
+
): NormalizedTextareaHeights {
|
|
72
|
+
const diagnostics: string[] = [];
|
|
73
|
+
let safeMin: number;
|
|
74
|
+
if (minHeight === undefined) {
|
|
75
|
+
safeMin = DEFAULT_TEXTAREA_MIN_HEIGHT;
|
|
76
|
+
} else if (isFiniteAtLeast(minHeight, fixed.hitTarget)) {
|
|
77
|
+
safeMin = minHeight;
|
|
78
|
+
} else {
|
|
79
|
+
safeMin = DEFAULT_TEXTAREA_MIN_HEIGHT;
|
|
80
|
+
diagnostics.push('minHeight');
|
|
81
|
+
}
|
|
82
|
+
if (maxHeight === undefined) {
|
|
83
|
+
return { minHeight: safeMin, maxHeight: undefined, diagnostics };
|
|
84
|
+
}
|
|
85
|
+
// 注意用**归一化后**的 min 比较:min 被回退时 max 必须跟着重新判定,
|
|
86
|
+
// 否则会留下一个比实际 min 还小的 max,直接把内容压没。
|
|
87
|
+
if (isFiniteAtLeast(maxHeight, safeMin)) {
|
|
88
|
+
return { minHeight: safeMin, maxHeight, diagnostics };
|
|
89
|
+
}
|
|
90
|
+
diagnostics.push('maxHeight');
|
|
91
|
+
return { minHeight: safeMin, maxHeight: undefined, diagnostics };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** slot 图标尺寸 —— 只接受有限的 `[1, 32]`。 */
|
|
95
|
+
export function normalizeSlotIconSize(value: unknown): NormalizedNumber {
|
|
96
|
+
return isFiniteWithin(value, 1, MAX_SLOT_ICON_SIZE)
|
|
97
|
+
? { value, diagnostics: [] }
|
|
98
|
+
: { value: DEFAULT_SLOT_ICON_SIZE, diagnostics: ['slot.size'] };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type NormalizedTextFieldSlot = {
|
|
102
|
+
slot: TextFieldSlot | undefined;
|
|
103
|
+
diagnostics: readonly string[];
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
function isIconName(value: unknown): value is IconName {
|
|
107
|
+
return (
|
|
108
|
+
typeof value === 'string' &&
|
|
109
|
+
Object.prototype.hasOwnProperty.call(ICONS, value)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 未类型化 JS 必须完整匹配一个受支持分支,不能靠 discriminant 后 cast 绕过校验。 */
|
|
114
|
+
export function normalizeTextFieldSlot(slot: unknown): NormalizedTextFieldSlot {
|
|
115
|
+
if (slot === undefined) {
|
|
116
|
+
return { slot: undefined, diagnostics: [] };
|
|
117
|
+
}
|
|
118
|
+
if (typeof slot !== 'object' || slot === null) {
|
|
119
|
+
return { slot: undefined, diagnostics: ['slot'] };
|
|
120
|
+
}
|
|
121
|
+
const candidate = slot as Record<string, unknown>;
|
|
122
|
+
switch (candidate.kind) {
|
|
123
|
+
case 'icon': {
|
|
124
|
+
const size =
|
|
125
|
+
typeof candidate.size === 'number' && Number.isFinite(candidate.size)
|
|
126
|
+
? candidate.size
|
|
127
|
+
: undefined;
|
|
128
|
+
const color =
|
|
129
|
+
typeof candidate.color === 'string' ? candidate.color : undefined;
|
|
130
|
+
const hasValidSize = candidate.size === undefined || size !== undefined;
|
|
131
|
+
const hasValidColor =
|
|
132
|
+
candidate.color === undefined || color !== undefined;
|
|
133
|
+
if (!isIconName(candidate.icon) || !hasValidSize || !hasValidColor) {
|
|
134
|
+
return { slot: undefined, diagnostics: ['slot.icon'] };
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
slot: {
|
|
138
|
+
kind: 'icon',
|
|
139
|
+
icon: candidate.icon,
|
|
140
|
+
...(size !== undefined && { size }),
|
|
141
|
+
...(color !== undefined && { color }),
|
|
142
|
+
},
|
|
143
|
+
diagnostics: [],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
case 'text':
|
|
147
|
+
if (
|
|
148
|
+
typeof candidate.value !== 'string' &&
|
|
149
|
+
typeof candidate.value !== 'number'
|
|
150
|
+
) {
|
|
151
|
+
return { slot: undefined, diagnostics: ['slot.text'] };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
slot: { kind: 'text', value: candidate.value },
|
|
155
|
+
diagnostics: [],
|
|
156
|
+
};
|
|
157
|
+
case 'action': {
|
|
158
|
+
const accessibilityLabel = normalizeNonBlankText(
|
|
159
|
+
candidate.accessibilityLabel
|
|
160
|
+
);
|
|
161
|
+
const hasValidDisabled =
|
|
162
|
+
candidate.disabled === undefined ||
|
|
163
|
+
typeof candidate.disabled === 'boolean';
|
|
164
|
+
const slotDisabled =
|
|
165
|
+
typeof candidate.disabled === 'boolean'
|
|
166
|
+
? candidate.disabled
|
|
167
|
+
: undefined;
|
|
168
|
+
if (
|
|
169
|
+
!isIconName(candidate.icon) ||
|
|
170
|
+
typeof candidate.onPress !== 'function' ||
|
|
171
|
+
accessibilityLabel === undefined ||
|
|
172
|
+
!hasValidDisabled
|
|
173
|
+
) {
|
|
174
|
+
return { slot: undefined, diagnostics: ['slot.action'] };
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
slot: {
|
|
178
|
+
kind: 'action',
|
|
179
|
+
icon: candidate.icon,
|
|
180
|
+
onPress: candidate.onPress as () => void,
|
|
181
|
+
accessibilityLabel,
|
|
182
|
+
...(slotDisabled !== undefined && { disabled: slotDisabled }),
|
|
183
|
+
},
|
|
184
|
+
diagnostics: [],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
return { slot: undefined, diagnostics: ['slot.kind'] };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type NormalizedSearchLayout = SearchFieldLayout & {
|
|
193
|
+
diagnostics: readonly string[];
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/** 搜索框的可见面可为 36pt,但承载输入/操作的实际行永远不得小于 44pt。 */
|
|
197
|
+
export function normalizeSearchLayout(
|
|
198
|
+
interactiveHeight: unknown,
|
|
199
|
+
visibleHeight: unknown
|
|
200
|
+
): NormalizedSearchLayout {
|
|
201
|
+
const diagnostics: string[] = [];
|
|
202
|
+
const safeInteractive = isFiniteAtLeast(interactiveHeight, fixed.hitTarget)
|
|
203
|
+
? interactiveHeight
|
|
204
|
+
: fixed.hitTarget;
|
|
205
|
+
if (safeInteractive !== interactiveHeight) {
|
|
206
|
+
diagnostics.push('interactiveHeight');
|
|
207
|
+
}
|
|
208
|
+
const safeVisible =
|
|
209
|
+
typeof visibleHeight === 'number' &&
|
|
210
|
+
Number.isFinite(visibleHeight) &&
|
|
211
|
+
visibleHeight > 0 &&
|
|
212
|
+
visibleHeight <= safeInteractive
|
|
213
|
+
? visibleHeight
|
|
214
|
+
: DEFAULT_SEARCH_VISIBLE_HEIGHT;
|
|
215
|
+
if (safeVisible !== visibleHeight) {
|
|
216
|
+
diagnostics.push('visibleHeight');
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
interactiveHeight: safeInteractive,
|
|
220
|
+
visibleHeight: safeVisible,
|
|
221
|
+
verticalInset: (safeInteractive - safeVisible) / 2,
|
|
222
|
+
diagnostics,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type SanitizedContainerStyle = {
|
|
227
|
+
style: TextFieldContainerStyle;
|
|
228
|
+
diagnostics: readonly string[];
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export type SanitizedTextFieldWrapperProps = {
|
|
232
|
+
props: Record<string, unknown>;
|
|
233
|
+
diagnostics: readonly string[];
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 公开 Input / Textarea 不允许未类型化 JS 覆盖内部 layout 开关。
|
|
238
|
+
*
|
|
239
|
+
* 返回新对象而不是 delete 原 props,既不改变调用方对象,也让 wrapper 能在安全 spread
|
|
240
|
+
* 后由可信边界写入自己的 `multiline`。
|
|
241
|
+
*/
|
|
242
|
+
export function sanitizeTextFieldWrapperProps(
|
|
243
|
+
props: Record<string, unknown>
|
|
244
|
+
): SanitizedTextFieldWrapperProps {
|
|
245
|
+
const { multiline, searchLayout, ...safeProps } = props;
|
|
246
|
+
const diagnostics: string[] = [];
|
|
247
|
+
if (multiline !== undefined) {
|
|
248
|
+
diagnostics.push('multiline');
|
|
249
|
+
}
|
|
250
|
+
if (searchLayout !== undefined) {
|
|
251
|
+
diagnostics.push('searchLayout');
|
|
252
|
+
}
|
|
253
|
+
return { props: safeProps, diagnostics };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 剥掉 containerStyle 里会覆盖最小 frame 的六个字段。
|
|
258
|
+
*
|
|
259
|
+
* 先 `StyleSheet.flatten` 再解构到新对象 —— 绝不原地修改调用方对象或已注册的
|
|
260
|
+
* StyleSheet 条目(那会污染同一 sheet 的其他使用者)。
|
|
261
|
+
*/
|
|
262
|
+
export function sanitizeTextFieldContainerStyle(
|
|
263
|
+
style: StyleProp<ViewStyle> | undefined
|
|
264
|
+
): SanitizedContainerStyle {
|
|
265
|
+
const flattened = (StyleSheet.flatten(style) ?? {}) as Record<
|
|
266
|
+
string,
|
|
267
|
+
unknown
|
|
268
|
+
>;
|
|
269
|
+
const reserved: readonly string[] = RESERVED_CONTAINER_KEYS;
|
|
270
|
+
const sanitized: Record<string, unknown> = {};
|
|
271
|
+
const diagnostics: string[] = [];
|
|
272
|
+
for (const [key, entry] of Object.entries(flattened)) {
|
|
273
|
+
if (reserved.includes(key)) {
|
|
274
|
+
diagnostics.push(key);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
sanitized[key] = entry;
|
|
278
|
+
}
|
|
279
|
+
return { style: sanitized as TextFieldContainerStyle, diagnostics };
|
|
280
|
+
}
|
|
@@ -17,6 +17,17 @@ export const makeStyles = (c: ColorTokens) =>
|
|
|
17
17
|
paddingVertical: space[4],
|
|
18
18
|
alignItems: 'flex-start',
|
|
19
19
|
},
|
|
20
|
+
/** Search 的可见底色/边框绝不承载命中区域。 */
|
|
21
|
+
searchInteractiveRow: {
|
|
22
|
+
borderWidth: 0,
|
|
23
|
+
},
|
|
24
|
+
searchVisibleSurface: {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
left: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
borderRadius: radius.md,
|
|
29
|
+
borderWidth: 1,
|
|
30
|
+
},
|
|
20
31
|
wrapIdle: {
|
|
21
32
|
backgroundColor: c.surfaceContainerHigh,
|
|
22
33
|
borderColor: 'transparent',
|
|
@@ -48,6 +59,23 @@ export const makeStyles = (c: ColorTokens) =>
|
|
|
48
59
|
inputMultiline: {
|
|
49
60
|
textAlignVertical: 'top' as const,
|
|
50
61
|
},
|
|
62
|
+
slotDisplay: {
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
justifyContent: 'center',
|
|
65
|
+
minWidth: 18,
|
|
66
|
+
minHeight: 18,
|
|
67
|
+
},
|
|
68
|
+
slotText: {
|
|
69
|
+
color: c.foregroundMuted,
|
|
70
|
+
fontSize: t.sm,
|
|
71
|
+
},
|
|
72
|
+
// 固定命中框不走 r()/fontScale:它是手指可达性约束,不是视觉 token。
|
|
73
|
+
actionFrame: {
|
|
74
|
+
width: 44,
|
|
75
|
+
height: 44,
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
justifyContent: 'center',
|
|
78
|
+
},
|
|
51
79
|
errorMsg: {
|
|
52
80
|
fontSize: t.micro,
|
|
53
81
|
color: c.error,
|
|
@@ -58,4 +86,7 @@ export const makeStyles = (c: ColorTokens) =>
|
|
|
58
86
|
containerDisabled: {
|
|
59
87
|
opacity: 0.5,
|
|
60
88
|
},
|
|
89
|
+
rootCentered: {
|
|
90
|
+
justifyContent: 'center',
|
|
91
|
+
},
|
|
61
92
|
});
|
|
@@ -1,27 +1,123 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
1
|
import type { StyleProp, TextInputProps, ViewStyle } from 'react-native';
|
|
2
|
+
import type { IconName } from '../Icon';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
/**
|
|
5
|
+
* 受控:必须同时给 `value` 和 `onChangeText`。
|
|
6
|
+
*
|
|
7
|
+
* `defaultValue?: never` 让「同时传 value 和 defaultValue」在类型层就报错 ——
|
|
8
|
+
* 那是最常见的受控/非受控混用写法,运行时表现为「defaultValue 被静默忽略」。
|
|
9
|
+
*/
|
|
10
|
+
export type ControlledTextValueProps = {
|
|
11
|
+
value: string;
|
|
12
|
+
onChangeText: (value: string) => void;
|
|
13
|
+
defaultValue?: never;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** 非受控:内部持值,`defaultValue` 只在首次 render 读一次。 */
|
|
17
|
+
export type UncontrolledTextValueProps = {
|
|
18
|
+
value?: never;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
onChangeText?: (value: string) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** internal —— 由 InputProps / TextareaProps / SearchProps 组合进公共类型。 */
|
|
24
|
+
export type TextFieldValueProps =
|
|
25
|
+
| ControlledTextValueProps
|
|
26
|
+
| UncontrolledTextValueProps;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 输入类组件对外暴露的 ref。**只有** focus / blur。
|
|
30
|
+
*
|
|
31
|
+
* 为什么不暴露原生 TextInput —— `clear()` 会绕过值状态机(受控下把 UI 清空但调用方
|
|
32
|
+
* state 不变),`setNativeProps()` 能直接改任意原生属性,两者都会让公共契约失效。
|
|
33
|
+
*/
|
|
34
|
+
export type TextFieldHandle = {
|
|
35
|
+
focus: () => void;
|
|
36
|
+
blur: () => void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 左右 slot 的可验证配置。**不接受任意 ReactNode** ——
|
|
41
|
+
* 任意节点意味着库无法判断它是装饰还是操作,也无法保证它有可访问名称与 44pt 命中框。
|
|
42
|
+
*/
|
|
43
|
+
export type TextFieldSlot =
|
|
44
|
+
| { kind: 'icon'; icon: IconName; size?: number; color?: string }
|
|
45
|
+
| { kind: 'text'; value: string | number }
|
|
46
|
+
| {
|
|
47
|
+
kind: 'action';
|
|
48
|
+
icon: IconName;
|
|
49
|
+
onPress: () => void;
|
|
50
|
+
accessibilityLabel: string;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* containerStyle 的可用字段。六个尺寸/裁剪字段被排除 ——
|
|
56
|
+
* 它们会覆盖 TextField 自持的最小命中框,让输入框缩到碰不到。
|
|
57
|
+
*/
|
|
58
|
+
export type TextFieldContainerStyle = Omit<
|
|
59
|
+
ViewStyle,
|
|
60
|
+
'height' | 'minHeight' | 'maxHeight' | 'minWidth' | 'maxWidth' | 'overflow'
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
/** internal:Search 把真实交互行与仅作视觉的 surface 明确分层。 */
|
|
64
|
+
export type SearchFieldLayout = {
|
|
65
|
+
interactiveHeight: number;
|
|
66
|
+
visibleHeight: number;
|
|
67
|
+
verticalInset: number;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** TextField 家族共享的非值 props(内部)。 */
|
|
71
|
+
export type TextFieldCommonProps = {
|
|
72
|
+
/** 左侧 slot —— 图标 / 文本 / 带 handler 与名称的操作 */
|
|
73
|
+
leading?: TextFieldSlot;
|
|
74
|
+
/** 右侧 slot —— 图标 / 文本 / 带 handler 与名称的操作 */
|
|
75
|
+
trailing?: TextFieldSlot;
|
|
76
|
+
/** 错误文案 —— 非空字符串时进入 error 态并在下方显示 */
|
|
22
77
|
error?: string;
|
|
23
|
-
/** 整体禁用 —— opacity 0.5 +
|
|
78
|
+
/** 整体禁用 —— opacity 0.5 + 不可编辑,优先级高于原生 `editable` */
|
|
24
79
|
disabled?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
containerStyle?: StyleProp<
|
|
80
|
+
/** 外层容器样式;不接受会破坏最小 frame 的尺寸字段 */
|
|
81
|
+
containerStyle?: StyleProp<TextFieldContainerStyle>;
|
|
27
82
|
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 这些原生 TextInput props 从公共类型删除:
|
|
86
|
+
* - `style` / `multiline` / `numberOfLines`:由组件自己决定,单行多行分属 Input / Textarea
|
|
87
|
+
* - `value` / `defaultValue` / `onChangeText`:改由严格判别联合提供
|
|
88
|
+
* - `aria-disabled` / `readOnly` / `role`:与 `disabled` / `editable` / `accessibilityRole` 重复,
|
|
89
|
+
* 两条入口同时存在时优先级不可预测
|
|
90
|
+
* - `enterKeyHint`:与 `returnKeyType` 重复
|
|
91
|
+
* - `clearTextOnFocus`:绕过值状态机静默清值
|
|
92
|
+
*/
|
|
93
|
+
export type RemovedTextInputProps =
|
|
94
|
+
| 'style'
|
|
95
|
+
| 'multiline'
|
|
96
|
+
| 'numberOfLines'
|
|
97
|
+
| 'value'
|
|
98
|
+
| 'defaultValue'
|
|
99
|
+
| 'onChangeText'
|
|
100
|
+
| 'aria-disabled'
|
|
101
|
+
| 'readOnly'
|
|
102
|
+
| 'role'
|
|
103
|
+
| 'enterKeyHint'
|
|
104
|
+
| 'clearTextOnFocus';
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* internal — TextFieldBase 的严格形状。公开组件在此基础上固定单/多行布局,
|
|
108
|
+
* 因此不能由未类型化的 native prop 反向覆盖 value、slot 或命中框规则。
|
|
109
|
+
*/
|
|
110
|
+
export type TextFieldBaseProps = Omit<TextInputProps, RemovedTextInputProps> &
|
|
111
|
+
TextFieldCommonProps &
|
|
112
|
+
TextFieldValueProps & {
|
|
113
|
+
/** internal:由 Input / Textarea / Search 固定,不作为公共可选入口。 */
|
|
114
|
+
multiline: boolean;
|
|
115
|
+
/** 单行 height(multiline=false 时生效),默认 control.lg */
|
|
116
|
+
height?: number;
|
|
117
|
+
/** 最小高度(multiline=true 时生效),默认 96 */
|
|
118
|
+
minHeight?: number;
|
|
119
|
+
/** 最大高度(multiline=true 时生效);超出 ScrollView 内滚 */
|
|
120
|
+
maxHeight?: number;
|
|
121
|
+
/** internal:Search 的 44pt interactive row + 36pt decorative surface。 */
|
|
122
|
+
searchLayout?: SearchFieldLayout;
|
|
123
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { AccessibilityInfo, Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** iOS 不会像 Android live region 一样自动播报动态错误,仅播报真实的后续变更。 */
|
|
5
|
+
export function useErrorAnnouncement(error: string | undefined): void {
|
|
6
|
+
const previousError = useRef('');
|
|
7
|
+
const didCommit = useRef(false);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const nextError = error ?? '';
|
|
11
|
+
const previous = previousError.current;
|
|
12
|
+
previousError.current = nextError;
|
|
13
|
+
|
|
14
|
+
if (!didCommit.current) {
|
|
15
|
+
didCommit.current = true;
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (Platform.OS !== 'ios' || nextError === '' || nextError === previous) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const timer = setTimeout(() => {
|
|
23
|
+
AccessibilityInfo.announceForAccessibility(nextError);
|
|
24
|
+
}, 0);
|
|
25
|
+
return () => clearTimeout(timer);
|
|
26
|
+
}, [error]);
|
|
27
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { createLogger } from '../../../utils/logger';
|
|
3
|
+
import {
|
|
4
|
+
applyTextChange,
|
|
5
|
+
createValueState,
|
|
6
|
+
reconcileValueState,
|
|
7
|
+
resolveCanUpdate,
|
|
8
|
+
} from './valueState';
|
|
9
|
+
import type {
|
|
10
|
+
TextFieldValueController,
|
|
11
|
+
ValueDiagnostic,
|
|
12
|
+
ValueState,
|
|
13
|
+
} from './valueState';
|
|
14
|
+
|
|
15
|
+
const log = createLogger('TextField');
|
|
16
|
+
|
|
17
|
+
const DIAGNOSTIC_MESSAGE: Record<ValueDiagnostic, string> = {
|
|
18
|
+
'controlled-to-uncontrolled':
|
|
19
|
+
'受控输入的 value 变成了 undefined。mode 已在首次 render 锁定为受控,本次沿用上一个合法值 —— 请始终传字符串(清空用 "")。',
|
|
20
|
+
'uncontrolled-to-controlled':
|
|
21
|
+
'非受控输入后来收到了 value。mode 已在首次 render 锁定为非受控,该 value 被忽略 —— 请从一开始就同时传 value 与 onChangeText。',
|
|
22
|
+
'invalid-controlled-value':
|
|
23
|
+
'受控输入的 value 必须是字符串。已保持最后一个合法值,不会切换到非受控 mode。',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type UseTextFieldValueInput = {
|
|
27
|
+
value?: unknown;
|
|
28
|
+
defaultValue?: unknown;
|
|
29
|
+
onChangeText?: ((value: string) => void) | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 把纯值状态机接到 React 上。
|
|
34
|
+
*
|
|
35
|
+
* state 放在 ref 而不是 useState:mode 与受控值必须在**本次 render 内**就正确,
|
|
36
|
+
* 不能等下一次提交 —— 否则受控组件会先渲染一帧旧值。非受控写入用一个递增 tick
|
|
37
|
+
* 触发重渲染,值本身仍以 ref 为准。
|
|
38
|
+
*
|
|
39
|
+
* 诊断只在 effect 里打:render 期打日志在 StrictMode 双调用下会重复,
|
|
40
|
+
* 且违反 render 必须纯净的约束。
|
|
41
|
+
*/
|
|
42
|
+
export function useTextFieldValue(
|
|
43
|
+
{ value, defaultValue, onChangeText }: UseTextFieldValueInput,
|
|
44
|
+
scope: string
|
|
45
|
+
): TextFieldValueController {
|
|
46
|
+
const stateRef = useRef<ValueState | null>(null);
|
|
47
|
+
if (stateRef.current === null) {
|
|
48
|
+
stateRef.current = createValueState(value, defaultValue);
|
|
49
|
+
}
|
|
50
|
+
const [, bumpTick] = useState(0);
|
|
51
|
+
|
|
52
|
+
const transition = reconcileValueState(stateRef.current, value);
|
|
53
|
+
stateRef.current = transition.state;
|
|
54
|
+
const mode = transition.state.mode;
|
|
55
|
+
const canUpdate = resolveCanUpdate(mode, onChangeText);
|
|
56
|
+
|
|
57
|
+
const diagnostic = transition.diagnostic;
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (diagnostic) log.warn(`${scope}: ${DIAGNOSTIC_MESSAGE[diagnostic]}`);
|
|
60
|
+
}, [diagnostic, scope]);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!canUpdate) {
|
|
64
|
+
log.warn(
|
|
65
|
+
`${scope}: 受控输入缺少 onChangeText,输入将无法生效。请补上回调,或改用非受控(不传 value)。`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}, [canUpdate, scope]);
|
|
69
|
+
|
|
70
|
+
const handleChangeText = useCallback(
|
|
71
|
+
(next: string) => {
|
|
72
|
+
const current = stateRef.current;
|
|
73
|
+
if (!current) return;
|
|
74
|
+
if (current.mode === 'uncontrolled') {
|
|
75
|
+
stateRef.current = applyTextChange(current, next);
|
|
76
|
+
bumpTick((tick) => tick + 1);
|
|
77
|
+
onChangeText?.(next);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// 受控:内部永不写值,只把输入交给调用方。没有回调时直接 no-op ——
|
|
81
|
+
// 若照旧透传给原生,UI 会显示一个 state 里并不存在的值。
|
|
82
|
+
if (!canUpdate) return;
|
|
83
|
+
onChangeText?.(next);
|
|
84
|
+
},
|
|
85
|
+
[canUpdate, onChangeText]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
mode,
|
|
90
|
+
value: transition.value,
|
|
91
|
+
canUpdate,
|
|
92
|
+
onChangeText: handleChangeText,
|
|
93
|
+
};
|
|
94
|
+
}
|