@webority/mobile-ui 0.156.0 → 0.158.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/canvas-kit.json +1 -1
  2. package/dist/canvas-kit/kit.js +5 -5
  3. package/dist/canvas-kit/manifest.json +17 -12
  4. package/dist/canvas-kit/release.json +7 -7
  5. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  6. package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
  7. package/lib/commonjs/components/AppIcon/index.js +1 -1
  8. package/lib/commonjs/components/Banner/Banner.js +1 -1
  9. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  10. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  11. package/lib/commonjs/components/Button/Button.js +1 -1
  12. package/lib/commonjs/components/Button/index.js +1 -1
  13. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  14. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  15. package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
  16. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  17. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  18. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  19. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  20. package/lib/commonjs/components/MessageList/MessageList.js +1 -1
  21. package/lib/commonjs/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
  22. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  23. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  24. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  25. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  26. package/lib/commonjs/components/Radio/Radio.js +1 -1
  27. package/lib/commonjs/components/Radio/RadioGroup.js +1 -1
  28. package/lib/commonjs/components/Rating/Rating.js +1 -1
  29. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  30. package/lib/commonjs/components/SearchBar/useRecentSearches.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/SkeletonList.js +1 -1
  34. package/lib/commonjs/components/Slider/valueText.js +1 -1
  35. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  36. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  37. package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
  38. package/lib/commonjs/components/Toast/Toast.js +1 -1
  39. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  40. package/lib/commonjs/hooks/useControllableState.js +1 -1
  41. package/lib/commonjs/icons.js +1 -1
  42. package/lib/commonjs/index.js +1 -1
  43. package/lib/module/components/AppBar/AppBar.js +1 -1
  44. package/lib/module/components/AppIcon/AppIcon.js +1 -1
  45. package/lib/module/components/AppIcon/index.js +1 -1
  46. package/lib/module/components/Banner/Banner.js +1 -1
  47. package/lib/module/components/BarChart/BarChart.js +1 -1
  48. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  49. package/lib/module/components/Button/Button.js +1 -1
  50. package/lib/module/components/Button/index.js +1 -1
  51. package/lib/module/components/Carousel/Carousel.js +1 -1
  52. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  53. package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
  54. package/lib/module/components/Confetti/Confetti.js +1 -1
  55. package/lib/module/components/Drawer/Drawer.js +1 -1
  56. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  57. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  58. package/lib/module/components/MessageList/MessageList.js +1 -1
  59. package/lib/module/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
  60. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  61. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  62. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  63. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  64. package/lib/module/components/Radio/Radio.js +1 -1
  65. package/lib/module/components/Radio/RadioGroup.js +1 -1
  66. package/lib/module/components/Rating/Rating.js +1 -1
  67. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  68. package/lib/module/components/SearchBar/useRecentSearches.js +1 -1
  69. package/lib/module/components/Skeleton/Skeleton.js +1 -1
  70. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  71. package/lib/module/components/Skeleton/SkeletonList.js +1 -1
  72. package/lib/module/components/Slider/valueText.js +1 -1
  73. package/lib/module/components/Stepper/Stepper.js +1 -1
  74. package/lib/module/components/TagInput/TagInput.js +1 -1
  75. package/lib/module/components/TimePicker/TimePicker.js +1 -1
  76. package/lib/module/components/Toast/Toast.js +1 -1
  77. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  78. package/lib/module/hooks/useControllableState.js +1 -1
  79. package/lib/module/icons.js +1 -1
  80. package/lib/module/index.js +1 -1
  81. package/lib/typescript/commonjs/components/AppIcon/AppIcon.d.ts +2 -0
  82. package/lib/typescript/commonjs/components/AppIcon/index.d.ts +1 -1
  83. package/lib/typescript/commonjs/components/Button/Button.d.ts +4 -0
  84. package/lib/typescript/commonjs/components/Button/index.d.ts +1 -1
  85. package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +7 -4
  86. package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +14 -6
  87. package/lib/typescript/commonjs/components/FieldBase/ChoiceText.d.ts +6 -5
  88. package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +2 -2
  89. package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +15 -9
  90. package/lib/typescript/commonjs/components/Radio/Radio.d.ts +7 -4
  91. package/lib/typescript/commonjs/components/Radio/RadioGroup.d.ts +5 -0
  92. package/lib/typescript/commonjs/components/Switch/Switch.d.ts +4 -4
  93. package/lib/typescript/commonjs/hooks/useControllableState.d.ts +23 -8
  94. package/lib/typescript/commonjs/icons.d.ts +1 -1
  95. package/lib/typescript/commonjs/index.d.ts +2 -1
  96. package/lib/typescript/module/components/AppIcon/AppIcon.d.ts +2 -0
  97. package/lib/typescript/module/components/AppIcon/index.d.ts +1 -1
  98. package/lib/typescript/module/components/Button/Button.d.ts +4 -0
  99. package/lib/typescript/module/components/Button/index.d.ts +1 -1
  100. package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +7 -4
  101. package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +14 -6
  102. package/lib/typescript/module/components/FieldBase/ChoiceText.d.ts +6 -5
  103. package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +2 -2
  104. package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +15 -9
  105. package/lib/typescript/module/components/Radio/Radio.d.ts +7 -4
  106. package/lib/typescript/module/components/Radio/RadioGroup.d.ts +5 -0
  107. package/lib/typescript/module/components/Switch/Switch.d.ts +4 -4
  108. package/lib/typescript/module/hooks/useControllableState.d.ts +23 -8
  109. package/lib/typescript/module/icons.d.ts +1 -1
  110. package/lib/typescript/module/index.d.ts +2 -1
  111. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import{Fragment,forwardRef,useCallback,useMemo,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{Menu}from"../Menu/index.js";import{Text as ThemedText}from"../Text/Text.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const ACTION_BUTTON_SIZE=44,DOT_OFFSET=10,DOT_SIZE=8,BADGE_OFFSET=4;export const DEFAULT_APP_BAR_LABELS=Object.freeze({back:"Back"});const variantSize=(e,t)=>{switch(t){case"compact":return{height:44,titleSize:e.text.lg.size,titleWeight:"semibold",subtitleLines:1};case"large":return{height:56,titleSize:e.text["2xl"].size,titleWeight:"bold",subtitleLines:2};default:return{height:56,titleSize:e.text.lg.size,titleWeight:"semibold",subtitleLines:1}}},ActionButton=forwardRef(({action:e,side:t,badgeStyle:i,haptic:n,flush:l,onPress:o},s)=>{const r=useTheme(),{style:a,pressIn:c,pressOut:d}=usePressAnimation({enabled:!0}),u=useMemo(()=>buildActionStyles(r),[r]),p=e.badge,h=void 0!==p&&0!==p,g=void 0!==e.label;return _jsx(Animated.View,{style:a,children:_jsxs(Pressable,{ref:s,onPress:t=>{const i=resolveHaptic(n,"selection");i&&triggerHaptic(i),"onPress"in e&&e.onPress(),o?.(t)},onPressIn:c,onPressOut:d,accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,android_ripple:{color:r.colors["surface-pressed"],borderless:!g},style:({pressed:e})=>[g?u.textButton:u.actionButton,l?null:"left"===t?u.actionLeft:u.actionRight,e&&!g?u.actionPressed:null,e&&g?u.textPressed:null],children:[g?_jsx(ThemedText,{variant:"body",weight:"semibold",color:"link",numberOfLines:1,children:e.label}):_jsx(View,{style:u.iconWrap,children:e.icon}),h?_jsx(View,{style:[u.badge,i],pointerEvents:"none",children:_jsx(ThemedText,{variant:"caption",weight:"semibold",numberOfLines:1,style:u.badgeText,children:String(p)})}):null,e.dot?_jsx(View,{testID:e.testID?`${e.testID}-dot`:"appbar-action-dot",style:u.dot,pointerEvents:"none"}):null]})})}),COLLAPSE_RANGE=60,AppBar=forwardRef((e,t)=>{const{title:i,subtitle:n,titleAlignment:l="left",leftAction:o,rightActions:s,leading:r,trailing:a,onBack:c,gutter:d,titleVariant:u,titleOffset:p,height:h,divider:g,elevated:m=!1,variant:x="default",transparent:f=!1,scrollY:b,style:y,containerStyle:A,titleStyle:S,subtitleStyle:j,badgeStyle:_,haptic:w,labels:v,testID:T}=e;assertValidValue("AppBar","variant",e.variant,["default","large","compact"]),assertValidValue("AppBar","titleAlignment",e.titleAlignment,["left","center"]);const B=useMemo(()=>({...DEFAULT_APP_BAR_LABELS,...v}),[v]),I=useTheme(),L=useSafeAreaInsets(),R=useMemo(()=>variantSize(I,x),[I,x]),V=useMemo(()=>buildStyles(I),[I]),C="large"===x,z=C&&void 0!==b,[P,O]=useState(40),D=useCallback(e=>O(e.nativeEvent.layout.height),[]),W=o??(c?{icon:_jsx(AppIcon,{name:"arrow-left",size:24,color:I.colors["text-body"]}),onPress:c,accessibilityLabel:B.back}:void 0),E=a?void 0:s?.[s.length-1],opticalInset=e=>void 0===e?0:void 0!==e.label?I.space.sm:Math.max((44-(e.glyphSize??24))/2,0),k=void 0===d?null:{paddingLeft:Math.max(d-opticalInset(W),0),paddingRight:Math.max(d-opticalInset(E),0)},H=void 0!==p,M=Boolean(W)||Boolean(r),F=!H&&"left"===l&&Boolean(W),N=H||F||!M&&"left"===l,$="default"!==x||M?R.titleSize:I.text.xl.size,U=g??!1,G=StyleSheet.hairlineWidth,Z=useMemo(()=>{if(!b)return null;const e=b;return{rootHeight:e.interpolate({inputRange:[0,60],outputRange:[L.top+R.height+P,L.top+R.height],extrapolate:"clamp"}),titleRowOpacity:e.interpolate({inputRange:[0,30],outputRange:[1,0],extrapolate:"clamp"}),compactTitleOpacity:e.interpolate({inputRange:[30,60],outputRange:[0,1],extrapolate:"clamp"}),borderOpacity:e.interpolate({inputRange:[0,60],outputRange:[0,1],extrapolate:"clamp"})}},[b,L.top,R.height,P]),Y=i?u?_jsx(ThemedText,{variant:u,align:"center"===l?"center":"left",accessibilityRole:"header",numberOfLines:1,style:[V.titleVariant,S],children:i}):_jsx(Animated.Text,{accessibilityRole:"header",style:[V.title,{fontSize:$,fontWeight:I.weight[R.titleWeight],textAlign:"center"===l?"center":"left"},n?V.stackedText:null,S],numberOfLines:1,children:i}):null,q=z&&Z&&i?_jsx(Animated.Text,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[V.title,{fontSize:I.text.lg.size,fontWeight:I.weight.semibold,textAlign:"center"===l?"center":"left",opacity:Z.compactTitleOpacity}],numberOfLines:1,children:i}):null,J=n?_jsx(Animated.Text,{style:[V.subtitle,{textAlign:"center"===l?"center":"left"},j],numberOfLines:R.subtitleLines,children:n}):null,K=_jsxs(View,{style:[V.titleColumn,"center"===l?V.titleColumnCenter:null],children:[Y,J]}),Q=z?Animated.View:View,X=z&&Z?{height:Z.rootHeight,overflow:"hidden"}:C&&void 0===h?null:{height:(h??R.height)+L.top};return _jsxs(Q,{ref:t,testID:T,style:[V.root,{paddingTop:L.top,backgroundColor:f?"transparent":I.colors.surface},X,!z&&U?{borderBottomWidth:G,borderBottomColor:I.colors.border}:null,m&&!f?I.shadow.card:null,A,y],children:[z&&Z&&U?_jsx(Animated.View,{pointerEvents:"none",style:[V.animatedBorder,{backgroundColor:I.colors.border,opacity:Z.borderOpacity}]}):null,_jsxs(View,{testID:C&&T?`${T}-bar-row`:void 0,style:[V.row,C?{height:R.height}:{flex:1},k],children:[_jsxs(View,{testID:T?`${T}-leading-slot`:void 0,style:[V.sideSlot,N?V.sideSlotCompact:null],children:[W?_jsx(ActionButton,{action:W,side:"left",haptic:w,flush:H||F}):null,null!=r&&!1!==r?_jsx(View,{style:V.slotNode,children:r}):null]}),_jsx(View,{pointerEvents:"none",style:[V.center,"center"===l?V.centerAligned:V.centerLeft,H?{paddingLeft:M?p:I.space.none,paddingRight:I.space.none}:N?{paddingLeft:I.space.none}:null],children:C?q:K}),_jsxs(View,{style:[V.sideSlot,V.sideSlotRight,H?V.sideSlotCompact:null],children:[s?.map((e,t)=>_jsx(Fragment,{children:"menu"in e?_jsx(Menu,{items:e.menu,title:e.menuTitle,haptic:w,trigger:_jsx(ActionButton,{action:e,side:"right",badgeStyle:_,haptic:w,flush:H})}):_jsx(ActionButton,{action:e,side:"right",badgeStyle:_,haptic:w,flush:H})},`appbar-right-${t}`)),null!=a&&!1!==a?_jsx(View,{style:V.slotNode,children:a}):null]})]}),C?_jsx(Animated.View,{testID:T?`${T}-title-row`:void 0,onLayout:z?D:void 0,pointerEvents:"none",style:[{paddingHorizontal:d??I.space.md,paddingBottom:I.space.sm},z&&Z?{opacity:Z.titleRowOpacity}:null],children:K}):null]})});AppBar.displayName="AppBar";const buildStyles=e=>StyleSheet.create({root:{width:"100%"},row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.xs},sideSlot:{flexDirection:"row",alignItems:"center",minWidth:48},sideSlotRight:{justifyContent:"flex-end"},sideSlotCompact:{minWidth:0},slotNode:{flexDirection:"row",alignItems:"center"},center:{flex:1,minWidth:0,paddingHorizontal:e.space.xs},centerAligned:{alignItems:"center"},centerLeft:{alignItems:"flex-start"},titleColumn:{flexDirection:"column",maxWidth:"100%"},titleColumnCenter:{alignItems:"center"},title:{color:e.colors["text-body"]},titleVariant:{includeFontPadding:!1,textAlignVertical:"center"},stackedText:{includeFontPadding:!1},subtitle:{includeFontPadding:!1,color:e.colors["text-subtle"],fontSize:e.text.sm.size,fontWeight:e.weight.normal},animatedBorder:{position:"absolute",left:0,right:0,bottom:0,height:StyleSheet.hairlineWidth}}),buildActionStyles=e=>StyleSheet.create({actionButton:{width:44,height:44,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},actionLeft:{marginRight:e.space.xs},actionRight:{marginLeft:e.space.xs},actionPressed:{backgroundColor:e.colors["surface-pressed"]},textButton:{minWidth:44,minHeight:44,paddingHorizontal:e.space.sm,alignItems:"center",justifyContent:"center"},textPressed:{opacity:.6},dot:{position:"absolute",top:10,right:10,width:8,height:8,borderRadius:e.radius.pill,backgroundColor:e.colors.danger},iconWrap:{alignItems:"center",justifyContent:"center"},badge:{position:"absolute",top:4,right:4,minWidth:16,height:16,paddingHorizontal:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.danger,alignItems:"center",justifyContent:"center"},badgeText:{color:e.colors["on-danger"],fontSize:e.text.xs.size,fontWeight:e.weight.semibold,lineHeight:Math.round(e.text.xs.size*e.leading.heading)}});export{AppBar};export default AppBar;
1
+ "use strict";import{Fragment,forwardRef,useCallback,useMemo,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{Menu}from"../Menu/index.js";import{Text as ThemedText}from"../Text/Text.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const ACTION_BUTTON_SIZE=44,DOT_OFFSET=10,DOT_SIZE=8,BADGE_OFFSET=4;export const DEFAULT_APP_BAR_LABELS=Object.freeze({back:"Back"});const variantSize=(e,t)=>{switch(t){case"compact":return{height:44,titleSize:e.text.lg.size,titleWeight:"semibold",subtitleLines:1};case"large":return{height:56,titleSize:e.text["2xl"].size,titleWeight:"bold",subtitleLines:2};default:return{height:56,titleSize:e.text.lg.size,titleWeight:"semibold",subtitleLines:1}}},ActionButton=forwardRef(({action:e,side:t,badgeStyle:i,haptic:n,flush:o,onPress:l},s)=>{const r=useTheme(),{style:a,pressIn:c,pressOut:d}=usePressAnimation({enabled:!0}),u=useMemo(()=>buildActionStyles(r),[r]),p=e.badge,h=void 0!==p&&0!==p,g=void 0!==e.label;return _jsx(Animated.View,{style:a,children:_jsxs(Pressable,{ref:s,onPress:t=>{const i=resolveHaptic(n,"selection");i&&triggerHaptic(i),"onPress"in e&&e.onPress(),l?.(t)},onPressIn:c,onPressOut:d,accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,android_ripple:{color:r.colors["surface-pressed"],borderless:!g},style:({pressed:e})=>[g?u.textButton:u.actionButton,o?null:"left"===t?u.actionLeft:u.actionRight,e&&!g?u.actionPressed:null,e&&g?u.textPressed:null],children:[g?_jsx(ThemedText,{variant:"body",weight:"semibold",color:"link",numberOfLines:1,children:e.label}):_jsx(View,{style:u.iconWrap,children:e.icon}),h?_jsx(View,{style:[u.badge,i],pointerEvents:"none",children:_jsx(ThemedText,{variant:"caption",weight:"semibold",numberOfLines:1,style:u.badgeText,children:String(p)})}):null,e.dot?_jsx(View,{testID:e.testID?`${e.testID}-dot`:"appbar-action-dot",style:u.dot,pointerEvents:"none"}):null]})})}),COLLAPSE_RANGE=60,AppBar=forwardRef((e,t)=>{const{title:i,subtitle:n,titleAlignment:o="left",leftAction:l,rightActions:s,leading:r,trailing:a,onBack:c,gutter:d,titleVariant:u,titleOffset:p,height:h,divider:g,elevated:m=!1,variant:x="default",transparent:f=!1,scrollY:b,style:y,containerStyle:A,titleStyle:S,subtitleStyle:j,badgeStyle:_,haptic:w,labels:v,testID:T}=e;assertValidValue("AppBar","variant",e.variant,["default","large","compact"]),assertValidValue("AppBar","titleAlignment",e.titleAlignment,["left","center"]);const B=useMemo(()=>({...DEFAULT_APP_BAR_LABELS,...v}),[v]),I=useTheme(),L=useSafeAreaInsets(),R=useMemo(()=>variantSize(I,x),[I,x]),V=useMemo(()=>buildStyles(I),[I]),C="large"===x,z=C&&void 0!==b,[P,O]=useState(40),D=useCallback(e=>O(e.nativeEvent.layout.height),[]),W=l??(c?{icon:_jsx(AppIcon,{name:"arrow-left",size:24,color:I.colors["text-body"]}),onPress:c,accessibilityLabel:B.back}:void 0),E=a?void 0:s?.[s.length-1],opticalInset=e=>void 0===e?0:void 0!==e.label?I.space.sm:Math.max((44-(e.glyphSize??24))/2,0),k=void 0===d?null:{paddingLeft:Math.max(d-opticalInset(W),0),paddingRight:Math.max(d-opticalInset(E),0)},H=void 0!==p,M=Boolean(W)||Boolean(r),F=!H&&"left"===o&&Boolean(W),N=H||F||!M&&"left"===o,$="default"!==x||M?R.titleSize:I.text.xl.size,U=g??!1,G=StyleSheet.hairlineWidth,Z=useMemo(()=>{if(!b)return null;const e=b;return{rootHeight:e.interpolate({inputRange:[0,60],outputRange:[L.top+R.height+P,L.top+R.height],extrapolate:"clamp"}),titleRowOpacity:e.interpolate({inputRange:[0,30],outputRange:[1,0],extrapolate:"clamp"}),compactTitleOpacity:e.interpolate({inputRange:[30,60],outputRange:[0,1],extrapolate:"clamp"}),borderOpacity:e.interpolate({inputRange:[0,60],outputRange:[0,1],extrapolate:"clamp"})}},[b,L.top,R.height,P]),Y=i?u?_jsx(ThemedText,{variant:u,align:"center"===o?"center":"left",accessibilityRole:"header",numberOfLines:1,style:[V.titleVariant,S],children:i}):_jsx(Animated.Text,{accessibilityRole:"header",style:[V.title,{fontSize:$,fontWeight:I.weight[R.titleWeight],textAlign:"center"===o?"center":"left"},n?V.stackedText:null,S],numberOfLines:1,children:i}):null,q=z&&Z&&i?_jsx(Animated.Text,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[V.title,{fontSize:I.text.lg.size,fontWeight:I.weight.semibold,textAlign:"center"===o?"center":"left",opacity:Z.compactTitleOpacity}],numberOfLines:1,children:i}):null,J=n?_jsx(Animated.Text,{style:[V.subtitle,{textAlign:"center"===o?"center":"left"},j],numberOfLines:R.subtitleLines,children:n}):null,K=_jsxs(View,{style:[V.titleColumn,"center"===o?V.titleColumnCenter:null],children:[Y,J]}),Q=z?Animated.View:View,X=z&&Z?{height:Z.rootHeight,overflow:"hidden"}:C&&void 0===h?null:{height:(h??R.height)+L.top},ee=useMemo(()=>(s??[]).map((e,t)=>({key:`appbar-right-${t}`,action:e})),[s]);return _jsxs(Q,{ref:t,testID:T,style:[V.root,{paddingTop:L.top,backgroundColor:f?"transparent":I.colors.surface},X,!z&&U?{borderBottomWidth:G,borderBottomColor:I.colors.border}:null,m&&!f?I.shadow.card:null,A,y],children:[z&&Z&&U?_jsx(Animated.View,{pointerEvents:"none",style:[V.animatedBorder,{backgroundColor:I.colors.border,opacity:Z.borderOpacity}]}):null,_jsxs(View,{testID:C&&T?`${T}-bar-row`:void 0,style:[V.row,C?{height:R.height}:{flex:1},k],children:[_jsxs(View,{testID:T?`${T}-leading-slot`:void 0,style:[V.sideSlot,N?V.sideSlotCompact:null],children:[W?_jsx(ActionButton,{action:W,side:"left",haptic:w,flush:H||F}):null,null!=r&&!1!==r?_jsx(View,{style:V.slotNode,children:r}):null]}),_jsx(View,{pointerEvents:"none",style:[V.center,"center"===o?V.centerAligned:V.centerLeft,H?{paddingLeft:M?p:I.space.none,paddingRight:I.space.none}:N?{paddingLeft:I.space.none}:null],children:C?q:K}),_jsxs(View,{style:[V.sideSlot,V.sideSlotRight,H?V.sideSlotCompact:null],children:[ee.map(({key:e,action:t})=>_jsx(Fragment,{children:"menu"in t?_jsx(Menu,{items:t.menu,title:t.menuTitle,haptic:w,trigger:_jsx(ActionButton,{action:t,side:"right",badgeStyle:_,haptic:w,flush:H})}):_jsx(ActionButton,{action:t,side:"right",badgeStyle:_,haptic:w,flush:H})},e)),null!=a&&!1!==a?_jsx(View,{style:V.slotNode,children:a}):null]})]}),C?_jsx(Animated.View,{testID:T?`${T}-title-row`:void 0,onLayout:z?D:void 0,pointerEvents:"none",style:[{paddingHorizontal:d??I.space.md,paddingBottom:I.space.sm},z&&Z?{opacity:Z.titleRowOpacity}:null],children:K}):null]})});AppBar.displayName="AppBar";const buildStyles=e=>StyleSheet.create({root:{width:"100%"},row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.xs},sideSlot:{flexDirection:"row",alignItems:"center",minWidth:48},sideSlotRight:{justifyContent:"flex-end"},sideSlotCompact:{minWidth:0},slotNode:{flexDirection:"row",alignItems:"center"},center:{flex:1,minWidth:0,paddingHorizontal:e.space.xs},centerAligned:{alignItems:"center"},centerLeft:{alignItems:"flex-start"},titleColumn:{flexDirection:"column",maxWidth:"100%"},titleColumnCenter:{alignItems:"center"},title:{color:e.colors["text-body"]},titleVariant:{includeFontPadding:!1,textAlignVertical:"center"},stackedText:{includeFontPadding:!1},subtitle:{includeFontPadding:!1,color:e.colors["text-subtle"],fontSize:e.text.sm.size,fontWeight:e.weight.normal},animatedBorder:{position:"absolute",left:0,right:0,bottom:0,height:StyleSheet.hairlineWidth}}),buildActionStyles=e=>StyleSheet.create({actionButton:{width:44,height:44,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},actionLeft:{marginRight:e.space.xs},actionRight:{marginLeft:e.space.xs},actionPressed:{backgroundColor:e.colors["surface-pressed"]},textButton:{minWidth:44,minHeight:44,paddingHorizontal:e.space.sm,alignItems:"center",justifyContent:"center"},textPressed:{opacity:.6},dot:{position:"absolute",top:10,right:10,width:8,height:8,borderRadius:e.radius.pill,backgroundColor:e.colors.danger},iconWrap:{alignItems:"center",justifyContent:"center"},badge:{position:"absolute",top:4,right:4,minWidth:16,height:16,paddingHorizontal:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.danger,alignItems:"center",justifyContent:"center"},badgeText:{color:e.colors["on-danger"],fontSize:e.text.xs.size,fontWeight:e.weight.semibold,lineHeight:Math.round(e.text.xs.size*e.leading.heading)}});export{AppBar};export default AppBar;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{useMemo}from"react";import{SvgXml}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hasKey}from"../../utils/guards.js";import{resolveColor}from"../Text/Text.js";import{CATALOG_LOADERS,ICON_NAMES}from"./catalog.g.js";import{CURATED_ICON_NAMES,GLYPHS}from"./glyphs.g.js";import{jsx as _jsx}from"react/jsx-runtime";export{CURATED_ICON_NAMES,ICON_NAMES};export const ICONSAX_SUFFIX="-iconsax";export const APP_ICON_SIZES={xs:14,sm:18,md:22,lg:28,xl:36};const tryRequire=e=>{try{return e()}catch{return null}};let curatedVariants=null;const loadCuratedVariants=()=>(curatedVariants||(curatedVariants=tryRequire(()=>require("./variants.g").VARIANT_GLYPHS)??{}),curatedVariants),shardCache=new Map,loadShard=(e,r)=>{const t=r[0]?.toLowerCase()??"",o=`${e}:${t}`,a=shardCache.get(o);if(void 0!==a)return a;const s=CATALOG_LOADERS[e]?.[t],n=s?tryRequire(s):null;return shardCache.set(o,n),n},warned=new Set,resolveCatalogue=(e,r)=>{const t=loadShard(r,e)?.[e];return t||("linear"===r?null:loadShard("linear",e)?.[e]??null)};export const resolveGlyph=(e,r="linear")=>{if(e.endsWith("-iconsax")){const t=e.slice(0,-8);return t in GLYPHS?resolveCatalogue(t,r):null}const t=hasKey(GLYPHS,e)?GLYPHS[e]:void 0;return t?"linear"===r?t:loadCuratedVariants()[r]?.[e]??t:resolveCatalogue(e,r)};export const buildIconXml=(e,r,t)=>`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${r}" viewBox="0 0 24 24" fill="none">${e.replace(/currentColor/g,t)}</svg>`;const iconXmlCache=new Map;export const AppIcon=({name:e,size:r="md",color:t,variant:o="linear",style:a,accessibilityLabel:s,testID:n})=>{const l=useTheme();"string"==typeof r&&assertValidValue("AppIcon","size",r,Object.keys(APP_ICON_SIZES)),assertValidValue("AppIcon","variant",o,["linear","bold","bulk","broken","outline","twotone"]);const i="number"==typeof r?r:APP_ICON_SIZES[r]??APP_ICON_SIZES.md,c=void 0===t?l.colors["text-body"]:resolveColor(l,t),u=resolveGlyph(e,o),m=useMemo(()=>{if(!u)return null;const r=`${e}|${o}|${i}|${c}`,t=iconXmlCache.get(r);if(void 0!==t)return t;iconXmlCache.size>=500&&iconXmlCache.clear();const a=buildIconXml(u,i,c);return iconXmlCache.set(r,a),a},[e,o,u,i,c]);if(!m)return __DEV__&&!warned.has(e)&&(warned.add(e),Logger.warn(`[@webority/mobile-ui] AppIcon: Unknown icon "${e}". Names come from webority-ui's icon map and the Iconsax catalogue; run node scripts/gen-icons.mjs after adding one there.`)),null;return _jsx(SvgXml,{xml:m,width:i,height:i,...void 0!==a?{style:a}:{},accessible:null!=s,...null!=s?{accessibilityLabel:s,accessibilityRole:"image"}:{},...void 0!==n?{testID:n}:{}})};AppIcon.displayName="AppIcon";export default AppIcon;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{useMemo}from"react";import{SvgXml}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hasKey}from"../../utils/guards.js";import{resolveColor}from"../Text/Text.js";import{CATALOG_LOADERS,ICON_NAMES}from"./catalog.g.js";import{CURATED_ICON_NAMES,GLYPHS}from"./glyphs.g.js";import{jsx as _jsx}from"react/jsx-runtime";export{CURATED_ICON_NAMES,ICON_NAMES};export const ICONSAX_SUFFIX="-iconsax";export function isAppIconName(e){return"string"==typeof e&&(!!ICON_NAMES.some(r=>r===e)||e.endsWith("-iconsax")&&CURATED_ICON_NAMES.some(r=>r===e.slice(0,-8)))}export const APP_ICON_SIZES={xs:14,sm:18,md:22,lg:28,xl:36};const tryRequire=e=>{try{return e()}catch{return null}};let curatedVariants=null;const loadCuratedVariants=()=>(curatedVariants||(curatedVariants=tryRequire(()=>require("./variants.g").VARIANT_GLYPHS)??{}),curatedVariants),shardCache=new Map,loadShard=(e,r)=>{const t=r[0]?.toLowerCase()??"",o=`${e}:${t}`,s=shardCache.get(o);if(void 0!==s)return s;const a=CATALOG_LOADERS[e]?.[t],n=a?tryRequire(a):null;return shardCache.set(o,n),n},warned=new Set,resolveCatalogue=(e,r)=>{const t=loadShard(r,e)?.[e];return t||("linear"===r?null:loadShard("linear",e)?.[e]??null)};export const resolveGlyph=(e,r="linear")=>{if(e.endsWith("-iconsax")){const t=e.slice(0,-8);return t in GLYPHS?resolveCatalogue(t,r):null}const t=hasKey(GLYPHS,e)?GLYPHS[e]:void 0;return t?"linear"===r?t:loadCuratedVariants()[r]?.[e]??t:resolveCatalogue(e,r)};export const buildIconXml=(e,r,t)=>`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${r}" viewBox="0 0 24 24" fill="none">${e.replace(/currentColor/g,t)}</svg>`;const iconXmlCache=new Map;export const AppIcon=({name:e,size:r="md",color:t,variant:o="linear",style:s,accessibilityLabel:a,testID:n})=>{const i=useTheme();"string"==typeof r&&assertValidValue("AppIcon","size",r,Object.keys(APP_ICON_SIZES)),assertValidValue("AppIcon","variant",o,["linear","bold","bulk","broken","outline","twotone"]);const l="number"==typeof r?r:APP_ICON_SIZES[r]??APP_ICON_SIZES.md,c=void 0===t?i.colors["text-body"]:resolveColor(i,t),u=resolveGlyph(e,o),m=useMemo(()=>{if(!u)return null;const r=`${e}|${o}|${l}|${c}`,t=iconXmlCache.get(r);if(void 0!==t)return t;iconXmlCache.size>=500&&iconXmlCache.clear();const s=buildIconXml(u,l,c);return iconXmlCache.set(r,s),s},[e,o,u,l,c]);if(!m)return __DEV__&&!warned.has(e)&&(warned.add(e),Logger.warn(`[@webority/mobile-ui] AppIcon: Unknown icon "${e}". Names come from webority-ui's icon map and the Iconsax catalogue; run node scripts/gen-icons.mjs after adding one there.`)),null;return _jsx(SvgXml,{xml:m,width:l,height:l,...void 0!==s?{style:s}:{},accessible:null!=a,...null!=a?{accessibilityLabel:a,accessibilityRole:"image"}:{},...void 0!==n?{testID:n}:{}})};AppIcon.displayName="AppIcon";export default AppIcon;
@@ -1 +1 @@
1
- "use strict";export{APP_ICON_SIZES,AppIcon,buildIconXml,CURATED_ICON_NAMES,default,ICON_NAMES,ICONSAX_SUFFIX,resolveGlyph}from"./AppIcon.js";export{defaultIcons}from"./defaultIcons.js";export{renderSlotIcon}from"./slotIcon.js";
1
+ "use strict";export{APP_ICON_SIZES,AppIcon,buildIconXml,CURATED_ICON_NAMES,default,ICON_NAMES,ICONSAX_SUFFIX,isAppIconName,resolveGlyph}from"./AppIcon.js";export{defaultIcons}from"./defaultIcons.js";export{renderSlotIcon}from"./slotIcon.js";
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{IconBadge}from"../IconBadge/index.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BANNER_LABELS=Object.freeze({dismiss:"Dismiss banner"});const BannerRoot=forwardRef((e,t)=>{const{title:r,message:o,tone:s="neutral",variant:n="bar",icon:i,actions:a,dismissible:l=!1,onClose:c,haptic:d,open:u=!0,animateMount:m=!0,loading:p=!1,accessibilityRole:g="alert",accessibilityLabel:h,labels:y,style:b,containerStyle:x,iconCircleStyle:f,tintBarStyle:w,closeButtonStyle:j,actionButtonStyle:v,testID:S}=e;assertValidValue("Banner","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","variant",e.variant,["bar","wash","tint"]),assertValidValue("Banner","accessibilityRole",e.accessibilityRole,["alert","summary","none"]);const B=useTheme(),V=usePresenceMotion(),k=useMemo(()=>buildStyles(B),[B]),C=useMemo(()=>tintFor(B,s),[B,s]),_=useMemo(()=>({...DEFAULT_BANNER_LABELS,...y}),[y]),[R,I]=V.range(-20,0),D=useRef(createAnimatedValue(m&&u?R:0)).current,A=useRef(createAnimatedValue(m&&u?0:u?1:0)).current,[T,L]=useState(u),M=useRef(!0);if(useEffect(()=>{if(M.current&&(M.current=!1,!m))return;let e;return u?(L(!0),e=Animated.parallel([Animated.timing(D,{toValue:I,duration:B.motion.duration.default,useNativeDriver:nativeDriver}),Animated.timing(A,{toValue:1,duration:V.duration("default"),useNativeDriver:nativeDriver})]),e.start()):T&&(e=Animated.parallel([Animated.timing(D,{toValue:R,duration:B.motion.duration.fast,useNativeDriver:nativeDriver}),Animated.timing(A,{toValue:0,duration:V.duration("fast"),useNativeDriver:nativeDriver})]),e.start(()=>{L(!1)})),()=>e?.stop()},[u]),!T)return null;const E=r??" ",z="string"==typeof o?o??" ":"",H="wash"===n,N="bar"!==n,P="alert"===g?"danger"===s?"assertive":"polite":"none",W=_jsxs(Animated.View,{ref:t,accessibilityRole:g,accessibilityLiveRegion:P,accessibilityLabel:h,testID:S,style:[k.container,{backgroundColor:N?C.soft:B.colors["bg-subtle"],borderRadius:H?B.radius.sm:B.radius.md,...smoothCorners,padding:B.space.md,opacity:A,transform:[{translateY:D}]},x,b],children:[!H&&B.components.banner["tint-bar-width"]>0?_jsx(View,{style:[k.tintBar,{backgroundColor:C.bar},w]}):null,_jsxs(View,{style:[k.row,void 0===r&&k.rowCentred],children:[!1===i?null:i?_jsx(View,{style:k.iconWrap,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(i,{color:C.ink,size:B.text.xl.size,disabled:!1})}):_jsx(IconBadge,{dimension:ICON_CIRCLE_SIZE,color:C.bar,icon:_jsx(Text,{variant:"body",weight:"bold",accessible:!1,style:[k.iconGlyph,{color:C.ink}],children:C.glyph}),style:[k.iconCircle,f]}),_jsxs(View,{style:k.textBlock,children:[r||p?_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:2,style:H?{color:C.ink}:void 0,children:E}):null,"string"==typeof o||p?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginTop:r?B.space.xxs:0},children:z||" "}):_jsx(View,{style:{marginTop:r?B.space.xxs:0},children:o})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:_.dismiss,onPress:()=>{const e=resolveHaptic(d,"selection");e&&triggerHaptic(e),c?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[k.closeBtn,{backgroundColor:e?B.colors["surface-pressed"]:"transparent"},j],children:_jsx(Text,{variant:"title",weight:"bold",color:"secondary",accessible:!1,style:{lineHeight:Math.round(B.text.lg.size*B.leading.heading)},children:"×"})}):null]}),a&&a.length>0?_jsx(View,{style:k.actionsRow,children:a.map((e,t)=>{assertValidValue("Banner","action.tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","action.variant",e.variant,["solid","outline","ghost"]),assertValidValue("Banner","action.size",e.size,["sm","md"]);const r=e.tone??"primary",o=e.variant??"ghost",s="primary"===r?C.glyphColor:"neutral"===r?B.colors["text-muted"]:B.colors[r],n="primary"===r?C.ink:"neutral"===r?B.colors["text-muted"]:B.colors[`${r}-text`],i="primary"===r?C.on:"neutral"===r?B.colors["on-neutral-strong"]:B.colors[`on-${r}`],a="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,testID:e.testID,onPress:()=>{const t=resolveHaptic(d,"selection");t&&triggerHaptic(t),e.onPress()},style:({pressed:t})=>[k.actionBtn,"md"===e.size&&k.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:n},{backgroundColor:a?s:t?B.colors["surface-pressed"]:"transparent",opacity:a&&t?.85:1},v],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:a?i:n},children:e.label})},`${e.label}-${t}`)})}):null]});return p?_jsx(BannerSkeleton,{...e}):W}),BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:o,style:s})=>{const n=useTheme(),i=!1!==r;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:n.colors.surface,borderRadius:n.radius.md,...smoothCorners,padding:n.space.md,borderWidth:1,borderColor:n.colors.border},o,s],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[i?_jsx(View,{style:{marginRight:n.space.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:n.space.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:n.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:n.space.sm},children:t.map((e,t)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:n.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton";const Banner=Object.assign(BannerRoot,{Skeleton:BannerSkeleton});Banner.displayName="Banner";const tintFor=(e,t)=>{switch(t){case"success":return{soft:e.colors["success-soft"],bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{soft:e.colors["warning-soft"],bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{soft:e.colors["danger-soft"],bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{soft:e.colors["bg-subtle"],bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};case"primary":return{soft:e.colors["primary-soft"],bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"};case"info":return{soft:e.colors["info-soft"],bar:e.colors.info,glyphColor:e.colors.info,ink:e.colors["info-text"],on:e.colors["on-info"],glyph:"i"};default:return tintFor(e,"neutral")}},ICON_CIRCLE_SIZE=28,buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},rowCentred:{alignItems:"center"},iconWrap:{marginRight:r},iconCircle:{marginRight:r},iconGlyph:{lineHeight:Math.round(e.text.base.size*e.leading.heading)},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{IconBadge}from"../IconBadge/index.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BANNER_LABELS=Object.freeze({dismiss:"Dismiss banner"});const BannerRoot=forwardRef((e,t)=>{const{title:r,message:n,tone:o="neutral",variant:s="bar",icon:i,actions:a,dismissible:l=!1,onClose:c,haptic:d,open:u=!0,animateMount:m=!0,loading:p=!1,accessibilityRole:g="alert",accessibilityLabel:h,labels:y,style:b,containerStyle:x,iconCircleStyle:f,tintBarStyle:w,closeButtonStyle:j,actionButtonStyle:v,testID:S}=e;assertValidValue("Banner","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","variant",e.variant,["bar","wash","tint"]),assertValidValue("Banner","accessibilityRole",e.accessibilityRole,["alert","summary","none"]);const B=useTheme(),k=usePresenceMotion(),V=useMemo(()=>buildStyles(B),[B]),C=useMemo(()=>tintFor(B,o),[B,o]),_=useMemo(()=>({...DEFAULT_BANNER_LABELS,...y}),[y]),R=useMemo(()=>(a??[]).map((e,t)=>({key:`${e.label}-${t}`,action:e})),[a]),[I,D]=k.range(-20,0),A=useRef(createAnimatedValue(m&&u?I:0)).current,M=useRef(createAnimatedValue(m&&u?0:u?1:0)).current,[T,L]=useState(u),E=useRef(!0),z=useRef({animateMount:m,mounted:T,theme:B,presence:k,hiddenY:I,shownY:D,translateY:A,opacity:M});if(z.current={animateMount:m,mounted:T,theme:B,presence:k,hiddenY:I,shownY:D,translateY:A,opacity:M},useEffect(()=>{if(E.current&&(E.current=!1,!z.current.animateMount))return;let e;return u?(L(!0),e=Animated.parallel([Animated.timing(z.current.translateY,{toValue:z.current.shownY,duration:z.current.theme.motion.duration.default,useNativeDriver:nativeDriver}),Animated.timing(z.current.opacity,{toValue:1,duration:z.current.presence.duration("default"),useNativeDriver:nativeDriver})]),e.start()):z.current.mounted&&(e=Animated.parallel([Animated.timing(z.current.translateY,{toValue:z.current.hiddenY,duration:z.current.theme.motion.duration.fast,useNativeDriver:nativeDriver}),Animated.timing(z.current.opacity,{toValue:0,duration:z.current.presence.duration("fast"),useNativeDriver:nativeDriver})]),e.start(()=>{L(!1)})),()=>e?.stop()},[u]),!T)return null;const H=r??" ",N="string"==typeof n?n??" ":"",Y="wash"===s,P="bar"!==s,W="alert"===g?"danger"===o?"assertive":"polite":"none",F=_jsxs(Animated.View,{ref:t,accessibilityRole:g,accessibilityLiveRegion:W,accessibilityLabel:h,testID:S,style:[V.container,{backgroundColor:P?C.soft:B.colors["bg-subtle"],borderRadius:Y?B.radius.sm:B.radius.md,...smoothCorners,padding:B.space.md,opacity:M,transform:[{translateY:A}]},x,b],children:[!Y&&B.components.banner["tint-bar-width"]>0?_jsx(View,{style:[V.tintBar,{backgroundColor:C.bar},w]}):null,_jsxs(View,{style:[V.row,void 0===r&&V.rowCentred],children:[!1===i?null:i?_jsx(View,{style:V.iconWrap,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(i,{color:C.ink,size:B.text.xl.size,disabled:!1})}):_jsx(IconBadge,{dimension:ICON_CIRCLE_SIZE,color:C.bar,icon:_jsx(Text,{variant:"body",weight:"bold",accessible:!1,style:[V.iconGlyph,{color:C.ink}],children:C.glyph}),style:[V.iconCircle,f]}),_jsxs(View,{style:V.textBlock,children:[r||p?_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:2,style:Y?{color:C.ink}:void 0,children:H}):null,"string"==typeof n||p?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginTop:r?B.space.xxs:0},children:N||" "}):_jsx(View,{style:{marginTop:r?B.space.xxs:0},children:n})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:_.dismiss,onPress:()=>{const e=resolveHaptic(d,"selection");e&&triggerHaptic(e),c?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[V.closeBtn,{backgroundColor:e?B.colors["surface-pressed"]:"transparent"},j],children:_jsx(Text,{variant:"title",weight:"bold",color:"secondary",accessible:!1,style:{lineHeight:Math.round(B.text.lg.size*B.leading.heading)},children:"×"})}):null]}),a&&a.length>0?_jsx(View,{style:V.actionsRow,children:R.map(({key:e,action:t})=>{assertValidValue("Banner","action.tone",t.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Banner","action.variant",t.variant,["solid","outline","ghost"]),assertValidValue("Banner","action.size",t.size,["sm","md"]);const r=t.tone??"primary",n=t.variant??"ghost",o="primary"===r?C.glyphColor:"neutral"===r?B.colors["text-muted"]:B.colors[r],s="primary"===r?C.ink:"neutral"===r?B.colors["text-muted"]:B.colors[`${r}-text`],i="primary"===r?C.on:"neutral"===r?B.colors["on-neutral-strong"]:B.colors[`on-${r}`],a="solid"===n;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t.label,testID:t.testID,onPress:()=>{const e=resolveHaptic(d,"selection");e&&triggerHaptic(e),t.onPress()},style:({pressed:e})=>[V.actionBtn,"md"===t.size&&V.actionBtnMd,"outline"===n&&{borderWidth:1,borderColor:s},{backgroundColor:a?o:e?B.colors["surface-pressed"]:"transparent",opacity:a&&e?.85:1},v],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:a?i:s},children:t.label})},e)})}):null]});return p?_jsx(BannerSkeleton,{...e}):F}),BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:n,style:o})=>{const s=useTheme(),i=!1!==r,a=t?.length??0,l=useMemo(()=>Array.from({length:a},(e,t)=>({key:`sk-banner-action-${t}`})),[a]);return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:s.colors.surface,borderRadius:s.radius.md,...smoothCorners,padding:s.space.md,borderWidth:1,borderColor:s.colors.border},n,o],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[i?_jsx(View,{style:{marginRight:s.space.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:s.space.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:s.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.sm},children:l.map(e=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:s.space.sm}},e.key))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton";const Banner=Object.assign(BannerRoot,{Skeleton:BannerSkeleton});Banner.displayName="Banner";const tintFor=(e,t)=>{switch(t){case"success":return{soft:e.colors["success-soft"],bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{soft:e.colors["warning-soft"],bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{soft:e.colors["danger-soft"],bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{soft:e.colors["bg-subtle"],bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};case"primary":return{soft:e.colors["primary-soft"],bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"};case"info":return{soft:e.colors["info-soft"],bar:e.colors.info,glyphColor:e.colors.info,ink:e.colors["info-text"],on:e.colors["on-info"],glyph:"i"};default:return tintFor(e,"neutral")}},ICON_CIRCLE_SIZE=28,buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},rowCentred:{alignItems:"center"},iconWrap:{marginRight:r},iconCircle:{marginRight:r},iconGlyph:{lineHeight:Math.round(e.text.base.size*e.leading.heading)},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
@@ -1 +1 @@
1
- "use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{barScale}from"./scale.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`});const AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>formatNumber(e),defaultFormatTick=e=>formatCompactNumber(e),BarChart=forwardRef((e,t)=>{const{data:r,tone:s="primary",color:a,series:o,height:i=160,label:l,summary:n,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:m,selection:h,defaultSelection:d=null,onSelect:p,haptic:x,labels:f,style:y,testID:b}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const g=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...f}),[f]),_=useTheme(),A=r.length,[C,S]=useState(0),[j,w]=useControllableState({value:h,defaultValue:d,onChange:p}),M=null!==j&&j>=0&&j<A?j:null,T=useRef(M);T.current=M;const v=useRef(-1),R=resolveHaptic(x,"tick"),V=useCallback(()=>{R&&triggerHaptic(R)},[R]),L=m??(A>0&&A<=7),D=void 0!==o&&o.length>0,$=useMemo(()=>D?o.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[D,o]),k=useMemo(()=>D?o.map(e=>e.key):[],[D,o]),I=useMemo(()=>D?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,D]),B=useMemo(()=>I?I.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,I]),E=useMemo(()=>I?I.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):B,[I,B]),H=useMemo(()=>barScale(E),[E]),O=L?20:6,F=L&&H.min<0?20:6,N=Math.max(1,i-O-F),G=useCallback(e=>O+(H.max-e)/(H.max-H.min)*N,[O,H.max,H.min,N]),W=G(0),U=useMemo(()=>H.ticks.map(e=>u(e)),[H.ticks,u]),z=Math.ceil(8*Math.max(...U.map(e=>e.length),1)*1.2)+_.space.xs,P=A>0?C/A:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useCallback(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(I&&o){const r=entryAt(I,e);return`${t.label}, ${o.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt(B,e))}`},[r,c,B,I,o]),J=useMemo(()=>{let e=-1,t=0;for(const[r,s]of B.entries())(-1===e||s>t)&&(e=r,t=s);return e},[B]),Y=n??(J>=0?g.highest(entryAt(r,J).label,c(entryAt(B,J))):""),Z=useRef({fire:V,setSelected:w,count:A,plotWidth:C});Z.current={fire:V,setSelected:w,count:A,plotWidth:C};const q=useCallback(e=>{const{count:t,plotWidth:r}=Z.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},[]),Q=useCallback(e=>{const t=q(e);t<0||t===v.current||(v.current=t,Z.current.fire(),Z.current.setSelected(t))},[q]),ee=useMemo(()=>({runOnJS:!0,activeOffsetX:[-8,8],failOffsetY:[-12,12],onActivate:e=>{v.current=T.current??-1,Q(e.x)},onUpdate:e=>Q(e.x),testID:b?`${b}-pan`:"bar-chart-pan"}),[Q,b]),te=usePanGesture(ee),re=useMemo(()=>({runOnJS:!0,onDeactivate:e=>{if(e.canceled)return;const t=q(e.x);t<0||(Z.current.fire(),v.current=t,Z.current.setSelected(t===T.current?null:t))},testID:b?`${b}-tap`:"bar-chart-tap"}),[q,b]),se=useTapGesture(re),ae=useCompetingGestures(te,se),oe=useCallback(e=>{if(0===A)return;const t=T.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(A-1,t+1):null===t?A-1:Math.max(0,t-1);r!==t&&(V(),w(r))},[A,V,w]),ie=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);S(e=>e===t?e:t)},[]),le=a??toneColor(_,s),ne=_.radius.sm,ce=l??g.chart,ue=0===A?`${ce}, ${g.noData}`:Y?`${ce}, ${Y}`:ce,me=null===M?Y:K(M),he=Math.min(40,Math.max(4,.6*P)),renderStack=(e,t,r)=>{const s=e.reduce((e,t)=>t>0?e+t:e,0),a=e.reduce((e,t)=>t<0?e+t:e,0);if(0===s&&0===a)return null;const o=G(s),i=[];let l=0,n=0;return e.forEach((e,r)=>{if(0===e)return;const s=e>0?l:n,a=s+e;e>0?l=a:n=a;const c=G(s),u=G(a);i.push(_jsx(View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-o,height:Math.abs(c-u),backgroundColor:toneColor(_,entryAt($,r))}},entryAt(k,r)))}),_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:o,width:he,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:null,...a<0?{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}:null},children:i})},de=B.map((e,t)=>{const r=G(e),s=e>=0?r:W,a=0===e?0:Math.max(2,Math.abs(r-W)),o=null!==M&&M!==t;return _jsxs(View,{style:[styles.slot,{height:i}],children:[C>0&&I?renderStack(entryAt(I,t),t,o):null,C>0&&!I&&a>0?_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:s,width:he,height:a,backgroundColor:le,opacity:o?.4:1,...smoothCorners,...e>=0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}}}):null,L&&C>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(I?G(entryAt(E,2*t)):r)-20+2:(I?G(entryAt(E,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===A?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ue,testID:b,style:[styles.root,y],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ue,accessibilityValue:{min:0,max:A-1,now:M??0,text:me},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:oe,testID:b,style:[styles.root,y],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:_.space.sm}],children:null===M?Y?_jsx(Text,{variant:"bodySmall",color:"secondary",children:Y}):null:_jsxs(_Fragment,{children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,M).label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt(B,M))})]})}),_jsxs(View,{style:styles.body,children:[_jsx(View,{style:{width:z,height:i},children:H.ticks.map((e,t)=>_jsx(Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:_.space.xs,left:0,top:G(e)-8},children:entryAt(U,t)},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:ae,children:_jsxs(View,{style:{height:i},onLayout:ie,testID:b?`${b}-plot`:void 0,children:[H.ticks.map(e=>_jsx(View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:StyleSheet.hairlineWidth),height:0===e?1.5:2*StyleSheet.hairlineWidth,backgroundColor:0===e?_.colors["text-subtle"]:_.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:de})]})}),_jsx(View,{style:styles.axis,children:r.map((e,t)=>_jsx(View,{style:styles.axisSlot,children:t%X===0?_jsx(Text,{variant:"caption",color:M===t?"primary":"tertiary",weight:M===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:P>0?{width:P*X}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),o&&D?_jsx(View,{style:[styles.legend,{marginTop:_.space.sm,columnGap:_.space.md,rowGap:_.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:_.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:_.radius.sm,...smoothCorners,backgroundColor:toneColor(_,entryAt($,t))}}),_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});export{BarChart};export default BarChart;
1
+ "use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{barScale}from"./scale.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`});const AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>formatNumber(e),defaultFormatTick=e=>formatCompactNumber(e),BarChart=forwardRef((e,t)=>{const{data:r,tone:s="primary",color:a,series:o,height:i=160,label:l,summary:n,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:m,selection:d,defaultSelection:h=null,onSelect:p,haptic:x,labels:y,style:f,testID:b}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const g=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...y}),[y]),_=useTheme(),A=r.length,[C,S]=useState(0),[j,w]=useControllableState({value:d,defaultValue:h,onChange:p}),M=null!==j&&j>=0&&j<A?j:null,T=useRef(M);T.current=M;const v=useRef(-1),R=resolveHaptic(x,"tick"),V=useCallback(()=>{R&&triggerHaptic(R)},[R]),L=m??(A>0&&A<=7),k=void 0!==o&&o.length>0,D=useMemo(()=>k?o.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[k,o]),$=useMemo(()=>k?o.map(e=>e.key):[],[k,o]),I=useMemo(()=>k?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,k]),B=useMemo(()=>I?I.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,I]),E=useMemo(()=>I?I.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):B,[I,B]),H=useMemo(()=>barScale(E),[E]),O=L?20:6,F=L&&H.min<0?20:6,N=Math.max(1,i-O-F),G=useCallback(e=>O+(H.max-e)/(H.max-H.min)*N,[O,H.max,H.min,N]),W=G(0),U=useMemo(()=>H.ticks.map(e=>u(e)),[H.ticks,u]),z=Math.ceil(8*Math.max(...U.map(e=>e.length),1)*1.2)+_.space.xs,P=A>0?C/A:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useMemo(()=>r.map((e,t)=>({key:`axis-${t}`,d:e,index:t})),[r]),J=useCallback(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(I&&o){const r=entryAt(I,e);return`${t.label}, ${o.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt(B,e))}`},[r,c,B,I,o]),Y=useMemo(()=>{let e=-1,t=0;for(const[r,s]of B.entries())(-1===e||s>t)&&(e=r,t=s);return e},[B]),Z=n??(Y>=0?g.highest(entryAt(r,Y).label,c(entryAt(B,Y))):""),q=useRef({fire:V,setSelected:w,count:A,plotWidth:C});q.current={fire:V,setSelected:w,count:A,plotWidth:C};const Q=useCallback(e=>{const{count:t,plotWidth:r}=q.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},[]),ee=useCallback(e=>{const t=Q(e);t<0||t===v.current||(v.current=t,q.current.fire(),q.current.setSelected(t))},[Q]),te=useMemo(()=>({runOnJS:!0,activeOffsetX:[-8,8],failOffsetY:[-12,12],onActivate:e=>{v.current=T.current??-1,ee(e.x)},onUpdate:e=>ee(e.x),testID:b?`${b}-pan`:"bar-chart-pan"}),[ee,b]),re=usePanGesture(te),se=useMemo(()=>({runOnJS:!0,onDeactivate:e=>{if(e.canceled)return;const t=Q(e.x);t<0||(q.current.fire(),v.current=t,q.current.setSelected(t===T.current?null:t))},testID:b?`${b}-tap`:"bar-chart-tap"}),[Q,b]),ae=useTapGesture(se),oe=useCompetingGestures(re,ae),ie=useCallback(e=>{if(0===A)return;const t=T.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(A-1,t+1):null===t?A-1:Math.max(0,t-1);r!==t&&(V(),w(r))},[A,V,w]),le=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);S(e=>e===t?e:t)},[]),ne=a??toneColor(_,s),ce=_.radius.sm,ue=l??g.chart,me=0===A?`${ue}, ${g.noData}`:Z?`${ue}, ${Z}`:ue,de=null===M?Z:J(M),he=Math.min(40,Math.max(4,.6*P)),renderStack=(e,t,r)=>{const s=e.reduce((e,t)=>t>0?e+t:e,0),a=e.reduce((e,t)=>t<0?e+t:e,0);if(0===s&&0===a)return null;const o=G(s),i=[];let l=0,n=0;return e.forEach((e,r)=>{if(0===e)return;const s=e>0?l:n,a=s+e;e>0?l=a:n=a;const c=G(s),u=G(a);i.push(_jsx(View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-o,height:Math.abs(c-u),backgroundColor:toneColor(_,entryAt(D,r))}},entryAt($,r)))}),_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:o,width:he,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:ce,borderTopRightRadius:ce}:null,...a<0?{borderBottomLeftRadius:ce,borderBottomRightRadius:ce}:null},children:i})},pe=useMemo(()=>B.map((e,t)=>({key:`bar-${t}`,value:e,index:t})),[B]).map(({key:e,value:t,index:r})=>{const s=G(t),a=t>=0?s:W,o=0===t?0:Math.max(2,Math.abs(s-W)),l=null!==M&&M!==r;return _jsxs(View,{style:[styles.slot,{height:i}],children:[C>0&&I?renderStack(entryAt(I,r),r,l):null,C>0&&!I&&o>0?_jsx(View,{testID:b?`${b}-bar-${r}`:void 0,style:{position:"absolute",left:(P-he)/2,top:a,width:he,height:o,backgroundColor:ne,opacity:l?.4:1,...smoothCorners,...t>=0?{borderTopLeftRadius:ce,borderTopRightRadius:ce}:{borderBottomLeftRadius:ce,borderBottomRightRadius:ce}}}):null,L&&C>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:t>=0?(I?G(entryAt(E,2*r)):s)-20+2:(I?G(entryAt(E,2*r+1)):s)+2},children:u(t)}):null]},e)});return 0===A?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:me,testID:b,style:[styles.root,f],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:me,accessibilityValue:{min:0,max:A-1,now:M??0,text:de},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:ie,testID:b,style:[styles.root,f],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:_.space.sm}],children:null===M?Z?_jsx(Text,{variant:"bodySmall",color:"secondary",children:Z}):null:_jsxs(_Fragment,{children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,M).label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt(B,M))})]})}),_jsxs(View,{style:styles.body,children:[_jsx(View,{style:{width:z,height:i},children:H.ticks.map((e,t)=>_jsx(Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:_.space.xs,left:0,top:G(e)-8},children:entryAt(U,t)},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:oe,children:_jsxs(View,{style:{height:i},onLayout:le,testID:b?`${b}-plot`:void 0,children:[H.ticks.map(e=>_jsx(View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:StyleSheet.hairlineWidth),height:0===e?1.5:2*StyleSheet.hairlineWidth,backgroundColor:0===e?_.colors["text-subtle"]:_.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:pe})]})}),_jsx(View,{style:styles.axis,children:K.map(({key:e,d:t,index:r})=>_jsx(View,{style:styles.axisSlot,children:r%X===0?_jsx(Text,{variant:"caption",color:M===r?"primary":"tertiary",weight:M===r?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:P>0?{width:P*X}:void 0,children:t.axisLabel??t.label}):null},e))})]})]}),o&&k?_jsx(View,{style:[styles.legend,{marginTop:_.space.sm,columnGap:_.space.md,rowGap:_.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:_.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:_.radius.sm,...smoothCorners,backgroundColor:toneColor(_,entryAt(D,t))}}),_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});export{BarChart};export default BarChart;
@@ -1 +1 @@
1
- "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:p,onScrollLayout:b,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:M,actions:O,actionsLayout:E="auto",footer:k,headerStyle:R,footerStyle:T,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=M||null!=d,L=null!=O&&O.length>0,P=null!=k||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),p?.(e,t)},[te,p,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,pe=fe[fe.length-1]??0,be=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Me,Oe]=useState(!1),[Ee,ke]=useState(!1),Re=useRef(!1),Te=useRef(i);Te.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Ee:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(Re.current=!0,"modal"===N?(Oe(!1),"ios"!==Platform.OS&&ke(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{Re.current&&ke(!1)},[]);useEffect(()=>{("modal"===N?!Ee:!Ae)&&Re.current&&(Re.current=!1,Te.current?.(),Ge(!0))},[N,Ee,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),be.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,be,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return Re.current=!1,Ge(!1),"modal"===N?(ke(!0),Oe(!0)):Ie(!0),o<0&&je.current?(be.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(be.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(be.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,be,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:be,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,be,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);be.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-pe,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>({testID:V?`${V}-content-gesture`:"bottom-sheet-content-gesture"}),[V]),at=useNativeGesture(rt),it=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return{testID:V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";ve.value=be.value},onUpdate:e=>{"worklet";const t=ve.value+e.translationY;be.value=t<o?o+.25*(t-o):t},onDeactivate:o=>{"worklet";const n=be.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)}}},[Se,ve,l,nt,tt,ot,V,be]),lt=usePanGesture(it),{height:ut}=useReanimatedKeyboardAnimation(),ct="shift"===y,dt=useDerivedValue(()=>ct?ut.value:0,[ct,ut]),ht=fe[we>=0?we:0]??pe,mt=H.space.md,ft=useAnimatedStyle(()=>{if(W){const e=dt.value,t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=be.value+dt.value,t=dt.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,dt,U,ht,mt,be,Z,ye,tt]),St=useAnimatedStyle(()=>{const e=dt.value;if(W){const t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value,s=U+e-mt-(o<Z?Z:o);return{height:s<0?0:s>ht?ht:s}}const t=e<0?Z:tt,o=be.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>pe?pe:s}},[dt,W,U,ht,mt,be,Z,tt,pe]),pt=we>=0,bt=useMemo(()=>buildStyles(H),[H]),vt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),yt=useMemo(()=>({testID:V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||runOnJS(vt)()}}),[vt,V]),gt=useTapGesture(yt),wt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Ee)return null;const Ct=_jsxs(View,{collapsable:!1,style:["modal"===N?bt.backdropModal:bt.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??pt,children:[_jsx(GestureDetector,{gesture:gt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??pt,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[bt.sheet,{height:pe,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ht,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ft],children:_jsxs(SheetBody,{style:[bt.body,St],keyboardOffset:dt,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:lt,children:_jsx(View,{style:bt.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[bt.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[bt.header,R],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),m?_jsx(GestureDetector,{gesture:at,children:_jsx(ScrollView,{ref:f,style:bt.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:b,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[bt.content,{overflow:"visible"}]:bt.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[bt.footer,T],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:bt.actions,children:_jsx(OverlayActions,{actions:O??[],layout:E})}):null,k]})]})})]}),xt=_jsx(BottomSheetContext.Provider,{value:wt,children:Ct});return"modal"===N?_jsx(Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:bt.modalRoot,children:xt}):xt}):xt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
1
+ "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:r,onSnapChange:n,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:p,onScrollLayout:b,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:x="sheet",animateMount:w=!0,handleIndicatorStyle:C,containerStyle:M,header:_,actions:O,actionsLayout:R="auto",footer:E,headerStyle:k,footerStyle:T,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=_||null!=d,L=null!=O&&O.length>0,P=null!=E||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===x||"auto"===x&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[re,ne]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?re:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),p?.(e,t)},[te,p,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,pe=fe[fe.length-1]??0,be=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[xe,we]=useState(-1),Ce=useRef(!1),[Me,Oe]=useState(!1),[Re,Ee]=useState(!1),ke=useRef(!1),Te=useRef(i);Te.current=i;const[Ae,Ie]=useState(!1),je=useRef(!w&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Re:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;xe!==e&&(we(e),ge.value=e,e>=0&&n?.(e))},[xe,ge,n]),Je=useCallback(()=>{Ce.current=!1,ge.value<0&&(ke.current=!0,"modal"===N?(Oe(!1),"ios"!==Platform.OS&&Ee(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{ke.current&&Ee(!1)},[]);useEffect(()=>{("modal"===N?!Re:!Ae)&&ke.current&&(ke.current=!1,Te.current?.(),Ge(!0))},[N,Re,Ae,Ge]);const Ye=useCallback((e,t,o)=>{Ce.current=!0,a?.(t,o),be.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,be,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):Math.max(xe,0),o=ge.value,s=Fe(t);return ke.current=!1,Ge(!1),"modal"===N?(Ee(!0),Oe(!0)):Ie(!0),o<0&&je.current?(be.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(be.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(be.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,xe,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,be,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),Ce.current=!0,a?.(t,-1);const o=G.reduced?ye:be,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,be,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const r=s();"boolean"!=typeof r?(Pe.current=!0,o?.(),r.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(r?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null),et=useRef(Ke);et.current=Ke;const tt=useRef($e);tt.current=$e,useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?et.current(r??0):tt.current():o&&"number"==typeof r&&r!==ge.value&&et.current(r)},[o,r,ge]);const ot=useRef({hostHeight:U,contentSnap:he}),st=useRef(Fe);st.current=Fe,useEffect(()=>{const e=ot.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(ot.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=st.current(ge.value);be.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he,ge,be]);const rt=U-pe,nt=useMemo(()=>fe.map(e=>U-e),[fe,U]),at=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),it=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},at,at)},[Ye,$e,ge,We,Ue,at]),lt=useMemo(()=>({testID:V?`${V}-content-gesture`:"bottom-sheet-content-gesture"}),[V]),ut=useNativeGesture(lt),ct=useMemo(()=>{const e=nt,t=Se,o=rt,s=l;return{testID:V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";ve.value=be.value},onUpdate:e=>{"worklet";const t=ve.value+e.translationY;be.value=t<o?o+.25*(t-o):t},onDeactivate:o=>{"worklet";const r=be.value,n=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(it)(-1,t);if(n>1e3)return s?void runOnJS(it)(-1,t):void runOnJS(it)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(r-t);e<u&&(u=e,l=t,i=c),c++}s&&r-a>80?runOnJS(it)(-1,t):runOnJS(it)(i,l)}}},[Se,ve,l,it,rt,nt,V,be]),dt=usePanGesture(ct),{height:ht}=useReanimatedKeyboardAnimation(),mt="shift"===y,ft=useDerivedValue(()=>mt?ht.value:0,[mt,ht]),St=fe[Math.max(xe,0)]??pe,pt=H.space.md,bt=useAnimatedStyle(()=>{if(W){const e=ft.value,t=U+e-St-pt,o=e<0&&be.value>t?t:be.value;return{top:Math.max(o,Z),opacity:ye.value}}const e=be.value+ft.value,t=ft.value<0?Z:rt;return{top:Math.max(e,t),opacity:ye.value}},[W,ft,U,St,pt,be,Z,ye,rt]),vt=useAnimatedStyle(()=>{const e=ft.value;if(W){const t=U+e-St-pt,o=e<0&&be.value>t?t:be.value,s=Math.max(o,Z),r=U+e-pt-s;return{height:r<0?0:Math.min(r,St)}}const t=e<0?Z:rt,o=be.value+e,s=Math.max(o,t),r=U+e-s;return{height:r<0?0:Math.min(r,pe)}},[ft,W,U,St,pt,be,Z,rt,pe]),yt=xe>=0,gt=useMemo(()=>buildStyles(H),[H]),xt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),wt=useMemo(()=>({testID:V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||runOnJS(xt)()}}),[xt,V]),Ct=useTapGesture(wt),Mt=useMemo(()=>({snapIndex:xe,snapPoints:fe,close:qe,requestClose:Xe}),[xe,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Re)return null;const _t=_jsxs(View,{collapsable:!1,style:["modal"===N?gt.backdropModal:gt.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??yt,children:[_jsx(GestureDetector,{gesture:Ct,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??yt,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[gt.sheet,{height:pe,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:St,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,M,bt],children:_jsxs(SheetBody,{style:[gt.body,vt],keyboardOffset:ft,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:dt,children:_jsx(View,{style:gt.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[gt.handle,{backgroundColor:H.colors.border},C]})})}),B&&_jsxs(View,{style:[gt.header,k],onLayout:te?ne:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,_]}),m?_jsx(GestureDetector,{gesture:ut,children:_jsx(ScrollView,{ref:f,style:gt.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:b,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[gt.content,{overflow:"visible"}]:gt.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[gt.footer,T],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:gt.actions,children:_jsx(OverlayActions,{actions:O??[],layout:R})}):null,E]})]})})]}),Ot=_jsx(BottomSheetContext.Provider,{value:Mt,children:_t});return"modal"===N?_jsx(Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:gt.modalRoot,children:Ot}):Ot}):Ot},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,r=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:Math.max(e,0)}},[s,t]);return _jsx(Animated.View,{style:[e,r],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/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";export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,t)=>{const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,containerStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:C,accessibilityHint:_,accessibilityState:v,testID:I,onLayout:j,labels:T,...k}=e;assertValidValue("Button","variant",e.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",e.size,["xs","sm","md","lg","xl"]);const w=useTheme(),F=w.settings.components.button,L=r??F?.defaultVariant??"solid",V=i??F?.defaultSize??"md",A=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...T}),[T]),[R,O]=useState(!1),P=useRef(!1),z=n||R,B=!l&&!z,E={...v,disabled:!B,busy:z},D="link"===L,H=y??F?.defaultPressAnimation??(!D&&"scale"),W=usePressAnimation({preset:H||"scale",enabled:!1!==H&&B}),N=useFlickGuard(),M=useMemo(()=>buildStyles(w),[w]),U=useMemo(()=>resolveButtonSize(w,V),[w,V]),q=useMemo(()=>toneFor(w,s),[w,s]),G=useMemo(()=>variantFor(w,L,q,l),[w,L,q,l]),K=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?w.settings.gradients[m]??null:m,[m,l,L,w.settings.gradients]),X=StyleSheet.flatten(f)?.borderRadius,Y=D?0:"number"==typeof X?X:p?w.radius.pill:U.radius,J=useSquircle(!K&&"link"!==L,Y,j),Q=useRef(createAnimatedValue(0)).current,[Z,$]=useState(0),[ee,te]=useState(null),oe=D?e=>$(e.nativeEvent.layout.width):void 0,settlePending=()=>{P.current=!1,O(!1)},re=C??o,se="outline"===L||"ghost"===L,ie=!se&&!D,ne={color:G.textColor,size:U.icon,disabled:l},le=b&&!D&&Boolean(d),ae=w.space.xs,de=U["min-height"]-2*ae-2*G.borderWidth,ce={color:G.badgeInk,size:U["badge-icon"],disabled:l},ue=z?_jsx(Spinner,{variant:"circular",size:"sm",color:le?G.badgeInk:G.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,le?ce:ne,u)}):null,be=_jsxs(View,{style:M.contentRow,children:[le?_jsx(View,{testID:"button-icon-badge",style:[M.iconLeft,M.iconBadge,{width:de,height:de,borderRadius:de/2,backgroundColor:G.badgeFill}],children:ue}):ue?_jsx(View,{style:M.iconLeft,children:ue}):null,_jsxs(View,{onLayout:oe,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[M.label,{color:G.textColor,fontSize:U.text,lineHeight:Math.round(U.text*w.leading.body)},x],children:o}),D?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[M.linkUnderline,{backgroundColor:G.textColor,transform:[{translateX:Q.interpolate({inputRange:[0,1],outputRange:[-Z/2,0]})},{scaleX:Q.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:M.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,ne,u)}):null]}),ge=D?null===ee?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(ee)):touchSlopFor(U["min-height"]),pe={top:ge,bottom:ge,left:D?LINK_HIT_SLOP:0,right:D?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[W.style,a?M.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!B||P.current||N.isFlick(e))return;W.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t);const o=S?.(e);return o instanceof Promise?(P.current=!0,O(!0),o.then(settlePending,e=>{throw settlePending(),e})):void 0},onPressIn:e=>{N.onPressIn(e),W.pressIn(),D&&B&&(Q.stopAnimation(),Q.setValue(0),Animated.timing(Q,{toValue:1,duration:w.motion.duration.slower,easing:Easing.bezier(...w.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{W.pressOut()},disabled:!B,hitSlop:pe,...hitSlopMarker(pe),accessibilityRole:"button",accessibilityLabel:re,accessibilityHint:_,accessibilityState:E,...ariaFromState(E),testID:I,onLayout:e=>{J.onLayout(e),D&&te(e.nativeEvent.layout.height)},style:({pressed:e})=>[M.base,{paddingHorizontal:D?0:U["padding-x"],paddingVertical:D?0:le?ae:U["padding-y"],paddingLeft:le?ae:void 0,minHeight:D?void 0:U["min-height"],borderRadius:Y,...smoothCorners,backgroundColor:K||J.active?"transparent":G.backgroundColor,borderWidth:G.borderWidth,borderColor:J.active?"transparent":G.borderColor,opacity:z?.55:1,overflow:J.active||D?"visible":"hidden"},e&&se&&!J.active?{backgroundColor:w.colors["surface-pressed"]}:null,a?M.fullWidth:null,f],...k,"aria-disabled":!B,"aria-busy":z,children:({pressed:e})=>_jsxs(_Fragment,{children:[J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:e&&se?w.colors["surface-pressed"]:G.backgroundColor,stroke:G.borderColor,strokeWidth:G.borderWidth}):null,K?_jsx(Gradient,{gradient:K,style:[StyleSheet.absoluteFill,{borderRadius:Y,...smoothCorners}]}):null,e&&ie?J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:G.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[M.pressedOverlay,{borderRadius:Y,backgroundColor:G.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,be]})})})});Button.displayName="Button";const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const 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:e.size.border},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
1
+ "use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/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";export const BUTTON_VARIANTS=["solid","soft","outline","ghost","link","glass"];export const BUTTON_TONES=["primary","success","warning","danger","info","neutral"];export function isButtonVariant(e){return BUTTON_VARIANTS.some(t=>t===e)}export function isButtonTone(e){return BUTTON_TONES.some(t=>t===e)}export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,t)=>{const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,containerStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:T,accessibilityHint:C,accessibilityState:_,testID:I,onLayout:v,labels:j,...k}=e;assertValidValue("Button","variant",e.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",e.size,["xs","sm","md","lg","xl"]);const w=useTheme(),F=w.settings.components.button,L=r??F?.defaultVariant??"solid",V=i??F?.defaultSize??"md",O=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...j}),[j]),[A,R]=useState(!1),B=useRef(!1),N=n||A,E=!l&&!N,P={..._,disabled:!E,busy:N},z="link"===L,D=y??F?.defaultPressAnimation??(!z&&"scale"),H=usePressAnimation({preset:D||"scale",enabled:!1!==D&&E}),W=useFlickGuard(),M=useMemo(()=>buildStyles(w),[w]),U=useMemo(()=>resolveButtonSize(w,V),[w,V]),q=useMemo(()=>toneFor(w,s),[w,s]),G=useMemo(()=>variantFor(w,L,q,l),[w,L,q,l]),K=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?w.settings.gradients[m]??null:m,[m,l,L,w.settings.gradients]),X=StyleSheet.flatten(f)?.borderRadius,Y=z?0:"number"==typeof X?X:p?w.radius.pill:U.radius,J=useSquircle(!K&&"link"!==L,Y,v),Q=useRef(createAnimatedValue(0)).current,[Z,$]=useState(0),[ee,te]=useState(null),oe=z?e=>$(e.nativeEvent.layout.width):void 0,settlePending=()=>{B.current=!1,R(!1)},re=T??o,se="outline"===L||"ghost"===L,ie=!se&&!z,ne={color:G.textColor,size:U.icon,disabled:l},le=b&&!z&&Boolean(d),ae=w.space.xs,de=U["min-height"]-2*ae-2*G.borderWidth,ce={color:G.badgeInk,size:U["badge-icon"],disabled:l},ue=N?_jsx(Spinner,{variant:"circular",size:"sm",color:le?G.badgeInk:G.textColor,accessibilityLabel:O.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,le?ce:ne,u)}):null,be=_jsxs(View,{style:M.contentRow,children:[le?_jsx(View,{testID:"button-icon-badge",style:[M.iconLeft,M.iconBadge,{width:de,height:de,borderRadius:de/2,backgroundColor:G.badgeFill}],children:ue}):ue?_jsx(View,{style:M.iconLeft,children:ue}):null,_jsxs(View,{onLayout:oe,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[M.label,{color:G.textColor,fontSize:U.text,lineHeight:Math.round(U.text*w.leading.body)},x],children:o}),z?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[M.linkUnderline,{backgroundColor:G.textColor,transform:[{translateX:Q.interpolate({inputRange:[0,1],outputRange:[-Z/2,0]})},{scaleX:Q.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:M.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,ne,u)}):null]}),ge=z?null===ee?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(ee)):touchSlopFor(U["min-height"]),pe={top:ge,bottom:ge,left:z?LINK_HIT_SLOP:0,right:z?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[H.style,a?M.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!E||B.current||W.isFlick(e))return;H.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t);const o=S?.(e);return o instanceof Promise?(B.current=!0,R(!0),o.then(settlePending,e=>{throw settlePending(),e})):void 0},onPressIn:e=>{W.onPressIn(e),H.pressIn(),z&&E&&(Q.stopAnimation(),Q.setValue(0),Animated.timing(Q,{toValue:1,duration:w.motion.duration.slower,easing:Easing.bezier(...w.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{H.pressOut()},disabled:!E,hitSlop:pe,...hitSlopMarker(pe),accessibilityRole:"button",accessibilityLabel:re,accessibilityHint:C,accessibilityState:P,...ariaFromState(P),testID:I,onLayout:e=>{J.onLayout(e),z&&te(e.nativeEvent.layout.height)},style:({pressed:e})=>[M.base,{paddingHorizontal:z?0:U["padding-x"],paddingVertical:z?0:le?ae:U["padding-y"],paddingLeft:le?ae:void 0,minHeight:z?void 0:U["min-height"],borderRadius:Y,...smoothCorners,backgroundColor:K||J.active?"transparent":G.backgroundColor,borderWidth:G.borderWidth,borderColor:J.active?"transparent":G.borderColor,opacity:N?.55:1,overflow:J.active||z?"visible":"hidden"},e&&se&&!J.active?{backgroundColor:w.colors["surface-pressed"]}:null,a?M.fullWidth:null,f],...k,"aria-disabled":!E,"aria-busy":N,children:({pressed:e})=>_jsxs(_Fragment,{children:[J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:e&&se?w.colors["surface-pressed"]:G.backgroundColor,stroke:G.borderColor,strokeWidth:G.borderWidth}):null,K?_jsx(Gradient,{gradient:K,style:[StyleSheet.absoluteFill,{borderRadius:Y,...smoothCorners}]}):null,e&&ie?J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:G.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[M.pressedOverlay,{borderRadius:Y,backgroundColor:G.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,be]})})})});Button.displayName="Button";const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const 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:e.size.border},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
@@ -1 +1 @@
1
- "use strict";export{Button,buttonLabelInk,default}from"./Button.js";
1
+ "use strict";export{BUTTON_TONES,BUTTON_VARIANTS,Button,buttonLabelInk,default,isButtonTone,isButtonVariant}from"./Button.js";
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,AppState,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CAROUSEL_LABELS=Object.freeze({carousel:"Carousel",slideOf:(e,t)=>`Slide ${e} of ${t}`,goToSlide:e=>`Go to slide ${e}`});function CarouselRoot({ref:e,...t}){const{data:n,renderItem:r,keyExtractor:i,index:s,defaultIndex:a=0,onIndexChange:l,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:b=0,containerStyle:p,accessibilityLabel:f,testID:y,showThumbnails:x=!1,haptic:S,renderThumbnail:v,loading:w=!1,labels:C}=t;assertValidValue("Carousel","paginationStyle",t.paginationStyle,["dots","bars","numbers"]);const T=useMemo(()=>({...DEFAULT_CAROUSEL_LABELS,...C}),[C]),j=useTheme(),I=d||c,[k,_]=useState(()=>Dimensions.get("window").width),A="screen"===g?k:g,E=A+b,R=useRef(null),V=useRef(createAnimatedValue(0)).current,L=clamp("number"==typeof s?s:a,0,Math.max(0,n.length-1)),[D,O]=useState(L),H=useRef(null),M=useRef(null),P=useRef(!1),z=useRef(D);z.current=D;const N=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));O(e=>e===t?e:(l?.(t),t))},[n.length,l]),W=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);R.current?.scrollToOffset({offset:r*E,animated:t}),N(r)},[n.length,E,N]),F=useCallback(()=>{if(0===n.length)return;const e=z.current+1;e>=n.length?I&&W(0,!1):W(e,!0)},[n.length,I,W]),$=useCallback(()=>{if(0===n.length)return;const e=z.current-1;e<0?I&&W(n.length-1,!1):W(e,!0)},[n.length,I,W]);useImperativeHandle(e,()=>({scrollTo:W,next:F,prev:$}),[W,F,$]),useEffect(()=>{"number"==typeof s&&s!==D&&W(s,!0)},[s]);const U=useCallback(()=>{H.current&&(clearInterval(H.current),H.current=null)},[]),B=useCallback(()=>{!c||n.length<=1||(U(),H.current=setInterval(()=>{if(P.current)return;const e=z.current+1;e>=n.length?W(0,!1):W(e,!0)},u))},[c,u,n.length,W,U]);useEffect(()=>(B(),()=>{U(),M.current&&clearTimeout(M.current)}),[B,U]),useEffect(()=>{const e=AppState.addEventListener("change",e=>{"active"!==e?(U(),M.current&&(clearTimeout(M.current),M.current=null)):B()});return()=>e.remove()},[B,U]);const G=m&&n.length>1&&"numbers"!==h||void 0!==o,K=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:V}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[V,o]),X=useCallback(e=>{if(E<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/E);N(n)},[E,N]),q=useCallback(()=>{P.current=!0,U(),M.current&&(clearTimeout(M.current),M.current=null)},[U]),J=useCallback(()=>{P.current=!1,c&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{B()},1e3))},[c,B]),Q=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":F();break;case"decrement":$()}},[F,$]),Y=useMemo(()=>buildStyles(j),[j]),Z=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:A,marginRight:t===n.length-1?0:b},accessibilityElementsHidden:t!==D,importantForAccessibility:t===D?"yes":"no-hide-descendants",children:r(e,t)}),[r,A,b,n.length,D]),ee=useCallback((e,t)=>String(t),[]),te=useCallback((e,t)=>({length:E,offset:E*t,index:t}),[E]);return w?_jsx(CarouselSkeleton,{...t,containerWidth:k}):_jsxs(View,{style:[Y.container,p],onLayout:e=>_(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:f??T.carousel,accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:D,text:T.slideOf(D+1,n.length)},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:y,children:[_jsx(FlatList,{ref:R,data:n,keyExtractor:i??ee,renderItem:Z,horizontal:!0,pagingEnabled:"screen"===g&&0===b,snapToInterval:E,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:G?K:void 0,scrollEventThrottle:G?16:void 0,onMomentumScrollEnd:X,onScrollBeginDrag:q,onScrollEndDrag:J,getItemLayout:te,initialScrollIndex:L,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:D,scrollX:V,slideStride:E,variant:h,theme:j,labels:T}):null,x&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:D,renderThumbnail:v,labels:T,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),W(e,!0)},theme:j}):null]})}CarouselRoot.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const s=useTheme(),a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:s.space.md}],children:SKELETON_PAGINATION_DOTS.map(e=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:s.space.xs}}:"bars"===n?{width:20,height:4,radius:"pill",style:{marginHorizontal:s.space.xxs}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:s.space.xs}},e))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const SKELETON_PAGINATION_DOTS=["first","second","third"],carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=Object.assign(CarouselRoot,{Skeleton:CarouselSkeleton}),Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:s,labels:a})=>{const l=useMemo(()=>buildPaginationStyles(s),[s]);if("numbers"===i)return _jsx(View,{style:l.numbersWrap,children:_jsx(Text,{variant:"bodySmall",weight:"medium",color:"secondary",style:l.numbersText,accessibilityLabel:a.slideOf(t+1,e),children:`${t+1} / ${e}`})});const o=Array.from({length:e},(e,t)=>t),c="bars"===i,u=c?24:6,d=c?36:16,m=c?3:6;return _jsx(View,{style:l.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],a=n.interpolate({inputRange:i,outputRange:[u,d,u],extrapolate:"clamp"}),l=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:a,height:m,marginHorizontal:s.space.xs,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:e===t?s.colors.primary:s.colors.border,opacity:l}]},e)})})};function ThumbnailStrip({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i,labels:s}){const a=useMemo(()=>buildThumbStyles(i),[i]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:a.row,accessibilityRole:"tablist",children:e.map((e,l)=>_jsx(ThumbnailItem,{item:e,index:l,isActive:l===t,renderThumbnail:n,onPress:()=>r(l),theme:i,styles:a,labels:s},l))})}function ThumbnailItem({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:s,styles:a,labels:l}){const o=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(o,{toValue:n?1.1:1,useNativeDriver:nativeDriver,friction:6,tension:80});return e.start(),()=>e.stop()},[n,o]);const c=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:a.image,resizeMode:"cover"}):_jsx(View,{style:[a.placeholder,{backgroundColor:s.colors["bg-subtle"]}],children:_jsx(Text,{variant:"caption",weight:"semibold",color:"secondary",children:t+1})}),[e,t,r,s,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:l.goToSlide(t+1),children:_jsx(Animated.View,{style:[a.thumb,{borderColor:n?s.colors.primary:"transparent",transform:[{scale:o}]}],children:c})})}const buildThumbStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.sm,paddingVertical:e.space.sm},thumb:{width:40,height:40,marginHorizontal:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),buildPaginationStyles=e=>StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
1
+ "use strict";import{useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,AppState,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CAROUSEL_LABELS=Object.freeze({carousel:"Carousel",slideOf:(e,t)=>`Slide ${e} of ${t}`,goToSlide:e=>`Go to slide ${e}`});function CarouselRoot({ref:e,...t}){const{data:n,renderItem:r,keyExtractor:i,index:s,defaultIndex:a=0,onIndexChange:l,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:b=0,containerStyle:p,accessibilityLabel:f,testID:y,showThumbnails:x=!1,haptic:S,renderThumbnail:v,loading:w=!1,labels:C}=t;assertValidValue("Carousel","paginationStyle",t.paginationStyle,["dots","bars","numbers"]);const T=useMemo(()=>({...DEFAULT_CAROUSEL_LABELS,...C}),[C]),j=useTheme(),k=d||c,[I,_]=useState(()=>Dimensions.get("window").width),A="screen"===g?I:g,E=A+b,R=useRef(null),V=useRef(createAnimatedValue(0)).current,L=clamp("number"==typeof s?s:a,0,Math.max(0,n.length-1)),[D,O]=useState(L),H=useRef(null),M=useRef(null),P=useRef(!1),z=useRef(D);z.current=D;const N=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));O(e=>e===t?e:(l?.(t),t))},[n.length,l]),W=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);R.current?.scrollToOffset({offset:r*E,animated:t}),N(r)},[n.length,E,N]),F=useRef(W);F.current=W;const $=useCallback(()=>{if(0===n.length)return;const e=z.current+1;e>=n.length?k&&W(0,!1):W(e,!0)},[n.length,k,W]),U=useCallback(()=>{if(0===n.length)return;const e=z.current-1;e<0?k&&W(n.length-1,!1):W(e,!0)},[n.length,k,W]);useImperativeHandle(e,()=>({scrollTo:W,next:$,prev:U}),[W,$,U]),useEffect(()=>{"number"==typeof s&&s!==z.current&&F.current(s,!0)},[s]);const B=useCallback(()=>{H.current&&(clearInterval(H.current),H.current=null)},[]),G=useCallback(()=>{!c||n.length<=1||(B(),H.current=setInterval(()=>{if(P.current)return;const e=z.current+1;e>=n.length?W(0,!1):W(e,!0)},u))},[c,u,n.length,W,B]);useEffect(()=>(G(),()=>{B(),M.current&&clearTimeout(M.current)}),[G,B]),useEffect(()=>{const e=AppState.addEventListener("change",e=>{"active"!==e?(B(),M.current&&(clearTimeout(M.current),M.current=null)):G()});return()=>e.remove()},[G,B]);const K=m&&n.length>1&&"numbers"!==h||void 0!==o,X=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:V}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[V,o]),q=useCallback(e=>{if(E<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/E);N(n)},[E,N]),J=useCallback(()=>{P.current=!0,B(),M.current&&(clearTimeout(M.current),M.current=null)},[B]),Q=useCallback(()=>{P.current=!1,c&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{G()},1e3))},[c,G]),Y=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":$();break;case"decrement":U()}},[$,U]),Z=useMemo(()=>buildStyles(j),[j]),ee=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:A,marginRight:t===n.length-1?0:b},accessibilityElementsHidden:t!==D,importantForAccessibility:t===D?"yes":"no-hide-descendants",children:r(e,t)}),[r,A,b,n.length,D]),te=useCallback((e,t)=>String(t),[]),ne=useCallback((e,t)=>({length:E,offset:E*t,index:t}),[E]);return w?_jsx(CarouselSkeleton,{...t,containerWidth:I}):_jsxs(View,{style:[Z.container,p],onLayout:e=>_(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:f??T.carousel,accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:D,text:T.slideOf(D+1,n.length)},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Y,testID:y,children:[_jsx(FlatList,{ref:R,data:n,keyExtractor:i??te,renderItem:ee,horizontal:!0,pagingEnabled:"screen"===g&&0===b,snapToInterval:E,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:K?X:void 0,scrollEventThrottle:K?16:void 0,onMomentumScrollEnd:q,onScrollBeginDrag:J,onScrollEndDrag:Q,getItemLayout:ne,initialScrollIndex:L,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:D,scrollX:V,slideStride:E,variant:h,theme:j,labels:T}):null,x&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:D,renderThumbnail:v,labels:T,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),W(e,!0)},theme:j}):null]})}CarouselRoot.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const s=useTheme(),a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:s.space.md}],children:SKELETON_PAGINATION_DOTS.map(e=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:s.space.xs}}:"bars"===n?{width:20,height:4,radius:"pill",style:{marginHorizontal:s.space.xxs}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:s.space.xs}},e))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const SKELETON_PAGINATION_DOTS=["first","second","third"],carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=Object.assign(CarouselRoot,{Skeleton:CarouselSkeleton}),Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:s,labels:a})=>{const l=useMemo(()=>buildPaginationStyles(s),[s]);if("numbers"===i)return _jsx(View,{style:l.numbersWrap,children:_jsx(Text,{variant:"bodySmall",weight:"medium",color:"secondary",style:l.numbersText,accessibilityLabel:a.slideOf(t+1,e),children:`${t+1} / ${e}`})});const o=Array.from({length:e},(e,t)=>t),c="bars"===i,u=c?24:6,d=c?36:16,m=c?3:6;return _jsx(View,{style:l.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],a=n.interpolate({inputRange:i,outputRange:[u,d,u],extrapolate:"clamp"}),l=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:a,height:m,marginHorizontal:s.space.xs,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:e===t?s.colors.primary:s.colors.border,opacity:l}]},e)})})};function ThumbnailStrip({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i,labels:s}){const a=useMemo(()=>buildThumbStyles(i),[i]),l=useMemo(()=>e.map((e,t)=>({key:`thumb-${t}`,item:e,index:t})),[e]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:a.row,accessibilityRole:"tablist",children:l.map(({key:e,item:l,index:o})=>_jsx(ThumbnailItem,{item:l,index:o,isActive:o===t,renderThumbnail:n,onPress:()=>r(o),theme:i,styles:a,labels:s},e))})}function ThumbnailItem({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:s,styles:a,labels:l}){const o=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(o,{toValue:n?1.1:1,useNativeDriver:nativeDriver,friction:6,tension:80});return e.start(),()=>e.stop()},[n,o]);const c=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:a.image,resizeMode:"cover"}):_jsx(View,{style:[a.placeholder,{backgroundColor:s.colors["bg-subtle"]}],children:_jsx(Text,{variant:"caption",weight:"semibold",color:"secondary",children:t+1})}),[e,t,r,s,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:l.goToSlide(t+1),children:_jsx(Animated.View,{style:[a.thumb,{borderColor:n?s.colors.primary:"transparent",transform:[{scale:o}]}],children:c})})}const buildThumbStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.sm,paddingVertical:e.space.sm},thumb:{width:40,height:40,marginHorizontal:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),buildPaginationStyles=e=>StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveCheckboxSize,spaceOf,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CHECKBOX_SHAPES=["circle"],toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:a=!1,label:l,helperText:n,description:c,error:d,help:h,size:u="md",tone:p="primary",shape:m,accessibilityLabel:f,haptic:x,style:b,boxStyle:g,indeterminateBarStyle:y,containerStyle:C,labelStyle:S,testID:w,hitSlop:k,...j}=e,[v,V]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),{"box-size":D}=useMemo(()=>resolveCheckboxSize(T,u),[T,u]),R=T.size.border,A=spaceOf(T,T.components.checkbox["label-gap"]),H=toneColor(T,p),M=k??6;assertValidValue("Checkbox","shape",m,CHECKBOX_SHAPES),assertValidValue("Checkbox","size",e.size,["sm","md","lg"]),assertValidValue("Checkbox","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const P="circle"===m,z="string"==typeof d?d:void 0,B={description:c,helperText:n,error:z},F=v||i,I=useRef(createAnimatedValue(F?1:0)).current;useEffect(()=>{const e=Animated.spring(I,{toValue:F?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[F,I,T.motion.spring.snappy]);const L=I.interpolate({inputRange:[0,1],outputRange:[0,1]}),O=f??fieldTextAsString(l),E=!0===d||hasFieldText(d),W=F?H:a?T.colors.border:E?T.colors["field-border-error"]:T.colors.border,K=F?H:a?T.colors["surface-disabled"]:"transparent",N=a&&!F?T.colors["text-disabled"]:toneOnColor(T,p),X=Math.round(.72*D),U=Math.round(.55*D),q=Math.max(2,Math.round(.12*D)),G=_jsxs(Pressable,{ref:r,onPress:e=>{if(a)return;const r=resolveHaptic(x,"selection");r&&triggerHaptic(r),V(!v),j.onPressOut?.(e)},disabled:a,accessibilityRole:"checkbox",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(n??c),accessibilityState:{checked:i?"mixed":v,disabled:a},"aria-checked":i?"mixed":v,"aria-disabled":a,testID:w,hitSlop:M,...hitSlopMarker(M),...j,style:({pressed:e})=>[_.row,hasChoiceDetail(B)?_.rowTop:null,hasFieldText(h)?_.rowShrink:null,{opacity:a?.55:e?.85:1},C,b],children:[_jsx(View,{style:[_.box,{width:D,height:D,borderWidth:R,borderRadius:P?D/2:T.radius.sm,...P?{}:smoothCorners,borderColor:W,backgroundColor:K},g],children:_jsx(Animated.View,{style:[_.glyphWrap,{opacity:I,transform:[{scale:L}]}],children:i?_jsx(View,{style:[{width:U,height:q,borderRadius:T.radius.pill,...smoothCorners,backgroundColor:N},y]}):_jsx(Svg,{width:X,height:X,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:N,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),_jsx(ChoiceText,{label:l,helperText:n,description:c,error:z,disabled:a,style:{marginLeft:A},labelStyle:S})]});return hasFieldText(h)?_jsxs(View,{style:[_.helpRow,hasChoiceDetail(B)?_.rowTop:null],children:[G,_jsx(View,{style:[_.help,{marginLeft:T.space.xs}],children:h})]}):G});Checkbox.displayName="Checkbox";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});export{Checkbox};export default Checkbox;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveCheckboxSize,spaceOf,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CHECKBOX_SHAPES=["circle"],toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:a=!1,label:l,helperText:n,description:c,error:d,help:h,size:u="md",tone:p="primary",shape:m,accessibilityLabel:f,haptic:x,style:b,boxStyle:g,indeterminateBarStyle:y,containerStyle:C,labelStyle:S,testID:w,hitSlop:k,...j}=e,[v,V]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),{"box-size":A}=useMemo(()=>resolveCheckboxSize(T,u),[T,u]),D=T.size.border,R=spaceOf(T,T.components.checkbox["label-gap"]),H=toneColor(T,p),M=k??6;assertValidValue("Checkbox","shape",m,CHECKBOX_SHAPES),assertValidValue("Checkbox","size",e.size,["sm","md","lg"]),assertValidValue("Checkbox","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const P="circle"===m,z="string"==typeof d?d:void 0,B={description:c,helperText:n,error:z},F=v||i,I=useRef(createAnimatedValue(F?1:0)).current;useEffect(()=>{const e=Animated.spring(I,{toValue:F?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[F,I,T.motion.spring.snappy]);const L=I.interpolate({inputRange:[0,1],outputRange:[0,1]}),O=f??fieldTextAsString(l),E=!0===d||hasFieldText(d),W=F?H:a?T.colors.border:E?T.colors["field-border-error"]:T.colors.border,K=F?H:a?T.colors["surface-disabled"]:"transparent",N=a&&!F?T.colors["text-disabled"]:toneOnColor(T,p),X=Math.round(.72*A),U=Math.round(.55*A),q=Math.max(2,Math.round(.12*A)),G=_jsxs(Pressable,{ref:r,onPress:e=>{if(a)return;const r=resolveHaptic(x,"selection");r&&triggerHaptic(r),V(!v),j.onPressOut?.(e)},disabled:a,accessibilityRole:"checkbox",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(n)??fieldTextAsString(c),accessibilityState:{checked:i?"mixed":v,disabled:a},"aria-checked":i?"mixed":v,"aria-disabled":a,testID:w,hitSlop:M,...hitSlopMarker(M),...j,style:({pressed:e})=>[_.row,hasChoiceDetail(B)?_.rowTop:null,hasFieldText(h)?_.rowShrink:null,{opacity:a?.55:e?.85:1},C,b],children:[_jsx(View,{style:[_.box,{width:A,height:A,borderWidth:D,borderRadius:P?A/2:T.radius.sm,...P?{}:smoothCorners,borderColor:W,backgroundColor:K},g],children:_jsx(Animated.View,{style:[_.glyphWrap,{opacity:I,transform:[{scale:L}]}],children:i?_jsx(View,{style:[{width:U,height:q,borderRadius:T.radius.pill,...smoothCorners,backgroundColor:N},y]}):_jsx(Svg,{width:X,height:X,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:N,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),_jsx(ChoiceText,{label:l,helperText:n,description:c,error:z,disabled:a,style:{marginLeft:R},labelStyle:S})]});return hasFieldText(h)?_jsxs(View,{style:[_.helpRow,hasChoiceDetail(B)?_.rowTop:null],children:[G,_jsx(View,{style:[_.help,{marginLeft:T.space.xs}],children:h})]}):G});Checkbox.displayName="Checkbox";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});export{Checkbox};export default Checkbox;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{isRecord}from"../../utils/guards.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),isChoiceOption=e=>isRecord(e)&&("string"==typeof e.value||"number"==typeof e.value);function ChoiceGroup(e){const{ref:i,options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:s,getOptionDescription:l,getOptionIcon:a,getOptionColor:n,renderOption:c,variant:d="card",indicatorPosition:p="trailing",direction:u="row",gap:h,wrap:m=!1,fullWidth:g,disabled:b=!1,size:x="md",labelLines:f,descriptionLines:y=2,haptic:C,accessibilityLabel:z,style:v,optionStyle:j,description:V,helperText:S,error:H,testID:w}=e,O=useTheme(),T=useMemo(()=>buildStyles(O),[O]),_=useMemo(()=>sizeTokensOf(O)[x],[O,x]);assertValidValue("ChoiceGroup","variant",e.variant,["card","chip"]),assertValidValue("ChoiceGroup","size",e.size,["sm","md","lg"]),assertValidValue("ChoiceGroup","direction",e.direction,["row","column"]),assertValidValue("ChoiceGroup","indicatorPosition",e.indicatorPosition,["leading","trailing"]),assertValidValue("ChoiceGroup","selectionMode",e.selectionMode,["single","multiple"]);const k=useCallback(e=>t?t(e):isChoiceOption(e)?e.label??"":"",[t]),G=useCallback(e=>{if(r)return r(e);if(isChoiceOption(e))return e.value;throw new Error("ChoiceGroup option has no value; pass getOptionValue.")},[r]),D=useCallback(e=>s?s(e):isChoiceOption(e)&&!0===e.disabled,[s]),M=useCallback(e=>l?l(e):isChoiceOption(e)?e.description:void 0,[l]),L=useCallback(e=>a?a(e):isChoiceOption(e)?e.icon:void 0,[a]),P=useCallback(e=>n?n(e):isChoiceOption(e)?e.color:void 0,[n]),I="multiple"===e.selectionMode,{min:R,max:A}=e,F=useCallback(i=>{if("multiple"!==e.selectionMode){if("string"!=typeof i&&"number"!=typeof i)throw new Error(`ChoiceGroup received a ${Array.isArray(i)?"list":"missing"} value in single mode.`);e.onChange?.(i)}else{if(!Array.isArray(i))throw new Error("ChoiceGroup received a single value in multiple mode.");e.onChange?.(i)}},[e.onChange,e.selectionMode]),[W,E]=useControllableState({value:e.value,defaultValue:e.defaultValue??(I?[]:void 0),onChange:F}),B=Array.isArray(W)?W:[],$=useCallback(e=>{const i=G(e);if(I){const e=B.includes(i);if(e&&null!=R&&B.length<=R)return;if(!e&&null!=A&&B.length>=A)return;const o=resolveHaptic(C,"selection");return o&&triggerHaptic(o),void E(e?B.filter(e=>e!==i):[...B,i])}const o=resolveHaptic(C,"selection");o&&triggerHaptic(o),E(i)},[C,I,R,A,B,E,G]),N=g??("card"===d&&"row"===u&&!m),q=m||N&&"row"===u,J=O.radius.md,surfaceFor=(e,i,o)=>i?{borderColor:O.colors.border,backgroundColor:O.colors["surface-disabled"]}:{borderColor:e?o:O.colors.border,backgroundColor:e?tintOf(o,.12,O.colors["surface-selected"]):O.colors.bg},renderIcon=(e,i,o,t)=>{const r=L(e);if(null==r)return null;return renderSlotIcon("string"==typeof r&&i?{name:r,variant:"bold"}:r,{color:o,size:_.iconSize,disabled:t})},renderChip=e=>{const{option:i,selected:o,disabled:t,color:r}=e,s=t?O.colors["text-disabled"]:o?r:O.colors["text-body"],l=renderIcon(i,o,s,t);return _jsxs(View,{style:[T.chip,{minHeight:_.minHeight,paddingHorizontal:_.chipPaddingHorizontal,paddingVertical:_.paddingVertical,borderRadius:O.radius.pill,...smoothCorners,borderWidth:O.size.border,...surfaceFor(o,t,r),columnGap:O.space.xs}],children:[l?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:l}):null,_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[T.cardLabel,{color:s,fontSize:_.fontSize,lineHeight:Math.round(_.fontSize*O.leading.body)}],children:k(i)})]})},renderDefaultCard=e=>{const{option:i,selected:o,disabled:t,color:r}=e,s=P(i),l=t?O.colors["text-disabled"]:s??O.colors["text-body"],a=M(i),n=renderIcon(i,o,l,t),c=_jsx(RadioDot,{selected:o,color:r,disabled:t,size:x});return _jsxs(View,{style:[T.card,{minHeight:_.minHeight,paddingHorizontal:_.paddingHorizontal,paddingVertical:_.paddingVertical,borderRadius:J,...smoothCorners,borderWidth:O.size.border,...surfaceFor(o,t,r),columnGap:O.space.sm}],children:["leading"===p?c:null,n?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:n}):null,_jsxs(View,{style:T.cardTextWrap,children:[_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[T.cardLabel,{color:l,fontSize:_.fontSize,lineHeight:Math.round(_.fontSize*O.leading.body)}],children:k(i)}),a?_jsx(Text,{numberOfLines:y,ellipsizeMode:"tail",style:[T.cardDescription,{color:o?O.colors["text-muted"]:O.colors["text-subtle"],fontSize:O.text.xs.size,lineHeight:Math.round(O.text.xs.size*O.leading.body)}],children:a}):null]}),"trailing"===p?c:null]})},K="string"==typeof H&&""!==H?H:void 0,Q=!0===H||void 0!==K?null:S,U=_jsx(View,{ref:i,accessibilityRole:I?void 0:"radiogroup",accessibilityLabel:z,accessibilityState:{disabled:b},"aria-disabled":b,testID:w,style:[{flexDirection:u,gap:h??O.space.sm,flexWrap:q?"wrap":"nowrap"},v],children:o.map((e,i)=>{const o=G(e),t=I?B.includes(o):W===o,r=I&&null!=A&&!t&&B.length>=A,s=b||r||D(e),l=P(e)??O.colors.primary,a=c||"card"!==d?void 0:M(e);return _jsx(Pressable,{testID:isChoiceOption(e)?e.testID:void 0,onPress:()=>{s||$(e)},disabled:s,accessibilityRole:I?"checkbox":"radio",accessibilityLabel:a?`${k(e)}, ${a}`:k(e),accessibilityState:{checked:t,disabled:s},"aria-checked":t,"aria-disabled":s,style:[N?T.stretchOption:null,{opacity:s&&c?.55:1},j],children:({pressed:o})=>{const r={option:e,index:i,selected:t,pressed:o&&!s,disabled:s,color:l};return _jsx(_Fragment,{children:c?c(r):"chip"===d?renderChip(r):renderDefaultCard(r)})}},String(o))})});return hasChoiceDetail({description:V,error:K,helperText:Q??void 0})?_jsxs(View,{children:[V?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginBottom:O.space.xs},children:V}):null,U,void 0!==K?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",style:{marginTop:O.space.xs},children:K}):Q?_jsx(Text,{variant:"caption",color:"tertiary",style:{marginTop:O.space.xs},children:Q}):null]}):U}ChoiceGroup.displayName="ChoiceGroup";const buildStyles=e=>StyleSheet.create({stretchOption:{flexGrow:1,flexShrink:0,flexBasis:"auto"},card:{flexDirection:"row",alignItems:"center"},chip:{flexDirection:"row",alignItems:"center",justifyContent:"center"},cardTextWrap:{flexGrow:1,flexShrink:1,flexBasis:"auto"},cardLabel:{includeFontPadding:!1},cardDescription:{includeFontPadding:!1,marginTop:e.space.xxs}});export{ChoiceGroup};export default ChoiceGroup;
1
+ "use strict";import{useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{isRecord}from"../../utils/guards.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),isChoiceOption=e=>isRecord(e)&&("string"==typeof e.value||"number"==typeof e.value);function ChoiceGroup(e){const{ref:i,options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:s,getOptionDescription:l,getOptionIcon:a,getOptionColor:n,renderOption:c,variant:d="card",indicatorPosition:p="trailing",direction:u="row",gap:h,wrap:m=!1,fullWidth:g,disabled:b=!1,size:x="md",labelLines:f,descriptionLines:y=2,haptic:C,accessibilityLabel:z,style:v,optionStyle:j,description:V,helperText:S,error:H,testID:w}=e,O=useTheme(),T=useMemo(()=>buildStyles(O),[O]),_=useMemo(()=>sizeTokensOf(O)[x],[O,x]);assertValidValue("ChoiceGroup","variant",e.variant,["card","chip"]),assertValidValue("ChoiceGroup","size",e.size,["sm","md","lg"]),assertValidValue("ChoiceGroup","direction",e.direction,["row","column"]),assertValidValue("ChoiceGroup","indicatorPosition",e.indicatorPosition,["leading","trailing"]),assertValidValue("ChoiceGroup","selectionMode",e.selectionMode,["single","multiple"]);const k=useCallback(e=>t?t(e):isChoiceOption(e)?e.label??"":"",[t]),G=useCallback(e=>{if(r)return r(e);if(isChoiceOption(e))return e.value;throw new Error("ChoiceGroup option has no value; pass getOptionValue.")},[r]),D=useCallback(e=>s?s(e):isChoiceOption(e)&&!0===e.disabled,[s]),M=useCallback(e=>l?l(e):isChoiceOption(e)?e.description:void 0,[l]),L=useCallback(e=>a?a(e):isChoiceOption(e)?e.icon:void 0,[a]),P=useCallback(e=>n?n(e):isChoiceOption(e)?e.color:void 0,[n]),I="multiple"===e.selectionMode,{min:R,max:A}=e,F=useCallback(i=>{if("multiple"!==e.selectionMode){if("string"!=typeof i&&"number"!=typeof i)throw new Error(`ChoiceGroup received a ${Array.isArray(i)?"list":"missing"} value in single mode.`);e.onChange?.(i)}else{if(!Array.isArray(i))throw new Error("ChoiceGroup received a single value in multiple mode.");e.onChange?.(i)}},[e.onChange,e.selectionMode]),[W,E]=useControllableState({controlled:"value"in e,value:e.value,defaultValue:e.defaultValue??(I?[]:void 0),onChange:F}),B=Array.isArray(W)?W:[],$=useCallback(e=>{const i=G(e);if(I){const e=B.includes(i);if(e&&null!=R&&B.length<=R)return;if(!e&&null!=A&&B.length>=A)return;const o=resolveHaptic(C,"selection");return o&&triggerHaptic(o),void E(e?B.filter(e=>e!==i):[...B,i])}const o=resolveHaptic(C,"selection");o&&triggerHaptic(o),E(i)},[C,I,R,A,B,E,G]),N=g??("card"===d&&"row"===u&&!m),q=m||N&&"row"===u,J=O.radius.md,surfaceFor=(e,i,o)=>i?{borderColor:O.colors.border,backgroundColor:O.colors["surface-disabled"]}:{borderColor:e?o:O.colors.border,backgroundColor:e?tintOf(o,.12,O.colors["surface-selected"]):O.colors.bg},renderIcon=(e,i,o,t)=>{const r=L(e);if(null==r)return null;return renderSlotIcon("string"==typeof r&&i?{name:r,variant:"bold"}:r,{color:o,size:_.iconSize,disabled:t})},renderChip=e=>{const{option:i,selected:o,disabled:t,color:r}=e,s=t?O.colors["text-disabled"]:o?r:O.colors["text-body"],l=renderIcon(i,o,s,t);return _jsxs(View,{style:[T.chip,{minHeight:_.minHeight,paddingHorizontal:_.chipPaddingHorizontal,paddingVertical:_.paddingVertical,borderRadius:O.radius.pill,...smoothCorners,borderWidth:O.size.border,...surfaceFor(o,t,r),columnGap:O.space.xs}],children:[l?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:l}):null,_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[T.cardLabel,{color:s,fontSize:_.fontSize,lineHeight:Math.round(_.fontSize*O.leading.body)}],children:k(i)})]})},renderDefaultCard=e=>{const{option:i,selected:o,disabled:t,color:r}=e,s=P(i),l=t?O.colors["text-disabled"]:s??O.colors["text-body"],a=M(i),n=renderIcon(i,o,l,t),c=_jsx(RadioDot,{selected:o,color:r,disabled:t,size:x});return _jsxs(View,{style:[T.card,{minHeight:_.minHeight,paddingHorizontal:_.paddingHorizontal,paddingVertical:_.paddingVertical,borderRadius:J,...smoothCorners,borderWidth:O.size.border,...surfaceFor(o,t,r),columnGap:O.space.sm}],children:["leading"===p?c:null,n?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:n}):null,_jsxs(View,{style:T.cardTextWrap,children:[_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[T.cardLabel,{color:l,fontSize:_.fontSize,lineHeight:Math.round(_.fontSize*O.leading.body)}],children:k(i)}),a?_jsx(Text,{numberOfLines:y,ellipsizeMode:"tail",style:[T.cardDescription,{color:o?O.colors["text-muted"]:O.colors["text-subtle"],fontSize:O.text.xs.size,lineHeight:Math.round(O.text.xs.size*O.leading.body)}],children:a}):null]}),"trailing"===p?c:null]})},K="string"==typeof H&&""!==H?H:void 0,Q=!0===H||void 0!==K?null:S,U=_jsx(View,{ref:i,accessibilityRole:I?void 0:"radiogroup",accessibilityLabel:z,accessibilityState:{disabled:b},"aria-disabled":b,testID:w,style:[{flexDirection:u,gap:h??O.space.sm,flexWrap:q?"wrap":"nowrap"},v],children:o.map((e,i)=>{const o=G(e),t=I?B.includes(o):W===o,r=I&&null!=A&&!t&&B.length>=A,s=b||r||D(e),l=P(e)??O.colors.primary,a=c||"card"!==d?void 0:M(e);return _jsx(Pressable,{testID:isChoiceOption(e)?e.testID:void 0,onPress:()=>{s||$(e)},disabled:s,accessibilityRole:I?"checkbox":"radio",accessibilityLabel:a?`${k(e)}, ${a}`:k(e),accessibilityState:{checked:t,disabled:s},"aria-checked":t,"aria-disabled":s,style:[N?T.stretchOption:null,{opacity:s&&c?.55:1},j],children:({pressed:o})=>{const r={option:e,index:i,selected:t,pressed:o&&!s,disabled:s,color:l};return _jsx(_Fragment,{children:c?c(r):"chip"===d?renderChip(r):renderDefaultCard(r)})}},String(o))})});return hasChoiceDetail({description:V,error:K,helperText:Q??void 0})?_jsxs(View,{children:[V?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginBottom:O.space.xs},children:V}):null,U,void 0!==K?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",style:{marginTop:O.space.xs},children:K}):Q?_jsx(Text,{variant:"caption",color:"tertiary",style:{marginTop:O.space.xs},children:Q}):null]}):U}ChoiceGroup.displayName="ChoiceGroup";const buildStyles=e=>StyleSheet.create({stretchOption:{flexGrow:1,flexShrink:0,flexBasis:"auto"},card:{flexDirection:"row",alignItems:"center"},chip:{flexDirection:"row",alignItems:"center",justifyContent:"center"},cardTextWrap:{flexGrow:1,flexShrink:1,flexBasis:"auto"},cardLabel:{includeFontPadding:!1},cardDescription:{includeFontPadding:!1,marginTop:e.space.xxs}});export{ChoiceGroup};export default ChoiceGroup;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useState}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withRepeat,withTiming}from"react-native-reanimated";import Svg,{Path,Polygon}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx}from"react/jsx-runtime";const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6};export const DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0};const PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),itemAt=(e,a,r)=>{const t=e[a];if(void 0===t)throw new Error(`Confetti needs at least one ${r}`);return t},pick=e=>itemAt(e,Math.floor(Math.random()*e.length),"shape"),randomSign=()=>Math.random()<.5?1:-1,commonPiece=(e,a)=>({color:itemAt(e.colors,a%e.colors.length,"colour"),size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:randomSign(),flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const r=e.physics.spread>0?e.physics.spread/2:100,t=(-90+rand(-r,r))*DEG,s=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(t)*s*.7,vyFrac:Math.sin(t)*s,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const r=Math.max(1,Math.round(e/4)),t=a.physics.spread>0?a.physics.spread/2:180,s=[];for(let i=0;i<4&&s.length<e;i+=1){const o=rand(.18,.82),n=rand(.18,.52),c=i/4*.5+rand(0,.06);for(let i=0;i<r&&s.length<e;i+=1){const e=rand(-t,t)*DEG,r=rand(1.4,3.4)*a.physics.velocity;s.push({...commonPiece(a,s.length),x0Frac:o,y0Frac:n,vxFrac:Math.cos(e)*r*.7,vyFrac:Math.sin(e)*r,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:c,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return s};export const buildPieces=(e,a,r)=>{if("fireworks"===a)return buildFireworks(e,r);const t="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>t(r,a))};const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:_jsx(Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:_jsx(Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:r,height:t,fadeOut:s})=>{const i=useAnimatedStyle(()=>{const i=1-e.delay,o=i<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/i)),n=(1-Math.exp(-e.drag*o))/e.drag,c=e.x0Frac*r+e.vxFrac*r*n,l=e.y0Frac*t+e.terminalFrac*t*o+(e.vyFrac-e.terminalFrac)*t*n,d=Math.sin(o*e.swayFreq*TAU)*e.swayAmp,h=e.rotateDir*e.rotations*360*o,p=.35+.65*Math.abs(Math.cos(o*e.flutterFreq*TAU));return{opacity:s?Math.max(0,1-Math.max(0,o-.75)/.25):1,transform:[{translateX:c+d},{translateY:l},{rotate:`${h}deg`},{scaleY:p}]}},[e,a,r,t,s]),o=SHAPE_BOX[e.shape],n="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return _jsx(Animated.View,{style:[{position:"absolute",width:e.size*o.w,height:e.size*o.h,borderRadius:"circle"===e.shape?e.size*o.h/2:1,backgroundColor:n?"transparent":e.color},i],children:_jsx(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=forwardRef(({count:e=80,colors:a,preset:r="pop",shapes:t,speed:s="normal",physics:i,origin:o,duration:n=2800,fadeOut:c=!0,autoStart:l=!1,recycle:d=!1,size:h=10,onComplete:p,style:m,testID:u},y)=>{assertValidValue("Confetti","preset",r,["pop","rain","fireworks"]),assertValidValue("Confetti","speed",s,["slow","normal","fast"]);for(const e of t??[])assertValidValue("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const S=useTheme(),g=useReducedMotion(),f=useWindowDimensions(),[w,F]=useState({width:f.width,height:f.height}),[v,A]=useState(!1),[P,x]=useState([]),E=useMemo(()=>a??[S.colors.primary,S.colors.neutral,S.colors.success,S.colors.warning,S.colors.danger,S.colors.info],[a,S.colors]),M=useSharedValue(0),T=n*SPEED_FACTOR[s],_=useCallback(()=>{A(!1),p?.()},[p]),C=useCallback(()=>{if(g)return void p?.();cancelAnimation(M),M.value=0,x(buildPieces(e,r,{colors:E,baseSize:h,originXFrac:o?o.x/Math.max(1,w.width):.5,originYFrac:o?o.y/Math.max(1,w.height):.5,physics:{velocity:void 0===i?.velocity?DEFAULT_PHYSICS.velocity:i.velocity,drag:void 0===i?.drag?DEFAULT_PHYSICS.drag:i.drag,fallSpeed:void 0===i?.fallSpeed?DEFAULT_PHYSICS.fallSpeed:i.fallSpeed,spread:void 0===i?.spread?DEFAULT_PHYSICS.spread:i.spread},shapes:t??PRESET_SHAPES[r]})),A(!0);const a=withTiming(1,{duration:T,easing:Easing.linear},e=>{"worklet";e&&!d&&runOnJS(_)()});M.value=d?withRepeat(a,-1,!1):a},[g,M,T,d,_,p,e,E,r,t,i,h,o,w.width,w.height]),R=useCallback(()=>{cancelAnimation(M),A(!1)},[M]);useImperativeHandle(y,()=>({start:C,stop:R}),[C,R]),useEffect(()=>(l&&C(),()=>cancelAnimation(M)),[]);const k=useCallback(e=>{const{width:a,height:r}=e.nativeEvent.layout;a>0&&r>0&&F({width:a,height:r})},[]);return _jsx(View,{style:[StyleSheet.absoluteFill,m],pointerEvents:"none",onLayout:k,testID:u,children:v?P.map((e,a)=>_jsx(ConfettiPiece,{piece:e,progress:M,width:w.width,height:w.height,fadeOut:c},a)):null})});Confetti.displayName="Confetti";export{Confetti};export default Confetti;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withRepeat,withTiming}from"react-native-reanimated";import Svg,{Path,Polygon}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx}from"react/jsx-runtime";const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6};export const DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0};const PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),itemAt=(e,a,r)=>{const t=e[a];if(void 0===t)throw new Error(`Confetti needs at least one ${r}`);return t},pick=e=>itemAt(e,Math.floor(Math.random()*e.length),"shape"),randomSign=()=>Math.random()<.5?1:-1,commonPiece=(e,a)=>({color:itemAt(e.colors,a%e.colors.length,"colour"),size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:randomSign(),flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const r=e.physics.spread>0?e.physics.spread/2:100,t=(-90+rand(-r,r))*DEG,s=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(t)*s*.7,vyFrac:Math.sin(t)*s,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const r=Math.max(1,Math.round(e/4)),t=a.physics.spread>0?a.physics.spread/2:180,s=[];for(let i=0;i<4&&s.length<e;i+=1){const o=rand(.18,.82),n=rand(.18,.52),c=i/4*.5+rand(0,.06);for(let i=0;i<r&&s.length<e;i+=1){const e=rand(-t,t)*DEG,r=rand(1.4,3.4)*a.physics.velocity;s.push({...commonPiece(a,s.length),x0Frac:o,y0Frac:n,vxFrac:Math.cos(e)*r*.7,vyFrac:Math.sin(e)*r,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:c,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return s};export const buildPieces=(e,a,r)=>{if("fireworks"===a)return buildFireworks(e,r);const t="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>t(r,a))};const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:_jsx(Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:_jsx(Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:r,height:t,fadeOut:s})=>{const i=useAnimatedStyle(()=>{const i=1-e.delay,o=i<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/i)),n=(1-Math.exp(-e.drag*o))/e.drag,c=e.x0Frac*r+e.vxFrac*r*n,l=e.y0Frac*t+e.terminalFrac*t*o+(e.vyFrac-e.terminalFrac)*t*n,d=Math.sin(o*e.swayFreq*TAU)*e.swayAmp,h=e.rotateDir*e.rotations*360*o,p=.35+.65*Math.abs(Math.cos(o*e.flutterFreq*TAU));return{opacity:s?Math.max(0,1-Math.max(0,o-.75)/.25):1,transform:[{translateX:c+d},{translateY:l},{rotate:`${h}deg`},{scaleY:p}]}},[e,a,r,t,s]),o=SHAPE_BOX[e.shape],n="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return _jsx(Animated.View,{style:[{position:"absolute",width:e.size*o.w,height:e.size*o.h,borderRadius:"circle"===e.shape?e.size*o.h/2:1,backgroundColor:n?"transparent":e.color},i],children:_jsx(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=forwardRef(({count:e=80,colors:a,preset:r="pop",shapes:t,speed:s="normal",physics:i,origin:o,duration:n=2800,fadeOut:c=!0,autoStart:l=!1,recycle:d=!1,size:h=10,onComplete:p,style:u,testID:m},y)=>{assertValidValue("Confetti","preset",r,["pop","rain","fireworks"]),assertValidValue("Confetti","speed",s,["slow","normal","fast"]);for(const e of t??[])assertValidValue("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const f=useTheme(),S=useReducedMotion(),g=useWindowDimensions(),[w,F]=useState({width:g.width,height:g.height}),[v,A]=useState(!1),[P,x]=useState([]),E=useMemo(()=>a??[f.colors.primary,f.colors.neutral,f.colors.success,f.colors.warning,f.colors.danger,f.colors.info],[a,f.colors]),M=useSharedValue(0),T=n*SPEED_FACTOR[s],_=useCallback(()=>{A(!1),p?.()},[p]),C=useCallback(()=>{if(S)return void p?.();cancelAnimation(M),M.value=0,x(buildPieces(e,r,{colors:E,baseSize:h,originXFrac:o?o.x/Math.max(1,w.width):.5,originYFrac:o?o.y/Math.max(1,w.height):.5,physics:{velocity:void 0===i?.velocity?DEFAULT_PHYSICS.velocity:i.velocity,drag:void 0===i?.drag?DEFAULT_PHYSICS.drag:i.drag,fallSpeed:void 0===i?.fallSpeed?DEFAULT_PHYSICS.fallSpeed:i.fallSpeed,spread:void 0===i?.spread?DEFAULT_PHYSICS.spread:i.spread},shapes:t??PRESET_SHAPES[r]})),A(!0);const a=withTiming(1,{duration:T,easing:Easing.linear},e=>{"worklet";e&&!d&&runOnJS(_)()});M.value=d?withRepeat(a,-1,!1):a},[S,M,T,d,_,p,e,E,r,t,i,h,o,w.width,w.height]),R=useCallback(()=>{cancelAnimation(M),A(!1)},[M]);useImperativeHandle(y,()=>({start:C,stop:R}),[C,R]);const k=useRef(l).current,I=useRef(C).current;useEffect(()=>(k&&I(),()=>cancelAnimation(M)),[M,k,I]);const b=useCallback(e=>{const{width:a,height:r}=e.nativeEvent.layout;a>0&&r>0&&F({width:a,height:r})},[]),D=useMemo(()=>P.map((e,a)=>({key:`confetti-${a}`,piece:e})),[P]);return _jsx(View,{style:[StyleSheet.absoluteFill,u],pointerEvents:"none",onLayout:b,testID:m,children:v?D.map(({key:e,piece:a})=>_jsx(ConfettiPiece,{piece:a,progress:M,width:w.width,height:w.height,fadeOut:c},e)):null})});Confetti.displayName="Confetti";export{Confetti};export default Confetti;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,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{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:i=!1,onOpenChange:o,side:r="left",width:s,enableSwipe:l=!0,enableBackdropPress:n=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:f,labels:h,testID:m}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...h}),[h]),v=usePresenceMotion(),S=v.reduced,E=v.duration("default"),w=v.duration("fast"),y=useSafeAreaInsets(),O="boolean"==typeof a,[D,M]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>M(e));return()=>e.remove()},[]);const _="left"===r||"right"===r,C=useMemo(()=>resolveSize(s,_,D),[s,_,D]),R=useMemo(()=>closedOffsetOf(r,C),[r,C]),T=useSharedValue(i?0:R),x=useSharedValue(i?0:R),A=useSharedValue(i?1:0),[L,k]=useState(i),V=useSharedValue(i);useEffect(()=>{L||S||(T.value=R,x.value=R)},[R,L,T,x,S]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(S)return T.value=0,void(A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));A.value=1,T.value=withSpring(0,j)},[T,A,j,S,E]),N=useCallback(()=>{S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,A,R,j,S,w]),P=useCallback(e=>{k(t=>t===e?t:(o?.(e),e)),V.value=e},[o,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{L?U():F()},[L,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]),useEffect(()=>{O&&a!==L&&(a?F():U())},[a]);const B=useMemo(()=>{const e=R,t=r,a=l;return{..._?{activeOffsetX:[-10,10],failOffsetY:[-15,15]}:{activeOffsetY:[-10,10],failOffsetX:[-15,15]},onActivate:()=>{"worklet";a&&(x.value=T.value)},onUpdate:t=>{"worklet";if(!a)return;const i=_?t.translationX:t.translationY,o=x.value+i,r=Math.min(0,e),s=Math.max(0,e);T.value=o<r?r+.25*(o-r):o>s?s+.25*(o-s):o},onDeactivate:i=>{"worklet";if(!a)return;const o=_?i.velocityX:i.velocityY,r=T.value;let s=!1;s="left"===t||"top"===t?o<-1e3:o>1e3;const l=Math.abs(e),n=Math.abs(r)/l;s||n>.5?(runOnJS(P)(!1),S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),S?(T.value=0,A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))}}},[R,x,l,_,T,A,P,r,j,S,E,w]),Y=usePanGesture(B),G=useAnimatedStyle(()=>_?{opacity:A.value,transform:[{translateX:T.value}]}:{opacity:A.value,transform:[{translateY:T.value}]},[_,T,A]),X=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*A.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,A]),J=useMemo(()=>buildStyles(g),[g]),z=useCallback(()=>{if(!n)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[n,U,c]),W=useMemo(()=>sideLayoutOf(r,C,y),[r,C,y]),q=useRef(i);return L&&(q.current=!0),q.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:m,accessibilityViewIsModal:L,children:[_jsx(Animated.View,{style:[J.backdrop,{backgroundColor:g.colors.scrim},X],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:z,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!n||!L})}),_jsx(GestureDetector,{gesture:Y,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:f??b.drawer,style:[W,{backgroundColor:g.colors.surface,...g.shadow.modal},d,G],children:_jsx(View,{style:J.content,children:p})})})]}):null});Drawer.displayName="Drawer";const closedOffsetOf=(e,t)=>{switch(e){case"left":case"top":return-t;case"right":case"bottom":return t}},sideLayoutOf=(e,t,a)=>{switch(e){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingLeft:a.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingRight:a.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:t,paddingTop:a.top,paddingLeft:a.left,paddingRight:a.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:t,paddingBottom:a.bottom,paddingLeft:a.left,paddingRight:a.right}}},resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);if(Number.isNaN(i))return t?280:Math.round(.4*a.height);return i/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,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{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:o=!1,onOpenChange:s,side:i="left",width:r,enableSwipe:n=!0,enableBackdropPress:l=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:f,labels:h,testID:m}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...h}),[h]),v=usePresenceMotion(),S=v.reduced,E=v.duration("default"),w=v.duration("fast"),y=useSafeAreaInsets(),O="boolean"==typeof a,[D,M]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>M(e));return()=>e.remove()},[]);const _="left"===i||"right"===i,C=useMemo(()=>resolveSize(r,_,D),[r,_,D]),R=useMemo(()=>closedOffsetOf(i,C),[i,C]),T=useSharedValue(o?0:R),x=useSharedValue(o?0:R),A=useSharedValue(o?1:0),[L,k]=useState(o),V=useSharedValue(o);useEffect(()=>{L||S||(T.value=R,x.value=R)},[R,L,T,x,S]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(S)return T.value=0,void(A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));A.value=1,T.value=withSpring(0,j)},[T,A,j,S,E]),N=useCallback(()=>{S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,A,R,j,S,w]),P=useCallback(e=>{k(t=>t===e?t:(s?.(e),e)),V.value=e},[s,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{L?U():F()},[L,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]);const B=useRef({isOpen:L,open:F,close:U});B.current={isOpen:L,open:F,close:U},useEffect(()=>{if(!O)return;const e=B.current;a!==e.isOpen&&(a?e.open():e.close())},[a,O]);const Y=useMemo(()=>{const e=R,t=i,a=n;return{..._?{activeOffsetX:[-10,10],failOffsetY:[-15,15]}:{activeOffsetY:[-10,10],failOffsetX:[-15,15]},onActivate:()=>{"worklet";a&&(x.value=T.value)},onUpdate:t=>{"worklet";if(!a)return;const o=_?t.translationX:t.translationY,s=x.value+o,i=Math.min(0,e),r=Math.max(0,e);T.value=s<i?i+.25*(s-i):s>r?r+.25*(s-r):s},onDeactivate:o=>{"worklet";if(!a)return;const s=_?o.velocityX:o.velocityY,i=T.value;let r=!1;r="left"===t||"top"===t?s<-1e3:s>1e3;const n=Math.abs(e),l=Math.abs(i)/n;r||l>.5?(runOnJS(P)(!1),S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),S?(T.value=0,A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))}}},[R,x,n,_,T,A,P,i,j,S,E,w]),G=usePanGesture(Y),X=useAnimatedStyle(()=>_?{opacity:A.value,transform:[{translateX:T.value}]}:{opacity:A.value,transform:[{translateY:T.value}]},[_,T,A]),J=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*A.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,A]),z=useMemo(()=>buildStyles(g),[g]),W=useCallback(()=>{if(!l)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[l,U,c]),q=useMemo(()=>sideLayoutOf(i,C,y),[i,C,y]),K=useRef(o);return L&&(K.current=!0),K.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:m,accessibilityViewIsModal:L,children:[_jsx(Animated.View,{style:[z.backdrop,{backgroundColor:g.colors.scrim},J],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:W,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!l||!L})}),_jsx(GestureDetector,{gesture:G,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:f??b.drawer,style:[q,{backgroundColor:g.colors.surface,...g.shadow.modal},d,X],children:_jsx(View,{style:z.content,children:p})})})]}):null});Drawer.displayName="Drawer";const closedOffsetOf=(e,t)=>{switch(e){case"left":case"top":return-t;case"right":case"bottom":return t}},sideLayoutOf=(e,t,a)=>{switch(e){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingLeft:a.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingRight:a.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:t,paddingTop:a.top,paddingLeft:a.left,paddingRight:a.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:t,paddingBottom:a.bottom,paddingLeft:a.left,paddingRight:a.right}}},resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const o=parseFloat(e);if(Number.isNaN(o))return t?280:Math.round(.4*a.height);return o/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;