@webority/mobile-ui 0.174.1 → 0.176.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 +10 -10
- package/dist/canvas-kit/manifest.json +1 -1
- package/dist/canvas-kit/release.json +5 -5
- package/lib/commonjs/components/Accordion/Accordion.js +1 -1
- package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/commonjs/components/AppBar/AppBar.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/Button/Button.js +1 -1
- package/lib/commonjs/components/Calendar/Calendar.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/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/Composer/Composer.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/commonjs/components/DecimalInput/DecimalInput.js +1 -1
- package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
- package/lib/commonjs/components/Divider/Divider.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
- package/lib/commonjs/components/FieldBase/ChoiceText.js +1 -1
- package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
- package/lib/commonjs/components/FieldBase/useFloatingLabel.js +1 -1
- package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
- package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/FormField/FormField.js +1 -1
- package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +1 -1
- package/lib/commonjs/components/ListItem/ListItem.js +1 -1
- package/lib/commonjs/components/Modal/Modal.js +1 -1
- package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/commonjs/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/commonjs/components/Radio/Radio.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/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/commonjs/components/Screen/Screen.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.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/SkeletonClock.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonProvider.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/Sparkline/Sparkline.js +1 -1
- package/lib/commonjs/components/Spinner/Spinner.js +1 -1
- package/lib/commonjs/components/SquircleView/SquircleView.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/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Switch/Switch.js +1 -1
- package/lib/commonjs/components/Tabs/Tabs.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/Toast/ToastProvider.js +1 -1
- package/lib/commonjs/navigation/DiscardGuard.js +1 -1
- package/lib/commonjs/theme/ThemeContext.js +1 -1
- package/lib/commonjs/utils/shadows.js +1 -1
- package/lib/module/components/Accordion/Accordion.js +1 -1
- package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/module/components/AppBar/AppBar.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/Button/Button.js +1 -1
- package/lib/module/components/Calendar/Calendar.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/Checkbox/Checkbox.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/Composer/Composer.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/module/components/DecimalInput/DecimalInput.js +1 -1
- package/lib/module/components/Descriptions/Descriptions.js +1 -1
- package/lib/module/components/Divider/Divider.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/EmptyState/EmptyState.js +1 -1
- package/lib/module/components/FieldBase/ChoiceText.js +1 -1
- package/lib/module/components/FieldBase/FieldBase.js +1 -1
- package/lib/module/components/FieldBase/useFloatingLabel.js +1 -1
- package/lib/module/components/FilePicker/FilePicker.js +1 -1
- package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/FormField/FormField.js +1 -1
- package/lib/module/components/IconBadge/IconBadge.js +1 -1
- package/lib/module/components/IconButton/IconButton.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +1 -1
- package/lib/module/components/ListItem/ListItem.js +1 -1
- package/lib/module/components/Modal/Modal.js +1 -1
- package/lib/module/components/NumberInput/NumberInput.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/module/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/module/components/Radio/Radio.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/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/module/components/Screen/Screen.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.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/SkeletonClock.js +1 -1
- package/lib/module/components/Skeleton/SkeletonProvider.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/Sparkline/Sparkline.js +1 -1
- package/lib/module/components/Spinner/Spinner.js +1 -1
- package/lib/module/components/SquircleView/SquircleView.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/Stepper/Stepper.js +1 -1
- package/lib/module/components/Switch/Switch.js +1 -1
- package/lib/module/components/Tabs/Tabs.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/Toast/ToastProvider.js +1 -1
- package/lib/module/navigation/DiscardGuard.js +1 -1
- package/lib/module/theme/ThemeContext.js +1 -1
- package/lib/module/utils/shadows.js +1 -1
- package/lib/typescript/commonjs/components/AmountSlider/AmountSlider.d.ts +3 -2
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +4 -1
- package/lib/typescript/commonjs/components/AuthedImage/authedImageCache.d.ts +3 -1
- package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +6 -1
- package/lib/typescript/commonjs/components/Badge/Badge.d.ts +5 -1
- package/lib/typescript/commonjs/components/Banner/Banner.d.ts +3 -1
- package/lib/typescript/commonjs/components/BarChart/BarChart.d.ts +4 -1
- package/lib/typescript/commonjs/components/BottomNavigation/BottomNavigation.d.ts +3 -1
- package/lib/typescript/commonjs/components/Box/Box.d.ts +6 -3
- package/lib/typescript/commonjs/components/Button/Button.d.ts +4 -2
- package/lib/typescript/commonjs/components/Calendar/Calendar.d.ts +4 -2
- package/lib/typescript/commonjs/components/Card/Card.d.ts +2 -1
- package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +4 -1
- package/lib/typescript/commonjs/components/Chip/Chip.d.ts +3 -1
- package/lib/typescript/commonjs/components/Composer/Composer.d.ts +3 -1
- package/lib/typescript/commonjs/components/Confetti/Confetti.d.ts +3 -1
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +4 -2
- package/lib/typescript/commonjs/components/DecimalInput/DecimalInput.d.ts +4 -2
- package/lib/typescript/commonjs/components/Divider/Divider.d.ts +3 -2
- package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +3 -1
- package/lib/typescript/commonjs/components/EmptyState/EmptyState.d.ts +2 -1
- package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +4 -1
- package/lib/typescript/commonjs/components/FilterChipRow/FilterChipRow.d.ts +4 -2
- package/lib/typescript/commonjs/components/FloatingActionButton/FloatingActionButton.d.ts +2 -1
- package/lib/typescript/commonjs/components/FormField/FormField.d.ts +3 -2
- package/lib/typescript/commonjs/components/IconBadge/IconBadge.d.ts +4 -2
- package/lib/typescript/commonjs/components/IconButton/IconButton.d.ts +4 -2
- package/lib/typescript/commonjs/components/Input/Input.d.ts +4 -1
- package/lib/typescript/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +4 -1
- package/lib/typescript/commonjs/components/ListItem/ListItem.d.ts +2 -0
- package/lib/typescript/commonjs/components/Modal/Modal.d.ts +3 -1
- package/lib/typescript/commonjs/components/NumberInput/NumberInput.d.ts +4 -2
- package/lib/typescript/commonjs/components/OTPInput/OTPInput.d.ts +3 -2
- package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +4 -2
- package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +4 -4
- package/lib/typescript/commonjs/components/ProfileCompletion/ProfileCompletion.d.ts +4 -1
- package/lib/typescript/commonjs/components/ProgressBar/ProgressBar.d.ts +3 -2
- package/lib/typescript/commonjs/components/ProgressRing/ProgressRing.d.ts +2 -1
- package/lib/typescript/commonjs/components/Radio/Radio.d.ts +4 -2
- package/lib/typescript/commonjs/components/Rating/Rating.d.ts +5 -1
- package/lib/typescript/commonjs/components/RichTextEditor/RichTextEditor.d.ts +2 -1
- package/lib/typescript/commonjs/components/ScannerOverlay/ScannerOverlay.d.ts +2 -1
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +4 -2
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +3 -2
- package/lib/typescript/commonjs/components/SignaturePad/SignaturePad.d.ts +4 -1
- package/lib/typescript/commonjs/components/SlideToConfirm/SlideToConfirm.d.ts +3 -1
- package/lib/typescript/commonjs/components/Slider/Slider.d.ts +3 -1
- package/lib/typescript/commonjs/components/SliderField/SliderField.d.ts +3 -1
- package/lib/typescript/commonjs/components/Sparkline/Sparkline.d.ts +4 -2
- package/lib/typescript/commonjs/components/Spinner/Spinner.d.ts +2 -1
- package/lib/typescript/commonjs/components/SquircleView/SquircleView.d.ts +8 -3
- package/lib/typescript/commonjs/components/StatTile/StatTile.d.ts +3 -2
- package/lib/typescript/commonjs/components/StatusBadge/StatusBadge.d.ts +4 -1
- package/lib/typescript/commonjs/components/Stepper/Stepper.d.ts +3 -1
- package/lib/typescript/commonjs/components/Switch/Switch.d.ts +3 -2
- package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +3 -2
- package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +4 -2
- package/lib/typescript/commonjs/components/Text/Text.d.ts +4 -1
- package/lib/typescript/commonjs/navigation/DiscardGuard.d.ts +3 -1
- package/lib/typescript/module/components/AmountSlider/AmountSlider.d.ts +3 -2
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +4 -1
- package/lib/typescript/module/components/AuthedImage/authedImageCache.d.ts +3 -1
- package/lib/typescript/module/components/Avatar/Avatar.d.ts +6 -1
- package/lib/typescript/module/components/Badge/Badge.d.ts +5 -1
- package/lib/typescript/module/components/Banner/Banner.d.ts +3 -1
- package/lib/typescript/module/components/BarChart/BarChart.d.ts +4 -1
- package/lib/typescript/module/components/BottomNavigation/BottomNavigation.d.ts +3 -1
- package/lib/typescript/module/components/Box/Box.d.ts +6 -3
- package/lib/typescript/module/components/Button/Button.d.ts +4 -2
- package/lib/typescript/module/components/Calendar/Calendar.d.ts +4 -2
- package/lib/typescript/module/components/Card/Card.d.ts +2 -1
- package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +4 -1
- package/lib/typescript/module/components/Chip/Chip.d.ts +3 -1
- package/lib/typescript/module/components/Composer/Composer.d.ts +3 -1
- package/lib/typescript/module/components/Confetti/Confetti.d.ts +3 -1
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +4 -2
- package/lib/typescript/module/components/DecimalInput/DecimalInput.d.ts +4 -2
- package/lib/typescript/module/components/Divider/Divider.d.ts +3 -2
- package/lib/typescript/module/components/Drawer/Drawer.d.ts +3 -1
- package/lib/typescript/module/components/EmptyState/EmptyState.d.ts +2 -1
- package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +4 -1
- package/lib/typescript/module/components/FilterChipRow/FilterChipRow.d.ts +4 -2
- package/lib/typescript/module/components/FloatingActionButton/FloatingActionButton.d.ts +2 -1
- package/lib/typescript/module/components/FormField/FormField.d.ts +3 -2
- package/lib/typescript/module/components/IconBadge/IconBadge.d.ts +4 -2
- package/lib/typescript/module/components/IconButton/IconButton.d.ts +4 -2
- package/lib/typescript/module/components/Input/Input.d.ts +4 -1
- package/lib/typescript/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +4 -1
- package/lib/typescript/module/components/ListItem/ListItem.d.ts +2 -0
- package/lib/typescript/module/components/Modal/Modal.d.ts +3 -1
- package/lib/typescript/module/components/NumberInput/NumberInput.d.ts +4 -2
- package/lib/typescript/module/components/OTPInput/OTPInput.d.ts +3 -2
- package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +4 -2
- package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +4 -4
- package/lib/typescript/module/components/ProfileCompletion/ProfileCompletion.d.ts +4 -1
- package/lib/typescript/module/components/ProgressBar/ProgressBar.d.ts +3 -2
- package/lib/typescript/module/components/ProgressRing/ProgressRing.d.ts +2 -1
- package/lib/typescript/module/components/Radio/Radio.d.ts +4 -2
- package/lib/typescript/module/components/Rating/Rating.d.ts +5 -1
- package/lib/typescript/module/components/RichTextEditor/RichTextEditor.d.ts +2 -1
- package/lib/typescript/module/components/ScannerOverlay/ScannerOverlay.d.ts +2 -1
- package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +4 -2
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +3 -2
- package/lib/typescript/module/components/SignaturePad/SignaturePad.d.ts +4 -1
- package/lib/typescript/module/components/SlideToConfirm/SlideToConfirm.d.ts +3 -1
- package/lib/typescript/module/components/Slider/Slider.d.ts +3 -1
- package/lib/typescript/module/components/SliderField/SliderField.d.ts +3 -1
- package/lib/typescript/module/components/Sparkline/Sparkline.d.ts +4 -2
- package/lib/typescript/module/components/Spinner/Spinner.d.ts +2 -1
- package/lib/typescript/module/components/SquircleView/SquircleView.d.ts +8 -3
- package/lib/typescript/module/components/StatTile/StatTile.d.ts +3 -2
- package/lib/typescript/module/components/StatusBadge/StatusBadge.d.ts +4 -1
- package/lib/typescript/module/components/Stepper/Stepper.d.ts +3 -1
- package/lib/typescript/module/components/Switch/Switch.d.ts +3 -2
- package/lib/typescript/module/components/Tabs/Tabs.d.ts +3 -2
- package/lib/typescript/module/components/TagInput/TagInput.d.ts +4 -2
- package/lib/typescript/module/components/Text/Text.d.ts +4 -1
- package/lib/typescript/module/navigation/DiscardGuard.d.ts +3 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fillText,pluralText,useMobileUiText}from"../../text/index.js";import{FLOATING_ACTION_BUTTON_TEXT}from"../../text/phone/floatingActionButton.g.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:f,accessibilityHint:b,haptic:g,style:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButton","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",e.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const S=!u&&!d,x=useTheme(),v=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),_=useMemo(()=>buildStyles(x),[x]),{scale:E,opacity:I,pressIn:R,pressOut:T}=usePressAnimation({enabled:S}),F=usePresenceMotion(),j=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],V=useRef(createAnimatedValue(1)).current,B=F.duration("default");useEffect(()=>{if(!m)return void setNativeValue(V,1);const e=Animated.timing(V,{toValue:p?0:1,duration:B,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[m,p,V,B,x.motion.ease["in-out"]]);const P=w.diameter+(c??C)+v.bottom+j,k=V.interpolate({inputRange:[0,1],outputRange:F.range(P,0)}),D=useMemo(()=>Animated.multiply(V,I),[V,I]),N="string"==typeof i&&i.length>0,O=N&&s,L=F.reduced,z=x.space.sm,M=w["label-padding-x"],H=x.motion.duration.fast,G=x.motion.ease["in-out"],$=useSharedValue(O?1:0),[U,W]=useState(null);useEffect(()=>{const e=O?1:0;return $.value=L?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...G)}),()=>cancelAnimation($)},[O,L,$,H,G]);const X=useCallback(e=>{const t=Math.ceil(e);W(e=>e===t?e:t)},[]),Y=useAnimatedStyle(()=>({paddingHorizontal:M*(1-$.value)}),[M,$]),Z=useAnimatedStyle(()=>{const e=Math.max(0,1-2*$.value);return null===U?$.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(U+z)*(1-$.value)}},[$,U,z]),q=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:w.icon,disabled:u}),Q=useMemo(()=>{if(!l)return null;const e=(c??C)+v.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:j}}},[l,c,v.bottom,C,j]);return _jsx(Animated.View,{style:[Q,{transform:[{translateY:k},{scale:E}],opacity:D},h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!S)return;const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),n()},onPressIn:R,onPressOut:T,disabled:!S,accessibilityRole:"button",accessibilityLabel:f,accessibilityHint:b,accessibilityState:{disabled:!S,busy:d},"aria-disabled":!S,"aria-busy":d,testID:A,style:[_.base,N?{height:w.diameter,minWidth:w.diameter,borderRadius:w.diameter/2,...smoothCorners}:{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:q,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&S?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[_.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:w.diameter/2,...smoothCorners}]}):null,N?_jsxs(Reanimated.View,{style:[_.extendedRow,Y],children:[K,_jsx(Reanimated.View,{style:[_.labelClip,Z],children:_jsx(Text,{onLayout:e=>X(e.nativeEvent.layout.width),style:[_.label,{color:J,fontSize:w.text,fontWeight:x.weight.semibold,marginLeft:z},y],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"",FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:f=!1,style:b,secondaryActionStyle:g,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMobileUiText("floatingActionButton",FLOATING_ACTION_BUTTON_TEXT),x=useMemo(()=>({...S,...a}),[S,a]),v=d??x.quickActions,w=useTheme(),_=useSafeAreaInsets(),E=useMemo(()=>resolveFloatingActionButtonSize(w,u),[w,u]),I=useMemo(()=>buildGroupStyles(w),[w]),R=usePresenceMotion(),T=R.duration("default"),F=w.space[w.components["floating-action-button"]["edge-offset"]],j=w.space[w.components["floating-action-button"]["bottom-offset"]],C=w.space[w.components["floating-action-button"]["secondary-gap"]],V=w.components["floating-action-button"]["stagger-ms"],B=useMemo(()=>n.slice(0,6),[n]),P=B.length,k=useMemo(()=>B.map((e,t)=>({action:e,index:t})).reverse(),[B]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const D=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&D&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${D}`)},[D]);const N="boolean"==typeof i,[O,L]=useState(s),z="boolean"==typeof i?i:O,M=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(M,1);const e=Animated.timing(M,{toValue:f?0:1,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[p,f,M,T,w.motion.ease["in-out"]]);const H=p&&f;useEffect(()=>{H&&z&&(N||L(!1),r?.(!1))},[H,z,N,r]);const G=E.diameter+(c??j)+_.bottom+F,$=M.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),U=M,W=useRef(createAnimatedValue(z?1:0)).current,X=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=X.current;if(e.length!==P){if(e.length<P){const t=e.slice();for(let o=e.length;o<P;o+=1)t.push(new Animated.Value(z?1:0));X.current=t}else X.current=e.slice(0,P);Z(e=>e+1)}},[P,z]),useEffect(()=>{const e=Animated.timing(W,{toValue:z?1:0,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver});e.start();const t=X.current.map(e=>Animated.timing(e,{toValue:z?1:0,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver})),o=z?t:[...t].reverse(),n=Animated.stagger(V,o);return n.start(),()=>{e.stop(),n.stop()}},[z,W,T,w.motion.ease["in-out"],P,Y,V]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),N||L(e),r?.(e)},[N,r,m]),J=useRef(null),K=useRef(z),Q=useRef(!1);useEffect(()=>{if(K.current===z)return;K.current=z;const e=Q.current;if(Q.current=!1,H||e)return;const t=J.current;t&&("web"===Platform.OS?"focus"in t&&"function"==typeof t.focus&&t.focus():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(z?pluralText(x,"expanded",P,{label:v}):fillText(x.collapsed,{label:v}))},[z,H,v,P,x]);const ee=useCallback(()=>{q(!z)},[z,q]),te=useCallback(e=>{!1!==m&&triggerHaptic("selection"),Q.current=!0,e.onPress(),N||L(!1),r?.(!1)},[N,r,m]),oe=useCallback(()=>{z&&q(!1)},[z,q]);useEffect(()=>{if(!z)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[z,q]),useEffect(()=>{if(!z||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[z,q]);const ne=useMemo(()=>{const e=(c??j)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,j,F]),slotOffset=e=>-(E.diameter+C)*(e+1),ie=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),se=.78*E.diameter,re=useMemo(()=>{const e=se+w.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:E.diameter/2+se/2+w.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,se,E.diameter,w.space.sm]),ae=W.interpolate({inputRange:[0,1],outputRange:[0,.4]}),le=W.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[z?_jsx(Animated.View,{pointerEvents:z?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:w.colors.scrim,opacity:ae}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:oe,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:H?"none":"box-none",style:[ne,{transform:[{translateY:$}],opacity:U},b],accessibilityRole:"menu",testID:A,children:[k.map(({action:e,index:t})=>{const o=X.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),s=toneBackground(w,e.tone??"primary"),r=toneForeground(w,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[I.labelSlot,re],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[I.labelPill,w.shadow.card,{backgroundColor:w.colors.surface,paddingHorizontal:w.space.sm,paddingVertical:w.space.xs,borderRadius:w.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:w.colors["text-body"],fontSize:w.text.sm.size,fontWeight:w.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:z?"auto":"none",accessibilityElementsHidden:!z,importantForAccessibility:z?"auto":"no-hide-descendants","aria-hidden":!z,style:[I.secondaryRow,ie,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>te(e),focusable:z,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[I.fabBase,w.shadow.elevated,{width:se,height:se,borderRadius:se/2,...smoothCorners,backgroundColor:s},g],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(w,e.tone??"primary"),borderRadius:se/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:E.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:J,onPress:ee,accessibilityRole:"button",accessibilityLabel:v,accessibilityState:{expanded:z},"aria-expanded":z,style:[I.fabBase,w.shadow.popover,{width:E.diameter,height:E.diameter,borderRadius:E.diameter/2,...smoothCorners,backgroundColor:w.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:E.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:le}]},children:renderSlotIcon(z&&o?o:t,{color:w.colors["on-primary"],size:E.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
|
|
1
|
+
"use strict";import{Logger}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fillText,pluralText,useMobileUiText}from"../../text/index.js";import{FLOATING_ACTION_BUTTON_TEXT}from"../../text/phone/floatingActionButton.g.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}};function FloatingActionButton({ref:e,...t}){const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:f,accessibilityHint:b,haptic:g,style:h,labelStyle:y,testID:A}=t;assertValidValue("FloatingActionButton","size",t.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",t.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",t.position,FAB_POSITIONS);const S=!u&&!d,x=useTheme(),v=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),_=useMemo(()=>buildStyles(x),[x]),{scale:E,opacity:I,pressIn:R,pressOut:T}=usePressAnimation({enabled:S}),j=usePresenceMotion(),C=x.space[x.components["floating-action-button"]["edge-offset"]],F=x.space[x.components["floating-action-button"]["bottom-offset"]],V=useRef(createAnimatedValue(1)).current,B=j.duration("default");useEffect(()=>{if(!m)return void setNativeValue(V,1);const e=Animated.timing(V,{toValue:p?0:1,duration:B,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[m,p,V,B,x.motion.ease["in-out"]]);const P=w.diameter+(c??F)+v.bottom+C,k=V.interpolate({inputRange:[0,1],outputRange:j.range(P,0)}),D=useMemo(()=>Animated.multiply(V,I),[V,I]),O="string"==typeof i&&i.length>0,N=O&&s,L=j.reduced,z=x.space.sm,M=w["label-padding-x"],H=x.motion.duration.fast,G=x.motion.ease["in-out"],$=useSharedValue(N?1:0),[U,W]=useState(null);useEffect(()=>{const e=N?1:0;return $.value=L?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...G)}),()=>cancelAnimation($)},[N,L,$,H,G]);const X=useCallback(e=>{const t=Math.ceil(e);W(e=>e===t?e:t)},[]),Y=useAnimatedStyle(()=>({paddingHorizontal:M*(1-$.value)}),[M,$]),Z=useAnimatedStyle(()=>{const e=Math.max(0,1-2*$.value);return null===U?$.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(U+z)*(1-$.value)}},[$,U,z]),q=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:w.icon,disabled:u}),Q=useMemo(()=>{if(!l)return null;const e=(c??F)+v.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:C};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:C}}},[l,c,v.bottom,F,C]);return _jsx(Animated.View,{style:[Q,{transform:[{translateY:k},{scale:E}],opacity:D},h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:e,onPress:e=>{if(!S)return;const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),n()},onPressIn:R,onPressOut:T,disabled:!S,accessibilityRole:"button",accessibilityLabel:f,accessibilityHint:b,accessibilityState:{disabled:!S,busy:d},"aria-disabled":!S,"aria-busy":d,testID:A,style:[_.base,O?{height:w.diameter,minWidth:w.diameter,borderRadius:w.diameter/2,...smoothCorners}:{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:q,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&S?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[_.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:w.diameter/2,...smoothCorners}]}):null,O?_jsxs(Reanimated.View,{style:[_.extendedRow,Y],children:[K,_jsx(Reanimated.View,{style:[_.labelClip,Z],children:_jsx(Text,{onLayout:e=>X(e.nativeEvent.layout.width),style:[_.label,{color:J,fontSize:w.text,fontWeight:x.weight.semibold,marginLeft:z},y],numberOfLines:1,children:i})})]}):K]})})})}const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"",FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:f=!1,style:b,secondaryActionStyle:g,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMobileUiText("floatingActionButton",FLOATING_ACTION_BUTTON_TEXT),x=useMemo(()=>({...S,...a}),[S,a]),v=d??x.quickActions,w=useTheme(),_=useSafeAreaInsets(),E=useMemo(()=>resolveFloatingActionButtonSize(w,u),[w,u]),I=useMemo(()=>buildGroupStyles(w),[w]),R=usePresenceMotion(),T=R.duration("default"),j=w.space[w.components["floating-action-button"]["edge-offset"]],C=w.space[w.components["floating-action-button"]["bottom-offset"]],F=w.space[w.components["floating-action-button"]["secondary-gap"]],V=w.components["floating-action-button"]["stagger-ms"],B=useMemo(()=>n.slice(0,6),[n]),P=B.length,k=useMemo(()=>B.map((e,t)=>({action:e,index:t})).reverse(),[B]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const D=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&D&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${D}`)},[D]);const O="boolean"==typeof i,[N,L]=useState(s),z="boolean"==typeof i?i:N,M=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(M,1);const e=Animated.timing(M,{toValue:f?0:1,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[p,f,M,T,w.motion.ease["in-out"]]);const H=p&&f;useEffect(()=>{H&&z&&(O||L(!1),r?.(!1))},[H,z,O,r]);const G=E.diameter+(c??C)+_.bottom+j,$=M.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),U=M,W=useRef(createAnimatedValue(z?1:0)).current,X=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=X.current;if(e.length!==P){if(e.length<P){const t=e.slice();for(let o=e.length;o<P;o+=1)t.push(new Animated.Value(z?1:0));X.current=t}else X.current=e.slice(0,P);Z(e=>e+1)}},[P,z]),useEffect(()=>{const e=Animated.timing(W,{toValue:z?1:0,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver});e.start();const t=X.current.map(e=>Animated.timing(e,{toValue:z?1:0,duration:T,easing:Easing.bezier(...w.motion.ease["in-out"]),useNativeDriver:nativeDriver})),o=z?t:[...t].reverse(),n=Animated.stagger(V,o);return n.start(),()=>{e.stop(),n.stop()}},[z,W,T,w.motion.ease["in-out"],P,Y,V]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),O||L(e),r?.(e)},[O,r,m]),J=useRef(null),K=useRef(z),Q=useRef(!1);useEffect(()=>{if(K.current===z)return;K.current=z;const e=Q.current;if(Q.current=!1,H||e)return;const t=J.current;t&&("web"===Platform.OS?"focus"in t&&"function"==typeof t.focus&&t.focus():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(z?pluralText(x,"expanded",P,{label:v}):fillText(x.collapsed,{label:v}))},[z,H,v,P,x]);const ee=useCallback(()=>{q(!z)},[z,q]),te=useCallback(e=>{!1!==m&&triggerHaptic("selection"),Q.current=!0,e.onPress(),O||L(!1),r?.(!1)},[O,r,m]),oe=useCallback(()=>{z&&q(!1)},[z,q]);useEffect(()=>{if(!z)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[z,q]),useEffect(()=>{if(!z||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[z,q]);const ne=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:j,alignItems:"flex-end"}}},[l,c,_.bottom,C,j]),slotOffset=e=>-(E.diameter+F)*(e+1),ie=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),se=.78*E.diameter,re=useMemo(()=>{const e=se+w.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:E.diameter/2+se/2+w.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,se,E.diameter,w.space.sm]),ae=W.interpolate({inputRange:[0,1],outputRange:[0,.4]}),le=W.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[z?_jsx(Animated.View,{pointerEvents:z?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:w.colors.scrim,opacity:ae}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:oe,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:H?"none":"box-none",style:[ne,{transform:[{translateY:$}],opacity:U},b],accessibilityRole:"menu",testID:A,children:[k.map(({action:e,index:t})=>{const o=X.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),s=toneBackground(w,e.tone??"primary"),r=toneForeground(w,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[I.labelSlot,re],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[I.labelPill,w.shadow.card,{backgroundColor:w.colors.surface,paddingHorizontal:w.space.sm,paddingVertical:w.space.xs,borderRadius:w.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:w.colors["text-body"],fontSize:w.text.sm.size,fontWeight:w.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:z?"auto":"none",accessibilityElementsHidden:!z,importantForAccessibility:z?"auto":"no-hide-descendants","aria-hidden":!z,style:[I.secondaryRow,ie,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>te(e),focusable:z,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[I.fabBase,w.shadow.elevated,{width:se,height:se,borderRadius:se/2,...smoothCorners,backgroundColor:s},g],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(w,e.tone??"primary"),borderRadius:se/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:E.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:J,onPress:ee,accessibilityRole:"button",accessibilityLabel:v,accessibilityState:{expanded:z},"aria-expanded":z,style:[I.fabBase,w.shadow.popover,{width:E.diameter,height:E.diameter,borderRadius:E.diameter/2,...smoothCorners,backgroundColor:w.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:E.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:le}]},children:renderSlotIcon(z&&o?o:t,{color:w.colors["on-primary"],size:E.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{
|
|
1
|
+
"use strict";import React,{useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,Text,View}from"react-native";import{useFieldErrorAnchor}from"../../hooks/useFieldErrorScroll.js";import{fillText,useMobileUiText}from"../../text/index.js";import{FORM_FIELD_TEXT}from"../../text/phone/formField.g.js";import{createAnimatedValue,fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{fieldTextAsString,hasFieldText,RequiredMark}from"../FieldBase/index.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function FormField({ref:e,...t}){assertValidValue("FormField","layout",t.layout,["stacked","inline"]);const{label:l,help:i,helperText:r,error:s,required:n=!1,children:o,layout:a="stacked",helperLines:d,labelStyle:x,helperStyle:u,errorStyle:c,style:m,inputContainerStyle:f,accessibilityLabel:h,labels:p,testID:T}=t,F=useFieldErrorAnchor(hasFieldText(s),e),b=useTheme(),S=useMemo(()=>buildStyles(b),[b]),j=useMobileUiText("formField",FORM_FIELD_TEXT),y=useMemo(()=>({...j,...p}),[j,p]),k=fieldTextAsString(s),I=useRef(createAnimatedValue(s?1:0)).current;useEffect(()=>{const e=Animated.timing(I,{toValue:s?1:0,duration:b.motion.duration.fast,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[s,I,b.motion.duration.fast]);const v=useMemo(()=>{if(h)return h;const e=fieldTextAsString(l);return e?k?fillText(y.labelWithError,{label:e,error:k}):e:void 0},[h,l,k,y]),g=resolveFieldSize(b,"md"),_=useTextInk(x,g["label-text"],b.colors["field-label"]),V=useTextInk(u,g["message-text"],b.colors["text-muted"]),w=useTextInk(c,g["message-text"],b.colors["field-message"]),E=hasFieldText(l),R=_jsxs(Text,{style:[S.label,"inline"!==a||hasFieldText(i)?null:S.labelInline,hasFieldText(i)?S.labelShrink:null,x],children:[_jsx(TextInkContext,{value:_,children:l}),n?_jsx(RequiredMark,{}):null]}),D=E?hasFieldText(i)?_jsxs(View,{style:[S.labelRow,"inline"===a?S.labelInline:null],children:[R,_jsx(View,{style:[S.help,{marginLeft:b.space.xs}],children:i})]}):R:null,A="inline"===a?S.inputInline:S.inputStacked,M=hasFieldText(s),L=!M&&hasFieldText(r),z=n&&!E&&React.isValidElement(o)?React.cloneElement(o,{required:!0}):o;return _jsxs(View,{ref:F,style:["inline"===a?S.rootInline:S.rootStacked,m],accessibilityLabel:v,accessibilityHint:k||void 0,testID:T,children:[D,_jsx(View,{style:[A,f],children:z}),L?_jsx(Text,{style:[S.helper,u],numberOfLines:d||void 0,children:_jsx(TextInkContext,{value:V,children:r})}):null,M?_jsx(Animated.Text,{style:[S.error,{opacity:I},c],numberOfLines:d||void 0,accessibilityLiveRegion:"polite",children:_jsx(TextInkContext,{value:w,children:s})}):null]})}const buildStyles=e=>{const t=resolveFieldSize(e,"md");return StyleSheet.create({rootStacked:{flexDirection:"column",gap:e.space.xs},rootInline:{flexDirection:"row",alignItems:"center",flexWrap:"wrap",gap:e.space.xs},label:{fontSize:t["label-text"],...fontFor(e,"semibold"),color:e.colors["field-label"]},labelShrink:{flexShrink:1},labelRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},labelInline:{width:"35%"},inputStacked:{width:"100%"},inputInline:{flex:1,minWidth:0},helper:{fontSize:t["message-text"],...fontFor(e,"normal"),color:e.colors["text-muted"]},error:{fontSize:t["message-text"],...fontFor(e,"normal"),color:e.colors["field-message"]}})};export{FormField};export default FormField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{Platform,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{squirclePath}from"../../squircle.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:56,icon:28}},FILL_OPACITY=.14,HALO_FILL_OPACITY=.16,inkFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}};function IconBadge(e){const{ref:t,icon:r,iconVariant:s,size:o="md",tone:i="primary",color:a,fill:n="tint",shape:l="circle",dimension:c,accessibilityLabel:d,pointerEvents:u,style:m,testID:h}=e;assertValidValue("IconBadge","size",e.size,["sm","md","lg"]),assertValidValue("IconBadge","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("IconBadge","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]),assertValidValue("IconBadge","fill",e.fill,["tint","halo","surface"]),assertValidValue("IconBadge","shape",e.shape,["circle","squircle"]);const g=useTheme(),f=SIZE_MAP[o],p=a??inkFor(g,i),I=c??f.diameter,b=null!=c?Math.round(c/2):f.icon,y="surface"===n?g.colors.surface:void 0===a&&"neutral"===i?g.colors["bg-muted"]:tintOf(p,"halo"===n?.16:.14,g.colors["bg-muted"]),V={color:p,size:b,disabled:!1},j=void 0!==d,v="squircle"===l;return _jsxs(View,{ref:t,testID:h,pointerEvents:u,accessible:j,accessibilityRole:j?"image":void 0,accessibilityLabel:d,importantForAccessibility:j?"yes":"no",..."web"!==Platform.OS||j?null:{"aria-hidden":!0},style:[styles.base,v?{width:I,height:I}:{width:I,height:I,borderRadius:I/2,...smoothCorners,backgroundColor:y},m],children:[v?_jsx(Svg,{style:styles.overlay,width:I,height:I,viewBox:`0 0 ${I} ${I}`,children:_jsx(Path,{d:squirclePath({width:I,height:I,radius:g.radius.lg,smoothing:g.cornerSmoothing}),fill:y})}):null,renderSlotIcon(r,V,s)]})}const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},overlay:{position:"absolute",top:0,left:0}});export{IconBadge};export default IconBadge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{Animated,Pressable,StyleSheet}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,o)=>{switch(o){case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}};function IconButton({ref:e,...o}){const{icon:s,iconVariant:t,onPress:r,accessibilityLabel:i,accessibilityHint:n,accessibilityState:a,tone:l="primary",variant:c="solid",size:d="md",shape:u="circle",active:m=!1,disabled:b=!1,loading:p=!1,haptic:f,style:g,testID:y}=o;assertValidValue("IconButton","tone",o.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("IconButton","variant",o.variant,["solid","soft","outline","ghost","glass"]),assertValidValue("IconButton","size",o.size,["sm","md","lg"]),assertValidValue("IconButton","shape",o.shape,["circle","rounded"]),assertValidValue("IconButton","iconVariant",o.iconVariant,["linear","bold","broken","bulk","outline","twotone"]);const h=useTheme(),I=SIZE_MAP[d],S=b||p,{style:x,pressIn:j,pressOut:V}=usePressAnimation({scaleTo:.92,enabled:!S}),{base:P,outline:A,on:_,fg:w}=toneFor(h,l),H=m?"solid":c,B=m||!0===a?.selected,v={...a,disabled:S,selected:B};let C="transparent",F="transparent",O=0,T=S?h.colors["text-disabled"]:w;"solid"===H?(C=S?h.colors["surface-disabled"]:P,T=S?h.colors["text-disabled"]:_):"soft"===H?C=S?h.colors["surface-disabled"]:tintOf(P,.14,h.colors["bg-subtle"]):"outline"===H?(F=S?h.colors.border:A,O=h.size.border):"glass"===H&&(C=h.colors["glass-fill"],F=h.colors["glass-border"],O=1,T=S?h.colors["text-disabled"]:h.colors["on-glass"]);const k={color:T,size:I.icon,disabled:S},z="circle"===u?I.diameter/2:h.radius.md;return _jsx(Pressable,{ref:e,onPress:e=>{if(S)return;const o=resolveHaptic(f,"selection");o&&triggerHaptic(o),r?.(e)},onPressIn:j,onPressOut:V,disabled:S,accessibilityRole:"button",accessibilityLabel:i,accessibilityHint:n,accessibilityState:v,...ariaFromState(v),"aria-disabled":S,"aria-selected":B,hitSlop:6,...hitSlopMarker(6),testID:y,style:({pressed:e})=>[styles.base,{width:I.diameter,height:I.diameter,borderRadius:z,...smoothCorners,backgroundColor:C,borderColor:F,borderWidth:O,opacity:e&&"solid"!==H?.7:1},g],children:_jsx(Animated.View,{style:[styles.content,x],accessibilityElementsHidden:!p,importantForAccessibility:p?"auto":"no-hide-descendants","aria-hidden":!p,children:p?_jsx(Spinner,{size:"sm",color:T}):renderSlotIcon(s,k,t)})})}const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},content:{alignItems:"center",justifyContent:"center"}});export{IconButton};export default IconButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{
|
|
1
|
+
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{useMobileUiText}from"../../text/index.js";import{INPUT_TEXT}from"../../text/phone/input.g.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function Input(e){const{ref:t,label:i,help:o,placeholder:n,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:y,prefixStyle:v,readOnly:b=!1,action:S,actionStyle:T,size:j="md",variant:I,labelMode:w,required:V=!1,maxLength:F,showCounter:_=!0,textAlign:A,format:R,parse:D,style:z,fieldStyle:k,inputStyle:C,labelStyle:P,messageStyle:L,radius:M,onFocus:N,onBlur:E,accessibilityLabel:B,labels:H,testID:O,editable:q,...G}=e;assertValidValue("Input","variant",I,["outline","filled","underline"]),assertValidValue("Input","size",e.size,["sm","md","lg"]),assertValidValue("Input","labelMode",w,["float","top"]),assertValidValue("Input","type",e.type,["input","password","textarea"]);const U=useMobileUiText("input",INPUT_TEXT),W=useMemo(()=>({...U,...H}),[U,H]),X=useTheme(),$=useMemo(()=>buildStyles(X),[X]),J=resolveFieldSize(X,j),K=X.components.input[j]["multiline-min-height"],Q=Math.round(J.text*X.leading.body),Y=I??X.settings.components.input?.defaultVariant??X.settings.components.field?.defaultVariant??"outline",Z=w??X.settings.components.input?.defaultLabelMode??"top",[ee,te]=useState(!1),[ie,oe]=useState(!1),ne="password"===d||u||c,le="password"===d||u,se="textarea"===d||f,re=se?Math.round(.1*J.text):0,ae="string"==typeof l&&l.length>0,de=hasFieldText(r),ce=!0===r||de,ue=hasFieldText(a),pe=de||!ce&&ue,fe=hasFieldText(i),me=hasFieldText(y),xe=!p&&!1!==q,ge=ee||ae||me,he=useRef(null),ye=useMemo(()=>mergeRefs(he,t),[t]),ve=useCallback(()=>{xe&&he.current?.focus()},[xe]),be=fe&&"float"===Z,Se=useRef(createAnimatedValue(0)).current,Te=useRef(createAnimatedValue(pe?1:0)).current;useEffect(()=>{const e=Animated.timing(Te,{toValue:pe?1:0,duration:X.motion.duration.fast,easing:Easing.bezier(...X.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[pe,Te,X.motion.duration.fast,X.motion.ease["in-out"]]);const je=useReducedMotion(),Ie=X.settings.components.input?.shakeOnError??!1,we=useRef(ce);useEffect(()=>{if(!Ie)return void(we.current=ce);let e;return ce&&!we.current&&(je||(setNativeValue(Se,0),e=Animated.sequence([Animated.timing(Se,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(Se,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(Se,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(Se,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(Se,{toValue:0,duration:100,useNativeDriver:nativeDriver})]),e.start()),triggerHaptic("notificationError")),we.current=ce,()=>e?.stop()},[ce,Se,Ie,je]);const Ve=useCallback(e=>{te(!0),N?.(e)},[N]),Fe=useCallback(e=>{te(!1),E?.(e)},[E]),Ae=useCallback(()=>{triggerHaptic("selection"),oe(e=>!e)},[]),Re=X.colors["field-caret"],De=X.settings.components.input?.tintLabelOnFocus??!1,ze=ee&&De?X.colors["field-border-focus"]:X.colors["field-label"],ke=Se.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Ce=Boolean(x)||Boolean(g)||le,Pe="underline"===Y,Le=m?J.icon+X.space.md+1+X.space.md:0,Me=useFloatingLabel({label:i,enabled:be,floated:ge,required:V,variant:Y,sizeTokens:J,leadingOffset:Le,trailingOffset:Ce?J.icon+X.space.sm:0,textAlign:"center"===A||"right"===A?A:"left",paddingLeft:Pe?X.space.none:J["padding-x"],lineHeight:se?Q:void 0,restNudge:re,floatTrim:se?2:0,color:ze,style:P}),Ne=resolveFieldTextStyle(X,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,He=V&&!fe&&!ae&&"string"==typeof n&&n.length>0,Oe=ce?r:a,qe=_&&"number"==typeof F&&"string"==typeof l?`${l.length} / ${F}`:null,Ge=ce?X.colors["field-message"]:X.colors["text-muted"],Ue=useTextInk(L,J["message-text"],Ge),We=B??fieldTextAsString(i)??n,Xe=p?X.colors["field-icon-disabled"]:ee?X.colors["field-icon-focus"]:X.colors["field-icon"],$e={focused:ee,disabled:p,error:ce,color:Xe,size:J.icon},renderSlot=e=>renderSlotIcon(e,$e),Je=(()=>{if(le){const e=(ie?X.settings.icons.eyeOff:X.settings.icons.eye)??(ie?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Ae,disabled:!xe,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:ie?W.hidePassword:W.showPassword,children:e({size:J.icon,color:Xe})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:J.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Ke=m?slotIconView(m,renderSlot(m)):null,Qe=StyleSheet.flatten(v),Ye=Qe?.fontSize??J.text,Ze=Qe?.color??Be,et=useMemo(()=>({fontSize:Ye,color:Ze}),[Ye,Ze]),tt=me?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:J.text,color:Be,marginRight:X.space.xs,lineHeight:se?Q:void 0,paddingTop:se?re:void 0},v],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:X.space.xs,minHeight:se?Q:void 0,justifyContent:"center",paddingTop:se?re:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:J.text,color:Be,lineHeight:se?Q:void 0},v],children:_jsx(TextInkContext,{value:et,children:y})})}):null,it=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:j,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:J["min-height"],alignSelf:se?"flex-start":"stretch"},T]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:ke}]},z],children:[fe&&!be?_jsx(FieldLabel,{size:j,required:V,help:o,color:ze,style:P,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:X.space.sm,alignItems:se?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{testID:O?`${O}-field`:void 0,size:j,variant:Y,focused:ee,disabled:p,error:ce,filled:ae,minHeight:se?K:void 0,radius:M,leading:Ke,leadingDivider:null!=m,paddingLeft:Pe?X.space.none:void 0,trailing:Je,slotAlign:se?"top":"center",slotLineHeight:se?Q:void 0,topNotch:Me.topNotch,onPress:ve,pressFeedback:!1,style:k,children:[tt,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:ye,style:[$.input,{color:Ee,fontSize:J.text,...Ne.weightStyle,paddingLeft:Pe?X.space.none:void 0,minHeight:se?K-2*J["padding-y"]:void 0,lineHeight:se?Q:void 0,paddingTop:se?re:void 0,textAlignVertical:se?"top":"center"},C],textAlign:A,placeholder:be&&!ge||He?void 0:n,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{reportIdleActivity(),s&&s(D?D(e):e)},onFocus:Ve,onBlur:Fe,editable:xe,readOnly:b,secureTextEntry:ne&&!ie,multiline:se,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:F,selectionColor:Re,accessibilityLabel:We,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),He&&"string"==typeof n?_jsx(RequiredPlaceholder,{text:n,color:Be,fontSize:J.text,weightStyle:Ne.weightStyle,align:se?"top":"center",paddingTop:se?re:void 0,textAlign:A}):null]})]}),Me.node]}),it]}),pe||qe?_jsxs(View,{style:[$.footerRow,{marginTop:J["message-gap"]}],children:[pe?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:X.space.xs,opacity:Te}],accessibilityLiveRegion:ce?"polite":"none",children:[ce?_jsx(FieldErrorGlyph,{size:J["message-text"],color:Ge}):null,_jsx(Text,{style:[$.messageText,{color:Ge,fontSize:J["message-text"],...fontFor(X,"normal")},L],children:_jsx(TextInkContext,{value:Ue,children:Oe})})]}):_jsx(View,{style:$.footerSpacer}),qe?_jsx(Text,{style:[$.counterText,{color:X.colors["text-subtle"],fontSize:J["message-text"],...fontFor(X,"normal")}],children:qe}):null]}):null]})}const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{Keyboard,Pressable,RefreshControl,StyleSheet}from"react-native";import{KeyboardAwareScrollView as ControllerScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{jsx as _jsx}from"react/jsx-runtime";const tapAreaStyle={flexGrow:1},CHILD_LAYOUT_KEYS=["gap","rowGap","columnGap","flexDirection","flexWrap","alignItems","alignContent","justifyContent"],childLayout=e=>{const r=StyleSheet.flatten(e),o={};for(const e of CHILD_LAYOUT_KEYS)void 0!==r?.[e]&&Object.assign(o,{[e]:r[e]});return o};function KeyboardAwareScrollView({ref:e,...r}){const{children:o,bottomOffset:t=24,extraKeyboardSpace:s=0,safeAreaEdges:l=["bottom"],refreshing:a=!1,onRefresh:n,dismissOnTapOutside:i=!0,contentContainerStyle:d,refreshControl:c,...f}=r,m=useTheme(),p=useSafeAreaInsets(),u=l.includes("bottom"),y={paddingBottom:u?p.bottom:0,...l.includes("top")?{paddingTop:p.top}:null,...l.includes("left")?{paddingLeft:p.left}:null,...l.includes("right")?{paddingRight:p.right}:null},b=c??(n?_jsx(RefreshControl,{refreshing:a,onRefresh:n,tintColor:m.colors.primary,colors:[m.colors.primary],progressBackgroundColor:m.colors.surface,titleColor:m.colors["text-muted"]}):void 0);return _jsx(ControllerScrollView,{ref:e,bottomOffset:t,extraKeyboardSpace:s-(u?p.bottom:0),disableScrollOnKeyboardHide:!0,keyboardShouldPersistTaps:"handled",keyboardDismissMode:"none",contentContainerStyle:[d,y],refreshControl:b,...f,children:i?_jsx(Pressable,{accessible:!1,onPress:Keyboard.dismiss,style:[tapAreaStyle,childLayout(d)],children:o}):o})}export{KeyboardAwareScrollView};export default KeyboardAwareScrollView;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{
|
|
1
|
+
"use strict";import React,{useMemo}from"react";import{Animated,Pressable,StyleSheet,Text,useWindowDimensions,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,resolveCheckboxSize,resolveListItemSize,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{themeStyles}from"../../utils/themeStyles.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Button}from"../Button/index.js";import{IconBadge}from"../IconBadge/index.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{webOnly}from"../Menu/webOnly.js";import{Skeleton}from"../Skeleton/index.js";import{Swipeable}from"../Swipeable/index.js";import{Fragment as _Fragment,jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Chevron=({color:e})=>{const t=useTheme();return _jsx(_Fragment,{children:(t.settings.icons.chevronRight??defaultIcons.chevronRight)({size:20,color:e})})},BADGE_SIZE={sm:"sm",md:"md",lg:"lg"},RIGHT_BELOW_FONT_SCALE=1.2,MENU_ROW_MIN_HEIGHT=48,WEB_CHECKABLE_ROLE=webOnly({role:"menuitemcheckbox"}),SelectionBox=({checked:e,disabled:t})=>{const i=useTheme(),s=resolveCheckboxSize(i,"md")["box-size"],l=Math.round(.72*s);return _jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",pointerEvents:"none",style:{width:s,height:s,alignItems:"center",justifyContent:"center",borderWidth:i.size.border,borderRadius:i.radius.sm,...smoothCorners,borderColor:e?i.colors.primary:i.colors.border,backgroundColor:e?i.colors.primary:t?i.colors["surface-disabled"]:"transparent"},children:e?_jsx(Svg,{width:l,height:l,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:i.colors["on-primary"],strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})}):null})},isActionList=e=>Array.isArray(e)&&e.length>0&&e.every(e=>null!=e&&"object"==typeof e&&!React.isValidElement(e)&&"label"in e),renderActions=e=>isActionList(e)?e.map(e=>_jsx(Button,{size:"sm",variant:e.variant??"outline",tone:e.tone,leftIcon:e.icon,disabled:e.disabled,testID:e.testID,label:e.label,onPress:e.onPress},e.label)):e,ListItemRoot=React.memo(function ListItemRoot({ref:e,...t}){const{title:i,loading:s=!1,subtitle:l,description:o,children:n,titleLines:r,subtitleLines:a=1,leading:c,icon:d,iconTone:m="primary",trailing:u,rightPlacement:h="auto",selectable:p=!1,checked:x=!1,onCheckedChange:g,actions:b,onPress:y,onFocus:f,haptic:j,selected:S=!1,expanded:_,disabled:w=!1,size:v="md",variant:I="list",divider:L=!1,chevron:k=!1,leftActions:V,rightActions:C,contextMenu:R,accessibilityLabel:A,accessibilityHint:B,style:z,rowStyle:T,titleStyle:E,subtitleStyle:F,descriptionStyle:P,leftSlotStyle:D,rightSlotStyle:H,testID:M}=t;assertValidValue("ListItem","size",t.size,["sm","md","lg"]),assertValidValue("ListItem","iconTone",t.iconTone,["primary","success","warning","danger","info","neutral"]),assertValidValue("ListItem","rightPlacement",t.rightPlacement,["auto","side","below"]),assertValidValue("ListItem","variant",t.variant,["list","menu"]);const O="menu"===I,W=r??(O?2:1),G=O?t.checked:void 0,N=useTheme(),K=useMemo(()=>resolveListItemSize(N,v),[N,v]),U=stylesFor(N),{fontScale:Z}=useWindowDimensions(),q=!!u&&("below"===h||"auto"===h&&Z>1.2),J=useContextMenu(w?void 0:R,{haptic:j||!1,testID:M}),Q=useMemo(()=>mergeRefs(e,J.hostRef),[e,J.hostRef]),X=p||!!y,Y=X||J.enabled,$=Y&&!w,{style:ee,pressIn:te,pressOut:ie}=usePressAnimation({enabled:$&&!O}),se=useFlickGuard(),le=A??("string"==typeof i?i:void 0),isText=e=>"string"==typeof e||"number"==typeof e,oe=c??(void 0===d?null:_jsx(IconBadge,{icon:d,tone:m,size:BADGE_SIZE[v]})),ne=p?_jsxs(View,{style:U.selectionLead,children:[_jsx(SelectionBox,{checked:x,disabled:w}),oe?_jsx(View,{style:U.selectionLeadContent,children:oe}):null]}):oe,re=null!=b&&!1!==b&&!(Array.isArray(b)&&0===b.length),ae=L&&!re,ce=_jsxs(View,{style:[U.row,{paddingVertical:O?N.space.sm:K["padding-y"],minHeight:O?48:K["min-height"],backgroundColor:S?N.colors["surface-selected"]:"transparent"},ae?U.divider:null,w&&!O?U.disabled:null,T],children:[ne?_jsx(View,{style:[U.leftSlot,D],children:ne}):null,_jsxs(View,{style:U.middle,children:[null==i||isText(i)?_jsx(Text,{style:[U.title,{fontSize:O?N.text.base.size:K["title-text"],...fontFor(N,O?"normal":"medium"),color:w?N.colors["text-disabled"]:N.colors["text-body"]},E],numberOfLines:W,children:i??" "}):i,null==l||""===l?null:isText(l)?_jsx(Text,{style:[U.subtitle,{fontSize:O?N.text.xs.size:K["subtitle-text"],color:w?N.colors["text-disabled"]:N.colors["text-muted"]},O?U.menuSubtitle:null,F],numberOfLines:a,children:l}):l,null==o||""===o?null:isText(o)?_jsx(Text,{style:[U.description,{fontSize:K["subtitle-text"],color:w?N.colors["text-disabled"]:N.colors["text-subtle"]},P],numberOfLines:2,children:o}):o,null!=n&&!1!==n?_jsx(View,{style:U.body,children:n}):null,q?_jsx(View,{style:[U.rightBelow,H],children:u}):null]}),u&&!q||k?_jsxs(View,{style:[U.rightSlot,q?null:H],children:[q?null:u,k?_jsx(View,{style:u&&!q?U.chevronWithRight:null,children:_jsx(Chevron,{color:w?N.colors["text-disabled"]:N.colors["text-subtle"]})}):null]}):null]}),de=Y?_jsx(Pressable,{ref:Q,onPress:e=>{$&&X&&!se.isFlick(e)&&(j&&triggerHaptic(j),p?g?.(!x):y?.(e))},onPressIn:e=>{se.onPressIn(e),te()},onPressOut:ie,disabled:!$,onFocus:f,accessibilityRole:p?"checkbox":O?"menuitem":y?"button":void 0,accessibilityLabel:le,accessibilityHint:B,accessibilityState:p?{checked:x,disabled:!$,expanded:_}:{selected:S,disabled:!$,expanded:_,...void 0!==G?{checked:G}:null},"aria-disabled":!$,"aria-expanded":_,...p?{"aria-checked":x}:void 0!==G?{"aria-checked":G}:{"aria-selected":S},...void 0!==G?WEB_CHECKABLE_ROLE:null,testID:M,android_ripple:{color:N.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[z,e?U.pressed:null],...J.hostProps,children:_jsx(Animated.View,{style:ee,children:ce})}):_jsx(View,{ref:e,accessibilityRole:"none",accessibilityLabel:le,accessibilityHint:B,accessibilityState:{selected:S,disabled:w},"aria-selected":S,"aria-disabled":w,testID:M,style:z,children:ce}),me=V&&V.length>0||C&&C.length>0,ue=re?_jsxs(View,{style:[S?{backgroundColor:N.colors["surface-selected"]}:null,L?U.divider:null],children:[de,_jsx(View,{style:U.actions,children:renderActions(b)})]}):de,he=me?_jsx(Swipeable,{leftActions:V,rightActions:C,accessibilityLabel:le,children:ue}):ue;return s?_jsx(ListItemSkeleton,{...t}):J.enabled?_jsxs(_Fragment,{children:[he,J.renderSurface(_jsx(View,{style:U.preview,children:ce}))]}):he}),ListItemSkeleton=({subtitle:e,description:t,leading:i,icon:s,trailing:l,chevron:o,size:n="md",variant:r="list",style:a})=>{const c=useTheme(),d=resolveListItemSize(c,n),m=Math.round(1.15*d["title-text"]),u=Math.round(1.15*d["subtitle-text"]),h="menu"===r;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"center",paddingHorizontal:c.space.md,paddingVertical:h?c.space.sm:d["padding-y"],minHeight:h?48:d["min-height"]},a],children:[void 0!==i||void 0!==s?_jsx(View,{style:{marginRight:c.space.sm},children:_jsx(Skeleton,{shape:"circle",width:40,height:40})}):null,_jsxs(View,{style:{flex:1},children:[_jsx(Skeleton,{shape:"text",width:"70%",height:m,style:{marginBottom:c.space.xs}}),void 0!==e?_jsx(Skeleton,{shape:"text",width:"50%",height:u,style:void 0!==t?{marginBottom:c.space.xs}:void 0}):null,void 0!==t?_jsx(Skeleton,{shape:"text",width:"85%",height:u}):null]}),void 0!==l||o?_jsx(View,{style:{marginLeft:c.space.sm},children:_jsx(Skeleton,{width:20,height:20,radius:"sm"})}):null]})};ListItemSkeleton.displayName="ListItemSkeleton";const ListItem=Object.assign(ListItemRoot,{Skeleton:ListItemSkeleton});ListItem.displayName="ListItem";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.md},divider:{borderBottomWidth:StyleSheet.hairlineWidth,borderBottomColor:e.colors.border},pressed:{backgroundColor:e.colors["surface-pressed"]},disabled:{opacity:.55},leftSlot:{marginRight:e.space.md,alignItems:"center",justifyContent:"center"},middle:{flex:1,flexDirection:"column",justifyContent:"center"},selectionLead:{flexDirection:"row",alignItems:"center"},selectionLeadContent:{marginLeft:e.space.sm},body:{marginTop:e.space.xs},rightBelow:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",marginTop:e.space.xs},rightSlot:{marginLeft:e.space.md,alignItems:"center",justifyContent:"center",flexDirection:"row"},actions:{flexDirection:"row",flexWrap:"wrap",gap:e.space.sm,paddingHorizontal:e.space.md,paddingBottom:e.space.md},chevronWithRight:{marginLeft:e.space.xs},preview:{flex:1,backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},title:{letterSpacing:e["letter-spacing"].normal},subtitle:{marginTop:e.space.xxs,...fontFor(e,"normal")},menuSubtitle:{marginTop:0},description:{marginTop:e.space.xxs,...fontFor(e,"normal")}}),stylesFor=themeStyles(buildStyles);export{ListItem};export default ListItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useMobileUiText}from"../../text/index.js";import{MODAL_TEXT}from"../../text/phone/modal.g.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9;function Modal({ref:e,...t}){assertValidValue("Modal","presentation",t.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:x="center",testID:A,bare:y=!1,onInsetsChange:M}=t,C=useTheme(),w=useMobileUiText("modal",MODAL_TEXT),D=useMemo(()=>({...w,...b}),[w,b]),R=usePresenceMotion(),[V,T]=useModalInsets();useEffect(()=>{M?.(V)},[V,M]);const{width:j,height:E}=useWindowDimensions(),[_,I]=useState({width:0,height:0}),k=a??R.duration("default"),H=E,N=useRef(!l&&o),P=N.current,L=useRef(createAnimatedValue(P?1:.9)).current,O=useRef(createAnimatedValue(P?1:0)).current,W=useRef(createAnimatedValue(P?0:H)).current,q=useRef(createAnimatedValue(P?1:0)).current,z=useRef(null),F=useRef(!1),[B,U]=useState(o),K=useMemo(()=>buildStyles(C),[C]),X=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(v,_,e,S,{align:x});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,_,S,x,j,E,V.top,V.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>q.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[q,G]);useEffect(()=>{o&&(Keyboard.dismiss(),U(!0))},[o]),useEffect(()=>{const e=[];if(o&&B&&N.current)N.current=!1;else if(o&&B){const t=Animated.timing(q,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===i){O.setValue(0),W.setValue(0),L.setValue(1);const t=Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){O.setValue(1);const t=Animated.spring(W,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(L,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(B){const t=R.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(O,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=R.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(W,{toValue:H,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(L,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(q,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(W.setValue(H),U(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,B,i,k,L,O,q,W,H,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,R,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{z.current&&AccessibilityInfo.sendAccessibilityEvent(z.current,"focus")},150),F.current=!0):F.current&&(F.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},k))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,k,f]);const $=useRef(h);$.current=h;const J=useRef(!1);useEffect(()=>{if(o)return void(J.current=!0);if(!J.current)return;J.current=!1;const e=setTimeout(()=>$.current?.(),300);return()=>clearTimeout(e)},[o]);const Q=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),ee=useSquircle(!y&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),te=useCallback(e=>{ee.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;I(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[ee.onLayout]),oe=useMemo(()=>y?"bottom"===i?K.bottomContent:"fullScreen"===i?K.fullScreenContent:K.bareCentredContent:"anchored"===i?[K.anchoredContent,{left:X?.x,top:X?.y,maxHeight:X?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[K.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[K.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+V.bottom},C.shadow.modal]:[K.centeredContent,{backgroundColor:C.colors.surface,borderRadius:ee.active&&ee.size?squircleHostRadius(ee.size.width,ee.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,K,V.bottom,ee.active,ee.size,X,y]),re=useMemo(()=>"anchored"===i?K.anchoredWrapper:"bottom"===i?K.bottomWrapper:"fullScreen"===i?K.fullScreenWrapper:K.centeredWrapper,[i,K]),ie=useMemo(()=>"bottom"===i?{opacity:O,transform:[{translateY:W}]}:"fullScreen"===i||"anchored"===i?{opacity:O}:{opacity:O,transform:[{scale:L}]},[i,L,O,W]);if("anchored"===i&&void 0===v)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(y&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:B,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:A,children:_jsx(View,{ref:t=>{z.current=t,"function"==typeof e?e(t):e&&(e.current=t)},style:K.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:T,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,re,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Q,accessibilityRole:n?"button":void 0,accessibilityLabel:n?D.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n,testID:A?`${A}-backdrop`:void 0}),_jsxs(Animated.View,{style:[oe,ie,_.height>0||"anchored"!==i?null:K.unmeasured,m],onLayout:te,pointerEvents:y&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[ee.active&&ee.size?_jsx(SquircleFill,{width:ee.size.width,height:ee.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})}const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import React,{
|
|
1
|
+
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useMobileUiText}from"../../text/index.js";import{NUMBER_INPUT_TEXT}from"../../text/phone/numberInput.g.js";import{resolveFieldSize,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{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"],DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i};function NumberInput({ref:e,...t}){const{value:i,defaultValue:s,onChange:l,min:r=Number.NEGATIVE_INFINITY,max:n=Number.POSITIVE_INFINITY,step:a=1,allowDecimal:o=!1,precision:c=0,label:u,help:d,helperText:m,error:b,disabled:p=!1,size:f="md",variant:x="inline",unit:h,haptic:T,labels:y,accessibilityLabel:S,style:g,inputStyle:I,buttonStyle:N,unitStyle:_,labelStyle:F,textInputProps:j,testID:v}=t;assertValidValue("NumberInput","size",t.size,NUMBER_INPUT_SIZES),assertValidValue("NumberInput","variant",t.variant,NUMBER_INPUT_VARIANTS);const V=useMobileUiText("numberInput",NUMBER_INPUT_TEXT),C=useMemo(()=>({...V,...y}),[V,y]),[E,R]=useControllableState({value:i,defaultValue:s??t.min??0,onChange:l}),P=useTheme(),z=resolveFieldSize(P,f),w=resolveFieldTextStyle(P,{disabled:p}),A=useMemo(()=>buildStyles(P),[P]),M=useRef(null),[L,U]=useState(formatValue(E,o,c)),[k,B]=useState(!1),[D,H]=useState(!1),O=useCallback(()=>{p||M.current?.focus()},[p]),G=useRef(null),W=useRef(null),Y=useCallback(()=>{null!==G.current&&(clearTimeout(G.current),G.current=null),null!==W.current&&(clearInterval(W.current),W.current=null)},[]);useEffect(()=>Y,[Y]),useEffect(()=>{k||U(formatValue(E,o,c))},[E,o,c,k]);const $=E<=r,X=E>=n,Z=!p,q=useCallback(e=>{const t=roundToPrecision(e,o?c:0),i=clamp(t,r,n);i!==E&&R(i)},[o,n,r,R,c,E]),J=useCallback(()=>{if(!Z||$)return;const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),q(E-a)},[$,Z,T,q,a,E]),K=useCallback(()=>{if(!Z||X)return;const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),q(E+a)},[X,Z,T,q,a,E]);React.useImperativeHandle(e,()=>({focus:()=>M.current?.focus(),blur:()=>M.current?.blur(),clear:()=>{U(""),Number.isFinite(r)&&r>0?R(r):R(0<r?r:Math.min(n,0))}}),[n,r,R]);const Q=useCallback(e=>{Z&&(Y(),G.current=setTimeout(()=>{W.current=setInterval(()=>{"inc"===e?K():J()},80)},500))},[Y,J,K,Z]),ee=useCallback(e=>{reportIdleActivity();const t=sanitizeTyped(e,o);U(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=r&&i<=n&&i!==E&&R(roundToPrecision(i,o?c:0))},[o,n,r,R,c,E]),te=useCallback(()=>{B(!1),H(!1);const e=Number(L);if(""===L||!Number.isFinite(e))return void U(formatValue(E,o,c));const t=roundToPrecision(e,o?c:0),i=clamp(t,r,n);i!==E&&R(i),U(formatValue(i,o,c))},[o,L,n,r,R,c,E]),ie=useCallback(()=>{B(!0),H(!0)},[]),se=$||p?P.colors["text-disabled"]:P.colors["text-body"],le=X||p?P.colors["text-disabled"]:P.colors["text-body"],re=z.icon+8,renderStepper=(e,t,i,s,l,r)=>_jsx(Pressable,{onPress:t,onLongPress:()=>Q(e),onPressOut:Y,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:re,height:re,alignItems:"center",justifyContent:"center",borderRadius:P.radius.pill,...smoothCorners},e&&!i?{backgroundColor:P.colors["surface-pressed"]}:null,N],testID:`${v??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:_jsx(Text,{variant:"body",weight:"semibold",style:{fontSize:z.icon,color:l,fontWeight:P.weight.semibold,lineHeight:z.icon+2},children:r})}),ne=S??fieldTextAsString(u)??C.input,ae=!0===b||hasFieldText(b),oe=_jsx(FieldBase,{testID:v?`${v}-field`:void 0,size:f,disabled:p,error:ae,filled:!0,focused:D,onPress:O,pressFeedback:!1,leading:renderStepper("dec",J,$||p,C.decrease,se,"−"),trailing:renderStepper("inc",K,X||p,C.increase,le,"+"),children:_jsxs(View,{style:A.inputRow,children:[_jsx(TextInput,{ref:M,value:L,onChangeText:ee,onFocus:ie,onBlur:te,editable:!p,keyboardType:o?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ne,accessibilityValue:{now:Number.isFinite(E)?E:0},accessibilityState:{disabled:p},"aria-disabled":p,accessibilityActions:[{name:"increment",label:C.increase},{name:"decrement",label:C.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&K(),"decrement"===e.nativeEvent.actionName&&J()},style:[A.input,{fontSize:z.text,color:w.color,...w.weightStyle},I],...j}),h?_jsx(Text,{variant:"bodySmall",style:[A.unit,{fontSize:z.text,color:w.placeholderColor},_],children:h}):null]})}),ce=hasFieldText(u)?_jsx(FieldLabel,{size:f,help:d,style:F,children:u}):null,ue=_jsx(FieldMessage,{size:f,error:ae,text:ae?b:m});return _jsxs(View,"horizontal"===x?{style:[A.horizontalContainer,g],testID:v,accessibilityState:{disabled:p},"aria-disabled":p,children:[_jsx(View,{style:A.horizontalLabelWrap,children:ce}),_jsxs(View,{children:[oe,ue]})]}:{style:[g],testID:v,accessibilityState:{disabled:p},"aria-disabled":p,children:[ce,oe,ue]})}const buildStyles=e=>StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});export{NumberInput};export default NumberInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{
|
|
1
|
+
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{fillText,useMobileUiText}from"../../text/index.js";import{OTP_INPUT_TEXT}from"../../text/phone/otpInput.g.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const cellAt=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`OTP cell ${t} is outside the ${e.length} cells.`);return i},sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"";function OTPInput({ref:e,...t}){const{value:i,defaultValue:n,onChange:r,onComplete:s,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:x,cellStyle:y,textStyle:v,testID:T}=t;assertValidValue("OTPInput","size",t.size,["sm","md","lg"]),assertValidValue("OTPInput","keyboardType",t.keyboardType,["number-pad","default"]);const j=useMobileUiText("otpInput",OTP_INPUT_TEXT),V=useMemo(()=>({...j,...g}),[j,g]),[A,C]=useControllableState({value:i,defaultValue:n??"",onChange:r}),k=useTheme(),I=useMemo(()=>buildStyles(k),[k]),w=resolveOtpInputSize(k,m),E=k.components["otp-input"][m].radius,S=useRef([]),[M,D]=useState(-1),[F,_]=useState(0),O=useRef(null),P=useRef(createAnimatedValue(0)).current,z=useRef(new Map),R=useMemo(()=>{const e=z.current,t=[];for(let i=0;i<a;i+=1){let n=e.get(i);n||(n=new Animated.Value(0),e.set(i,n)),t.push(n)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),N=useRef(-1),H=k.settings.components["otp-input"]?.shakeOnError??!1,B=useReducedMotion(),L=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===O.current||!L||O.current||(f&&triggerHaptic("notificationError"),H&&!B&&(setNativeValue(P,0),e=Animated.sequence([Animated.timing(P,{toValue:1,duration:k.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:-1,duration:k.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:1,duration:k.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:0,duration:k.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver})]),e.start())),O.current=L,()=>e?.stop()},[L,P,H,f,B,k.motion.duration.instant]),useEffect(()=>{const e=N.current;if(N.current=M,e===M)return;if(-1===e&&-1===M)return;const t=[];return R.forEach((i,n)=>{const r=n===M?1:0;if(n!==M&&n!==e)return;const s=Animated.timing(i,{toValue:r,duration:k.motion.duration.fast,easing:Easing.bezier(...k.motion.ease["in-out"]),useNativeDriver:nativeDriver});s.start(),t.push(s)}),()=>t.forEach(e=>{e.stop()})},[M,R,k]);const U=useCallback(e=>{const t=S.current[e];t&&t.focus()},[]);useImperativeHandle(e,()=>({focus:()=>U(0),blur:()=>{const e=S.current[Math.max(M,0)];e?.blur()},clear:()=>{C(""),U(0)}}),[U,M,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>U(0),u);return()=>clearTimeout(e)}},[l,u,c,U]);const W=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(A.length,a);t+=1)e[t]=A.charAt(t);return e},[A,a]),X=useMemo(()=>W.map((e,t)=>({key:`otp-cell-${t}`,index:t,char:e})),[W]),$=useCallback(e=>{const t=e.slice(0,a);t!==A&&(C(t),t.length===a&&s&&s(t))},[a,C,s,A]),q=useCallback((e,t)=>{const i=t.replace(/\u200B/g,""),n=sanitizeChar(i,o);if(!n){const t=W.slice(),i=cellAt(W,e).length>0;if(t[e]="",$(t.join("").slice(0,a)),!i&&e>0){const t=W.slice();t[e-1]="",$(t.join("")),U(e-1)}return}const r=cellAt(W,e),s=r&&n.length>a&&n.startsWith(r)?n.slice(r.length):n;if(s.length>=a){const t=s.slice(0,a),i=A.length;return $(t),t.length!==i&&f&&triggerHaptic(f),void S.current[e]?.blur()}const l=W.slice();let u=e;for(let e=0;e<n.length&&u<a;e+=1)l[u]=n.charAt(e),u+=1;const c=l.join("").slice(0,a),d=A.length;$(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?S.current[e]?.blur():U(m)},[W,U,o,a,f,$,A]),G=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===cellAt(W,e).length){if(e>0){const t=W.slice();t[e-1]="",$(t.join("")),U(e-1)}}else{const t=W.slice();t[e]="",$(t.join(""))}},[W,U,$]),K=useCallback((e,t)=>{D(e),h?.(t)},[h]),J=useCallback(()=>{D(-1)},[]),Q=useCallback(()=>{if(c)return;const e=W.indexOf("");U(-1===e?a-1:e)},[W,c,U,a]),Y=useCallback(e=>{_(e.nativeEvent.layout.width)},[]),Z=b??fillText(V.field,{length:a}),ee=F>0?Math.max(24,Math.min(w.cell,Math.floor((F-w.gap*(a-1))/a))):w.cell,te=P.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:x,onLayout:Y,accessible:!0,accessibilityRole:"none",accessibilityLabel:Z,accessibilityValue:{text:i},accessibilityState:{disabled:c},"aria-disabled":c,testID:T,children:[_jsx(Pressable,{onPress:Q,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[I.row,{columnGap:w.gap,transform:[{translateX:te}]}],children:X.map(({key:e,index:t,char:i})=>{const n=M===t,r=i.length>0,s=L?k.colors["danger-border"]:k.colors["focus-ring"],l=R[t];if(!l)return null;const u=p&&r?"●":i;return _jsxs(View,{style:I.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:ee,height:ee,radius:E,borderWidth:1.5,focused:n,error:L,filled:r,disabled:c,paddingHorizontal:k.space.none,paddingVertical:k.space.none,gap:k.space.none,style:y,children:[_jsx(TextInput,{ref:e=>{S.current[t]=e},value:(p&&r?"":i)||"",onChangeText:e=>{reportIdleActivity(),q(t,e)},onKeyPress:e=>G(t,e),onFocus:e=>K(t,e),onBlur:J,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:r,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[I.input,{fontSize:w.text,color:k.colors["text-body"],...fontFor(k,"semibold")},v]}),p&&r?_jsx(View,{pointerEvents:"none",style:I.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:w.text},v],children:u})}):null]}),_jsx(Animated.View,{style:[I.underline,{backgroundColor:s,opacity:l}]})]},e)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})}const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{fillText,useMobileUiText}from"../../text/index.js";import{OPTION_SHEET_TEXT}from"../../text/phone/optionSheet.g.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionAction,selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,getOptionAction:b,value:g,onChange:x,multi:f=!1,searchable:y=!1,searchSelectionColor:S,accessibilityLabel:T,optionStyle:j,selectedOptionStyle:w,optionTextStyle:C,selectedOptionTextStyle:_,testID:I}=e,k=c??selectOptionLabel,O=d??selectOptionValue,R=p??selectOptionDescription,L=u??selectOptionDisabled,V=h??selectOptionIcon,D=b??selectOptionAction,v=useTheme(),H=useSafeAreaInsets(),M=useMemo(()=>buildStyles(v),[v]),[P,A]=useState(""),B=useCallback(e=>{reportIdleActivity(),A(e)},[]),z=Dimensions.get("window").height,E=Math.round(.7*z),F=useRef(createAnimatedValue(0)).current,{handleGesture:W,opacity:G}=useDragToDismiss({drag:F,travel:E,onDismiss:t,testID:I}),N=useNativeGesture(),U=useKeyboardState(e=>e.height),$=Math.max(0,Math.round(U)),K=Math.max(H.top,StatusBar.currentHeight??0)+v.space.sm,X=$>0,Y=X?Math.max(0,Math.min(E,z-$-K)):E,Z=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(R(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,R]),J=useCallback(()=>{t()},[t]),Q=useRef(null),q=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of Z.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of Z.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,Z,i,k]),ee=n&&q.size>0&&0===P.trim().length,te=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...q.has("#")?["#"]:[]],[q]),oe=useCallback(e=>{const t=q.get(e);void 0!==t&&Q.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[q]),se=useRef(null),ie=useCallback(()=>{null!==se.current&&(clearTimeout(se.current),se.current=null)},[]),re=useCallback(e=>{Q.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),ie(),se.current=setTimeout(()=>{se.current=null,Q.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[ie]);useEffect(()=>ie,[ie]);return _jsx(GestureHandlerRootView,{style:M.gestureRoot,children:_jsxs(Animated.View,{testID:I,accessibilityViewIsModal:!0,accessibilityLabel:T??o??a.fallbackName,style:[M.sheet,{maxHeight:Y,marginBottom:$,paddingBottom:X?v.space.lg:H.bottom+v.space.lg,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,opacity:G,transform:[{translateY:F}],...v.shadow.modal}],children:[_jsx(GestureDetector,{gesture:W,children:_jsxs(View,{children:[_jsx(View,{style:M.sheetHandleRow,children:_jsx(View,{style:[M.sheetHandle,{backgroundColor:v.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[M.sheetTitle,{paddingHorizontal:v.space.lg,marginBottom:v.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[M.searchWrap,{marginHorizontal:v.space.lg,marginBottom:v.space.sm}],children:_jsxs(View,{style:[M.searchBox,{backgroundColor:v.colors["bg-subtle"],borderColor:v.colors.border,borderRadius:v.radius.md,...smoothCorners,paddingHorizontal:v.space.md,gap:v.space.sm}],children:[(v.settings.icons.search??defaultIcons.search)({size:18,color:v.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:B,placeholder:a.searchPlaceholder,placeholderTextColor:v.colors["text-subtle"],selectionColor:S??v.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[M.searchInput,{color:v.colors["text-body"],fontSize:v.text.base.size,paddingVertical:v.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>A(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(v.settings.icons.close??defaultIcons.close)({size:18,color:v.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[M.listWrap,ee?M.listRow:null],children:[_jsx(GestureDetector,{gesture:N,children:_jsx(FlatList,{ref:Q,data:Z,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(O(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[M.sectionHeader,{paddingHorizontal:v.space.lg,paddingTop:v.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:M.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=O(o),n=R(o),a=V(o),c=(d=i,Array.isArray(g)?g.some(e=>String(e)===String(d)):null!=g&&String(g)===String(d));var d;const p=L(o),u=m?.(o)??!1,h=D(o),b=Boolean(a);return _jsxs(Pressable,{onPress:()=>{if(h)return h(),void J();x(i,o)},disabled:p,android_ripple:{color:v.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[M.optionRow,{backgroundColor:c?v.colors["surface-selected"]:e?v.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:v.space.lg,paddingVertical:v.space.md},j,c?w:null],children:[l?_jsx(View,{style:M.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[b?_jsx(View,{style:M.optionIcon,children:a}):null,_jsxs(View,{style:M.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[M.optionLabel,C,c?_:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:M.optionDescription,children:n}):null]})]}),f?_jsx(View,{style:[M.checkbox,{borderColor:c?v.colors.primary:v.colors.border,backgroundColor:c?v.colors.primary:"transparent"}],children:c?_jsx(View,{style:M.checkboxTick}):null}):c?"icon"===v.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:M.singleSelectedIcon,children:(v.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:v.colors.primary})}):_jsx(View,{style:[M.singleSelectedDot,{backgroundColor:v.colors.primary}]}):null]})},onScrollToIndexFailed:re,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!ee,style:ee?M.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:v.space.xl},children:a.empty})})}),ee?_jsx(View,{style:[M.rail,{paddingRight:v.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:te.map(e=>{const t=q.has(e);return _jsx(Pressable,{onPress:()=>oe(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:fillText(a.jumpTo,{letter:e}),accessibilityState:{disabled:!t},"aria-disabled":!t,style:M.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[M.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),f?_jsx(View,{style:[M.sheetFooter,{borderTopColor:v.colors["border-subtle"],paddingHorizontal:v.space.lg,paddingVertical:v.space.md}],children:_jsx(Pressable,{onPress:J,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[M.doneButton,{backgroundColor:e?v.colors["primary-pressed"]:v.colors.primary,borderRadius:v.radius.md,...smoothCorners,paddingVertical:v.space.sm,paddingHorizontal:v.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:v.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMobileUiText("optionSheet",OPTION_SHEET_TEXT),c=useMemo(()=>({...a,...i}),[a,i]),d=useRef(o);d.current=o;const p=useRef(!1);return useEffect(()=>{p.current!==t&&(p.current=t,d.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:c.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??c.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:c})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
|
|
1
|
+
"use strict";import{reportIdleActivity}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,FlatList,Pressable,StatusBar,StyleSheet,TextInput,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{fillText,useMobileUiText}from"../../text/index.js";import{OPTION_SHEET_TEXT}from"../../text/phone/optionSheet.g.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionAction,selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,getOptionAction:b,value:g,onChange:x,multi:f=!1,searchable:y=!1,searchSelectionColor:S,accessibilityLabel:T,optionStyle:j,selectedOptionStyle:w,optionTextStyle:C,selectedOptionTextStyle:_,testID:I}=e,k=c??selectOptionLabel,O=d??selectOptionValue,R=p??selectOptionDescription,L=u??selectOptionDisabled,V=h??selectOptionIcon,D=b??selectOptionAction,v=useTheme(),H=useSafeAreaInsets(),M=useMemo(()=>buildStyles(v),[v]),[P,A]=useState(""),B=useCallback(e=>{reportIdleActivity(),A(e)},[]),{height:z}=useWindowDimensions(),W=Math.round(.7*z),E=useRef(createAnimatedValue(0)).current,{handleGesture:F,opacity:G}=useDragToDismiss({drag:E,travel:W,onDismiss:t,testID:I}),N=useNativeGesture(),U=useKeyboardState(e=>e.height),$=Math.max(0,Math.round(U)),K=Math.max(H.top,StatusBar.currentHeight??0)+v.space.sm,X=$>0,Y=X?Math.max(0,Math.min(W,z-$-K)):W,Z=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(R(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,R]),J=useCallback(()=>{t()},[t]),Q=useRef(null),q=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of Z.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of Z.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,Z,i,k]),ee=n&&q.size>0&&0===P.trim().length,te=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...q.has("#")?["#"]:[]],[q]),oe=useCallback(e=>{const t=q.get(e);void 0!==t&&Q.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[q]),se=useRef(null),ie=useCallback(()=>{null!==se.current&&(clearTimeout(se.current),se.current=null)},[]),re=useCallback(e=>{Q.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),ie(),se.current=setTimeout(()=>{se.current=null,Q.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[ie]);useEffect(()=>ie,[ie]);return _jsx(GestureHandlerRootView,{style:M.gestureRoot,children:_jsxs(Animated.View,{testID:I,accessibilityViewIsModal:!0,accessibilityLabel:T??o??a.fallbackName,style:[M.sheet,{maxHeight:Y,marginBottom:$,paddingBottom:X?v.space.lg:H.bottom+v.space.lg,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,opacity:G,transform:[{translateY:E}],...v.shadow.modal}],children:[_jsx(GestureDetector,{gesture:F,children:_jsxs(View,{children:[_jsx(View,{style:M.sheetHandleRow,children:_jsx(View,{style:[M.sheetHandle,{backgroundColor:v.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[M.sheetTitle,{paddingHorizontal:v.space.lg,marginBottom:v.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[M.searchWrap,{marginHorizontal:v.space.lg,marginBottom:v.space.sm}],children:_jsxs(View,{style:[M.searchBox,{backgroundColor:v.colors["bg-subtle"],borderColor:v.colors.border,borderRadius:v.radius.md,...smoothCorners,paddingHorizontal:v.space.md,gap:v.space.sm}],children:[(v.settings.icons.search??defaultIcons.search)({size:18,color:v.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:B,placeholder:a.searchPlaceholder,placeholderTextColor:v.colors["text-subtle"],selectionColor:S??v.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[M.searchInput,{color:v.colors["text-body"],fontSize:v.text.base.size,paddingVertical:v.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>A(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(v.settings.icons.close??defaultIcons.close)({size:18,color:v.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[M.listWrap,ee?M.listRow:null],children:[_jsx(GestureDetector,{gesture:N,children:_jsx(FlatList,{ref:Q,data:Z,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(O(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[M.sectionHeader,{paddingHorizontal:v.space.lg,paddingTop:v.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:M.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=O(o),n=R(o),a=V(o),c=(d=i,Array.isArray(g)?g.some(e=>String(e)===String(d)):null!=g&&String(g)===String(d));var d;const p=L(o),u=m?.(o)??!1,h=D(o),b=Boolean(a);return _jsxs(Pressable,{onPress:()=>{if(h)return h(),void J();x(i,o)},disabled:p,android_ripple:{color:v.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[M.optionRow,{backgroundColor:c?v.colors["surface-selected"]:e?v.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:v.space.lg,paddingVertical:v.space.md},j,c?w:null],children:[l?_jsx(View,{style:M.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[b?_jsx(View,{style:M.optionIcon,children:a}):null,_jsxs(View,{style:M.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[M.optionLabel,C,c?_:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:M.optionDescription,children:n}):null]})]}),f?_jsx(View,{style:[M.checkbox,{borderColor:c?v.colors.primary:v.colors.border,backgroundColor:c?v.colors.primary:"transparent"}],children:c?_jsx(View,{style:M.checkboxTick}):null}):c?"icon"===v.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:M.singleSelectedIcon,children:(v.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:v.colors.primary})}):_jsx(View,{style:[M.singleSelectedDot,{backgroundColor:v.colors.primary}]}):null]})},onScrollToIndexFailed:re,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!ee,style:ee?M.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:v.space.xl},children:a.empty})})}),ee?_jsx(View,{style:[M.rail,{paddingRight:v.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:te.map(e=>{const t=q.has(e);return _jsx(Pressable,{onPress:()=>oe(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:fillText(a.jumpTo,{letter:e}),accessibilityState:{disabled:!t},"aria-disabled":!t,style:M.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[M.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),f?_jsx(View,{style:[M.sheetFooter,{borderTopColor:v.colors["border-subtle"],paddingHorizontal:v.space.lg,paddingVertical:v.space.md}],children:_jsx(Pressable,{onPress:J,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[M.doneButton,{backgroundColor:e?v.colors["primary-pressed"]:v.colors.primary,borderRadius:v.radius.md,...smoothCorners,paddingVertical:v.space.sm,paddingHorizontal:v.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:v.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMobileUiText("optionSheet",OPTION_SHEET_TEXT),c=useMemo(()=>({...a,...i}),[a,i]),d=useRef(o);d.current=o;const p=useRef(!1);return useEffect(()=>{p.current!==t&&(p.current=t,d.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:c.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??c.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:c})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,reportIdleActivity,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fillText,useMobileUiText}from"../../text/index.js";import{PHONE_NUMBER_INPUT_TEXT}from"../../text/phone/phoneNumberInput.g.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const i=e.replace(/[^0-9]/g,"");if(!i)return null;const n=splitPhoneNumber(`+${i}`);let l=n?.callingCode,r=n?.nationalNumber??"";if(!l){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(l=e.find(e=>i.startsWith(e)),!l)return null;r=i.slice(l.length)}const a=t.filter(e=>e.code===l),s=a.find(e=>e.iso===o)?.iso??a.find(e=>e.iso===n?.country)?.iso??n?.country??a[0]?.iso??"";return{callingCode:l,nationalNumber:r,iso:s}};const planOf=e=>isSupportedCountry(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)};export const PhoneNumberInput=forwardRef((e,t)=>{const{value:o,defaultValue:i,onChange:n,e164:l,onChangeE164:r,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:p=ALL_CALLING_CODES,popularCountries:m,hiddenCountries:b,showFlag:f=!0,renderFlag:h,renderCountry:g,showAlphabetIndex:N,defaultCountry:x,validation:y="any",maxLength:C,formatAsYouType:v=!0,countryLocked:S=!1,label:T,labelMode:I="top",labelStyle:F,placeholder:E,helperText:P,error:j,invalidMessage:_,required:L,disabled:V=!1,size:O="md",variant:A,radius:M,labels:w,haptic:k,accessibilityLabel:z,countryAccessibilityLabel:D,onFocus:R,onBlur:U,style:B,testID:$}=e;assertValidValue("PhoneNumberInput","size",e.size,["sm","md","lg"]),assertValidValue("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),assertValidValue("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),assertValidValue("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const H=useTheme(),W=useMemo(()=>buildStyles(H),[H]),q=useRef(null),G=useMobileUiText("phoneNumberInput",PHONE_NUMBER_INPUT_TEXT),Y=useMemo(()=>({...G,...w}),[G,w]),K=E??Y.placeholder,X=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),Z=useMemo(()=>b?.length?p.filter(e=>!b.includes(e.iso)):p,[p,b]),J=useMemo(()=>{if(!m?.length)return;const e=m.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:Z}]:void 0},[m,Y.popular,Y.allCountries,Z]),Q=useCallback((e,t,o)=>{if(!e)return null;if(h)return h(e);if(!f)return null;const i=countryFlagEmoji(e.iso);return i?_jsx(Text,{variant:"body",style:[W.flag,{fontSize:t}],testID:o,children:i}):null},[h,f,W.flag]),ee=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===y?"any":y):Number.POSITIVE_INFINITY;return C?Math.min(o,C):o},[C,y]),te=useCallback((e,t)=>e.slice(0,ee(t)),[ee]),oe=useCallback((e,t)=>{const o=planOf(t)??void 0,i=splitPhoneNumber(e,o);if(!i)return null;const n=i.country??t,l=p.find(e=>e.iso===n);return{callingCode:l?.code??i.callingCode,nationalNumber:te(i.nationalNumber,n),iso:l?.iso??n}},[p,te]);useState(()=>assertDefaultCountryVisible(x,Z));const ie=useMemo(()=>{const e=Z.find(e=>e.iso===(x??X))??Z[0]??p[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof i?oe(i,t.iso)??t:i??t},[p,Z,x,X,i,oe]),ne=useCallback(e=>{if(!1===y)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,y):e.nationalNumber.length>0},[y]),[le,re]=useState(ie.iso),ae=useMemo(()=>{if(void 0===l)return;const e=l?parseE164(l,p,le):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=p.find(e=>e.iso===le);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:le}},[l,p,le,ie.callingCode,te]),se=useCallback(e=>{re(e.iso),n?.(e),r?.(e.nationalNumber?formatE164(e):"",{country:p.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ne(e)})},[n,r,p,ne]),[ue,de]=useControllableState({value:o??ae,defaultValue:ie,onChange:se}),[ce,pe]=useState(!1),me=useCallback(()=>{V||q.current?.focus()},[V]),[be,fe]=useState(!1),[he,ge]=useState(!1),[Ne,xe]=useState(!1),ye=useRef(!1);useEffect(()=>{Ne||(ye.current=!1)},[Ne]);const Ce=resolveFieldSize(H,O),ve=resolveFieldTextStyle(H,{disabled:V}),Se=A??H.settings.components.field?.defaultVariant??"outline",Te="underline"===Se,Ie=H.space.md,[Fe,Ee]=useState(0),Pe=Fe+Ie+1+Ie,je=ue.nationalNumber.length>0,Le=L&&!T&&!je&&K.length>0,Ve=ce||je,Oe=Boolean(T)&&"float"===I&&Fe>0,Ae=useFloatingLabel({label:T,enabled:Oe,floated:Ve,required:L,variant:Se,sizeTokens:Ce,leadingOffset:Pe,paddingLeft:Te?H.space.none:Ce["padding-x"],color:H.colors["field-label"],style:F}),Me=useMemo(()=>p.find(e=>e.iso===ue.iso),[p,ue.iso]),we=planOf(ue.iso),ke=v&&we?formatPhoneAsTyped(ue.nationalNumber,we):ue.nationalNumber,ze=ee(ue.iso),De=0===ue.nationalNumber.length||be||!Number.isFinite(ze)?void 0:ke.length+Math.max(0,ze-ue.nationalNumber.length),Re=ne(ue);useEffect(()=>{je||ge(!1)},[je]);const Ue=we?maxNationalNumberLength(we,!1===y?"any":y):Number.POSITIVE_INFINITY,Be=ue.nationalNumber.length>=Ue,$e=!1!==y&&!1!==_&&je&&!Re&&(he||Be),He="mobile"===y?Y.invalidMobile:Y.invalid,We=hasFieldText(j)?j:$e?_||He:void 0,qe=!0===j||hasFieldText(We),Ge=useRef(Re),Ye=useRef(ue);Ye.current=ue,useEffect(()=>{Ge.current!==Re&&(Ge.current=Re,c?.(Re),Re&&d?.(formatE164(Ye.current)))},[Re,d,c]);const Ke=useCallback(e=>{if(reportIdleActivity(),e.includes("+")){const t=oe(e,ue.iso);if(t&&!S&&Z.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[Z,S,ue,oe,te,de]),Xe=useCallback(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),xe(!1);const t=resolveHaptic(k,"selection");t&&triggerHaptic(t)},[ue,k,te,de]);useImperativeHandle(t,()=>({focus:()=>q.current?.focus(),blur:()=>q.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>q.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>ne(Ye.current),getCountry:()=>p.find(e=>e.iso===Ye.current.iso)}),[p,ne,de]);const Ze=V||S,Je=_jsx(FieldBase,{testID:$?`${$}-field`:void 0,size:O,variant:Se,radius:M,topNotch:Ae.topNotch,focused:ce,disabled:V,error:qe,filled:je,onPress:me,pressFeedback:!1,leadingDivider:!0,paddingLeft:Te?H.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Ze||(ye.current=!0,xe(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:D??fillText(Y.countryButton,{callingCode:ue.callingCode}),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ee(e=>e===t?e:t)},style:W.codeTrigger,testID:$?`${$}-code`:void 0,children:[Q(Me,Ce.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[W.codeText,{color:ve.color,fontSize:Ce.text}],children:`+${ue.callingCode}`}),S?null:_jsx(Chevron,{color:V?H.colors["field-icon-disabled"]:H.colors["field-icon"],size:Ce.icon,open:Ne})]}),children:_jsxs(View,{style:W.inputWrap,children:[_jsx(TextInput,{ref:q,value:ke,maxLength:De,onChangeText:Ke,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;fe(t!==o)},onFocus:()=>{pe(!0),R?.()},onBlur:()=>{pe(!1),je&&!ye.current&&ge(!0),U?.()},editable:!V,placeholder:Oe&&!Ve||Le?void 0:K,placeholderTextColor:ve.placeholderColor,accessibilityLabel:z??T??K,selectionColor:H.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[W.input,{color:ve.color,fontSize:Ce.text,...ve.weightStyle,paddingLeft:Te?H.space.none:void 0}],testID:$?`${$}-input`:void 0}),Le?_jsx(RequiredPlaceholder,{text:K,color:ve.placeholderColor,fontSize:Ce.text,weightStyle:ve.weightStyle}):null]})});return _jsxs(View,{style:B,testID:$,children:[T&&"top"===I?_jsx(FieldLabel,{size:O,required:L,style:F,children:T}):null,_jsxs(View,{style:W.fieldWrapper,children:[Je,Ae.node]}),_jsx(FieldMessage,{size:O,error:qe,text:qe?We:P}),_jsx(OptionSheet,{open:Ne,haptic:k,onClose:()=>xe(!1),title:Y.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,H.text.lg.size),renderOption:g?({option:e,selected:t})=>g(e,{selected:t}):void 0,value:Me?.iso,onChange:(e,t)=>Xe(t),searchable:Z.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:N??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...fontFor(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});export default PhoneNumberInput;
|
|
1
|
+
"use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,reportIdleActivity,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fillText,useMobileUiText}from"../../text/index.js";import{PHONE_NUMBER_INPUT_TEXT}from"../../text/phone/phoneNumberInput.g.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const i=e.replace(/[^0-9]/g,"");if(!i)return null;const l=splitPhoneNumber(`+${i}`);let n=l?.callingCode,r=l?.nationalNumber??"";if(!n){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(n=e.find(e=>i.startsWith(e)),!n)return null;r=i.slice(n.length)}const a=t.filter(e=>e.code===n),s=a.find(e=>e.iso===o)?.iso??a.find(e=>e.iso===l?.country)?.iso??l?.country??a[0]?.iso??"";return{callingCode:n,nationalNumber:r,iso:s}};const planOf=e=>isSupportedCountry(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)};export const PhoneNumberInput=({ref:e,...t})=>{const{value:o,defaultValue:i,onChange:l,e164:n,onChangeE164:r,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:p=ALL_CALLING_CODES,popularCountries:m,hiddenCountries:b,showFlag:f=!0,renderFlag:h,renderCountry:g,showAlphabetIndex:x,defaultCountry:y,validation:C="any",maxLength:N,formatAsYouType:v=!0,countryLocked:S=!1,label:T,labelMode:I="top",labelStyle:F,placeholder:E,helperText:P,error:j,invalidMessage:_,required:L,disabled:V=!1,size:O="md",variant:A,radius:M,labels:w,haptic:k,accessibilityLabel:z,countryAccessibilityLabel:D,onFocus:U,onBlur:B,style:R,testID:$}=t;assertValidValue("PhoneNumberInput","size",t.size,["sm","md","lg"]),assertValidValue("PhoneNumberInput","variant",t.variant,["outline","filled","underline"]),assertValidValue("PhoneNumberInput","labelMode",t.labelMode,["top","float"]),assertValidValue("PhoneNumberInput","validation",!1===t.validation?void 0:t.validation,["any","mobile"]);const H=useTheme(),W=useMemo(()=>buildStyles(H),[H]),q=useRef(null),G=useMobileUiText("phoneNumberInput",PHONE_NUMBER_INPUT_TEXT),Y=useMemo(()=>({...G,...w}),[G,w]),K=E??Y.placeholder,X=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),Z=useMemo(()=>b?.length?p.filter(e=>!b.includes(e.iso)):p,[p,b]),J=useMemo(()=>{if(!m?.length)return;const e=m.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:Z}]:void 0},[m,Y.popular,Y.allCountries,Z]),Q=useCallback((e,t,o)=>{if(!e)return null;if(h)return h(e);if(!f)return null;const i=countryFlagEmoji(e.iso);return i?_jsx(Text,{variant:"body",style:[W.flag,{fontSize:t}],testID:o,children:i}):null},[h,f,W.flag]),ee=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(o,N):o},[N,C]),te=useCallback((e,t)=>e.slice(0,ee(t)),[ee]),oe=useCallback((e,t)=>{const o=planOf(t)??void 0,i=splitPhoneNumber(e,o);if(!i)return null;const l=i.country??t,n=p.find(e=>e.iso===l);return{callingCode:n?.code??i.callingCode,nationalNumber:te(i.nationalNumber,l),iso:n?.iso??l}},[p,te]);useState(()=>assertDefaultCountryVisible(y,Z));const ie=useMemo(()=>{const e=Z.find(e=>e.iso===(y??X))??Z[0]??p[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof i?oe(i,t.iso)??t:i??t},[p,Z,y,X,i,oe]),le=useCallback(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,re]=useState(ie.iso),ae=useMemo(()=>{if(void 0===n)return;const e=n?parseE164(n,p,ne):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=p.find(e=>e.iso===ne);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:ne}},[n,p,ne,ie.callingCode,te]),se=useCallback(e=>{re(e.iso),l?.(e),r?.(e.nationalNumber?formatE164(e):"",{country:p.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:le(e)})},[l,r,p,le]),[ue,de]=useControllableState({value:o??ae,defaultValue:ie,onChange:se}),[ce,pe]=useState(!1),me=useCallback(()=>{V||q.current?.focus()},[V]),[be,fe]=useState(!1),[he,ge]=useState(!1),[xe,ye]=useState(!1),Ce=useRef(!1);useEffect(()=>{xe||(Ce.current=!1)},[xe]);const Ne=resolveFieldSize(H,O),ve=resolveFieldTextStyle(H,{disabled:V}),Se=A??H.settings.components.field?.defaultVariant??"outline",Te="underline"===Se,Ie=H.space.md,[Fe,Ee]=useState(0),Pe=Fe+Ie+1+Ie,je=ue.nationalNumber.length>0,Le=L&&!T&&!je&&K.length>0,Ve=ce||je,Oe=Boolean(T)&&"float"===I&&Fe>0,Ae=useFloatingLabel({label:T,enabled:Oe,floated:Ve,required:L,variant:Se,sizeTokens:Ne,leadingOffset:Pe,paddingLeft:Te?H.space.none:Ne["padding-x"],color:H.colors["field-label"],style:F}),Me=useMemo(()=>p.find(e=>e.iso===ue.iso),[p,ue.iso]),we=planOf(ue.iso),ke=v&&we?formatPhoneAsTyped(ue.nationalNumber,we):ue.nationalNumber,ze=ee(ue.iso),De=0===ue.nationalNumber.length||be||!Number.isFinite(ze)?void 0:ke.length+Math.max(0,ze-ue.nationalNumber.length),Ue=le(ue);useEffect(()=>{je||ge(!1)},[je]);const Be=we?maxNationalNumberLength(we,!1===C?"any":C):Number.POSITIVE_INFINITY,Re=ue.nationalNumber.length>=Be,$e=!1!==C&&!1!==_&&je&&!Ue&&(he||Re),He="mobile"===C?Y.invalidMobile:Y.invalid,We=hasFieldText(j)?j:$e?_||He:void 0,qe=!0===j||hasFieldText(We),Ge=useRef(Ue),Ye=useRef(ue);Ye.current=ue,useEffect(()=>{Ge.current!==Ue&&(Ge.current=Ue,c?.(Ue),Ue&&d?.(formatE164(Ye.current)))},[Ue,d,c]);const Ke=useCallback(e=>{if(reportIdleActivity(),e.includes("+")){const t=oe(e,ue.iso);if(t&&!S&&Z.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[Z,S,ue,oe,te,de]),Xe=useCallback(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),ye(!1);const t=resolveHaptic(k,"selection");t&&triggerHaptic(t)},[ue,k,te,de]);useImperativeHandle(e,()=>({focus:()=>q.current?.focus(),blur:()=>q.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>q.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>le(Ye.current),getCountry:()=>p.find(e=>e.iso===Ye.current.iso)}),[p,le,de]);const Ze=V||S,Je=_jsx(FieldBase,{testID:$?`${$}-field`:void 0,size:O,variant:Se,radius:M,topNotch:Ae.topNotch,focused:ce,disabled:V,error:qe,filled:je,onPress:me,pressFeedback:!1,leadingDivider:!0,paddingLeft:Te?H.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Ze||(Ce.current=!0,ye(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:D??fillText(Y.countryButton,{callingCode:ue.callingCode}),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ee(e=>e===t?e:t)},style:W.codeTrigger,testID:$?`${$}-code`:void 0,children:[Q(Me,Ne.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[W.codeText,{color:ve.color,fontSize:Ne.text}],children:`+${ue.callingCode}`}),S?null:_jsx(Chevron,{color:V?H.colors["field-icon-disabled"]:H.colors["field-icon"],size:Ne.icon,open:xe})]}),children:_jsxs(View,{style:W.inputWrap,children:[_jsx(TextInput,{ref:q,value:ke,maxLength:De,onChangeText:Ke,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;fe(t!==o)},onFocus:()=>{pe(!0),U?.()},onBlur:()=>{pe(!1),je&&!Ce.current&&ge(!0),B?.()},editable:!V,placeholder:Oe&&!Ve||Le?void 0:K,placeholderTextColor:ve.placeholderColor,accessibilityLabel:z??T??K,selectionColor:H.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[W.input,{color:ve.color,fontSize:Ne.text,...ve.weightStyle,paddingLeft:Te?H.space.none:void 0}],testID:$?`${$}-input`:void 0}),Le?_jsx(RequiredPlaceholder,{text:K,color:ve.placeholderColor,fontSize:Ne.text,weightStyle:ve.weightStyle}):null]})});return _jsxs(View,{style:R,testID:$,children:[T&&"top"===I?_jsx(FieldLabel,{size:O,required:L,style:F,children:T}):null,_jsxs(View,{style:W.fieldWrapper,children:[Je,Ae.node]}),_jsx(FieldMessage,{size:O,error:qe,text:qe?We:P}),_jsx(OptionSheet,{open:xe,haptic:k,onClose:()=>ye(!1),title:Y.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,H.text.lg.size),renderOption:g?({option:e,selected:t})=>g(e,{selected:t}):void 0,value:Me?.iso,onChange:(e,t)=>Xe(t),searchable:Z.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:x??Z.length>20})]})};const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...fontFor(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});export default PhoneNumberInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useMobileUiText}from"../../text/index.js";import{PICKER_TRIGGER_TEXT}from"../../text/phone/pickerTrigger.g.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function PickerTrigger(e){assertValidValue("PickerTrigger","size",e.size,["sm","md","lg"]),assertValidValue("PickerTrigger","variant",e.variant,["outline","filled","underline"]);const{value:i,placeholder:l,label:t,help:r,helperText:s,error:o,required:a=!1,onPress:n,clearable:d=!1,onClear:c,leftIcon:x,trailing:u,disabled:g=!1,size:m="md",variant:b,style:T,triggerStyle:y,valueStyle:h,labelStyle:p,messageStyle:f,accessibilityLabel:j,labels:S,testID:v}=e,F=useMobileUiText("pickerTrigger",PICKER_TRIGGER_TEXT),_=useMemo(()=>({...F,...S}),[F,S]),P=useTheme(),z=useMemo(()=>buildStyles(P),[P]),R=resolveFieldSize(P,m),V=resolveFieldTextStyle(P,{disabled:g}),k="string"==typeof i&&i.length>0,M=!0===o||hasFieldText(o),w=hasFieldText(t),I=k?i:l??_.placeholder,C=k?V.color:V.placeholderColor,E=k?`${fieldTextAsString(t)??_.selection}: ${i}`:l??_.noSelection,L=j??E,q={disabled:g},B=void 0===u,G=d&&k&&!g;return _jsxs(View,{style:[z.root,T],testID:v,children:[w?_jsx(FieldLabel,{size:m,required:a,help:r,style:p,children:t}):null,_jsx(FieldBase,{size:m,variant:b,disabled:g,error:M,filled:k,onPress:n,leading:x,trailing:G||B||null!==u?_jsxs(View,{style:z.trailingRow,children:[G?_jsx(Text,{variant:"body",onPress:()=>{g||c?.()},accessibilityRole:"button",accessibilityLabel:_.clear,style:{fontSize:R.icon,color:P.colors["text-muted"],paddingHorizontal:P.space.xs},children:"×"}):null,void 0!==u?u:B?_jsx(Chevron,{size:R.icon,color:g?P.colors["text-disabled"]:P.colors["text-subtle"]}):null]}):null,accessibilityLabel:L,accessibilityState:q,accessibilityRole:"button",style:y,children:_jsxs(Text,{variant:"body",numberOfLines:1,style:[z.valueText,{color:C,fontSize:R.text,...V.weightStyle},h],children:[I,k||!a||w?null:_jsx(RequiredMark,{})]})}),_jsx(FieldMessage,{size:m,error:M,text:M?o:s,style:f})]})}const buildStyles=e=>StyleSheet.create({root:{width:"100%"},label:{includeFontPadding:!1},valueText:{flex:1,includeFontPadding:!1},message:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center"}});export{PickerTrigger};export default PickerTrigger;
|