@webority/mobile-ui 0.148.0 → 0.150.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/dist/canvas-kit/kit.js +13 -56553
- package/dist/canvas-kit/manifest.json +20 -41
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/Accordion/Accordion.js +1 -1
- package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
- package/lib/commonjs/components/AppIcon/glyphs.g.js +1 -1
- package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/commonjs/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/commonjs/components/Avatar/Avatar.js +1 -1
- package/lib/commonjs/components/Badge/Badge.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Box/Box.js +1 -1
- package/lib/commonjs/components/Card/Card.js +1 -1
- package/lib/commonjs/components/Carousel/Carousel.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
- package/lib/commonjs/components/Dialog/Dialog.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/FieldBase/useFloatingLabel.js +1 -1
- package/lib/commonjs/components/FileViewer/fileSource.js +1 -1
- package/lib/commonjs/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/ListItem/ListItem.js +1 -1
- package/lib/commonjs/components/Markdown/Markdown.js +1 -1
- package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
- package/lib/commonjs/components/Menu/focusHost.js +1 -1
- package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/OptionSheet/optionAccessors.js +1 -0
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/commonjs/components/Radio/RadioGroup.js +1 -1
- package/lib/commonjs/components/Rating/Rating.js +1 -1
- package/lib/commonjs/components/Repeater/Repeater.js +1 -1
- package/lib/commonjs/components/Screen/Screen.js +1 -1
- package/lib/commonjs/components/SearchBar/useRecentSearches.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/Select/Select.js +1 -1
- package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonList.js +1 -1
- package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/commonjs/components/Slider/Slider.js +1 -1
- package/lib/commonjs/components/SliderField/SliderField.js +1 -1
- package/lib/commonjs/components/SortableList/SortableList.js +1 -1
- package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
- package/lib/commonjs/components/SquircleFill/SquircleFill.js +1 -1
- package/lib/commonjs/components/StatTile/StatTile.js +1 -1
- package/lib/commonjs/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/commonjs/components/StatusBadge/statusMap.js +1 -1
- package/lib/commonjs/components/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
- package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/commonjs/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/commonjs/form/HookFormField.js +1 -1
- package/lib/commonjs/form/path.js +1 -1
- package/lib/commonjs/hooks/useControllableState.js +1 -1
- package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
- package/lib/commonjs/navigation/NavigationScreen.js +1 -1
- package/lib/commonjs/specs/NativePdfRasterizer.js +1 -1
- package/lib/commonjs/theme/ThemeContext.js +1 -1
- package/lib/commonjs/theme/animatedValue.js +1 -1
- package/lib/commonjs/theme/componentSizes.js +1 -1
- package/lib/commonjs/theme/merge.js +1 -1
- package/lib/commonjs/theme/scale.js +1 -1
- package/lib/commonjs/utils/complete.js +1 -0
- package/lib/commonjs/utils/guards.js +1 -0
- package/lib/commonjs/utils/hapticUtils.js +1 -1
- package/lib/module/components/Accordion/Accordion.js +1 -1
- package/lib/module/components/AppIcon/AppIcon.js +1 -1
- package/lib/module/components/AppIcon/glyphs.g.js +1 -1
- package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/module/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/module/components/Avatar/Avatar.js +1 -1
- package/lib/module/components/Badge/Badge.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Box/Box.js +1 -1
- package/lib/module/components/Card/Card.js +1 -1
- package/lib/module/components/Carousel/Carousel.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/module/components/Descriptions/Descriptions.js +1 -1
- package/lib/module/components/Dialog/Dialog.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/FieldBase/useFloatingLabel.js +1 -1
- package/lib/module/components/FileViewer/fileSource.js +1 -1
- package/lib/module/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/ListItem/ListItem.js +1 -1
- package/lib/module/components/Markdown/Markdown.js +1 -1
- package/lib/module/components/Menu/MenuSurface.js +1 -1
- package/lib/module/components/Menu/focusHost.js +1 -1
- package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/OptionSheet/optionAccessors.js +1 -0
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/module/components/Radio/RadioGroup.js +1 -1
- package/lib/module/components/Rating/Rating.js +1 -1
- package/lib/module/components/Repeater/Repeater.js +1 -1
- package/lib/module/components/Screen/Screen.js +1 -1
- package/lib/module/components/SearchBar/useRecentSearches.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/Select/Select.js +1 -1
- package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/module/components/Skeleton/SkeletonList.js +1 -1
- package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/module/components/Slider/Slider.js +1 -1
- package/lib/module/components/SliderField/SliderField.js +1 -1
- package/lib/module/components/SortableList/SortableList.js +1 -1
- package/lib/module/components/Sparkline/Sparkline.js +1 -1
- package/lib/module/components/SquircleFill/SquircleFill.js +1 -1
- package/lib/module/components/StatTile/StatTile.js +1 -1
- package/lib/module/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/module/components/StatusBadge/statusMap.js +1 -1
- package/lib/module/components/Stepper/Stepper.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/TimePicker/TimePicker.js +1 -1
- package/lib/module/components/WheelPicker/Wheel.js +1 -1
- package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/module/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/module/form/HookFormField.js +1 -1
- package/lib/module/form/path.js +1 -1
- package/lib/module/hooks/useControllableState.js +1 -1
- package/lib/module/hooks/useDragToDismiss.js +1 -1
- package/lib/module/navigation/NavigationScreen.js +1 -1
- package/lib/module/specs/NativePdfRasterizer.js +1 -1
- package/lib/module/theme/ThemeContext.js +1 -1
- package/lib/module/theme/animatedValue.js +1 -1
- package/lib/module/theme/componentSizes.js +1 -1
- package/lib/module/theme/merge.js +1 -1
- package/lib/module/theme/scale.js +1 -1
- package/lib/module/utils/complete.js +1 -0
- package/lib/module/utils/guards.js +1 -0
- package/lib/module/utils/hapticUtils.js +1 -1
- package/lib/typescript/commonjs/canvasKit/index.d.ts +12 -12
- package/lib/typescript/commonjs/canvasKit/meta.d.ts +5 -7
- package/lib/typescript/commonjs/components/Accordion/Accordion.d.ts +22 -22
- package/lib/typescript/commonjs/components/AmountSlider/AmountSlider.d.ts +23 -23
- package/lib/typescript/commonjs/components/AnimatePresence/AnimatePresence.d.ts +5 -5
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +39 -39
- package/lib/typescript/commonjs/components/AppIcon/AppIcon.d.ts +7 -7
- package/lib/typescript/commonjs/components/AppIcon/defaultIcons.d.ts +2 -1
- package/lib/typescript/commonjs/components/AppIcon/glyphs.g.d.ts +233 -233
- package/lib/typescript/commonjs/components/AppIcon/slotIcon.d.ts +1 -1
- package/lib/typescript/commonjs/components/AppLockOverlay/AppLockOverlay.d.ts +5 -5
- package/lib/typescript/commonjs/components/AsyncBlock/AsyncBlock.d.ts +22 -40
- package/lib/typescript/commonjs/components/AuthedImage/AuthedImage.d.ts +15 -15
- package/lib/typescript/commonjs/components/AuthedImage/authedImageCache.d.ts +2 -2
- package/lib/typescript/commonjs/components/Autocomplete/Autocomplete.d.ts +24 -24
- package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +36 -36
- package/lib/typescript/commonjs/components/Badge/Badge.d.ts +18 -18
- package/lib/typescript/commonjs/components/Banner/Banner.d.ts +25 -25
- package/lib/typescript/commonjs/components/BarChart/BarChart.d.ts +21 -21
- package/lib/typescript/commonjs/components/BottomNavigation/BottomNavigation.d.ts +36 -36
- package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +33 -33
- package/lib/typescript/commonjs/components/Box/Box.d.ts +27 -27
- package/lib/typescript/commonjs/components/Button/Button.d.ts +22 -22
- package/lib/typescript/commonjs/components/Calendar/Calendar.d.ts +20 -20
- package/lib/typescript/commonjs/components/Calendar/CalendarDay.d.ts +4 -2
- package/lib/typescript/commonjs/components/Card/Card.d.ts +41 -41
- package/lib/typescript/commonjs/components/Carousel/Carousel.d.ts +21 -21
- package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +21 -21
- package/lib/typescript/commonjs/components/Chip/Chip.d.ts +23 -23
- package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +51 -46
- package/lib/typescript/commonjs/components/Composer/Composer.d.ts +27 -27
- package/lib/typescript/commonjs/components/Confetti/Confetti.d.ts +22 -21
- package/lib/typescript/commonjs/components/Confirm/confirm.d.ts +4 -4
- package/lib/typescript/commonjs/components/DatePicker/DatePicker.d.ts +20 -20
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +22 -22
- package/lib/typescript/commonjs/components/DateSeparator/DateSeparator.d.ts +9 -9
- package/lib/typescript/commonjs/components/DecimalInput/DecimalInput.d.ts +14 -14
- package/lib/typescript/commonjs/components/Descriptions/Descriptions.d.ts +13 -13
- package/lib/typescript/commonjs/components/Dialog/Dialog.d.ts +24 -24
- package/lib/typescript/commonjs/components/Dialog/OverlayActions.d.ts +5 -5
- package/lib/typescript/commonjs/components/Divider/Divider.d.ts +9 -9
- package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +15 -15
- package/lib/typescript/commonjs/components/EmptyState/EmptyState.d.ts +13 -13
- package/lib/typescript/commonjs/components/ErrorBoundary/ErrorBoundary.d.ts +8 -8
- package/lib/typescript/commonjs/components/FieldBase/Chevron.d.ts +2 -2
- package/lib/typescript/commonjs/components/FieldBase/ChoiceText.d.ts +10 -10
- package/lib/typescript/commonjs/components/FieldBase/FieldBase.d.ts +54 -54
- package/lib/typescript/commonjs/components/FieldBase/useFloatingLabel.d.ts +8 -8
- package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +35 -35
- package/lib/typescript/commonjs/components/FileViewer/FileViewer.d.ts +10 -10
- package/lib/typescript/commonjs/components/FileViewer/fileSource.d.ts +3 -3
- package/lib/typescript/commonjs/components/FileViewer/useFileViewerZoom.d.ts +3 -3
- package/lib/typescript/commonjs/components/FilterChipRow/FilterChipRow.d.ts +12 -12
- package/lib/typescript/commonjs/components/FloatingActionButton/FloatingActionButton.d.ts +35 -35
- package/lib/typescript/commonjs/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +11 -11
- package/lib/typescript/commonjs/components/FormField/FormField.d.ts +15 -15
- package/lib/typescript/commonjs/components/IconBadge/IconBadge.d.ts +11 -11
- package/lib/typescript/commonjs/components/IconButton/IconButton.d.ts +14 -14
- package/lib/typescript/commonjs/components/ImageGallery/ImageGallery.d.ts +14 -14
- package/lib/typescript/commonjs/components/InlineSelect/InlineSelect.d.ts +36 -31
- package/lib/typescript/commonjs/components/Input/Input.d.ts +47 -47
- package/lib/typescript/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +7 -7
- package/lib/typescript/commonjs/components/KeyboardToolbar/KeyboardToolbar.d.ts +8 -8
- package/lib/typescript/commonjs/components/ListItem/ListItem.d.ts +44 -44
- package/lib/typescript/commonjs/components/ListSection/ListSection.d.ts +6 -6
- package/lib/typescript/commonjs/components/LoaderOverlay/LoaderOverlay.d.ts +17 -11
- package/lib/typescript/commonjs/components/Markdown/Markdown.d.ts +15 -15
- package/lib/typescript/commonjs/components/Menu/Menu.d.ts +17 -12
- package/lib/typescript/commonjs/components/Menu/MenuSurface.d.ts +8 -8
- package/lib/typescript/commonjs/components/Menu/menuModel.d.ts +11 -11
- package/lib/typescript/commonjs/components/Menu/useContextMenu.d.ts +13 -13
- package/lib/typescript/commonjs/components/Menu/webOnly.d.ts +3 -3
- package/lib/typescript/commonjs/components/MessageBubble/MessageBubble.d.ts +20 -20
- package/lib/typescript/commonjs/components/MessageList/MessageList.d.ts +14 -14
- package/lib/typescript/commonjs/components/Modal/Modal.d.ts +19 -19
- package/lib/typescript/commonjs/components/NumberInput/NumberInput.d.ts +27 -27
- package/lib/typescript/commonjs/components/OTPInput/OTPInput.d.ts +20 -20
- package/lib/typescript/commonjs/components/OTPInput/OTPResendRow.d.ts +9 -9
- package/lib/typescript/commonjs/components/OnboardingPager/OnboardingPager.d.ts +5 -5
- package/lib/typescript/commonjs/components/OptionSheet/OptionSheet.d.ts +33 -33
- package/lib/typescript/commonjs/components/OptionSheet/optionAccessors.d.ts +8 -0
- package/lib/typescript/commonjs/components/PagedListFooter/PagedListFooter.d.ts +2 -2
- package/lib/typescript/commonjs/components/PermissionPrompt/PermissionPrompt.d.ts +6 -6
- package/lib/typescript/commonjs/components/PermissionPrompt/usePermissionPrompt.d.ts +1 -1
- package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +43 -43
- package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +23 -23
- package/lib/typescript/commonjs/components/ProfileCompletion/ProfileCompletion.d.ts +23 -23
- package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +30 -30
- package/lib/typescript/commonjs/components/ProgressBar/ProgressBar.d.ts +21 -21
- package/lib/typescript/commonjs/components/ProgressRing/ProgressRing.d.ts +13 -13
- package/lib/typescript/commonjs/components/Radio/Radio.d.ts +18 -18
- package/lib/typescript/commonjs/components/Radio/RadioDot.d.ts +5 -5
- package/lib/typescript/commonjs/components/Radio/RadioGroup.d.ts +8 -8
- package/lib/typescript/commonjs/components/Rating/Rating.d.ts +15 -15
- package/lib/typescript/commonjs/components/Repeater/Repeater.d.ts +10 -10
- package/lib/typescript/commonjs/components/RichTextEditor/RichTextEditor.d.ts +15 -15
- package/lib/typescript/commonjs/components/ScannerOverlay/ScannerOverlay.d.ts +13 -13
- package/lib/typescript/commonjs/components/Screen/Screen.d.ts +43 -44
- package/lib/typescript/commonjs/components/Screen/index.d.ts +1 -1
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +31 -31
- package/lib/typescript/commonjs/components/SearchBar/SearchPanel.d.ts +6 -6
- package/lib/typescript/commonjs/components/SearchBar/useRecentSearches.d.ts +1 -1
- package/lib/typescript/commonjs/components/SectionHeader/SectionHeader.d.ts +10 -10
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +25 -24
- package/lib/typescript/commonjs/components/Select/Select.d.ts +50 -45
- package/lib/typescript/commonjs/components/SignaturePad/SignaturePad.d.ts +20 -20
- package/lib/typescript/commonjs/components/Skeleton/Skeleton.d.ts +13 -13
- package/lib/typescript/commonjs/components/Skeleton/SkeletonContent.d.ts +9 -9
- package/lib/typescript/commonjs/components/Skeleton/SkeletonList.d.ts +30 -8
- package/lib/typescript/commonjs/components/Skeleton/SkeletonProvider.d.ts +9 -9
- package/lib/typescript/commonjs/components/SlideToConfirm/SlideToConfirm.d.ts +14 -14
- package/lib/typescript/commonjs/components/Slider/Slider.d.ts +30 -30
- package/lib/typescript/commonjs/components/Slider/valueText.d.ts +9 -9
- package/lib/typescript/commonjs/components/SliderField/SliderField.d.ts +41 -41
- package/lib/typescript/commonjs/components/SortableList/SortableList.d.ts +5 -5
- package/lib/typescript/commonjs/components/Sparkline/Sparkline.d.ts +13 -13
- package/lib/typescript/commonjs/components/Sparkline/geometry.d.ts +3 -1
- package/lib/typescript/commonjs/components/Spinner/Spinner.d.ts +10 -10
- package/lib/typescript/commonjs/components/SquircleFill/SquircleFill.d.ts +3 -3
- package/lib/typescript/commonjs/components/SquircleImage/SquircleImage.d.ts +5 -12
- package/lib/typescript/commonjs/components/StatTile/StatTile.d.ts +14 -14
- package/lib/typescript/commonjs/components/StatusBadge/StatusBadge.d.ts +13 -13
- package/lib/typescript/commonjs/components/Stepper/Stepper.d.ts +21 -21
- package/lib/typescript/commonjs/components/Swipeable/Swipeable.d.ts +16 -16
- package/lib/typescript/commonjs/components/Switch/Switch.d.ts +19 -19
- package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +20 -20
- package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +19 -19
- package/lib/typescript/commonjs/components/Text/Text.d.ts +10 -10
- package/lib/typescript/commonjs/components/TimePicker/TimePicker.d.ts +14 -14
- package/lib/typescript/commonjs/components/Timeline/Timeline.d.ts +12 -12
- package/lib/typescript/commonjs/components/Toast/Toast.d.ts +17 -17
- package/lib/typescript/commonjs/components/Toast/ToastProvider.d.ts +8 -8
- package/lib/typescript/commonjs/components/Tooltip/RichTooltipBody.d.ts +4 -4
- package/lib/typescript/commonjs/components/Tooltip/Tooltip.d.ts +24 -19
- package/lib/typescript/commonjs/components/Tour/Tour.d.ts +7 -7
- package/lib/typescript/commonjs/components/TypingIndicator/TypingIndicator.d.ts +6 -6
- package/lib/typescript/commonjs/components/WheelPicker/Wheel.d.ts +6 -6
- package/lib/typescript/commonjs/components/WheelPicker/WheelPicker.d.ts +20 -20
- package/lib/typescript/commonjs/components/ZoomableImage/ZoomableImage.d.ts +8 -8
- package/lib/typescript/commonjs/form/HookFormField.d.ts +5 -18
- package/lib/typescript/commonjs/form/path.d.ts +4 -2
- package/lib/typescript/commonjs/form/useFormCompletion.d.ts +1 -1
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts +2 -2
- package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +8 -8
- package/lib/typescript/commonjs/hooks/useFieldErrorScroll.d.ts +1 -1
- package/lib/typescript/commonjs/hooks/usePressAnimation.d.ts +4 -4
- package/lib/typescript/commonjs/hooks/useRefreshControl.d.ts +8 -8
- package/lib/typescript/commonjs/hooks/useResendCountdown.d.ts +1 -1
- package/lib/typescript/commonjs/hooks/useScrollDirection.d.ts +1 -1
- package/lib/typescript/commonjs/navigation/DiscardGuard.d.ts +2 -2
- package/lib/typescript/commonjs/navigation/NavigationScreen.d.ts +3 -3
- package/lib/typescript/commonjs/network/NetworkStatusBanner.d.ts +7 -7
- package/lib/typescript/commonjs/theme/Gradient.d.ts +2 -2
- package/lib/typescript/commonjs/theme/ThemeContext.d.ts +5 -5
- package/lib/typescript/commonjs/theme/componentSizes.d.ts +15 -38
- package/lib/typescript/commonjs/theme/types.d.ts +84 -84
- package/lib/typescript/commonjs/utils/announce.d.ts +1 -1
- package/lib/typescript/commonjs/utils/complete.d.ts +5 -0
- package/lib/typescript/commonjs/utils/feedback.d.ts +3 -1
- package/lib/typescript/commonjs/utils/guards.d.ts +9 -0
- package/lib/typescript/commonjs/utils/placement.d.ts +3 -3
- package/lib/typescript/commonjs/utils/squircle.d.ts +2 -2
- package/lib/typescript/module/canvasKit/index.d.ts +12 -12
- package/lib/typescript/module/canvasKit/meta.d.ts +5 -7
- package/lib/typescript/module/components/Accordion/Accordion.d.ts +22 -22
- package/lib/typescript/module/components/AmountSlider/AmountSlider.d.ts +23 -23
- package/lib/typescript/module/components/AnimatePresence/AnimatePresence.d.ts +5 -5
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +39 -39
- package/lib/typescript/module/components/AppIcon/AppIcon.d.ts +7 -7
- package/lib/typescript/module/components/AppIcon/defaultIcons.d.ts +2 -1
- package/lib/typescript/module/components/AppIcon/glyphs.g.d.ts +233 -233
- package/lib/typescript/module/components/AppIcon/slotIcon.d.ts +1 -1
- package/lib/typescript/module/components/AppLockOverlay/AppLockOverlay.d.ts +5 -5
- package/lib/typescript/module/components/AsyncBlock/AsyncBlock.d.ts +22 -40
- package/lib/typescript/module/components/AuthedImage/AuthedImage.d.ts +15 -15
- package/lib/typescript/module/components/AuthedImage/authedImageCache.d.ts +2 -2
- package/lib/typescript/module/components/Autocomplete/Autocomplete.d.ts +24 -24
- package/lib/typescript/module/components/Avatar/Avatar.d.ts +36 -36
- package/lib/typescript/module/components/Badge/Badge.d.ts +18 -18
- package/lib/typescript/module/components/Banner/Banner.d.ts +25 -25
- package/lib/typescript/module/components/BarChart/BarChart.d.ts +21 -21
- package/lib/typescript/module/components/BottomNavigation/BottomNavigation.d.ts +36 -36
- package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +33 -33
- package/lib/typescript/module/components/Box/Box.d.ts +27 -27
- package/lib/typescript/module/components/Button/Button.d.ts +22 -22
- package/lib/typescript/module/components/Calendar/Calendar.d.ts +20 -20
- package/lib/typescript/module/components/Calendar/CalendarDay.d.ts +4 -2
- package/lib/typescript/module/components/Card/Card.d.ts +41 -41
- package/lib/typescript/module/components/Carousel/Carousel.d.ts +21 -21
- package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +21 -21
- package/lib/typescript/module/components/Chip/Chip.d.ts +23 -23
- package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +51 -46
- package/lib/typescript/module/components/Composer/Composer.d.ts +27 -27
- package/lib/typescript/module/components/Confetti/Confetti.d.ts +22 -21
- package/lib/typescript/module/components/Confirm/confirm.d.ts +4 -4
- package/lib/typescript/module/components/DatePicker/DatePicker.d.ts +20 -20
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +22 -22
- package/lib/typescript/module/components/DateSeparator/DateSeparator.d.ts +9 -9
- package/lib/typescript/module/components/DecimalInput/DecimalInput.d.ts +14 -14
- package/lib/typescript/module/components/Descriptions/Descriptions.d.ts +13 -13
- package/lib/typescript/module/components/Dialog/Dialog.d.ts +24 -24
- package/lib/typescript/module/components/Dialog/OverlayActions.d.ts +5 -5
- package/lib/typescript/module/components/Divider/Divider.d.ts +9 -9
- package/lib/typescript/module/components/Drawer/Drawer.d.ts +15 -15
- package/lib/typescript/module/components/EmptyState/EmptyState.d.ts +13 -13
- package/lib/typescript/module/components/ErrorBoundary/ErrorBoundary.d.ts +8 -8
- package/lib/typescript/module/components/FieldBase/Chevron.d.ts +2 -2
- package/lib/typescript/module/components/FieldBase/ChoiceText.d.ts +10 -10
- package/lib/typescript/module/components/FieldBase/FieldBase.d.ts +54 -54
- package/lib/typescript/module/components/FieldBase/useFloatingLabel.d.ts +8 -8
- package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +35 -35
- package/lib/typescript/module/components/FileViewer/FileViewer.d.ts +10 -10
- package/lib/typescript/module/components/FileViewer/fileSource.d.ts +3 -3
- package/lib/typescript/module/components/FileViewer/useFileViewerZoom.d.ts +3 -3
- package/lib/typescript/module/components/FilterChipRow/FilterChipRow.d.ts +12 -12
- package/lib/typescript/module/components/FloatingActionButton/FloatingActionButton.d.ts +35 -35
- package/lib/typescript/module/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +11 -11
- package/lib/typescript/module/components/FormField/FormField.d.ts +15 -15
- package/lib/typescript/module/components/IconBadge/IconBadge.d.ts +11 -11
- package/lib/typescript/module/components/IconButton/IconButton.d.ts +14 -14
- package/lib/typescript/module/components/ImageGallery/ImageGallery.d.ts +14 -14
- package/lib/typescript/module/components/InlineSelect/InlineSelect.d.ts +36 -31
- package/lib/typescript/module/components/Input/Input.d.ts +47 -47
- package/lib/typescript/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +7 -7
- package/lib/typescript/module/components/KeyboardToolbar/KeyboardToolbar.d.ts +8 -8
- package/lib/typescript/module/components/ListItem/ListItem.d.ts +44 -44
- package/lib/typescript/module/components/ListSection/ListSection.d.ts +6 -6
- package/lib/typescript/module/components/LoaderOverlay/LoaderOverlay.d.ts +17 -11
- package/lib/typescript/module/components/Markdown/Markdown.d.ts +15 -15
- package/lib/typescript/module/components/Menu/Menu.d.ts +17 -12
- package/lib/typescript/module/components/Menu/MenuSurface.d.ts +8 -8
- package/lib/typescript/module/components/Menu/menuModel.d.ts +11 -11
- package/lib/typescript/module/components/Menu/useContextMenu.d.ts +13 -13
- package/lib/typescript/module/components/Menu/webOnly.d.ts +3 -3
- package/lib/typescript/module/components/MessageBubble/MessageBubble.d.ts +20 -20
- package/lib/typescript/module/components/MessageList/MessageList.d.ts +14 -14
- package/lib/typescript/module/components/Modal/Modal.d.ts +19 -19
- package/lib/typescript/module/components/NumberInput/NumberInput.d.ts +27 -27
- package/lib/typescript/module/components/OTPInput/OTPInput.d.ts +20 -20
- package/lib/typescript/module/components/OTPInput/OTPResendRow.d.ts +9 -9
- package/lib/typescript/module/components/OnboardingPager/OnboardingPager.d.ts +5 -5
- package/lib/typescript/module/components/OptionSheet/OptionSheet.d.ts +33 -33
- package/lib/typescript/module/components/OptionSheet/optionAccessors.d.ts +8 -0
- package/lib/typescript/module/components/PagedListFooter/PagedListFooter.d.ts +2 -2
- package/lib/typescript/module/components/PermissionPrompt/PermissionPrompt.d.ts +6 -6
- package/lib/typescript/module/components/PermissionPrompt/usePermissionPrompt.d.ts +1 -1
- package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +43 -43
- package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +23 -23
- package/lib/typescript/module/components/ProfileCompletion/ProfileCompletion.d.ts +23 -23
- package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +30 -30
- package/lib/typescript/module/components/ProgressBar/ProgressBar.d.ts +21 -21
- package/lib/typescript/module/components/ProgressRing/ProgressRing.d.ts +13 -13
- package/lib/typescript/module/components/Radio/Radio.d.ts +18 -18
- package/lib/typescript/module/components/Radio/RadioDot.d.ts +5 -5
- package/lib/typescript/module/components/Radio/RadioGroup.d.ts +8 -8
- package/lib/typescript/module/components/Rating/Rating.d.ts +15 -15
- package/lib/typescript/module/components/Repeater/Repeater.d.ts +10 -10
- package/lib/typescript/module/components/RichTextEditor/RichTextEditor.d.ts +15 -15
- package/lib/typescript/module/components/ScannerOverlay/ScannerOverlay.d.ts +13 -13
- package/lib/typescript/module/components/Screen/Screen.d.ts +43 -44
- package/lib/typescript/module/components/Screen/index.d.ts +1 -1
- package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +31 -31
- package/lib/typescript/module/components/SearchBar/SearchPanel.d.ts +6 -6
- package/lib/typescript/module/components/SearchBar/useRecentSearches.d.ts +1 -1
- package/lib/typescript/module/components/SectionHeader/SectionHeader.d.ts +10 -10
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +25 -24
- package/lib/typescript/module/components/Select/Select.d.ts +50 -45
- package/lib/typescript/module/components/SignaturePad/SignaturePad.d.ts +20 -20
- package/lib/typescript/module/components/Skeleton/Skeleton.d.ts +13 -13
- package/lib/typescript/module/components/Skeleton/SkeletonContent.d.ts +9 -9
- package/lib/typescript/module/components/Skeleton/SkeletonList.d.ts +30 -8
- package/lib/typescript/module/components/Skeleton/SkeletonProvider.d.ts +9 -9
- package/lib/typescript/module/components/SlideToConfirm/SlideToConfirm.d.ts +14 -14
- package/lib/typescript/module/components/Slider/Slider.d.ts +30 -30
- package/lib/typescript/module/components/Slider/valueText.d.ts +9 -9
- package/lib/typescript/module/components/SliderField/SliderField.d.ts +41 -41
- package/lib/typescript/module/components/SortableList/SortableList.d.ts +5 -5
- package/lib/typescript/module/components/Sparkline/Sparkline.d.ts +13 -13
- package/lib/typescript/module/components/Sparkline/geometry.d.ts +3 -1
- package/lib/typescript/module/components/Spinner/Spinner.d.ts +10 -10
- package/lib/typescript/module/components/SquircleFill/SquircleFill.d.ts +3 -3
- package/lib/typescript/module/components/SquircleImage/SquircleImage.d.ts +5 -12
- package/lib/typescript/module/components/StatTile/StatTile.d.ts +14 -14
- package/lib/typescript/module/components/StatusBadge/StatusBadge.d.ts +13 -13
- package/lib/typescript/module/components/Stepper/Stepper.d.ts +21 -21
- package/lib/typescript/module/components/Swipeable/Swipeable.d.ts +16 -16
- package/lib/typescript/module/components/Switch/Switch.d.ts +19 -19
- package/lib/typescript/module/components/Tabs/Tabs.d.ts +20 -20
- package/lib/typescript/module/components/TagInput/TagInput.d.ts +19 -19
- package/lib/typescript/module/components/Text/Text.d.ts +10 -10
- package/lib/typescript/module/components/TimePicker/TimePicker.d.ts +14 -14
- package/lib/typescript/module/components/Timeline/Timeline.d.ts +12 -12
- package/lib/typescript/module/components/Toast/Toast.d.ts +17 -17
- package/lib/typescript/module/components/Toast/ToastProvider.d.ts +8 -8
- package/lib/typescript/module/components/Tooltip/RichTooltipBody.d.ts +4 -4
- package/lib/typescript/module/components/Tooltip/Tooltip.d.ts +24 -19
- package/lib/typescript/module/components/Tour/Tour.d.ts +7 -7
- package/lib/typescript/module/components/TypingIndicator/TypingIndicator.d.ts +6 -6
- package/lib/typescript/module/components/WheelPicker/Wheel.d.ts +6 -6
- package/lib/typescript/module/components/WheelPicker/WheelPicker.d.ts +20 -20
- package/lib/typescript/module/components/ZoomableImage/ZoomableImage.d.ts +8 -8
- package/lib/typescript/module/form/HookFormField.d.ts +5 -18
- package/lib/typescript/module/form/path.d.ts +4 -2
- package/lib/typescript/module/form/useFormCompletion.d.ts +1 -1
- package/lib/typescript/module/hooks/useControllableState.d.ts +2 -2
- package/lib/typescript/module/hooks/useDragToDismiss.d.ts +8 -8
- package/lib/typescript/module/hooks/useFieldErrorScroll.d.ts +1 -1
- package/lib/typescript/module/hooks/usePressAnimation.d.ts +4 -4
- package/lib/typescript/module/hooks/useRefreshControl.d.ts +8 -8
- package/lib/typescript/module/hooks/useResendCountdown.d.ts +1 -1
- package/lib/typescript/module/hooks/useScrollDirection.d.ts +1 -1
- package/lib/typescript/module/navigation/DiscardGuard.d.ts +2 -2
- package/lib/typescript/module/navigation/NavigationScreen.d.ts +3 -3
- package/lib/typescript/module/network/NetworkStatusBanner.d.ts +7 -7
- package/lib/typescript/module/theme/Gradient.d.ts +2 -2
- package/lib/typescript/module/theme/ThemeContext.d.ts +5 -5
- package/lib/typescript/module/theme/componentSizes.d.ts +15 -38
- package/lib/typescript/module/theme/types.d.ts +84 -84
- package/lib/typescript/module/utils/announce.d.ts +1 -1
- package/lib/typescript/module/utils/complete.d.ts +5 -0
- package/lib/typescript/module/utils/feedback.d.ts +3 -1
- package/lib/typescript/module/utils/guards.d.ts +9 -0
- package/lib/typescript/module/utils/placement.d.ts +3 -3
- package/lib/typescript/module/utils/squircle.d.ts +2 -2
- package/package.json +11 -11
- package/src/specs/NativePdfRasterizer.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{OFFLINE_CODE}from"@webority/mobile-core";import{useMemo}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{AppIcon}from"../AppIcon/index.js";import{EmptyState}from"../EmptyState/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_ASYNC_BLOCK_LABELS=Object.freeze({emptyTitle:"Nothing here yet",errorTitle:"That didn't load",offlineTitle:"You're offline",retry:"Try again"});export function AsyncBlock({state:e,children:t,empty:r,errorVariant:s,skeleton:i,errorTitle:o,offlineTitle:l,labels:n,style:a,testID:c}){const m=useTheme(),p=useMemo(()=>({...DEFAULT_ASYNC_BLOCK_LABELS,...n}),[n]);switch(assertValidValue("AsyncBlock","errorVariant",s,["default","offline"]),assertValidValue("AsyncBlock","status",e.status,["loading","error","empty","data"]),e.status){case"loading":return _jsx(View,{style:a,testID:c,children:i??_jsx(View,{style:{paddingVertical:m.space["2xl"],alignItems:"center"},children:_jsx(Spinner,{})})});case"error":{const t="offline"===(s??(e.error.code===OFFLINE_CODE?"offline":"default"));return _jsx(View,{style:a,testID:c,children:_jsx(EmptyState,{icon:t?_jsx(AppIcon,{name:"cloud-cross",size:"xl",color:m.colors["text-subtle"],testID:"async-block-offline-icon"}):void 0,title:t?l??p.offlineTitle:o??p.errorTitle,description:e.error.message,action:{label:p.retry,onPress:e.retry}})})}case"empty":return _jsx(View,{style:a,testID:c,children:_jsx(EmptyState,{...r??{title:p.emptyTitle}})});case"data":return _jsx(_Fragment,{children:t(e.data)})}}export default AsyncBlock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Image}from"expo-image";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{acquireFetch,DEFAULT_TTL_MS,deriveCacheKey,isFresh,isPermanentRefusal,readEntry,releaseFetch,removeEntry,touchEntry}from"./authedImageCache.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_AUTHED_IMAGE_LABELS=Object.freeze({loading:"Loading image",unavailable:"Image unavailable",unavailableNamed:e=>`${e}, image unavailable`});const CONTENT_FIT={cover:"cover",contain:"contain",stretch:"fill",center:"scale-down",repeat:"cover"},toError=e=>e instanceof Error?e:new Error(String(e)),AuthedImage=e=>{const{uri:t,headers:r,client:
|
|
1
|
+
"use strict";import{Image}from"expo-image";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{acquireFetch,DEFAULT_TTL_MS,deriveCacheKey,isFresh,isPermanentRefusal,readEntry,releaseFetch,removeEntry,touchEntry}from"./authedImageCache.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_AUTHED_IMAGE_LABELS=Object.freeze({loading:"Loading image",unavailable:"Image unavailable",unavailableNamed:e=>`${e}, image unavailable`});const CONTENT_FIT={cover:"cover",contain:"contain",stretch:"fill",center:"scale-down",repeat:"cover"},toError=e=>e instanceof Error?e:new Error(String(e)),AuthedImage=e=>{const{uri:t,headers:r,client:i,authenticated:a=!0,ttlMs:s=DEFAULT_TTL_MS,placeholder:o,fallback:n,onLoadStart:l,onLoadEnd:c,onError:d,cacheKey:u,testID:m,accessibilityLabel:h,style:y,resizeMode:f,fadeDuration:b,contentFit:E,transition:g,labels:v,cachePolicy:p="memory",...I}=e;assertValidValue("AuthedImage","resizeMode",f,Object.keys(CONTENT_FIT));const L=useMemo(()=>({...DEFAULT_AUTHED_IMAGE_LABELS,...v}),[v]),T=useTheme(),S=useMemo(()=>buildStyles(T),[T]),[j,x]=useState({status:"loading"}),_=useRef({onLoadStart:l,onLoadEnd:c,onError:d});_.current={onLoadStart:l,onLoadEnd:c,onError:d};const F=JSON.stringify(r??{});if(useEffect(()=>{let e=!1,r=null;const finish=t=>{e||(x(t),_.current.onLoadEnd?.())};return(async()=>{if(!t){const t=new Error("[@webority/mobile-ui] AuthedImage was given an empty `uri`. Pass the image URL, or render nothing while the URL is still unknown.");return void(e||(x({status:"error"}),_.current.onError?.(t)))}x({status:"loading"}),_.current.onLoadStart?.();const o=deriveCacheKey(t,u),n=await readEntry(o);if(e)return;if(n&&isFresh(n.meta,s))return touchEntry(o),void finish({status:"ready",fileUri:n.fileUri});const l=JSON.parse(F),c=acquireFetch(o,{uri:t,headers:l,authenticated:a,client:i});r={key:o,entry:c};try{const e=await c.promise;finish({status:"ready",fileUri:e.fileUri})}catch(t){if(e)return;if(n&&!isPermanentRefusal(t))return void finish({status:"ready",fileUri:n.fileUri});if(n&&(await removeEntry(o),e))return;x({status:"error"}),_.current.onError?.(toError(t)),_.current.onLoadEnd?.()}})(),()=>{e=!0,r&&releaseFetch(r.key,r.entry)}},[t,u,s,a,i,F]),"loading"===j.status)return _jsx(View,void 0!==o?{style:y,testID:m,children:o}:{style:[S.placeholder,y],testID:m,children:_jsx(View,{style:S.stateFill,testID:m?`${m}-placeholder`:void 0,pointerEvents:"none",children:_jsx(Spinner,{size:"sm",accessibilityLabel:L.loading})})});if("error"===j.status)return _jsx(View,void 0!==n?{style:y,testID:m,children:n}:{style:[S.fallback,y],testID:m,children:_jsx(View,{accessible:!0,accessibilityRole:"image",accessibilityLabel:h?L.unavailableNamed(h):L.unavailable,testID:m?`${m}-fallback`:void 0,style:S.stateFill,children:_jsx(Text,{variant:"title",color:"tertiary",accessible:!1,children:"!"})})});const A=E??(f?CONTENT_FIT[f]:void 0),w=g??b,C={...void 0!==h?{accessibilityLabel:h}:{},...void 0!==m?{testID:m}:{},...void 0!==y?{style:y}:{},...void 0!==A?{contentFit:A}:{},...void 0!==w?{transition:w}:{}};return _jsx(Image,{...I,...C,accessible:!0,accessibilityRole:"image",cachePolicy:p,source:{uri:j.fileUri}})};AuthedImage.displayName="AuthedImage";const buildStyles=e=>StyleSheet.create({placeholder:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.md,...smoothCorners},fallback:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.md,...smoothCorners,borderWidth:e.size.border,borderColor:e.colors["border-subtle"],padding:e.space.sm},stateFill:{alignItems:"center",flex:1,justifyContent:"center"}});export{AuthedImage};export default AuthedImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{ACCESS_TOKEN_KEY,getConfigValue,getToken,isStorageAvailable,Logger,publicClient,Storage}from"@webority/mobile-core";import{AppState}from"react-native";import{hashString}from"../../utils/hashString.js";import{clearImages,deleteImage,imageExists,imageUri,listImageNames,writeImage}from"./imageStore";const INDEX_KEY="@webority/authed-image/v2/index",LEGACY_PREFIX="@webority/authed-image/v1/",DEFAULT_BYTE_CEILING=52428800,TOUCH_PERSIST_MS=36e5,PERSIST_DELAY_MS=1e3;export const DEFAULT_TTL_MS=6048e5;let byteCeiling=52428800;export const setAuthedImageCacheLimit=e=>{if(!Number.isFinite(e)||e<=0)throw new Error(`[@webority/mobile-ui] setAuthedImageCacheLimit() needs a positive number of bytes, received ${String(e)}. Pass e.g. 50 * 1024 * 1024 for 50 MB.`);byteCeiling=e};export const getAuthedImageCacheLimit=()=>byteCeiling;export const deriveCacheKey=(e,t)=>hashString(t??e);const toMeta=({fetchedAt:e,bytes:t,contentType:
|
|
1
|
+
"use strict";import{ACCESS_TOKEN_KEY,getConfigValue,getToken,isStorageAvailable,Logger,publicClient,Storage}from"@webority/mobile-core";import{AppState}from"react-native";import{isRecord}from"../../utils/guards.js";import{hashString}from"../../utils/hashString.js";import{clearImages,deleteImage,imageExists,imageUri,listImageNames,writeImage}from"./imageStore";const INDEX_KEY="@webority/authed-image/v2/index",LEGACY_PREFIX="@webority/authed-image/v1/",DEFAULT_BYTE_CEILING=52428800,TOUCH_PERSIST_MS=36e5,PERSIST_DELAY_MS=1e3;export const DEFAULT_TTL_MS=6048e5;const isIndexEntry=e=>isRecord(e)&&"number"==typeof e.fetchedAt&&"number"==typeof e.bytes&&"string"==typeof e.contentType&&"number"==typeof e.lastAccessedAt&&"string"==typeof e.fileName&&"number"==typeof e.persistedAccessAt;let byteCeiling=52428800;export const setAuthedImageCacheLimit=e=>{if(!Number.isFinite(e)||e<=0)throw new Error(`[@webority/mobile-ui] setAuthedImageCacheLimit() needs a positive number of bytes, received ${String(e)}. Pass e.g. 50 * 1024 * 1024 for 50 MB.`);byteCeiling=e};export const getAuthedImageCacheLimit=()=>byteCeiling;export const deriveCacheKey=(e,t)=>hashString(t??e);const toMeta=({fetchedAt:e,bytes:t,contentType:r,lastAccessedAt:s})=>({fetchedAt:e,bytes:t,contentType:r,lastAccessedAt:s});let index=null,indexBytes=0,indexLoad=null,persistTimer=null,persistTarget=null,appStateSub=null;const persistIndex=async e=>{if(!isStorageAvailable())return;const t={};for(const[r,s]of e)t[r]={...s,persistedAccessAt:s.lastAccessedAt};if(await Storage.setItem(INDEX_KEY,JSON.stringify(t)))for(const t of e.values())t.persistedAccessAt=t.lastAccessedAt},schedulePersist=e=>{persistTarget=e,null===appStateSub&&(appStateSub=AppState.addEventListener("change",e=>{"active"!==e&&flushAuthedImageIndex()})),null===persistTimer&&(persistTimer=setTimeout(()=>{flushAuthedImageIndex()},1e3))};export const flushAuthedImageIndex=async()=>{null!==persistTimer&&(clearTimeout(persistTimer),persistTimer=null);const e=persistTarget;persistTarget=null,null!==e&&await persistIndex(e)};const removeLegacyEntries=async()=>{const e=(await Storage.getAllKeys()).filter(e=>e.startsWith(LEGACY_PREFIX));e.length>0&&await Storage.multiRemove(e)},removeOrphanFiles=e=>{try{const t=new Set([...e.values()].map(e=>e.fileName));for(const e of listImageNames())t.has(e)||deleteImage(e)}catch(e){Logger.warn("[@webority/mobile-ui] AuthedImage could not tidy the image cache folder",e)}},readStoredIndex=async()=>{const e=new Map;if(!isStorageAvailable())return e;const t=await Storage.getItem(INDEX_KEY);if(!t)return await removeLegacyEntries(),e;try{const r=JSON.parse(t);if(isRecord(r))for(const[t,s]of Object.entries(r))isIndexEntry(s)&&e.set(t,s)}catch{}return e},loadIndex=()=>index?Promise.resolve(index):(indexLoad||(indexLoad=readStoredIndex().then(e=>{removeOrphanFiles(e);for(const[t,r]of e)imageExists(r.fileName)||e.delete(t);return index=e,indexBytes=[...e.values()].reduce((e,t)=>e+t.bytes,0),e}).finally(()=>{indexLoad=null})),indexLoad),deleteFile=e=>{try{deleteImage(e)}catch(e){Logger.warn("[@webority/mobile-ui] AuthedImage could not delete a cached image file",e)}};export const readEntry=async e=>{const t=await loadIndex(),r=t.get(e);return r?imageExists(r.fileName)?{fileUri:imageUri(r.fileName),meta:toMeta(r)}:(t.delete(e),indexBytes-=r.bytes,schedulePersist(t),null):null};export const removeEntry=async e=>{const t=await loadIndex(),r=t.get(e);r&&(t.delete(e),indexBytes-=r.bytes,deleteFile(r.fileName),schedulePersist(t))};export class AuthedImageHttpError extends Error{constructor(e,t){super(e),this.name="AuthedImageHttpError",this.status=t}}export const isPermanentRefusal=e=>e instanceof AuthedImageHttpError&&e.status>=400&&e.status<500&&408!==e.status&&429!==e.status;export const isFresh=(e,t,r=Date.now())=>r-e.fetchedAt<t;export const touchEntry=async e=>{const t=await loadIndex(),r=t.get(e);r&&(r.lastAccessedAt=Date.now(),r.lastAccessedAt-r.persistedAccessAt>=36e5&&schedulePersist(t))};const evictIfNeeded=e=>{let t=indexBytes;if(t<=byteCeiling)return 0;const r=[...e].sort(([,e],[,t])=>e.lastAccessedAt-t.lastAccessedAt);let s=0;for(const[i,a]of r){if(t<=byteCeiling)break;e.delete(i),indexBytes-=a.bytes,deleteFile(a.fileName),t-=a.bytes,s+=1}return s};export const clearAuthedImageCache=async()=>{null!==persistTimer&&(clearTimeout(persistTimer),persistTimer=null),persistTarget=null;(await loadIndex()).clear(),indexBytes=0,clearImages(),isStorageAvailable()&&await Storage.removeItem(INDEX_KEY)};export const authedImageCacheStats=async()=>{const e=await loadIndex();let t=0;for(const r of e.values())t+=r.bytes;return{entries:e.size,bytes:t}};const responseHeader=(e,t)=>{if(!isRecord(e))return;const r=e.get,s="function"==typeof r?r.call(e,t):e[t];return"string"==typeof s?s:void 0},originOf=e=>{const t=/^([a-z][a-z0-9+.-]*:\/\/[^/?#]+)/i.exec(e);if(null===t)return null;const r=t[1];if(void 0===r)throw new Error("originOf: the origin pattern always captures group 1 when it matches");return r.toLowerCase()},mediaTypeOf=e=>{const[t]=e.split(";");if(void 0===t)throw new Error("mediaTypeOf: String.split always returns at least one part");return t.trim()},isOwnApiAddress=e=>{const t=originOf(e);if(null===t)return!0;const r=getConfigValue("baseUrl");return"string"==typeof r&&originOf(r)===t},fetchAndStore=async(e,t,r)=>{const s={Accept:"image/*",...t.headers};if(!t.client&&t.authenticated&&isOwnApiAddress(t.uri)){const e=await getToken(ACCESS_TOKEN_KEY);e?.token&&(s.Authorization=`Bearer ${e.token}`)}const i=t.client??publicClient;let a;try{a=await i.get(t.uri,{headers:s,responseType:"arraybuffer",signal:r})}catch(e){const r=isRecord(e)&&isRecord(e.response)?e.response.status:void 0;if("number"!=typeof r)throw e;throw new AuthedImageHttpError(`[@webority/mobile-ui] AuthedImage could not load "${t.uri}": the server answered ${r}. Check the URL and whether the request needs to be signed in (pass the signed-in client as \`client\`, or authenticated={false} for public media).`,r)}const{data:n}=a;if(null!=n&&!(n instanceof ArrayBuffer))throw new Error(`[@webority/mobile-ui] AuthedImage could not load "${t.uri}": the client returned ${typeof n} instead of raw bytes. Pass a client that honours \`responseType: "arraybuffer"\`.`);const o=new Uint8Array(n??new ArrayBuffer(0));if(0===o.byteLength)throw new AuthedImageHttpError(`[@webority/mobile-ui] AuthedImage could not load "${t.uri}": the server answered with an empty body, so the address holds no image.`,404);const l=responseHeader(a.headers,"content-type"),c=(l?mediaTypeOf(l):"")||"image/jpeg",d=await loadIndex(),u=Date.now(),g=`${e}-${u.toString(36)}`;let m;try{m=await writeImage(g,o,c)}catch(e){throw new Error(`[@webority/mobile-ui] AuthedImage fetched "${t.uri}" but could not write it to the app's cache folder: ${e instanceof Error?e.message:String(e)}. The device may be out of storage.`)}const h={fetchedAt:u,bytes:o.byteLength,contentType:c,lastAccessedAt:u,fileName:g,persistedAccessAt:u},f=d.get(e);f&&(indexBytes-=f.bytes),d.set(e,h),indexBytes+=h.bytes,f&&f.fileName!==g&&deleteFile(f.fileName);const p=evictIfNeeded(d);return schedulePersist(d),p>0&&Logger.info(`[@webority/mobile-ui] AuthedImage evicted ${p} cached image(s) over the byte ceiling`),{fileUri:m,meta:toMeta(h)}},inFlight=new Map;export const acquireFetch=(e,t)=>{const r=inFlight.get(e);if(r)return r.waiters+=1,r;const s=new AbortController,i={controller:s,waiters:1,promise:fetchAndStore(e,t,s.signal).finally(()=>{inFlight.get(e)===i&&inFlight.delete(e)})};return inFlight.set(e,i),i};export const releaseFetch=(e,t)=>{t.waiters-=1,t.waiters>0||(inFlight.get(e)===t&&inFlight.delete(e),t.controller.abort())};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Image}from"expo-image";import{Children,cloneElement,forwardRef,isValidElement,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{AuthedImage}from"../AuthedImage/AuthedImage.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const SOFT_FILL_OPACITY=.14,MIN_TOUCH_TARGET=44,PRESSED_OPACITY=.7,INITIALS_MAX_FONT_SCALE=1.2;export const AVATAR_COLORS=["avatar-1","avatar-2","avatar-3","avatar-4","avatar-5","avatar-6","avatar-7","avatar-8"];export const avatarToneColors=(e,t)=>{const soft=(e,t)=>tintOf(e,.14,t);switch(t){case"primary":return{background:soft(e.colors.primary,e.colors["primary-soft"]),color:e.colors["primary-text"]};case"success":return{background:soft(e.colors.success,e.colors["bg-subtle"]),color:e.colors["success-text"]};case"warning":return{background:soft(e.colors.warning,e.colors["bg-subtle"]),color:e.colors["warning-text"]};case"danger":return{background:soft(e.colors.danger,e.colors["bg-subtle"]),color:e.colors["danger-text"]};case"info":return{background:soft(e.colors.info,e.colors["bg-subtle"]),color:e.colors["info-text"]};case"neutral":return{background:e.colors["bg-muted"],color:e.colors["text-body"]}}};export const DEFAULT_AVATAR_LABELS=Object.freeze({avatar:"Avatar",avatarOf:e=>`${e}'s avatar`,verified:"verified",pendingVerification:"pending verification",groupOf:e=>`Group of ${e} ${1===e?"person":"people"}`,moreCount:e=>`${e} more`,moreAvatars:"More avatars"});const sizeMap={xs:24,sm:32,md:48,lg:64,xl:80},resolveSize=e=>sizeMap[e],resolveRadius=(e,t,r,o)=>{switch(t){case"circle":return r/2;case"rounded":return o?e.radius[o]:Math.max(e.radius.sm,Math.round(.22*r));case"square":return 0}},initialsFromName=e=>{if(!e)return"";const t=e.trim().split(/\s+/u).filter(Boolean),[r,o]=t;return void 0===r?"":void 0===o?r.charAt(0).toUpperCase():(r.charAt(0)+o.charAt(0)).toUpperCase()},hashColor=(e,t)=>{let r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t),r|=0;const o=t[Math.abs(r)%t.length];if(void 0===o)throw new Error("The avatar colour palette is empty.");return o},RING_WIDTH=1.5,keyOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:e,uriOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:void 0,isImageSourceList=e=>Array.isArray(e),isRingStatus=e=>"verified"===e||"pending"===e,statusColor=(e,t)=>{switch(t){case"online":case"verified":return e.colors.success;case"busy":return e.colors.danger;case"away":case"pending":return e.colors.warning;case"offline":return e.colors["text-subtle"]}},Avatar=forwardRef((e,t)=>{const{source:r,ImageComponent:o,imageClient:s,name:a,size:i="md",shape:n="circle",dimension:l,radius:c,border:u=!1,contentFit:d="cover",placeholderIcon:m,status:g=null,statusPosition:h="bottomRight",tone:p,backgroundColor:b,color:v,fontSize:f,loading:y=!1,accessibilityLabel:A,onPress:x,onLongPress:S,haptic:C,hitSlop:I,style:V,textStyle:_,testID:R,labels:j}=e;assertValidValue("Avatar","size",e.size,Object.keys(sizeMap)),assertValidValue("Avatar","shape",e.shape,["circle","square","rounded"]),assertValidValue("Avatar","radius",e.radius,["sm","md","lg"]),assertValidValue("Avatar","contentFit",e.contentFit,["cover","contain"]),assertValidValue("Avatar","status",e.status,["online","offline","busy","away","verified","pending"]),assertValidValue("Avatar","statusPosition",e.statusPosition,["topRight","bottomRight"]),assertValidValue("Avatar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const w=useMemo(()=>j?{...DEFAULT_AVATAR_LABELS,...j}:DEFAULT_AVATAR_LABELS,[j]),M=useTheme(),[T,L]=useState(null),E=useMemo(()=>l??resolveSize(i),[l,i]),k=useMemo(()=>resolveRadius(M,n,E,c),[M,n,E,c]),z=u?M.size.border:0,O=M.colors.border,F=M.colors.surface,D=useMemo(()=>initialsFromName(a),[a]),G=useMemo(()=>p?avatarToneColors(M,p):null,[M,p]),P=useMemo(()=>b||(G?.background??M.colors[hashColor(a??"",AVATAR_COLORS)]),[b,G,a,M]),N=v??G?.color??M.colors["on-primary"],$=r?keyOfSource(r):null,B=null!==$&&$!==T,H=!B&&""===D&&null!=m,U=v??G?.color??M.colors["text-subtle"],W=f??Math.max(M.text.xs.size,Math.round(.4*E)),q=Math.max(8,Math.round(.25*E)),Y=isRingStatus(g),X=E-2*(Y?3:z),J=Y?resolveRadius(M,n,X,c):Math.max(0,k-z),K=H?renderSlotIcon(m,{color:U,size:Math.round(.45*X),disabled:!1}):null,Q=Y?statusColor(M,g):"transparent",Z=Math.max(12,Math.round(.32*E)),ee=Math.max(10,Z-4),te=b??G?.background??M.colors["bg-muted"],re=B?"contain"===d?"transparent":M.colors["bg-muted"]:H?te:P,oe=R??"avatar",se=a?w.avatarOf(a):w.avatar,ae="verified"===g?`, ${w.verified}`:"pending"===g?`, ${w.pendingVerification}`:"",ie=A??`${se}${ae}`,ne="function"==typeof x||"function"==typeof S,le=A??`${a||se}${ae}`,ce=Math.max(0,Math.ceil((44-E)/2)),ue=I??ce,de=[styles.root,{width:E,height:E,borderRadius:k,...smoothCorners,borderWidth:Y?0:z,borderColor:O,backgroundColor:Y?"transparent":re},V],me=_jsxs(_Fragment,{children:[Y?_jsx(View,{style:[styles.ring,{borderRadius:k,...smoothCorners,borderWidth:1.5,borderColor:Q}],accessible:!1,pointerEvents:"none",testID:`${oe}-ring`}):null,_jsx(View,{style:[styles.picture,{width:X,height:X,borderRadius:J,...smoothCorners,borderWidth:Y?z:0,borderColor:O,backgroundColor:Y?re:"transparent"}],children:B?(()=>{const e={width:X,height:X,borderRadius:J,...smoothCorners},onError=()=>L($),t=uriOfSource(r);return o?_jsx(o,{source:r,onError:onError,style:e,contentFit:d,resizeMode:d,accessibilityIgnoresInvertColors:!0}):s&&void 0!==t?_jsx(AuthedImage,{uri:t,client:s,onError:onError,style:e,contentFit:d,placeholder:null,fallback:null,accessibilityIgnoresInvertColors:!0}):_jsx(Image,{source:isImageSourceList(r)?[...r]:r,onError:onError,style:e,contentFit:d,accessibilityIgnoresInvertColors:!0})})():K||_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,maxFontSizeMultiplier:1.2,style:[styles.initials,{color:N,fontSize:W,lineHeight:Math.round(W*M.leading.body)},_],children:D??" "})}),"verified"===g?_jsx(View,{style:[styles.status,"topRight"===h?styles.badgeTopRight:styles.badgeBottomRight,{width:Z,height:Z,borderRadius:Z/2,...smoothCorners,backgroundColor:F}],accessible:!1,pointerEvents:"none",testID:`${oe}-badge`,children:_jsx(AppIcon,{name:"verify",variant:"bold",size:ee,color:Q})}):null,g&&!Y?_jsx(View,{style:[styles.status,"topRight"===h?styles.statusTopRight:styles.statusBottomRight,{width:q,height:q,borderRadius:q/2,...smoothCorners,backgroundColor:statusColor(M,g),borderWidth:2,borderColor:F}],accessible:!1,pointerEvents:"none"}):null]}),ge=ne?_jsx(Pressable,{ref:t,onPress:x?e=>{const t=resolveHaptic(C,"selection");t&&triggerHaptic(t),x?.(e)}:void 0,onLongPress:S?e=>{const t=resolveHaptic(C,"longPress");t&&triggerHaptic(t),S?.(e)}:void 0,hitSlop:ue,...hitSlopMarker(ue),accessibilityRole:"button",accessibilityLabel:le,testID:R,style:({pressed:e})=>[de,e?styles.pressed:null],children:me}):_jsx(View,{ref:t,style:de,accessible:!0,accessibilityRole:"image",accessibilityLabel:ie,testID:R,children:me});return y?_jsx(AvatarSkeleton,{...e}):ge});Avatar.displayName="Avatar";const AvatarSkeleton=({size:e="md",shape:t="circle",dimension:r,style:o})=>{const s=r??resolveSize(e);return _jsx(Skeleton,{shape:"circle"===t?"circle":"rounded"===t?"rounded":"rect",width:s,height:s,style:o})};AvatarSkeleton.displayName="AvatarSkeleton",Avatar.Skeleton=AvatarSkeleton;const styles=StyleSheet.create({root:{alignItems:"center",justifyContent:"center",overflow:"visible",position:"relative"},pressed:{opacity:.7},initials:{textAlign:"center"},ring:{position:"absolute",top:0,right:0,bottom:0,left:0},picture:{alignItems:"center",justifyContent:"center",overflow:"hidden"},status:{position:"absolute"},badgeTopRight:{top:-2,right:-2,alignItems:"center",justifyContent:"center"},badgeBottomRight:{bottom:-2,right:-2,alignItems:"center",justifyContent:"center"},statusTopRight:{top:0,right:0},statusBottomRight:{bottom:0,right:0}}),SPACING_OFFSET={tight:"lg",normal:"md",loose:"sm"},STAGGER_MS=50,ENTRANCE_DURATION_MS=220,AvatarGroupItem=({delay:e,marginLeft:t,borderColor:r,borderWidth:o,children:s})=>{const a=useTheme(),i=useRef(createAnimatedValue(0)).current;return useEffect(()=>{const t=Animated.timing(i,{toValue:1,duration:220,delay:e,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver});return t.start(),()=>t.stop()},[e,i]),_jsx(Animated.View,{style:[groupStyles.item,{marginLeft:t,borderRadius:a.radius.pill,borderColor:r,borderWidth:o,opacity:i}],children:s})},AvatarGroup=e=>{const{children:t,max:r=4,size:o="md",spacing:s="normal",overflowVariant:a="count",accessibilityLabel:i,style:n,testID:l,labels:c}=e;assertValidValue("AvatarGroup","spacing",e.spacing,["tight","normal","loose"]),assertValidValue("AvatarGroup","overflowVariant",e.overflowVariant,["count","plus"]),assertValidValue("AvatarGroup","size",e.size,Object.keys(sizeMap));const u=useMemo(()=>c?{...DEFAULT_AVATAR_LABELS,...c}:DEFAULT_AVATAR_LABELS,[c]),d=useTheme(),m=useMemo(()=>Children.toArray(t).filter(e=>isValidElement(e)),[t]),g=m.length,h=m.slice(0,r),p=Math.max(0,g-r),b=p>0,v=-d.space[SPACING_OFFSET[s]],f=d.colors.surface,y=i??u.groupOf(g),A=useMemo(()=>resolveSize(o),[o]),x=Math.max(d.text.xs.size,Math.round(.34*A));return _jsxs(View,{style:[groupStyles.row,n],accessible:!0,accessibilityLabel:y,accessibilityRole:"summary",testID:l,children:[h.map((e,t)=>{const r=e.key??`avatar-${t}`,s=cloneElement(e,{size:o,labels:e.props.labels??c});return _jsx(AvatarGroupItem,{delay:50*t,marginLeft:0===t?0:v,borderColor:f,borderWidth:1.5,children:s},r)}),b?_jsx(AvatarGroupItem,{delay:50*h.length,marginLeft:0===h.length?0:v,borderColor:f,borderWidth:1.5,children:_jsx(View,{style:[groupStyles.overflow,{width:A,height:A,borderRadius:A/2,...smoothCorners,backgroundColor:d.colors["surface-disabled"]}],accessible:!0,accessibilityRole:"text",accessibilityLabel:"count"===a?u.moreCount(p):u.moreAvatars,children:_jsx(Text,{variant:"label",weight:"semibold",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{fontSize:x,lineHeight:Math.round(x*d.leading.body)},children:"count"===a?`+${p}`:"+"})})},"avatar-overflow"):null]})},groupStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},item:{...smoothCorners},overflow:{alignItems:"center",justifyContent:"center"}});export{Avatar,AvatarGroup};export default Avatar;
|
|
1
|
+
"use strict";import{Image}from"expo-image";import{Children,cloneElement,forwardRef,isValidElement,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{AuthedImage}from"../AuthedImage/AuthedImage.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const SOFT_FILL_OPACITY=.14,MIN_TOUCH_TARGET=44,PRESSED_OPACITY=.7,INITIALS_MAX_FONT_SCALE=1.2;export const AVATAR_COLORS=["avatar-1","avatar-2","avatar-3","avatar-4","avatar-5","avatar-6","avatar-7","avatar-8"];export const avatarToneColors=(e,t)=>{const soft=(e,t)=>tintOf(e,.14,t);switch(t){case"primary":return{background:soft(e.colors.primary,e.colors["primary-soft"]),color:e.colors["primary-text"]};case"success":return{background:soft(e.colors.success,e.colors["bg-subtle"]),color:e.colors["success-text"]};case"warning":return{background:soft(e.colors.warning,e.colors["bg-subtle"]),color:e.colors["warning-text"]};case"danger":return{background:soft(e.colors.danger,e.colors["bg-subtle"]),color:e.colors["danger-text"]};case"info":return{background:soft(e.colors.info,e.colors["bg-subtle"]),color:e.colors["info-text"]};case"neutral":return{background:e.colors["bg-muted"],color:e.colors["text-body"]}}};export const DEFAULT_AVATAR_LABELS=Object.freeze({avatar:"Avatar",avatarOf:e=>`${e}'s avatar`,verified:"verified",pendingVerification:"pending verification",groupOf:e=>`Group of ${e} ${1===e?"person":"people"}`,moreCount:e=>`${e} more`,moreAvatars:"More avatars"});const sizeMap={xs:24,sm:32,md:48,lg:64,xl:80},resolveSize=e=>sizeMap[e],resolveRadius=(e,t,r,o)=>{switch(t){case"circle":return r/2;case"rounded":return o?e.radius[o]:Math.max(e.radius.sm,Math.round(.22*r));case"square":return 0}},initialsFromName=e=>{if(!e)return"";const t=e.trim().split(/\s+/u).filter(Boolean),[r,o]=t;return void 0===r?"":void 0===o?r.charAt(0).toUpperCase():(r.charAt(0)+o.charAt(0)).toUpperCase()},hashColor=(e,t)=>{let r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t),r|=0;const o=t[Math.abs(r)%t.length];if(void 0===o)throw new Error("The avatar colour palette is empty.");return o},RING_WIDTH=1.5,keyOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:e,uriOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:void 0,isImageSourceList=e=>Array.isArray(e),toExpoSource=e=>({...void 0!==e.uri?{uri:e.uri}:{},...void 0!==e.headers?{headers:e.headers}:{},...void 0!==e.width?{width:e.width}:{},...void 0!==e.height?{height:e.height}:{}}),toExpoSources=e=>"number"==typeof e?e:isImageSourceList(e)?e.map(toExpoSource):toExpoSource(e),isRingStatus=e=>"verified"===e||"pending"===e,statusColor=(e,t)=>{switch(t){case"online":case"verified":return e.colors.success;case"busy":return e.colors.danger;case"away":case"pending":return e.colors.warning;case"offline":return e.colors["text-subtle"]}},AvatarRoot=forwardRef((e,t)=>{const{source:r,ImageComponent:o,imageClient:s,name:a,size:i="md",shape:n="circle",dimension:l,radius:c,border:u=!1,contentFit:d="cover",placeholderIcon:m,status:h=null,statusPosition:g="bottomRight",tone:p,backgroundColor:b,color:v,fontSize:f,loading:y=!1,accessibilityLabel:A,onPress:x,onLongPress:S,haptic:C,hitSlop:I,style:R,textStyle:V,testID:_,labels:j}=e;assertValidValue("Avatar","size",e.size,Object.keys(sizeMap)),assertValidValue("Avatar","shape",e.shape,["circle","square","rounded"]),assertValidValue("Avatar","radius",e.radius,["sm","md","lg"]),assertValidValue("Avatar","contentFit",e.contentFit,["cover","contain"]),assertValidValue("Avatar","status",e.status,["online","offline","busy","away","verified","pending"]),assertValidValue("Avatar","statusPosition",e.statusPosition,["topRight","bottomRight"]),assertValidValue("Avatar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const w=useMemo(()=>j?{...DEFAULT_AVATAR_LABELS,...j}:DEFAULT_AVATAR_LABELS,[j]),M=useTheme(),[T,E]=useState(null),L=useMemo(()=>l??resolveSize(i),[l,i]),k=useMemo(()=>resolveRadius(M,n,L,c),[M,n,L,c]),z=u?M.size.border:0,O=M.colors.border,F=M.colors.surface,D=useMemo(()=>initialsFromName(a),[a]),G=useMemo(()=>p?avatarToneColors(M,p):null,[M,p]),P=useMemo(()=>b||(G?.background??M.colors[hashColor(a??"",AVATAR_COLORS)]),[b,G,a,M]),N=v??G?.color??M.colors["on-primary"],$=r?keyOfSource(r):null,B=useMemo(()=>void 0!==r?toExpoSources(r):void 0,[r]),H=null!==$&&$!==T,U=!H&&""===D&&null!=m,W=v??G?.color??M.colors["text-subtle"],q=f??Math.max(M.text.xs.size,Math.round(.4*L)),Y=Math.max(8,Math.round(.25*L)),X=isRingStatus(h),J=L-2*(X?3:z),K=X?resolveRadius(M,n,J,c):Math.max(0,k-z),Q=U?renderSlotIcon(m,{color:W,size:Math.round(.45*J),disabled:!1}):null,Z=X?statusColor(M,h):"transparent",ee=Math.max(12,Math.round(.32*L)),te=Math.max(10,ee-4),re=b??G?.background??M.colors["bg-muted"],oe=H?"contain"===d?"transparent":M.colors["bg-muted"]:U?re:P,se=_??"avatar",ae=a?w.avatarOf(a):w.avatar,ie="verified"===h?`, ${w.verified}`:"pending"===h?`, ${w.pendingVerification}`:"",ne=A??`${ae}${ie}`,le="function"==typeof x||"function"==typeof S,ce=A??`${a||ae}${ie}`,ue=Math.max(0,Math.ceil((44-L)/2)),de=I??ue,me=[styles.root,{width:L,height:L,borderRadius:k,...smoothCorners,borderWidth:X?0:z,borderColor:O,backgroundColor:X?"transparent":oe},R],he=_jsxs(_Fragment,{children:[X?_jsx(View,{style:[styles.ring,{borderRadius:k,...smoothCorners,borderWidth:1.5,borderColor:Z}],accessible:!1,pointerEvents:"none",testID:`${se}-ring`}):null,_jsx(View,{style:[styles.picture,{width:J,height:J,borderRadius:K,...smoothCorners,borderWidth:X?z:0,borderColor:O,backgroundColor:X?oe:"transparent"}],children:H?(()=>{const e={width:J,height:J,borderRadius:K,...smoothCorners};if(!r)return null;const onError=()=>E($),t=uriOfSource(r);return o?_jsx(o,{source:r,onError:onError,style:e,contentFit:d,resizeMode:d,accessibilityIgnoresInvertColors:!0}):s&&void 0!==t?_jsx(AuthedImage,{uri:t,client:s,onError:onError,style:e,contentFit:d,placeholder:null,fallback:null,accessibilityIgnoresInvertColors:!0}):_jsx(Image,{...void 0!==B?{source:B}:{},onError:onError,style:e,contentFit:d,accessibilityIgnoresInvertColors:!0})})():Q||_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,maxFontSizeMultiplier:1.2,style:[styles.initials,{color:N,fontSize:q,lineHeight:Math.round(q*M.leading.body)},V],children:D??" "})}),"verified"===h?_jsx(View,{style:[styles.status,"topRight"===g?styles.badgeTopRight:styles.badgeBottomRight,{width:ee,height:ee,borderRadius:ee/2,...smoothCorners,backgroundColor:F}],accessible:!1,pointerEvents:"none",testID:`${se}-badge`,children:_jsx(AppIcon,{name:"verify",variant:"bold",size:te,color:Z})}):null,h&&!X?_jsx(View,{style:[styles.status,"topRight"===g?styles.statusTopRight:styles.statusBottomRight,{width:Y,height:Y,borderRadius:Y/2,...smoothCorners,backgroundColor:statusColor(M,h),borderWidth:2,borderColor:F}],accessible:!1,pointerEvents:"none"}):null]}),ge=le?_jsx(Pressable,{ref:t,onPress:x?e=>{const t=resolveHaptic(C,"selection");t&&triggerHaptic(t),x?.(e)}:void 0,onLongPress:S?e=>{const t=resolveHaptic(C,"longPress");t&&triggerHaptic(t),S?.(e)}:void 0,hitSlop:de,...hitSlopMarker(de),accessibilityRole:"button",accessibilityLabel:ce,testID:_,style:({pressed:e})=>[me,e?styles.pressed:null],children:he}):_jsx(View,{ref:t,style:me,accessible:!0,accessibilityRole:"image",accessibilityLabel:ne,testID:_,children:he});return y?_jsx(AvatarSkeleton,{...e}):ge}),AvatarSkeleton=({size:e="md",shape:t="circle",dimension:r,style:o})=>{const s=r??resolveSize(e);return _jsx(Skeleton,{shape:"circle"===t?"circle":"rounded"===t?"rounded":"rect",width:s,height:s,style:o})};AvatarSkeleton.displayName="AvatarSkeleton";const Avatar=Object.assign(AvatarRoot,{Skeleton:AvatarSkeleton});Avatar.displayName="Avatar";const styles=StyleSheet.create({root:{alignItems:"center",justifyContent:"center",overflow:"visible",position:"relative"},pressed:{opacity:.7},initials:{textAlign:"center"},ring:{position:"absolute",top:0,right:0,bottom:0,left:0},picture:{alignItems:"center",justifyContent:"center",overflow:"hidden"},status:{position:"absolute"},badgeTopRight:{top:-2,right:-2,alignItems:"center",justifyContent:"center"},badgeBottomRight:{bottom:-2,right:-2,alignItems:"center",justifyContent:"center"},statusTopRight:{top:0,right:0},statusBottomRight:{bottom:0,right:0}}),SPACING_OFFSET={tight:"lg",normal:"md",loose:"sm"},STAGGER_MS=50,ENTRANCE_DURATION_MS=220,AvatarGroupItem=({delay:e,marginLeft:t,borderColor:r,borderWidth:o,children:s})=>{const a=useTheme(),i=useRef(createAnimatedValue(0)).current;return useEffect(()=>{const t=Animated.timing(i,{toValue:1,duration:220,delay:e,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver});return t.start(),()=>t.stop()},[e,i]),_jsx(Animated.View,{style:[groupStyles.item,{marginLeft:t,borderRadius:a.radius.pill,borderColor:r,borderWidth:o,opacity:i}],children:s})},AvatarGroup=e=>{const{children:t,max:r=4,size:o="md",spacing:s="normal",overflowVariant:a="count",accessibilityLabel:i,style:n,testID:l,labels:c}=e;assertValidValue("AvatarGroup","spacing",e.spacing,["tight","normal","loose"]),assertValidValue("AvatarGroup","overflowVariant",e.overflowVariant,["count","plus"]),assertValidValue("AvatarGroup","size",e.size,Object.keys(sizeMap));const u=useMemo(()=>c?{...DEFAULT_AVATAR_LABELS,...c}:DEFAULT_AVATAR_LABELS,[c]),d=useTheme(),m=useMemo(()=>Children.toArray(t).filter(e=>isValidElement(e)),[t]),h=m.length,g=m.slice(0,r),p=Math.max(0,h-r),b=p>0,v=-d.space[SPACING_OFFSET[s]],f=d.colors.surface,y=i??u.groupOf(h),A=useMemo(()=>resolveSize(o),[o]),x=Math.max(d.text.xs.size,Math.round(.34*A));return _jsxs(View,{style:[groupStyles.row,n],accessible:!0,accessibilityLabel:y,accessibilityRole:"summary",testID:l,children:[g.map((e,t)=>{const r=e.key??`avatar-${t}`,s=cloneElement(e,{size:o,labels:e.props.labels??c});return _jsx(AvatarGroupItem,{delay:50*t,marginLeft:0===t?0:v,borderColor:f,borderWidth:1.5,children:s},r)}),b?_jsx(AvatarGroupItem,{delay:50*g.length,marginLeft:0===g.length?0:v,borderColor:f,borderWidth:1.5,children:_jsx(View,{style:[groupStyles.overflow,{width:A,height:A,borderRadius:A/2,...smoothCorners,backgroundColor:d.colors["surface-disabled"]}],accessible:!0,accessibilityRole:"text",accessibilityLabel:"count"===a?u.moreCount(p):u.moreAvatars,children:_jsx(Text,{variant:"label",weight:"semibold",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{fontSize:x,lineHeight:Math.round(x*d.leading.body)},children:"count"===a?`+${p}`:"+"})})},"avatar-overflow"):null]})},groupStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},item:{...smoothCorners},overflow:{alignItems:"center",justifyContent:"center"}});export{Avatar,AvatarGroup};export default Avatar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveBadgeSize,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BADGE_LABELS=Object.freeze({indicator:"Notification indicator",unread:e=>`${e} unread`});const toneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors.primary,text:e.colors["on-primary"]};case"success":return{background:e.colors.success,text:e.colors["on-success"]};case"warning":return{background:e.colors.warning,text:e.colors["on-warning"]};case"info":return{background:e.colors.info,text:e.colors["on-info"]};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-body"]};default:return{background:e.colors.danger,text:e.colors["on-danger"]}}},softToneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors["primary-soft"],text:e.colors.primary};case"success":return{background:e.colors["success-soft"],text:e.colors.success};case"warning":return{background:e.colors["warning-soft"],text:e.colors.warning};case"info":return{background:e.colors["info-soft"],text:e.colors.info};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-muted"]};default:return{background:e.colors["danger-soft"],text:e.colors.danger}}},anchorPosition=(e,t)=>{const o=-t;switch(e){case"topLeft":return{top:o,left:o};case"bottomRight":return{bottom:o,right:o};case"bottomLeft":return{bottom:o,left:o};default:return{top:o,right:o}}},formatValue=(e,t)=>{if(null==e)return null;if("number"==typeof e)return e<=0?null:e>t?`${t}+`:String(e);const o=String(e);return 0===o.length?null:o},
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveBadgeSize,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BADGE_LABELS=Object.freeze({indicator:"Notification indicator",unread:e=>`${e} unread`});const toneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors.primary,text:e.colors["on-primary"]};case"success":return{background:e.colors.success,text:e.colors["on-success"]};case"warning":return{background:e.colors.warning,text:e.colors["on-warning"]};case"info":return{background:e.colors.info,text:e.colors["on-info"]};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-body"]};default:return{background:e.colors.danger,text:e.colors["on-danger"]}}},softToneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors["primary-soft"],text:e.colors.primary};case"success":return{background:e.colors["success-soft"],text:e.colors.success};case"warning":return{background:e.colors["warning-soft"],text:e.colors.warning};case"info":return{background:e.colors["info-soft"],text:e.colors.info};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-muted"]};default:return{background:e.colors["danger-soft"],text:e.colors.danger}}},anchorPosition=(e,t)=>{const o=-t;switch(e){case"topLeft":return{top:o,left:o};case"bottomRight":return{bottom:o,right:o};case"bottomLeft":return{bottom:o,left:o};default:return{top:o,right:o}}},formatValue=(e,t)=>{if(null==e)return null;if("number"==typeof e)return e<=0?null:e>t?`${t}+`:String(e);const o=String(e);return 0===o.length?null:o},BadgeRoot=forwardRef((e,t)=>{const{value:o,max:r=99,variant:i="standard",tone:s="danger",size:n="sm",fill:a="solid",accessible:l=!0,invisible:d=!1,loading:c=!1,children:u,anchor:g="topRight",pulse:m=!1,accessibilityLabel:h,labels:f,style:b,badgeStyle:p,textStyle:x,testID:y}=e;assertValidValue("Badge","variant",e.variant,["standard","dot"]),assertValidValue("Badge","tone",e.tone,["primary","success","warning","danger","neutral","info"]),assertValidValue("Badge","size",e.size,["sm","md"]),assertValidValue("Badge","anchor",e.anchor,["topRight","topLeft","bottomRight","bottomLeft"]),assertValidValue("Badge","fill",e.fill,["solid","soft"]);const v=useMemo(()=>({...DEFAULT_BADGE_LABELS,...f}),[f]),w=useTheme(),V=useMemo(()=>"soft"===a?softToneFor(w,s):toneFor(w,s),[w,s,a]),S=resolveBadgeSize(w,n),k=w.components.badge["border-width"],j=w.components.badge["anchor-offset"],B="dot"===i?null:formatValue(o,r),z=!d&&("dot"===i||null!==B),A=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!m||!z)return void setNativeValue(A,1);const e=Animated.loop(Animated.sequence([Animated.timing(A,{toValue:1.15,duration:w.motion.duration.slow,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver}),Animated.timing(A,{toValue:1,duration:w.motion.duration.slow,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver})]));return e.start(),()=>{e.stop()}},[m,z,A,w]);const _="dot"===i,L=_?"image":"text",D=h??(_?v.indicator:B?v.unread(B):void 0),R=z?_jsx(Animated.View,{style:[styles.badge,_?{width:S["dot-size"],height:S["dot-size"],borderRadius:S["dot-size"]/2,...smoothCorners,paddingHorizontal:0}:{minWidth:S["min-width"],minHeight:S.height,borderRadius:w.radius.pill,...smoothCorners,paddingHorizontal:S["padding-x"]},{backgroundColor:V.background,transform:[{scale:A}]},u?{position:"absolute",borderWidth:k,borderColor:w.colors.surface,...anchorPosition(g,j)}:null,p],accessible:l,importantForAccessibility:l?void 0:"no-hide-descendants",accessibilityElementsHidden:!l||void 0,accessibilityRole:l?L:void 0,accessibilityLabel:l?D:void 0,children:_||null===B?null:_jsx(Text,{variant:"caption",weight:"soft"===a?"semibold":"bold",numberOfLines:1,style:[styles.text,{color:V.text,fontSize:S.text,lineHeight:Math.round(S.text*w.leading.body)},x],children:B??" "})}):null,E=u?_jsxs(View,{ref:t,style:[styles.wrapper,b],testID:y,children:[u,R]}):_jsx(View,{ref:t,style:b,testID:y,children:R});return c?_jsx(BadgeSkeleton,{...e}):E}),BadgeSkeleton=({variant:e="standard",size:t="md",children:o,anchor:r,style:i,badgeStyle:s})=>{const n=useTheme(),a=resolveBadgeSize(n,t);if("dot"===e)return _jsx(Skeleton,{shape:"circle",width:a["dot-size"],height:a["dot-size"],style:[s,i]});const l=a.height/2;if(void 0!==o){const e="topLeft"===r?{top:-a.height/2,left:-a.height/2}:"bottomRight"===r?{bottom:-a.height/2,right:-a.height/2}:"bottomLeft"===r?{bottom:-a.height/2,left:-a.height/2}:{top:-a.height/2,right:-a.height/2};return _jsxs(View,{style:[styles.wrapper,i],children:[o,_jsx(View,{style:[{position:"absolute"},e],children:_jsx(Skeleton,{width:a["min-width"]+a["padding-x"],height:a.height,radius:l,style:s})})]})}return _jsx(Skeleton,{width:a["min-width"]+a["padding-x"],height:a.height,radius:l,style:[s,i]})};BadgeSkeleton.displayName="BadgeSkeleton";const Badge=Object.assign(BadgeRoot,{Skeleton:BadgeSkeleton});Badge.displayName="Badge";const styles=StyleSheet.create({wrapper:{position:"relative",alignSelf:"flex-start"},badge:{alignItems:"center",justifyContent:"center",flexDirection:"row"},text:{textAlign:"center",includeFontPadding:!1}});export{Badge};export default Badge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{IconBadge}from"../IconBadge/index.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BANNER_LABELS=Object.freeze({dismiss:"Dismiss banner"});const
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{IconBadge}from"../IconBadge/index.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BANNER_LABELS=Object.freeze({dismiss:"Dismiss banner"});const BannerRoot=forwardRef((e,t)=>{const{title:r,message:o,tone:s="neutral",variant:n="bar",icon:i,actions:a,dismissible:l=!1,onClose:c,haptic:d,open:u=!0,animateMount:m=!0,loading:p=!1,accessibilityRole:g="alert",accessibilityLabel:h,labels:y,style:b,containerStyle:x,iconCircleStyle:f,tintBarStyle:w,closeButtonStyle:j,actionButtonStyle:S,testID:v}=e;assertValidValue("Banner","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","variant",e.variant,["bar","wash","tint"]),assertValidValue("Banner","accessibilityRole",e.accessibilityRole,["alert","summary","none"]);const B=useTheme(),V=usePresenceMotion(),k=useMemo(()=>buildStyles(B),[B]),C=useMemo(()=>tintFor(B,s),[B,s]),_=useMemo(()=>({...DEFAULT_BANNER_LABELS,...y}),[y]),[R,I]=V.range(-20,0),D=useRef(createAnimatedValue(m&&u?R:0)).current,A=useRef(createAnimatedValue(m&&u?0:u?1:0)).current,[T,L]=useState(u),H=useRef(!0);if(useEffect(()=>{if(H.current&&(H.current=!1,!m))return;let e;return u?(L(!0),e=Animated.parallel([Animated.timing(D,{toValue:I,duration:B.motion.duration.default,useNativeDriver:nativeDriver}),Animated.timing(A,{toValue:1,duration:V.duration("default"),useNativeDriver:nativeDriver})]),e.start()):T&&(e=Animated.parallel([Animated.timing(D,{toValue:R,duration:B.motion.duration.fast,useNativeDriver:nativeDriver}),Animated.timing(A,{toValue:0,duration:V.duration("fast"),useNativeDriver:nativeDriver})]),e.start(()=>{L(!1)})),()=>e?.stop()},[u]),!T)return null;const E=r??" ",M="string"==typeof o?o??" ":"",N="wash"===n,z="bar"!==n,P="alert"===g?"danger"===s?"assertive":"polite":"none",W=_jsxs(Animated.View,{ref:t,accessibilityRole:g,accessibilityLiveRegion:P,accessibilityLabel:h,testID:v,style:[k.container,{backgroundColor:z?C.soft:B.colors["bg-subtle"],borderRadius:N?B.radius.sm:B.radius.md,...smoothCorners,padding:B.space.md,opacity:A,transform:[{translateY:D}]},x,b],children:[!N&&B.components.banner["tint-bar-width"]>0?_jsx(View,{style:[k.tintBar,{backgroundColor:C.bar},w]}):null,_jsxs(View,{style:[k.row,void 0===r&&k.rowCentred],children:[!1===i?null:i?_jsx(View,{style:k.iconWrap,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(i,{color:C.ink,size:B.text.xl.size,disabled:!1})}):_jsx(IconBadge,{dimension:ICON_CIRCLE_SIZE,color:C.bar,icon:_jsx(Text,{variant:"body",weight:"bold",accessible:!1,style:[k.iconGlyph,{color:C.ink}],children:C.glyph}),style:[k.iconCircle,f]}),_jsxs(View,{style:k.textBlock,children:[r||p?_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:2,style:{lineHeight:20,...N?{color:C.ink}:null},children:E}):null,"string"==typeof o||p?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{lineHeight:18,marginTop:r?B.space.xxs:0},children:M||" "}):_jsx(View,{style:{marginTop:r?B.space.xxs:0},children:o})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:_.dismiss,onPress:()=>{const e=resolveHaptic(d,"selection");e&&triggerHaptic(e),c?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[k.closeBtn,{backgroundColor:e?B.colors["surface-pressed"]:"transparent"},j],children:_jsx(Text,{variant:"title",weight:"bold",color:"secondary",accessible:!1,style:{lineHeight:17},children:"×"})}):null]}),a&&a.length>0?_jsx(View,{style:k.actionsRow,children:a.map((e,t)=>{assertValidValue("Banner","action.tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","action.variant",e.variant,["solid","outline","ghost"]),assertValidValue("Banner","action.size",e.size,["sm","md"]);const r=e.tone??"primary",o=e.variant??"ghost",s="primary"===r?C.glyphColor:"neutral"===r?B.colors["text-muted"]:B.colors[r],n="primary"===r?C.ink:"neutral"===r?B.colors["text-muted"]:B.colors[`${r}-text`],i="primary"===r?C.on:"neutral"===r?B.colors["on-neutral-strong"]:B.colors[`on-${r}`],a="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,testID:e.testID,onPress:()=>{const t=resolveHaptic(d,"selection");t&&triggerHaptic(t),e.onPress()},style:({pressed:t})=>[k.actionBtn,"md"===e.size&&k.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:n},{backgroundColor:a?s:t?B.colors["surface-pressed"]:"transparent",opacity:a&&t?.85:1},S],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:a?i:n},children:e.label})},`${e.label}-${t}`)})}):null]});return p?_jsx(BannerSkeleton,{...e}):W}),BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:o,style:s})=>{const n=useTheme(),i=!1!==r;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:n.colors.surface,borderRadius:n.radius.md,...smoothCorners,padding:n.space.md,borderWidth:1,borderColor:n.colors.border},o,s],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[i?_jsx(View,{style:{marginRight:n.space.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:n.space.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:n.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:n.space.sm},children:t.map((e,t)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:n.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton";const Banner=Object.assign(BannerRoot,{Skeleton:BannerSkeleton});Banner.displayName="Banner";const tintFor=(e,t)=>{switch(t){case"success":return{soft:e.colors["success-soft"],bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{soft:e.colors["warning-soft"],bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{soft:e.colors["danger-soft"],bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{soft:e.colors["bg-subtle"],bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};case"primary":return{soft:e.colors["primary-soft"],bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"};case"info":return{soft:e.colors["info-soft"],bar:e.colors.info,glyphColor:e.colors.info,ink:e.colors["info-text"],on:e.colors["on-info"],glyph:"i"};default:return tintFor(e,"neutral")}},ICON_CIRCLE_SIZE=28,buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},rowCentred:{alignItems:"center"},iconWrap:{marginRight:r},iconCircle:{marginRight:r},iconGlyph:{lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{
|
|
1
|
+
"use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{barScale}from"./scale.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`});const AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>formatNumber(e),defaultFormatTick=e=>formatCompactNumber(e),BarChart=forwardRef((e,t)=>{const{data:r,tone:s="primary",color:a,series:o,height:i=160,label:l,summary:n,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:m,selection:h,defaultSelection:d=null,onSelect:p,haptic:x,labels:f,style:y,testID:b}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const g=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...f}),[f]),_=useTheme(),A=r.length,[C,S]=useState(0),[j,w]=useControllableState({value:h,defaultValue:d,onChange:p}),M=null!==j&&j>=0&&j<A?j:null,T=useRef(M);T.current=M;const v=useRef(-1),R=resolveHaptic(x,"tick"),V=useCallback(()=>{R&&triggerHaptic(R)},[R]),L=m??(A>0&&A<=7),D=void 0!==o&&o.length>0,$=useMemo(()=>D?o.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[D,o]),k=useMemo(()=>D?o.map(e=>e.key):[],[D,o]),I=useMemo(()=>D?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,D]),B=useMemo(()=>I?I.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,I]),E=useMemo(()=>I?I.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):B,[I,B]),H=useMemo(()=>barScale(E),[E]),O=L?20:6,F=L&&H.min<0?20:6,N=Math.max(1,i-O-F),G=useCallback(e=>O+(H.max-e)/(H.max-H.min)*N,[O,H.max,H.min,N]),W=G(0),U=useMemo(()=>H.ticks.map(e=>u(e)),[H.ticks,u]),z=Math.ceil(8*Math.max(...U.map(e=>e.length),1)*1.2)+_.space.xs,P=A>0?C/A:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useCallback(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(I&&o){const r=entryAt(I,e);return`${t.label}, ${o.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt(B,e))}`},[r,c,B,I,o]),J=useMemo(()=>{let e=-1,t=0;for(const[r,s]of B.entries())(-1===e||s>t)&&(e=r,t=s);return e},[B]),Y=n??(J>=0?g.highest(entryAt(r,J).label,c(entryAt(B,J))):""),Z=useRef({fire:V,setSelected:w,count:A,plotWidth:C});Z.current={fire:V,setSelected:w,count:A,plotWidth:C};const q=useCallback(e=>{const{count:t,plotWidth:r}=Z.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},[]),Q=useCallback(e=>{const t=q(e);t<0||t===v.current||(v.current=t,Z.current.fire(),Z.current.setSelected(t))},[q]),ee=useMemo(()=>({runOnJS:!0,activeOffsetX:[-8,8],failOffsetY:[-12,12],onActivate:e=>{v.current=T.current??-1,Q(e.x)},onUpdate:e=>Q(e.x),testID:b?`${b}-pan`:"bar-chart-pan"}),[Q,b]),te=usePanGesture(ee),re=useMemo(()=>({runOnJS:!0,onDeactivate:e=>{if(e.canceled)return;const t=q(e.x);t<0||(Z.current.fire(),v.current=t,Z.current.setSelected(t===T.current?null:t))},testID:b?`${b}-tap`:"bar-chart-tap"}),[q,b]),se=useTapGesture(re),ae=useCompetingGestures(te,se),oe=useCallback(e=>{if(0===A)return;const t=T.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(A-1,t+1):null===t?A-1:Math.max(0,t-1);r!==t&&(V(),w(r))},[A,V,w]),ie=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);S(e=>e===t?e:t)},[]),le=a??toneColor(_,s),ne=_.radius.sm,ce=l??g.chart,ue=0===A?`${ce}, ${g.noData}`:Y?`${ce}, ${Y}`:ce,me=null===M?Y:K(M),he=Math.min(40,Math.max(4,.6*P)),renderStack=(e,t,r)=>{const s=e.reduce((e,t)=>t>0?e+t:e,0),a=e.reduce((e,t)=>t<0?e+t:e,0);if(0===s&&0===a)return null;const o=G(s),i=[];let l=0,n=0;return e.forEach((e,r)=>{if(0===e)return;const s=e>0?l:n,a=s+e;e>0?l=a:n=a;const c=G(s),u=G(a);i.push(_jsx(View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-o,height:Math.abs(c-u),backgroundColor:toneColor(_,entryAt($,r))}},entryAt(k,r)))}),_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:o,width:he,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:null,...a<0?{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}:null},children:i})},de=B.map((e,t)=>{const r=G(e),s=e>=0?r:W,a=0===e?0:Math.max(2,Math.abs(r-W)),o=null!==M&&M!==t;return _jsxs(View,{style:[styles.slot,{height:i}],children:[C>0&&I?renderStack(entryAt(I,t),t,o):null,C>0&&!I&&a>0?_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:s,width:he,height:a,backgroundColor:le,opacity:o?.4:1,...smoothCorners,...e>=0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}}}):null,L&&C>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(I?G(entryAt(E,2*t)):r)-20+2:(I?G(entryAt(E,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===A?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ue,testID:b,style:[styles.root,y],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ue,accessibilityValue:{min:0,max:A-1,now:M??0,text:me},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:oe,testID:b,style:[styles.root,y],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:_.space.sm}],children:null===M?Y?_jsx(Text,{variant:"bodySmall",color:"secondary",children:Y}):null:_jsxs(_Fragment,{children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,M).label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt(B,M))})]})}),_jsxs(View,{style:styles.body,children:[_jsx(View,{style:{width:z,height:i},children:H.ticks.map((e,t)=>_jsx(Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:_.space.xs,left:0,top:G(e)-8},children:entryAt(U,t)},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:ae,children:_jsxs(View,{style:{height:i},onLayout:ie,testID:b?`${b}-plot`:void 0,children:[H.ticks.map(e=>_jsx(View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:StyleSheet.hairlineWidth),height:0===e?1.5:2*StyleSheet.hairlineWidth,backgroundColor:0===e?_.colors["text-subtle"]:_.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:de})]})}),_jsx(View,{style:styles.axis,children:r.map((e,t)=>_jsx(View,{style:styles.axisSlot,children:t%X===0?_jsx(Text,{variant:"caption",color:M===t?"primary":"tertiary",weight:M===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:P>0?{width:P*X}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),o&&D?_jsx(View,{style:[styles.legend,{marginTop:_.space.sm,columnGap:_.space.md,rowGap:_.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:_.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:_.radius.sm,...smoothCorners,backgroundColor:toneColor(_,entryAt($,t))}}),_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});export{BarChart};export default BarChart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:v,indicatorStyle:w,labelStyle:A,labelMaxFontScale:E,labels:I,testID:R}=e;assertValidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),assertValidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>I?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...I}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[I]),V=useTheme(),j=useSafeAreaInsets(),L=useMemo(()=>buildStyles(V),[V]),B=m??18,D=B+4+8,C=V.space.lg,M=V.space.lg,k=V.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+V.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-C,64):0,ve=ge>0?(ge-Se)/2:0,we=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:V.space.xs+(B+4)/2,Ie=Ee-14-24,Re=Math.max(0,ae-4),Te=K?2:Ee-D/2,Ve=useRef(ie);useEffect(()=>{if(Ve.current===ie)return;Ve.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Le=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),De=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?De?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,De]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:nativeDriver}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:nativeDriver})]).start()},Ce=useRef(new Animated.Value(1)).current,{colors:Me}=V,ke=ee?Me.primary:Me.surface,Ne=ee?Me["on-primary"]:Me.primary,Pe=ee?Me["on-primary"]:K?Me["text-body"]:Me["text-subtle"],ze=ee?Me["on-primary"]:Me["primary-soft"],Fe=ee?Me.primary:J?Me["on-primary"]:Ne,He=h??M,Oe=g??(q?M:0),We=Oe>0,Ue=f??V.space.sm,$e=b??(q?V.space.sm:V.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+V.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:V.radius.pill:c??(K?V.radius.pill:q?k:V.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:V.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?Me.primary:Me.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[L.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Ce),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(R?`${R}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:n.content}):_jsx(View,{style:[L.centerCircle,{width:ue,height:ue,borderRadius:V.radius.pill,...smoothCorners,backgroundColor:n.color??Me.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??Me["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&<.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?L.accessoryInline:L.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:R?`${R}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[L.tabRow,L.tabRowInline]:L.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||Re>0)?_jsx(Animated.View,{pointerEvents:"none",style:[L.pill,{width:Se,height:K?Re:D,left:ve,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(Re,Re/2):activeBgRadius(D,V.radius.pill),...smoothCorners,transform:[{translateX:Le}]},w]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.bubble,V.shadow.elevated,{width:48,height:48,borderRadius:V.radius.pill,...smoothCorners,left:we,top:Ie,backgroundColor:Me.primary,borderColor:Me.surface,transform:[{translateX:Le}]},w]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key];if(void 0===d||void 0===c)throw new Error(`BottomNavigation has no animation values for tab "${e.key}".`);const u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?Me.primary:Me.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[L.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1})}),u?_jsx(Badge,{variant:u,value:"standard"===u?e.badge:void 0,tone:"danger",accessible:!1,style:"dot"===u?L.badgeDotPosition:L.badgePillPosition,badgeStyle:["dot"===u?L.badgeDot:L.badgePill,{borderColor:h}],textStyle:L.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,Q?L.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?V.weight.semibold:V.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.tab,K?L.tabTile:null,e?{opacity:.85}:null],testID:R?`${R}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[L.expandPill,{height:D,paddingHorizontal:t&&g?V.space.md:Math.max(0,(D-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[L.expandFill,{borderRadius:activeBgRadius(D,D/2),...smoothCorners,backgroundColor:t?Me["primary-soft"]:"transparent"},t?w:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.underline,"top"===d?L.underlineTop:L.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:Me.primary,transform:[{translateX:Le}]},w]}):null]});var ut;return _jsx(View,{ref:t,testID:R,accessibilityRole:"tablist",style:[L.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},v],children:_jsxs(View,{style:[q?L.floatingBar:L.dockedBar,X?L.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:13}});export{BottomNavigation};export default BottomNavigation;
|
|
1
|
+
"use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:v,indicatorStyle:w,labelStyle:A,labelMaxFontScale:E,labels:I,testID:R}=e;assertValidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),assertValidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>I?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...I}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[I]),V=useTheme(),j=useSafeAreaInsets(),L=useMemo(()=>buildStyles(V),[V]),B=m??18,D=B+4+8,C=V.space.lg,M=V.space.lg,k=V.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+V.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-C,64):0,ve=ge>0?(ge-Se)/2:0,we=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:V.space.xs+(B+4)/2,Ie=Ee-14-24,Re=Math.max(0,ae-4),Te=K?2:Ee-D/2,Ve=useRef(ie);useEffect(()=>{if(Ve.current===ie)return;Ve.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Le=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),De=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?De?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,De]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:nativeDriver}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:nativeDriver})]).start()},Ce=useRef(new Animated.Value(1)).current,{colors:Me}=V,ke=ee?Me.primary:Me.surface,Ne=ee?Me["on-primary"]:Me.primary,Pe=ee?Me["on-primary"]:K?Me["text-body"]:Me["text-subtle"],ze=ee?Me["on-primary"]:Me["primary-soft"],Fe=ee?Me.primary:J?Me["on-primary"]:Ne,He=h??M,Oe=g??(q?M:0),We=Oe>0,Ue=f??V.space.sm,$e=b??(q?V.space.sm:V.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+V.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:V.radius.pill:c??(K?V.radius.pill:q?k:V.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:V.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?Me.primary:Me.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[L.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Ce),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(R?`${R}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:n.content}):_jsx(View,{style:[L.centerCircle,{width:ue,height:ue,borderRadius:V.radius.pill,...smoothCorners,backgroundColor:n.color??Me.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??Me["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&<.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?L.accessoryInline:L.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:R?`${R}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[L.tabRow,L.tabRowInline]:L.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||Re>0)?_jsx(Animated.View,{pointerEvents:"none",style:[L.pill,{width:Se,height:K?Re:D,left:ve,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(Re,Re/2):activeBgRadius(D,V.radius.pill),...smoothCorners,transform:[{translateX:Le}]},w]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.bubble,V.shadow.elevated,{width:48,height:48,borderRadius:V.radius.pill,...smoothCorners,left:we,top:Ie,backgroundColor:Me.primary,borderColor:Me.surface,transform:[{translateX:Le}]},w]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key];if(void 0===d||void 0===c)throw new Error(`BottomNavigation has no animation values for tab "${e.key}".`);const u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?Me.primary:Me.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[L.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1})}),u?_jsx(Badge,{variant:u,value:"standard"!==u||"number"!=typeof e.badge&&"string"!=typeof e.badge?void 0:e.badge,tone:"danger",accessible:!1,style:"dot"===u?L.badgeDotPosition:L.badgePillPosition,badgeStyle:["dot"===u?L.badgeDot:L.badgePill,{borderColor:h}],textStyle:L.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,Q?L.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?V.weight.semibold:V.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.tab,K?L.tabTile:null,e?{opacity:.85}:null],testID:R?`${R}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[L.expandPill,{height:D,paddingHorizontal:t&&g?V.space.md:Math.max(0,(D-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[L.expandFill,{borderRadius:activeBgRadius(D,D/2),...smoothCorners,backgroundColor:t?Me["primary-soft"]:"transparent"},t?w:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.underline,"top"===d?L.underlineTop:L.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:Me.primary,transform:[{translateX:Le}]},w]}):null]});var ut;return _jsx(View,{ref:t,testID:R,accessibilityRole:"tablist",style:[L.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},v],children:_jsxs(View,{style:[q?L.floatingBar:L.dockedBar,X?L.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:13}});export{BottomNavigation};export default BottomNavigation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:b,onScrollLayout:p,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:E,actions:M,actionsLayout:O="auto",footer:T,headerStyle:k,footerStyle:R,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=E||null!=d,L=null!=M&&M.length>0,P=null!=T||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),b?.(e,t)},[te,b,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,be=fe[fe.length-1]??0,pe=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Ee,Me]=useState(!1),[Oe,Te]=useState(!1),ke=useRef(!1),Re=useRef(i);Re.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Oe:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(ke.current=!0,"modal"===N?(Me(!1),"ios"!==Platform.OS&&Te(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{ke.current&&Te(!1)},[]);useEffect(()=>{("modal"===N?!Oe:!Ae)&&ke.current&&(ke.current=!1,Re.current?.(),Ge(!0))},[N,Oe,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),pe.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,pe,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return ke.current=!1,Ge(!1),"modal"===N?(Te(!0),Me(!0)):Ie(!0),o<0&&je.current?(pe.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(pe.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(pe.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,pe,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:pe,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,pe,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);pe.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-be,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>Gesture.Native().withTestId(V?`${V}-content-gesture`:"bottom-sheet-content-gesture"),[V]),at=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return Gesture.Pan().withTestId(V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";ve.value=pe.value}).onUpdate(e=>{"worklet";const t=ve.value+e.translationY;pe.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=pe.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)})},[Se,ve,l,nt,tt,ot,V,pe]),{height:it}=useReanimatedKeyboardAnimation(),lt="shift"===y,ut=useDerivedValue(()=>lt?it.value:0,[lt,it]),ct=fe[we>=0?we:0]??be,dt=H.space.md,ht=useAnimatedStyle(()=>{if(W){const e=ut.value,t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=pe.value+ut.value,t=ut.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,ut,U,ct,dt,pe,Z,ye,tt]),mt=useAnimatedStyle(()=>{const e=ut.value;if(W){const t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value,s=U+e-dt-(o<Z?Z:o);return{height:s<0?0:s>ct?ct:s}}const t=e<0?Z:tt,o=pe.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>be?be:s}},[ut,W,U,ct,dt,pe,Z,tt,be]),ft=we>=0,St=useMemo(()=>buildStyles(H),[H]),bt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),pt=useMemo(()=>Gesture.Tap().withTestId(V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(bt)()}),[bt,V]),vt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Oe)return null;const yt=_jsxs(View,{collapsable:!1,style:["modal"===N?St.backdropModal:St.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??ft,children:[_jsx(GestureDetector,{gesture:pt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??ft,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[St.sheet,{height:be,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ct,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ht],children:_jsxs(SheetBody,{style:[St.body,mt],keyboardOffset:ut,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:at,children:_jsx(View,{style:St.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[St.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[St.header,k],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,E]}),m?_jsx(GestureDetector,{gesture:rt,children:_jsx(ScrollView,{ref:f,style:St.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:p,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[St.content,{overflow:"visible"}]:St.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[St.footer,R],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:St.actions,children:_jsx(OverlayActions,{actions:M??[],layout:O})}):null,T]})]})})]}),gt=_jsx(BottomSheetContext.Provider,{value:vt,children:yt});return"modal"===N?_jsx(Modal,{open:Ee,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:St.modalRoot,children:gt}):gt}):gt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
|
|
1
|
+
"use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:p,onScrollLayout:b,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:M,actions:O,actionsLayout:E="auto",footer:k,headerStyle:R,footerStyle:T,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=M||null!=d,L=null!=O&&O.length>0,P=null!=k||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),p?.(e,t)},[te,p,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,pe=fe[fe.length-1]??0,be=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Me,Oe]=useState(!1),[Ee,ke]=useState(!1),Re=useRef(!1),Te=useRef(i);Te.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Ee:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(Re.current=!0,"modal"===N?(Oe(!1),"ios"!==Platform.OS&&ke(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{Re.current&&ke(!1)},[]);useEffect(()=>{("modal"===N?!Ee:!Ae)&&Re.current&&(Re.current=!1,Te.current?.(),Ge(!0))},[N,Ee,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),be.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,be,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return Re.current=!1,Ge(!1),"modal"===N?(ke(!0),Oe(!0)):Ie(!0),o<0&&je.current?(be.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(be.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(be.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,be,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:be,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,be,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);be.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-pe,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>({testID:V?`${V}-content-gesture`:"bottom-sheet-content-gesture"}),[V]),at=useNativeGesture(rt),it=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return{testID:V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";ve.value=be.value},onUpdate:e=>{"worklet";const t=ve.value+e.translationY;be.value=t<o?o+.25*(t-o):t},onDeactivate:o=>{"worklet";const n=be.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)}}},[Se,ve,l,nt,tt,ot,V,be]),lt=usePanGesture(it),{height:ut}=useReanimatedKeyboardAnimation(),ct="shift"===y,dt=useDerivedValue(()=>ct?ut.value:0,[ct,ut]),ht=fe[we>=0?we:0]??pe,mt=H.space.md,ft=useAnimatedStyle(()=>{if(W){const e=dt.value,t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=be.value+dt.value,t=dt.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,dt,U,ht,mt,be,Z,ye,tt]),St=useAnimatedStyle(()=>{const e=dt.value;if(W){const t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value,s=U+e-mt-(o<Z?Z:o);return{height:s<0?0:s>ht?ht:s}}const t=e<0?Z:tt,o=be.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>pe?pe:s}},[dt,W,U,ht,mt,be,Z,tt,pe]),pt=we>=0,bt=useMemo(()=>buildStyles(H),[H]),vt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),yt=useMemo(()=>({testID:V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||runOnJS(vt)()}}),[vt,V]),gt=useTapGesture(yt),wt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Ee)return null;const Ct=_jsxs(View,{collapsable:!1,style:["modal"===N?bt.backdropModal:bt.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??pt,children:[_jsx(GestureDetector,{gesture:gt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??pt,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[bt.sheet,{height:pe,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ht,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ft],children:_jsxs(SheetBody,{style:[bt.body,St],keyboardOffset:dt,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:lt,children:_jsx(View,{style:bt.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[bt.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[bt.header,R],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),m?_jsx(GestureDetector,{gesture:at,children:_jsx(ScrollView,{ref:f,style:bt.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:b,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[bt.content,{overflow:"visible"}]:bt.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[bt.footer,T],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:bt.actions,children:_jsx(OverlayActions,{actions:O??[],layout:E})}):null,k]})]})})]}),xt=_jsx(BottomSheetContext.Provider,{value:wt,children:Ct});return"modal"===N?_jsx(Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:bt.modalRoot,children:xt}):xt}):xt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{radiusOf,spaceOf}from"../../theme/scale.js";import{smoothCorners}from"../../utils/corners.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],space=(e
|
|
1
|
+
"use strict";import{forwardRef}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{radiusOf,spaceOf}from"../../theme/scale.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],space=(r,e)=>null==e?void 0:spaceOf(r,e);export const resolveBoxStyle=(r,e)=>({...null!=e.p?{padding:space(r,e.p)}:{},...null!=e.px?{paddingHorizontal:space(r,e.px)}:{},...null!=e.py?{paddingVertical:space(r,e.py)}:{},...null!=e.pt?{paddingTop:space(r,e.pt)}:{},...null!=e.pr?{paddingRight:space(r,e.pr)}:{},...null!=e.pb?{paddingBottom:space(r,e.pb)}:{},...null!=e.pl?{paddingLeft:space(r,e.pl)}:{},...null!=e.m?{margin:space(r,e.m)}:{},...null!=e.mx?{marginHorizontal:space(r,e.mx)}:{},...null!=e.my?{marginVertical:space(r,e.my)}:{},...null!=e.mt?{marginTop:space(r,e.mt)}:{},...null!=e.mr?{marginRight:space(r,e.mr)}:{},...null!=e.mb?{marginBottom:space(r,e.mb)}:{},...null!=e.ml?{marginLeft:space(r,e.ml)}:{},...null!=e.gap?{gap:space(r,e.gap)}:{},...null!=e.bg?{backgroundColor:isOneOf(BACKGROUND_TOKENS,e.bg)?r.colors[e.bg]:e.bg}:{},...null!=e.radius?{borderRadius:radiusOf(r,e.radius),borderCurve:smoothCorners.borderCurve}:{},...e.border?{borderWidth:r.size.border,borderColor:r.colors.border}:{},...null!=e.flex?{flex:e.flex}:{},...null!=e.align?{alignItems:e.align}:{},...null!=e.justify?{justifyContent:e.justify}:{},...null!=e.direction?{flexDirection:e.direction}:{},...e.wrap?{flexWrap:"wrap"}:{}});const Box=forwardRef((r,e)=>{const o=useTheme(),{p:l,px:t,py:i,pt:s,pr:a,pb:n,pl:p,m:u,mx:d,my:m,mt:c,mr:g,mb:f,ml:b,gap:x,bg:y,radius:h,border:j,flex:w,align:S,justify:C,direction:R,wrap:B,style:O,children:k,...v}=r,_=resolveBoxStyle(o,{p:l,px:t,py:i,pt:s,pr:a,pb:n,pl:p,m:u,mx:d,my:m,mt:c,mr:g,mb:f,ml:b,gap:x,bg:y,radius:h,border:j,flex:w,align:S,justify:C,direction:R,wrap:B}),N="number"==typeof _.borderRadius?_.borderRadius:0,z="string"==typeof _.backgroundColor?_.backgroundColor:"transparent",T="string"==typeof _.borderColor?_.borderColor:void 0,q="number"==typeof _.borderWidth?_.borderWidth:0,D=useSquircle(null!=h&&(null!=y||Boolean(j)),N,v.onLayout),V=D.active?{..._,backgroundColor:"transparent",borderColor:"transparent"}:_;return _jsxs(View,{ref:e,...v,onLayout:D.onLayout,style:[V,O],children:[D.active&&D.size?_jsx(SquircleFill,{width:D.size.width,height:D.size.height,radius:N,fill:z,stroke:T,strokeWidth:q}):null,k]})});Box.displayName="Box";const Stack=forwardRef(({gap:r="md",...e},o)=>_jsx(Box,{ref:o,direction:"column",gap:r,...e}));Stack.displayName="Stack";const Row=forwardRef(({gap:r="sm",align:e="center",...o},l)=>_jsx(Box,{ref:l,direction:"row",gap:r,align:e,...o}));Row.displayName="Row";const Spacer=({size:r,style:e,testID:o})=>{const l=useTheme();if(null!=r){const t=spaceOf(l,r);return _jsx(View,{testID:o,style:[{width:t,height:t},e]})}return _jsx(View,{testID:o,style:[{flex:1},e]})};Spacer.displayName="Spacer";export{Box,Row,Spacer,Stack};export default Box;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=React.memo(forwardRef((e,t)=>{const{children:i,variant:s,elevation:o="card",radius:a,padding:r,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:x=!1,onCollapsedChange:f,collapsedSummary:S,onRemove:j,separatorHeight:v=StyleSheet.hairlineWidth,footer:C,imageSource:_,imageHeight:w=160,imageAspectRatio:R,imageOverlay:A,loading:V=!1,gradient:F,onPress:T,haptic:k,contextMenu:B,accessibilityLabel:L,accessibilityHint:I,accessibilityRole:H,style:P,containerStyle:z,headerStyle:M,bodyStyle:D,footerStyle:E,testID:q,labels:O,onLayout:W,...N}=e;assertValidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),assertValidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),assertValidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),assertValidValue("Card","titleFont",e.titleFont,["sans","serif"]),assertValidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=s??U?.defaultVariant??"elevated",$=a??U?.defaultRadius??"lg",J=r??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...O}),[O]),Y=l||"function"==typeof T,Z=useContextMenu(B,{haptic:k||!1,testID:q,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:se,pressOut:oe}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),ae=stylesFor(G),re=Boolean(_),le=G.space[paddingMap[J]],ne=useMemo(()=>F?"string"==typeof F?G.settings.gradients[F]??null:F:null,[F,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:x,onChange:f}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!re&&!ne&&!de,ce,W),xe=StyleSheet.flatten([z,P])??{},fe=xe.backgroundColor,Se=xe.borderColor,je=fe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),ve="outline"===K?G.size.border:0,Ce=Se??G.colors.border,we="none"===o?void 0:G.shadow[o],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Ve=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Fe=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:re||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:v,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,re,le,ye.active,ye.size,Re,Ae,ue,v]),Te=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:w},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,w]),ke=u??"",Be=_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:ae.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:ae.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:k}):p?_jsx(View,{style:ae.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${ke}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:k}):null,j?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:j,color:G.colors["danger-text"],haptic:k}):null]}),Le=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[ae.header,!c&&ae.headerRow,pe&&ae.headerFolded,M],children:c??Be}):null,pe?null:_jsx(View,{style:[be||C?ae.body:null,D],children:i}),C&&!pe?_jsx(View,{style:[ae.footer,E],children:C}):null]}),Ie=re?_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.imageWrapper,children:[_jsx(Image,{source:_,resizeMode:"cover",style:Te,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:ae.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Le})]}):Le,He=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Ie]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:je,stroke:ve?Ce:void 0,strokeWidth:ve}),_jsx(View,{style:[ae.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Ie})]}):Ie;let Pe;if(te){const handlePress=e=>{Y&&(k&&triggerHaptic(k),T?.(e))};Pe=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:se,onPressOut:oe,accessibilityRole:H??(Y?"button":void 0),accessibilityLabel:L,accessibilityHint:I,testID:q,onLayout:ye.onLayout,style:[Fe,z,P,Ve],...N,...Z.hostProps,children:He})})}else Pe=_jsx(View,{ref:t,accessibilityLabel:L,accessibilityHint:I,accessibilityRole:H,testID:q,onLayout:ye.onLayout,style:[Fe,z,P,Ve],...N,children:He});return V?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[Pe,Z.renderSurface(_jsx(View,{style:[Fe,z,P,Ve,ae.preview],children:He}))]}):Pe}));Card.displayName="Card";const CardSkeleton=({variant:e,elevation:t,radius:i,padding:s,bg:o,header:a,footer:r,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),x=y.settings.components.card,f=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",j=s??x?.defaultPadding??"md",v={...DEFAULT_CARD_LABELS,...g},C=paddingMap[j],_=y.space[C],w="flat"===f?y.radius.none:y.radius[S],R=void 0!==a||hasBuiltInHeaderContent(b),A=resolveBackground(y,o)??y.colors.surface,V="outline"===f?1:0,F="outline"===f?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:w,...smoothCorners,borderWidth:V,borderColor:F,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:v.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:_,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:_},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==r?_jsx(View,{style:[{padding:_,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:s,color:o,haptic:a})=>{const r=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===s?void 0:{expanded:s},"aria-expanded":s,onPress:()=>{a&&triggerHaptic(a),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:o??r.colors["text-body"]})})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return BACKGROUND_TOKENS.includes(t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
|
|
1
|
+
"use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},CardRoot=React.memo(forwardRef((e,t)=>{const{children:i,variant:o,elevation:s="card",radius:r,padding:a,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:f=!1,onCollapsedChange:x,collapsedSummary:S,onRemove:j,separatorHeight:C=StyleSheet.hairlineWidth,footer:v,imageSource:_,imageHeight:w=160,imageAspectRatio:R,imageOverlay:A,loading:V=!1,gradient:F,onPress:k,haptic:T,contextMenu:B,accessibilityLabel:L,accessibilityHint:I,accessibilityRole:H,style:P,containerStyle:z,headerStyle:M,bodyStyle:O,footerStyle:D,testID:E,labels:q,onLayout:W,...N}=e;assertValidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),assertValidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),assertValidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),assertValidValue("Card","titleFont",e.titleFont,["sans","serif"]),assertValidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=o??U?.defaultVariant??"elevated",$=r??U?.defaultRadius??"lg",J=a??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...q}),[q]),Y=l||"function"==typeof k,Z=useContextMenu(B,{haptic:T||!1,testID:E,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:oe,pressOut:se}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),re=stylesFor(G),ae=Boolean(_),le=G.space[paddingMap[J]],ne=useMemo(()=>F?"string"==typeof F?G.settings.gradients[F]??null:F:null,[F,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:f,onChange:x}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!ae&&!ne&&!de,ce,W),fe=StyleSheet.flatten([z,P])??{},xe="string"==typeof fe.backgroundColor?fe.backgroundColor:void 0,Se="string"==typeof fe.borderColor?fe.borderColor:void 0,je=xe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),Ce="outline"===K?G.size.border:0,ve=Se??G.colors.border,we="none"===s?void 0:G.shadow[s],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Ve=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Fe=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:ae||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:C,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,ae,le,ye.active,ye.size,Re,Ae,ue,C]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:w},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,w]),Te=u??"",Be=_jsxs(_Fragment,{children:[_jsxs(View,{style:re.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:re.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:re.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:T}):p?_jsx(View,{style:re.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${Te}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:T}):null,j?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:j,color:G.colors["danger-text"],haptic:T}):null]}),Le=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[re.header,!c&&re.headerRow,pe&&re.headerFolded,M],children:c??Be}):null,pe?null:_jsx(View,{style:[be||v?re.body:null,O],children:i}),v&&!pe?_jsx(View,{style:[re.footer,D],children:v}):null]}),Ie=_?_jsxs(_Fragment,{children:[_jsxs(View,{style:re.imageWrapper,children:[_jsx(Image,{source:_,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:re.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Le})]}):Le,He=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Ie]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:je,stroke:Ce?ve:void 0,strokeWidth:Ce}),_jsx(View,{style:[re.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Ie})]}):Ie;let Pe;if(te){const handlePress=e=>{Y&&(T&&triggerHaptic(T),k?.(e))};Pe=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:oe,onPressOut:se,accessibilityRole:H??(Y?"button":void 0),accessibilityLabel:L,accessibilityHint:I,testID:E,onLayout:ye.onLayout,style:[Fe,z,P,Ve],...N,...Z.hostProps,children:He})})}else Pe=_jsx(View,{ref:t,accessibilityLabel:L,accessibilityHint:I,accessibilityRole:H,testID:E,onLayout:ye.onLayout,style:[Fe,z,P,Ve],...N,children:He});return V?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[Pe,Z.renderSurface(_jsx(View,{style:[Fe,z,P,Ve,re.preview],children:He}))]}):Pe})),CardSkeleton=({variant:e,elevation:t,radius:i,padding:o,bg:s,header:r,footer:a,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),f=y.settings.components.card,x=e??f?.defaultVariant??"elevated",S=i??f?.defaultRadius??"lg",j=o??f?.defaultPadding??"md",C={...DEFAULT_CARD_LABELS,...g},v=paddingMap[j],_=y.space[v],w="flat"===x?y.radius.none:y.radius[S],R=void 0!==r||hasBuiltInHeaderContent(b),A=resolveBackground(y,s)??y.colors.surface,V="outline"===x?1:0,F="outline"===x?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:w,...smoothCorners,borderWidth:V,borderColor:F,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:C.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:_,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:_},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==a?_jsx(View,{style:[{padding:_,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton";const Card=Object.assign(CardRoot,{Skeleton:CardSkeleton});Card.displayName="Card";const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:o,color:s,haptic:r})=>{const a=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===o?void 0:{expanded:o},"aria-expanded":o,onPress:()=>{r&&triggerHaptic(r),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:s??a.colors["text-body"]})})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return isOneOf(BACKGROUND_TOKENS,t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,AppState,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CAROUSEL_LABELS=Object.freeze({carousel:"Carousel",slideOf:(e,t)=>`Slide ${e} of ${t}`,goToSlide:e=>`Go to slide ${e}`});function CarouselRoot({ref:e,...t}){const{data:n,renderItem:r,keyExtractor:i,index:s,defaultIndex:a=0,onIndexChange:l,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:b=0,containerStyle:p,accessibilityLabel:f,testID:y,showThumbnails:x=!1,haptic:S,renderThumbnail:v,loading:w=!1,labels:C}=t;assertValidValue("Carousel","paginationStyle",t.paginationStyle,["dots","bars","numbers"]);const T=useMemo(()=>({...DEFAULT_CAROUSEL_LABELS,...C}),[C]),j=useTheme(),I=d||c,[k,_]=useState(()=>Dimensions.get("window").width),A="screen"===g?k:g,E=A+b,R=useRef(null),V=useRef(createAnimatedValue(0)).current,L=clamp("number"==typeof s?s:a,0,Math.max(0,n.length-1)),[D,O]=useState(L),H=useRef(null),M=useRef(null),P=useRef(!1),z=useRef(D);z.current=D;const N=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));O(e=>e===t?e:(l?.(t),t))},[n.length,l]),W=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);R.current?.scrollToOffset({offset:r*E,animated:t}),N(r)},[n.length,E,N]),F=useCallback(()=>{if(0===n.length)return;const e=z.current+1;e>=n.length?I&&W(0,!1):W(e,!0)},[n.length,I,W]),$=useCallback(()=>{if(0===n.length)return;const e=z.current-1;e<0?I&&W(n.length-1,!1):W(e,!0)},[n.length,I,W]);useImperativeHandle(e,()=>({scrollTo:W,next:F,prev:$}),[W,F,$]),useEffect(()=>{"number"==typeof s&&s!==D&&W(s,!0)},[s]);const U=useCallback(()=>{H.current&&(clearInterval(H.current),H.current=null)},[]),B=useCallback(()=>{!c||n.length<=1||(U(),H.current=setInterval(()=>{if(P.current)return;const e=z.current+1;e>=n.length?W(0,!1):W(e,!0)},u))},[c,u,n.length,W,U]);useEffect(()=>(B(),()=>{U(),M.current&&clearTimeout(M.current)}),[B,U]),useEffect(()=>{const e=AppState.addEventListener("change",e=>{"active"!==e?(U(),M.current&&(clearTimeout(M.current),M.current=null)):B()});return()=>e.remove()},[B,U]);const G=m&&n.length>1&&"numbers"!==h||void 0!==o,K=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:V}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[V,o]),X=useCallback(e=>{if(E<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/E);N(n)},[E,N]),q=useCallback(()=>{P.current=!0,U(),M.current&&(clearTimeout(M.current),M.current=null)},[U]),J=useCallback(()=>{P.current=!1,c&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{B()},1e3))},[c,B]),Q=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":F();break;case"decrement":$()}},[F,$]),Y=useMemo(()=>buildStyles(j),[j]),Z=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:A,marginRight:t===n.length-1?0:b},accessibilityElementsHidden:t!==D,importantForAccessibility:t===D?"yes":"no-hide-descendants",children:r(e,t)}),[r,A,b,n.length,D]),ee=useCallback((e,t)=>String(t),[]),te=useCallback((e,t)=>({length:E,offset:E*t,index:t}),[E]);return w?_jsx(CarouselSkeleton,{...t,containerWidth:k}):_jsxs(View,{style:[Y.container,p],onLayout:e=>_(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:f??T.carousel,accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:D,text:T.slideOf(D+1,n.length)},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:y,children:[_jsx(FlatList,{ref:R,data:n,keyExtractor:i??ee,renderItem:Z,horizontal:!0,pagingEnabled:"screen"===g&&0===b,snapToInterval:E,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:G?K:void 0,scrollEventThrottle:G?16:void 0,onMomentumScrollEnd:X,onScrollBeginDrag:q,onScrollEndDrag:J,getItemLayout:te,initialScrollIndex:L,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:D,scrollX:V,slideStride:E,variant:h,theme:j,labels:T}):null,x&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:D,renderThumbnail:v,labels:T,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),W(e,!0)},theme:j}):null]})}CarouselRoot.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const s=useTheme(),a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:s.space.md}],children:SKELETON_PAGINATION_DOTS.map(e=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:s.space.xs}}:"bars"===n?{width:20,height:4,radius:"pill",style:{marginHorizontal:s.space.xxs}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:s.space.xs}},e))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const SKELETON_PAGINATION_DOTS=["first","second","third"],carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=Object.assign(CarouselRoot,{Skeleton:CarouselSkeleton}),Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:s,labels:a})=>{const l=useMemo(()=>buildPaginationStyles(s),[s]);if("numbers"===i)return _jsx(View,{style:l.numbersWrap,children:_jsx(Text,{variant:"bodySmall",weight:"medium",color:"secondary",style:l.numbersText,accessibilityLabel:a.slideOf(t+1,e),children:`${t+1} / ${e}`})});const o=Array.from({length:e},(e,t)=>t),c="bars"===i,u=c?24:6,d=c?36:16,m=c?3:6;return _jsx(View,{style:l.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],a=n.interpolate({inputRange:i,outputRange:[u,d,u],extrapolate:"clamp"}),l=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:a,height:m,marginHorizontal:s.space.xs,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:e===t?s.colors.primary:s.colors.border,opacity:l}]},e)})})};function ThumbnailStrip({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i,labels:s}){const a=useMemo(()=>buildThumbStyles(i),[i]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:a.row,accessibilityRole:"tablist",children:e.map((e,l)=>_jsx(ThumbnailItem,{item:e,index:l,isActive:l===t,renderThumbnail:n,onPress:()=>r(l),theme:i,styles:a,labels:s},l))})}function ThumbnailItem({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:s,styles:a,labels:l}){const o=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(o,{toValue:n?1.1:1,useNativeDriver:nativeDriver,friction:6,tension:80});return e.start(),()=>e.stop()},[n,o]);const c=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:a.image,resizeMode:"cover"}):_jsx(View,{style:[a.placeholder,{backgroundColor:s.colors["bg-subtle"]}],children:_jsx(Text,{variant:"caption",weight:"semibold",color:"secondary",children:t+1})}),[e,t,r,s,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:l.goToSlide(t+1),children:_jsx(Animated.View,{style:[a.thumb,{borderColor:n?s.colors.primary:"transparent",transform:[{scale:o}]}],children:c})})}const buildThumbStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.sm,paddingVertical:e.space.sm},thumb:{width:40,height:40,marginHorizontal:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),buildPaginationStyles=e=>StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
|