@webority/mobile-ui 0.15.0 → 0.16.1

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 (161) hide show
  1. package/lib/commonjs/components/Accordion/Accordion.js +1 -1
  2. package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
  3. package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +1 -1
  4. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  5. package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
  6. package/lib/commonjs/components/Banner/Banner.js +1 -1
  7. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  8. package/lib/commonjs/components/Button/Button.js +1 -1
  9. package/lib/commonjs/components/Calendar/Calendar.js +1 -1
  10. package/lib/commonjs/components/Card/Card.js +1 -1
  11. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  12. package/lib/commonjs/components/Chip/Chip.js +1 -1
  13. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  14. package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
  15. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  16. package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
  17. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  18. package/lib/commonjs/components/IconButton/IconButton.js +1 -1
  19. package/lib/commonjs/components/ListItem/ListItem.js +1 -1
  20. package/lib/commonjs/components/LoaderOverlay/LoaderOverlay.js +1 -1
  21. package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
  22. package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
  23. package/lib/commonjs/components/Modal/Modal.js +1 -1
  24. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  25. package/lib/commonjs/components/OnboardingPager/OnboardingPager.js +1 -1
  26. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  27. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  28. package/lib/commonjs/components/Screen/Screen.js +1 -0
  29. package/lib/commonjs/components/Screen/index.js +1 -0
  30. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  31. package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
  32. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  33. package/lib/commonjs/components/Skeleton/SkeletonProvider.js +1 -1
  34. package/lib/commonjs/components/Skeleton/index.js +1 -1
  35. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  36. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  37. package/lib/commonjs/components/Text/Text.js +1 -1
  38. package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
  39. package/lib/commonjs/components/Toast/Toast.js +1 -1
  40. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  41. package/lib/commonjs/components/Tour/Tour.js +1 -1
  42. package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
  43. package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
  44. package/lib/commonjs/components/index.js +1 -1
  45. package/lib/commonjs/hooks/index.js +1 -1
  46. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  47. package/lib/commonjs/hooks/useFieldChain.js +1 -0
  48. package/lib/commonjs/hooks/usePresenceMotion.js +1 -0
  49. package/lib/commonjs/hooks/usePressAnimation.js +1 -1
  50. package/lib/commonjs/hooks/useReducedMotion.js +1 -1
  51. package/lib/commonjs/index.js +1 -1
  52. package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
  53. package/lib/commonjs/theme/tokens.js +1 -1
  54. package/lib/commonjs/utils/hapticUtils.js +1 -1
  55. package/lib/module/components/Accordion/Accordion.js +1 -1
  56. package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
  57. package/lib/module/components/AnimatePresence/AnimatePresence.js +1 -1
  58. package/lib/module/components/AppBar/AppBar.js +1 -1
  59. package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
  60. package/lib/module/components/Banner/Banner.js +1 -1
  61. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  62. package/lib/module/components/Button/Button.js +1 -1
  63. package/lib/module/components/Calendar/Calendar.js +1 -1
  64. package/lib/module/components/Card/Card.js +1 -1
  65. package/lib/module/components/Carousel/Carousel.js +1 -1
  66. package/lib/module/components/Chip/Chip.js +1 -1
  67. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  68. package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
  69. package/lib/module/components/Drawer/Drawer.js +1 -1
  70. package/lib/module/components/EmptyState/EmptyState.js +1 -1
  71. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  72. package/lib/module/components/IconButton/IconButton.js +1 -1
  73. package/lib/module/components/ListItem/ListItem.js +1 -1
  74. package/lib/module/components/LoaderOverlay/LoaderOverlay.js +1 -1
  75. package/lib/module/components/Menu/MenuSurface.js +1 -1
  76. package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
  77. package/lib/module/components/Modal/Modal.js +1 -1
  78. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  79. package/lib/module/components/OnboardingPager/OnboardingPager.js +1 -1
  80. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  81. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  82. package/lib/module/components/Screen/Screen.js +1 -0
  83. package/lib/module/components/Screen/index.js +1 -0
  84. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  85. package/lib/module/components/Skeleton/Skeleton.js +1 -1
  86. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  87. package/lib/module/components/Skeleton/SkeletonProvider.js +1 -1
  88. package/lib/module/components/Skeleton/index.js +1 -1
  89. package/lib/module/components/Spinner/Spinner.js +1 -1
  90. package/lib/module/components/TagInput/TagInput.js +1 -1
  91. package/lib/module/components/Text/Text.js +1 -1
  92. package/lib/module/components/TimePicker/TimePicker.js +1 -1
  93. package/lib/module/components/Toast/Toast.js +1 -1
  94. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  95. package/lib/module/components/Tour/Tour.js +1 -1
  96. package/lib/module/components/WheelPicker/Wheel.js +1 -1
  97. package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
  98. package/lib/module/components/index.js +1 -1
  99. package/lib/module/hooks/index.js +1 -1
  100. package/lib/module/hooks/useDragToDismiss.js +1 -1
  101. package/lib/module/hooks/useFieldChain.js +1 -0
  102. package/lib/module/hooks/usePresenceMotion.js +1 -0
  103. package/lib/module/hooks/usePressAnimation.js +1 -1
  104. package/lib/module/hooks/useReducedMotion.js +1 -1
  105. package/lib/module/index.js +1 -1
  106. package/lib/module/network/NetworkStatusBanner.js +1 -1
  107. package/lib/module/theme/tokens.js +1 -1
  108. package/lib/module/utils/hapticUtils.js +1 -1
  109. package/lib/typescript/commonjs/components/AnimatePresence/AnimatePresence.d.ts +5 -5
  110. package/lib/typescript/commonjs/components/AsyncBlock/AsyncBlock.d.ts +11 -6
  111. package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +8 -2
  112. package/lib/typescript/commonjs/components/Button/Button.d.ts +6 -3
  113. package/lib/typescript/commonjs/components/Card/Card.d.ts +1 -1
  114. package/lib/typescript/commonjs/components/Carousel/Carousel.d.ts +2 -0
  115. package/lib/typescript/commonjs/components/ListItem/ListItem.d.ts +1 -1
  116. package/lib/typescript/commonjs/components/MessageBubble/MessageBubble.d.ts +6 -3
  117. package/lib/typescript/commonjs/components/OTPInput/OTPInput.d.ts +1 -2
  118. package/lib/typescript/commonjs/components/Screen/Screen.d.ts +39 -0
  119. package/lib/typescript/commonjs/components/Screen/index.d.ts +3 -0
  120. package/lib/typescript/commonjs/components/SignaturePad/SignaturePad.d.ts +6 -0
  121. package/lib/typescript/commonjs/components/Skeleton/Skeleton.d.ts +2 -2
  122. package/lib/typescript/commonjs/components/Skeleton/SkeletonProvider.d.ts +3 -11
  123. package/lib/typescript/commonjs/components/Skeleton/index.d.ts +1 -1
  124. package/lib/typescript/commonjs/components/WheelPicker/Wheel.d.ts +2 -0
  125. package/lib/typescript/commonjs/components/WheelPicker/WheelPicker.d.ts +5 -0
  126. package/lib/typescript/commonjs/components/index.d.ts +3 -1
  127. package/lib/typescript/commonjs/hooks/index.d.ts +4 -0
  128. package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +10 -2
  129. package/lib/typescript/commonjs/hooks/useFieldChain.d.ts +10 -0
  130. package/lib/typescript/commonjs/hooks/usePresenceMotion.d.ts +14 -0
  131. package/lib/typescript/commonjs/hooks/usePressAnimation.d.ts +2 -2
  132. package/lib/typescript/commonjs/hooks/useReducedMotion.d.ts +0 -6
  133. package/lib/typescript/commonjs/index.d.ts +2 -2
  134. package/lib/typescript/commonjs/theme/types.d.ts +4 -0
  135. package/lib/typescript/module/components/AnimatePresence/AnimatePresence.d.ts +5 -5
  136. package/lib/typescript/module/components/AsyncBlock/AsyncBlock.d.ts +11 -6
  137. package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +8 -2
  138. package/lib/typescript/module/components/Button/Button.d.ts +6 -3
  139. package/lib/typescript/module/components/Card/Card.d.ts +1 -1
  140. package/lib/typescript/module/components/Carousel/Carousel.d.ts +2 -0
  141. package/lib/typescript/module/components/ListItem/ListItem.d.ts +1 -1
  142. package/lib/typescript/module/components/MessageBubble/MessageBubble.d.ts +6 -3
  143. package/lib/typescript/module/components/OTPInput/OTPInput.d.ts +1 -2
  144. package/lib/typescript/module/components/Screen/Screen.d.ts +39 -0
  145. package/lib/typescript/module/components/Screen/index.d.ts +3 -0
  146. package/lib/typescript/module/components/SignaturePad/SignaturePad.d.ts +6 -0
  147. package/lib/typescript/module/components/Skeleton/Skeleton.d.ts +2 -2
  148. package/lib/typescript/module/components/Skeleton/SkeletonProvider.d.ts +3 -11
  149. package/lib/typescript/module/components/Skeleton/index.d.ts +1 -1
  150. package/lib/typescript/module/components/WheelPicker/Wheel.d.ts +2 -0
  151. package/lib/typescript/module/components/WheelPicker/WheelPicker.d.ts +5 -0
  152. package/lib/typescript/module/components/index.d.ts +3 -1
  153. package/lib/typescript/module/hooks/index.d.ts +4 -0
  154. package/lib/typescript/module/hooks/useDragToDismiss.d.ts +10 -2
  155. package/lib/typescript/module/hooks/useFieldChain.d.ts +10 -0
  156. package/lib/typescript/module/hooks/usePresenceMotion.d.ts +14 -0
  157. package/lib/typescript/module/hooks/usePressAnimation.d.ts +2 -2
  158. package/lib/typescript/module/hooks/useReducedMotion.d.ts +0 -6
  159. package/lib/typescript/module/index.d.ts +2 -2
  160. package/lib/typescript/module/theme/types.d.ts +4 -0
  161. package/package.json +3 -3
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{Text as ThemedText}from"../Text/Text.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const variantSize=(t,e)=>{switch(e){case"compact":return{height:44,titleSize:t.typography.fontSize.lg,titleWeight:"semibold",alignBottom:!1};case"large":return{height:96,titleSize:t.typography.fontSize["2xl"],titleWeight:"bold",alignBottom:!0};default:return{height:56,titleSize:t.typography.fontSize.lg,titleWeight:"semibold",alignBottom:!1}}},ActionButton=({action:t,side:e,badgeStyle:i,haptic:o,flush:n})=>{const r=useTheme(),{scale:a,pressIn:l,pressOut:s}=usePressAnimation({enabled:!0}),c=useMemo(()=>buildActionStyles(r),[r]),p=t.badge,d=void 0!==p&&0!==p,m=void 0!==t.text;return _jsx(Animated.View,{style:{transform:[{scale:a}]},children:_jsxs(Pressable,{onPress:()=>{const e=resolveHaptic(o,"selection");e&&triggerHaptic(e),t.onPress()},onPressIn:l,onPressOut:s,accessibilityRole:"button",accessibilityLabel:t.accessibilityLabel??t.text,testID:t.testID,android_ripple:{color:r.colors.surface.pressed,borderless:!m},style:({pressed:t})=>[m?c.textButton:c.actionButton,n?null:"left"===e?c.actionLeft:c.actionRight,t&&!m?c.actionPressed:null,t&&m?c.textPressed:null],children:[m?_jsx(Text,{style:c.actionText,numberOfLines:1,children:t.text}):_jsx(View,{style:c.iconWrap,children:t.icon}),d?_jsx(View,{style:[c.badge,i],pointerEvents:"none",children:_jsx(Text,{style:c.badgeText,numberOfLines:1,children:String(p)})}):null,t.dot?_jsx(View,{testID:t.testID?`${t.testID}-dot`:"appbar-action-dot",style:c.dot,pointerEvents:"none"}):null]})})},COLLAPSE_RANGE=60,LARGE_TITLE_SCALE_END=.71,AppBar=forwardRef((t,e)=>{const{title:i,subtitle:o,titleAlignment:n="left",leftAction:r,rightActions:a,leading:l,trailing:s,onBack:c,gutter:p,titleVariant:d,titleOffset:m,height:g,divider:u,variant:h="default",transparent:f=!1,scrollY:x,style:y,containerStyle:b,titleStyle:S,subtitleStyle:B,badgeStyle:A,haptic:j,testID:T}=t,w=useTheme(),z=useSafeAreaInsets(),C=useMemo(()=>variantSize(w,h),[w,h]),_=useMemo(()=>buildStyles(w),[w]),I="large"===h&&void 0!==x,R=w.components.appBar?.iconSize??24,v=w.components.appBar?.actionButtonSize??44,W=r??(c?{icon:_jsx(AppIcon,{name:"arrow-left",size:R,color:w.colors.text.primary}),onPress:c,accessibilityLabel:"Back"}:void 0),L=s?void 0:a?.[a.length-1],opticalInset=t=>void 0===t?0:void 0!==t.text?w.spacing.sm:Math.max((v-R)/2,0),V=void 0===p?null:{paddingLeft:Math.max(p-opticalInset(W),0),paddingRight:Math.max(p-opticalInset(L),0)},O=void 0!==m,P=Boolean(W)||Boolean(l),H=u??!f,D=w.components.appBar?.dividerWidth??StyleSheet.hairlineWidth,E=w.components.appBar?.collapseTranslateDistance??-20,M=useMemo(()=>{if(!x)return null;const t={inputRange:[0,60],extrapolate:"clamp"};return{titleScale:x.interpolate({...t,outputRange:[1,.71]}),titleTranslateY:x.interpolate({...t,outputRange:[0,E]}),titleTranslateX:x.interpolate({...t,outputRange:"center"===n?[0,0]:[0,8]}),subtitleOpacity:x.interpolate({inputRange:[0,30],outputRange:[1,0],extrapolate:"clamp"}),barHeight:x.interpolate({...t,outputRange:[96,56]}),borderOpacity:x.interpolate({...t,outputRange:[0,1]})}},[x,n,E]),k=I&&M?{transform:[{translateX:M.titleTranslateX},{translateY:M.titleTranslateY},{scale:M.titleScale}]}:null,F=i?d?_jsx(Animated.View,{style:k,children:_jsx(ThemedText,{variant:d,align:"center"===n?"center":"left",accessibilityRole:"header",numberOfLines:1,style:[_.titleVariant,S],children:i})}):_jsx(Animated.Text,{accessibilityRole:"header",style:[_.title,{fontSize:C.titleSize,fontWeight:w.typography.fontWeight[C.titleWeight],textAlign:"center"===n?"center":"left"},k,S],numberOfLines:1,children:i}):null,Y=o?_jsx(Animated.Text,{style:[_.subtitle,{textAlign:"center"===n?"center":"left"},I&&M?{opacity:M.subtitleOpacity}:null,B],numberOfLines:1,children:o}):null,N=_jsxs(View,{style:[_.titleColumn,"center"===n?_.titleColumnCenter:null,C.alignBottom?_.titleColumnBottom:null],children:[F,Y]}),X=I?Animated.View:View,G=I&&M?{height:Animated.add(M.barHeight,new Animated.Value(z.top))}:{height:(g??C.height)+z.top};return _jsxs(X,{ref:e,testID:T,style:[_.root,{paddingTop:z.top,backgroundColor:f?"transparent":w.colors.background.elevated},G,!I&&H?{borderBottomWidth:D,borderBottomColor:w.colors.border.primary}:null,y,b],children:[I&&M&&H?_jsx(Animated.View,{pointerEvents:"none",style:[_.animatedBorder,{backgroundColor:w.colors.border.primary,opacity:M.borderOpacity}]}):null,_jsxs(View,{style:[_.row,C.alignBottom?_.rowAlignBottom:null,V,{flex:1}],children:[_jsxs(View,{style:[_.sideSlot,O?_.sideSlotCompact:null],children:[W?_jsx(ActionButton,{action:W,side:"left",haptic:j,flush:O}):null,l]}),_jsx(View,{pointerEvents:"none",style:[_.center,"center"===n?_.centerAligned:_.centerLeft,O?{paddingLeft:P?m:0,paddingRight:0}:null],children:N}),_jsxs(View,{style:[_.sideSlot,_.sideSlotRight,O?_.sideSlotCompact:null],children:[a?.map((t,e)=>_jsx(ActionButton,{action:t,side:"right",badgeStyle:A,haptic:j,flush:O},`appbar-right-${e}`)),s]})]})]})});AppBar.displayName="AppBar";const buildStyles=t=>StyleSheet.create({root:{width:"100%"},row:{flexDirection:"row",alignItems:"center",paddingHorizontal:t.spacing.xs},rowAlignBottom:{alignItems:"flex-end",paddingBottom:t.spacing.sm},sideSlot:{flexDirection:"row",alignItems:"center",minWidth:t.components.appBar?.sideSlotMinWidth??48},sideSlotRight:{justifyContent:"flex-end"},sideSlotCompact:{minWidth:0},center:{flex:1,paddingHorizontal:t.spacing.xs},centerAligned:{alignItems:"center"},centerLeft:{alignItems:"flex-start"},titleColumn:{flexDirection:"column"},titleColumnCenter:{alignItems:"center"},titleColumnBottom:{justifyContent:"flex-end"},title:{color:t.colors.text.primary},titleVariant:{includeFontPadding:!1,textAlignVertical:"center"},subtitle:{marginTop:t.components.appBar?.subtitleMarginTop??2,color:t.colors.text.tertiary,fontSize:t.typography.fontSize.sm,fontWeight:t.typography.fontWeight.normal},animatedBorder:{position:"absolute",left:0,right:0,bottom:0,height:StyleSheet.hairlineWidth}}),buildActionStyles=t=>StyleSheet.create({actionButton:{width:t.components.appBar?.actionButtonSize??44,height:t.components.appBar?.actionButtonSize??44,borderRadius:t.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center"},actionLeft:{marginRight:t.spacing.xs},actionRight:{marginLeft:t.spacing.xs},actionPressed:{backgroundColor:t.colors.surface.pressed},textButton:{minWidth:44,minHeight:44,paddingHorizontal:t.spacing.sm,alignItems:"center",justifyContent:"center"},textPressed:{opacity:.6},actionText:{color:t.colors.text.link,fontSize:t.typography.fontSize.base,...fontFor(t,"semibold")},dot:{position:"absolute",top:t.components.appBar?.dotOffset??10,right:t.components.appBar?.dotOffset??10,width:t.components.appBar?.dotSize??8,height:t.components.appBar?.dotSize??8,borderRadius:t.radius.full,backgroundColor:t.colors.error},iconWrap:{alignItems:"center",justifyContent:"center"},badge:{position:"absolute",top:t.components.appBar?.badgeOffset??4,right:t.components.appBar?.badgeOffset??4,minWidth:t.components.appBar?.badgeMinWidth??16,height:t.components.appBar?.badgeHeight??16,paddingHorizontal:t.components.appBar?.badgePaddingHorizontal??4,borderRadius:t.radius.full,...smoothCorners,backgroundColor:t.colors.error,alignItems:"center",justifyContent:"center"},badgeText:{color:t.colors.onError,fontSize:t.components.appBar?.badgeFontSize??10,fontWeight:t.typography.fontWeight.semibold,lineHeight:t.components.appBar?.badgeLineHeight??12}});export{AppBar};export default AppBar;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{Text as ThemedText}from"../Text/Text.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const variantSize=(t,e)=>{switch(e){case"compact":return{height:44,titleSize:t.typography.fontSize.lg,titleWeight:"semibold",alignBottom:!1};case"large":return{height:96,titleSize:t.typography.fontSize["2xl"],titleWeight:"bold",alignBottom:!0};default:return{height:56,titleSize:t.typography.fontSize.lg,titleWeight:"semibold",alignBottom:!1}}},ActionButton=({action:t,side:e,badgeStyle:i,haptic:o,flush:n})=>{const r=useTheme(),{style:a,pressIn:l,pressOut:s}=usePressAnimation({enabled:!0}),c=useMemo(()=>buildActionStyles(r),[r]),p=t.badge,d=void 0!==p&&0!==p,m=void 0!==t.text;return _jsx(Animated.View,{style:a,children:_jsxs(Pressable,{onPress:()=>{const e=resolveHaptic(o,"selection");e&&triggerHaptic(e),t.onPress()},onPressIn:l,onPressOut:s,accessibilityRole:"button",accessibilityLabel:t.accessibilityLabel??t.text,testID:t.testID,android_ripple:{color:r.colors.surface.pressed,borderless:!m},style:({pressed:t})=>[m?c.textButton:c.actionButton,n?null:"left"===e?c.actionLeft:c.actionRight,t&&!m?c.actionPressed:null,t&&m?c.textPressed:null],children:[m?_jsx(Text,{style:c.actionText,numberOfLines:1,children:t.text}):_jsx(View,{style:c.iconWrap,children:t.icon}),d?_jsx(View,{style:[c.badge,i],pointerEvents:"none",children:_jsx(Text,{style:c.badgeText,numberOfLines:1,children:String(p)})}):null,t.dot?_jsx(View,{testID:t.testID?`${t.testID}-dot`:"appbar-action-dot",style:c.dot,pointerEvents:"none"}):null]})})},COLLAPSE_RANGE=60,LARGE_TITLE_SCALE_END=.71,AppBar=forwardRef((t,e)=>{const{title:i,subtitle:o,titleAlignment:n="left",leftAction:r,rightActions:a,leading:l,trailing:s,onBack:c,gutter:p,titleVariant:d,titleOffset:m,height:g,divider:u,variant:h="default",transparent:f=!1,scrollY:x,style:y,containerStyle:b,titleStyle:S,subtitleStyle:B,badgeStyle:A,haptic:j,testID:T}=t,w=useTheme(),z=useSafeAreaInsets(),C=useMemo(()=>variantSize(w,h),[w,h]),_=useMemo(()=>buildStyles(w),[w]),I="large"===h&&void 0!==x,R=w.components.appBar?.iconSize??24,v=w.components.appBar?.actionButtonSize??44,W=r??(c?{icon:_jsx(AppIcon,{name:"arrow-left",size:R,color:w.colors.text.primary}),onPress:c,accessibilityLabel:"Back"}:void 0),L=s?void 0:a?.[a.length-1],opticalInset=t=>void 0===t?0:void 0!==t.text?w.spacing.sm:Math.max((v-R)/2,0),V=void 0===p?null:{paddingLeft:Math.max(p-opticalInset(W),0),paddingRight:Math.max(p-opticalInset(L),0)},O=void 0!==m,P=Boolean(W)||Boolean(l),H=u??!f,D=w.components.appBar?.dividerWidth??StyleSheet.hairlineWidth,E=w.components.appBar?.collapseTranslateDistance??-20,M=useMemo(()=>{if(!x)return null;const t={inputRange:[0,60],extrapolate:"clamp"};return{titleScale:x.interpolate({...t,outputRange:[1,.71]}),titleTranslateY:x.interpolate({...t,outputRange:[0,E]}),titleTranslateX:x.interpolate({...t,outputRange:"center"===n?[0,0]:[0,8]}),subtitleOpacity:x.interpolate({inputRange:[0,30],outputRange:[1,0],extrapolate:"clamp"}),barHeight:x.interpolate({...t,outputRange:[96,56]}),borderOpacity:x.interpolate({...t,outputRange:[0,1]})}},[x,n,E]),k=I&&M?{transform:[{translateX:M.titleTranslateX},{translateY:M.titleTranslateY},{scale:M.titleScale}]}:null,F=i?d?_jsx(Animated.View,{style:k,children:_jsx(ThemedText,{variant:d,align:"center"===n?"center":"left",accessibilityRole:"header",numberOfLines:1,style:[_.titleVariant,S],children:i})}):_jsx(Animated.Text,{accessibilityRole:"header",style:[_.title,{fontSize:C.titleSize,fontWeight:w.typography.fontWeight[C.titleWeight],textAlign:"center"===n?"center":"left"},k,S],numberOfLines:1,children:i}):null,Y=o?_jsx(Animated.Text,{style:[_.subtitle,{textAlign:"center"===n?"center":"left"},I&&M?{opacity:M.subtitleOpacity}:null,B],numberOfLines:1,children:o}):null,N=_jsxs(View,{style:[_.titleColumn,"center"===n?_.titleColumnCenter:null,C.alignBottom?_.titleColumnBottom:null],children:[F,Y]}),X=I?Animated.View:View,G=I&&M?{height:Animated.add(M.barHeight,new Animated.Value(z.top))}:{height:(g??C.height)+z.top};return _jsxs(X,{ref:e,testID:T,style:[_.root,{paddingTop:z.top,backgroundColor:f?"transparent":w.colors.background.elevated},G,!I&&H?{borderBottomWidth:D,borderBottomColor:w.colors.border.primary}:null,y,b],children:[I&&M&&H?_jsx(Animated.View,{pointerEvents:"none",style:[_.animatedBorder,{backgroundColor:w.colors.border.primary,opacity:M.borderOpacity}]}):null,_jsxs(View,{style:[_.row,C.alignBottom?_.rowAlignBottom:null,V,{flex:1}],children:[_jsxs(View,{style:[_.sideSlot,O?_.sideSlotCompact:null],children:[W?_jsx(ActionButton,{action:W,side:"left",haptic:j,flush:O}):null,l]}),_jsx(View,{pointerEvents:"none",style:[_.center,"center"===n?_.centerAligned:_.centerLeft,O?{paddingLeft:P?m:0,paddingRight:0}:null],children:N}),_jsxs(View,{style:[_.sideSlot,_.sideSlotRight,O?_.sideSlotCompact:null],children:[a?.map((t,e)=>_jsx(ActionButton,{action:t,side:"right",badgeStyle:A,haptic:j,flush:O},`appbar-right-${e}`)),s]})]})]})});AppBar.displayName="AppBar";const buildStyles=t=>StyleSheet.create({root:{width:"100%"},row:{flexDirection:"row",alignItems:"center",paddingHorizontal:t.spacing.xs},rowAlignBottom:{alignItems:"flex-end",paddingBottom:t.spacing.sm},sideSlot:{flexDirection:"row",alignItems:"center",minWidth:t.components.appBar?.sideSlotMinWidth??48},sideSlotRight:{justifyContent:"flex-end"},sideSlotCompact:{minWidth:0},center:{flex:1,paddingHorizontal:t.spacing.xs},centerAligned:{alignItems:"center"},centerLeft:{alignItems:"flex-start"},titleColumn:{flexDirection:"column"},titleColumnCenter:{alignItems:"center"},titleColumnBottom:{justifyContent:"flex-end"},title:{color:t.colors.text.primary},titleVariant:{includeFontPadding:!1,textAlignVertical:"center"},subtitle:{marginTop:t.components.appBar?.subtitleMarginTop??2,color:t.colors.text.tertiary,fontSize:t.typography.fontSize.sm,fontWeight:t.typography.fontWeight.normal},animatedBorder:{position:"absolute",left:0,right:0,bottom:0,height:StyleSheet.hairlineWidth}}),buildActionStyles=t=>StyleSheet.create({actionButton:{width:t.components.appBar?.actionButtonSize??44,height:t.components.appBar?.actionButtonSize??44,borderRadius:t.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center"},actionLeft:{marginRight:t.spacing.xs},actionRight:{marginLeft:t.spacing.xs},actionPressed:{backgroundColor:t.colors.surface.pressed},textButton:{minWidth:44,minHeight:44,paddingHorizontal:t.spacing.sm,alignItems:"center",justifyContent:"center"},textPressed:{opacity:.6},actionText:{color:t.colors.text.link,fontSize:t.typography.fontSize.base,...fontFor(t,"semibold")},dot:{position:"absolute",top:t.components.appBar?.dotOffset??10,right:t.components.appBar?.dotOffset??10,width:t.components.appBar?.dotSize??8,height:t.components.appBar?.dotSize??8,borderRadius:t.radius.full,backgroundColor:t.colors.error},iconWrap:{alignItems:"center",justifyContent:"center"},badge:{position:"absolute",top:t.components.appBar?.badgeOffset??4,right:t.components.appBar?.badgeOffset??4,minWidth:t.components.appBar?.badgeMinWidth??16,height:t.components.appBar?.badgeHeight??16,paddingHorizontal:t.components.appBar?.badgePaddingHorizontal??4,borderRadius:t.radius.full,...smoothCorners,backgroundColor:t.colors.error,alignItems:"center",justifyContent:"center"},badgeText:{color:t.colors.onError,fontSize:t.components.appBar?.badgeFontSize??10,fontWeight:t.typography.fontWeight.semibold,lineHeight:t.components.appBar?.badgeLineHeight??12}});export{AppBar};export default AppBar;
@@ -1 +1 @@
1
- "use strict";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{AppIcon}from"../AppIcon/index.js";import{EmptyState}from"../EmptyState/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const OFFLINE_HINT="Check your connection, then try again.";export const AsyncBlock=({loading:e=!1,error:t,errorVariant:n="default",empty:r=!1,onRetry:i,skeleton:o,emptyTitle:s="Nothing here yet",emptyDescription:c,emptyIcon:l,errorTitle:a="That didn't load",offlineTitle:p="You're offline",retryLabel:m="Try again",children:y,style:d,testID:x})=>{const f=useTheme();if(e)return _jsx(View,{style:d,testID:x,children:o??_jsx(View,{style:{paddingVertical:f.spacing["2xl"],alignItems:"center"},children:_jsx(Spinner,{})})});if(t){const e="offline"===n,r="string"==typeof t?t:e?OFFLINE_HINT:void 0;return _jsxs(View,{style:d,testID:x,children:[_jsx(EmptyState,{icon:e?_jsx(AppIcon,{name:"cloud-cross",size:"xl",color:f.colors.text.tertiary,testID:"async-block-offline-icon"}):void 0,title:e?p:a,description:r,action:i?{label:m,onPress:i}:void 0}),"string"==typeof t?null:t]})}return r?_jsx(View,{style:d,testID:x,children:_jsx(EmptyState,{icon:l,title:s,description:c})}):_jsx(_Fragment,{children:y})};export default AsyncBlock;
1
+ "use strict";import{extractApiError,OFFLINE_CODE}from"@webority/mobile-core";import{isValidElement}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{AppIcon}from"../AppIcon/index.js";import{EmptyState}from"../EmptyState/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const OFFLINE_HINT="Check your connection, then try again.",isNode=e=>isValidElement(e)||Array.isArray(e);export const AsyncBlock=({loading:e=!1,error:t,errorVariant:r,empty:i=!1,onRetry:o,skeleton:n,emptyTitle:s="Nothing here yet",emptyDescription:l,emptyIcon:c,errorTitle:a="That didn't load",offlineTitle:m="You're offline",retryLabel:p="Try again",children:d,style:y,testID:x})=>{const f=useTheme();if(e)return _jsx(View,{style:y,testID:x,children:n??_jsx(View,{style:{paddingVertical:f.spacing["2xl"],alignItems:"center"},children:_jsx(Spinner,{})})});if(t){const e="string"==typeof t?t:null,i=null!==e||isNode(t)?null:extractApiError(t),n="offline"===(r??(i?.code===OFFLINE_CODE?"offline":"default")),s=e??i?.message??(n?OFFLINE_HINT:void 0);return _jsxs(View,{style:y,testID:x,children:[_jsx(EmptyState,{icon:n?_jsx(AppIcon,{name:"cloud-cross",size:"xl",color:f.colors.text.tertiary,testID:"async-block-offline-icon"}):void 0,title:n?m:a,description:s,action:o?{label:p,onPress:o}:void 0}),isNode(t)?t:null]})}return i?_jsx(View,{style:y,testID:x,children:_jsx(EmptyState,{icon:c,title:s,description:l})}):_jsx(_Fragment,{children:d})};export default AsyncBlock;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Banner=forwardRef((e,n)=>{const{title:t,message:o,variant:r="info",icon:i,actions:s,dismissible:a=!1,onDismiss:l,haptic:c,visible:d=!0,animateMount:p=!0,loading:m=!1,accessibilityRole:u="alert",accessibilityLabel:g,style:h,containerStyle:y,iconCircleStyle:b,tintBarStyle:x,closeButtonStyle:f,actionButtonStyle:S,testID:w}=e,j=useTheme(),B=useMemo(()=>buildStyles(j),[j]),k=useMemo(()=>tintFor(j,r),[j,r]),R=useRef(createAnimatedValue(p&&d?-20:0)).current,C=useRef(createAnimatedValue(p&&d?0:d?1:0)).current,[_,T]=useState(d),V=useRef(!0);if(useEffect(()=>{if(V.current&&(V.current=!1,!p))return;let e;return d?(T(!0),e=Animated.parallel([Animated.timing(R,{toValue:0,duration:j.motion.duration.normal,useNativeDriver:!0}),Animated.timing(C,{toValue:1,duration:j.motion.duration.normal,useNativeDriver:!0})]),e.start()):_&&(e=Animated.parallel([Animated.timing(R,{toValue:-20,duration:j.motion.duration.fast,useNativeDriver:!0}),Animated.timing(C,{toValue:0,duration:j.motion.duration.fast,useNativeDriver:!0})]),e.start(()=>{T(!1)})),()=>e?.stop()},[d]),!_)return null;const v=t??" ",z="string"==typeof o?o??" ":"",H="alert"===u?"error"===r?"assertive":"polite":"none",W=_jsxs(Animated.View,{ref:n,accessibilityRole:u,accessibilityLiveRegion:H,accessibilityLabel:g,testID:w,style:[B.container,{backgroundColor:j.colors.background.secondary,borderRadius:j.radius.md,...smoothCorners,padding:j.spacing.md,opacity:C,transform:[{translateY:R}]},h,y],children:[(j.components.banner?.tintBarWidth??0)>0?_jsx(View,{style:[B.tintBar,{backgroundColor:k.bar},x]}):null,_jsxs(View,{style:B.row,children:[!1===i?null:_jsx(View,i?{style:B.iconWrap,children:i}:{style:[B.iconCircle,{backgroundColor:k.bar+"22"},b],children:_jsx(Text,{style:[B.iconGlyph,{color:k.ink}],accessible:!1,children:k.glyph})}),_jsxs(View,{style:B.textBlock,children:[t||m?_jsx(Text,{style:{color:j.colors.text.primary,fontSize:j.typography.fontSize.base,...fontFor(j,"semibold"),lineHeight:20},numberOfLines:2,children:v}):null,"string"==typeof o||m?_jsx(Text,{style:{color:j.colors.text.secondary,fontSize:j.typography.fontSize.sm,...fontFor(j,"normal"),lineHeight:18,marginTop:t?2:0},children:z||" "}):_jsx(View,{style:{marginTop:t?2:0},children:o})]}),a?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),l?.()},hitSlop:8,style:({pressed:e})=>[B.closeBtn,{backgroundColor:e?j.colors.surface.pressed:"transparent"},f],children:_jsx(Text,{style:{color:j.colors.text.secondary,fontSize:j.components.banner?.closeGlyphFontSize??18,fontWeight:j.typography.fontWeight.bold,lineHeight:18},accessible:!1,children:"×"})}):null]}),s&&s.length>0?_jsx(View,{style:B.actionsRow,children:s.map((e,n)=>{const t=e.tone??"primary",o=e.variant??"ghost",r="danger"===t?j.colors.error:"neutral"===t?j.colors.text.secondary:k.glyphColor,i="danger"===t?j.colors.toneText.error:"neutral"===t?j.colors.text.secondary:k.ink,s="danger"===t?j.colors.onError:"neutral"===t?j.colors.onNeutral:k.on,a="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const n=resolveHaptic(c,"selection");n&&triggerHaptic(n),e.onPress()},style:({pressed:n})=>[B.actionBtn,"md"===e.size&&B.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:i},{backgroundColor:a?r:n?j.colors.surface.pressed:"transparent",opacity:a&&n?.85:1},S],children:_jsx(Text,{style:{color:a?s:i,fontSize:j.typography.fontSize.sm,textAlign:"center",...fontFor(j,"semibold")},children:e.label})},`${e.label}-${n}`)})}):null]});return m?_jsx(BannerSkeleton,{...e}):W});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:n,icon:t,containerStyle:o,style:r})=>{const i=useTheme(),s=!1!==t;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:i.colors.background.elevated,borderRadius:i.radius.md,...smoothCorners,padding:i.spacing.md,borderWidth:1,borderColor:i.colors.border.primary},o,r],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(View,{style:{marginRight:i.spacing.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:i.spacing.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:13,lastLineWidth:"70%"}),n&&n.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:i.spacing.sm},children:n.map((e,n)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:i.spacing.sm}},`sk-banner-action-${n}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,n)=>{switch(n){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors.toneText.success,on:e.colors.onSuccess,glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors.toneText.warning,on:e.colors.onWarning,glyph:"⚠"};case"error":return{bar:e.colors.error,glyphColor:e.colors.error,ink:e.colors.toneText.error,on:e.colors.onError,glyph:"✗"};case"neutral":return{bar:e.colors.text.tertiary,glyphColor:e.colors.text.secondary,ink:e.colors.text.secondary,on:e.colors.onNeutral,glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors.toneText.primary,on:e.colors.onPrimary,glyph:"i"}}},buildStyles=e=>{const n=e.components.banner?.iconCircleSize??28,t=e.components.banner?.closeButtonSize??28;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.components.banner?.containerPaddingLeft??e.spacing.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:e.components.banner?.tintBarWidth??0},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:e.components.banner?.iconGap??e.spacing.sm},iconCircle:{width:n,height:n,borderRadius:e.components.banner?.iconCircleRadius??n/2,...smoothCorners,alignItems:"center",justifyContent:"center",marginRight:e.components.banner?.iconGap??e.spacing.sm},iconGlyph:{fontSize:e.components.banner?.iconGlyphFontSize??15,fontWeight:"700",lineHeight:e.components.banner?.iconGlyphLineHeight??17},textBlock:{flex:1,paddingRight:e.components.banner?.textBlockPaddingRight??e.spacing.xs},closeBtn:{width:t,height:t,borderRadius:e.components.banner?.closeButtonRadius??t/2,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.components.banner?.closeButtonMarginLeft??e.spacing.xxs??4},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.components.banner?.actionsRowMarginTop??e.spacing.xs,columnGap:e.components.banner?.actionsRowGap??e.spacing.xs,rowGap:e.components.banner?.actionsRowGap??e.spacing.xs},actionBtn:{paddingHorizontal:e.components.banner?.actionButtonPaddingHorizontal??e.spacing.sm,paddingVertical:e.components.banner?.actionButtonPaddingVertical??6,borderRadius:e.components.banner?.actionButtonRadius??e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.spacing.md}})};export{Banner};export default Banner;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Banner=forwardRef((e,n)=>{const{title:t,message:o,variant:r="info",icon:i,actions:s,dismissible:a=!1,onDismiss:l,haptic:c,visible:d=!0,animateMount:p=!0,loading:m=!1,accessibilityRole:u="alert",accessibilityLabel:g,style:h,containerStyle:y,iconCircleStyle:b,tintBarStyle:x,closeButtonStyle:f,actionButtonStyle:S,testID:w}=e,j=useTheme(),B=usePresenceMotion(),k=useMemo(()=>buildStyles(j),[j]),R=useMemo(()=>tintFor(j,r),[j,r]),[C,_]=B.range(-20,0),T=useRef(createAnimatedValue(p&&d?C:0)).current,V=useRef(createAnimatedValue(p&&d?0:d?1:0)).current,[v,z]=useState(d),H=useRef(!0);if(useEffect(()=>{if(H.current&&(H.current=!1,!p))return;let e;return d?(z(!0),e=Animated.parallel([Animated.timing(T,{toValue:_,duration:j.motion.duration.normal,useNativeDriver:!0}),Animated.timing(V,{toValue:1,duration:B.duration("normal"),useNativeDriver:!0})]),e.start()):v&&(e=Animated.parallel([Animated.timing(T,{toValue:C,duration:j.motion.duration.fast,useNativeDriver:!0}),Animated.timing(V,{toValue:0,duration:B.duration("fast"),useNativeDriver:!0})]),e.start(()=>{z(!1)})),()=>e?.stop()},[d]),!v)return null;const P=t??" ",W="string"==typeof o?o??" ":"",A="alert"===u?"error"===r?"assertive":"polite":"none",D=_jsxs(Animated.View,{ref:n,accessibilityRole:u,accessibilityLiveRegion:A,accessibilityLabel:g,testID:w,style:[k.container,{backgroundColor:j.colors.background.secondary,borderRadius:j.radius.md,...smoothCorners,padding:j.spacing.md,opacity:V,transform:[{translateY:T}]},h,y],children:[(j.components.banner?.tintBarWidth??0)>0?_jsx(View,{style:[k.tintBar,{backgroundColor:R.bar},x]}):null,_jsxs(View,{style:k.row,children:[!1===i?null:_jsx(View,i?{style:k.iconWrap,children:i}:{style:[k.iconCircle,{backgroundColor:R.bar+"22"},b],children:_jsx(Text,{style:[k.iconGlyph,{color:R.ink}],accessible:!1,children:R.glyph})}),_jsxs(View,{style:k.textBlock,children:[t||m?_jsx(Text,{style:{color:j.colors.text.primary,fontSize:j.typography.fontSize.base,...fontFor(j,"semibold"),lineHeight:20},numberOfLines:2,children:P}):null,"string"==typeof o||m?_jsx(Text,{style:{color:j.colors.text.secondary,fontSize:j.typography.fontSize.sm,...fontFor(j,"normal"),lineHeight:18,marginTop:t?2:0},children:W||" "}):_jsx(View,{style:{marginTop:t?2:0},children:o})]}),a?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),l?.()},hitSlop:8,style:({pressed:e})=>[k.closeBtn,{backgroundColor:e?j.colors.surface.pressed:"transparent"},f],children:_jsx(Text,{style:{color:j.colors.text.secondary,fontSize:j.components.banner?.closeGlyphFontSize??18,fontWeight:j.typography.fontWeight.bold,lineHeight:18},accessible:!1,children:"×"})}):null]}),s&&s.length>0?_jsx(View,{style:k.actionsRow,children:s.map((e,n)=>{const t=e.tone??"primary",o=e.variant??"ghost",r="danger"===t?j.colors.error:"neutral"===t?j.colors.text.secondary:R.glyphColor,i="danger"===t?j.colors.toneText.error:"neutral"===t?j.colors.text.secondary:R.ink,s="danger"===t?j.colors.onError:"neutral"===t?j.colors.onNeutral:R.on,a="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const n=resolveHaptic(c,"selection");n&&triggerHaptic(n),e.onPress()},style:({pressed:n})=>[k.actionBtn,"md"===e.size&&k.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:i},{backgroundColor:a?r:n?j.colors.surface.pressed:"transparent",opacity:a&&n?.85:1},S],children:_jsx(Text,{style:{color:a?s:i,fontSize:j.typography.fontSize.sm,textAlign:"center",...fontFor(j,"semibold")},children:e.label})},`${e.label}-${n}`)})}):null]});return m?_jsx(BannerSkeleton,{...e}):D});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:n,icon:t,containerStyle:o,style:r})=>{const i=useTheme(),s=!1!==t;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:i.colors.background.elevated,borderRadius:i.radius.md,...smoothCorners,padding:i.spacing.md,borderWidth:1,borderColor:i.colors.border.primary},o,r],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(View,{style:{marginRight:i.spacing.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:i.spacing.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:13,lastLineWidth:"70%"}),n&&n.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:i.spacing.sm},children:n.map((e,n)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:i.spacing.sm}},`sk-banner-action-${n}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,n)=>{switch(n){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors.toneText.success,on:e.colors.onSuccess,glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors.toneText.warning,on:e.colors.onWarning,glyph:"⚠"};case"error":return{bar:e.colors.error,glyphColor:e.colors.error,ink:e.colors.toneText.error,on:e.colors.onError,glyph:"✗"};case"neutral":return{bar:e.colors.text.tertiary,glyphColor:e.colors.text.secondary,ink:e.colors.text.secondary,on:e.colors.onNeutral,glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors.toneText.primary,on:e.colors.onPrimary,glyph:"i"}}},buildStyles=e=>{const n=e.components.banner?.iconCircleSize??28,t=e.components.banner?.closeButtonSize??28;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.components.banner?.containerPaddingLeft??e.spacing.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:e.components.banner?.tintBarWidth??0},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:e.components.banner?.iconGap??e.spacing.sm},iconCircle:{width:n,height:n,borderRadius:e.components.banner?.iconCircleRadius??n/2,...smoothCorners,alignItems:"center",justifyContent:"center",marginRight:e.components.banner?.iconGap??e.spacing.sm},iconGlyph:{fontSize:e.components.banner?.iconGlyphFontSize??15,fontWeight:"700",lineHeight:e.components.banner?.iconGlyphLineHeight??17},textBlock:{flex:1,paddingRight:e.components.banner?.textBlockPaddingRight??e.spacing.xs},closeBtn:{width:t,height:t,borderRadius:e.components.banner?.closeButtonRadius??t/2,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.components.banner?.closeButtonMarginLeft??e.spacing.xxs??4},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.components.banner?.actionsRowMarginTop??e.spacing.xs,columnGap:e.components.banner?.actionsRowGap??e.spacing.xs,rowGap:e.components.banner?.actionsRowGap??e.spacing.xs},actionBtn:{paddingHorizontal:e.components.banner?.actionButtonPaddingHorizontal??e.spacing.sm,paddingVertical:e.components.banner?.actionButtonPaddingVertical??6,borderRadius:e.components.banner?.actionButtonRadius??e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.spacing.md}})};export{Banner};export default Banner;
@@ -1 +1 @@
1
- "use strict";import{createContext,forwardRef,useCallback,useContext,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Modal,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=forwardRef((e,t)=>{const{snapPoints:o,index:s,onChange:n,onAnimate:r,onAfterClose:a,enablePanDownToClose:l=!0,enableBackdropPress:i=!0,confirmDismiss:u,scrollable:c=!1,scrollRef:d,onScroll:h,onContentSizeChange:m,onScrollLayout:f,scrollEventThrottle:b,keyboardBehavior:S="shift",mode:p="modal",presentation:g="sheet",handleIndicatorStyle:y,containerStyle:v,header:w,footer:x,headerStyle:C,footerStyle:k,children:R,accessibilityLabel:M,accessibilityViewIsModal:I,testID:_}=e,j=useTheme(),T=useSafeAreaInsets(),[V,D]=useState(()=>Dimensions.get("window").height),[O,A]=useState(()=>Dimensions.get("window").width),H=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&D(e=>e===t?e:t),o>0&&A(e=>e===o?e:o)},[]),B=useWindowDimensions(),E="dialog"===g||"auto"===g&&Math.min(B.width,B.height)>=600,P=Math.min(560,O-2*j.spacing.xl),[G,L]=useModalInsets(),N="modal"===p?G.top:T.top,F="modal"===p?G.bottom:T.bottom,J=o.includes("content"),[z,Y]=useMeasuredHeight(),[$,q]=useMeasuredHeight(),[W,K,X]=useMeasuredHeight(),[U,Q]=useMeasuredHeight(),Z=E?j.spacing.md:z,ee=J?Math.min(Z+(null!=w?$:0)+W+(null!=x?U:0)+F,V-N):0,te=useCallback((e,t)=>{J&&X(t),m?.(e,t)},[J,m,X]),oe=useMemo(()=>resolveSnapPoints(o,V,ee),[o,V,ee]),se=V,ne=oe[oe.length-1]??0,re=useSharedValue(se),ae=useSharedValue(se),le=useSharedValue(-1),[ie,ue]=useState(-1),ce=useRef(!1),[de,he]=useState(!1),[me,fe]=useState(!1),be=useRef(!1),Se=useRef(a);Se.current=a;const[pe,ge]=useState(!1),ye=useRef(-1),ve=useRef(!1);ve.current="modal"===p?me:pe;const we=useRef(u);we.current=u;const xe=useRef(!1),Ce=useRef(!0),ke=useRef([]),Re=useCallback(e=>{const t=ke.current;ke.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ce.current=!0,()=>{Ce.current=!1,Re(!1)}),[Re]);const Me=useCallback(e=>{if(e<0||e>=oe.length)return se;const t=oe[e];return E?(V-t)/2:V-t},[oe,V,se,E]),Ie=useCallback(e=>{ye.current=e;ie!==e&&(ue(e),le.value=e,n?.(e))},[ie,le,n]),je=useCallback(()=>{ce.current=!1,le.value<0&&(be.current=!0,"modal"===p?(he(!1),"ios"!==Platform.OS&&fe(!1)):ge(!1))},[p,le]),Te=useCallback(()=>{be.current&&fe(!1)},[]);useEffect(()=>{("modal"===p?!me:!pe)&&be.current&&(be.current=!1,Se.current?.(),Re(!0))},[p,me,pe,Re]);const Ve=useCallback((e,t,o)=>{ce.current=!0,r?.(t,o),re.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(je)()})},[r,re,je]),De=useCallback(e=>{const t="number"==typeof e?clamp(e,0,oe.length-1):ie>=0?ie:0,o=le.value,s=Me(t);be.current=!1,Re(!1),"modal"===p?(fe(!0),he(!0)):ge(!0),o<0&&(re.value=se),Ie(t),Ve(s,o,t)},[Ve,se,ie,le,p,oe.length,Ie,Re,re,Me]),Oe=useCallback(()=>{if(0===oe.length)return;const e=le.value,t=Me(0);Ie(0),Ve(t,e,0)},[Ve,le,oe.length,Ie,Me]),Ae=useCallback(()=>new Promise(e=>{if(ye.current<0)return void(ve.current?ke.current.push(e):e(!0));ke.current.push(e);const t=le.value;Ie(-1),ce.current=!0,r?.(t,-1),re.value=withTiming(se,{duration:j.motion.duration.fast,easing:Easing.bezier(...j.motion.easing.accelerate)},e=>{"worklet";e&&runOnJS(je)()})}),[se,le,je,r,Ie,re,j.motion.duration.fast,j.motion.easing.accelerate]),He=useCallback(async()=>{await Ae()},[Ae]),Be=useCallback((e,t,o)=>{const s=we.current;if(!s)return void e();if(xe.current)return void t?.();const n=s();"boolean"!=typeof n?(xe.current=!0,o?.(),n.then(o=>{xe.current=!1,o&&Ce.current&&ye.current>=0?e():t?.()},e=>{throw xe.current=!1,e})):(n?e:t)?.()},[]),Ee=useCallback(()=>new Promise(e=>{ye.current<0?Ae().then(e):Be(()=>{Ae().then(e)},()=>e(!1))}),[Ae,Be]),Pe=useCallback(()=>{Be(()=>{He()})},[He,Be]);useImperativeHandle(t,()=>({expand:De,collapse:Oe,close:He,requestClose:Ee}),[De,Oe,He,Ee]),useEffect(()=>{"number"==typeof s&&s!==ie&&(-1===s?He():De(s))},[s]);const Ge=useRef({hostHeight:V,contentSnap:ee});useEffect(()=>{const e=Ge.current;e.hostHeight===V&&e.contentSnap===ee||(Ge.current={hostHeight:V,contentSnap:ee},e.hostHeight===V&&le.value<0||(re.value=withSpring(Me(le.value),SPRING_CONFIG)))},[V,ee]);const Le=V-ne,Ne=useMemo(()=>oe.map(e=>V-e),[oe,V]),Fe=useCallback(()=>{const e=ye.current;e<0||Ve(Me(e),e,e)},[Ve,Me]),Je=useCallback((e,t)=>{const o=le.value;-1!==e?(Ie(e),Ve(t,o,e)):Be(()=>{triggerHaptic("selection"),He()},Fe,Fe)},[Ve,He,le,Be,Ie,Fe]),ze=useMemo(()=>Gesture.Native().withTestId(_?`${_}-content-gesture`:"bottom-sheet-content-gesture"),[_]),Ye=useMemo(()=>{const e=Ne,t=se,o=Le,s=l;return Gesture.Pan().withTestId(_?`${_}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";ae.value=re.value}).onUpdate(e=>{"worklet";const t=ae.value+e.translationY;re.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=re.value;if(o.velocityY>1e3)return s?void runOnJS(Je)(-1,t):void runOnJS(Je)(0,e[0]);let r=0,a=Math.abs(n-e[0]);for(let t=1;t<e.length;t++){const o=Math.abs(n-e[t]);o<a&&(a=o,r=t)}const l=e[0];s&&n-l>80?runOnJS(Je)(-1,t):runOnJS(Je)(r,e[r])})},[se,ae,l,Je,Le,Ne,_,re]),{height:$e}=useReanimatedKeyboardAnimation(),qe="shift"===S,We=useDerivedValue(()=>qe?$e.value:0),Ke=oe[ie>=0?ie:0]??ne,Xe=j.spacing.md,Ue=useAnimatedStyle(()=>{if(E){const e=We.value,t=V+e-Ke-Xe,o=e<0&&re.value>t?t:re.value;return{top:o<N?N:o}}const e=re.value+We.value,t=We.value<0?N:Le;return{top:e<t?t:e}}),Qe=useAnimatedStyle(()=>{const e=We.value;if(E){const t=V+e-Ke-Xe,o=e<0&&re.value>t?t:re.value,s=V+e-Xe-(o<N?N:o);return{height:s<0?0:s>Ke?Ke:s}}const t=e<0?N:Le,o=re.value+e,s=V+e-(o<t?t:o);return{height:s<0?0:s>ne?ne:s}}),Ze=ie>=0,et=useMemo(()=>buildStyles(j),[j]),tt=useCallback(()=>{i&&Be(()=>{triggerHaptic("selection"),He()})},[i,He,Be]),ot=useMemo(()=>Gesture.Tap().withTestId(_?`${_}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(tt)()}),[tt,_]),st=useMemo(()=>({snapIndex:ie,snapPoints:oe,expand:De,collapse:Oe,close:He,requestClose:Ee}),[ie,oe,De,Oe,He,Ee]);if("inline"===p&&!pe)return null;if("modal"===p&&!me)return null;const nt=_jsxs(View,{collapsable:!1,style:["modal"===p?et.backdropModal:et.backdropInline,{backgroundColor:j.colors.background.overlay}],onLayout:H,testID:_,accessibilityViewIsModal:I??Ze,children:[_jsx(GestureDetector,{gesture:ot,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:"Close bottom sheet"})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:M,accessibilityViewIsModal:I??Ze,style:[et.sheet,{height:ne,backgroundColor:j.colors.background.elevated,borderTopLeftRadius:j.radius["2xl"],borderTopRightRadius:j.radius["2xl"],...smoothCorners,...j.shadows.xl},E?{height:Ke,left:(O-P)/2,right:void 0,width:P,borderBottomLeftRadius:j.radius["2xl"],borderBottomRightRadius:j.radius["2xl"]}:null,v,Ue],children:_jsxs(SheetBody,{style:[et.body,Qe],keyboardOffset:We,children:[E?_jsx(View,{style:{height:j.spacing.md}}):_jsx(GestureDetector,{gesture:Ye,children:_jsx(View,{style:et.handleRow,onLayout:J?Y:void 0,accessible:!0,accessibilityLabel:"Drag handle",accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:_?`${_}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[et.handle,{backgroundColor:j.components.bottomSheet?.handleColor??j.colors.border.primary},y]})})}),null!=w&&_jsx(View,{style:[et.header,C],onLayout:J?q:void 0,children:w}),c?_jsx(GestureDetector,{gesture:ze,children:_jsx(ScrollView,{ref:d,style:et.scrollContent,onScroll:h,onContentSizeChange:te,onLayout:f,scrollEventThrottle:b,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:R})}):_jsx(View,{style:et.content,children:J?_jsx(View,{onLayout:K,children:R}):R}),null!=x&&_jsx(View,{style:[et.footer,k],onLayout:J?Q:void 0,children:x})]})})]}),rt=_jsx(BottomSheetContext.Provider,{value:st,children:nt});return"modal"===p?_jsx(Modal,{transparent:!0,visible:de,onRequestClose:Pe,onDismiss:"ios"===Platform.OS?Te:void 0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",supportedOrientations:["portrait","landscape"],children:_jsxs(ModalSafeArea,{onInsets:L,children:["android"===Platform.OS?_jsx(GestureHandlerRootView,{style:et.modalRoot,children:rt}):rt,_jsx(ToastHost,{})]})}):rt}),SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}});return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:12,paddingBottom:24},header:{},footer:{},handle:{width:36,height:4,borderRadius:2,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
1
+ "use strict";import{createContext,forwardRef,useCallback,useContext,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Modal,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=forwardRef((e,t)=>{const{snapPoints:o,index:s,onChange:n,onAnimate:r,onAfterClose:a,enablePanDownToClose:l=!0,enableBackdropPress:i=!0,confirmDismiss:u,scrollable:c=!1,scrollRef:d,onScroll:h,onContentSizeChange:m,onScrollLayout:f,scrollEventThrottle:b,keyboardBehavior:p="shift",mode:S="modal",presentation:g="sheet",handleIndicatorStyle:v,containerStyle:y,header:w,footer:C,headerStyle:x,footerStyle:k,children:M,accessibilityLabel:R,accessibilityViewIsModal:_,testID:E}=e,I=useTheme(),T=usePresenceMotion(),j=useSafeAreaInsets(),[O,A]=useState(()=>Dimensions.get("window").height),[D,V]=useState(()=>Dimensions.get("window").width),P=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&A(e=>e===t?e:t),o>0&&V(e=>e===o?e:o)},[]),H=useWindowDimensions(),B="dialog"===g||"auto"===g&&Math.min(H.width,H.height)>=600,N=Math.min(560,D-2*I.spacing.xl),[G,L]=useModalInsets(),F="modal"===S?G.top:j.top,J="modal"===S?G.bottom:j.bottom,z=o.includes("content"),[U,Y]=useMeasuredHeight(),[$,q]=useMeasuredHeight(),[W,K,X]=useMeasuredHeight(),[Q,Z]=useMeasuredHeight(),ee=B?I.spacing.md:U,te=z?Math.min(ee+(null!=w?$:0)+W+(null!=C?Q:0)+J,O-F):0,oe=useCallback((e,t)=>{z&&X(t),m?.(e,t)},[z,m,X]),se=useMemo(()=>resolveSnapPoints(o,O,te),[o,O,te]),ne=O,re=se[se.length-1]??0,ae=useSharedValue(ne),le=useSharedValue(ne),ie=useSharedValue(1),ue=useSharedValue(-1),[ce,de]=useState(-1),he=useRef(!1),[me,fe]=useState(!1),[be,pe]=useState(!1),Se=useRef(!1),ge=useRef(a);ge.current=a;const[ve,ye]=useState(!1),we=useRef(-1),Ce=useRef(!1);Ce.current="modal"===S?be:ve;const xe=useRef(u);xe.current=u;const ke=useRef(!1),Me=useRef(!0),Re=useRef([]),Ee=useCallback(e=>{const t=Re.current;Re.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Me.current=!0,()=>{Me.current=!1,Ee(!1)}),[Ee]);const Ie=useCallback(e=>{if(e<0||e>=se.length)return ne;const t=se[e];return B?(O-t)/2:O-t},[se,O,ne,B]),Te=useCallback(e=>{we.current=e;ce!==e&&(de(e),ue.value=e,n?.(e))},[ce,ue,n]),je=useCallback(()=>{he.current=!1,ue.value<0&&(Se.current=!0,"modal"===S?(fe(!1),"ios"!==Platform.OS&&pe(!1)):ye(!1))},[S,ue]),Oe=useCallback(()=>{Se.current&&pe(!1)},[]);useEffect(()=>{("modal"===S?!be:!ve)&&Se.current&&(Se.current=!1,ge.current?.(),Ee(!0))},[S,be,ve,Ee]);const Ae=useCallback((e,t,o)=>{he.current=!0,r?.(t,o),ae.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(je)()})},[r,ae,je]),De=useCallback(e=>{const t="number"==typeof e?clamp(e,0,se.length-1):ce>=0?ce:0,o=ue.value,s=Ie(t);if(Se.current=!1,Ee(!1),"modal"===S?(pe(!0),fe(!0)):ye(!0),o<0&&T.reduced)return ae.value=s,ie.value=0,ie.value=withTiming(1,{duration:T.duration("fast"),easing:Easing.bezier(...I.motion.easing.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Te(t),void r?.(o,t);o<0&&(ae.value=ne,ie.value=1),Te(t),Ae(s,o,t)},[Ae,ne,ce,ue,S,r,T,ie,se.length,Te,Ee,I.motion.easing.decelerate,ae,Ie]),Ve=useCallback(()=>{if(0===se.length)return;const e=ue.value,t=Ie(0);Te(0),Ae(t,e,0)},[Ae,ue,se.length,Te,Ie]),Pe=useCallback(()=>new Promise(e=>{if(we.current<0)return void(Ce.current?Re.current.push(e):e(!0));Re.current.push(e);const t=ue.value;Te(-1),he.current=!0,r?.(t,-1);const o=T.reduced?ie:ae,s=T.reduced?0:ne;o.value=withTiming(s,{duration:T.duration("fast"),easing:Easing.bezier(...I.motion.easing.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(je)()})}),[ne,ue,je,r,T,ie,Te,ae,I.motion.easing.accelerate]),He=useCallback(async()=>{await Pe()},[Pe]),Be=useCallback((e,t,o)=>{const s=xe.current;if(!s)return void e();if(ke.current)return void t?.();const n=s();"boolean"!=typeof n?(ke.current=!0,o?.(),n.then(o=>{ke.current=!1,o&&Me.current&&we.current>=0?e():t?.()},e=>{throw ke.current=!1,e})):(n?e:t)?.()},[]),Ne=useCallback(()=>new Promise(e=>{we.current<0?Pe().then(e):Be(()=>{Pe().then(e)},()=>e(!1))}),[Pe,Be]),Ge=useCallback(()=>{i&&Ne()},[i,Ne]);useImperativeHandle(t,()=>({expand:De,collapse:Ve,close:He,requestClose:Ne}),[De,Ve,He,Ne]),useEffect(()=>{"number"==typeof s&&s!==ce&&(-1===s?He():De(s))},[s]);const Le=useRef({hostHeight:O,contentSnap:te});useEffect(()=>{const e=Le.current;e.hostHeight===O&&e.contentSnap===te||(Le.current={hostHeight:O,contentSnap:te},e.hostHeight===O&&ue.value<0||(ae.value=withSpring(Ie(ue.value),SPRING_CONFIG)))},[O,te]);const Fe=O-re,Je=useMemo(()=>se.map(e=>O-e),[se,O]),ze=useCallback(()=>{const e=we.current;e<0||Ae(Ie(e),e,e)},[Ae,Ie]),Ue=useCallback((e,t)=>{const o=ue.value;-1!==e?(Te(e),Ae(t,o,e)):Be(()=>{triggerHaptic("selection"),He()},ze,ze)},[Ae,He,ue,Be,Te,ze]),Ye=useMemo(()=>Gesture.Native().withTestId(E?`${E}-content-gesture`:"bottom-sheet-content-gesture"),[E]),$e=useMemo(()=>{const e=Je,t=ne,o=Fe,s=l;return Gesture.Pan().withTestId(E?`${E}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";le.value=ae.value}).onUpdate(e=>{"worklet";const t=le.value+e.translationY;ae.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=ae.value;if(o.velocityY>1e3)return s?void runOnJS(Ue)(-1,t):void runOnJS(Ue)(0,e[0]);let r=0,a=Math.abs(n-e[0]);for(let t=1;t<e.length;t++){const o=Math.abs(n-e[t]);o<a&&(a=o,r=t)}const l=e[0];s&&n-l>80?runOnJS(Ue)(-1,t):runOnJS(Ue)(r,e[r])})},[ne,le,l,Ue,Fe,Je,E,ae]),{height:qe}=useReanimatedKeyboardAnimation(),We="shift"===p,Ke=useDerivedValue(()=>We?qe.value:0),Xe=se[ce>=0?ce:0]??re,Qe=I.spacing.md,Ze=useAnimatedStyle(()=>{if(B){const e=Ke.value,t=O+e-Xe-Qe,o=e<0&&ae.value>t?t:ae.value;return{top:o<F?F:o,opacity:ie.value}}const e=ae.value+Ke.value,t=Ke.value<0?F:Fe;return{top:e<t?t:e,opacity:ie.value}}),et=useAnimatedStyle(()=>{const e=Ke.value;if(B){const t=O+e-Xe-Qe,o=e<0&&ae.value>t?t:ae.value,s=O+e-Qe-(o<F?F:o);return{height:s<0?0:s>Xe?Xe:s}}const t=e<0?F:Fe,o=ae.value+e,s=O+e-(o<t?t:o);return{height:s<0?0:s>re?re:s}}),tt=ce>=0,ot=useMemo(()=>buildStyles(I),[I]),st=useCallback(()=>{i&&Be(()=>{triggerHaptic("selection"),He()})},[i,He,Be]),nt=useMemo(()=>Gesture.Tap().withTestId(E?`${E}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(st)()}),[st,E]),rt=useMemo(()=>({snapIndex:ce,snapPoints:se,expand:De,collapse:Ve,close:He,requestClose:Ne}),[ce,se,De,Ve,He,Ne]);if("inline"===S&&!ve)return null;if("modal"===S&&!be)return null;const at=_jsxs(View,{collapsable:!1,style:["modal"===S?ot.backdropModal:ot.backdropInline,{backgroundColor:I.colors.background.overlay}],onLayout:P,testID:E,accessibilityViewIsModal:_??tt,children:[_jsx(GestureDetector,{gesture:nt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:"Close bottom sheet"})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:R,accessibilityViewIsModal:_??tt,accessibilityActions:[{name:"escape",label:"Close bottom sheet"}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Ge()},onAccessibilityEscape:Ge,style:[ot.sheet,{height:re,backgroundColor:I.colors.background.elevated,borderTopLeftRadius:I.radius["2xl"],borderTopRightRadius:I.radius["2xl"],...smoothCorners,...I.shadows.xl},B?{height:Xe,left:(D-N)/2,right:void 0,width:N,borderBottomLeftRadius:I.radius["2xl"],borderBottomRightRadius:I.radius["2xl"]}:null,y,Ze],children:_jsxs(SheetBody,{style:[ot.body,et],keyboardOffset:Ke,children:[B?_jsx(View,{style:{height:I.spacing.md}}):_jsx(GestureDetector,{gesture:$e,children:_jsx(View,{style:ot.handleRow,onLayout:z?Y:void 0,accessible:!0,accessibilityLabel:"Drag handle",accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:E?`${E}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[ot.handle,{backgroundColor:I.components.bottomSheet?.handleColor??I.colors.border.primary},v]})})}),null!=w&&_jsx(View,{style:[ot.header,x],onLayout:z?q:void 0,children:w}),c?_jsx(GestureDetector,{gesture:Ye,children:_jsx(ScrollView,{ref:d,style:ot.scrollContent,onScroll:h,onContentSizeChange:oe,onLayout:f,scrollEventThrottle:b,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:M})}):_jsx(View,{style:z?[ot.content,{overflow:"visible"}]:ot.content,children:z?_jsx(View,{onLayout:K,children:M}):M}),null!=C&&_jsx(View,{style:[ot.footer,k],onLayout:z?Z:void 0,children:C})]})})]}),lt=_jsx(BottomSheetContext.Provider,{value:rt,children:at});return"modal"===S?_jsx(Modal,{transparent:!0,visible:me,onRequestClose:Ge,onDismiss:"ios"===Platform.OS?Oe:void 0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",supportedOrientations:["portrait","landscape"],children:_jsxs(ModalSafeArea,{onInsets:L,children:["android"===Platform.OS?_jsx(GestureHandlerRootView,{style:ot.modalRoot,children:lt}):lt,_jsx(ToastHost,{})]})}):lt}),SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}});return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:12,paddingBottom:24},header:{},footer:{},handle:{width:36,height:4,borderRadius:2,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Button=forwardRef((e,r)=>{const{title:o,children:t,variant:s="solid",tone:i="primary",size:n="md",loading:a=!1,disabled:l=!1,fullWidth:d=!1,leftIcon:c,rightIcon:u,iconVariant:b,leftIconBadge:g=!1,haptic:p="selection",rounded:m=!1,gradient:f,style:h,textStyle:y,pressAnimation:S,onPress:x,accessibilityLabel:C,accessibilityHint:I,accessibilityState:_,testID:k,onLayout:T,...w}=e;if(__DEV__&&hasTextChild(t))throw new Error('[@webority/mobile-ui] Button was given its label as text children. Pass it as `title` (<Button title="Save" />): text children draw a blank button with no accessible name.');const z=useTheme(),j=!l&&!a,R={..._,disabled:!j,busy:a},F="link"===s,v=S??(!F&&"scale"),V=usePressAnimation({preset:v||"scale",enabled:!1!==v&&j}),E=useFlickGuard(),A=useMemo(()=>buildStyles(z),[z]),H={...sizeMap[n],...z.components.button?.[n]??{}},L=useMemo(()=>toneFor(z,i),[z,i]),W=useMemo(()=>variantFor(z,s,L,l),[z,s,L,l]),D=useMemo(()=>!f||l||"solid"!==s?null:"string"==typeof f?z.gradients[f]??null:f,[f,l,s,z.gradients]),P=StyleSheet.flatten(h)?.borderRadius,B=F?0:"number"==typeof P?P:m?z.radius.full:H.borderRadius,O=useSquircle(!D&&"link"!==s,B,T),N=useRef(createAnimatedValue(0)).current,[G,M]=useState(0),q=F?e=>M(e.nativeEvent.layout.width):void 0,U=C??o,K="outline"===s||"ghost"===s,X=!K&&!F,Y={color:W.textColor,size:H.iconSize,disabled:l},J=g&&!F&&Boolean(c),Q=H.minHeight-2*BADGE_INSET-2*W.borderWidth,Z={color:W.badgeInk,size:H.badgeIconSize??H.iconSize,disabled:l},$=_jsx(View,{style:A.contentRow,children:a?_jsx(Spinner,{variant:"circular",size:"sm",color:W.textColor,accessibilityLabel:"Loading"}):_jsxs(_Fragment,{children:[J?_jsx(View,{testID:"button-icon-badge",style:[A.iconLeft,A.iconBadge,{width:Q,height:Q,borderRadius:Q/2,backgroundColor:W.badgeFill}],children:renderSlotIcon(c,Z,b)}):c?_jsx(View,{style:A.iconLeft,children:renderSlotIcon(c,Y,b)}):null,o?_jsxs(View,{onLayout:q,children:[_jsx(Text,{style:[A.label,{color:W.textColor,fontSize:H.fontSize,...fontFor(z,"semibold")},y],numberOfLines:1,children:o}),F?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[A.linkUnderline,{backgroundColor:W.textColor,transform:[{translateX:N.interpolate({inputRange:[0,1],outputRange:[-G/2,0]})},{scaleX:N.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}):t,u?_jsx(View,{style:A.iconRight,children:renderSlotIcon(u,Y,b)}):null]})});return _jsx(Animated.View,{style:[V.style,d?A.fullWidth:null],children:_jsx(Pressable,{ref:r,onPress:e=>{j&&!E.isFlick(e)&&(V.press(),!1!==p&&triggerHaptic(p),x?.(e))},onPressIn:e=>{E.onPressIn(e),V.pressIn(),F&&j&&(N.stopAnimation(),N.setValue(0),Animated.timing(N,{toValue:1,duration:z.motion.duration.slower,easing:Easing.bezier(...z.motion.easing.decelerate),useNativeDriver:!0}).start())},onPressOut:()=>{V.pressOut()},disabled:!j,hitSlop:F?LINK_HIT_SLOP:void 0,accessibilityRole:"button",accessibilityLabel:U,accessibilityHint:I,accessibilityState:R,...ariaFromState(R),testID:k,onLayout:O.onLayout,style:({pressed:e})=>[A.base,{paddingHorizontal:F?0:H.paddingHorizontal,paddingVertical:F?0:J?BADGE_INSET:H.paddingVertical,paddingLeft:J?BADGE_INSET:void 0,minHeight:F?void 0:H.minHeight,borderRadius:B,...smoothCorners,backgroundColor:D||O.active?"transparent":W.backgroundColor,borderWidth:W.borderWidth,borderColor:O.active?"transparent":W.borderColor,opacity:a?.55:1,overflow:O.active||F?"visible":"hidden"},e&&K&&!O.active?{backgroundColor:z.colors.surface.pressed}:null,d?A.fullWidth:null,h],...w,"aria-disabled":!j,"aria-busy":a,children:({pressed:e})=>_jsxs(_Fragment,{children:[O.active&&O.size?_jsx(SquircleFill,{width:O.size.width,height:O.size.height,radius:B,fill:e&&K?z.colors.surface.pressed:W.backgroundColor,stroke:W.borderColor,strokeWidth:W.borderWidth,outset:W.borderWidth}):null,D?_jsx(Gradient,{gradient:D,style:[StyleSheet.absoluteFill,{borderRadius:B,...smoothCorners}]}):null,e&&X?O.active&&O.size?_jsx(SquircleFill,{width:O.size.width,height:O.size.height,radius:B,fill:W.pressedTint,outset:W.borderWidth,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[A.pressedOverlay,{borderRadius:B,backgroundColor:W.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,$]})})})});Button.displayName="Button";const hasTextChild=e=>React.Children.toArray(e).some(e=>"string"==typeof e||"number"==typeof e),sizeMap={xs:{paddingHorizontal:10,paddingVertical:4,minHeight:28,fontSize:12,borderRadius:8,iconSize:14,badgeIconSize:11},sm:{paddingHorizontal:12,paddingVertical:6,minHeight:34,fontSize:14,borderRadius:10,iconSize:16},md:{paddingHorizontal:16,paddingVertical:9,minHeight:42,fontSize:16,borderRadius:12,iconSize:18},lg:{paddingHorizontal:20,paddingVertical:12,minHeight:50,fontSize:18,borderRadius:14,iconSize:20},xl:{paddingHorizontal:24,paddingVertical:14,minHeight:58,fontSize:20,borderRadius:16,iconSize:22}},SOFT_FILL_OPACITY=.14,toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors.primary,on:e.colors.onPrimary,fg:e.colors.toneText.primary,soft:tintOf(e.colors.primary,.14,e.colors.primaryMuted)};case"secondary":return{base:e.colors.secondary,on:e.colors.onSecondary,fg:e.colors.onSecondary,soft:e.colors.secondary};case"success":return{base:e.colors.success,on:e.colors.onSuccess,fg:e.colors.toneText.success,soft:tintOf(e.colors.success,.14,e.colors.background.secondary)};case"warning":return{base:e.colors.warning,on:e.colors.onWarning,fg:e.colors.toneText.warning,soft:tintOf(e.colors.warning,.14,e.colors.background.secondary)};case"error":return{base:e.colors.error,on:e.colors.onError,fg:e.colors.toneText.error,soft:tintOf(e.colors.error,.14,e.colors.background.secondary)};default:return{base:e.colors.background.tertiary,on:e.colors.text.primary,fg:e.colors.text.primary,soft:e.colors.background.secondary}}},BADGE_INSET=4,BUTTON_BORDER_WIDTH=1,LINK_HIT_SLOP={top:8,bottom:8,left:8,right:8},variantFor=(e,r,o,t)=>{const s=t?e.colors.text.disabled:o.fg,i={badgeFill:e.colors.surface.disabled,badgeInk:e.colors.text.disabled},n=t?i:{badgeFill:o.on,badgeInk:o.base},a=t?i:{badgeFill:o.base,badgeInk:o.on};switch(r){case"solid":return{backgroundColor:t?e.colors.surface.disabled:o.base,borderColor:"transparent",borderWidth:1,textColor:t?e.colors.text.disabled:o.on,pressedTint:e.colors.surface.pressed,...n};case"soft":return{backgroundColor:t?e.colors.surface.disabled:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"outline":return{backgroundColor:"transparent",borderColor:t?e.colors.border.primary:o.base,borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:t?e.colors.text.disabled:e.colors.text.link,pressedTint:e.colors.surface.pressed,...a};case"glass":return{backgroundColor:e.colors.glass.fill,borderColor:e.colors.glass.border,borderWidth:1,textColor:t?e.colors.text.disabled:e.colors.glass.on,pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors.glass.badge,badgeInk:t?e.colors.text.disabled:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors.surface.pressed,...n}}},buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:1},iconLeft:{marginRight:8},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:8},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
1
+ "use strict";import React,{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Button=forwardRef((e,r)=>{const{title:o,children:t,variant:s="solid",tone:i="primary",size:n="md",loading:a=!1,disabled:l=!1,fullWidth:d=!1,leftIcon:c,rightIcon:u,iconVariant:b,leftIconBadge:g=!1,haptic:p,rounded:m=!1,gradient:h,style:f,containerStyle:S,textStyle:y,pressAnimation:x,onPress:C,accessibilityLabel:I,accessibilityHint:_,accessibilityState:T,testID:k,onLayout:w,...z}=e;if(__DEV__&&hasTextChild(t))throw new Error('[@webority/mobile-ui] Button was given its label as text children. Pass it as `title` (<Button title="Save" />): text children draw a blank button with no accessible name.');const j=useTheme(),F=!l&&!a,R={...T,disabled:!F,busy:a},v="link"===s,H=x??(!v&&"scale"),L=usePressAnimation({preset:H||"scale",enabled:!1!==H&&F}),E=useFlickGuard(),V=useMemo(()=>buildStyles(j),[j]),A={...sizeMap[n],...j.components.button?.[n]??{}},P=useMemo(()=>toneFor(j,i),[j,i]),O=useMemo(()=>variantFor(j,s,P,l),[j,s,P,l]),W=useMemo(()=>!h||l||"solid"!==s?null:"string"==typeof h?j.gradients[h]??null:h,[h,l,s,j.gradients]),D=StyleSheet.flatten(f)?.borderRadius,B=v?0:"number"==typeof D?D:m?j.radius.full:A.borderRadius,N=useSquircle(!W&&"link"!==s,B,w),M=useRef(createAnimatedValue(0)).current,[G,q]=useState(0),[K,U]=useState(null),X=v?e=>q(e.nativeEvent.layout.width):void 0,Y=I??o,J="outline"===s||"ghost"===s,Q=!J&&!v,Z={color:O.textColor,size:A.iconSize,disabled:l},$=g&&!v&&Boolean(c),ee=A.minHeight-2*BADGE_INSET-2*O.borderWidth,re={color:O.badgeInk,size:A.badgeIconSize??A.iconSize,disabled:l},oe=a?_jsx(Spinner,{variant:"circular",size:"sm",color:$?O.badgeInk:O.textColor,accessibilityLabel:"Loading"}):c?renderSlotIcon(c,$?re:Z,b):null,te=_jsxs(View,{style:V.contentRow,children:[$?_jsx(View,{testID:"button-icon-badge",style:[V.iconLeft,V.iconBadge,{width:ee,height:ee,borderRadius:ee/2,backgroundColor:O.badgeFill}],children:oe}):oe?_jsx(View,{style:V.iconLeft,children:oe}):null,o?_jsxs(View,{onLayout:X,children:[_jsx(Text,{style:[V.label,{color:O.textColor,fontSize:A.fontSize,...fontFor(j,"semibold")},y],numberOfLines:1,children:o}),v?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[V.linkUnderline,{backgroundColor:O.textColor,transform:[{translateX:M.interpolate({inputRange:[0,1],outputRange:[-G/2,0]})},{scaleX:M.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}):t,u?_jsx(View,{style:V.iconRight,children:renderSlotIcon(u,Z,b)}):null]}),se=v?null===K?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(K)):touchSlopFor(A.minHeight),ie={top:se,bottom:se,left:v?LINK_HIT_SLOP:0,right:v?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[L.style,d?V.fullWidth:null,S],children:_jsx(Pressable,{ref:r,onPress:e=>{F&&!E.isFlick(e)&&(L.press(),p&&triggerHaptic(p),C?.(e))},onPressIn:e=>{E.onPressIn(e),L.pressIn(),v&&F&&(M.stopAnimation(),M.setValue(0),Animated.timing(M,{toValue:1,duration:j.motion.duration.slower,easing:Easing.bezier(...j.motion.easing.decelerate),useNativeDriver:!0}).start())},onPressOut:()=>{L.pressOut()},disabled:!F,hitSlop:ie,accessibilityRole:"button",accessibilityLabel:Y,accessibilityHint:_,accessibilityState:R,...ariaFromState(R),testID:k,onLayout:e=>{N.onLayout(e),v&&U(e.nativeEvent.layout.height)},style:({pressed:e})=>[V.base,{paddingHorizontal:v?0:A.paddingHorizontal,paddingVertical:v?0:$?BADGE_INSET:A.paddingVertical,paddingLeft:$?BADGE_INSET:void 0,minHeight:v?void 0:A.minHeight,borderRadius:B,...smoothCorners,backgroundColor:W||N.active?"transparent":O.backgroundColor,borderWidth:O.borderWidth,borderColor:N.active?"transparent":O.borderColor,opacity:a?.55:1,overflow:N.active||v?"visible":"hidden"},e&&J&&!N.active?{backgroundColor:j.colors.surface.pressed}:null,d?V.fullWidth:null,f],...z,"aria-disabled":!F,"aria-busy":a,children:({pressed:e})=>_jsxs(_Fragment,{children:[N.active&&N.size?_jsx(SquircleFill,{width:N.size.width,height:N.size.height,radius:B,fill:e&&J?j.colors.surface.pressed:O.backgroundColor,stroke:O.borderColor,strokeWidth:O.borderWidth,outset:O.borderWidth}):null,W?_jsx(Gradient,{gradient:W,style:[StyleSheet.absoluteFill,{borderRadius:B,...smoothCorners}]}):null,e&&Q?N.active&&N.size?_jsx(SquircleFill,{width:N.size.width,height:N.size.height,radius:B,fill:O.pressedTint,outset:O.borderWidth,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[V.pressedOverlay,{borderRadius:B,backgroundColor:O.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,te]})})})});Button.displayName="Button";const hasTextChild=e=>React.Children.toArray(e).some(e=>"string"==typeof e||"number"==typeof e),sizeMap={xs:{paddingHorizontal:10,paddingVertical:4,minHeight:28,fontSize:12,borderRadius:8,iconSize:14,badgeIconSize:11},sm:{paddingHorizontal:12,paddingVertical:6,minHeight:34,fontSize:14,borderRadius:10,iconSize:16},md:{paddingHorizontal:16,paddingVertical:9,minHeight:42,fontSize:16,borderRadius:12,iconSize:18},lg:{paddingHorizontal:20,paddingVertical:12,minHeight:50,fontSize:18,borderRadius:14,iconSize:20},xl:{paddingHorizontal:24,paddingVertical:14,minHeight:58,fontSize:20,borderRadius:16,iconSize:22}},SOFT_FILL_OPACITY=.14,toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors.primary,on:e.colors.onPrimary,fg:e.colors.toneText.primary,soft:tintOf(e.colors.primary,.14,e.colors.primaryMuted)};case"secondary":return{base:e.colors.secondary,on:e.colors.onSecondary,fg:e.colors.onSecondary,soft:e.colors.secondary};case"success":return{base:e.colors.success,on:e.colors.onSuccess,fg:e.colors.toneText.success,soft:tintOf(e.colors.success,.14,e.colors.background.secondary)};case"warning":return{base:e.colors.warning,on:e.colors.onWarning,fg:e.colors.toneText.warning,soft:tintOf(e.colors.warning,.14,e.colors.background.secondary)};case"error":return{base:e.colors.error,on:e.colors.onError,fg:e.colors.toneText.error,soft:tintOf(e.colors.error,.14,e.colors.background.secondary)};default:return{base:e.colors.background.tertiary,on:e.colors.text.primary,fg:e.colors.text.primary,soft:e.colors.background.secondary}}},BADGE_INSET=4,BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,r,o,t)=>{const s=t?e.colors.text.disabled:o.fg,i={badgeFill:e.colors.surface.disabled,badgeInk:e.colors.text.disabled},n=t?i:{badgeFill:o.on,badgeInk:o.base},a=t?i:{badgeFill:o.base,badgeInk:o.on};switch(r){case"solid":return{backgroundColor:t?e.colors.surface.disabled:o.base,borderColor:"transparent",borderWidth:1,textColor:t?e.colors.text.disabled:o.on,pressedTint:e.colors.surface.pressed,...n};case"soft":return{backgroundColor:t?e.colors.surface.disabled:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"outline":return{backgroundColor:"transparent",borderColor:t?e.colors.border.primary:o.base,borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors.surface.pressed,...a};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:t?e.colors.text.disabled:e.colors.text.link,pressedTint:e.colors.surface.pressed,...a};case"glass":return{backgroundColor:e.colors.glass.fill,borderColor:e.colors.glass.border,borderWidth:1,textColor:t?e.colors.text.disabled:e.colors.glass.on,pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors.glass.badge,badgeInk:t?e.colors.text.disabled:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors.surface.pressed,...n}}},buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:1},iconLeft:{marginRight:8},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:8},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useLayoutEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Animated,Easing,Pressable,Text,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{CalendarDay}from"./CalendarDay.js";import{addMonths,buildMonthMatrix,GRID_CELLS,startOfDay,startOfMonth,toIso,weekdayLabels}from"./calendarDates.js";import{buildCalendarStyles,MIN_CELL_SIZE,NAV_BUTTON_SIZE}from"./calendarStyles.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_TONE={holiday:"error",event:"primary",pending:"warning"},MAX_DOTS=3,DAY_TEXT_MAX_SCALE=1.5,toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;case"info":return e.colors.info;case"primary":return e.colors.primary;default:return e.colors.text.secondary}},toneInk=(e,t)=>"neutral"===t?e.colors.text.secondary:e.colors.toneText[t],Calendar=forwardRef((e,t)=>{const{mode:a="single",value:s,onChange:n,month:i,onMonthChange:r,minDate:o,maxDate:l,disabledDates:d,weekStartsOn:u=0,locale:c="en-IN",markedDates:m,strikeMarkedInRange:h=!1,cellSize:y,haptic:p,accessibilityLabel:g,style:f,headerLabelStyle:b,navButtonStyle:x,testID:M}=e,D=useTheme(),T=useMemo(()=>buildCalendarStyles(D),[D]),[w,S]=useControllableState({value:i?startOfMonth(i):void 0,defaultValue:startOfMonth(s?.start??new Date),onChange:r}),_=12*w.getFullYear()+w.getMonth(),k=s?.start?startOfDay(s.start):null,v="range"===a&&s?.end?startOfDay(s.end):null,C=k?.getTime()??null,I=v?.getTime()??null,L=toIso(new Date),E=o?startOfDay(o).getTime():null,j=l?startOfDay(l).getTime():null,A=useMemo(()=>new Set((d??[]).map(e=>toIso(e))),[d]),R=useCallback(e=>null!==E&&e.getTime()<E||null!==j&&e.getTime()>j||A.has(toIso(e)),[E,j,A]),V=useMemo(()=>{const e=new Map;for(const t of m??[]){const a=toIso(t.date);let s=e.get(a);s||(s={dots:[],holiday:!1,spoken:[]},e.set(a,s));const n=t.tone??DEFAULT_TONE[t.kind],i=toneColor(D,n);s.dots.length<3&&s.dots.push({key:`${t.kind}-${s.dots.length}`,color:i}),"holiday"===t.kind&&(s.holiday=!0,s.holidayInk??=toneInk(D,n)),t.label&&s.spoken.push(t.label),s.spoken.push(t.kind)}return e},[m,D]),N=useMemo(()=>buildMonthMatrix(new Date(Math.floor(_/12),_%12,1),u),[_,u]),O=useMemo(()=>weekdayLabels(c,u),[c,u]),F=useMemo(()=>new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}),[c]),P=useMemo(()=>new Intl.DateTimeFormat(c,{weekday:"short",day:"numeric",month:"long"}),[c]),B=F.format(w),z=null===E||startOfMonth(new Date(E)).getTime()<w.getTime(),H=null===j||startOfMonth(new Date(j)).getTime()>w.getTime(),Z=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(1)).current,U=useRef(null);useEffect(()=>()=>U.current?.stop(),[]);const $=useCallback(e=>{!1!==p&&triggerHaptic("impactLight");const t=D.components.dateRangePicker,a=t?.monthSlideDistance??32,s=t?.monthSlideOutDuration??D.motion.duration.fast,n=t?.monthSlideInDuration??D.motion.duration.fast;U.current?.stop(),U.current=Animated.sequence([Animated.parallel([Animated.timing(Z,{toValue:-e*a,duration:s,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(X,{toValue:0,duration:s,useNativeDriver:!0})]),Animated.timing(Z,{toValue:e*a,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(Z,{toValue:0,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(X,{toValue:1,duration:n,useNativeDriver:!0})])]),U.current.start();const i=addMonths(w,e);S(i),AccessibilityInfo.announceForAccessibility(F.format(i))},[p,w,X,F,Z,S,D]),q=useCallback(()=>$(-1),[$]),G=useCallback(()=>$(1),[$]),pressDay=e=>{if(R(e.date))return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t);const s=e.date;"single"===a||!k||v||s.getTime()<k.getTime()?n({start:s}):n({start:k,end:s}),e.inMonth||S(startOfMonth(s))},Y=useRef(pressDay);useLayoutEffect(()=>{Y.current=pressDay});const W=useCallback(e=>Y.current(e),[]),J=void 0===y?void 0:Math.max(y,MIN_CELL_SIZE),K=useMemo(()=>void 0===J?{flex:1}:{width:J},[J]),Q=useMemo(()=>void 0===J?{flex:1,aspectRatio:1,minHeight:MIN_CELL_SIZE}:{width:J,height:J},[J]),ee=D.components.dateRangePicker?.navButtonSize??NAV_BUTTON_SIZE,te=Math.max(D.spacing.sm,(MIN_CELL_SIZE-ee)/2),ae=Math.min(D.maxFontSizeMultiplier??1.5,1.5),se=[];for(let e=0;e<GRID_CELLS;e+=7)se.push(N.slice(e,e+7));return _jsxs(View,{ref:t,style:[T.root,f],testID:M,children:[_jsxs(View,{style:T.headerRow,children:[_jsx(Pressable,{onPress:q,disabled:!z,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!z&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:"Previous month",accessibilityState:{disabled:!z},"aria-disabled":!z,hitSlop:te,children:_jsx(Text,{style:T.navText,maxFontSizeMultiplier:ae,children:"‹"})}),_jsx(Animated.View,{style:[T.headerLabelWrap,{opacity:X,transform:[{translateX:Z}]},b],children:_jsx(Text,{style:T.headerLabel,accessibilityRole:"header",accessibilityLabel:g?`${g}, ${B}`:void 0,maxFontSizeMultiplier:D.maxFontSizeMultiplier,children:B})}),_jsx(Pressable,{onPress:G,disabled:!H,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!H&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:"Next month",accessibilityState:{disabled:!H},"aria-disabled":!H,hitSlop:te,children:_jsx(Text,{style:T.navText,maxFontSizeMultiplier:ae,children:"›"})})]}),_jsx(View,{style:T.weekdayRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:O.map(({weekday:e,label:t})=>_jsx(View,{style:[T.weekdayCell,K],children:_jsx(Text,{style:T.weekdayText,maxFontSizeMultiplier:ae,children:t})},e))}),_jsx(Animated.View,{style:{opacity:X,transform:[{translateX:Z}]},children:se.map(e=>_jsx(View,{style:T.gridRow,children:e.map(e=>{const t=e.date.getTime(),s=null!==C&&t===C,n=null!==I&&t===I,i=null!==C&&null!==I&&t>=C&&t<=I,r=i&&!s&&!n,o=e.iso===L,l=V.get(e.iso),d=h&&i&&!0===l?.holiday,u=[P.format(e.date),...l?.spoken??[]];return o&&u.push("today"),"range"===a&&(s&&n?u.push("start and end of your range"):s?u.push("start of your range"):n?u.push("end of your range"):r&&u.push("in your range")),d&&u.push("not counted"),_jsx(CalendarDay,{cell:e,accessibilityLabel:u.join(", "),disabled:R(e.date),edge:s||n,mid:r,barLeft:i&&(n||r)&&!(s&&n),barRight:i&&(s||r)&&!(s&&n),today:o,struck:d,dots:l?.dots,inkColor:l?.holidayInk,cellStyle:Q,styles:T,maxFontSizeMultiplier:ae,onPressDay:W},e.iso)})},e[0].iso))})]})});Calendar.displayName="Calendar";export{Calendar};export default Calendar;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useLayoutEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Animated,Easing,Pressable,Text,View}from"react-native";import{useControllableState,usePresenceMotion}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{CalendarDay}from"./CalendarDay.js";import{addMonths,buildMonthMatrix,GRID_CELLS,startOfDay,startOfMonth,toIso,weekdayLabels}from"./calendarDates.js";import{buildCalendarStyles,MIN_CELL_SIZE,NAV_BUTTON_SIZE}from"./calendarStyles.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_TONE={holiday:"error",event:"primary",pending:"warning"},MAX_DOTS=3,DAY_TEXT_MAX_SCALE=1.5,toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;case"info":return e.colors.info;case"primary":return e.colors.primary;default:return e.colors.text.secondary}},toneInk=(e,t)=>"neutral"===t?e.colors.text.secondary:e.colors.toneText[t],Calendar=forwardRef((e,t)=>{const{mode:a="single",value:s,onChange:n,month:i,onMonthChange:r,minDate:o,maxDate:l,disabledDates:d,weekStartsOn:u=0,locale:c="en-IN",markedDates:m,strikeMarkedInRange:h=!1,cellSize:y,haptic:g,accessibilityLabel:f,style:p,headerLabelStyle:b,navButtonStyle:x,testID:M}=e,D=useTheme(),T=usePresenceMotion(),w=useMemo(()=>buildCalendarStyles(D),[D]),[S,_]=useControllableState({value:i?startOfMonth(i):void 0,defaultValue:startOfMonth(s?.start??new Date),onChange:r}),k=12*S.getFullYear()+S.getMonth(),v=s?.start?startOfDay(s.start):null,C="range"===a&&s?.end?startOfDay(s.end):null,I=v?.getTime()??null,L=C?.getTime()??null,E=toIso(new Date),j=o?startOfDay(o).getTime():null,A=l?startOfDay(l).getTime():null,R=useMemo(()=>new Set((d??[]).map(e=>toIso(e))),[d]),V=useCallback(e=>null!==j&&e.getTime()<j||null!==A&&e.getTime()>A||R.has(toIso(e)),[j,A,R]),N=useMemo(()=>{const e=new Map;for(const t of m??[]){const a=toIso(t.date);let s=e.get(a);s||(s={dots:[],holiday:!1,spoken:[]},e.set(a,s));const n=t.tone??DEFAULT_TONE[t.kind],i=toneColor(D,n);s.dots.length<3&&s.dots.push({key:`${t.kind}-${s.dots.length}`,color:i}),"holiday"===t.kind&&(s.holiday=!0,s.holidayInk??=toneInk(D,n)),t.label&&s.spoken.push(t.label),s.spoken.push(t.kind)}return e},[m,D]),O=useMemo(()=>buildMonthMatrix(new Date(Math.floor(k/12),k%12,1),u),[k,u]),F=useMemo(()=>weekdayLabels(c,u),[c,u]),P=useMemo(()=>new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}),[c]),B=useMemo(()=>new Intl.DateTimeFormat(c,{weekday:"short",day:"numeric",month:"long"}),[c]),z=P.format(S),H=null===j||startOfMonth(new Date(j)).getTime()<S.getTime(),Z=null===A||startOfMonth(new Date(A)).getTime()>S.getTime(),X=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current,$=useRef(null);useEffect(()=>()=>$.current?.stop(),[]);const q=useCallback(e=>{!1!==g&&triggerHaptic("impactLight");const t=D.components.dateRangePicker,a=t?.monthSlideDistance??32,s=t?.monthSlideOutDuration??D.motion.duration.fast,n=t?.monthSlideInDuration??D.motion.duration.fast,[i]=T.range(-e*a,0),[r]=T.range(e*a,0),o=T.reduced?T.duration("fast"):s,l=T.reduced?T.duration("fast"):n;$.current?.stop(),$.current=Animated.sequence([Animated.parallel([Animated.timing(X,{toValue:i,duration:s,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(U,{toValue:0,duration:o,useNativeDriver:!0})]),Animated.timing(X,{toValue:r,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(X,{toValue:0,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(U,{toValue:1,duration:l,useNativeDriver:!0})])]),$.current.start();const d=addMonths(S,e);_(d),AccessibilityInfo.announceForAccessibility(P.format(d))},[g,S,U,P,X,T,_,D]),G=useCallback(()=>q(-1),[q]),Y=useCallback(()=>q(1),[q]),pressDay=e=>{if(V(e.date))return;const t=resolveHaptic(g,"selection");t&&triggerHaptic(t);const s=e.date;"single"===a||!v||C||s.getTime()<v.getTime()?n({start:s}):n({start:v,end:s}),e.inMonth||_(startOfMonth(s))},W=useRef(pressDay);useLayoutEffect(()=>{W.current=pressDay});const J=useCallback(e=>W.current(e),[]),K=void 0===y?void 0:Math.max(y,MIN_CELL_SIZE),Q=useMemo(()=>void 0===K?{flex:1}:{width:K},[K]),ee=useMemo(()=>void 0===K?{flex:1,aspectRatio:1,minHeight:MIN_CELL_SIZE}:{width:K,height:K},[K]),te=D.components.dateRangePicker?.navButtonSize??NAV_BUTTON_SIZE,ae=Math.max(D.spacing.sm,(MIN_CELL_SIZE-te)/2),se=Math.min(D.maxFontSizeMultiplier??1.5,1.5),ne=[];for(let e=0;e<GRID_CELLS;e+=7)ne.push(O.slice(e,e+7));return _jsxs(View,{ref:t,style:[w.root,p],testID:M,children:[_jsxs(View,{style:w.headerRow,children:[_jsx(Pressable,{onPress:G,disabled:!H,style:({pressed:e})=>[w.navBtn,e&&w.navBtnPressed,!H&&w.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:"Previous month",accessibilityState:{disabled:!H},"aria-disabled":!H,hitSlop:ae,children:_jsx(Text,{style:w.navText,maxFontSizeMultiplier:se,children:"‹"})}),_jsx(Animated.View,{style:[w.headerLabelWrap,{opacity:U,transform:[{translateX:X}]},b],children:_jsx(Text,{style:w.headerLabel,accessibilityRole:"header",accessibilityLabel:f?`${f}, ${z}`:void 0,maxFontSizeMultiplier:D.maxFontSizeMultiplier,children:z})}),_jsx(Pressable,{onPress:Y,disabled:!Z,style:({pressed:e})=>[w.navBtn,e&&w.navBtnPressed,!Z&&w.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:"Next month",accessibilityState:{disabled:!Z},"aria-disabled":!Z,hitSlop:ae,children:_jsx(Text,{style:w.navText,maxFontSizeMultiplier:se,children:"›"})})]}),_jsx(View,{style:w.weekdayRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:F.map(({weekday:e,label:t})=>_jsx(View,{style:[w.weekdayCell,Q],children:_jsx(Text,{style:w.weekdayText,maxFontSizeMultiplier:se,children:t})},e))}),_jsx(Animated.View,{style:{opacity:U,transform:[{translateX:X}]},children:ne.map(e=>_jsx(View,{style:w.gridRow,children:e.map(e=>{const t=e.date.getTime(),s=null!==I&&t===I,n=null!==L&&t===L,i=null!==I&&null!==L&&t>=I&&t<=L,r=i&&!s&&!n,o=e.iso===E,l=N.get(e.iso),d=h&&i&&!0===l?.holiday,u=[B.format(e.date),...l?.spoken??[]];return o&&u.push("today"),"range"===a&&(s&&n?u.push("start and end of your range"):s?u.push("start of your range"):n?u.push("end of your range"):r&&u.push("in your range")),d&&u.push("not counted"),_jsx(CalendarDay,{cell:e,accessibilityLabel:u.join(", "),disabled:V(e.date),edge:s||n,mid:r,barLeft:i&&(n||r)&&!(s&&n),barRight:i&&(s||r)&&!(s&&n),today:o,struck:d,dots:l?.dots,inkColor:l?.holidayInk,cellStyle:ee,styles:w,maxFontSizeMultiplier:se,onPressDay:J},e.iso)})},e[0].iso))})]})});Calendar.displayName="Calendar";export{Calendar};export default Calendar;
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=forwardRef((e,t)=>{const{children:o,variant:i="elevated",elevation:r="sm",radius:s="lg",padding:l="md",interactive:a=!1,bg:n,header:d,title:c,lead:u,action:h,headerActions:m,collapsible:p=!1,collapsed:g,defaultCollapsed:b=!1,onCollapsedChange:y,collapsedSummary:x,onRemove:f,removeLabel:S="Remove",separatorHeight:v=StyleSheet.hairlineWidth,footer:j,imageSource:w,imageHeight:C=160,imageAspectRatio:_,imageOverlay:R,loading:k=!1,gradient:A,onPress:T,haptic:B,contextMenu:H,accessibilityLabel:I,accessibilityHint:L,accessibilityRole:P,style:V,containerStyle:F,headerStyle:M,bodyStyle:z,footerStyle:q,borderRadius:W,testID:D,onLayout:O,...E}=e,N=useTheme(),G=a||"function"==typeof T,$=useContextMenu(H,{haptic:B,testID:D,accessibilityActions:E.accessibilityActions,onAccessibilityAction:E.onAccessibilityAction}),U=useMemo(()=>mergeRefs(t,$.hostRef),[t,$.hostRef]),J=G||$.enabled,{scale:K,pressIn:Q,pressOut:X}=usePressAnimation({enabled:J}),Y=useMemo(()=>buildStyles(N),[N]),Z=Boolean(w),ee=N.spacing[paddingMap[l]],te=useMemo(()=>A?"string"==typeof A?N.gradients[A]??null:A:null,[A,N.gradients]),oe="flat"===i,ie=oe?0:W??N.radius[s],re=resolveBackground(N,n),[se,le]=useControllableState({value:g,defaultValue:b,onChange:y}),ae=p&&se,ne=hasBuiltInHeaderContent(e),de=Boolean(d)||ne,ce=useSquircle(!Z&&!te&&!oe,ie,O),ue=StyleSheet.flatten([V,F])??{},he=ue.backgroundColor,me=ue.borderColor,pe=he??re??("filled"===i?N.colors.background.secondary:N.colors.background.elevated),ge="outlined"===i?N.colors.border.width:0,be=me??N.colors.border.primary,ye="elevated"===i&&supportsBoxShadow()?toBoxShadow(N.shadows[r]):void 0,xe=ce.active&&"elevated"===i&&!ye,fe=ce.active&&!xe?{backgroundColor:"transparent",borderColor:"transparent"}:null,Se=useMemo(()=>{const e={borderRadius:xe&&ce.size?squircleHostRadius(ce.size.width,ce.size.height,ie):ie,...smoothCorners,padding:Z?0:ee,overflow:ce.active?"visible":"hidden"};switch(i){case"flat":return{...e,backgroundColor:re??N.colors.background.elevated,borderBottomWidth:v,borderBottomColor:N.colors.border.primary};case"outlined":return{...e,backgroundColor:ce.active?"transparent":re??N.colors.background.elevated,borderWidth:N.colors.border.width,borderColor:ce.active?"transparent":N.colors.border.primary};case"filled":return{...e,backgroundColor:ce.active?"transparent":re??N.colors.background.secondary};default:return{...e,backgroundColor:re??N.colors.background.elevated,...ye?{boxShadow:ye}:N.shadows[r]}}},[N,i,r,ie,Z,ee,ce.active,ce.size,ye,xe,re,v]),ve=useMemo(()=>({..."number"==typeof _?{width:"100%",aspectRatio:_}:{width:"100%",height:C},borderTopLeftRadius:ie,borderTopRightRadius:ie,borderBottomLeftRadius:0,borderBottomRightRadius:0,...smoothCorners}),[ie,_,C]),je="string"==typeof c?c:"",we=_jsxs(_Fragment,{children:[_jsxs(View,{style:Y.titleColumn,children:["string"==typeof c?_jsx(Text,{variant:"title",accessibilityRole:"header",children:c}):c,u?_jsx(Text,{variant:"bodySmall",style:Y.lead,children:u}):null,ae&&x?_jsx(Text,{variant:"caption",style:Y.lead,children:x}):null]}),isCardTextAction(h)?_jsx(CardTextActionButton,{action:h,haptic:B}):h?_jsx(View,{style:Y.actionNode,children:h}):null,m,p?_jsx(CardIconAction,{icon:ae?"chevron-down":"chevron-up",label:`${ae?"Show":"Hide"} ${je}`.trim(),expanded:!ae,onPress:()=>le(!ae),haptic:B}):null,f?_jsx(CardIconAction,{icon:"trash",label:S,onPress:f,color:N.colors.toneText.error,haptic:B}):null]}),Ce=_jsxs(_Fragment,{children:[de?_jsx(View,{style:[Y.header,!d&&Y.headerRow,ae&&Y.headerFolded,M],children:d??we}):null,ae?null:_jsx(View,{style:[de||j?Y.body:null,z],children:o}),j&&!ae?_jsx(View,{style:[Y.footer,q],children:j}):null]}),Re=Z?_jsxs(_Fragment,{children:[_jsxs(View,{style:Y.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:ve,accessibilityLabel:"",accessible:!1}),R?_jsx(View,{pointerEvents:"box-none",style:Y.imageOverlay,children:R}):null]}),_jsx(View,{style:{padding:ee},children:Ce})]}):Ce,ke=te?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:te,style:StyleSheet.absoluteFill}),Re]}):ce.active&&ce.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ce.size.width,height:ce.size.height,radius:ie,fill:pe,stroke:ge?be:void 0,strokeWidth:ge,outset:ge}),Re]}):Re;let Ae;if(J){const handlePress=e=>{if(!G)return;const t=resolveHaptic(B,"selection");t&&triggerHaptic(t),T?.(e)};Ae=_jsx(Animated.View,{style:[{transform:[{scale:K}]}],children:_jsx(Pressable,{ref:U,onPress:handlePress,onPressIn:Q,onPressOut:X,android_ripple:{color:N.colors.surface.pressed,borderless:!1},accessibilityRole:P??(G?"button":void 0),accessibilityLabel:I,accessibilityHint:L,testID:D,onLayout:ce.onLayout,style:[Se,V,F,fe],...E,...$.hostProps,children:ke})})}else Ae=_jsx(View,{ref:t,accessibilityLabel:I,accessibilityHint:L,accessibilityRole:P,testID:D,onLayout:ce.onLayout,style:[Se,V,F,fe],...E,children:ke});return k?_jsx(CardSkeleton,{...e}):$.enabled?_jsxs(_Fragment,{children:[Ae,$.renderSurface(_jsx(View,{style:[Se,V,F,fe,Y.preview],children:ke}))]}):Ae});Card.displayName="Card";const CardSkeleton=({variant:e="elevated",elevation:t,radius:o="lg",padding:i="md",bg:r,header:s,footer:l,imageSource:a,imageHeight:n=160,imageAspectRatio:d,borderRadius:c,containerStyle:u,headerStyle:h,bodyStyle:m,footerStyle:p,style:g,...b})=>{const y=useTheme(),x=paddingMap[i],f=y.spacing[x],S="flat"===e?0:c??y.radius[o],v=void 0!==s||hasBuiltInHeaderContent(b),j=resolveBackground(y,r)??y.colors.background.elevated,w="outlined"===e?1:0,C="outlined"===e?y.colors.border.primary:void 0;return _jsxs(View,{style:[{backgroundColor:j,borderRadius:S,...smoothCorners,borderWidth:w,borderColor:C,overflow:"hidden"},u,g],accessibilityRole:"progressbar",accessibilityLabel:"Loading",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==a?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,v?_jsx(View,{style:[{padding:f,paddingBottom:y.spacing.sm},h],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:f},m],children:_jsx(SkeletonText,{lines:3,fontSize:14,lastLineWidth:"55%"})}),void 0!==l?_jsx(View,{style:[{padding:f,paddingTop:y.spacing.sm,flexDirection:"row"},p],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:o,expanded:i,color:r,haptic:s})=>{const l=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===i?void 0:{expanded:i},"aria-expanded":i,onPress:()=>{const e=resolveHaptic(s,"selection");e&&triggerHaptic(e),o()},style:iconActionStyle,children:_jsx(AppIcon,{name:e,size:20,color:r??l.colors.text.primary})})},CardTextActionButton=({action:e,haptic:t})=>{const o=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{const o=resolveHaptic(t,"selection");o&&triggerHaptic(o),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:o.colors.primary,children:e.label})})},iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},resolveBackground=(e,t)=>{if(null==t)return;return e.colors.background[t]??t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.spacing.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.spacing.sm},headerFolded:{marginBottom:0},titleColumn:{flex:1},lead:{marginTop:e.spacing.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.spacing.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},preview:{margin:0,marginTop:0,marginBottom:0,marginLeft:0,marginRight:0,marginStart:0,marginEnd:0,marginHorizontal:0,marginVertical:0,position:"relative",top:0,left:0,width:"100%",height:"100%"}});export{Card};export default Card;
1
+ "use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=forwardRef((e,t)=>{const{children:o,variant:i="elevated",elevation:r="sm",radius:s="lg",padding:l="md",interactive:a=!1,bg:n,header:d,title:c,lead:u,action:h,headerActions:m,collapsible:p=!1,collapsed:g,defaultCollapsed:b=!1,onCollapsedChange:y,collapsedSummary:x,onRemove:f,removeLabel:S="Remove",separatorHeight:j=StyleSheet.hairlineWidth,footer:v,imageSource:w,imageHeight:C=160,imageAspectRatio:_,imageOverlay:R,loading:k=!1,gradient:A,onPress:T,haptic:B,contextMenu:I,accessibilityLabel:H,accessibilityHint:L,accessibilityRole:P,style:V,containerStyle:F,headerStyle:M,bodyStyle:z,footerStyle:q,borderRadius:W,testID:D,onLayout:O,...E}=e,N=useTheme(),G=a||"function"==typeof T,$=useContextMenu(I,{haptic:B||!1,testID:D,accessibilityActions:E.accessibilityActions,onAccessibilityAction:E.onAccessibilityAction}),U=useMemo(()=>mergeRefs(t,$.hostRef),[t,$.hostRef]),J=G||$.enabled,{style:K,pressIn:Q,pressOut:X}=usePressAnimation({enabled:J}),Y=useMemo(()=>buildStyles(N),[N]),Z=Boolean(w),ee=N.spacing[paddingMap[l]],te=useMemo(()=>A?"string"==typeof A?N.gradients[A]??null:A:null,[A,N.gradients]),oe="flat"===i,ie=oe?0:W??N.radius[s],re=resolveBackground(N,n),[se,le]=useControllableState({value:g,defaultValue:b,onChange:y}),ae=p&&se,ne=hasBuiltInHeaderContent(e),de=Boolean(d)||ne,ce=useSquircle(!Z&&!te&&!oe,ie,O),ue=StyleSheet.flatten([V,F])??{},he=ue.backgroundColor,me=ue.borderColor,pe=he??re??("filled"===i?N.colors.background.secondary:N.colors.background.elevated),ge="outlined"===i?N.colors.border.width:0,be=me??N.colors.border.primary,ye="elevated"===i&&supportsBoxShadow()?toBoxShadow(N.shadows[r]):void 0,xe=ce.active&&"elevated"===i&&!ye,fe=ce.active&&!xe?{backgroundColor:"transparent",borderColor:"transparent"}:null,Se=useMemo(()=>{const e={borderRadius:xe&&ce.size?squircleHostRadius(ce.size.width,ce.size.height,ie):ie,...smoothCorners,padding:Z?0:ee,overflow:ce.active?"visible":"hidden"};switch(i){case"flat":return{...e,backgroundColor:re??N.colors.background.elevated,borderBottomWidth:j,borderBottomColor:N.colors.border.primary};case"outlined":return{...e,backgroundColor:ce.active?"transparent":re??N.colors.background.elevated,borderWidth:N.colors.border.width,borderColor:ce.active?"transparent":N.colors.border.primary};case"filled":return{...e,backgroundColor:ce.active?"transparent":re??N.colors.background.secondary};default:return{...e,backgroundColor:re??N.colors.background.elevated,...ye?{boxShadow:ye}:N.shadows[r]}}},[N,i,r,ie,Z,ee,ce.active,ce.size,ye,xe,re,j]),je=useMemo(()=>({..."number"==typeof _?{width:"100%",aspectRatio:_}:{width:"100%",height:C},borderTopLeftRadius:ie,borderTopRightRadius:ie,borderBottomLeftRadius:0,borderBottomRightRadius:0,...smoothCorners}),[ie,_,C]),ve="string"==typeof c?c:"",we=_jsxs(_Fragment,{children:[_jsxs(View,{style:Y.titleColumn,children:["string"==typeof c?_jsx(Text,{variant:"title",accessibilityRole:"header",children:c}):c,u?_jsx(Text,{variant:"bodySmall",style:Y.lead,children:u}):null,ae&&x?_jsx(Text,{variant:"caption",style:Y.lead,children:x}):null]}),isCardTextAction(h)?_jsx(CardTextActionButton,{action:h,haptic:B}):h?_jsx(View,{style:Y.actionNode,children:h}):null,m,p?_jsx(CardIconAction,{icon:ae?"chevron-down":"chevron-up",label:`${ae?"Show":"Hide"} ${ve}`.trim(),expanded:!ae,onPress:()=>le(!ae),haptic:B}):null,f?_jsx(CardIconAction,{icon:"trash",label:S,onPress:f,color:N.colors.toneText.error,haptic:B}):null]}),Ce=_jsxs(_Fragment,{children:[de?_jsx(View,{style:[Y.header,!d&&Y.headerRow,ae&&Y.headerFolded,M],children:d??we}):null,ae?null:_jsx(View,{style:[de||v?Y.body:null,z],children:o}),v&&!ae?_jsx(View,{style:[Y.footer,q],children:v}):null]}),Re=Z?_jsxs(_Fragment,{children:[_jsxs(View,{style:Y.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:je,accessibilityLabel:"",accessible:!1}),R?_jsx(View,{pointerEvents:"box-none",style:Y.imageOverlay,children:R}):null]}),_jsx(View,{style:{padding:ee},children:Ce})]}):Ce,ke=te?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:te,style:StyleSheet.absoluteFill}),Re]}):ce.active&&ce.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ce.size.width,height:ce.size.height,radius:ie,fill:pe,stroke:ge?be:void 0,strokeWidth:ge,outset:ge}),Re]}):Re;let Ae;if(J){const handlePress=e=>{G&&(B&&triggerHaptic(B),T?.(e))};Ae=_jsx(Animated.View,{style:K,children:_jsx(Pressable,{ref:U,onPress:handlePress,onPressIn:Q,onPressOut:X,android_ripple:{color:N.colors.surface.pressed,borderless:!1},accessibilityRole:P??(G?"button":void 0),accessibilityLabel:H,accessibilityHint:L,testID:D,onLayout:ce.onLayout,style:[Se,V,F,fe],...E,...$.hostProps,children:ke})})}else Ae=_jsx(View,{ref:t,accessibilityLabel:H,accessibilityHint:L,accessibilityRole:P,testID:D,onLayout:ce.onLayout,style:[Se,V,F,fe],...E,children:ke});return k?_jsx(CardSkeleton,{...e}):$.enabled?_jsxs(_Fragment,{children:[Ae,$.renderSurface(_jsx(View,{style:[Se,V,F,fe,Y.preview],children:ke}))]}):Ae});Card.displayName="Card";const CardSkeleton=({variant:e="elevated",elevation:t,radius:o="lg",padding:i="md",bg:r,header:s,footer:l,imageSource:a,imageHeight:n=160,imageAspectRatio:d,borderRadius:c,containerStyle:u,headerStyle:h,bodyStyle:m,footerStyle:p,style:g,...b})=>{const y=useTheme(),x=paddingMap[i],f=y.spacing[x],S="flat"===e?0:c??y.radius[o],j=void 0!==s||hasBuiltInHeaderContent(b),v=resolveBackground(y,r)??y.colors.background.elevated,w="outlined"===e?1:0,C="outlined"===e?y.colors.border.primary:void 0;return _jsxs(View,{style:[{backgroundColor:v,borderRadius:S,...smoothCorners,borderWidth:w,borderColor:C,overflow:"hidden"},u,g],accessibilityRole:"progressbar",accessibilityLabel:"Loading",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==a?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,j?_jsx(View,{style:[{padding:f,paddingBottom:y.spacing.sm},h],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:f},m],children:_jsx(SkeletonText,{lines:3,fontSize:14,lastLineWidth:"55%"})}),void 0!==l?_jsx(View,{style:[{padding:f,paddingTop:y.spacing.sm,flexDirection:"row"},p],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:o,expanded:i,color:r,haptic:s})=>{const l=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===i?void 0:{expanded:i},"aria-expanded":i,onPress:()=>{s&&triggerHaptic(s),o()},style:iconActionStyle,children:_jsx(AppIcon,{name:e,size:20,color:r??l.colors.text.primary})})},CardTextActionButton=({action:e,haptic:t})=>{const o=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:o.colors.primary,children:e.label})})},iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},resolveBackground=(e,t)=>{if(null==t)return;return e.colors.background[t]??t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.spacing.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.spacing.sm},headerFolded:{marginBottom:0},titleColumn:{flex:1},lead:{marginTop:e.spacing.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.spacing.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},preview:{margin:0,marginTop:0,marginBottom:0,marginLeft:0,marginRight:0,marginStart:0,marginEnd:0,marginHorizontal:0,marginVertical:0,position:"relative",top:0,left:0,width:"100%",height:"100%"}});export{Card};export default Card;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Skeleton}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CarouselInner=forwardRef((e,t)=>{const{data:n,renderItem:r,keyExtractor:i,index:a,defaultIndex:l=0,onIndexChange:s,autoPlay:o=!1,autoPlayInterval:c=4e3,loop:u=!1,showPagination:m=!0,paginationStyle:d="dots",itemWidth:h="screen",spacing:g=0,containerStyle:y,accessibilityLabel:p,testID:b,showThumbnails:f=!1,haptic:x,renderThumbnail:S,loading:w=!1}=e,C=useTheme(),j="number"==typeof a,k=u||o,[v,I]=useState(()=>Dimensions.get("window").width),T="screen"===h?v:h,R=T+g,_=useRef(null),V=useRef(createAnimatedValue(0)).current,A=clamp(j?a:l,0,Math.max(0,n.length-1)),[E,H]=useState(A),z=useRef(null),M=useRef(null),D=useRef(!1),P=useRef(E);P.current=E;const W=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));H(e=>e===t?e:(s?.(t),t))},[n.length,s]),L=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);_.current?.scrollToOffset({offset:r*R,animated:t}),W(r)},[n.length,R,W]),$=useCallback(()=>{if(0===n.length)return;const e=P.current+1;e>=n.length?k&&L(0,!1):L(e,!0)},[n.length,k,L]),N=useCallback(()=>{if(0===n.length)return;const e=P.current-1;e<0?k&&L(n.length-1,!1):L(e,!0)},[n.length,k,L]);useImperativeHandle(t,()=>({scrollTo:L,next:$,prev:N}),[L,$,N]),useEffect(()=>{j&&a!==E&&L(a,!0)},[a]);const F=useCallback(()=>{z.current&&(clearInterval(z.current),z.current=null)},[]),O=useCallback(()=>{!o||n.length<=1||(F(),z.current=setInterval(()=>{if(D.current)return;const e=P.current+1;e>=n.length?L(0,!1):L(e,!0)},c))},[o,c,n.length,L,F]);useEffect(()=>(O(),()=>{F(),M.current&&clearTimeout(M.current)}),[O,F]);const X=m&&n.length>1&&"numbers"!==d,B=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:V}}}],{useNativeDriver:!1}),[V]),G=useCallback(e=>{if(R<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/R);W(n)},[R,W]),q=useCallback(()=>{D.current=!0,F(),M.current&&(clearTimeout(M.current),M.current=null)},[F]),J=useCallback(()=>{D.current=!1,o&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{O()},1e3))},[o,O]),K=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":$();break;case"decrement":N()}},[$,N]),Q=useMemo(()=>buildStyles(C),[C]),U=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:T,marginRight:t===n.length-1?0:g},accessibilityElementsHidden:t!==E,importantForAccessibility:t===E?"yes":"no-hide-descendants",children:r(e,t)}),[r,T,g,n.length,E]),Y=useCallback((e,t)=>String(t),[]),Z=useCallback((e,t)=>({length:R,offset:R*t,index:t}),[R]);return w?_jsx(CarouselSkeleton,{...e,containerWidth:v}):_jsxs(View,{style:[Q.container,y],onLayout:e=>I(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:p??"Carousel",accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:E,text:`Slide ${E+1} of ${n.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:K,testID:b,children:[_jsx(FlatList,{ref:_,data:n,keyExtractor:i??Y,renderItem:U,horizontal:!0,pagingEnabled:"screen"===h&&0===g,snapToInterval:R,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:X?B:void 0,scrollEventThrottle:X?16:void 0,onMomentumScrollEnd:G,onScrollBeginDrag:q,onScrollEndDrag:J,getItemLayout:Z,initialScrollIndex:A,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:E,scrollX:V,slideStride:R,variant:d,theme:C}):null,f&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:E,renderThumbnail:S,onSelect:e=>{const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),L(e,!0)},theme:C}):null]})});CarouselInner.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:12}],children:Array.from({length:3}).map((e,t)=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:4}}:"bars"===n?{width:20,height:4,radius:2,style:{marginHorizontal:3}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:4}},`sk-pg-${t}`))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=CarouselInner;Carousel.Skeleton=CarouselSkeleton;const Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:a})=>{if("numbers"===i)return _jsx(View,{style:paginationStyles.numbersWrap,children:_jsx(Text,{style:[paginationStyles.numbersText,{color:a.colors.text.secondary,fontSize:a.typography.fontSize.sm,fontWeight:a.typography.fontWeight.medium}],accessibilityLabel:`Slide ${t+1} of ${e}`,children:`${t+1} / ${e}`})});const l=Array.from({length:e},(e,t)=>t),s="bars"===i,o=s?24:6,c=s?36:16,u=s?3:6;return _jsx(View,{style:paginationStyles.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:l.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],l=n.interpolate({inputRange:i,outputRange:[o,c,o],extrapolate:"clamp"}),s=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:l,height:u,marginHorizontal:4,borderRadius:u/2,...smoothCorners,backgroundColor:e===t?a.colors.primary:a.colors.border.primary,opacity:s}]},e)})})},ThumbnailStrip=({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i})=>_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:thumbStyles.row,accessibilityRole:"tablist",children:e.map((e,a)=>_jsx(ThumbnailItem,{item:e,index:a,isActive:a===t,renderThumbnail:n,onPress:()=>r(a),theme:i},a))}),ThumbnailItem=({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:a})=>{const l=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(l,{toValue:n?1.1:1,useNativeDriver:!0,friction:6,tension:80});return e.start(),()=>e.stop()},[n,l]);const s=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:thumbStyles.image,resizeMode:"cover"}):_jsx(View,{style:[thumbStyles.placeholder,{backgroundColor:a.colors.background.secondary}],children:_jsx(Text,{style:{color:a.colors.text.secondary,fontSize:a.typography.fontSize.xs,fontWeight:a.typography.fontWeight.semibold},children:t+1})}),[e,t,r,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:`Go to slide ${t+1}`,children:_jsx(Animated.View,{style:[thumbStyles.thumb,{borderColor:n?a.colors.primary:"transparent",transform:[{scale:l}]}],children:s})})},thumbStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:8,paddingVertical:8},thumb:{width:40,height:40,marginHorizontal:4,borderRadius:6,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),paginationStyles=StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:12},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:12},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Skeleton}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CarouselInner=forwardRef((e,t)=>{const{data:n,renderItem:r,keyExtractor:i,index:a,defaultIndex:l=0,onIndexChange:s,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:y=0,containerStyle:p,accessibilityLabel:b,testID:f,showThumbnails:x=!1,haptic:S,renderThumbnail:w,loading:C=!1}=e,j=useTheme(),v="number"==typeof a,k=d||c,[I,T]=useState(()=>Dimensions.get("window").width),R="screen"===g?I:g,_=R+y,V=useRef(null),A=useRef(createAnimatedValue(0)).current,E=clamp(v?a:l,0,Math.max(0,n.length-1)),[H,z]=useState(E),M=useRef(null),D=useRef(null),P=useRef(!1),W=useRef(H);W.current=H;const L=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));z(e=>e===t?e:(s?.(t),t))},[n.length,s]),$=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);V.current?.scrollToOffset({offset:r*_,animated:t}),L(r)},[n.length,_,L]),N=useCallback(()=>{if(0===n.length)return;const e=W.current+1;e>=n.length?k&&$(0,!1):$(e,!0)},[n.length,k,$]),O=useCallback(()=>{if(0===n.length)return;const e=W.current-1;e<0?k&&$(n.length-1,!1):$(e,!0)},[n.length,k,$]);useImperativeHandle(t,()=>({scrollTo:$,next:N,prev:O}),[$,N,O]),useEffect(()=>{v&&a!==H&&$(a,!0)},[a]);const F=useCallback(()=>{M.current&&(clearInterval(M.current),M.current=null)},[]),X=useCallback(()=>{!c||n.length<=1||(F(),M.current=setInterval(()=>{if(P.current)return;const e=W.current+1;e>=n.length?$(0,!1):$(e,!0)},u))},[c,u,n.length,$,F]);useEffect(()=>(X(),()=>{F(),D.current&&clearTimeout(D.current)}),[X,F]);const B=m&&n.length>1&&"numbers"!==h||void 0!==o,G=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:A}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[A,o]),q=useCallback(e=>{if(_<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/_);L(n)},[_,L]),J=useCallback(()=>{P.current=!0,F(),D.current&&(clearTimeout(D.current),D.current=null)},[F]),K=useCallback(()=>{P.current=!1,c&&(D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{X()},1e3))},[c,X]),Q=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":N();break;case"decrement":O()}},[N,O]),U=useMemo(()=>buildStyles(j),[j]),Y=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:R,marginRight:t===n.length-1?0:y},accessibilityElementsHidden:t!==H,importantForAccessibility:t===H?"yes":"no-hide-descendants",children:r(e,t)}),[r,R,y,n.length,H]),Z=useCallback((e,t)=>String(t),[]),ee=useCallback((e,t)=>({length:_,offset:_*t,index:t}),[_]);return C?_jsx(CarouselSkeleton,{...e,containerWidth:I}):_jsxs(View,{style:[U.container,p],onLayout:e=>T(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:b??"Carousel",accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:H,text:`Slide ${H+1} of ${n.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:f,children:[_jsx(FlatList,{ref:V,data:n,keyExtractor:i??Z,renderItem:Y,horizontal:!0,pagingEnabled:"screen"===g&&0===y,snapToInterval:_,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:B?G:void 0,scrollEventThrottle:B?16:void 0,onMomentumScrollEnd:q,onScrollBeginDrag:J,onScrollEndDrag:K,getItemLayout:ee,initialScrollIndex:E,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:H,scrollX:A,slideStride:_,variant:h,theme:j}):null,x&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:H,renderThumbnail:w,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),$(e,!0)},theme:j}):null]})});CarouselInner.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:12}],children:Array.from({length:3}).map((e,t)=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:4}}:"bars"===n?{width:20,height:4,radius:2,style:{marginHorizontal:3}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:4}},`sk-pg-${t}`))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=CarouselInner;Carousel.Skeleton=CarouselSkeleton;const Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:a})=>{if("numbers"===i)return _jsx(View,{style:paginationStyles.numbersWrap,children:_jsx(Text,{style:[paginationStyles.numbersText,{color:a.colors.text.secondary,fontSize:a.typography.fontSize.sm,fontWeight:a.typography.fontWeight.medium}],accessibilityLabel:`Slide ${t+1} of ${e}`,children:`${t+1} / ${e}`})});const l=Array.from({length:e},(e,t)=>t),s="bars"===i,o=s?24:6,c=s?36:16,u=s?3:6;return _jsx(View,{style:paginationStyles.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:l.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],l=n.interpolate({inputRange:i,outputRange:[o,c,o],extrapolate:"clamp"}),s=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:l,height:u,marginHorizontal:4,borderRadius:u/2,...smoothCorners,backgroundColor:e===t?a.colors.primary:a.colors.border.primary,opacity:s}]},e)})})},ThumbnailStrip=({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i})=>_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:thumbStyles.row,accessibilityRole:"tablist",children:e.map((e,a)=>_jsx(ThumbnailItem,{item:e,index:a,isActive:a===t,renderThumbnail:n,onPress:()=>r(a),theme:i},a))}),ThumbnailItem=({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:a})=>{const l=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(l,{toValue:n?1.1:1,useNativeDriver:!0,friction:6,tension:80});return e.start(),()=>e.stop()},[n,l]);const s=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:thumbStyles.image,resizeMode:"cover"}):_jsx(View,{style:[thumbStyles.placeholder,{backgroundColor:a.colors.background.secondary}],children:_jsx(Text,{style:{color:a.colors.text.secondary,fontSize:a.typography.fontSize.xs,fontWeight:a.typography.fontWeight.semibold},children:t+1})}),[e,t,r,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:`Go to slide ${t+1}`,children:_jsx(Animated.View,{style:[thumbStyles.thumb,{borderColor:n?a.colors.primary:"transparent",transform:[{scale:l}]}],children:s})})},thumbStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:8,paddingVertical:8},thumb:{width:40,height:40,marginHorizontal:4,borderRadius:6,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),paginationStyles=StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:12},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:12},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,useTheme}from"../../theme/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Skeleton}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneFor=(e,o)=>{switch(o){case"primary":return{base:e.colors.primaryMuted,on:e.colors.primary,ink:e.colors.toneText.primary,border:e.colors.primary,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"success":return{base:e.colors.background.tertiary,on:e.colors.success,ink:e.colors.toneText.success,border:e.colors.success,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"warning":return{base:e.colors.background.tertiary,on:e.colors.warning,ink:e.colors.toneText.warning,border:e.colors.warning,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"error":return{base:e.colors.background.tertiary,on:e.colors.error,ink:e.colors.toneText.error,border:e.colors.error,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"info":return{base:e.colors.background.tertiary,on:e.colors.info,ink:e.colors.toneText.info,border:e.colors.info,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};default:return{base:e.colors.background.tertiary,on:e.colors.text.primary,ink:e.colors.text.primary,border:e.colors.border.primary,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,sizeMap={sm:{paddingH:10,paddingV:4,fontSize:12,minHeight:26,closeSize:16,closeFont:12,gap:6,iconSize:14},md:{paddingH:12,paddingV:6,fontSize:13,minHeight:32,closeSize:18,closeFont:13,gap:8,iconSize:16}},hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,o)=>{const{label:r,count:t,selected:s=!1,selectionMode:i="single",onPress:l,onClose:n,leftIcon:a,iconVariant:c,variant:d="filled",tone:p="neutral",size:m="md",disabled:u=!1,loading:g=!1,accessibilityLabel:y,haptic:b,style:h,textStyle:f,containerStyle:S,countStyle:x,closeButtonStyle:z,closeIconStyle:k,testID:C}=e,I=useTheme(),M=!!l&&!u,j="radio"===i,H=!!l&&(!u||j),T=hasChipCount(t),{scale:w,pressIn:_,pressOut:F}=usePressAnimation({enabled:M}),O=useMemo(()=>toneFor(I,p),[I,p]),B=I.components.chip?.[m],L={paddingH:B?.paddingHorizontal??sizeMap[m].paddingH,paddingV:B?.paddingVertical??sizeMap[m].paddingV,fontSize:B?.fontSize??sizeMap[m].fontSize,minHeight:B?.minHeight??sizeMap[m].minHeight,closeSize:B?.closeSize??sizeMap[m].closeSize,closeFont:B?.closeFontSize??sizeMap[m].closeFont,gap:B?.gap??sizeMap[m].gap,iconSize:B?.iconSize??sizeMap[m].iconSize},V=Math.max(0,Math.ceil((44-L.minHeight)/2)),P=j?{top:V,bottom:V}:void 0,v="filled"===d,A="soft"===d,R=(()=>{if(A){const e=s?O.selectedOn:O.on;return tintOf(e,s?.24:.14,s?O.selectedBg:O.base)}return s?v?O.selectedBg:"transparent":v?O.base:"transparent"})(),D=A?"transparent":s?O.selectedBorder:v?"transparent":O.border,E=u?I.colors.text.disabled:s?A?I.colors.text.primary:O.selectedInk:O.ink,$=v||A?0:I.colors.border.width,handlePress=()=>{if(!M)return;const e=resolveHaptic(b,"selection");e&&triggerHaptic(e),l?.()},N=y??(T?`${r}, ${t}`:r),Y=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:L.gap},children:renderSlotIcon(a,{color:E,size:L.iconSize,disabled:u},c)}):null,_jsx(Text,{style:[styles.label,{color:E,fontSize:L.fontSize,...fontFor(I,"medium")},f],numberOfLines:1,children:r??" "}),T?_jsx(Text,{style:[styles.count,{color:E,fontSize:Math.min(I.typography.fontSize.xs,L.fontSize),marginLeft:I.spacing.xs,...fontFor(I,"normal")},x],numberOfLines:1,children:t}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==b&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:`Remove ${r}`,accessibilityState:{disabled:u},"aria-disabled":u,hitSlop:6,style:({pressed:e})=>[styles.close,{width:L.closeSize,height:L.closeSize,borderRadius:L.closeSize/2,...smoothCorners,marginLeft:L.gap,backgroundColor:e?I.colors.surface.pressed:I.colors.surface.hovered},z],children:_jsx(Text,{style:[{color:E,fontSize:L.closeFont,...fontFor(I,"bold"),lineHeight:L.closeFont+2},k],maxFontSizeMultiplier:1,children:"×"})}):null]}),U={paddingHorizontal:L.paddingH,paddingVertical:L.paddingV,minHeight:L.minHeight,borderRadius:I.radius.full,...smoothCorners,backgroundColor:R,borderWidth:$,borderColor:D,opacity:u?.55:1};let W;return W=H?_jsx(Animated.View,{style:{transform:[{scale:w}],alignSelf:"flex-start"},children:_jsx(Pressable,{ref:o,onPress:handlePress,onPressIn:_,onPressOut:F,disabled:!M,accessibilityRole:j?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:N,accessibilityState:j||"multiple"===i?{checked:s,disabled:u}:{selected:s,disabled:u},"aria-checked":j||"multiple"===i?s:void 0,"aria-selected":j||"multiple"===i?void 0:s,"aria-disabled":u,hitSlop:P,android_ripple:{color:I.colors.surface.pressed,borderless:!1},testID:C,style:({pressed:e})=>[styles.base,U,e&&"outlined"===d?{backgroundColor:I.colors.surface.pressed}:null,S,h],children:Y})}):_jsx(View,{ref:o,style:[styles.base,U,S,h],accessible:!0,accessibilityRole:"text",accessibilityLabel:N,accessibilityState:{selected:s,disabled:u},"aria-selected":s,"aria-disabled":u,testID:C,children:Y}),g?_jsx(ChipSkeleton,{...e}):W});Chip.displayName="Chip";const ChipSkeleton=({label:e,count:o,size:r="md",leftIcon:t,onClose:s,style:i,containerStyle:l})=>{const n=sizeMap[r],a=Math.max(40,Math.min(120,7*(e??"").length)),c=n.minHeight,d=c/2,p=a+2*n.paddingH+(hasChipCount(o)?n.gap/2+7*String(o).length:0)+(void 0!==t?n.gap+14:0)+(void 0!==s?n.gap+n.closeSize:0);return _jsx(Skeleton,{width:p,height:c,radius:d,style:[{alignSelf:"flex-start"},l,i]})};ChipSkeleton.displayName="ChipSkeleton",Chip.Skeleton=ChipSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},row:{flexDirection:"row",alignItems:"center"},label:{flexShrink:1,textAlign:"center"},count:{flexShrink:0,fontVariant:["tabular-nums"]},close:{alignItems:"center",justifyContent:"center"}});export{Chip};export default Chip;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,useTheme}from"../../theme/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Skeleton}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneFor=(e,o)=>{switch(o){case"primary":return{base:e.colors.primaryMuted,on:e.colors.primary,ink:e.colors.toneText.primary,border:e.colors.primary,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"success":return{base:e.colors.background.tertiary,on:e.colors.success,ink:e.colors.toneText.success,border:e.colors.success,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"warning":return{base:e.colors.background.tertiary,on:e.colors.warning,ink:e.colors.toneText.warning,border:e.colors.warning,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"error":return{base:e.colors.background.tertiary,on:e.colors.error,ink:e.colors.toneText.error,border:e.colors.error,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};case"info":return{base:e.colors.background.tertiary,on:e.colors.info,ink:e.colors.toneText.info,border:e.colors.info,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary};default:return{base:e.colors.background.tertiary,on:e.colors.text.primary,ink:e.colors.text.primary,border:e.colors.border.primary,selectedBg:e.colors.primaryMuted,selectedOn:e.colors.primary,selectedInk:e.colors.toneText.primary,selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,sizeMap={sm:{paddingH:10,paddingV:4,fontSize:12,minHeight:26,closeSize:16,closeFont:12,gap:6,iconSize:14},md:{paddingH:12,paddingV:6,fontSize:13,minHeight:32,closeSize:18,closeFont:13,gap:8,iconSize:16}},hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,o)=>{const{label:r,count:t,selected:s=!1,selectionMode:i="single",onPress:l,onClose:n,leftIcon:a,iconVariant:c,variant:d="filled",tone:p="neutral",size:m="md",disabled:u=!1,loading:y=!1,accessibilityLabel:g,haptic:b,style:h,textStyle:f,containerStyle:S,countStyle:x,closeButtonStyle:z,closeIconStyle:k,testID:C}=e,I=useTheme(),M=!!l&&!u,j="radio"===i,H=!!l&&(!u||j),T=hasChipCount(t),{style:w,pressIn:_,pressOut:F}=usePressAnimation({enabled:M}),O=useMemo(()=>toneFor(I,p),[I,p]),B=I.components.chip?.[m],L={paddingH:B?.paddingHorizontal??sizeMap[m].paddingH,paddingV:B?.paddingVertical??sizeMap[m].paddingV,fontSize:B?.fontSize??sizeMap[m].fontSize,minHeight:B?.minHeight??sizeMap[m].minHeight,closeSize:B?.closeSize??sizeMap[m].closeSize,closeFont:B?.closeFontSize??sizeMap[m].closeFont,gap:B?.gap??sizeMap[m].gap,iconSize:B?.iconSize??sizeMap[m].iconSize},V=Math.max(0,Math.ceil((44-L.minHeight)/2)),P=j?{top:V,bottom:V}:void 0,v="filled"===d,A="soft"===d,R=(()=>{if(A){const e=s?O.selectedOn:O.on;return tintOf(e,s?.24:.14,s?O.selectedBg:O.base)}return s?v?O.selectedBg:"transparent":v?O.base:"transparent"})(),D=A?"transparent":s?O.selectedBorder:v?"transparent":O.border,E=u?I.colors.text.disabled:s?A?I.colors.text.primary:O.selectedInk:O.ink,$=v||A?0:I.colors.border.width,handlePress=()=>{if(!M)return;const e=resolveHaptic(b,"selection");e&&triggerHaptic(e),l?.()},N=g??(T?`${r}, ${t}`:r),Y=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:L.gap},children:renderSlotIcon(a,{color:E,size:L.iconSize,disabled:u},c)}):null,_jsx(Text,{style:[styles.label,{color:E,fontSize:L.fontSize,...fontFor(I,"medium")},f],numberOfLines:1,children:r??" "}),T?_jsx(Text,{style:[styles.count,{color:E,fontSize:Math.min(I.typography.fontSize.xs,L.fontSize),marginLeft:I.spacing.xs,...fontFor(I,"normal")},x],numberOfLines:1,children:t}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==b&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:`Remove ${r}`,accessibilityState:{disabled:u},"aria-disabled":u,hitSlop:6,style:({pressed:e})=>[styles.close,{width:L.closeSize,height:L.closeSize,borderRadius:L.closeSize/2,...smoothCorners,marginLeft:L.gap,backgroundColor:e?I.colors.surface.pressed:I.colors.surface.hovered},z],children:_jsx(Text,{style:[{color:E,fontSize:L.closeFont,...fontFor(I,"bold"),lineHeight:L.closeFont+2},k],maxFontSizeMultiplier:1,children:"×"})}):null]}),U={paddingHorizontal:L.paddingH,paddingVertical:L.paddingV,minHeight:L.minHeight,borderRadius:I.radius.full,...smoothCorners,backgroundColor:R,borderWidth:$,borderColor:D,opacity:u?.55:1};let W;return W=H?_jsx(Animated.View,{style:[w,{alignSelf:"flex-start"}],children:_jsx(Pressable,{ref:o,onPress:handlePress,onPressIn:_,onPressOut:F,disabled:!M,accessibilityRole:j?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:N,accessibilityState:j||"multiple"===i?{checked:s,disabled:u}:{selected:s,disabled:u},"aria-checked":j||"multiple"===i?s:void 0,"aria-selected":j||"multiple"===i?void 0:s,"aria-disabled":u,hitSlop:P,android_ripple:{color:I.colors.surface.pressed,borderless:!1},testID:C,style:({pressed:e})=>[styles.base,U,e&&"outlined"===d?{backgroundColor:I.colors.surface.pressed}:null,S,h],children:Y})}):_jsx(View,{ref:o,style:[styles.base,U,S,h],accessible:!0,accessibilityRole:"text",accessibilityLabel:N,accessibilityState:{selected:s,disabled:u},"aria-selected":s,"aria-disabled":u,testID:C,children:Y}),y?_jsx(ChipSkeleton,{...e}):W});Chip.displayName="Chip";const ChipSkeleton=({label:e,count:o,size:r="md",leftIcon:t,onClose:s,style:i,containerStyle:l})=>{const n=sizeMap[r],a=Math.max(40,Math.min(120,7*(e??"").length)),c=n.minHeight,d=c/2,p=a+2*n.paddingH+(hasChipCount(o)?n.gap/2+7*String(o).length:0)+(void 0!==t?n.gap+14:0)+(void 0!==s?n.gap+n.closeSize:0);return _jsx(Skeleton,{width:p,height:c,radius:d,style:[{alignSelf:"flex-start"},l,i]})};ChipSkeleton.displayName="ChipSkeleton",Chip.Skeleton=ChipSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},row:{flexDirection:"row",alignItems:"center"},label:{flexShrink:1,textAlign:"center"},count:{flexShrink:0,fontVariant:["tabular-nums"]},close:{alignItems:"center",justifyContent:"center"}});export{Chip};export default Chip;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,s=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);s.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return s},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),formatLongDate=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"long",year:"numeric",month:"long",day:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:s,disabledDates:o,mode:n="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:g="Cancel",style:m,containerStyle:y,headerLabelStyle:p,navButtonStyle:h,footerButtonStyle:f,haptic:b,testID:x,label:D,placeholder:w,helperText:v,error:C,required:S,disabled:j,size:k,variant:P,clearable:T,onClear:V,formatValue:_,triggerStyle:A}=e,R=void 0!==e.visible,[M,I]=useState(!1),F=R?e.visible:M,L=R?x:x?`${x}-calendar`:void 0,B=useTheme(),[Y,z]=useModalInsets(),H=useMemo(()=>buildStyles(B),[B]),[N,$]=useState(()=>startOfDay(new Date));useEffect(()=>{F&&$(startOfDay(new Date))},[F]);const W=t?startOfDay(t):N,[E,O]=useState(W),[G,q]=useState(t?startOfDay(t):null),[X,Z]=useState("days"),J=useRef(createAnimatedValue(0)).current,K=useRef(createAnimatedValue(0)).current,Q=useRef(createAnimatedValue(0)).current,U=useRef(0),ee=useRef(createAnimatedValue(0)).current,te=useRef(createAnimatedValue(1)).current,ae=useRef(createAnimatedValue(1)).current,re=useRef(createAnimatedValue(1)).current,ie=useRef(createAnimatedValue(1)).current,se=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);q(e),O(e)}else q(null)},[t]),useEffect(()=>{if("modal"===n&&F){J.setValue(0),setNativeValue(K,0),setNativeValue(Q,0);const e=Animated.parallel([Animated.timing(J,{toValue:1,duration:B.motion.duration.normal,easing:Easing.out(Easing.cubic),useNativeDriver:!1}),Animated.spring(K,{toValue:1,damping:B.motion.spring.gentle.damping,stiffness:B.motion.spring.gentle.stiffness,mass:B.motion.spring.gentle.mass,useNativeDriver:!0})]);return e.start(),()=>e.stop()}},[F,n,J,K,Q,B.motion]);const oe=useMemo(()=>{const e=new Set;return o?.forEach(t=>e.add(toIso(startOfDay(t)))),e},[o]),ne=useMemo(()=>i?startOfDay(i):null,[i]),le=useMemo(()=>s?startOfDay(s):null,[s]),ce=useCallback(e=>!!(ne&&e.getTime()<ne.getTime())||(!!(le&&e.getTime()>le.getTime())||!!oe.has(toIso(e))),[ne,le,oe]),de=useMemo(()=>buildMonthMatrix(E,c),[E,c]),ue=useMemo(()=>buildYearCells(E.getFullYear()),[E]),ge=useMemo(()=>buildDecadeCells(E.getFullYear()),[E]),me=useMemo(()=>weekdayLabels(l,c),[l,c]),ye=useMemo(()=>{if("days"===X)return formatMonthYear(E,l);if("years"===X){return`${ue[0]} - ${ue[ue.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[E,ge,l,X,ue]),pe=useCallback(e=>!!(ne&&e<ne.getFullYear())||!!(le&&e>le.getFullYear()),[ne,le]),he=useCallback(e=>!!(ne&&e+10-1<ne.getFullYear())||!!(le&&e>le.getFullYear()),[ne,le]),fe=useCallback(e=>{!1!==b&&triggerHaptic("impactLight");const t=e>0?1:-1,a=B.components.datePicker?.monthSlideDistance??32,r=B.components.datePicker?.monthSlideOutDuration??B.motion.duration.fast??140,i=B.components.datePicker?.monthSlideInDuration??B.motion.duration.fast??160;Animated.sequence([Animated.parallel([Animated.timing(ee,{toValue:-t*a,duration:r,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(te,{toValue:0,duration:r,useNativeDriver:!0})]),Animated.timing(ee,{toValue:t*a,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(ee,{toValue:0,duration:i,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(te,{toValue:1,duration:i,useNativeDriver:!0})])]).start();const s=addMonths(E,e);O(s),AccessibilityInfo.announceForAccessibility(formatMonthYear(s,l))},[E,b,l,te,ee,B.components.datePicker,B.motion.duration.fast]),be=useCallback(()=>{"days"!==X?(!1!==b&&triggerHaptic("impactLight"),O("years"===X?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):fe(-1)},[fe,X,b]),xe=useCallback(()=>{"days"!==X?(!1!==b&&triggerHaptic("impactLight"),O("years"===X?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):fe(1)},[fe,X,b]),De=useCallback(()=>{const e=B.components.datePicker?.viewTransitionDuration??B.motion.duration.normal??200;setNativeValue(re,0),setNativeValue(ie,.9),Animated.parallel([Animated.timing(re,{toValue:1,duration:e,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ie,{toValue:1,duration:e,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[re,ie,B.components.datePicker,B.motion.duration.normal]),we=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e);const t=B.components.datePicker?.headerPressDuration??80,a=B.components.datePicker?.headerReleaseDuration??100;Animated.sequence([Animated.timing(se,{toValue:.96,duration:t,useNativeDriver:!0}),Animated.timing(se,{toValue:1,duration:a,useNativeDriver:!0})]).start(),Z(e=>"days"===e?"years":"years"===e?"decades":"years"),De()},[De,se,b,B.components.datePicker]),ve=useCallback(e=>{const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),O(t=>new Date(e,t.getMonth(),1)),Z("days"),De()},[De,b]),Ce=useCallback(e=>{const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),O(t=>new Date(e+4,t.getMonth(),1)),Z("years"),De()},[De,b]),Se=useCallback(e=>{if(ce(e.date))return;const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),q(e.date),e.inMonth||O(new Date(e.date.getFullYear(),e.date.getMonth(),1)),setNativeValue(ae,.7),Animated.spring(ae,{toValue:1,damping:B.motion.spring.bouncy.damping,stiffness:B.motion.spring.bouncy.stiffness,mass:B.motion.spring.bouncy.mass,useNativeDriver:!0}).start()},[ce,ae,B.motion.spring.bouncy,b]),je=useCallback(()=>{R||I(!1),r?.()},[R,r]),ke=useCallback(()=>{"modal"===n?Animated.parallel([Animated.timing(J,{toValue:0,duration:B.motion.duration.fast,easing:Easing.bezier(...B.motion.easing.accelerate),useNativeDriver:!1}),Animated.timing(K,{toValue:0,duration:B.motion.duration.fast,easing:Easing.bezier(...B.motion.easing.accelerate),useNativeDriver:!0})]).start(()=>{je()}):je()},[J,n,je,K,B.motion.duration.fast,B.motion.easing.accelerate]),{handleGesture:Pe}=useDragToDismiss({drag:Q,travel:()=>U.current||320,onDismiss:ke}),Te=useCallback(()=>{!1!==b&&triggerHaptic("selection"),ke()},[ke,b]),Ve=useCallback(()=>{G&&(!1!==b&&triggerHaptic("notificationSuccess"),a?.(G),ke())},[ke,a,G,b]),Ae=K.interpolate({inputRange:[0,1],outputRange:[320,0]}),Re=_jsx(View,{style:H.titleRow,children:_jsx(Text,{style:H.title,accessibilityRole:"header",children:d})}),Me=_jsxs(View,{style:[H.card,m,y],accessibilityRole:"modal"===n?void 0:"none",accessible:!1,testID:L,children:["modal"===n?_jsx(GestureDetector,{gesture:Pe,children:_jsxs(View,{style:H.grabArea,children:[_jsx(View,{style:H.handle}),Re]})}):Re,_jsxs(View,{style:H.headerRow,children:[_jsx(Pressable,{onPress:be,style:({pressed:e})=>[H.navBtn,e&&H.navBtnPressed,h],accessibilityRole:"button",accessibilityLabel:"days"===X?"Previous month":"years"===X?"Previous years":"Previous decades",hitSlop:8,children:_jsx(Text,{style:H.navText,children:"‹"})}),_jsx(Pressable,{onPress:we,style:[H.headerLabelWrap,p],accessibilityRole:"button",accessibilityLabel:"days"===X?`${ye}, switch to year selection`:"years"===X?`${ye}, switch to decade selection`:`${ye}, switch to year selection`,hitSlop:8,children:_jsxs(Animated.View,{style:[H.headerLabelInner,{transform:[{scale:se}],opacity:"days"===X?te:1}],children:[_jsx(Animated.Text,{style:[H.headerLabel,{transform:[{translateX:"days"===X?ee:0}]}],accessibilityLiveRegion:"polite",children:ye}),_jsx(View,{style:H.headerCaret,children:(B.icons?.chevronDown??defaultIcons.chevronDown)({size:B.typography.fontSize.sm,color:B.colors.text.secondary})})]})}),_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[H.navBtn,e&&H.navBtnPressed,h],accessibilityRole:"button",accessibilityLabel:"days"===X?"Next month":"years"===X?"Next years":"Next decades",hitSlop:8,children:_jsx(Text,{style:H.navText,children:"›"})})]}),"days"===X?_jsxs(_Fragment,{children:[_jsx(View,{style:H.weekdayRow,children:me.map((e,t)=>_jsx(View,{style:H.weekdayCell,children:_jsx(Text,{style:H.weekdayText,children:e})},`${e}-${t}`))}),_jsx(Animated.View,{style:[H.grid,{opacity:te,transform:[{translateX:ee}]}],children:Array.from({length:6}).map((e,t)=>_jsx(View,{style:H.gridRow,children:de.slice(7*t,7*t+7).map(e=>{const t=ce(e.date),a=!!G&&isSameDay(e.date,G),r=isSameDay(e.date,N),i=a?B.colors.primary:"transparent",s=r&&!a?B.colors.primary:"transparent",o=a?B.colors.onPrimary:e.inMonth?t?B.colors.text.disabled:B.colors.text.primary:B.colors.text.tertiary,n=t?.3:e.inMonth?1:.4;return _jsx(Pressable,{disabled:t,onPress:()=>Se(e),accessibilityRole:"button",accessibilityLabel:formatLongDate(e.date,l),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:H.dayCell,children:_jsx(Animated.View,{style:[H.dayInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:n},a?{transform:[{scale:ae}]}:null],children:_jsx(Text,{style:[H.dayText,{color:o}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):_jsx(Animated.View,"years"===X?{style:[H.yearGrid,{opacity:re,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:H.gridRow,children:ue.slice(4*t,4*t+4).map(e=>{const t=pe(e),a=!!G&&G.getFullYear()===e,r=N.getFullYear()===e,i=a?B.colors.primary:"transparent",s=r&&!a?B.colors.primary:"transparent",o=a?B.colors.onPrimary:t?B.colors.text.disabled:B.colors.text.primary,n=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>ve(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:H.yearCell,children:_jsx(View,{style:[H.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:n}],children:_jsx(Text,{style:[H.yearText,{color:o}],children:e})})},`year-${e}`)})},`yr-${t}`))}:{style:[H.yearGrid,{opacity:re,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:H.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=he(e),r=!!G&&decadeStartFor(G.getFullYear())===e,i=decadeStartFor(N.getFullYear())===e,s=r?B.colors.primary:"transparent",o=i&&!r?B.colors.primary:"transparent",n=r?B.colors.onPrimary:a?B.colors.text.disabled:B.colors.text.primary,l=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:H.yearCell,children:_jsxs(View,{style:[H.yearInner,{backgroundColor:s,borderColor:o,borderWidth:i&&!r?1.5:0,opacity:l}],children:[_jsx(Text,{style:[H.yearText,{color:n}],children:`${e}s`}),_jsx(Text,{style:[H.decadeRangeText,{color:r?B.colors.onPrimary:B.colors.text.tertiary}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),_jsxs(View,{style:H.footer,children:[_jsx(Pressable,{onPress:Te,style:({pressed:e})=>[H.footerBtn,H.footerCancel,e&&H.footerBtnPressed,f],accessibilityRole:"button",accessibilityLabel:g,children:_jsx(Text,{style:[H.footerBtnText,{color:B.colors.text.secondary}],children:g})}),_jsx(Pressable,{onPress:Ve,disabled:!G,style:({pressed:e})=>[H.footerBtn,H.footerConfirm,{backgroundColor:B.colors.primary,opacity:G?1:.5},e&&{backgroundColor:B.colors.primaryHover},f],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!G},"aria-disabled":!G,children:_jsx(Text,{style:[H.footerBtnText,{color:B.colors.onPrimary}],children:u})})]})]}),Ie=t?(_??(e=>e.toLocaleDateString()))(t):void 0,Fe=!R;if("inline"===n)return F||Fe?Fe?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:D,value:Ie,placeholder:w,helperText:v,error:C,required:S,disabled:j,size:k,variant:P,clearable:T,onClear:V,onPress:()=>I(!0),triggerStyle:A,testID:x}),F?Me:null]}):Me:null;const Le=_jsx(Modal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:ke,children:_jsx(ModalSafeArea,{onInsets:z,children:_jsxs(GestureHandlerRootView,{collapsable:!1,style:[H.backdrop,{backgroundColor:B.colors.background.overlay}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:ke,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[H.sheetWrap,{paddingBottom:Math.max(Y.bottom,B.spacing.lg),opacity:K,transform:[{translateY:Animated.add(Ae,Q)}]}],onLayout:e=>{U.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Me}),_jsx(ToastHost,{})]})})});return Fe?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:D,value:Ie,placeholder:w,helperText:v,error:C,required:S,disabled:j,size:k,variant:P,clearable:T,onClear:V,onPress:()=>I(!0),triggerStyle:A,testID:x}),Le]}):Le},buildStyles=e=>{const t=e.shadows.lg;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.spacing.md,paddingBottom:e.spacing.lg},card:{backgroundColor:e.colors.background.elevated,borderRadius:e.radius.xl,...smoothCorners,padding:e.spacing.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.spacing.lg,paddingTop:e.spacing.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.full,...smoothCorners,backgroundColor:e.colors.border.secondary,marginBottom:e.spacing.sm},titleRow:{marginBottom:e.spacing.sm},title:{fontSize:e.typography.fontSize.lg,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.spacing.md},navBtn:{width:e.components.datePicker?.navButtonSize??36,height:e.components.datePicker?.navButtonSize??36,borderRadius:e.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors.background.secondary},navBtnPressed:{backgroundColor:e.colors.surface.pressed},navText:{fontSize:e.components.datePicker?.navTextFontSize??22,lineHeight:e.components.datePicker?.navTextLineHeight??24,color:e.colors.text.primary,fontWeight:e.typography.fontWeight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.typography.fontSize.base,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},headerCaret:{marginLeft:e.spacing.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.spacing.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.spacing.xs},weekdayText:{fontSize:e.typography.fontSize.xs,fontWeight:e.typography.fontWeight.medium,color:e.colors.text.tertiary,letterSpacing:e.typography.letterSpacing.wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.components.datePicker?.dayCellPadding??2},dayInner:{width:"100%",height:"100%",borderRadius:e.components.datePicker?.dayInnerBorderRadius??e.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.components.datePicker?.yearCellPadding??4},yearInner:{width:"100%",height:"100%",borderRadius:e.components.datePicker?.yearInnerBorderRadius??e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.typography.fontSize.base,fontWeight:e.typography.fontWeight.semibold},decadeRangeText:{fontSize:e.typography.fontSize.xs,fontWeight:e.typography.fontWeight.medium,marginTop:e.components.datePicker?.decadeRangeMarginTop??2},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.spacing.lg,gap:e.spacing.sm},footerBtn:{paddingHorizontal:e.spacing.lg,paddingVertical:e.spacing.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:e.components.datePicker?.footerButtonMinHeight??40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.semibold}})};export{DatePicker};export default DatePicker;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const AnimatedGestureRoot=Animated.createAnimatedComponent(GestureHandlerRootView),transparentOf=e=>{const t=e.match(/^rgba?\(([^)]+)\)$/);if(!t)return"transparent";const[a,r,i]=t[1].split(",").map(e=>e.trim());return`rgba(${a}, ${r}, ${i}, 0)`},GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,o=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);o.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return o},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),formatLongDate=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"long",year:"numeric",month:"long",day:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:o,disabledDates:s,mode:n="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:g,containerStyle:y,headerLabelStyle:p,navButtonStyle:h,footerButtonStyle:f,haptic:b,testID:x,label:D,placeholder:v,helperText:w,error:C,required:S,disabled:j,size:k,variant:P,clearable:A,onClear:T,formatValue:R,triggerStyle:V}=e,_=void 0!==e.visible,[M,I]=useState(!1),F=_?e.visible:M,L=_?x:x?`${x}-calendar`:void 0,B=useTheme(),Y=usePresenceMotion(),[$,z]=useModalInsets(),N=useMemo(()=>buildStyles(B),[B]),[H,W]=useState(()=>startOfDay(new Date));useEffect(()=>{F&&W(startOfDay(new Date))},[F]);const E=t?startOfDay(t):H,[O,G]=useState(E),[q,X]=useState(t?startOfDay(t):null),[Z,J]=useState("days"),K=useRef(createAnimatedValue(0)).current,Q=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(0)).current,ee=useRef(0),te=useRef(createAnimatedValue(0)).current,ae=useRef(createAnimatedValue(1)).current,re=useRef(createAnimatedValue(1)).current,ie=useRef(createAnimatedValue(1)).current,oe=useRef(createAnimatedValue(1)).current,se=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);X(e),G(e)}else X(null)},[t]);const ne=useMemo(()=>{const e=new Set;return s?.forEach(t=>e.add(toIso(startOfDay(t)))),e},[s]),le=useMemo(()=>i?startOfDay(i):null,[i]),ce=useMemo(()=>o?startOfDay(o):null,[o]),de=useCallback(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!ne.has(toIso(e))),[le,ce,ne]),ue=useMemo(()=>buildMonthMatrix(O,c),[O,c]),me=useMemo(()=>buildYearCells(O.getFullYear()),[O]),ge=useMemo(()=>buildDecadeCells(O.getFullYear()),[O]),ye=useMemo(()=>weekdayLabels(l,c),[l,c]),pe=useMemo(()=>{if("days"===Z)return formatMonthYear(O,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[O,ge,l,Z,me]),he=useCallback(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),fe=useCallback(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),be=useCallback(e=>{!1!==b&&triggerHaptic("impactLight");const t=e>0?1:-1,a=B.components.datePicker?.monthSlideDistance??32,r=B.components.datePicker?.monthSlideOutDuration??B.motion.duration.fast??140,i=B.components.datePicker?.monthSlideInDuration??B.motion.duration.fast??160,[o]=Y.range(-t*a,0),[s]=Y.range(t*a,0),n=Y.reduced?Y.duration("fast"):r,c=Y.reduced?Y.duration("fast"):i;Animated.sequence([Animated.parallel([Animated.timing(te,{toValue:o,duration:r,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(ae,{toValue:0,duration:n,useNativeDriver:!0})]),Animated.timing(te,{toValue:s,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(te,{toValue:0,duration:i,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ae,{toValue:1,duration:c,useNativeDriver:!0})])]).start();const d=addMonths(O,e);G(d),AccessibilityInfo.announceForAccessibility(formatMonthYear(d,l))},[O,b,l,ae,te,Y,B.components.datePicker,B.motion.duration.fast]),xe=useCallback(()=>{"days"!==Z?(!1!==b&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):be(-1)},[be,Z,b]),De=useCallback(()=>{"days"!==Z?(!1!==b&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):be(1)},[be,Z,b]),ve=useCallback(()=>{const[e]=Y.range(.9,1),t=Y.reduced?Y.duration("normal"):B.components.datePicker?.viewTransitionDuration??B.motion.duration.normal??200;setNativeValue(ie,0),setNativeValue(oe,e),Animated.parallel([Animated.timing(ie,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(oe,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[ie,oe,Y,B.components.datePicker,B.motion.duration.normal]),we=useCallback(()=>{const e=resolveHaptic(b,"selection");if(e&&triggerHaptic(e),!Y.reduced){const e=B.components.datePicker?.headerPressDuration??80,t=B.components.datePicker?.headerReleaseDuration??100;Animated.sequence([Animated.timing(se,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(se,{toValue:1,duration:t,useNativeDriver:!0})]).start()}J(e=>"days"===e?"years":"years"===e?"decades":"years"),ve()},[ve,se,b,Y.reduced,B.components.datePicker]),Ce=useCallback(e=>{const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),G(t=>new Date(e,t.getMonth(),1)),J("days"),ve()},[ve,b]),Se=useCallback(e=>{const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),G(t=>new Date(e+4,t.getMonth(),1)),J("years"),ve()},[ve,b]),je=useCallback(e=>{if(de(e.date))return;const t=resolveHaptic(b,"selection");t&&triggerHaptic(t),X(e.date),e.inMonth||G(new Date(e.date.getFullYear(),e.date.getMonth(),1)),Y.reduced||(setNativeValue(re,.7),Animated.spring(re,{toValue:1,damping:B.motion.spring.bouncy.damping,stiffness:B.motion.spring.bouncy.stiffness,mass:B.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,Y.reduced,re,B.motion.spring.bouncy,b]),ke=useCallback(()=>{_||I(!1),r?.()},[_,r]),Pe=useCallback(()=>{"modal"===n?Animated.parallel([Animated.timing(K,{toValue:0,duration:Y.duration("normal"),easing:Easing.bezier(...B.motion.easing.accelerate),useNativeDriver:!1}),Animated.timing(Q,{toValue:0,duration:Y.duration("fast"),easing:Easing.bezier(...B.motion.easing.accelerate),useNativeDriver:!0})]).start(()=>{ke()}):ke()},[K,n,ke,Y,Q,B.motion.easing.accelerate]),{handleGesture:Ae,opacity:Te}=useDragToDismiss({drag:U,travel:()=>ee.current||320,onDismiss:Pe}),Re=useMemo(()=>Animated.multiply(Q,Te),[Q,Te]),Ve=useMemo(()=>K.interpolate({inputRange:[0,1],outputRange:[transparentOf(B.colors.background.overlay),B.colors.background.overlay]}),[K,B.colors.background.overlay]);useEffect(()=>{if("modal"===n&&F){K.setValue(0),setNativeValue(Q,0),setNativeValue(U,0),setNativeValue(Te,1);const e=Y.reduced?Animated.timing(Q,{toValue:1,duration:Y.duration("normal"),useNativeDriver:!0}):Animated.spring(Q,{toValue:1,damping:B.motion.spring.gentle.damping,stiffness:B.motion.spring.gentle.stiffness,mass:B.motion.spring.gentle.mass,useNativeDriver:!0}),t=Animated.parallel([Animated.timing(K,{toValue:1,duration:Y.duration("normal"),easing:Easing.out(Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[F,n,K,Y,Q,U,Te,B.motion]);const Me=useCallback(()=>{!1!==b&&triggerHaptic("selection"),Pe()},[Pe,b]),Ie=useCallback(()=>{q&&(!1!==b&&triggerHaptic("notificationSuccess"),a?.(q),Pe())},[Pe,a,q,b]),Fe=Q.interpolate({inputRange:[0,1],outputRange:Y.range(320,0)}),Le=_jsx(View,{style:N.titleRow,children:_jsx(Text,{style:N.title,accessibilityRole:"header",children:d})}),Be=_jsxs(View,{style:[N.card,g,y],accessibilityRole:"modal"===n?void 0:"none",accessible:!1,testID:L,children:["modal"===n?_jsx(GestureDetector,{gesture:Ae,children:_jsxs(View,{style:N.grabArea,children:[_jsx(View,{style:N.handle}),Le]})}):Le,_jsxs(View,{style:N.headerRow,children:[_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[N.navBtn,e&&N.navBtnPressed,h],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,children:_jsx(Text,{style:N.navText,children:"‹"})}),_jsx(Pressable,{onPress:we,style:[N.headerLabelWrap,p],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${pe}, switch to year selection`:"years"===Z?`${pe}, switch to decade selection`:`${pe}, switch to year selection`,hitSlop:8,children:_jsxs(Animated.View,{style:[N.headerLabelInner,{transform:[{scale:se}],opacity:"days"===Z?ae:1}],children:[_jsx(Animated.Text,{style:[N.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:pe}),_jsx(View,{style:N.headerCaret,children:(B.icons?.chevronDown??defaultIcons.chevronDown)({size:B.typography.fontSize.sm,color:B.colors.text.secondary})})]})}),_jsx(Pressable,{onPress:De,style:({pressed:e})=>[N.navBtn,e&&N.navBtnPressed,h],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,children:_jsx(Text,{style:N.navText,children:"›"})})]}),"days"===Z?_jsxs(_Fragment,{children:[_jsx(View,{style:N.weekdayRow,children:ye.map((e,t)=>_jsx(View,{style:N.weekdayCell,children:_jsx(Text,{style:N.weekdayText,children:e})},`${e}-${t}`))}),_jsx(Animated.View,{style:[N.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>_jsx(View,{style:N.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!q&&isSameDay(e.date,q),r=isSameDay(e.date,H),i=a?B.colors.primary:"transparent",o=r&&!a?B.colors.primary:"transparent",s=a?B.colors.onPrimary:e.inMonth?t?B.colors.text.disabled:B.colors.text.primary:B.colors.text.tertiary,n=t?.3:e.inMonth?1:.4;return _jsx(Pressable,{disabled:t,onPress:()=>je(e),accessibilityRole:"button",accessibilityLabel:formatLongDate(e.date,l),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:N.dayCell,children:_jsx(Animated.View,{style:[N.dayInner,{backgroundColor:i,borderColor:o,borderWidth:r&&!a?1.5:0,opacity:n},a?{transform:[{scale:re}]}:null],children:_jsx(Text,{style:[N.dayText,{color:s}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):_jsx(Animated.View,"years"===Z?{style:[N.yearGrid,{opacity:ie,transform:[{scale:oe}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:N.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=he(e),a=!!q&&q.getFullYear()===e,r=H.getFullYear()===e,i=a?B.colors.primary:"transparent",o=r&&!a?B.colors.primary:"transparent",s=a?B.colors.onPrimary:t?B.colors.text.disabled:B.colors.text.primary,n=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:N.yearCell,children:_jsx(View,{style:[N.yearInner,{backgroundColor:i,borderColor:o,borderWidth:r&&!a?1.5:0,opacity:n}],children:_jsx(Text,{style:[N.yearText,{color:s}],children:e})})},`year-${e}`)})},`yr-${t}`))}:{style:[N.yearGrid,{opacity:ie,transform:[{scale:oe}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:N.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=fe(e),r=!!q&&decadeStartFor(q.getFullYear())===e,i=decadeStartFor(H.getFullYear())===e,o=r?B.colors.primary:"transparent",s=i&&!r?B.colors.primary:"transparent",n=r?B.colors.onPrimary:a?B.colors.text.disabled:B.colors.text.primary,l=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Se(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:N.yearCell,children:_jsxs(View,{style:[N.yearInner,{backgroundColor:o,borderColor:s,borderWidth:i&&!r?1.5:0,opacity:l}],children:[_jsx(Text,{style:[N.yearText,{color:n}],children:`${e}s`}),_jsx(Text,{style:[N.decadeRangeText,{color:r?B.colors.onPrimary:B.colors.text.tertiary}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),_jsxs(View,{style:N.footer,children:[_jsx(Pressable,{onPress:Me,style:({pressed:e})=>[N.footerBtn,N.footerCancel,e&&N.footerBtnPressed,f],accessibilityRole:"button",accessibilityLabel:m,children:_jsx(Text,{style:[N.footerBtnText,{color:B.colors.text.secondary}],children:m})}),_jsx(Pressable,{onPress:Ie,disabled:!q,style:({pressed:e})=>[N.footerBtn,N.footerConfirm,{backgroundColor:B.colors.primary,opacity:q?1:.5},e&&{backgroundColor:B.colors.primaryHover},f],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!q},"aria-disabled":!q,children:_jsx(Text,{style:[N.footerBtnText,{color:B.colors.onPrimary}],children:u})})]})]}),Ye=t?(R??(e=>e.toLocaleDateString()))(t):void 0,$e=!_;if("inline"===n)return F||$e?$e?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:D,value:Ye,placeholder:v,helperText:w,error:C,required:S,disabled:j,size:k,variant:P,clearable:A,onClear:T,onPress:()=>I(!0),triggerStyle:V,testID:x}),F?Be:null]}):Be:null;const ze=_jsx(Modal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Pe,children:_jsx(ModalSafeArea,{onInsets:z,children:_jsxs(AnimatedGestureRoot,{collapsable:!1,style:[N.backdrop,{backgroundColor:Ve}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Pe,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[N.sheetWrap,{paddingBottom:Math.max($.bottom,B.spacing.lg),opacity:Re,transform:[{translateY:Animated.add(Fe,U)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Be}),_jsx(ToastHost,{})]})})});return $e?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:D,value:Ye,placeholder:v,helperText:w,error:C,required:S,disabled:j,size:k,variant:P,clearable:A,onClear:T,onPress:()=>I(!0),triggerStyle:V,testID:x}),ze]}):ze},buildStyles=e=>{const t=e.shadows.lg;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.spacing.md,paddingBottom:e.spacing.lg},card:{backgroundColor:e.colors.background.elevated,borderRadius:e.radius.xl,...smoothCorners,padding:e.spacing.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.spacing.lg,paddingTop:e.spacing.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.full,...smoothCorners,backgroundColor:e.colors.border.secondary,marginBottom:e.spacing.sm},titleRow:{marginBottom:e.spacing.sm},title:{fontSize:e.typography.fontSize.lg,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.spacing.md},navBtn:{width:e.components.datePicker?.navButtonSize??36,height:e.components.datePicker?.navButtonSize??36,borderRadius:e.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors.background.secondary},navBtnPressed:{backgroundColor:e.colors.surface.pressed},navText:{fontSize:e.components.datePicker?.navTextFontSize??22,lineHeight:e.components.datePicker?.navTextLineHeight??24,color:e.colors.text.primary,fontWeight:e.typography.fontWeight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.typography.fontSize.base,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},headerCaret:{marginLeft:e.spacing.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.spacing.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.spacing.xs},weekdayText:{fontSize:e.typography.fontSize.xs,fontWeight:e.typography.fontWeight.medium,color:e.colors.text.tertiary,letterSpacing:e.typography.letterSpacing.wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.components.datePicker?.dayCellPadding??2},dayInner:{width:"100%",height:"100%",borderRadius:e.components.datePicker?.dayInnerBorderRadius??e.radius.full,...smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.components.datePicker?.yearCellPadding??4},yearInner:{width:"100%",height:"100%",borderRadius:e.components.datePicker?.yearInnerBorderRadius??e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.typography.fontSize.base,fontWeight:e.typography.fontWeight.semibold},decadeRangeText:{fontSize:e.typography.fontSize.xs,fontWeight:e.typography.fontWeight.medium,marginTop:e.components.datePicker?.decadeRangeMarginTop??2},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.spacing.lg,gap:e.spacing.sm},footerBtn:{paddingHorizontal:e.spacing.lg,paddingVertical:e.spacing.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:e.components.datePicker?.footerButtonMinHeight??40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.semibold}})};export{DatePicker};export default DatePicker;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Calendar}from"../Calendar/index.js";import{daysBetween,startOfDay,startOfMonth}from"../Calendar/calendarDates.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=forwardRef((e,t)=>{const{visible:a,value:r,onChange:s,onClose:o,label:i,placeholder:n,helperText:l,error:d,required:c,disabled:g,size:m,variant:u,clearable:f,onClear:p,formatValue:h,triggerStyle:y,minDate:b,maxDate:x,disabledDates:D,markedDates:S,strikeMarkedInRange:v,locale:R="en-IN",weekStartsOn:j=0,title:C="Select Date Range",confirmLabel:k="Confirm",cancelLabel:w="Cancel",maxRange:T,haptic:P,style:_,containerStyle:V,headerLabelStyle:M,navButtonStyle:B,footerButtonStyle:A,testID:I}=e,O=void 0!==a,[H,z]=useState(!1),L=O?a:H,E=O?I:I?`${I}-calendar`:void 0,N=useTheme(),[W,$]=useModalInsets(),F=useMemo(()=>buildStyles(N),[N]),[G,q]=useState(()=>startOfMonth(r.start??new Date)),[Y,J]=useState(r.start?startOfDay(r.start):null),[K,Q]=useState(r.end?startOfDay(r.end):null),U=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,Z=useRef(createAnimatedValue(0)).current,ee=useRef(0);useEffect(()=>{if(r.start){const e=startOfDay(r.start);J(e),q(startOfMonth(e))}else J(null);r.end?Q(startOfDay(r.end)):Q(null)},[r.start,r.end]),useEffect(()=>{let e;return L&&(U.setValue(0),setNativeValue(X,0),setNativeValue(Z,0),e=Animated.parallel([Animated.timing(U,{toValue:1,duration:N.motion.duration.normal,easing:Easing.out(Easing.cubic),useNativeDriver:!1}),Animated.spring(X,{toValue:1,damping:N.motion.spring.gentle.damping,stiffness:N.motion.spring.gentle.stiffness,mass:N.motion.spring.gentle.mass,useNativeDriver:!0})]),e.start()),()=>e?.stop()},[L,U,X,Z,N.motion]);const te=useCallback(e=>{if(e.end&&T&&daysBetween(e.start,e.end)+1>T)return!1!==P&&triggerHaptic("notificationWarning"),J(e.end),void Q(null);J(e.start),Q(e.end??null)},[T,P]),ae=useCallback(()=>{O?o?.():z(!1)},[O,o]),re=useCallback(()=>{Animated.parallel([Animated.timing(U,{toValue:0,duration:N.motion.duration.fast,easing:Easing.bezier(...N.motion.easing.accelerate),useNativeDriver:!1}),Animated.timing(X,{toValue:0,duration:N.motion.duration.fast,easing:Easing.bezier(...N.motion.easing.accelerate),useNativeDriver:!0})]).start(()=>{ae()})},[U,ae,X,N.motion.duration.fast,N.motion.easing.accelerate]),{handleGesture:se}=useDragToDismiss({drag:Z,travel:()=>ee.current||320,onDismiss:re}),oe=useCallback(()=>{!1!==P&&triggerHaptic("selection"),re()},[re,P]),ie=useCallback(()=>{Y&&K&&(!1!==P&&triggerHaptic("notificationSuccess"),s?.({start:Y,end:K}),re())},[re,s,Y,K,P]),ne=X.interpolate({inputRange:[0,1],outputRange:[320,0]}),le=useMemo(()=>Y&&K?`${formatRangePart(Y,R)} — ${formatRangePart(K,R)}`:Y?`${formatRangePart(Y,R)} — …`:"—",[Y,K,R]),de=!Y||!K,ce=_jsxs(View,{style:[F.card,_,V],ref:t,accessible:!1,testID:E,children:[_jsx(GestureDetector,{gesture:se,children:_jsxs(View,{style:F.grabArea,children:[_jsx(View,{style:F.handle}),_jsxs(View,{style:F.titleRow,children:[_jsx(Text,{style:F.title,accessibilityRole:"header",children:C}),_jsx(Text,{style:F.subtitle,accessibilityLiveRegion:"polite",children:le})]})]})}),_jsx(Calendar,{mode:"range",value:Y?{start:Y,end:K??void 0}:null,onChange:te,month:G,onMonthChange:q,minDate:b,maxDate:x,disabledDates:D,markedDates:S,strikeMarkedInRange:v,weekStartsOn:j,locale:R,haptic:P,headerLabelStyle:M,navButtonStyle:B,testID:E?`${E}-grid`:void 0}),_jsxs(View,{style:F.footer,children:[_jsx(Pressable,{onPress:oe,style:({pressed:e})=>[F.footerBtn,F.footerCancel,e&&F.footerBtnPressed,A],accessibilityRole:"button",accessibilityLabel:w,children:_jsx(Text,{style:[F.footerBtnText,{color:N.colors.text.secondary}],children:w})}),_jsx(Pressable,{onPress:ie,disabled:de,style:({pressed:e})=>[F.footerBtn,F.footerConfirm,{backgroundColor:N.colors.primary,opacity:de?.5:1},e&&{backgroundColor:N.colors.primaryHover},A],accessibilityRole:"button",accessibilityLabel:k,accessibilityState:{disabled:de},"aria-disabled":de,children:_jsx(Text,{style:[F.footerBtnText,{color:N.colors.onPrimary}],children:k})})]})]}),ge=useMemo(()=>{if(!r.start||!r.end)return"";const e={start:r.start,end:r.end};return h?h(e):`${e.start.toLocaleDateString()} – ${e.end.toLocaleDateString()}`},[r.start,r.end,h]);return _jsxs(_Fragment,{children:[O?null:_jsx(PickerTrigger,{label:i,placeholder:n,helperText:l,error:d,required:c,disabled:g,size:m,variant:u,clearable:f,onClear:p,value:ge,onPress:()=>z(!0),triggerStyle:y,testID:I}),_jsx(Modal,{visible:L,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:re,children:_jsx(ModalSafeArea,{onInsets:$,children:_jsxs(GestureHandlerRootView,{collapsable:!1,style:[F.backdrop,{backgroundColor:N.colors.background.overlay}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:re,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[F.sheetWrap,{paddingBottom:Math.max(W.bottom,N.spacing.lg),opacity:X,transform:[{translateY:Animated.add(ne,Z)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:ce}),_jsx(ToastHost,{})]})})})]})});DateRangePicker.displayName="DateRangePicker";const buildStyles=e=>{const t=e.shadows.lg;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.spacing.md,paddingBottom:e.spacing.lg},card:{backgroundColor:e.colors.background.elevated,borderRadius:e.radius.xl,...smoothCorners,padding:e.spacing.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.spacing.lg,paddingTop:e.spacing.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.full,...smoothCorners,backgroundColor:e.colors.border.secondary,marginBottom:e.spacing.sm},titleRow:{marginBottom:e.spacing.sm},title:{fontSize:e.typography.fontSize.lg,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},subtitle:{marginTop:e.spacing.xxs,fontSize:e.typography.fontSize.sm,color:e.colors.text.secondary},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.spacing.lg,gap:e.spacing.sm},footerBtn:{paddingHorizontal:e.spacing.lg,paddingVertical:e.spacing.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:e.components.dateRangePicker?.footerButtonMinHeight??40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.semibold}})};export{DateRangePicker};export default DateRangePicker;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Calendar}from"../Calendar/index.js";import{daysBetween,startOfDay,startOfMonth}from"../Calendar/calendarDates.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const AnimatedGestureRoot=Animated.createAnimatedComponent(GestureHandlerRootView),transparentOf=e=>{const t=e.match(/^rgba?\(([^)]+)\)$/);if(!t)return"transparent";const[a,r,s]=t[1].split(",").map(e=>e.trim());return`rgba(${a}, ${r}, ${s}, 0)`},formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=forwardRef((e,t)=>{const{visible:a,value:r,onChange:s,onClose:o,label:n,placeholder:i,helperText:l,error:d,required:c,disabled:u,size:m,variant:g,clearable:p,onClear:f,formatValue:h,triggerStyle:y,minDate:b,maxDate:x,disabledDates:D,markedDates:v,strikeMarkedInRange:R,locale:S="en-IN",weekStartsOn:j=0,title:k="Select Date Range",confirmLabel:C="Confirm",cancelLabel:w="Cancel",maxRange:T,haptic:P,style:M,containerStyle:V,headerLabelStyle:A,navButtonStyle:_,footerButtonStyle:B,testID:O}=e,I=void 0!==a,[H,z]=useState(!1),L=I?a:H,N=I?O:O?`${O}-calendar`:void 0,$=useTheme(),E=usePresenceMotion(),[G,W]=useModalInsets(),F=useMemo(()=>buildStyles($),[$]),[q,Y]=useState(()=>startOfMonth(r.start??new Date)),[J,K]=useState(r.start?startOfDay(r.start):null),[Q,U]=useState(r.end?startOfDay(r.end):null),X=useRef(createAnimatedValue(0)).current,Z=useRef(createAnimatedValue(0)).current,ee=useRef(createAnimatedValue(0)).current,te=useRef(0);useEffect(()=>{if(r.start){const e=startOfDay(r.start);K(e),Y(startOfMonth(e))}else K(null);r.end?U(startOfDay(r.end)):U(null)},[r.start,r.end]);const ae=useCallback(e=>{if(e.end&&T&&daysBetween(e.start,e.end)+1>T)return!1!==P&&triggerHaptic("notificationWarning"),K(e.end),void U(null);K(e.start),U(e.end??null)},[T,P]),re=useCallback(()=>{I?o?.():z(!1)},[I,o]),se=useCallback(()=>{Animated.parallel([Animated.timing(X,{toValue:0,duration:E.duration("normal"),easing:Easing.bezier(...$.motion.easing.accelerate),useNativeDriver:!1}),Animated.timing(Z,{toValue:0,duration:E.duration("fast"),easing:Easing.bezier(...$.motion.easing.accelerate),useNativeDriver:!0})]).start(()=>{re()})},[X,re,E,Z,$.motion.easing.accelerate]),{handleGesture:oe,opacity:ne}=useDragToDismiss({drag:ee,travel:()=>te.current||320,onDismiss:se}),ie=useMemo(()=>Animated.multiply(Z,ne),[Z,ne]),le=useMemo(()=>X.interpolate({inputRange:[0,1],outputRange:[transparentOf($.colors.background.overlay),$.colors.background.overlay]}),[X,$.colors.background.overlay]);useEffect(()=>{let e;if(L){X.setValue(0),setNativeValue(Z,0),setNativeValue(ee,0),setNativeValue(ne,1);const t=E.reduced?Animated.timing(Z,{toValue:1,duration:E.duration("normal"),useNativeDriver:!0}):Animated.spring(Z,{toValue:1,damping:$.motion.spring.gentle.damping,stiffness:$.motion.spring.gentle.stiffness,mass:$.motion.spring.gentle.mass,useNativeDriver:!0});e=Animated.parallel([Animated.timing(X,{toValue:1,duration:E.duration("normal"),easing:Easing.out(Easing.cubic),useNativeDriver:!1}),t]),e.start()}return()=>e?.stop()},[L,X,E,Z,ee,ne,$.motion]);const de=useCallback(()=>{!1!==P&&triggerHaptic("selection"),se()},[se,P]),ce=useCallback(()=>{J&&Q&&(!1!==P&&triggerHaptic("notificationSuccess"),s?.({start:J,end:Q}),se())},[se,s,J,Q,P]),ue=Z.interpolate({inputRange:[0,1],outputRange:E.range(320,0)}),me=useMemo(()=>J&&Q?`${formatRangePart(J,S)} — ${formatRangePart(Q,S)}`:J?`${formatRangePart(J,S)} — …`:"—",[J,Q,S]),ge=!J||!Q,pe=_jsxs(View,{style:[F.card,M,V],ref:t,accessible:!1,testID:N,children:[_jsx(GestureDetector,{gesture:oe,children:_jsxs(View,{style:F.grabArea,children:[_jsx(View,{style:F.handle}),_jsxs(View,{style:F.titleRow,children:[_jsx(Text,{style:F.title,accessibilityRole:"header",children:k}),_jsx(Text,{style:F.subtitle,accessibilityLiveRegion:"polite",children:me})]})]})}),_jsx(Calendar,{mode:"range",value:J?{start:J,end:Q??void 0}:null,onChange:ae,month:q,onMonthChange:Y,minDate:b,maxDate:x,disabledDates:D,markedDates:v,strikeMarkedInRange:R,weekStartsOn:j,locale:S,haptic:P,headerLabelStyle:A,navButtonStyle:_,testID:N?`${N}-grid`:void 0}),_jsxs(View,{style:F.footer,children:[_jsx(Pressable,{onPress:de,style:({pressed:e})=>[F.footerBtn,F.footerCancel,e&&F.footerBtnPressed,B],accessibilityRole:"button",accessibilityLabel:w,children:_jsx(Text,{style:[F.footerBtnText,{color:$.colors.text.secondary}],children:w})}),_jsx(Pressable,{onPress:ce,disabled:ge,style:({pressed:e})=>[F.footerBtn,F.footerConfirm,{backgroundColor:$.colors.primary,opacity:ge?.5:1},e&&{backgroundColor:$.colors.primaryHover},B],accessibilityRole:"button",accessibilityLabel:C,accessibilityState:{disabled:ge},"aria-disabled":ge,children:_jsx(Text,{style:[F.footerBtnText,{color:$.colors.onPrimary}],children:C})})]})]}),fe=useMemo(()=>{if(!r.start||!r.end)return"";const e={start:r.start,end:r.end};return h?h(e):`${e.start.toLocaleDateString()} – ${e.end.toLocaleDateString()}`},[r.start,r.end,h]);return _jsxs(_Fragment,{children:[I?null:_jsx(PickerTrigger,{label:n,placeholder:i,helperText:l,error:d,required:c,disabled:u,size:m,variant:g,clearable:p,onClear:f,value:fe,onPress:()=>z(!0),triggerStyle:y,testID:O}),_jsx(Modal,{visible:L,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:se,children:_jsx(ModalSafeArea,{onInsets:W,children:_jsxs(AnimatedGestureRoot,{collapsable:!1,style:[F.backdrop,{backgroundColor:le}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:se,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[F.sheetWrap,{paddingBottom:Math.max(G.bottom,$.spacing.lg),opacity:ie,transform:[{translateY:Animated.add(ue,ee)}]}],onLayout:e=>{te.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:pe}),_jsx(ToastHost,{})]})})})]})});DateRangePicker.displayName="DateRangePicker";const buildStyles=e=>{const t=e.shadows.lg;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.spacing.md,paddingBottom:e.spacing.lg},card:{backgroundColor:e.colors.background.elevated,borderRadius:e.radius.xl,...smoothCorners,padding:e.spacing.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.spacing.lg,paddingTop:e.spacing.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.full,...smoothCorners,backgroundColor:e.colors.border.secondary,marginBottom:e.spacing.sm},titleRow:{marginBottom:e.spacing.sm},title:{fontSize:e.typography.fontSize.lg,fontWeight:e.typography.fontWeight.semibold,color:e.colors.text.primary},subtitle:{marginTop:e.spacing.xxs,fontSize:e.typography.fontSize.sm,color:e.colors.text.secondary},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.spacing.lg,gap:e.spacing.sm},footerBtn:{paddingHorizontal:e.spacing.lg,paddingVertical:e.spacing.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:e.components.dateRangePicker?.footerButtonMinHeight??40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.semibold}})};export{DateRangePicker};export default DateRangePicker;