@webority/mobile-ui 0.144.2 → 0.145.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.
Files changed (174) hide show
  1. package/dist/canvas-kit/kit.js +4429 -3708
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/Accordion/Accordion.js +1 -1
  5. package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
  6. package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +1 -1
  7. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  8. package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
  9. package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
  10. package/lib/commonjs/components/AuthedImage/AuthedImage.js +1 -1
  11. package/lib/commonjs/components/Autocomplete/Autocomplete.js +1 -1
  12. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  13. package/lib/commonjs/components/Badge/Badge.js +1 -1
  14. package/lib/commonjs/components/Banner/Banner.js +1 -1
  15. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  16. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  17. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  18. package/lib/commonjs/components/Button/Button.js +1 -1
  19. package/lib/commonjs/components/Calendar/Calendar.js +1 -1
  20. package/lib/commonjs/components/Card/Card.js +1 -1
  21. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  22. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  23. package/lib/commonjs/components/Chip/Chip.js +1 -1
  24. package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
  25. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  26. package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
  27. package/lib/commonjs/components/Dialog/Dialog.js +1 -1
  28. package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
  29. package/lib/commonjs/components/Divider/Divider.js +1 -1
  30. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  31. package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
  32. package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
  33. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  34. package/lib/commonjs/components/FileViewer/FileViewer.js +1 -1
  35. package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
  36. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  37. package/lib/commonjs/components/FormField/FormField.js +1 -1
  38. package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
  39. package/lib/commonjs/components/IconButton/IconButton.js +1 -1
  40. package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
  41. package/lib/commonjs/components/Input/Input.js +1 -1
  42. package/lib/commonjs/components/ListItem/ListItem.js +1 -1
  43. package/lib/commonjs/components/ListSection/ListSection.js +1 -1
  44. package/lib/commonjs/components/Menu/Menu.js +1 -1
  45. package/lib/commonjs/components/Menu/useContextMenu.js +1 -1
  46. package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
  47. package/lib/commonjs/components/Modal/Modal.js +1 -1
  48. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  49. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  50. package/lib/commonjs/components/PermissionPrompt/PermissionPrompt.js +1 -1
  51. package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  52. package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
  53. package/lib/commonjs/components/ProfileCompletion/ProfileCompletion.js +1 -1
  54. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  55. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  56. package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
  57. package/lib/commonjs/components/Radio/Radio.js +1 -1
  58. package/lib/commonjs/components/Rating/Rating.js +1 -1
  59. package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
  60. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  61. package/lib/commonjs/components/SectionHeader/SectionHeader.js +1 -1
  62. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  63. package/lib/commonjs/components/Select/Select.js +1 -1
  64. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  65. package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
  66. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  67. package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
  68. package/lib/commonjs/components/Slider/Slider.js +1 -1
  69. package/lib/commonjs/components/SliderField/SliderField.js +1 -1
  70. package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
  71. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  72. package/lib/commonjs/components/StatTile/StatTile.js +1 -1
  73. package/lib/commonjs/components/StatusBadge/StatusBadge.js +1 -1
  74. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  75. package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
  76. package/lib/commonjs/components/Switch/Switch.js +1 -1
  77. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  78. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  79. package/lib/commonjs/components/Text/Text.js +1 -1
  80. package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
  81. package/lib/commonjs/components/Timeline/Timeline.js +1 -1
  82. package/lib/commonjs/components/Toast/Toast.js +1 -1
  83. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  84. package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
  85. package/lib/commonjs/utils/assertValidValue.js +1 -0
  86. package/lib/module/components/Accordion/Accordion.js +1 -1
  87. package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
  88. package/lib/module/components/AnimatePresence/AnimatePresence.js +1 -1
  89. package/lib/module/components/AppBar/AppBar.js +1 -1
  90. package/lib/module/components/AppIcon/AppIcon.js +1 -1
  91. package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
  92. package/lib/module/components/AuthedImage/AuthedImage.js +1 -1
  93. package/lib/module/components/Autocomplete/Autocomplete.js +1 -1
  94. package/lib/module/components/Avatar/Avatar.js +1 -1
  95. package/lib/module/components/Badge/Badge.js +1 -1
  96. package/lib/module/components/Banner/Banner.js +1 -1
  97. package/lib/module/components/BarChart/BarChart.js +1 -1
  98. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  99. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  100. package/lib/module/components/Button/Button.js +1 -1
  101. package/lib/module/components/Calendar/Calendar.js +1 -1
  102. package/lib/module/components/Card/Card.js +1 -1
  103. package/lib/module/components/Carousel/Carousel.js +1 -1
  104. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  105. package/lib/module/components/Chip/Chip.js +1 -1
  106. package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
  107. package/lib/module/components/Confetti/Confetti.js +1 -1
  108. package/lib/module/components/Descriptions/Descriptions.js +1 -1
  109. package/lib/module/components/Dialog/Dialog.js +1 -1
  110. package/lib/module/components/Dialog/OverlayActions.js +1 -1
  111. package/lib/module/components/Divider/Divider.js +1 -1
  112. package/lib/module/components/Drawer/Drawer.js +1 -1
  113. package/lib/module/components/EmptyState/EmptyState.js +1 -1
  114. package/lib/module/components/FieldBase/FieldBase.js +1 -1
  115. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  116. package/lib/module/components/FileViewer/FileViewer.js +1 -1
  117. package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
  118. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  119. package/lib/module/components/FormField/FormField.js +1 -1
  120. package/lib/module/components/IconBadge/IconBadge.js +1 -1
  121. package/lib/module/components/IconButton/IconButton.js +1 -1
  122. package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
  123. package/lib/module/components/Input/Input.js +1 -1
  124. package/lib/module/components/ListItem/ListItem.js +1 -1
  125. package/lib/module/components/ListSection/ListSection.js +1 -1
  126. package/lib/module/components/Menu/Menu.js +1 -1
  127. package/lib/module/components/Menu/useContextMenu.js +1 -1
  128. package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
  129. package/lib/module/components/Modal/Modal.js +1 -1
  130. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  131. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  132. package/lib/module/components/PermissionPrompt/PermissionPrompt.js +1 -1
  133. package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  134. package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
  135. package/lib/module/components/ProfileCompletion/ProfileCompletion.js +1 -1
  136. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  137. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  138. package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
  139. package/lib/module/components/Radio/Radio.js +1 -1
  140. package/lib/module/components/Rating/Rating.js +1 -1
  141. package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
  142. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  143. package/lib/module/components/SectionHeader/SectionHeader.js +1 -1
  144. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  145. package/lib/module/components/Select/Select.js +1 -1
  146. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  147. package/lib/module/components/Skeleton/Skeleton.js +1 -1
  148. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  149. package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
  150. package/lib/module/components/Slider/Slider.js +1 -1
  151. package/lib/module/components/SliderField/SliderField.js +1 -1
  152. package/lib/module/components/Sparkline/Sparkline.js +1 -1
  153. package/lib/module/components/Spinner/Spinner.js +1 -1
  154. package/lib/module/components/StatTile/StatTile.js +1 -1
  155. package/lib/module/components/StatusBadge/StatusBadge.js +1 -1
  156. package/lib/module/components/Stepper/Stepper.js +1 -1
  157. package/lib/module/components/Swipeable/Swipeable.js +1 -1
  158. package/lib/module/components/Switch/Switch.js +1 -1
  159. package/lib/module/components/Tabs/Tabs.js +1 -1
  160. package/lib/module/components/TagInput/TagInput.js +1 -1
  161. package/lib/module/components/Text/Text.js +1 -1
  162. package/lib/module/components/TimePicker/TimePicker.js +1 -1
  163. package/lib/module/components/Timeline/Timeline.js +1 -1
  164. package/lib/module/components/Toast/Toast.js +1 -1
  165. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  166. package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
  167. package/lib/module/utils/assertValidValue.js +1 -0
  168. package/lib/typescript/commonjs/utils/assertValidValue.d.ts +10 -0
  169. package/lib/typescript/module/utils/assertValidValue.d.ts +10 -0
  170. package/package.json +7 -7
  171. package/lib/commonjs/utils/warnInvalidValue.js +0 -1
  172. package/lib/module/utils/warnInvalidValue.js +0 -1
  173. package/lib/typescript/commonjs/utils/warnInvalidValue.d.ts +0 -10
  174. package/lib/typescript/module/utils/warnInvalidValue.d.ts +0 -10
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];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-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:i,threshold:o,fullSwipeThreshold:s,onSwipeOpen:r,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),w=o??80,b=s??200,f=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,v=!!i&&i.length>0,x=Dimensions.get("window").width,I=y?w*(n?.length??0):0,A=v?w*(i?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,r?.(e))},[r]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:i,o=t?.[0];o&&(!1!==c&&triggerHaptic("notificationSuccess"),o.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,i,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=I,t=A,n=b,i=-b,o=x,s=-x,r=w,a=y,c=v;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const i=C.value+n.translationX;_.value=i>0&&!a||i<0&&!c?0:i>e&&a?e+.35*(i-e):i<-t&&c?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(o,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=i?(_.value=withSpring(s,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=r?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-r?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,b,y,v,I,G,j,A,x,w,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,_.value/I)):0}),[I,_]),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,-_.value/A)):0}),[A,_]),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,i]),D=useCallback(e=>{const t=e.nativeEvent.actionName,o=[...n??[],...i??[]].find(e=>e.key===t);o&&(!1!==c&&triggerHaptic("selection"),o.onPress())},[n,i,c]);return y||v?_jsxs(View,{style:[f.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[f.actionsRow,f.actionsLeft,{width:I},m,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,v?_jsx(Animated.View,{style:[f.actionsRow,f.actionsRight,{width:A},m,V],pointerEvents:"box-none",children:i?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[f.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:i,onPress:o})=>{warnInvalidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const s=e.tone??"neutral",r=toneToBg(t,s),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,s),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>o(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:i,backgroundColor:r,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,s)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];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-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:i,threshold:s,fullSwipeThreshold:o,onSwipeOpen:r,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),b=s??80,f=o??200,w=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,x=!!i&&i.length>0,v=Dimensions.get("window").width,A=y?b*(n?.length??0):0,I=x?b*(i?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,r?.(e))},[r]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:i,s=t?.[0];s&&(!1!==c&&triggerHaptic("notificationSuccess"),s.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,i,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=A,t=I,n=f,i=-f,s=v,o=-v,r=b,a=y,c=x;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const i=C.value+n.translationX;_.value=i>0&&!a||i<0&&!c?0:i>e&&a?e+.35*(i-e):i<-t&&c?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(s,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=i?(_.value=withSpring(o,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=r?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-r?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,f,y,x,A,G,j,I,v,b,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,_.value/A)):0}),[A,_]),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,-_.value/I)):0}),[I,_]),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,i]),D=useCallback(e=>{const t=e.nativeEvent.actionName,s=[...n??[],...i??[]].find(e=>e.key===t);s&&(!1!==c&&triggerHaptic("selection"),s.onPress())},[n,i,c]);return y||x?_jsxs(View,{style:[w.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[w.actionsRow,w.actionsLeft,{width:A},m,V],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:b,onPress:k},e.key))}):null,x?_jsx(Animated.View,{style:[w.actionsRow,w.actionsRight,{width:I},m,F],pointerEvents:"box-none",children:i?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:b,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[w.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:i,onPress:s})=>{assertValidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const o=e.tone??"neutral",r=toneToBg(t,o),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,o),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>s(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:i,backgroundColor:r,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,o)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(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.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:r,disabled:a=!1,size:o="md",tone:n="primary",label:l,description:c,helperText:d,error:u,layout:p="inline",accessibilityLabel:m,haptic:h="selection",bounce:f=!1,style:b,containerStyle:g,trackStyle:w,thumbStyle:y,testID:x,hitSlop:S,...j}=e,T=useTheme(),v=Object.keys(T.components.switch);warnInvalidValue("Switch","size",e.size,v),warnInvalidValue("Switch","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Switch","layout",e.layout,["inline","row"]);const[C,R]=useControllableState({value:i,defaultValue:s??!1,onChange:r}),V=v.includes(o)?o:"md",k=useMemo(()=>resolveSwitchSize(T,V),[T,V]),A=T.colors["switch-thumb"],_=useMemo(()=>buildStyles(T),[T]),D="dark"===T.mode?T.colors.neutral:T.colors["surface-disabled"],I=toneColor(T,n),z=S??8,E=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.spring(E,{toValue:C?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[C,E,T.motion.spring.snappy]);const F=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.timing(F,{toValue:C?1:0,duration:T.motion.duration.fast,easing:Easing.out(Easing.ease),useNativeDriver:!1});return e.start(),()=>e.stop()},[C,F,T.motion.duration.fast]);const H=k.padding,M=k["track-width"]-k["thumb-size"]-k.padding,P=E.interpolate({inputRange:[0,1],outputRange:[H,M]}),N=F.interpolate({inputRange:[0,1],outputRange:[D,I]}),L=useRef(createAnimatedValue(1)).current,B=useRef(!0);useEffect(()=>{if(!f)return;if(B.current)return void(B.current=!1);const e=Animated.sequence([Animated.spring(L,{toValue:1.15,damping:10,stiffness:220,mass:1,useNativeDriver:!0}),Animated.spring(L,{toValue:1,damping:14,stiffness:240,mass:1,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[C,f,L]);const handlePress=e=>{a||(!1!==h&&triggerHaptic(h),R(!C),j.onPressOut?.(e))},O=m??fieldTextAsString(l),q="string"==typeof u?u:void 0,U=hasChoiceDetail({description:c,error:q,helperText:d}),W=hasFieldText(l)||U,X=(!0===u||hasFieldText(u))&&!C&&!a,G="row"===p&&W,J=_jsxs(Animated.View,{style:[_.track,{width:k["track-width"],height:k["track-height"],borderRadius:T.radius.pill,...smoothCorners,backgroundColor:N},w],children:[X?_jsx(View,{pointerEvents:"none",style:[_.errorRing,{borderRadius:T.radius.pill,...smoothCorners,borderWidth:T.size.border,borderColor:T.colors["field-border-error"]}]}):null,_jsx(Animated.View,{style:[_.thumb,T.shadow.card,{backgroundColor:A,width:k["thumb-size"],height:k["thumb-size"],borderRadius:T.radius.pill,...smoothCorners,transform:[{translateX:P},{scale:L}]},y]})]});if(G)return _jsxs(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:S,...null==S?{}:hitSlopMarker(S),...j,style:({pressed:e})=>[_.row,_.spreadRow,U?_.rowTop:null,{opacity:a?.55:e?.9:1},g,b],children:[_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.spreadText}),J]});const K=_jsx(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:z,...hitSlopMarker(z),...j,style:({pressed:e})=>[{opacity:a?.55:e?.9:1},W?null:b],children:J});return W?_jsxs(View,{style:[_.row,U?_.rowTop:null,g,b],children:[K,_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.text})]}):g?_jsx(View,{style:g,children:K}):K});Switch.displayName="Switch";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},track:{justifyContent:"center"},thumb:{position:"absolute",top:2},errorRing:{...StyleSheet.absoluteFill},rowTop:{alignItems:"flex-start"},text:{marginLeft:e.space.sm},spreadRow:{minHeight:44,justifyContent:"space-between"},spreadText:{flex:1,marginRight:e.space.md}});export{Switch};export default Switch;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(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.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:s,defaultValue:i,onChange:r,disabled:a=!1,size:o="md",tone:n="primary",label:l,description:c,helperText:d,error:u,layout:p="inline",accessibilityLabel:m,haptic:h="selection",bounce:f=!1,style:b,containerStyle:g,trackStyle:y,thumbStyle:w,testID:x,hitSlop:S,...V}=e,j=useTheme(),T=Object.keys(j.components.switch);assertValidValue("Switch","size",e.size,T),assertValidValue("Switch","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Switch","layout",e.layout,["inline","row"]);const[C,R]=useControllableState({value:s,defaultValue:i??!1,onChange:r}),k=T.includes(o)?o:"md",v=useMemo(()=>resolveSwitchSize(j,k),[j,k]),A=j.colors["switch-thumb"],_=useMemo(()=>buildStyles(j),[j]),D="dark"===j.mode?j.colors.neutral:j.colors["surface-disabled"],z=toneColor(j,n),E=S??8,F=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.spring(F,{toValue:C?1:0,damping:j.motion.spring.snappy.damping,stiffness:j.motion.spring.snappy.stiffness,mass:j.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[C,F,j.motion.spring.snappy]);const H=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.timing(H,{toValue:C?1:0,duration:j.motion.duration.fast,easing:Easing.out(Easing.ease),useNativeDriver:!1});return e.start(),()=>e.stop()},[C,H,j.motion.duration.fast]);const M=v.padding,P=v["track-width"]-v["thumb-size"]-v.padding,I=F.interpolate({inputRange:[0,1],outputRange:[M,P]}),N=H.interpolate({inputRange:[0,1],outputRange:[D,z]}),L=useRef(createAnimatedValue(1)).current,B=useRef(!0);useEffect(()=>{if(!f)return;if(B.current)return void(B.current=!1);const e=Animated.sequence([Animated.spring(L,{toValue:1.15,damping:10,stiffness:220,mass:1,useNativeDriver:!0}),Animated.spring(L,{toValue:1,damping:14,stiffness:240,mass:1,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[C,f,L]);const handlePress=e=>{a||(!1!==h&&triggerHaptic(h),R(!C),V.onPressOut?.(e))},O=m??fieldTextAsString(l),q="string"==typeof u?u:void 0,U=hasChoiceDetail({description:c,error:q,helperText:d}),W=hasFieldText(l)||U,X=(!0===u||hasFieldText(u))&&!C&&!a,G="row"===p&&W,J=_jsxs(Animated.View,{style:[_.track,{width:v["track-width"],height:v["track-height"],borderRadius:j.radius.pill,...smoothCorners,backgroundColor:N},y],children:[X?_jsx(View,{pointerEvents:"none",style:[_.errorRing,{borderRadius:j.radius.pill,...smoothCorners,borderWidth:j.size.border,borderColor:j.colors["field-border-error"]}]}):null,_jsx(Animated.View,{style:[_.thumb,j.shadow.card,{backgroundColor:A,width:v["thumb-size"],height:v["thumb-size"],borderRadius:j.radius.pill,...smoothCorners,transform:[{translateX:I},{scale:L}]},w]})]});if(G)return _jsxs(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:V.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:S,...null==S?{}:hitSlopMarker(S),...V,style:({pressed:e})=>[_.row,_.spreadRow,U?_.rowTop:null,{opacity:a?.55:e?.9:1},g,b],children:[_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.spreadText}),J]});const K=_jsx(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:V.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:E,...hitSlopMarker(E),...V,style:({pressed:e})=>[{opacity:a?.55:e?.9:1},W?null:b],children:J});return W?_jsxs(View,{style:[_.row,U?_.rowTop:null,g,b],children:[K,_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.text})]}):g?_jsx(View,{style:g,children:K}):K});Switch.displayName="Switch";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},track:{justifyContent:"center"},thumb:{position:"absolute",top:2},errorRing:{...StyleSheet.absoluteFill},rowTop:{alignItems:"flex-start"},text:{marginLeft:e.space.sm},spreadRow:{minHeight:44,justifyContent:"space-between"},spreadText:{flex:1,marginRight:e.space.md}});export{Switch};export default Switch;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:r,variant:n="underline",radius:s,size:l="md",scrollable:o=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:p,tabBadgeStyle:b,dividerStyle:g,indicatorStyle:f,progress:h,pages:y,haptic:x,accessibilityLabel:v,testID:S}=e;warnInvalidValue("Tabs","variant",e.variant,["underline","pills","segmented"]),warnInvalidValue("Tabs","size",e.size,["sm","md","lg"]),warnInvalidValue("Tabs","align",e.align,["left","center"]);const w=useTheme(),j=useMemo(()=>buildStyles(w),[w]),V=w.components.tabs,T=useMemo(()=>resolveTabsSize(w,l),[w,l]),_=o?T["scrollable-padding-x"]:T["padding-x"],k=T["padding-y"],I=T.text,R=w.space[V["icon-gap"]],z=T.icon,C=V["underline-height"],E=w.space[V["pill-inset"]],A=V["disabled-opacity"],L=w.space[V["badge-gap"]],F="segmented"===n,M=useMemo(()=>resolveSegmentedControlSize(w,l),[w,l]),H=w.space[V["track-padding"]],D="number"==typeof s?s:s?w.radius[s]:void 0,B=D??w.radius.md,P=void 0===D?w.radius.sm:Math.max(D-H,0),q=D??w.radius.pill,N=D??w.radius.none,O=w.colors["bg-muted"],W=useSquircle(F,B),[$,U]=useState({}),K=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,[G,J]=useState(0),Q=useRef(createAnimatedValue(0)).current,Y=useRef(null),Z=useRef(0),ee=$[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=useMemo(()=>y&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[y,G,Q])??h,ae=i.every(e=>void 0!==$[e.key]),re=void 0!==ie&&ae&&i.length>1,ne=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].x),extrapolate:"clamp"}):null,[re,ie,i,$]),se=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].width),extrapolate:"clamp"}):null,[re,ie,i,$]),le=useRef(null);useEffect(()=>{if(!ee)return;if(re)return;const e=null!==le.current&&le.current!==a;if(le.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=w.motion.spring.snappy,i=Animated.parallel([Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,w.motion.spring.snappy,re]),useEffect(()=>{y&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[y,G,te]);const oe=y?.length;useEffect(()=>{__DEV__&&void 0!==oe&&oe!==i.length&&Logger.warn(`[@webority/mobile-ui] Tabs pages has ${oe} entries for ${i.length} tabs; each tab needs one page.`)},[oe,i.length]);const de=useCallback(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const r=t[e];return r&&r.x===i&&r.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=useCallback(e=>{if(e.disabled)return;if(e.key===a)return;const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),r(e.key)},[a,r,x]),ue="pills"===n,me=_jsx(Animated.View,{pointerEvents:"none",style:[F?j.indicatorThumb:ue?j.indicatorPill:j.indicatorUnderline,F?null:ue?{top:E,bottom:E}:{height:C},{width:se??X,transform:[{translateX:ne??K}],backgroundColor:F?w.colors.surface:ue?w.colors["primary-soft"]:w.colors.primary,borderRadius:F?P:ue?q:N,...smoothCorners},f]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,r=t?w.colors.primary:w.colors["text-subtle"],n=renderSlotIcon(e.icon,{color:r,size:z,focused:t,disabled:i});return _jsxs(Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:F?void 0:{color:w.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[j.tab,o?null:j.tabFlex,F?{paddingHorizontal:M["padding-x"],height:M.height-2*H}:{paddingHorizontal:_,paddingVertical:k},{opacity:i?A:e&&F&&!t?.7:1,backgroundColor:e&&!F?w.colors["surface-pressed"]:"transparent"},u],children:[n?_jsx(View,{style:[j.tabIcon,{marginRight:R},p],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:n}):null,_jsx(Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[j.tabLabel,{fontSize:F?M.text:I},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?_jsx(Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:L},badgeStyle:[j.tabBadge,b]}):null]},e.key)}),pe={flexDirection:"row",alignItems:"stretch",justifyContent:o?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},be=_jsxs(_Fragment,F?{children:[me,renderTabs()]}:{children:[renderTabs(),me]}),ge=_jsxs(View,{ref:t,style:[j.container,{borderBottomColor:w.colors["border-subtle"],borderBottomWidth:"underline"===n?StyleSheet.hairlineWidth:0},"underline"===n?g:null,F?{padding:H,borderRadius:B,...smoothCorners,backgroundColor:W.active?"transparent":O}:null,c],onLayout:W.onLayout,accessibilityRole:"tablist",accessibilityLabel:v,testID:S,children:[W.active&&W.size?_jsx(SquircleFill,{width:W.size.width,height:W.size.height,radius:B,fill:O}):null,o?_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[pe],keyboardShouldPersistTaps:"handled",children:be}):_jsx(View,{style:pe,children:be})]});return y?_jsxs(View,{style:j.root,children:[ge,_jsx(Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),n=i[t];n?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,n&&n.key!==a&&r(n.key))},style:j.pager,testID:S?`${S}-pages`:void 0,children:i.map((e,t)=>_jsx(View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:y[t]},e.key))})]}):ge});Tabs.displayName="Tabs";const buildStyles=e=>StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});export{Tabs};export default Tabs;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,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{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:s,variant:r="underline",radius:n,size:l="md",scrollable:o=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:p,tabBadgeStyle:b,dividerStyle:g,indicatorStyle:f,progress:h,pages:y,haptic:x,accessibilityLabel:v,testID:S}=e;assertValidValue("Tabs","variant",e.variant,["underline","pills","segmented"]),assertValidValue("Tabs","size",e.size,["sm","md","lg"]),assertValidValue("Tabs","align",e.align,["left","center"]);const w=useTheme(),V=useMemo(()=>buildStyles(w),[w]),j=w.components.tabs,T=useMemo(()=>resolveTabsSize(w,l),[w,l]),_=o?T["scrollable-padding-x"]:T["padding-x"],k=T["padding-y"],R=T.text,z=w.space[j["icon-gap"]],C=T.icon,I=j["underline-height"],E=w.space[j["pill-inset"]],A=j["disabled-opacity"],L=w.space[j["badge-gap"]],F="segmented"===r,M=useMemo(()=>resolveSegmentedControlSize(w,l),[w,l]),H=w.space[j["track-padding"]],D="number"==typeof n?n:n?w.radius[n]:void 0,B=D??w.radius.md,P=void 0===D?w.radius.sm:Math.max(D-H,0),q=D??w.radius.pill,N=D??w.radius.none,O=w.colors["bg-muted"],W=useSquircle(F,B),[$,U]=useState({}),K=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,[G,J]=useState(0),Q=useRef(createAnimatedValue(0)).current,Y=useRef(null),Z=useRef(0),ee=$[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=useMemo(()=>y&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[y,G,Q])??h,ae=i.every(e=>void 0!==$[e.key]),se=void 0!==ie&&ae&&i.length>1,re=useMemo(()=>se&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].x),extrapolate:"clamp"}):null,[se,ie,i,$]),ne=useMemo(()=>se&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].width),extrapolate:"clamp"}):null,[se,ie,i,$]),le=useRef(null);useEffect(()=>{if(!ee)return;if(se)return;const e=null!==le.current&&le.current!==a;if(le.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=w.motion.spring.snappy,i=Animated.parallel([Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,w.motion.spring.snappy,se]),useEffect(()=>{y&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[y,G,te]);const oe=y?.length;useEffect(()=>{__DEV__&&void 0!==oe&&oe!==i.length&&Logger.warn(`[@webority/mobile-ui] Tabs pages has ${oe} entries for ${i.length} tabs; each tab needs one page.`)},[oe,i.length]);const de=useCallback(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const s=t[e];return s&&s.x===i&&s.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=useCallback(e=>{if(e.disabled)return;if(e.key===a)return;const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),s(e.key)},[a,s,x]),ue="pills"===r,me=_jsx(Animated.View,{pointerEvents:"none",style:[F?V.indicatorThumb:ue?V.indicatorPill:V.indicatorUnderline,F?null:ue?{top:E,bottom:E}:{height:I},{width:ne??X,transform:[{translateX:re??K}],backgroundColor:F?w.colors.surface:ue?w.colors["primary-soft"]:w.colors.primary,borderRadius:F?P:ue?q:N,...smoothCorners},f]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,s=t?w.colors.primary:w.colors["text-subtle"],r=renderSlotIcon(e.icon,{color:s,size:C,focused:t,disabled:i});return _jsxs(Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:F?void 0:{color:w.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[V.tab,o?null:V.tabFlex,F?{paddingHorizontal:M["padding-x"],height:M.height-2*H}:{paddingHorizontal:_,paddingVertical:k},{opacity:i?A:e&&F&&!t?.7:1,backgroundColor:e&&!F?w.colors["surface-pressed"]:"transparent"},u],children:[r?_jsx(View,{style:[V.tabIcon,{marginRight:z},p],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:r}):null,_jsx(Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[V.tabLabel,{fontSize:F?M.text:R},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?_jsx(Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:L},badgeStyle:[V.tabBadge,b]}):null]},e.key)}),pe={flexDirection:"row",alignItems:"stretch",justifyContent:o?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},be=_jsxs(_Fragment,F?{children:[me,renderTabs()]}:{children:[renderTabs(),me]}),ge=_jsxs(View,{ref:t,style:[V.container,{borderBottomColor:w.colors["border-subtle"],borderBottomWidth:"underline"===r?StyleSheet.hairlineWidth:0},"underline"===r?g:null,F?{padding:H,borderRadius:B,...smoothCorners,backgroundColor:W.active?"transparent":O}:null,c],onLayout:W.onLayout,accessibilityRole:"tablist",accessibilityLabel:v,testID:S,children:[W.active&&W.size?_jsx(SquircleFill,{width:W.size.width,height:W.size.height,radius:B,fill:O}):null,o?_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[pe],keyboardShouldPersistTaps:"handled",children:be}):_jsx(View,{style:pe,children:be})]});return y?_jsxs(View,{style:V.root,children:[ge,_jsx(Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),r=i[t];r?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,r&&r.key!==a&&s(r.key))},style:V.pager,testID:S?`${S}-pages`:void 0,children:i.map((e,t)=>_jsx(View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:y[t]},e.key))})]}):ge});Tabs.displayName="Tabs";const buildStyles=e=>StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});export{Tabs};export default Tabs;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:v,testID:j}=e;warnInvalidValue("TagInput","size",e.size,["sm","md","lg"]),warnInvalidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const w=useTheme(),y=useMemo(()=>buildStyles(w),[w]),[C,T]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[I,S]=useState(""),[F,z]=useState(!1),V=useRef(null),_=useMemo(()=>mergeRefs(V,t),[t]),k=useCallback(()=>{d||V.current?.focus()},[d]),R="number"==typeof m&&C.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===C.length&&0===I.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&C.some(e=>e.toLowerCase()===t.toLowerCase()))return void S("");T([...C,t]),S("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,T,C,f,x]),L=useCallback(e=>{const t=C.filter((t,s)=>s!==e);T(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,T,C]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));if(t){const[s]=e.split(t);return void q(s)}S(e)},[q,h]),D=useCallback(e=>{d||"Backspace"===e.nativeEvent.key&&""===I&&C.length>0&&L(C.length-1)},[d,I,L,C.length]),P=_jsx(FieldBase,{size:c,variant:p,focused:F,disabled:d,error:B,filled:C.length>0||I.length>0,onPress:k,pressFeedback:!1,style:v,children:_jsxs(View,{style:y.wrap,children:[C.map((e,t)=>_jsx(Chip,{label:e,size:"sm",onRemove:d?void 0:()=>L(t),haptic:g},`${e}-${t}`)),_jsxs(View,{style:y.inputBox,children:[_jsx(TextInput,{ref:_,value:I,onChangeText:M,onKeyPress:D,onSubmitEditing:()=>q(I),onFocus:e=>{z(!0),b?.(e)},onBlur:()=>{z(!1),q(I)},editable:!d&&!R,placeholder:R||H?void 0:a,placeholderTextColor:w.colors["text-subtle"],blurOnSubmit:!1,returnKeyType:"done",accessibilityLabel:i??a,style:[y.input,{color:w.colors["text-body"],fontSize:w.text.base.size}],testID:j?`${j}-input`:void 0}),H?_jsx(RequiredPlaceholder,{text:a??"",color:w.colors["text-subtle"],fontSize:w.text.base.size,weightStyle:fontFor(w,"normal")}):null]})]})});return _jsxs(View,{testID:j,children:[i?_jsx(FieldLabel,{size:c,required:u,children:i}):null,P,_jsx(FieldMessage,{size:c,error:B,text:B?n:o})]})});TagInput.displayName="TagInput";const buildStyles=e=>StyleSheet.create({wrap:{flex:1,flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:e.space.xs,paddingVertical:e.space.xs},inputBox:{flexGrow:1,minWidth:80},input:{...fontFor(e,"normal"),padding:e.space.none}});export default TagInput;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:j,testID:v}=e;assertValidValue("TagInput","size",e.size,["sm","md","lg"]),assertValidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const y=useTheme(),C=useMemo(()=>buildStyles(y),[y]),[T,S]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[F,V]=useState(""),[w,I]=useState(!1),z=useRef(null),_=useMemo(()=>mergeRefs(z,t),[t]),k=useCallback(()=>{d||z.current?.focus()},[d]),R="number"==typeof m&&T.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===T.length&&0===F.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&T.some(e=>e.toLowerCase()===t.toLowerCase()))return void V("");S([...T,t]),V("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,S,T,f,x]),L=useCallback(e=>{const t=T.filter((t,s)=>s!==e);S(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,S,T]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));if(t){const[s]=e.split(t);return void q(s)}V(e)},[q,h]),D=useCallback(e=>{d||"Backspace"===e.nativeEvent.key&&""===F&&T.length>0&&L(T.length-1)},[d,F,L,T.length]),P=_jsx(FieldBase,{size:c,variant:p,focused:w,disabled:d,error:B,filled:T.length>0||F.length>0,onPress:k,pressFeedback:!1,style:j,children:_jsxs(View,{style:C.wrap,children:[T.map((e,t)=>_jsx(Chip,{label:e,size:"sm",onRemove:d?void 0:()=>L(t),haptic:g},`${e}-${t}`)),_jsxs(View,{style:C.inputBox,children:[_jsx(TextInput,{ref:_,value:F,onChangeText:M,onKeyPress:D,onSubmitEditing:()=>q(F),onFocus:e=>{I(!0),b?.(e)},onBlur:()=>{I(!1),q(F)},editable:!d&&!R,placeholder:R||H?void 0:a,placeholderTextColor:y.colors["text-subtle"],blurOnSubmit:!1,returnKeyType:"done",accessibilityLabel:i??a,style:[C.input,{color:y.colors["text-body"],fontSize:y.text.base.size}],testID:v?`${v}-input`:void 0}),H?_jsx(RequiredPlaceholder,{text:a??"",color:y.colors["text-subtle"],fontSize:y.text.base.size,weightStyle:fontFor(y,"normal")}):null]})]})});return _jsxs(View,{testID:v,children:[i?_jsx(FieldLabel,{size:c,required:u,children:i}):null,P,_jsx(FieldMessage,{size:c,error:B,text:B?n:o})]})});TagInput.displayName="TagInput";const buildStyles=e=>StyleSheet.create({wrap:{flex:1,flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:e.space.xs,paddingVertical:e.space.xs},inputBox:{flexGrow:1,minWidth:80},input:{...fontFor(e,"normal"),padding:e.space.none}});export default TagInput;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)?e.colors[TEXT_ROLE_COLOR[t]]:Object.hasOwn(SEMANTIC,t)?e.colors[`${t}-text`]:t;const resolveVariantColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)||Object.hasOwn(SEMANTIC,t)?resolveColor(e,t):e.colors[t],decorationOf=(e,t)=>e&&t?"underline line-through":e?"underline":t?"line-through":void 0,Text=forwardRef((e,t)=>{const{variant:i="body",color:o,weight:r,size:n,align:a,italic:l,underline:s,strikethrough:d,style:c,children:m,...x}=e,g=useTheme(),y=Object.hasOwn(VARIANTS,i),h=g.settings.textVariants,p=!y&&h&&Object.hasOwn(h,i)?h[i]:void 0;y||p||warnInvalidValue("Text","variant",e.variant,[...Object.keys(VARIANTS),...Object.keys(h??{})]),warnInvalidValue("Text","color",o,COLOR_NAMES),warnInvalidValue("Text","size",n,TEXT_NAMES);const u=void 0!==o&&COLOR_NAMES.includes(o)?o:void 0,b=useMemo(()=>{if(p){const e=n??p.size,t=g.text[e].size;return{fontSize:t,lineHeight:p.lineHeight??Math.round(t*g.leading[p.heading?"heading":"body"]),color:void 0!==u?resolveColor(g,u):p.color?resolveVariantColor(g,p.color):resolveColor(g,"primary"),textAlign:a,textTransform:p.uppercase?"uppercase":void 0,letterSpacing:p.letterSpacing?g["letter-spacing"][p.letterSpacing]:void 0,fontStyle:l||p.italic?"italic":void 0,fontVariant:p.fontVariant,textDecorationLine:decorationOf(s,d),...fontFor(g,r??p.weight??"normal",p.fontFamily)}}const e=VARIANTS[y?i:"body"],t=g.text[n??e.size].size;return{fontSize:t,lineHeight:Math.round(t*g.leading[e.line]),color:resolveColor(g,u??e.color),textAlign:a,textTransform:e.uppercase?"uppercase":void 0,letterSpacing:e.letterSpacing?g["letter-spacing"][e.letterSpacing]:void 0,fontStyle:l?"italic":void 0,textDecorationLine:decorationOf(s,d),...fontFor(g,r??e.weight,e.fontFamily)}},[g,p,y,i,u,r,n,a,l,s,d]),T=useTextInk([b,c],g.text.base.size,g.colors["text-body"]),f=y?VARIANTS[i].heading:p?.heading,O="string"==typeof m||"number"==typeof m;return _jsx(RNText,{ref:t,style:[b,c],maxFontSizeMultiplier:g.settings.maxFontSizeMultiplier,accessibilityRole:f?"header":x.accessibilityRole,...x,children:O?m:_jsx(TextInkContext.Provider,{value:T,children:m})})});Text.displayName="Text";export{Text};export default Text;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)?e.colors[TEXT_ROLE_COLOR[t]]:Object.hasOwn(SEMANTIC,t)?e.colors[`${t}-text`]:t;const resolveVariantColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)||Object.hasOwn(SEMANTIC,t)?resolveColor(e,t):e.colors[t],decorationOf=(e,t)=>e&&t?"underline line-through":e?"underline":t?"line-through":void 0,Text=forwardRef((e,t)=>{const{variant:i="body",color:o,weight:r,size:n,align:a,italic:l,underline:s,strikethrough:d,style:c,children:m,...x}=e,g=useTheme(),y=Object.hasOwn(VARIANTS,i),h=g.settings.textVariants,p=!y&&h&&Object.hasOwn(h,i)?h[i]:void 0;y||p||assertValidValue("Text","variant",e.variant,[...Object.keys(VARIANTS),...Object.keys(h??{})]),assertValidValue("Text","color",o,COLOR_NAMES),assertValidValue("Text","size",n,TEXT_NAMES);const u=void 0!==o&&COLOR_NAMES.includes(o)?o:void 0,b=useMemo(()=>{if(p){const e=n??p.size,t=g.text[e].size;return{fontSize:t,lineHeight:p.lineHeight??Math.round(t*g.leading[p.heading?"heading":"body"]),color:void 0!==u?resolveColor(g,u):p.color?resolveVariantColor(g,p.color):resolveColor(g,"primary"),textAlign:a,textTransform:p.uppercase?"uppercase":void 0,letterSpacing:p.letterSpacing?g["letter-spacing"][p.letterSpacing]:void 0,fontStyle:l||p.italic?"italic":void 0,fontVariant:p.fontVariant,textDecorationLine:decorationOf(s,d),...fontFor(g,r??p.weight??"normal",p.fontFamily)}}const e=VARIANTS[y?i:"body"],t=g.text[n??e.size].size;return{fontSize:t,lineHeight:Math.round(t*g.leading[e.line]),color:resolveColor(g,u??e.color),textAlign:a,textTransform:e.uppercase?"uppercase":void 0,letterSpacing:e.letterSpacing?g["letter-spacing"][e.letterSpacing]:void 0,fontStyle:l?"italic":void 0,textDecorationLine:decorationOf(s,d),...fontFor(g,r??e.weight,e.fontFamily)}},[g,p,y,i,u,r,n,a,l,s,d]),T=useTextInk([b,c],g.text.base.size,g.colors["text-body"]),f=y?VARIANTS[i].heading:p?.heading,O="string"==typeof m||"number"==typeof m;return _jsx(RNText,{ref:t,style:[b,c],maxFontSizeMultiplier:g.settings.maxFontSizeMultiplier,accessibilityRole:f?"header":x.accessibilityRole,...x,children:O?m:_jsx(TextInkContext.Provider,{value:T,children:m})})});Text.displayName="Text";export{Text};export default Text;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import Button from"../Button/Button.js";import{Modal}from"../Modal/index.js";import{PickerTrigger}from"../PickerTrigger/PickerTrigger.js";import{Text}from"../Text/index.js";import{WheelPicker}from"../WheelPicker/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TIME_PICKER_LABELS=Object.freeze({title:"Select Time",confirm:"Confirm",cancel:"Cancel",selected:e=>`Selected ${e}`,hour:"Hour",minute:"Minute",period:"Period",hourItem:e=>`Hour ${e}`,minuteItem:e=>`${e} minutes`,cancelHint:"Dismiss without changes",confirmHint:"Confirm selected time"});const range=(e,t,i=1)=>{const r=[];for(let a=e;a<=t;a+=i)r.push(a);return r},pad2=e=>e.toString().padStart(2,"0"),to24h=(e,t,i)=>"24h"===i?e:"AM"===t?12===e?0:e:12===e?12:e+12,from24h=(e,t)=>"24h"===t?{displayHour:e,period:"AM"}:0===e?{displayHour:12,period:"AM"}:12===e?{displayHour:12,period:"PM"}:e>12?{displayHour:e-12,period:"PM"}:{displayHour:e,period:"AM"},clampMinuteToStep=(e,t)=>{const i=Math.round(e/t)*t;return Math.min(59,Math.max(0,i))},TimePicker=e=>{const{open:t,value:i,onChange:r,onClose:a,format:l="12h",minuteStep:o=1,labels:s,testID:n,style:u,containerStyle:m,headerLabelStyle:c,footerButtonStyle:p,formatValue:d,haptic:h,triggerLabels:g,label:b,help:f,placeholder:y,helperText:M,error:x,required:S,disabled:v,size:k,variant:T,clearable:I,onClear:P,leftIcon:j,trailing:H,triggerStyle:_,valueStyle:w,labelStyle:C,messageStyle:D,accessibilityLabel:L}=e,B={label:b,help:f,placeholder:y,helperText:M,error:x,required:S,disabled:v,size:k,variant:T,clearable:I,onClear:P,leftIcon:j,trailing:H,triggerStyle:_,valueStyle:w,labelStyle:C,messageStyle:D,accessibilityLabel:L};warnInvalidValue("TimePicker","format",e.format,["12h","24h"]),warnInvalidValue("TimePicker","minuteStep",e.minuteStep?.toString(),["1","5","15","30"]),warnInvalidValue("TimePicker","size",e.size,["sm","md","lg"]),warnInvalidValue("TimePicker","variant",e.variant,["outline","filled","underline"]);const $=useMemo(()=>({...DEFAULT_TIME_PICKER_LABELS,...s}),[s]),A=void 0!==e.open,[F,E]=useState(!1),V=A?t:F,N=A?n:n?`${n}-modal`:void 0,O=useTheme(),z=useMemo(()=>buildStyles(O),[O]),W=useCallback(()=>{A?a?.():E(!1)},[A,a]),R=useMemo(()=>"24h"===l?range(0,23):range(1,12),[l]),U=useMemo(()=>range(0,59,o),[o]),q=useMemo(()=>["AM","PM"],[]),K=useMemo(()=>{const e=i&&Number.isFinite(i.hour)?i.hour:(new Date).getHours(),t=i&&Number.isFinite(i.minute)?i.minute:(new Date).getMinutes(),r=clampMinuteToStep(t,o),{displayHour:a,period:s}=from24h(e,l);return{displayHour:a,minute:r,period:s,hour24:e}},[i,l,o]),[G,J]=useState(()=>{const e=R.indexOf(K.displayHour);return e>=0?e:0}),[Q,X]=useState(()=>{const e=U.indexOf(K.minute);return e>=0?e:0}),[Y,Z]=useState(()=>"PM"===K.period?1:0);useEffect(()=>{if(!V)return;const e=i&&Number.isFinite(i.hour)?i.hour:(new Date).getHours(),t=i&&Number.isFinite(i.minute)?i.minute:(new Date).getMinutes(),r=clampMinuteToStep(t,o),{displayHour:a,period:s}=from24h(e,l),n=R.indexOf(a);J(n>=0?n:0);const u=U.indexOf(r);X(u>=0?u:0),Z("PM"===s?1:0)},[V,i,l,o,R,U]);const ee=useCallback((e,t)=>{"hour"===e?J(Math.max(0,R.indexOf(Number(t)))):"minute"===e?X(Math.max(0,U.indexOf(Number(t)))):Z("PM"===t?1:0)},[R,U]),te=useCallback(()=>{!1!==h&&triggerHaptic("selection"),W()},[W,h]),ie=useCallback(()=>{const e=R[G]??0,t=q[Y]??"AM",i=to24h(e,t,l),a=U[Q]??0;!1!==h&&triggerHaptic("notificationSuccess"),r?.({hour:i,minute:a}),W()},[R,G,q,Y,U,Q,l,r,W,h]),re=useMemo(()=>{const e=R[G]??0,t=U[Q]??0;if("24h"===l)return`${pad2(e)}:${pad2(t)}`;const i=q[Y]??"AM";return`${pad2(e)}:${pad2(t)} ${i}`},[R,G,U,Q,q,Y,l]),ae=useMemo(()=>R.map(e=>({value:e,label:pad2(e),accessibilityLabel:$.hourItem(e)})),[R,$]),le=useMemo(()=>U.map(e=>({value:e,label:pad2(e),accessibilityLabel:$.minuteItem(e)})),[U,$]),oe=useMemo(()=>q.map(e=>({value:e,label:e})),[q]),se=useMemo(()=>{const e=[{key:"hour",label:$.hour,items:ae,value:R[G]??0,separator:":",testID:"time-picker-hour"},{key:"minute",label:$.minute,items:le,value:U[Q]??0,gapAfter:"12h"===l?O.space.md:void 0,testID:"time-picker-minute"}];return"12h"===l&&e.push({key:"period",label:$.period,items:oe,value:q[Y]??"AM",testID:"time-picker-period"}),e},[ae,le,oe,R,G,U,Q,q,Y,l,O.space.md,$]),ne=useCallback(e=>{if("24h"===l)return`${pad2(e.hour)}:${pad2(e.minute)}`;const{displayHour:t,period:i}=from24h(e.hour,"12h");return`${t}:${pad2(e.minute)} ${i}`},[l]),ue=!A&&i&&Number.isFinite(i.hour)&&Number.isFinite(i.minute)?(d??ne)(i):void 0,me=_jsxs(Modal,{open:V,onClose:W,presentation:"bottom",accessibilityLabel:$.title,haptic:h,contentStyle:[m,u],testID:N,children:[_jsx(Text,{variant:"title",align:"center",accessibilityRole:"header",style:[z.title,c],children:$.title}),_jsx(View,{style:z.summaryWrap,accessibilityLiveRegion:"polite",accessibilityLabel:$.selected(re),children:_jsx(Text,{variant:"h2",weight:"bold",color:"brand",style:z.summary,children:re})}),_jsx(WheelPicker,{columns:se,onChange:ee,haptic:h,style:z.wheels}),_jsxs(View,{style:z.footer,children:[_jsx(Button,{label:$.cancel,haptic:!1,variant:"ghost",tone:"neutral",onPress:te,style:[z.footerBtn,p],accessibilityHint:$.cancelHint,testID:"time-picker-cancel"}),_jsx(Button,{label:$.confirm,variant:"solid",tone:"primary",haptic:!1,onPress:ie,style:[z.footerBtn,p],accessibilityHint:$.confirmHint,testID:"time-picker-confirm"})]})]});return A?me:_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...B,labels:g,value:ue,onPress:()=>E(!0),testID:n}),me]})},buildStyles=e=>StyleSheet.create({title:{marginBottom:e.space.sm},summaryWrap:{alignItems:"center",marginBottom:e.space.md},summary:{letterSpacing:e["letter-spacing"].wide},wheels:{marginBottom:e.space.lg},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg}});export{TimePicker};export default TimePicker;
1
+ "use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import Button from"../Button/Button.js";import{Modal}from"../Modal/index.js";import{PickerTrigger}from"../PickerTrigger/PickerTrigger.js";import{Text}from"../Text/index.js";import{WheelPicker}from"../WheelPicker/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TIME_PICKER_LABELS=Object.freeze({title:"Select Time",confirm:"Confirm",cancel:"Cancel",selected:e=>`Selected ${e}`,hour:"Hour",minute:"Minute",period:"Period",hourItem:e=>`Hour ${e}`,minuteItem:e=>`${e} minutes`,cancelHint:"Dismiss without changes",confirmHint:"Confirm selected time"});const range=(e,t,i=1)=>{const r=[];for(let a=e;a<=t;a+=i)r.push(a);return r},pad2=e=>e.toString().padStart(2,"0"),to24h=(e,t,i)=>"24h"===i?e:"AM"===t?12===e?0:e:12===e?12:e+12,from24h=(e,t)=>"24h"===t?{displayHour:e,period:"AM"}:0===e?{displayHour:12,period:"AM"}:12===e?{displayHour:12,period:"PM"}:e>12?{displayHour:e-12,period:"PM"}:{displayHour:e,period:"AM"},clampMinuteToStep=(e,t)=>{const i=Math.round(e/t)*t;return Math.min(59,Math.max(0,i))},TimePicker=e=>{const{open:t,value:i,onChange:r,onClose:a,format:s="12h",minuteStep:l=1,labels:o,testID:n,style:u,containerStyle:m,headerLabelStyle:c,footerButtonStyle:p,formatValue:d,haptic:h,triggerLabels:g,label:b,help:f,placeholder:y,helperText:M,error:x,required:S,disabled:k,size:T,variant:P,clearable:j,onClear:v,leftIcon:H,trailing:I,triggerStyle:_,valueStyle:C,labelStyle:D,messageStyle:V,accessibilityLabel:L}=e,B={label:b,help:f,placeholder:y,helperText:M,error:x,required:S,disabled:k,size:T,variant:P,clearable:j,onClear:v,leftIcon:H,trailing:I,triggerStyle:_,valueStyle:C,labelStyle:D,messageStyle:V,accessibilityLabel:L};assertValidValue("TimePicker","format",e.format,["12h","24h"]),assertValidValue("TimePicker","minuteStep",e.minuteStep?.toString(),["1","5","15","30"]),assertValidValue("TimePicker","size",e.size,["sm","md","lg"]),assertValidValue("TimePicker","variant",e.variant,["outline","filled","underline"]);const $=useMemo(()=>({...DEFAULT_TIME_PICKER_LABELS,...o}),[o]),w=void 0!==e.open,[A,F]=useState(!1),E=w?t:A,N=w?n:n?`${n}-modal`:void 0,O=useTheme(),z=useMemo(()=>buildStyles(O),[O]),W=useCallback(()=>{w?a?.():F(!1)},[w,a]),R=useMemo(()=>"24h"===s?range(0,23):range(1,12),[s]),U=useMemo(()=>range(0,59,l),[l]),q=useMemo(()=>["AM","PM"],[]),K=useMemo(()=>{const e=i&&Number.isFinite(i.hour)?i.hour:(new Date).getHours(),t=i&&Number.isFinite(i.minute)?i.minute:(new Date).getMinutes(),r=clampMinuteToStep(t,l),{displayHour:a,period:o}=from24h(e,s);return{displayHour:a,minute:r,period:o,hour24:e}},[i,s,l]),[G,J]=useState(()=>{const e=R.indexOf(K.displayHour);return e>=0?e:0}),[Q,X]=useState(()=>{const e=U.indexOf(K.minute);return e>=0?e:0}),[Y,Z]=useState(()=>"PM"===K.period?1:0);useEffect(()=>{if(!E)return;const e=i&&Number.isFinite(i.hour)?i.hour:(new Date).getHours(),t=i&&Number.isFinite(i.minute)?i.minute:(new Date).getMinutes(),r=clampMinuteToStep(t,l),{displayHour:a,period:o}=from24h(e,s),n=R.indexOf(a);J(n>=0?n:0);const u=U.indexOf(r);X(u>=0?u:0),Z("PM"===o?1:0)},[E,i,s,l,R,U]);const ee=useCallback((e,t)=>{"hour"===e?J(Math.max(0,R.indexOf(Number(t)))):"minute"===e?X(Math.max(0,U.indexOf(Number(t)))):Z("PM"===t?1:0)},[R,U]),te=useCallback(()=>{!1!==h&&triggerHaptic("selection"),W()},[W,h]),ie=useCallback(()=>{const e=R[G]??0,t=q[Y]??"AM",i=to24h(e,t,s),a=U[Q]??0;!1!==h&&triggerHaptic("notificationSuccess"),r?.({hour:i,minute:a}),W()},[R,G,q,Y,U,Q,s,r,W,h]),re=useMemo(()=>{const e=R[G]??0,t=U[Q]??0;if("24h"===s)return`${pad2(e)}:${pad2(t)}`;const i=q[Y]??"AM";return`${pad2(e)}:${pad2(t)} ${i}`},[R,G,U,Q,q,Y,s]),ae=useMemo(()=>R.map(e=>({value:e,label:pad2(e),accessibilityLabel:$.hourItem(e)})),[R,$]),se=useMemo(()=>U.map(e=>({value:e,label:pad2(e),accessibilityLabel:$.minuteItem(e)})),[U,$]),le=useMemo(()=>q.map(e=>({value:e,label:e})),[q]),oe=useMemo(()=>{const e=[{key:"hour",label:$.hour,items:ae,value:R[G]??0,separator:":",testID:"time-picker-hour"},{key:"minute",label:$.minute,items:se,value:U[Q]??0,gapAfter:"12h"===s?O.space.md:void 0,testID:"time-picker-minute"}];return"12h"===s&&e.push({key:"period",label:$.period,items:le,value:q[Y]??"AM",testID:"time-picker-period"}),e},[ae,se,le,R,G,U,Q,q,Y,s,O.space.md,$]),ne=useCallback(e=>{if("24h"===s)return`${pad2(e.hour)}:${pad2(e.minute)}`;const{displayHour:t,period:i}=from24h(e.hour,"12h");return`${t}:${pad2(e.minute)} ${i}`},[s]),ue=!w&&i&&Number.isFinite(i.hour)&&Number.isFinite(i.minute)?(d??ne)(i):void 0,me=_jsxs(Modal,{open:E,onClose:W,presentation:"bottom",accessibilityLabel:$.title,haptic:h,contentStyle:[m,u],testID:N,children:[_jsx(Text,{variant:"title",align:"center",accessibilityRole:"header",style:[z.title,c],children:$.title}),_jsx(View,{style:z.summaryWrap,accessibilityLiveRegion:"polite",accessibilityLabel:$.selected(re),children:_jsx(Text,{variant:"h2",weight:"bold",color:"brand",style:z.summary,children:re})}),_jsx(WheelPicker,{columns:oe,onChange:ee,haptic:h,style:z.wheels}),_jsxs(View,{style:z.footer,children:[_jsx(Button,{label:$.cancel,haptic:!1,variant:"ghost",tone:"neutral",onPress:te,style:[z.footerBtn,p],accessibilityHint:$.cancelHint,testID:"time-picker-cancel"}),_jsx(Button,{label:$.confirm,variant:"solid",tone:"primary",haptic:!1,onPress:ie,style:[z.footerBtn,p],accessibilityHint:$.confirmHint,testID:"time-picker-confirm"})]})]});return w?me:_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...B,labels:g,value:ue,onPress:()=>F(!0),testID:n}),me]})},buildStyles=e=>StyleSheet.create({title:{marginBottom:e.space.sm},summaryWrap:{alignItems:"center",marginBottom:e.space.md},summary:{letterSpacing:e["letter-spacing"].wide},wheels:{marginBottom:e.space.lg},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg}});export{TimePicker};export default TimePicker;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{IconBadge}from"../IconBadge/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DOT=12,HALO=6,RAIL=2,GUTTER=28,DISC=24,STATUS_VALUES=["upcoming","current","done","onHold","rejected","cancelled","skipped"];export const Timeline=({items:e,variant:t="feed",orientation:r="vertical",style:s,testID:o})=>{const n=useTheme(),l=n.space.xs,i=useMemo(()=>buildStyles(n),[n]),a="horizontal"===r,c=n.colors.border;warnInvalidValue("Timeline","variant",t,["feed","progress"]),warnInvalidValue("Timeline","orientation",r,["vertical","horizontal"]);const[d,u]=useState(0),m=useCallback(e=>{const{width:t}=e.nativeEvent.layout;u(e=>e===t?e:t)},[]),h=a&&d>0&&e.length>0?d/e.length:0,renderDisc=(e,t)=>e.icon?_jsx(View,{style:i.disc,children:e.icon}):_jsx(IconBadge,{dimension:24,color:t,fill:"halo",icon:_jsx(View,{style:[i.dot,{backgroundColor:t}]})}),renderText=(e,t)=>_jsxs(_Fragment,{children:[_jsx(Text,{variant:a?"bodySmall":"body",weight:"semibold",style:[{color:"upcoming"===t?n.colors["text-muted"]:n.colors["text-body"]},a?i.centred:null],children:e.title}),e.meta?_jsx(Text,{variant:"caption",style:[{color:n.colors["text-subtle"]},a?i.centred:null],children:e.meta}):null,e.description?_jsx(Text,{variant:"bodySmall",style:[{color:n.colors["text-muted"]},a?i.centred:null],children:e.description}):null,e.children]}),x=e.map((r,s)=>{warnInvalidValue("Timeline","status",r.status,STATUS_VALUES);const o=r.status??("feed"===t?"done":"upcoming"),d=r.color??(e=>{switch(e){case"done":return n.colors.success;case"current":return n.colors.warning;case"onHold":return n.colors.info;case"rejected":return n.colors.danger;case"cancelled":case"skipped":return n.colors["text-subtle"];default:return n.colors["text-disabled"]}})(o),u=0===s,m=s===e.length-1,x=r.key??`${r.title}-${s}`;return _jsxs(View,a?{testID:r.testID,style:[i.hColumn,h>0?{width:h,flex:0}:null],children:[_jsxs(View,{style:i.hDotRow,children:[_jsx(View,{style:[i.hSegment,{marginRight:l,backgroundColor:u?"transparent":c}]}),renderDisc(r,d),_jsx(View,{style:[i.hSegment,{marginLeft:l,backgroundColor:m?"transparent":c}]})]}),_jsx(View,{style:i.hBody,children:renderText(r,o)})]}:{testID:r.testID,style:i.row,children:[_jsxs(View,{style:i.gutter,children:[renderDisc(r,d),m?null:_jsx(View,{style:[i.rail,{backgroundColor:c}]})]}),_jsx(View,{style:[i.body,{paddingBottom:m?0:n.space.lg}],children:renderText(r,o)})]},x)});return _jsx(View,{style:[a?i.hRow:null,s],onLayout:a?m:void 0,testID:o,children:x})};const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row"},gutter:{width:Math.max(28,28),alignItems:"center"},disc:{width:24,height:24,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},dot:{width:12,height:12,borderRadius:e.radius.pill,...smoothCorners},rail:{width:2,flex:1,marginTop:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},body:{flex:1,gap:e.space.xxs,paddingLeft:e.space.sm},hRow:{flexDirection:"row",alignItems:"flex-start"},hColumn:{flex:1,minWidth:0,alignItems:"center"},hDotRow:{alignSelf:"stretch",flexDirection:"row",alignItems:"center"},hSegment:{flex:1,height:2,borderRadius:e.radius.pill,...smoothCorners},hBody:{alignSelf:"stretch",alignItems:"center",paddingHorizontal:e.space.xs,marginTop:e.space.sm,gap:e.space.xxs},centred:{textAlign:"center"}});export default Timeline;
1
+ "use strict";import{useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{IconBadge}from"../IconBadge/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DOT=12,HALO=6,RAIL=2,GUTTER=28,DISC=24,STATUS_VALUES=["upcoming","current","done","onHold","rejected","cancelled","skipped"];export const Timeline=({items:e,variant:t="feed",orientation:s="vertical",style:r,testID:o})=>{const l=useTheme(),i=l.space.xs,n=useMemo(()=>buildStyles(l),[l]),a="horizontal"===s,c=l.colors.border;assertValidValue("Timeline","variant",t,["feed","progress"]),assertValidValue("Timeline","orientation",s,["vertical","horizontal"]);const[d,u]=useState(0),m=useCallback(e=>{const{width:t}=e.nativeEvent.layout;u(e=>e===t?e:t)},[]),h=a&&d>0&&e.length>0?d/e.length:0,renderDisc=(e,t)=>e.icon?_jsx(View,{style:n.disc,children:e.icon}):_jsx(IconBadge,{dimension:24,color:t,fill:"halo",icon:_jsx(View,{style:[n.dot,{backgroundColor:t}]})}),renderText=(e,t)=>_jsxs(_Fragment,{children:[_jsx(Text,{variant:a?"bodySmall":"body",weight:"semibold",style:[{color:"upcoming"===t?l.colors["text-muted"]:l.colors["text-body"]},a?n.centred:null],children:e.title}),e.meta?_jsx(Text,{variant:"caption",style:[{color:l.colors["text-subtle"]},a?n.centred:null],children:e.meta}):null,e.description?_jsx(Text,{variant:"bodySmall",style:[{color:l.colors["text-muted"]},a?n.centred:null],children:e.description}):null,e.children]}),x=e.map((s,r)=>{assertValidValue("Timeline","status",s.status,STATUS_VALUES);const o=s.status??("feed"===t?"done":"upcoming"),d=s.color??(e=>{switch(e){case"done":return l.colors.success;case"current":return l.colors.warning;case"onHold":return l.colors.info;case"rejected":return l.colors.danger;case"cancelled":case"skipped":return l.colors["text-subtle"];default:return l.colors["text-disabled"]}})(o),u=0===r,m=r===e.length-1,x=s.key??`${s.title}-${r}`;return _jsxs(View,a?{testID:s.testID,style:[n.hColumn,h>0?{width:h,flex:0}:null],children:[_jsxs(View,{style:n.hDotRow,children:[_jsx(View,{style:[n.hSegment,{marginRight:i,backgroundColor:u?"transparent":c}]}),renderDisc(s,d),_jsx(View,{style:[n.hSegment,{marginLeft:i,backgroundColor:m?"transparent":c}]})]}),_jsx(View,{style:n.hBody,children:renderText(s,o)})]}:{testID:s.testID,style:n.row,children:[_jsxs(View,{style:n.gutter,children:[renderDisc(s,d),m?null:_jsx(View,{style:[n.rail,{backgroundColor:c}]})]}),_jsx(View,{style:[n.body,{paddingBottom:m?0:l.space.lg}],children:renderText(s,o)})]},x)});return _jsx(View,{style:[a?n.hRow:null,r],onLayout:a?m:void 0,testID:o,children:x})};const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row"},gutter:{width:Math.max(28,28),alignItems:"center"},disc:{width:24,height:24,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},dot:{width:12,height:12,borderRadius:e.radius.pill,...smoothCorners},rail:{width:2,flex:1,marginTop:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},body:{flex:1,gap:e.space.xxs,paddingLeft:e.space.sm},hRow:{flexDirection:"row",alignItems:"flex-start"},hColumn:{flex:1,minWidth:0,alignItems:"center"},hDotRow:{alignSelf:"stretch",flexDirection:"row",alignItems:"center"},hSegment:{flex:1,height:2,borderRadius:e.radius.pill,...smoothCorners},hBody:{alignSelf:"stretch",alignItems:"center",paddingHorizontal:e.space.xs,marginTop:e.space.sm,gap:e.space.xxs},centred:{textAlign:"center"}});export default Timeline;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:n,shownAt:i,runtime:a})=>{const s=useTheme(),r=usePresenceMotion(),o=r.duration("fast");warnInvalidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=a?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(s),[s]),p=useMemo(()=>tintFor(s,l),[s,l]),g=useMemo(()=>inkFor(s,l),[s,l]),h=s.components.toast["icon-circle-size"],f=s.text[s.components.toast["icon-glyph-text"]].size,b=s.components.toast["tint-bar-width"],v=s.settings.components.toast?.defaultDurationMs??3e3,A=s.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(!1),V="top"===c?8*t:8*-t,M=Math.max(1-.04*t,.9),_=useRef(createAnimatedValue(V)).current;useEffect(()=>{setNativeValue(_,V)},[V,_]);const D=useMemo(()=>Animated.add(y,_),[y,_]),R=void 0!==e.action,C=e.duration??v,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===a?.screenReaderOn,j=!0===e.countdown&&!N,I=useRef(createAnimatedValue(1)).current,P=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),O=useRef({touch:!1,pan:!1,hover:!1}),k=useRef(()=>{}),L=useRef({id:e.id,totalMs:E,shownAt:i,runtime:a,persistent:N,animateBar:!1});L.current={id:e.id,totalMs:E,shownAt:i,runtime:a,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=P.current,t=L.current,n=O.current;if(!e.initialised){e.initialised=!0;const n=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=n??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(I,e.remaining/t.totalMs)}const i=!(t.persistent||T.current||n.touch||n.pan||n.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,k.current()},e.remaining),t.animateBar&&Animated.timing(I,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),I.stopAnimation())},[I]),dismiss=()=>{if(T.current)return;T.current=!0,H();const t=[Animated.timing(S,{toValue:0,duration:o,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:!0})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:s.motion.duration.fast,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:!0})),Animated.parallel(t).start(()=>n(e.id))};k.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=P.current,t=L.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),I.stopAnimation(),e.initialised&&t.totalMs>0&&!T.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[I]);const B=useCallback((e,t)=>{O.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const n=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(S,n)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:s.motion.spring.snappy.damping,stiffness:s.motion.spring.snappy.stiffness,mass:s.motion.spring.snappy.mass,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;T.current=!0,B("pan",!1);const a=[Animated.timing(S,{toValue:0,duration:o,useNativeDriver:!0})];r.reduced||a.push(Animated.timing(w,{toValue:500*t,duration:s.motion.duration.fast,useNativeDriver:!0})),Animated.parallel(a).start(()=>n(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:!0}),Animated.spring(S,{toValue:1,useNativeDriver:!0})]).start()}}),[w,S,B,o,r.reduced,s.motion.duration.fast,s.motion.spring.snappy.damping,s.motion.spring.snappy.stiffness,s.motion.spring.snappy.mass,n,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>I.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[I,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:s.colors.surface,borderRadius:s.radius.lg,...smoothCorners,padding:s.space.md,...s.shadow.elevated,opacity:S,transform:[{translateY:D},{translateX:w},{scale:M}]},e.style],children:[b>0?_jsx(View,{style:[m.tintBar,{width:b,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:h,height:h,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:f}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?s.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:n,shownAt:i,runtime:s})=>{const a=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=s?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(a),[a]),p=useMemo(()=>tintFor(a,l),[a,l]),g=useMemo(()=>inkFor(a,l),[a,l]),h=a.components.toast["icon-circle-size"],f=a.text[a.components.toast["icon-glyph-text"]].size,b=a.components.toast["tint-bar-width"],v=a.settings.components.toast?.defaultDurationMs??3e3,A=a.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(!1),V="top"===c?8*t:8*-t,M=Math.max(1-.04*t,.9),_=useRef(createAnimatedValue(V)).current;useEffect(()=>{setNativeValue(_,V)},[V,_]);const D=useMemo(()=>Animated.add(y,_),[y,_]),R=void 0!==e.action,C=e.duration??v,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===s?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:i,runtime:s,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:i,runtime:s,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=O.current,t=I.current,n=k.current;if(!e.initialised){e.initialised=!0;const n=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=n??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const i=!(t.persistent||T.current||n.touch||n.pan||n.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(T.current)return;T.current=!0,H();const t=[Animated.timing(S,{toValue:0,duration:o,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:a.motion.duration.fast,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})),Animated.parallel(t).start(()=>n(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!T.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const B=useCallback((e,t)=>{k.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const n=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(S,n)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;T.current=!0,B("pan",!1);const s=[Animated.timing(S,{toValue:0,duration:o,useNativeDriver:!0})];r.reduced||s.push(Animated.timing(w,{toValue:500*t,duration:a.motion.duration.fast,useNativeDriver:!0})),Animated.parallel(s).start(()=>n(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:!0}),Animated.spring(S,{toValue:1,useNativeDriver:!0})]).start()}}),[w,S,B,o,r.reduced,a.motion.duration.fast,a.motion.spring.snappy.damping,a.motion.spring.snappy.stiffness,a.motion.spring.snappy.mass,n,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:a.colors.surface,borderRadius:a.radius.lg,...smoothCorners,padding:a.space.md,...a.shadow.elevated,opacity:S,transform:[{translateY:D},{translateX:w},{scale:M}]},e.style],children:[b>0?_jsx(View,{style:[m.tintBar,{width:b,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:h,height:h,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:f}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?a.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
@@ -1 +1 @@
1
- "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:o,variant:r="plain",title:s,action:n,placement:i="auto",open:a,onOpenChange:l,hideOnContentPress:u=!0,maxWidth:c,showArrow:m=!0,accessibilityLabel:p,style:f,containerStyle:d,arrowStyle:h,messageStyle:g,labels:b,testID:T}=e;warnInvalidValue("Tooltip","variant",e.variant,["plain","rich"]),warnInvalidValue("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),warnInvalidValue("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const S="rich"===r,w=e.trigger??(S?"press":"longPress"),y=useMemo(()=>({...DEFAULT_TOOLTIP_LABELS,...b}),[b]),R=useTheme(),A=usePresenceMotion(),_=useSafeAreaInsets(),[v,x]=useModalInsets(),j=useMemo(()=>({..._,top:v.top,bottom:v.bottom}),[_,v]),C=useWindowDimensions(),E=useMemo(()=>buildStyles(R),[R]),I=R.space.sm,M=R.space.sm,P=c??(S?280:240),L="press"===w&&!S,O=(R.settings.components.tooltip?.enableScaleAnimation??!1)&&!A.reduced,D="manual"===w||"boolean"==typeof a,[V,H]=useState(!1),W=D?Boolean(a):V,[k,N]=useState(null),[F,B]=useState({width:0,height:0}),U=useRef(null),z=useRef(null),G=useRef(null),X=useRef(null),Y=useRef(null),q=useRef(!1),J=useRef(!1),K=useRef(createAnimatedValue(W||!O?1:.85)).current,Q=useRef(createAnimatedValue(W?1:0)).current,Z=useRef(null),$=useRef(!1),[ee,te]=useState(W),oe=useCallback(e=>{D||H(e),l?.(e)},[D,l]),re=useCallback(()=>{U.current&&U.current.measureInWindow((e,t,o,r)=>{N({x:e,y:t,width:o,height:r})})},[]),se=useCallback(e=>{re(),oe(!0)},[re,oe]),ne=useCallback(()=>{oe(!1)},[oe]),ie=useRef(ne);ie.current=ne;const ae=useCallback(()=>{if(!q.current)return;q.current=!1;const e=Y.current;Y.current=null,e?e():S&&focusHost(z.current??U.current)},[S]);useEffect(()=>{if(W)return J.current=!0,q.current=!1,claimAnchoredSurface(()=>ie.current());J.current&&(J.current=!1,q.current=!0)},[W]),useEffect(()=>{W&&te(!0)},[W]);const le=useCallback(()=>{Y.current=n?.onPress??null,ne()},[n,ne]);useEffect(()=>{if(!$.current)return $.current=!0,W&&(re(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(W){re();const t=[Animated.timing(Q,{toValue:1,duration:A.duration("fast"),useNativeDriver:!0})];O?t.push(Animated.spring(K,{toValue:1,damping:R.motion.spring.snappy.damping,stiffness:R.motion.spring.snappy.stiffness,mass:R.motion.spring.snappy.mass,useNativeDriver:!0})):setNativeValue(K,1),e=Animated.parallel(t),e.start(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))}else{const t=[Animated.timing(Q,{toValue:0,duration:A.reduced?A.duration("fast"):150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:!0})];O&&t.push(Animated.timing(K,{toValue:.85,duration:150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:!0})),e=Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[W]);const handleContentLayout=e=>{const{width:t,height:o}=e.nativeEvent.layout;t===F.width&&o===F.height||B({width:t,height:o})},ue=useMemo(()=>resolveTooltipPosition({anchor:k,size:F,placement:i,rich:S,viewport:{width:C.width,height:C.height,insets:j},maxWidth:P,gap:I,padding:M,arrowCornerPadding:12}),[k,F,i,S,C.width,C.height,j,P,I,M]),ce=null!==k&&F.width>0,me=W&&ce;useEffect(()=>{if(!S||!me)return;const e="web"===Platform.OS?X:G,t=setTimeout(()=>focusHost(e.current),FOCUS_DELAY_MS);return()=>clearTimeout(t)},[S,me]),useEffect(()=>{!S&&me&&"ios"===Platform.OS&&"string"==typeof t&&announce(t)},[S,me,t]);const pe=o.props,fe=useMemo(()=>mergeRefs(pe.ref,z),[pe.ref]),de={};"longPress"!==w||pe.contextMenu?"press"===w&&(de.onPress=e=>{pe.onPress?.(e),se(e)}):(de.onLongPress=se,de.accessibilityHint=y.longPressHint),S&&(de.ref=fe);const he=React.cloneElement(o,de),ge=p??("string"==typeof t?t:y.fallbackName),be=useMemo(()=>{if(!m)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:S?R.colors.surface:R.colors["surface-inverse"]};return"top"===ue.placement?{...e,bottom:-6,left:ue.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===ue.placement?{...e,top:-6,left:ue.arrowOffset-4}:"left"===ue.placement?{...e,right:-6,top:ue.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:ue.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[m,ue,R,S]),Te={position:"absolute",top:ue.top,left:ue.left,maxWidth:P,opacity:W&&!ce?0:Q,transform:[{scale:K}]},Se=be?_jsx(View,{style:[be,h],pointerEvents:"none"}):null;return _jsxs(_Fragment,{children:[_jsx(View,{ref:U,collapsable:!1,onLayout:re,testID:T,children:he}),_jsxs(Modal,{open:ee,onClose:ne,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:u,haptic:!1,labels:{close:y.close},onInsetsChange:x,onDismissed:ae,children:[ee&&S?_jsxs(Animated.View,{onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(RichTooltipBody,{title:s,content:t,action:n,onAction:le,focusRef:G,actionRef:X,messageStyle:g}),Se]}):null,ee&&!S?_jsxs(Animated.View,{accessibilityRole:"web"===Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(View,{style:[E.tooltip,{backgroundColor:R.colors["surface-inverse"],borderRadius:R.radius.md,...smoothCorners,paddingHorizontal:R.space.md,paddingVertical:R.space.sm,...R.shadow.popover,shadowColor:R.shadow.popover.shadowColor}],children:"string"==typeof t?_jsx(Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,...StyleSheet.flatten(g)},children:t}):t}),Se]}):null]})]})},buildStyles=e=>StyleSheet.create({tooltip:{overflow:"hidden"}});export{Tooltip};export default Tooltip;
1
+ "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:o,variant:r="plain",title:s,action:n,placement:i="auto",open:a,onOpenChange:l,hideOnContentPress:u=!0,maxWidth:c,showArrow:m=!0,accessibilityLabel:p,style:f,containerStyle:d,arrowStyle:h,messageStyle:g,labels:b,testID:T}=e;assertValidValue("Tooltip","variant",e.variant,["plain","rich"]),assertValidValue("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),assertValidValue("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const S="rich"===r,y=e.trigger??(S?"press":"longPress"),R=useMemo(()=>({...DEFAULT_TOOLTIP_LABELS,...b}),[b]),A=useTheme(),_=usePresenceMotion(),w=useSafeAreaInsets(),[v,x]=useModalInsets(),j=useMemo(()=>({...w,top:v.top,bottom:v.bottom}),[w,v]),C=useWindowDimensions(),E=useMemo(()=>buildStyles(A),[A]),M=A.space.sm,P=A.space.sm,V=c??(S?280:240),L="press"===y&&!S,O=(A.settings.components.tooltip?.enableScaleAnimation??!1)&&!_.reduced,D="manual"===y||"boolean"==typeof a,[I,H]=useState(!1),W=D?Boolean(a):I,[k,N]=useState(null),[F,B]=useState({width:0,height:0}),U=useRef(null),z=useRef(null),G=useRef(null),X=useRef(null),Y=useRef(null),q=useRef(!1),J=useRef(!1),K=useRef(createAnimatedValue(W||!O?1:.85)).current,Q=useRef(createAnimatedValue(W?1:0)).current,Z=useRef(null),$=useRef(!1),[ee,te]=useState(W),oe=useCallback(e=>{D||H(e),l?.(e)},[D,l]),re=useCallback(()=>{U.current&&U.current.measureInWindow((e,t,o,r)=>{N({x:e,y:t,width:o,height:r})})},[]),se=useCallback(e=>{re(),oe(!0)},[re,oe]),ne=useCallback(()=>{oe(!1)},[oe]),ie=useRef(ne);ie.current=ne;const ae=useCallback(()=>{if(!q.current)return;q.current=!1;const e=Y.current;Y.current=null,e?e():S&&focusHost(z.current??U.current)},[S]);useEffect(()=>{if(W)return J.current=!0,q.current=!1,claimAnchoredSurface(()=>ie.current());J.current&&(J.current=!1,q.current=!0)},[W]),useEffect(()=>{W&&te(!0)},[W]);const le=useCallback(()=>{Y.current=n?.onPress??null,ne()},[n,ne]);useEffect(()=>{if(!$.current)return $.current=!0,W&&(re(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(W){re();const t=[Animated.timing(Q,{toValue:1,duration:_.duration("fast"),useNativeDriver:!0})];O?t.push(Animated.spring(K,{toValue:1,damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass,useNativeDriver:!0})):setNativeValue(K,1),e=Animated.parallel(t),e.start(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))}else{const t=[Animated.timing(Q,{toValue:0,duration:_.reduced?_.duration("fast"):150,easing:Easing.bezier(...A.motion.ease.accelerate),useNativeDriver:!0})];O&&t.push(Animated.timing(K,{toValue:.85,duration:150,easing:Easing.bezier(...A.motion.ease.accelerate),useNativeDriver:!0})),e=Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[W]);const handleContentLayout=e=>{const{width:t,height:o}=e.nativeEvent.layout;t===F.width&&o===F.height||B({width:t,height:o})},ue=useMemo(()=>resolveTooltipPosition({anchor:k,size:F,placement:i,rich:S,viewport:{width:C.width,height:C.height,insets:j},maxWidth:V,gap:M,padding:P,arrowCornerPadding:12}),[k,F,i,S,C.width,C.height,j,V,M,P]),ce=null!==k&&F.width>0,me=W&&ce;useEffect(()=>{if(!S||!me)return;const e="web"===Platform.OS?X:G,t=setTimeout(()=>focusHost(e.current),FOCUS_DELAY_MS);return()=>clearTimeout(t)},[S,me]),useEffect(()=>{!S&&me&&"ios"===Platform.OS&&"string"==typeof t&&announce(t)},[S,me,t]);const pe=o.props,fe=useMemo(()=>mergeRefs(pe.ref,z),[pe.ref]),de={};"longPress"!==y||pe.contextMenu?"press"===y&&(de.onPress=e=>{pe.onPress?.(e),se(e)}):(de.onLongPress=se,de.accessibilityHint=R.longPressHint),S&&(de.ref=fe);const he=React.cloneElement(o,de),ge=p??("string"==typeof t?t:R.fallbackName),be=useMemo(()=>{if(!m)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:S?A.colors.surface:A.colors["surface-inverse"]};return"top"===ue.placement?{...e,bottom:-6,left:ue.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===ue.placement?{...e,top:-6,left:ue.arrowOffset-4}:"left"===ue.placement?{...e,right:-6,top:ue.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:ue.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[m,ue,A,S]),Te={position:"absolute",top:ue.top,left:ue.left,maxWidth:V,opacity:W&&!ce?0:Q,transform:[{scale:K}]},Se=be?_jsx(View,{style:[be,h],pointerEvents:"none"}):null;return _jsxs(_Fragment,{children:[_jsx(View,{ref:U,collapsable:!1,onLayout:re,testID:T,children:he}),_jsxs(Modal,{open:ee,onClose:ne,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:u,haptic:!1,labels:{close:R.close},onInsetsChange:x,onDismissed:ae,children:[ee&&S?_jsxs(Animated.View,{onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(RichTooltipBody,{title:s,content:t,action:n,onAction:le,focusRef:G,actionRef:X,messageStyle:g}),Se]}):null,ee&&!S?_jsxs(Animated.View,{accessibilityRole:"web"===Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(View,{style:[E.tooltip,{backgroundColor:A.colors["surface-inverse"],borderRadius:A.radius.md,...smoothCorners,paddingHorizontal:A.space.md,paddingVertical:A.space.sm,...A.shadow.popover,shadowColor:A.shadow.popover.shadowColor}],children:"string"==typeof t?_jsx(Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,...StyleSheet.flatten(g)},children:t}):t}),Se]}):null]})]})},buildStyles=e=>StyleSheet.create({tooltip:{overflow:"hidden"}});export{Tooltip};export default Tooltip;
@@ -1 +1 @@
1
- "use strict";import{Fragment,useCallback,useMemo}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Chip}from"../Chip/index.js";import{Text}from"../Text/index.js";import{WHEEL_CENTER_OFFSET,WHEEL_VISIBLE_ITEMS,Wheel}from"./Wheel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BASE_ITEM_HEIGHT=40,MAX_FONT_SCALE=1.5,DEFAULT_COLUMN_WIDTH=64,MAX_DURATION_MINUTES=1439;export const DEFAULT_WHEEL_PICKER_LABELS=Object.freeze({hours:"Hours",minutes:"Minutes",hourUnit:"hr",minuteUnit:"min",hourOne:"hour",hourMany:"hours",minuteOne:"minute",minuteMany:"minutes",value:"Value"});const range=(e,t,i=1)=>{const s=[];for(let n=e;n<=t;n+=i)s.push(n);return s},plural=(e,t,i)=>`${e} ${1===e?t:i}`,formatPreset=(e,t,i)=>{const s=Math.floor(e/60),n=e%60;return 0===s?`${n} ${i}`:0===n?`${s} ${t}`:`${s} ${t} ${n} ${i}`},toItem=e=>"object"==typeof e?e:{value:e,label:String(e)},WheelPicker=e=>{const{haptic:t,disabled:i,testID:s,style:n,labels:o}=e;warnInvalidValue("WheelPicker","mode",e.mode,["columns","list","duration"]);const r=useTheme(),a=useReducedMotion(),{fontScale:l}=useWindowDimensions(),u=Math.min(Math.max(l,1),1.5),m=Math.round(40*u),d=useMemo(()=>buildStyles(r,m),[r,m]),h="list"===e.mode?e.items:void 0,c=useMemo(()=>h?.map(toItem),[h]),p="duration"===e.mode?e.minuteStep??1:1,b="duration"===e.mode?Math.max(0,Math.min(1439,Math.floor(e.maxMinutes??1/0))):0,f=Math.floor(b/60),x=useMemo(()=>({...DEFAULT_WHEEL_PICKER_LABELS,...o}),[o]),M="duration"===e.mode?e.presets:void 0;for(const e of M??[])if(!Number.isInteger(e)||e<0||e>b||e%p!==0)throw new Error(`WheelPicker preset ${e} must be a whole number of minutes from 0 to ${b} in steps of ${p}.`);const y=useCallback(e=>{const t=e===f?b%60:59;return Math.floor(t/p)*p},[f,b,p]),E="duration"===e.mode?e.value:0,_=useMemo(()=>{const e=Number.isFinite(E)?E:0,t=Math.max(0,Math.min(b,e)),i=Math.floor(t/60),s=Math.round(t%60/p)*p;return{hour:i,minute:Math.min(y(i),s)}},[E,b,p,y]),g=useMemo(()=>"duration"===e.mode?range(0,f).map(e=>({value:e,label:String(e),accessibilityLabel:plural(e,x.hourOne,x.hourMany)})):[],[e.mode,f,x]),w=y(_.hour),j=useMemo(()=>"duration"===e.mode?range(0,w,p).map(e=>({value:e,label:String(e).padStart(2,"0"),accessibilityLabel:plural(e,x.minuteOne,x.minuteMany)})):[],[e.mode,w,p,x]),I=useMemo(()=>"list"===e.mode?[{key:"list",label:e.label??x.value,items:c??[],value:e.value??"",width:e.width}]:"duration"===e.mode?[{key:"hours",label:x.hours,items:g,value:_.hour,unit:x.hourUnit,gapAfter:r.space.md},{key:"minutes",label:x.minutes,items:j,value:_.minute,unit:x.minuteUnit}]:e.columns,[e,c,g,j,_,x,r.space.md]),{onChange:S}=e,v=useCallback((t,i)=>{const s=t.items[i];if(s&&S)if("list"===e.mode)S(s.value);else if("duration"===e.mode){const e=Number(s.value),i=S;"hours"===t.key?i(60*e+Math.min(_.minute,y(e))):i(60*_.hour+e)}else S(t.key,s.value)},[S,e.mode,_,y]),L=useCallback(e=>{S?.(e)},[S]),T=60*_.hour+_.minute,C=_jsxs(View,{style:[d.wheels,n],testID:s,children:[_jsxs(View,{pointerEvents:"none",style:d.selectionBand,children:[_jsx(View,{style:d.bandLine}),_jsx(View,{style:d.bandLine})]}),I.map(s=>{if(0===s.items.length)return null;const n=s.items.findIndex(e=>e.value===s.value);return _jsxs(Fragment,{children:[_jsx(Wheel,{label:s.label,items:s.items,selectedIndex:Math.max(0,n),onIndexChange:e=>v(s,e),itemHeight:m,width:s.width??("list"===e.mode?void 0:64),theme:r,haptic:t,disabled:i,reducedMotion:a,typeable:"duration"===e.mode,testID:s.testID}),s.unit?_jsx(Text,{variant:"body",weight:"semibold",color:"secondary",style:d.unit,maxFontSizeMultiplier:1.5,numberOfLines:1,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:s.unit}):null,s.separator?_jsx(Text,{variant:"h2",weight:"bold",style:d.separator,maxFontSizeMultiplier:1.5,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:s.separator}):null,s.gapAfter?_jsx(View,{style:{width:s.gapAfter}}):null]},s.key)})]});return M&&0!==M.length?_jsxs(View,{children:[C,_jsx(View,{style:d.presets,children:M.map(e=>_jsx(Chip,{label:formatPreset(e,x.hourUnit,x.minuteUnit),size:"sm",selected:e===T,disabled:i,onPress:()=>L(e)},e))})]}):C},buildStyles=(e,t)=>StyleSheet.create({wheels:{flexDirection:"row",alignItems:"center",justifyContent:"center",height:t*WHEEL_VISIBLE_ITEMS,position:"relative"},selectionBand:{position:"absolute",left:0,right:0,top:t*WHEEL_CENTER_OFFSET,height:t,justifyContent:"space-between"},bandLine:{height:2*StyleSheet.hairlineWidth,backgroundColor:e.colors.primary,opacity:.85},separator:{paddingHorizontal:e.space.xs},unit:{paddingLeft:e.space.xs},presets:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:e.space.xs,paddingTop:e.space.sm}});export{WheelPicker};export default WheelPicker;
1
+ "use strict";import{Fragment,useCallback,useMemo}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{Text}from"../Text/index.js";import{WHEEL_CENTER_OFFSET,WHEEL_VISIBLE_ITEMS,Wheel}from"./Wheel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BASE_ITEM_HEIGHT=40,MAX_FONT_SCALE=1.5,DEFAULT_COLUMN_WIDTH=64,MAX_DURATION_MINUTES=1439;export const DEFAULT_WHEEL_PICKER_LABELS=Object.freeze({hours:"Hours",minutes:"Minutes",hourUnit:"hr",minuteUnit:"min",hourOne:"hour",hourMany:"hours",minuteOne:"minute",minuteMany:"minutes",value:"Value"});const range=(e,t,i=1)=>{const s=[];for(let o=e;o<=t;o+=i)s.push(o);return s},plural=(e,t,i)=>`${e} ${1===e?t:i}`,formatPreset=(e,t,i)=>{const s=Math.floor(e/60),o=e%60;return 0===s?`${o} ${i}`:0===o?`${s} ${t}`:`${s} ${t} ${o} ${i}`},toItem=e=>"object"==typeof e?e:{value:e,label:String(e)},WheelPicker=e=>{const{haptic:t,disabled:i,testID:s,style:o,labels:n}=e;assertValidValue("WheelPicker","mode",e.mode,["columns","list","duration"]);const r=useTheme(),a=useReducedMotion(),{fontScale:l}=useWindowDimensions(),u=Math.min(Math.max(l,1),1.5),m=Math.round(40*u),d=useMemo(()=>buildStyles(r,m),[r,m]),h="list"===e.mode?e.items:void 0,c=useMemo(()=>h?.map(toItem),[h]),p="duration"===e.mode?e.minuteStep??1:1,b="duration"===e.mode?Math.max(0,Math.min(1439,Math.floor(e.maxMinutes??1/0))):0,f=Math.floor(b/60),x=useMemo(()=>({...DEFAULT_WHEEL_PICKER_LABELS,...n}),[n]),M="duration"===e.mode?e.presets:void 0;for(const e of M??[])if(!Number.isInteger(e)||e<0||e>b||e%p!==0)throw new Error(`WheelPicker preset ${e} must be a whole number of minutes from 0 to ${b} in steps of ${p}.`);const y=useCallback(e=>{const t=e===f?b%60:59;return Math.floor(t/p)*p},[f,b,p]),E="duration"===e.mode?e.value:0,_=useMemo(()=>{const e=Number.isFinite(E)?E:0,t=Math.max(0,Math.min(b,e)),i=Math.floor(t/60),s=Math.round(t%60/p)*p;return{hour:i,minute:Math.min(y(i),s)}},[E,b,p,y]),g=useMemo(()=>"duration"===e.mode?range(0,f).map(e=>({value:e,label:String(e),accessibilityLabel:plural(e,x.hourOne,x.hourMany)})):[],[e.mode,f,x]),j=y(_.hour),S=useMemo(()=>"duration"===e.mode?range(0,j,p).map(e=>({value:e,label:String(e).padStart(2,"0"),accessibilityLabel:plural(e,x.minuteOne,x.minuteMany)})):[],[e.mode,j,p,x]),w=useMemo(()=>"list"===e.mode?[{key:"list",label:e.label??x.value,items:c??[],value:e.value??"",width:e.width}]:"duration"===e.mode?[{key:"hours",label:x.hours,items:g,value:_.hour,unit:x.hourUnit,gapAfter:r.space.md},{key:"minutes",label:x.minutes,items:S,value:_.minute,unit:x.minuteUnit}]:e.columns,[e,c,g,S,_,x,r.space.md]),{onChange:I}=e,L=useCallback((t,i)=>{const s=t.items[i];if(s&&I)if("list"===e.mode)I(s.value);else if("duration"===e.mode){const e=Number(s.value),i=I;"hours"===t.key?i(60*e+Math.min(_.minute,y(e))):i(60*_.hour+e)}else I(t.key,s.value)},[I,e.mode,_,y]),v=useCallback(e=>{I?.(e)},[I]),T=60*_.hour+_.minute,C=_jsxs(View,{style:[d.wheels,o],testID:s,children:[_jsxs(View,{pointerEvents:"none",style:d.selectionBand,children:[_jsx(View,{style:d.bandLine}),_jsx(View,{style:d.bandLine})]}),w.map(s=>{if(0===s.items.length)return null;const o=s.items.findIndex(e=>e.value===s.value);return _jsxs(Fragment,{children:[_jsx(Wheel,{label:s.label,items:s.items,selectedIndex:Math.max(0,o),onIndexChange:e=>L(s,e),itemHeight:m,width:s.width??("list"===e.mode?void 0:64),theme:r,haptic:t,disabled:i,reducedMotion:a,typeable:"duration"===e.mode,testID:s.testID}),s.unit?_jsx(Text,{variant:"body",weight:"semibold",color:"secondary",style:d.unit,maxFontSizeMultiplier:1.5,numberOfLines:1,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:s.unit}):null,s.separator?_jsx(Text,{variant:"h2",weight:"bold",style:d.separator,maxFontSizeMultiplier:1.5,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:s.separator}):null,s.gapAfter?_jsx(View,{style:{width:s.gapAfter}}):null]},s.key)})]});return M&&0!==M.length?_jsxs(View,{children:[C,_jsx(View,{style:d.presets,children:M.map(e=>_jsx(Chip,{label:formatPreset(e,x.hourUnit,x.minuteUnit),size:"sm",selected:e===T,disabled:i,onPress:()=>v(e)},e))})]}):C},buildStyles=(e,t)=>StyleSheet.create({wheels:{flexDirection:"row",alignItems:"center",justifyContent:"center",height:t*WHEEL_VISIBLE_ITEMS,position:"relative"},selectionBand:{position:"absolute",left:0,right:0,top:t*WHEEL_CENTER_OFFSET,height:t,justifyContent:"space-between"},bandLine:{height:2*StyleSheet.hairlineWidth,backgroundColor:e.colors.primary,opacity:.85},separator:{paddingHorizontal:e.space.xs},unit:{paddingLeft:e.space.xs},presets:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:e.space.xs,paddingTop:e.space.sm}});export{WheelPicker};export default WheelPicker;
@@ -0,0 +1 @@
1
+ "use strict";export function assertValidValue(e,o,t,r){if(null==t)return;const i=String(t);if(!r.some(e=>String(e)===i))throw new RangeError(`[@webority/mobile-ui] <${e}> received ${o}="${i}", which is not one of ${r.map(e=>`"${e}"`).join(" | ")}. Pass one of these values, or omit the prop for the default.`)}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Throw when a declared prop receives a value outside its allowed vocabulary.
3
+ *
4
+ * Pass the value the caller supplied, before any defaulting, or the check cannot fail.
5
+ * Nullish is accepted: an omitted prop means the default was wanted.
6
+ *
7
+ * @throws {RangeError} when `value` is not nullish and not in `allowed`
8
+ */
9
+ export declare function assertValidValue(component: string, prop: string, value: unknown, allowed: ReadonlyArray<string | number>): void;
10
+ //# sourceMappingURL=assertValidValue.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Throw when a declared prop receives a value outside its allowed vocabulary.
3
+ *
4
+ * Pass the value the caller supplied, before any defaulting, or the check cannot fail.
5
+ * Nullish is accepted: an omitted prop means the default was wanted.
6
+ *
7
+ * @throws {RangeError} when `value` is not nullish and not in `allowed`
8
+ */
9
+ export declare function assertValidValue(component: string, prop: string, value: unknown, allowed: ReadonlyArray<string | number>): void;
10
+ //# sourceMappingURL=assertValidValue.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-ui",
3
- "version": "0.144.2",
3
+ "version": "0.145.0",
4
4
  "description": "Beautiful, animated, accessible React Native components, theme and form engine for Webority projects.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -115,13 +115,13 @@
115
115
  }
116
116
  },
117
117
  "dependencies": {
118
- "@webority/markdown-core": "0.144.2"
118
+ "@webority/markdown-core": "0.145.0"
119
119
  },
120
120
  "peerDependencies": {
121
121
  "@react-navigation/bottom-tabs": ">=7.0.0",
122
122
  "@react-navigation/native": ">=7.0.0",
123
- "@webority/canvas-kit": "0.144.2",
124
- "@webority/mobile-core": "0.144.2",
123
+ "@webority/canvas-kit": "0.145.0",
124
+ "@webority/mobile-core": "0.145.0",
125
125
  "expo": ">=57.0.0",
126
126
  "expo-file-system": ">=57.0.0",
127
127
  "expo-haptics": ">=57.0.0",
@@ -185,10 +185,10 @@
185
185
  "@types/node": "25.6.0",
186
186
  "@types/react": "19.2.18",
187
187
  "@types/react-test-renderer": "19.1.0",
188
- "@webority/canvas-kit": "0.144.2",
189
- "@webority/mobile-core": "0.144.2",
188
+ "@webority/canvas-kit": "0.145.0",
189
+ "@webority/mobile-core": "0.145.0",
190
190
  "@webority/mobile-dev": "0.0.0",
191
- "@webority/tokens": "0.144.2",
191
+ "@webority/tokens": "0.145.0",
192
192
  "expo": "57.0.31",
193
193
  "expo-file-system": "57.0.7",
194
194
  "expo-haptics": "57.0.3",
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resetInvalidValueWarnings=resetInvalidValueWarnings,exports.warnInvalidValue=warnInvalidValue;const seen=new Set;function warnInvalidValue(e,n,t,s){if(!__DEV__||null==t)return;const a=String(t);if(s.some(e=>String(e)===a))return;const r=`${e}.${n}.${a}`;seen.has(r)||(seen.add(r),console.warn(`[@webority/mobile-ui] <${e}> received ${n}="${a}", which is not one of ${s.map(e=>`"${e}"`).join(" | ")}. The component fell back to its default, so this renders something other than what the call site asks for.`))}function resetInvalidValueWarnings(){seen.clear()}
@@ -1 +0,0 @@
1
- "use strict";const seen=new Set;export function warnInvalidValue(e,n,t,o){if(!__DEV__||null==t)return;const s=String(t);if(o.some(e=>String(e)===s))return;const i=`${e}.${n}.${s}`;seen.has(i)||(seen.add(i),console.warn(`[@webority/mobile-ui] <${e}> received ${n}="${s}", which is not one of ${o.map(e=>`"${e}"`).join(" | ")}. The component fell back to its default, so this renders something other than what the call site asks for.`))}export function resetInvalidValueWarnings(){seen.clear()}
@@ -1,10 +0,0 @@
1
- /**
2
- * Warn when a declared prop receives a value outside its allowed vocabulary.
3
- *
4
- * Pass the value the caller supplied, before any defaulting, or the check cannot fail.
5
- * Nullish is accepted: an omitted prop means the default was wanted.
6
- */
7
- export declare function warnInvalidValue(component: string, prop: string, value: unknown, allowed: ReadonlyArray<string | number>): void;
8
- /** Tests only: clears the once-per-value memory so each case starts from a clean state. */
9
- export declare function resetInvalidValueWarnings(): void;
10
- //# sourceMappingURL=warnInvalidValue.d.ts.map
@@ -1,10 +0,0 @@
1
- /**
2
- * Warn when a declared prop receives a value outside its allowed vocabulary.
3
- *
4
- * Pass the value the caller supplied, before any defaulting, or the check cannot fail.
5
- * Nullish is accepted: an omitted prop means the default was wanted.
6
- */
7
- export declare function warnInvalidValue(component: string, prop: string, value: unknown, allowed: ReadonlyArray<string | number>): void;
8
- /** Tests only: clears the once-per-value memory so each case starts from a clean state. */
9
- export declare function resetInvalidValueWarnings(): void;
10
- //# sourceMappingURL=warnInvalidValue.d.ts.map