@webority/mobile-ui 0.144.2 → 0.146.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-kit/kit.js +4429 -3708
- package/dist/canvas-kit/manifest.json +1 -1
- package/dist/canvas-kit/release.json +5 -5
- package/lib/commonjs/components/Accordion/Accordion.js +1 -1
- package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +1 -1
- package/lib/commonjs/components/AppBar/AppBar.js +1 -1
- package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
- package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/commonjs/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/commonjs/components/Autocomplete/Autocomplete.js +1 -1
- package/lib/commonjs/components/Avatar/Avatar.js +1 -1
- package/lib/commonjs/components/Badge/Badge.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Button/Button.js +1 -1
- package/lib/commonjs/components/Calendar/Calendar.js +1 -1
- package/lib/commonjs/components/Card/Card.js +1 -1
- package/lib/commonjs/components/Carousel/Carousel.js +1 -1
- package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
- package/lib/commonjs/components/Dialog/Dialog.js +1 -1
- package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
- package/lib/commonjs/components/Divider/Divider.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
- package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
- package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
- package/lib/commonjs/components/FileViewer/FileViewer.js +1 -1
- package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/FormField/FormField.js +1 -1
- package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +1 -1
- package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/ListItem/ListItem.js +1 -1
- package/lib/commonjs/components/ListSection/ListSection.js +1 -1
- package/lib/commonjs/components/Menu/Menu.js +1 -1
- package/lib/commonjs/components/Menu/useContextMenu.js +1 -1
- package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
- package/lib/commonjs/components/Modal/Modal.js +1 -1
- package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/PermissionPrompt/PermissionPrompt.js +1 -1
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/commonjs/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/commonjs/components/Radio/Radio.js +1 -1
- package/lib/commonjs/components/Rating/Rating.js +1 -1
- package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
- package/lib/commonjs/components/SectionHeader/SectionHeader.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/Select/Select.js +1 -1
- package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/commonjs/components/Slider/Slider.js +1 -1
- package/lib/commonjs/components/SliderField/SliderField.js +1 -1
- package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
- package/lib/commonjs/components/Spinner/Spinner.js +1 -1
- package/lib/commonjs/components/StatTile/StatTile.js +1 -1
- package/lib/commonjs/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/commonjs/components/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/Switch/Switch.js +1 -1
- package/lib/commonjs/components/Tabs/Tabs.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
- package/lib/commonjs/components/Timeline/Timeline.js +1 -1
- package/lib/commonjs/components/Toast/Toast.js +1 -1
- package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
- package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/commonjs/utils/assertValidValue.js +1 -0
- package/lib/module/components/Accordion/Accordion.js +1 -1
- package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/module/components/AnimatePresence/AnimatePresence.js +1 -1
- package/lib/module/components/AppBar/AppBar.js +1 -1
- package/lib/module/components/AppIcon/AppIcon.js +1 -1
- package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/module/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/module/components/Autocomplete/Autocomplete.js +1 -1
- package/lib/module/components/Avatar/Avatar.js +1 -1
- package/lib/module/components/Badge/Badge.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Button/Button.js +1 -1
- package/lib/module/components/Calendar/Calendar.js +1 -1
- package/lib/module/components/Card/Card.js +1 -1
- package/lib/module/components/Carousel/Carousel.js +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/Descriptions/Descriptions.js +1 -1
- package/lib/module/components/Dialog/Dialog.js +1 -1
- package/lib/module/components/Dialog/OverlayActions.js +1 -1
- package/lib/module/components/Divider/Divider.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/EmptyState/EmptyState.js +1 -1
- package/lib/module/components/FieldBase/FieldBase.js +1 -1
- package/lib/module/components/FilePicker/FilePicker.js +1 -1
- package/lib/module/components/FileViewer/FileViewer.js +1 -1
- package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/FormField/FormField.js +1 -1
- package/lib/module/components/IconBadge/IconBadge.js +1 -1
- package/lib/module/components/IconButton/IconButton.js +1 -1
- package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/ListItem/ListItem.js +1 -1
- package/lib/module/components/ListSection/ListSection.js +1 -1
- package/lib/module/components/Menu/Menu.js +1 -1
- package/lib/module/components/Menu/useContextMenu.js +1 -1
- package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
- package/lib/module/components/Modal/Modal.js +1 -1
- package/lib/module/components/NumberInput/NumberInput.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/PermissionPrompt/PermissionPrompt.js +1 -1
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/module/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/module/components/Radio/Radio.js +1 -1
- package/lib/module/components/Rating/Rating.js +1 -1
- package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.js +1 -1
- package/lib/module/components/SectionHeader/SectionHeader.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/Select/Select.js +1 -1
- package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/module/components/Skeleton/Skeleton.js +1 -1
- package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/module/components/Slider/Slider.js +1 -1
- package/lib/module/components/SliderField/SliderField.js +1 -1
- package/lib/module/components/Sparkline/Sparkline.js +1 -1
- package/lib/module/components/Spinner/Spinner.js +1 -1
- package/lib/module/components/StatTile/StatTile.js +1 -1
- package/lib/module/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/module/components/Stepper/Stepper.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/Switch/Switch.js +1 -1
- package/lib/module/components/Tabs/Tabs.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/TimePicker/TimePicker.js +1 -1
- package/lib/module/components/Timeline/Timeline.js +1 -1
- package/lib/module/components/Toast/Toast.js +1 -1
- package/lib/module/components/Tooltip/Tooltip.js +1 -1
- package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/module/utils/assertValidValue.js +1 -0
- package/lib/typescript/commonjs/utils/assertValidValue.d.ts +10 -0
- package/lib/typescript/module/utils/assertValidValue.d.ts +10 -0
- package/package.json +7 -7
- package/lib/commonjs/utils/warnInvalidValue.js +0 -1
- package/lib/module/utils/warnInvalidValue.js +0 -1
- package/lib/typescript/commonjs/utils/warnInvalidValue.d.ts +0 -10
- package/lib/typescript/module/utils/warnInvalidValue.d.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Toast=exports.DEFAULT_TOAST_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_warnInvalidValue=require("../../utils/warnInvalidValue.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_TOAST_LABELS=exports.DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`}),SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:a,shownAt:i,runtime:n})=>{const r=(0,_index.useTheme)(),s=(0,_usePresenceMotion.usePresenceMotion)(),o=s.duration("fast");(0,_warnInvalidValue.warnInvalidValue)("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_warnInvalidValue.warnInvalidValue)("Toast","position",e.position,["top","bottom"]);const c=e.tone??"neutral",l=e.position??"bottom",u=n?.labels??DEFAULT_TOAST_LABELS,d=(0,_react.useMemo)(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=(0,_react.useMemo)(()=>buildStyles(r),[r]),_=(0,_react.useMemo)(()=>tintFor(r,c),[r,c]),p=(0,_react.useMemo)(()=>inkFor(r,c),[r,c]),v=r.components.toast["icon-circle-size"],g=r.text[r.components.toast["icon-glyph-text"]].size,x=r.components.toast["tint-bar-width"],h=r.settings.components.toast?.defaultDurationMs??3e3,f=r.settings.components.toast?.enableSwipeDismiss??!0,b="top"===l?-120:120,N=(0,_react.useRef)((0,_index.createAnimatedValue)(s.reduced?0:b)).current,A=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,w=(0,_react.useRef)(!1),T="top"===l?8*t:8*-t,S=Math.max(1-.04*t,.9),R=(0,_react.useRef)((0,_index.createAnimatedValue)(T)).current;(0,_react.useEffect)(()=>{(0,_index.setNativeValue)(R,T)},[T,R]);const M=(0,_react.useMemo)(()=>_reactNative.Animated.add(N,R),[N,R]),V=void 0!==e.action,j=e.duration??h,D=j>0&&V&&"web"===_reactNative.Platform.OS?Math.max(j,8e3):j,E=D<=0||V&&!0===n?.screenReaderOn,C=!0===e.countdown&&!E,L=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,I=(0,_react.useRef)({initialised:!1,timer:null,remaining:0,startedAt:0}),O=(0,_react.useRef)({touch:!1,pan:!1,hover:!1}),P=(0,_react.useRef)(()=>{}),k=(0,_react.useRef)({id:e.id,totalMs:D,shownAt:i,runtime:n,persistent:E,animateBar:!1});k.current={id:e.id,totalMs:D,shownAt:i,runtime:n,persistent:E,animateBar:C&&!s.reduced};const B=(0,_react.useCallback)(()=>{const e=I.current,t=k.current,a=O.current;if(!e.initialised){e.initialised=!0;const a=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=a??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&(0,_index.setNativeValue)(L,e.remaining/t.totalMs)}const i=!(t.persistent||w.current||a.touch||a.pan||a.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,P.current()},e.remaining),t.animateBar&&_reactNative.Animated.timing(L,{toValue:0,duration:e.remaining,easing:_reactNative.Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),L.stopAnimation())},[L]),dismiss=()=>{if(w.current)return;w.current=!0,B();const t=[_reactNative.Animated.timing(y,{toValue:0,duration:o,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})];s.reduced||t.push(_reactNative.Animated.timing(N,{toValue:b,duration:r.motion.duration.fast,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})),_reactNative.Animated.parallel(t).start(()=>a(e.id))};P.current=dismiss,(0,_react.useEffect)(()=>{const e=s.reduced?_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),(0,_react.useEffect)(()=>{B()},[E,B]),(0,_react.useEffect)(()=>()=>{const e=I.current,t=k.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),L.stopAnimation(),e.initialised&&t.totalMs>0&&!w.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[L]);const H=(0,_react.useCallback)((e,t)=>{O.current[e]=t,B()},[B]),F=(0,_react.useCallback)(()=>H("touch",!0),[H]),q=(0,_react.useCallback)(e=>H("touch",(e.nativeEvent.touches?.length??0)>0),[H]),U=(0,_react.useCallback)(()=>H("hover",!0),[H]),z=(0,_react.useCallback)(()=>H("hover",!1),[H]),$=(0,_react.useMemo)(()=>_reactNative.PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>H("pan",!0),onPanResponderMove:(e,t)=>{(0,_index.setNativeValue)(A,t.dx);const a=1-.7*Math.min(Math.abs(t.dx)/200,1);(0,_index.setNativeValue)(y,a)},onPanResponderTerminate:()=>{if(H("pan",!1),s.reduced)return(0,_index.setNativeValue)(A,0),void _reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}).start();_reactNative.Animated.parallel([_reactNative.Animated.spring(A,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:!0}),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;w.current=!0,H("pan",!1);const n=[_reactNative.Animated.timing(y,{toValue:0,duration:o,useNativeDriver:!0})];s.reduced||n.push(_reactNative.Animated.timing(A,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:!0})),_reactNative.Animated.parallel(n).start(()=>a(e.id))}else H("pan",!1),s.reduced?((0,_index.setNativeValue)(A,0),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}).start()):_reactNative.Animated.parallel([_reactNative.Animated.spring(A,{toValue:0,useNativeDriver:!0}),_reactNative.Animated.spring(y,{toValue:1,useNativeDriver:!0})]).start()}}),[A,y,H,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,a,e.id]),G={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[W,K]=(0,_react.useState)(0),X=(0,_react.useMemo)(()=>L.interpolate({inputRange:[0,1],outputRange:[-W,0]}),[L,W]),Y=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&C?`${e.action.label}, ${u.seconds(Math.ceil(D/1e3))}`:e.action?.label;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{...f?$.panHandlers:{},...V?{}:{accessible:!0,...G},..."web"===_reactNative.Platform.OS?{onPointerEnter:U,onPointerLeave:z}:{},onTouchStart:F,onTouchEnd:q,onTouchCancel:q,accessibilityLabel:Y,testID:e.testID,style:[m.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,..._corners.smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:y,transform:[{translateY:M},{translateX:A},{scale:S}]},e.style],children:[x>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.tintBar,{width:x,backgroundColor:_}]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(c);return t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.iconCircle,{width:v,height:v,borderRadius:r.radius.pill,..._corners.smoothCorners,backgroundColor:`${_}22`},e.iconCircleStyle],children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",style:[m.iconGlyph,{color:p,fontSize:g}],accessible:!1,children:t})}):null})(),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.textBlock,children:[(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?(0,_jsxRuntime.jsx)(_index2.Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...(0,_hitSlop.hitSlopMarker)(ACTION_HIT_SLOP),...G,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"bodySmall",weight:"semibold",style:{color:_},numberOfLines:1,children:e.action.label})}):null]}),C?(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>K(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${_}22`}],children:[s.reduced?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.countdownFill,{backgroundColor:_}]}):null,!s.reduced&&W>0?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[m.countdownFill,{backgroundColor:_,transform:[{translateX:X}]}]}):null]}):null]})};exports.Toast=Toast;const tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>_reactNative.StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,..._corners.smoothCorners,marginLeft:e.space.sm}});var _default=exports.default=Toast;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Toast=exports.DEFAULT_TOAST_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_TOAST_LABELS=exports.DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`}),SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:a,shownAt:i,runtime:n})=>{const r=(0,_index.useTheme)(),s=(0,_usePresenceMotion.usePresenceMotion)(),o=s.duration("fast");(0,_assertValidValue.assertValidValue)("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("Toast","position",e.position,["top","bottom"]);const c=e.tone??"neutral",l=e.position??"bottom",u=n?.labels??DEFAULT_TOAST_LABELS,d=(0,_react.useMemo)(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=(0,_react.useMemo)(()=>buildStyles(r),[r]),_=(0,_react.useMemo)(()=>tintFor(r,c),[r,c]),p=(0,_react.useMemo)(()=>inkFor(r,c),[r,c]),g=r.components.toast["icon-circle-size"],v=r.text[r.components.toast["icon-glyph-text"]].size,x=r.components.toast["tint-bar-width"],h=r.settings.components.toast?.defaultDurationMs??3e3,f=r.settings.components.toast?.enableSwipeDismiss??!0,b="top"===l?-120:120,N=(0,_react.useRef)((0,_index.createAnimatedValue)(s.reduced?0:b)).current,A=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,T=(0,_react.useRef)(!1),S="top"===l?8*t:8*-t,w=Math.max(1-.04*t,.9),V=(0,_react.useRef)((0,_index.createAnimatedValue)(S)).current;(0,_react.useEffect)(()=>{(0,_index.setNativeValue)(V,S)},[S,V]);const R=(0,_react.useMemo)(()=>_reactNative.Animated.add(N,V),[N,V]),M=void 0!==e.action,j=e.duration??h,D=j>0&&M&&"web"===_reactNative.Platform.OS?Math.max(j,8e3):j,E=D<=0||M&&!0===n?.screenReaderOn,C=!0===e.countdown&&!E,L=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,O=(0,_react.useRef)({initialised:!1,timer:null,remaining:0,startedAt:0}),P=(0,_react.useRef)({touch:!1,pan:!1,hover:!1}),I=(0,_react.useRef)(()=>{}),k=(0,_react.useRef)({id:e.id,totalMs:D,shownAt:i,runtime:n,persistent:E,animateBar:!1});k.current={id:e.id,totalMs:D,shownAt:i,runtime:n,persistent:E,animateBar:C&&!s.reduced};const B=(0,_react.useCallback)(()=>{const e=O.current,t=k.current,a=P.current;if(!e.initialised){e.initialised=!0;const a=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=a??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&(0,_index.setNativeValue)(L,e.remaining/t.totalMs)}const i=!(t.persistent||T.current||a.touch||a.pan||a.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,I.current()},e.remaining),t.animateBar&&_reactNative.Animated.timing(L,{toValue:0,duration:e.remaining,easing:_reactNative.Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),L.stopAnimation())},[L]),dismiss=()=>{if(T.current)return;T.current=!0,B();const t=[_reactNative.Animated.timing(y,{toValue:0,duration:o,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})];s.reduced||t.push(_reactNative.Animated.timing(N,{toValue:b,duration:r.motion.duration.fast,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})),_reactNative.Animated.parallel(t).start(()=>a(e.id))};I.current=dismiss,(0,_react.useEffect)(()=>{const e=s.reduced?_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),(0,_react.useEffect)(()=>{B()},[E,B]),(0,_react.useEffect)(()=>()=>{const e=O.current,t=k.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),L.stopAnimation(),e.initialised&&t.totalMs>0&&!T.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[L]);const H=(0,_react.useCallback)((e,t)=>{P.current[e]=t,B()},[B]),F=(0,_react.useCallback)(()=>H("touch",!0),[H]),q=(0,_react.useCallback)(e=>H("touch",(e.nativeEvent.touches?.length??0)>0),[H]),U=(0,_react.useCallback)(()=>H("hover",!0),[H]),z=(0,_react.useCallback)(()=>H("hover",!1),[H]),$=(0,_react.useMemo)(()=>_reactNative.PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>H("pan",!0),onPanResponderMove:(e,t)=>{(0,_index.setNativeValue)(A,t.dx);const a=1-.7*Math.min(Math.abs(t.dx)/200,1);(0,_index.setNativeValue)(y,a)},onPanResponderTerminate:()=>{if(H("pan",!1),s.reduced)return(0,_index.setNativeValue)(A,0),void _reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}).start();_reactNative.Animated.parallel([_reactNative.Animated.spring(A,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:!0}),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;T.current=!0,H("pan",!1);const n=[_reactNative.Animated.timing(y,{toValue:0,duration:o,useNativeDriver:!0})];s.reduced||n.push(_reactNative.Animated.timing(A,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:!0})),_reactNative.Animated.parallel(n).start(()=>a(e.id))}else H("pan",!1),s.reduced?((0,_index.setNativeValue)(A,0),_reactNative.Animated.timing(y,{toValue:1,duration:o,useNativeDriver:!0}).start()):_reactNative.Animated.parallel([_reactNative.Animated.spring(A,{toValue:0,useNativeDriver:!0}),_reactNative.Animated.spring(y,{toValue:1,useNativeDriver:!0})]).start()}}),[A,y,H,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,a,e.id]),G={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[W,K]=(0,_react.useState)(0),X=(0,_react.useMemo)(()=>L.interpolate({inputRange:[0,1],outputRange:[-W,0]}),[L,W]),Y=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&C?`${e.action.label}, ${u.seconds(Math.ceil(D/1e3))}`:e.action?.label;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{...f?$.panHandlers:{},...M?{}:{accessible:!0,...G},..."web"===_reactNative.Platform.OS?{onPointerEnter:U,onPointerLeave:z}:{},onTouchStart:F,onTouchEnd:q,onTouchCancel:q,accessibilityLabel:Y,testID:e.testID,style:[m.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,..._corners.smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:y,transform:[{translateY:R},{translateX:A},{scale:w}]},e.style],children:[x>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.tintBar,{width:x,backgroundColor:_}]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(c);return t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.iconCircle,{width:g,height:g,borderRadius:r.radius.pill,..._corners.smoothCorners,backgroundColor:`${_}22`},e.iconCircleStyle],children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",style:[m.iconGlyph,{color:p,fontSize:v}],accessible:!1,children:t})}):null})(),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.textBlock,children:[(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?(0,_jsxRuntime.jsx)(_index2.Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...(0,_hitSlop.hitSlopMarker)(ACTION_HIT_SLOP),...G,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"bodySmall",weight:"semibold",style:{color:_},numberOfLines:1,children:e.action.label})}):null]}),C?(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>K(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${_}22`}],children:[s.reduced?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[m.countdownFill,{backgroundColor:_}]}):null,!s.reduced&&W>0?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[m.countdownFill,{backgroundColor:_,transform:[{translateX:X}]}]}):null]}):null]})};exports.Toast=Toast;const tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>_reactNative.StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,..._corners.smoothCorners,marginLeft:e.space.sm}});var _default=exports.default=Toast;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Tooltip=exports.DEFAULT_TOOLTIP_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Tooltip=exports.DEFAULT_TOOLTIP_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_mergeRefs=require("../../utils/mergeRefs.js"),_placement=require("../../utils/placement.js"),_focusHost=require("../Menu/focusHost.js"),_index2=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../Text/index.js"),_RichTooltipBody=require("./RichTooltipBody.js"),_tooltipPosition=require("./tooltipPosition.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var r,a,o=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(a in e)"default"!==a&&{}.hasOwnProperty.call(e,a)&&((r=o&&Object.getOwnPropertyDescriptor(e,a))&&(r.get||r.set)?o(s,a,r):s[a]=e[a]);return s}const DEFAULT_TOOLTIP_LABELS=exports.DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"}),PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:r,variant:a="plain",title:o,action:s,placement:i="auto",open:n,onOpenChange:c,hideOnContentPress:l=!0,maxWidth:u,showArrow:d=!0,accessibilityLabel:_,style:p,containerStyle:f,arrowStyle:m,messageStyle:h,labels:g,testID:v}=e;(0,_assertValidValue.assertValidValue)("Tooltip","variant",e.variant,["plain","rich"]),(0,_assertValidValue.assertValidValue)("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),(0,_assertValidValue.assertValidValue)("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const b="rich"===a,R=e.trigger??(b?"press":"longPress"),x=(0,_react.useMemo)(()=>({...DEFAULT_TOOLTIP_LABELS,...g}),[g]),T=(0,_index.useTheme)(),y=(0,_usePresenceMotion.usePresenceMotion)(),A=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),[S,j]=(0,_ModalSafeArea.useModalInsets)(),w=(0,_react.useMemo)(()=>({...A,top:S.top,bottom:S.bottom}),[A,S]),N=(0,_reactNative.useWindowDimensions)(),P=(0,_react.useMemo)(()=>buildStyles(T),[T]),O=T.space.sm,L=T.space.sm,E=u??(b?280:240),M="press"===R&&!b,V=(T.settings.components.tooltip?.enableScaleAnimation??!1)&&!y.reduced,C="manual"===R||"boolean"==typeof n,[D,H]=(0,_react.useState)(!1),I=C?Boolean(n):D,[q,W]=(0,_react.useState)(null),[k,B]=(0,_react.useState)({width:0,height:0}),F=(0,_react.useRef)(null),U=(0,_react.useRef)(null),z=(0,_react.useRef)(null),G=(0,_react.useRef)(null),X=(0,_react.useRef)(null),Y=(0,_react.useRef)(!1),J=(0,_react.useRef)(!1),K=(0,_react.useRef)((0,_index.createAnimatedValue)(I||!V?1:.85)).current,Q=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:0)).current,Z=(0,_react.useRef)(null),$=(0,_react.useRef)(!1),[ee,te]=(0,_react.useState)(I),re=(0,_react.useCallback)(e=>{C||H(e),c?.(e)},[C,c]),ae=(0,_react.useCallback)(()=>{F.current&&F.current.measureInWindow((e,t,r,a)=>{W({x:e,y:t,width:r,height:a})})},[]),oe=(0,_react.useCallback)(e=>{ae(),re(!0)},[ae,re]),se=(0,_react.useCallback)(()=>{re(!1)},[re]),ie=(0,_react.useRef)(se);ie.current=se;const ne=(0,_react.useCallback)(()=>{if(!Y.current)return;Y.current=!1;const e=X.current;X.current=null,e?e():b&&(0,_focusHost.focusHost)(U.current??F.current)},[b]);(0,_react.useEffect)(()=>{if(I)return J.current=!0,Y.current=!1,(0,_placement.claimAnchoredSurface)(()=>ie.current());J.current&&(J.current=!1,Y.current=!0)},[I]),(0,_react.useEffect)(()=>{I&&te(!0)},[I]);const ce=(0,_react.useCallback)(()=>{X.current=s?.onPress??null,se()},[s,se]);(0,_react.useEffect)(()=>{if(!$.current)return $.current=!0,I&&(ae(),M&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{se()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(I){ae();const t=[_reactNative.Animated.timing(Q,{toValue:1,duration:y.duration("fast"),useNativeDriver:!0})];V?t.push(_reactNative.Animated.spring(K,{toValue:1,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:!0})):(0,_index.setNativeValue)(K,1),e=_reactNative.Animated.parallel(t),e.start(),M&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{se()},4e3))}else{const t=[_reactNative.Animated.timing(Q,{toValue:0,duration:y.reduced?y.duration("fast"):150,easing:_reactNative.Easing.bezier(...T.motion.ease.accelerate),useNativeDriver:!0})];V&&t.push(_reactNative.Animated.timing(K,{toValue:.85,duration:150,easing:_reactNative.Easing.bezier(...T.motion.ease.accelerate),useNativeDriver:!0})),e=_reactNative.Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[I]);const handleContentLayout=e=>{const{width:t,height:r}=e.nativeEvent.layout;t===k.width&&r===k.height||B({width:t,height:r})},le=(0,_react.useMemo)(()=>(0,_tooltipPosition.resolveTooltipPosition)({anchor:q,size:k,placement:i,rich:b,viewport:{width:N.width,height:N.height,insets:w},maxWidth:E,gap:O,padding:L,arrowCornerPadding:12}),[q,k,i,b,N.width,N.height,w,E,O,L]),ue=null!==q&&k.width>0,de=I&&ue;(0,_react.useEffect)(()=>{if(!b||!de)return;const e="web"===_reactNative.Platform.OS?G:z,t=setTimeout(()=>(0,_focusHost.focusHost)(e.current),_focusHost.FOCUS_DELAY_MS);return()=>clearTimeout(t)},[b,de]),(0,_react.useEffect)(()=>{!b&&de&&"ios"===_reactNative.Platform.OS&&"string"==typeof t&&(0,_announce.announce)(t)},[b,de,t]);const pe=r.props,fe=(0,_react.useMemo)(()=>(0,_mergeRefs.mergeRefs)(pe.ref,U),[pe.ref]),me={};"longPress"!==R||pe.contextMenu?"press"===R&&(me.onPress=e=>{pe.onPress?.(e),oe(e)}):(me.onLongPress=oe,me.accessibilityHint=x.longPressHint),b&&(me.ref=fe);const he=_react.default.cloneElement(r,me),ge=_??("string"==typeof t?t:x.fallbackName),ve=(0,_react.useMemo)(()=>{if(!d)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:b?T.colors.surface:T.colors["surface-inverse"]};return"top"===le.placement?{...e,bottom:-6,left:le.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===le.placement?{...e,top:-6,left:le.arrowOffset-4}:"left"===le.placement?{...e,right:-6,top:le.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:le.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[d,le,T,b]),be={position:"absolute",top:le.top,left:le.left,maxWidth:E,opacity:I&&!ue?0:Q,transform:[{scale:K}]},Re=ve?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[ve,m],pointerEvents:"none"}):null;return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{ref:F,collapsable:!1,onLayout:ae,testID:v,children:he}),(0,_jsxRuntime.jsxs)(_index2.Modal,{open:ee,onClose:se,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:l,haptic:!1,labels:{close:x.close},onInsetsChange:j,onDismissed:ne,children:[ee&&b?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{onLayout:handleContentLayout,style:[be,f,p],children:[(0,_jsxRuntime.jsx)(_RichTooltipBody.RichTooltipBody,{title:o,content:t,action:s,onAction:ce,focusRef:z,actionRef:G,messageStyle:h}),Re]}):null,ee&&!b?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{accessibilityRole:"web"===_reactNative.Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[be,f,p],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[P.tooltip,{backgroundColor:T.colors["surface-inverse"],borderRadius:T.radius.md,..._corners.smoothCorners,paddingHorizontal:T.space.md,paddingVertical:T.space.sm,...T.shadow.popover,shadowColor:T.shadow.popover.shadowColor}],children:"string"==typeof t?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,..._reactNative.StyleSheet.flatten(h)},children:t}):t}),Re]}):null]})]})};exports.Tooltip=Tooltip;const buildStyles=e=>_reactNative.StyleSheet.create({tooltip:{overflow:"hidden"}});var _default=exports.default=Tooltip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.WheelPicker=exports.DEFAULT_WHEEL_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.WheelPicker=exports.DEFAULT_WHEEL_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_index2=require("../Chip/index.js"),_index3=require("../Text/index.js"),_Wheel=require("./Wheel.js"),_jsxRuntime=require("react/jsx-runtime");const BASE_ITEM_HEIGHT=40,MAX_FONT_SCALE=1.5,DEFAULT_COLUMN_WIDTH=64,MAX_DURATION_MINUTES=1439,DEFAULT_WHEEL_PICKER_LABELS=exports.DEFAULT_WHEEL_PICKER_LABELS=Object.freeze({hours:"Hours",minutes:"Minutes",hourUnit:"hr",minuteUnit:"min",hourOne:"hour",hourMany:"hours",minuteOne:"minute",minuteMany:"minutes",value:"Value"}),range=(e,t,i=1)=>{const a=[];for(let r=e;r<=t;r+=i)a.push(r);return a},plural=(e,t,i)=>`${e} ${1===e?t:i}`,formatPreset=(e,t,i)=>{const a=Math.floor(e/60),r=e%60;return 0===a?`${r} ${i}`:0===r?`${a} ${t}`:`${a} ${t} ${r} ${i}`},toItem=e=>"object"==typeof e?e:{value:e,label:String(e)},WheelPicker=e=>{const{haptic:t,disabled:i,testID:a,style:r,labels:s}=e;(0,_assertValidValue.assertValidValue)("WheelPicker","mode",e.mode,["columns","list","duration"]);const n=(0,_index.useTheme)(),o=(0,_useReducedMotion.useReducedMotion)(),{fontScale:l}=(0,_reactNative.useWindowDimensions)(),u=Math.min(Math.max(l,1),1.5),d=Math.round(40*u),m=(0,_react.useMemo)(()=>buildStyles(n,d),[n,d]),c="list"===e.mode?e.items:void 0,h=(0,_react.useMemo)(()=>c?.map(toItem),[c]),_="duration"===e.mode?e.minuteStep??1:1,x="duration"===e.mode?Math.max(0,Math.min(1439,Math.floor(e.maxMinutes??1/0))):0,p=Math.floor(x/60),b=(0,_react.useMemo)(()=>({...DEFAULT_WHEEL_PICKER_LABELS,...s}),[s]),M="duration"===e.mode?e.presets:void 0;for(const e of M??[])if(!Number.isInteger(e)||e<0||e>x||e%_!==0)throw new Error(`WheelPicker preset ${e} must be a whole number of minutes from 0 to ${x} in steps of ${_}.`);const f=(0,_react.useCallback)(e=>{const t=e===p?x%60:59;return Math.floor(t/_)*_},[p,x,_]),j="duration"===e.mode?e.value:0,v=(0,_react.useMemo)(()=>{const e=Number.isFinite(j)?j:0,t=Math.max(0,Math.min(x,e)),i=Math.floor(t/60),a=Math.round(t%60/_)*_;return{hour:i,minute:Math.min(f(i),a)}},[j,x,_,f]),y=(0,_react.useMemo)(()=>"duration"===e.mode?range(0,p).map(e=>({value:e,label:String(e),accessibilityLabel:plural(e,b.hourOne,b.hourMany)})):[],[e.mode,p,b]),E=f(v.hour),L=(0,_react.useMemo)(()=>"duration"===e.mode?range(0,E,_).map(e=>({value:e,label:String(e).padStart(2,"0"),accessibilityLabel:plural(e,b.minuteOne,b.minuteMany)})):[],[e.mode,E,_,b]),g=(0,_react.useMemo)(()=>"list"===e.mode?[{key:"list",label:e.label??b.value,items:h??[],value:e.value??"",width:e.width}]:"duration"===e.mode?[{key:"hours",label:b.hours,items:y,value:v.hour,unit:b.hourUnit,gapAfter:n.space.md},{key:"minutes",label:b.minutes,items:L,value:v.minute,unit:b.minuteUnit}]:e.columns,[e,h,y,L,v,b,n.space.md]),{onChange:w}=e,S=(0,_react.useCallback)((t,i)=>{const a=t.items[i];if(a&&w)if("list"===e.mode)w(a.value);else if("duration"===e.mode){const e=Number(a.value),i=w;"hours"===t.key?i(60*e+Math.min(v.minute,f(e))):i(60*v.hour+e)}else w(t.key,a.value)},[w,e.mode,v,f]),I=(0,_react.useCallback)(e=>{w?.(e)},[w]),R=60*v.hour+v.minute,W=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[m.wheels,r],testID:a,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:"none",style:m.selectionBand,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.bandLine}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.bandLine})]}),g.map(a=>{if(0===a.items.length)return null;const r=a.items.findIndex(e=>e.value===a.value);return(0,_jsxRuntime.jsxs)(_react.Fragment,{children:[(0,_jsxRuntime.jsx)(_Wheel.Wheel,{label:a.label,items:a.items,selectedIndex:Math.max(0,r),onIndexChange:e=>S(a,e),itemHeight:d,width:a.width??("list"===e.mode?void 0:64),theme:n,haptic:t,disabled:i,reducedMotion:o,typeable:"duration"===e.mode,testID:a.testID}),a.unit?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:"semibold",color:"secondary",style:m.unit,maxFontSizeMultiplier:1.5,numberOfLines:1,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:a.unit}):null,a.separator?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"h2",weight:"bold",style:m.separator,maxFontSizeMultiplier:1.5,accessible:!1,importantForAccessibility:"no","aria-hidden":!0,children:a.separator}):null,a.gapAfter?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:a.gapAfter}}):null]},a.key)})]});return M&&0!==M.length?(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[W,(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.presets,children:M.map(e=>(0,_jsxRuntime.jsx)(_index2.Chip,{label:formatPreset(e,b.hourUnit,b.minuteUnit),size:"sm",selected:e===R,disabled:i,onPress:()=>I(e)},e))})]}):W};exports.WheelPicker=WheelPicker;const buildStyles=(e,t)=>_reactNative.StyleSheet.create({wheels:{flexDirection:"row",alignItems:"center",justifyContent:"center",height:t*_Wheel.WHEEL_VISIBLE_ITEMS,position:"relative"},selectionBand:{position:"absolute",left:0,right:0,top:t*_Wheel.WHEEL_CENTER_OFFSET,height:t,justifyContent:"space-between"},bandLine:{height:2*_reactNative.StyleSheet.hairlineWidth,backgroundColor:e.colors.primary,opacity:.85},separator:{paddingHorizontal:e.space.xs},unit:{paddingLeft:e.space.xs},presets:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:e.space.xs,paddingTop:e.space.sm}});var _default=exports.default=WheelPicker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function assertValidValue(e,t,o,r){if(null==o)return;const i=String(o);if(!r.some(e=>String(e)===i))throw new RangeError(`[@webority/mobile-ui] <${e}> received ${t}="${i}", which is not one of ${r.map(e=>`"${e}"`).join(" | ")}. Pass one of these values, or omit the prop for the default.`)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.assertValidValue=assertValidValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,LayoutAnimation,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,LayoutAnimation,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{defaultIcons}from"../AppIcon/defaultIcons.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const AccordionGroupContext=createContext(null),useAccordionGroup=()=>useContext(AccordionGroupContext),AccordionGroup=({children:e,allowMultiple:t=!1,defaultExpandedKeys:o,expandedKeys:i,onChange:n,style:r,testID:s})=>{const a=void 0!==i,[l,c]=useState(o??[]),d=a?i:l,u=useCallback(e=>{a||c(e),n?.(e)},[a,n]),p=useCallback(e=>{let o;o=d.includes(e)?d.filter(t=>t!==e):t?[...d,e]:[e],u(o)},[d,t,u]),m=useCallback(e=>d.includes(e),[d]),h=useMemo(()=>({isExpanded:m,toggle:p,allowMultiple:t}),[m,p,t]);return _jsx(AccordionGroupContext.Provider,{value:h,children:_jsx(View,{style:r,testID:s,children:e})})};AccordionGroup.displayName="AccordionGroup";const Chevron=({rotate:e,color:t})=>{const o=useTheme();return _jsx(Animated.View,{style:[chevronStyles.icon,{transform:[{rotate:e}]}],accessible:!1,children:(o.settings.icons.chevronDown??defaultIcons.chevronDown)({size:16,color:t})})},chevronStyles=StyleSheet.create({icon:{width:16,height:16,alignItems:"center",justifyContent:"center"}}),Accordion=e=>{const{title:t,children:o,id:i,expanded:n,defaultExpanded:r=!1,onChange:s,icon:a,disabled:l=!1,variant:c="plain",accessibilityLabel:d,style:u,headerStyle:p,contentStyle:m,contentWrapperStyle:h,containerStyle:x,testID:y,loading:g=!1,haptic:f}=e;assertValidValue("Accordion","variant",e.variant,["plain","card"]);const b=useTheme(),A=usePresenceMotion(),j=A.duration("default"),v=useMemo(()=>buildStyles(b),[b]),S=useAccordionGroup(),V=void 0!==n,[w,C]=useState(r),k=S&&i?S.isExpanded(i):null,_=null!==k?k:V?!!n:w,[R,I]=useState(null),D=useRef(createAnimatedValue(_?1:0)).current,E=useRef(createAnimatedValue(_?1:0)).current,G=useRef(createAnimatedValue(_?1:0)).current,L=useRef(_);useEffect(()=>{if(L.current===_)return;L.current=_;const e=_?1:0,t=Easing.bezier(...b.motion.ease["in-out"]),o=Animated.timing(D,{toValue:e,duration:b.motion.duration.default,easing:t,useNativeDriver:!1}),i=Animated.timing(E,{toValue:e,duration:j,easing:t,useNativeDriver:!1}),n=Animated.timing(G,{toValue:e,duration:b.motion.duration.default,easing:t,useNativeDriver:!1}),r=A.reduced&&!_?Animated.sequence([i,Animated.parallel([o,n])]):Animated.parallel([o,i,n]);return r.start(),()=>r.stop()},[_,D,E,G,j,A.reduced,b.motion]);const M=useCallback(e=>{const t=e.nativeEvent.layout.height;t>0&&t!==R&&I(t)},[R]),P=useCallback(()=>{if(l)return;const e=resolveHaptic(f,"selection");if(e&&triggerHaptic(e),S&&i)return S.toggle(i),void s?.(!_);V||C(!_),s?.(!_)},[l,S,i,_,V,s,f]),T=G.interpolate({inputRange:[0,1],outputRange:["0deg","180deg"]}),H=null===R?void 0:D.interpolate({inputRange:[0,1],outputRange:[0,R]}),N="card"===c?[v.card,b.shadow.card,{backgroundColor:b.colors.surface,borderRadius:b.radius.md,...smoothCorners}]:null;return g?_jsx(AccordionSkeleton,{...e}):_jsxs(View,{style:[N,x,u],testID:y,children:[_jsxs(Pressable,{onPress:P,disabled:l,accessibilityRole:"button",accessibilityLabel:d??t,accessibilityState:{expanded:_,disabled:l},"aria-expanded":_,"aria-disabled":l,style:({pressed:e})=>[v.header,p,{opacity:l?.55:e?.85:1}],children:[a?_jsx(View,{style:v.iconLeft,children:a}):null,_jsx(Text,{variant:"body",weight:"semibold",color:l?"disabled":"primary",numberOfLines:2,style:v.title,children:t}),_jsx(Chevron,{rotate:T,color:l?b.colors["text-disabled"]:b.colors["text-muted"]})]}),null===R?_jsx(View,{style:v.measurer,pointerEvents:"none",onLayout:M,children:_jsx(View,{style:[v.content,m],children:o})}):null,_jsx(Animated.View,{style:[v.contentWrapper,null===R?{height:0,opacity:0}:{height:H,opacity:E},h],children:_jsx(View,{onLayout:M,style:[v.content,m],children:o})})]})};Accordion.displayName="Accordion";const AccordionSkeleton=({variant:e="plain",style:t})=>{const o=useTheme();return _jsx(View,{style:["card"===e?{paddingHorizontal:o.space.md,paddingVertical:o.space.sm,backgroundColor:o.colors.surface,borderRadius:o.radius.md,...smoothCorners}:{paddingVertical:o.space.sm},t],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:{flexDirection:"row",alignItems:"center"},children:[_jsx(Skeleton,{shape:"text",width:"60%",height:18,style:{flex:1}}),_jsx(Skeleton,{width:16,height:16,radius:"sm",style:{marginLeft:o.space.sm}})]})})};AccordionSkeleton.displayName="AccordionSkeleton",Accordion.Skeleton=AccordionSkeleton;const buildStyles=e=>StyleSheet.create({card:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,marginVertical:e.space.xs},header:{flexDirection:"row",alignItems:"center",paddingVertical:e.space.sm},iconLeft:{marginRight:e.space.sm},title:{flex:1},contentWrapper:{overflow:"hidden"},content:{paddingBottom:e.space.sm},measurer:{position:"absolute",opacity:0,left:0,right:0,top:0,zIndex:-1}});export{Accordion,AccordionGroup};export default Accordion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatCurrency,formatNumber,getFormatterConfig,groupingForLocale}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{formatCurrency,formatNumber,getFormatterConfig,groupingForLocale}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Input}from"../Input/index.js";import{Slider}from"../Slider/index.js";import{clampValue,RollingText,useValueDraft}from"../Slider/valueText.js";import{Text}from"../Text/index.js";import{jsxs as _jsxs,jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_AMOUNT_SLIDER_LABELS=Object.freeze({inputLabel:"Amount",thousand:"Thousand",lakh:"Lakh",crore:"Crore",million:"Million",billion:"Billion"});const tiersFor=(e,t)=>"indian"===e?[[1e7,t.crore],[1e5,t.lakh],[1e3,t.thousand]]:[[1e9,t.billion],[1e6,t.million],[1e3,t.thousand]];export const scaleAmount=(e,t,i=DEFAULT_AMOUNT_SLIDER_LABELS)=>{const n=Math.abs(e);for(const[o,r]of tiersFor(t,i))if(n>=o)return{amount:e/o,unit:r};return{amount:e,unit:""}};const formatAmount=(e,t,i)=>{const n=Math.round(100*e)/100;return t?String(n):formatNumber(Math.round(e),{grouping:i,maximumFractionDigits:0})},AmountSlider=forwardRef((e,t)=>{const{min:i=0,max:n=100,step:o=1,disabled:r=!1,tone:a,size:l,variant:s="inset",currency:u,labels:m,formatInput:c,animationDuration:d,haptic:f,accessibilityLabel:x,style:p,headerStyle:b,valueStyle:h,unitStyle:y,inputStyle:S,sliderStyle:g,testID:v}=e;assertValidValue("AmountSlider","units",e.units,["indian","international"]),assertValidValue("AmountSlider","variant",e.variant,["default","inset","minimal","bar"]);const j=useTheme(),A=useMemo(()=>buildStyles(j),[j]),L=d??j.motion.duration.default,D=useMemo(()=>({...DEFAULT_AMOUNT_SLIDER_LABELS,...m}),[m]),T=e.units??("indian"===groupingForLocale(getFormatterConfig().locale)?"indian":"international"),V=useMemo(()=>formatCurrency(0,{currency:u,maximumFractionDigits:0}).replace(/[\d\s.,]/g,""),[u]),_=useCallback(e=>formatCurrency(e,{currency:u,maximumFractionDigits:0}),[u]),C=c??_,[w,I]=useControllableState({value:e.value,defaultValue:e.defaultValue??i,onChange:e.onChange}),F=clampValue(w,i,n),R=useValueDraft({value:F,min:i,max:n,step:o,format:C,onChange:I}),M=scaleAmount(F,T,D),E=""!==M.unit,$=useRef(F),k=useRef("up");F!==$.current&&(k.current=F>$.current?"up":"down",$.current=F);const z=k.current,B=`${V}${formatAmount(M.amount,E,T)}${E?` ${M.unit}`:""}`;return _jsxs(View,{ref:t,style:[A.container,p],testID:v,children:[_jsxs(View,{style:[A.header,b],children:[_jsxs(View,{style:A.valueRow,accessible:!0,accessibilityRole:"text",accessibilityLabel:B,children:[V?_jsxs(Text,{variant:"body",style:[A.value,h],children:[V," "]}):null,_jsx(RollingText,{text:formatAmount(M.amount,E,T),direction:z,duration:L,style:[A.value,h],testID:v?`${v}-value`:void 0}),E?_jsx(RollingText,{text:` ${M.unit}`,direction:z,duration:L,perCharacter:!1,style:[A.unit,y],testID:v?`${v}-unit`:void 0}):null]}),_jsx(Input,{size:"sm",value:R.text,onChangeText:R.onChangeText,onFocus:R.onFocus,onBlur:R.onBlur,onSubmitEditing:R.onBlur,keyboardType:"number-pad",returnKeyType:"done",disabled:r,accessibilityLabel:D.inputLabel,style:[A.input,S],testID:v?`${v}-input`:void 0})]}),_jsx(Slider,{value:F,onChange:I,min:i,max:n,step:o,disabled:r,tone:a,size:l,variant:s,haptic:f,accessibilityLabel:x,style:g,testID:v?`${v}-slider`:void 0})]})});AmountSlider.displayName="AmountSlider";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:e.space.md},valueRow:{flexDirection:"row",alignItems:"baseline",flexShrink:1},value:{color:e.colors["text-body"],fontSize:e.text["3xl"].size,fontWeight:e.weight.bold,fontVariant:["tabular-nums"]},unit:{color:e.colors["text-body"],fontSize:e.text.lg.size,fontWeight:e.weight.semibold},input:{width:"45%",maxWidth:180}});export{AmountSlider};export default AmountSlider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import Animated,{FadeIn,FadeInDown,FadeInUp,FadeOut,FadeOutDown,FadeOutUp,ZoomIn,ZoomOut}from"react-native-reanimated";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{
|
|
1
|
+
"use strict";import Animated,{FadeIn,FadeInDown,FadeInUp,FadeOut,FadeOutDown,FadeOutUp,ZoomIn,ZoomOut}from"react-native-reanimated";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx}from"react/jsx-runtime";const AnimatePresence=({children:e,preset:t="fade",duration:a,style:n,testID:r})=>{assertValidValue("AnimatePresence","preset",t,["fade","scale","slide-up","slide-down"]);const i=usePresenceMotion();if(!(null!=e&&!1!==e))return null;const o=a??i.duration("default");let d,s;if(i.reduced)d=FadeIn.duration(o).reduceMotion(PRESENCE_REDUCE_MOTION),s=FadeOut.duration(o).reduceMotion(PRESENCE_REDUCE_MOTION);else switch(t){case"scale":d=ZoomIn.duration(o),s=ZoomOut.duration(o);break;case"slide-up":d=FadeInUp.duration(o),s=FadeOutDown.duration(o);break;case"slide-down":d=FadeInDown.duration(o),s=FadeOutUp.duration(o);break;default:d=FadeIn.duration(o),s=FadeOut.duration(o)}return _jsx(Animated.View,{entering:d,exiting:s,style:n,testID:r,children:e})};AnimatePresence.displayName="AnimatePresence";export{AnimatePresence};export default AnimatePresence;
|
|
@@ -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{
|
|
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}),p=useMemo(()=>buildActionStyles(r),[r]),u=e.badge,h=void 0!==u&&0!==u,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?p.textButton:p.actionButton,l?null:"left"===t?p.actionLeft:p.actionRight,e&&!g?p.actionPressed:null,e&&g?p.textPressed:null],children:[g?_jsx(ThemedText,{variant:"body",weight:"semibold",color:"link",numberOfLines:1,children:e.label}):_jsx(View,{style:p.iconWrap,children:e.icon}),h?_jsx(View,{style:[p.badge,i],pointerEvents:"none",children:_jsx(ThemedText,{variant:"caption",weight:"semibold",numberOfLines:1,style:p.badgeText,children:String(u)})}):null,e.dot?_jsx(View,{testID:e.testID?`${e.testID}-dot`:"appbar-action-dot",style:p.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:p,titleOffset:u,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!==u,F=Boolean(W)||Boolean(r),M=!H&&"left"===l&&Boolean(W),N=H||M||!F&&"left"===l,$="default"!==x||F?R.titleSize:I.text.xl.size,U=g??!1,G=StyleSheet.hairlineWidth,Z=useMemo(()=>b?{rootHeight:b.interpolate({inputRange:[0,60],outputRange:[L.top+R.height+P,L.top+R.height],extrapolate:"clamp"}),titleRowOpacity:b.interpolate({inputRange:[0,30],outputRange:[1,0],extrapolate:"clamp"}),compactTitleOpacity:b.interpolate({inputRange:[30,60],outputRange:[0,1],extrapolate:"clamp"}),borderOpacity:b.interpolate({inputRange:[0,60],outputRange:[0,1],extrapolate:"clamp"})}:null,[b,L.top,R.height,P]),Y=i?p?_jsx(ThemedText,{variant:p,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||M}):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:F?u: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:13}});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{
|
|
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{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 n=CATALOG_LOADERS[e]?.[t],s=n?tryRequire(n):null;return shardCache.set(o,s),s},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=GLYPHS[e];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:n,testID:s})=>{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]);return m?_jsx(SvgXml,{xml:m,width:i,height:i,style:a,accessible:null!=n,accessibilityLabel:n,accessibilityRole:null!=n?"image":void 0,testID:s}):(__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)};AppIcon.displayName="AppIcon";export default AppIcon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{extractApiError,OFFLINE_CODE}from"@webority/mobile-core";import{isValidElement,useMemo}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{extractApiError,OFFLINE_CODE}from"@webority/mobile-core";import{isValidElement,useMemo}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{AppIcon}from"../AppIcon/index.js";import{EmptyState}from"../EmptyState/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_ASYNC_BLOCK_LABELS=Object.freeze({emptyTitle:"Nothing here yet",errorTitle:"That didn't load",offlineTitle:"You're offline",offlineHint:"Check your connection, then try again.",retry:"Try again"});const isNode=e=>isValidElement(e)||Array.isArray(e);export const AsyncBlock=({loading:e=!1,error:t,errorVariant:r,empty:i=!1,onRetry:o,skeleton:n,emptyTitle:s,emptyDescription:l,emptyIcon:a,errorTitle:c,offlineTitle:m,labels:p,children:f,style:d,testID:y})=>{const x=useTheme(),u=useMemo(()=>({...DEFAULT_ASYNC_BLOCK_LABELS,...p}),[p]);if(assertValidValue("AsyncBlock","errorVariant",r,["default","offline"]),e)return _jsx(View,{style:d,testID:y,children:n??_jsx(View,{style:{paddingVertical:x.space["2xl"],alignItems:"center"},children:_jsx(Spinner,{})})});if(t){const e="string"==typeof t?t:null,i=null!==e||isNode(t)?null:extractApiError(t),n="offline"===(r??(i?.code===OFFLINE_CODE?"offline":"default")),s=e??i?.message??(n?u.offlineHint:void 0);return _jsxs(View,{style:d,testID:y,children:[_jsx(EmptyState,{icon:n?_jsx(AppIcon,{name:"cloud-cross",size:"xl",color:x.colors["text-subtle"],testID:"async-block-offline-icon"}):void 0,title:n?m??u.offlineTitle:c??u.errorTitle,description:s,action:o?{label:u.retry,onPress:o}:void 0}),isNode(t)?t:null]})}return i?_jsx(View,{style:d,testID:y,children:_jsx(EmptyState,{icon:a,title:s??u.emptyTitle,description:l})}):_jsx(_Fragment,{children:f})};export default AsyncBlock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Image}from"expo-image";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{Image}from"expo-image";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{acquireFetch,DEFAULT_TTL_MS,deriveCacheKey,isFresh,isPermanentRefusal,readEntry,releaseFetch,removeEntry,touchEntry}from"./authedImageCache.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_AUTHED_IMAGE_LABELS=Object.freeze({loading:"Loading image",unavailable:"Image unavailable",unavailableNamed:e=>`${e}, image unavailable`});const CONTENT_FIT={cover:"cover",contain:"contain",stretch:"fill",center:"scale-down",repeat:"cover"},toError=e=>e instanceof Error?e:new Error(String(e)),AuthedImage=e=>{const{uri:t,headers:r,client:a,authenticated:i=!0,ttlMs:s=DEFAULT_TTL_MS,placeholder:o,fallback:n,onLoadStart:l,onLoadEnd:c,onError:d,cacheKey:u,testID:m,accessibilityLabel:h,style:y,resizeMode:f,fadeDuration:b,contentFit:E,transition:g,labels:p,cachePolicy:I="memory",...L}=e;assertValidValue("AuthedImage","resizeMode",f,Object.keys(CONTENT_FIT));const v=useMemo(()=>({...DEFAULT_AUTHED_IMAGE_LABELS,...p}),[p]),T=useTheme(),S=useMemo(()=>buildStyles(T),[T]),[j,x]=useState({status:"loading"}),_=useRef({onLoadStart:l,onLoadEnd:c,onError:d});_.current={onLoadStart:l,onLoadEnd:c,onError:d};const F=JSON.stringify(r??{});return useEffect(()=>{let e=!1,r=null;const finish=t=>{e||(x(t),_.current.onLoadEnd?.())};return(async()=>{if(!t){const t=new Error("[@webority/mobile-ui] AuthedImage was given an empty `uri`. Pass the image URL, or render nothing while the URL is still unknown.");return void(e||(x({status:"error"}),_.current.onError?.(t)))}x({status:"loading"}),_.current.onLoadStart?.();const o=deriveCacheKey(t,u),n=await readEntry(o);if(e)return;if(n&&isFresh(n.meta,s))return touchEntry(o),void finish({status:"ready",fileUri:n.fileUri});const l=acquireFetch(o,{uri:t,headers:JSON.parse(F),authenticated:i,client:a});r={key:o,entry:l};try{const e=await l.promise;finish({status:"ready",fileUri:e.fileUri})}catch(t){if(e)return;if(n&&!isPermanentRefusal(t))return void finish({status:"ready",fileUri:n.fileUri});if(n&&(await removeEntry(o),e))return;x({status:"error"}),_.current.onError?.(toError(t)),_.current.onLoadEnd?.()}})(),()=>{e=!0,r&&releaseFetch(r.key,r.entry)}},[t,u,s,i,a,F]),"loading"===j.status?_jsx(View,void 0!==o?{style:y,testID:m,children:o}:{style:[S.placeholder,y],testID:m,children:_jsx(View,{style:S.stateFill,testID:m?`${m}-placeholder`:void 0,pointerEvents:"none",children:_jsx(Spinner,{size:"sm",accessibilityLabel:v.loading})})}):"error"===j.status?_jsx(View,void 0!==n?{style:y,testID:m,children:n}:{style:[S.fallback,y],testID:m,children:_jsx(View,{accessible:!0,accessibilityRole:"image",accessibilityLabel:h?v.unavailableNamed(h):v.unavailable,testID:m?`${m}-fallback`:void 0,style:S.stateFill,children:_jsx(Text,{variant:"title",color:"tertiary",accessible:!1,children:"!"})})}):_jsx(Image,{...L,accessible:!0,accessibilityRole:"image",accessibilityLabel:h,testID:m,style:y,contentFit:E??(f?CONTENT_FIT[f]:void 0),transition:g??b,cachePolicy:I,source:{uri:j.fileUri}})};AuthedImage.displayName="AuthedImage";const buildStyles=e=>StyleSheet.create({placeholder:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.md,...smoothCorners},fallback:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.md,...smoothCorners,borderWidth:e.size.border,borderColor:e.colors["border-subtle"],padding:e.space.sm},stateFill:{alignItems:"center",flex:1,justifyContent:"center"}});export{AuthedImage};export default AuthedImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Keyboard,Pressable,ScrollView,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{
|
|
1
|
+
"use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Keyboard,Pressable,ScrollView,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{smoothCorners}from"../../utils/corners.js";import{Input}from"../Input/index.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_AUTOCOMPLETE_LABELS=Object.freeze({empty:"No matches",searching:"Searching…"});const defaultGetLabel=e=>"string"==typeof e?e:String(e);function Autocomplete(e){const{options:t,value:o,defaultValue:r,onChangeText:l,onSelect:s,getOptionLabel:i,getOptionKey:a,filter:n,minChars:c=1,maxResults:d=8,loading:u=!1,filterMode:p="client",loadingText:m,labels:h,placeholder:x,label:b,error:g,helperText:f,disabled:y=!1,size:S="md",variant:T,haptic:j,style:C,listStyle:_,optionTextStyle:v,testID:w}=e;assertValidValue("Autocomplete","filterMode",e.filterMode,["client","none"]);const L=useMemo(()=>({...DEFAULT_AUTOCOMPLETE_LABELS,...h}),[h]),V=useTheme(),A=useMemo(()=>buildStyles(V),[V]),[E,M]=useControllableState({value:o,defaultValue:r??"",onChange:l}),[P,R]=useState(!1),[k,z]=useState(0),I=useRef(null),O=useCallback(e=>i?i(e):defaultGetLabel(e),[i]),H=useMemo(()=>{if("none"===p)return t.slice(0,d);const e=E.trim();if(e.length<c)return[];const o=e.toLowerCase(),r=n?t=>n(t,e):e=>O(e).toLowerCase().includes(o);return t.filter(r).slice(0,d)},[t,E,c,d,n,O,p]),F=P&&(u||E.trim().length>=c),D=useCallback(e=>{const t=resolveHaptic(j,"selection");t&&triggerHaptic(t),I.current&&clearTimeout(I.current),M(O(e)),R(!1),Keyboard.dismiss(),s(e)},[j,M,O,s]);React.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[]);const U=useCallback(e=>{z(e.nativeEvent.layout.height)},[]);return _jsxs(View,{style:[A.container,C],testID:w,children:[_jsx(View,{onLayout:U,children:_jsx(Input,{value:E,onChangeText:M,onFocus:()=>{I.current&&clearTimeout(I.current),R(!0)},onBlur:()=>{I.current=setTimeout(()=>R(!1),120)},placeholder:x,label:b,error:g,helperText:f,editable:!y,accessibilityState:{disabled:y},"aria-disabled":y,size:S,variant:T,autoCorrect:!1,autoCapitalize:"none"})}),F?_jsx(View,{style:[A.list,{top:k,backgroundColor:V.colors.surface,borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,...V.shadow.popover},_],children:u?_jsxs(View,{style:A.loadingRow,children:[_jsx(Spinner,{size:"sm"}),_jsx(Text,{variant:"bodySmall",color:"secondary",style:A.loadingText,children:m??L.searching})]}):0===H.length?_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:A.empty,children:L.empty}):_jsx(ScrollView,{keyboardShouldPersistTaps:"handled",style:A.scroll,children:H.map(e=>_jsx(Pressable,{onPress:()=>D(e),android_ripple:{color:V.colors["surface-pressed"]},style:({pressed:e})=>[A.option,{paddingHorizontal:V.space.md,paddingVertical:V.space.sm,backgroundColor:e?V.colors["surface-pressed"]:"transparent"}],accessibilityRole:"button",accessibilityLabel:O(e),accessibilityState:{selected:O(e)===E},"aria-selected":O(e)===E,children:_jsx(Text,{variant:"body",numberOfLines:1,style:[A.optionText,v],children:O(e)})},a?a(e):O(e)))})}):null]})}Autocomplete.displayName="Autocomplete";const buildStyles=e=>StyleSheet.create({container:{width:"100%",position:"relative",zIndex:10},list:{position:"absolute",left:0,right:0,borderWidth:StyleSheet.hairlineWidth,overflow:"hidden",zIndex:20,maxHeight:240},scroll:{maxHeight:240},option:{width:"100%"},optionText:{includeFontPadding:!1},empty:{padding:e.space.md,includeFontPadding:!1},loadingRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm,padding:e.space.md},loadingText:{includeFontPadding:!1}});export{Autocomplete};export default Autocomplete;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Image}from"expo-image";import{Children,cloneElement,forwardRef,isValidElement,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{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{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{AuthedImage}from"../AuthedImage/AuthedImage.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const SOFT_FILL_OPACITY=.14,MIN_TOUCH_TARGET=44,PRESSED_OPACITY=.7,INITIALS_MAX_FONT_SCALE=1.2;export const AVATAR_COLORS=["avatar-1","avatar-2","avatar-3","avatar-4","avatar-5","avatar-6","avatar-7","avatar-8"];export const avatarToneColors=(e,t)=>{const soft=(e,t)=>tintOf(e,.14,t);switch(t){case"primary":return{background:soft(e.colors.primary,e.colors["primary-soft"]),color:e.colors["primary-text"]};case"success":return{background:soft(e.colors.success,e.colors["bg-subtle"]),color:e.colors["success-text"]};case"warning":return{background:soft(e.colors.warning,e.colors["bg-subtle"]),color:e.colors["warning-text"]};case"danger":return{background:soft(e.colors.danger,e.colors["bg-subtle"]),color:e.colors["danger-text"]};case"info":return{background:soft(e.colors.info,e.colors["bg-subtle"]),color:e.colors["info-text"]};default:return{background:e.colors["bg-muted"],color:e.colors["text-body"]}}};export const DEFAULT_AVATAR_LABELS=Object.freeze({avatar:"Avatar",avatarOf:e=>`${e}'s avatar`,verified:"verified",pendingVerification:"pending verification",groupOf:e=>`Group of ${e} ${1===e?"person":"people"}`,moreCount:e=>`${e} more`,moreAvatars:"More avatars"});const sizeMap={xs:24,sm:32,md:48,lg:64,xl:80},resolveSize=e=>sizeMap[e],resolveRadius=(e,t,r,o)=>{switch(t){case"circle":return r/2;case"rounded":return o?e.radius[o]:Math.max(e.radius.sm,Math.round(.22*r));default:return 0}},initialsFromName=e=>{if(!e)return"";const t=e.trim().split(/\s+/u).filter(Boolean);return 0===t.length?"":1===t.length?t[0].charAt(0).toUpperCase():(t[0].charAt(0)+t[1].charAt(0)).toUpperCase()},hashColor=(e,t)=>{if(!e)return t[0];let r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t[Math.abs(r)%t.length]},RING_WIDTH=1.5,keyOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:e,uriOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:void 0,isRingStatus=e=>"verified"===e||"pending"===e,statusColor=(e,t)=>{switch(t){case"online":case"verified":return e.colors.success;case"busy":return e.colors.danger;case"away":case"pending":return e.colors.warning;default:return e.colors["text-subtle"]}},Avatar=forwardRef((e,t)=>{const{source:r,ImageComponent:o,imageClient:s,name:a,size:i="md",shape:n="circle",dimension:l,radius:c,border:u=!1,contentFit:d="cover",placeholderIcon:m,status:g=null,statusPosition:h="bottomRight",tone:p,backgroundColor:b,color:v,fontSize:f,loading:y=!1,accessibilityLabel:A,onPress:x,onLongPress:S,haptic:I,hitSlop:C,style:w,textStyle:_,testID:R,labels:j}=e;warnInvalidValue("Avatar","size",e.size,Object.keys(sizeMap)),warnInvalidValue("Avatar","shape",e.shape,["circle","square","rounded"]),warnInvalidValue("Avatar","radius",e.radius,["sm","md","lg"]),warnInvalidValue("Avatar","contentFit",e.contentFit,["cover","contain"]),warnInvalidValue("Avatar","status",e.status,["online","offline","busy","away","verified","pending"]),warnInvalidValue("Avatar","statusPosition",e.statusPosition,["topRight","bottomRight"]),warnInvalidValue("Avatar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const M=useMemo(()=>j?{...DEFAULT_AVATAR_LABELS,...j}:DEFAULT_AVATAR_LABELS,[j]),T=useTheme(),[V,L]=useState(null),E=useMemo(()=>l??resolveSize(i),[l,i]),k=useMemo(()=>resolveRadius(T,n,E,c),[T,n,E,c]),z=u?T.size.border:0,O=T.colors.border,F=T.colors.surface,D=useMemo(()=>initialsFromName(a),[a]),G=useMemo(()=>p?avatarToneColors(T,p):null,[T,p]),P=useMemo(()=>b||(G?.background??T.colors[hashColor(a??"",AVATAR_COLORS)]),[b,G,a,T]),N=v??G?.color??T.colors["on-primary"],$=r?keyOfSource(r):null,B=null!==$&&$!==V,H=!B&&""===D&&null!=m,U=v??G?.color??T.colors["text-subtle"],W=f??Math.max(T.text.xs.size,Math.round(.4*E)),Y=Math.max(8,Math.round(.25*E)),q=isRingStatus(g),X=E-2*(q?3:z),J=q?resolveRadius(T,n,X,c):Math.max(0,k-z),K=H?renderSlotIcon(m,{color:U,size:Math.round(.45*X),disabled:!1}):null,Q=q?statusColor(T,g):"transparent",Z=Math.max(12,Math.round(.32*E)),ee=Math.max(10,Z-4),te=b??G?.background??T.colors["bg-muted"],re=B?"contain"===d?"transparent":T.colors["bg-muted"]:H?te:P,oe=R??"avatar",se=a?M.avatarOf(a):M.avatar,ae="verified"===g?`, ${M.verified}`:"pending"===g?`, ${M.pendingVerification}`:"",ie=A??`${se}${ae}`,ne="function"==typeof x||"function"==typeof S,le=A??`${a||se}${ae}`,ce=Math.max(0,Math.ceil((44-E)/2)),ue=C??ce,de=[styles.root,{width:E,height:E,borderRadius:k,...smoothCorners,borderWidth:q?0:z,borderColor:O,backgroundColor:q?"transparent":re},w],me=_jsxs(_Fragment,{children:[q?_jsx(View,{style:[styles.ring,{borderRadius:k,...smoothCorners,borderWidth:1.5,borderColor:Q}],accessible:!1,pointerEvents:"none",testID:`${oe}-ring`}):null,_jsx(View,{style:[styles.picture,{width:X,height:X,borderRadius:J,...smoothCorners,borderWidth:q?z:0,borderColor:O,backgroundColor:q?re:"transparent"}],children:B?(()=>{const e={width:X,height:X,borderRadius:J,...smoothCorners},onError=()=>L($),t=uriOfSource(r);return o?_jsx(o,{source:r,onError:onError,style:e,contentFit:d,resizeMode:d,accessibilityIgnoresInvertColors:!0}):s&&void 0!==t?_jsx(AuthedImage,{uri:t,client:s,onError:onError,style:e,contentFit:d,placeholder:null,fallback:null,accessibilityIgnoresInvertColors:!0}):_jsx(Image,{source:r,onError:onError,style:e,contentFit:d,accessibilityIgnoresInvertColors:!0})})():K||_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,maxFontSizeMultiplier:1.2,style:[styles.initials,{color:N,fontSize:W,lineHeight:Math.round(W*T.leading.body)},_],children:D??" "})}),"verified"===g?_jsx(View,{style:[styles.status,"topRight"===h?styles.badgeTopRight:styles.badgeBottomRight,{width:Z,height:Z,borderRadius:Z/2,...smoothCorners,backgroundColor:F}],accessible:!1,pointerEvents:"none",testID:`${oe}-badge`,children:_jsx(AppIcon,{name:"verify",variant:"bold",size:ee,color:Q})}):null,g&&!q?_jsx(View,{style:[styles.status,"topRight"===h?styles.statusTopRight:styles.statusBottomRight,{width:Y,height:Y,borderRadius:Y/2,...smoothCorners,backgroundColor:statusColor(T,g),borderWidth:2,borderColor:F}],accessible:!1,pointerEvents:"none"}):null]}),ge=ne?_jsx(Pressable,{ref:t,onPress:x?e=>{const t=resolveHaptic(I,"selection");t&&triggerHaptic(t),x?.(e)}:void 0,onLongPress:S?e=>{const t=resolveHaptic(I,"longPress");t&&triggerHaptic(t),S?.(e)}:void 0,hitSlop:ue,...hitSlopMarker(ue),accessibilityRole:"button",accessibilityLabel:le,testID:R,style:({pressed:e})=>[de,e?styles.pressed:null],children:me}):_jsx(View,{ref:t,style:de,accessible:!0,accessibilityRole:"image",accessibilityLabel:ie,testID:R,children:me});return y?_jsx(AvatarSkeleton,{...e}):ge});Avatar.displayName="Avatar";const AvatarSkeleton=({size:e="md",shape:t="circle",dimension:r,style:o})=>{const s=r??resolveSize(e);return _jsx(Skeleton,{shape:"circle"===t?"circle":"rounded"===t?"rounded":"rect",width:s,height:s,style:o})};AvatarSkeleton.displayName="AvatarSkeleton",Avatar.Skeleton=AvatarSkeleton;const styles=StyleSheet.create({root:{alignItems:"center",justifyContent:"center",overflow:"visible",position:"relative"},pressed:{opacity:.7},initials:{textAlign:"center"},ring:{position:"absolute",top:0,right:0,bottom:0,left:0},picture:{alignItems:"center",justifyContent:"center",overflow:"hidden"},status:{position:"absolute"},badgeTopRight:{top:-2,right:-2,alignItems:"center",justifyContent:"center"},badgeBottomRight:{bottom:-2,right:-2,alignItems:"center",justifyContent:"center"},statusTopRight:{top:0,right:0},statusBottomRight:{bottom:0,right:0}}),SPACING_OFFSET={tight:"lg",normal:"md",loose:"sm"},STAGGER_MS=50,ENTRANCE_DURATION_MS=220,AvatarGroupItem=({delay:e,marginLeft:t,borderColor:r,borderWidth:o,children:s})=>{const a=useTheme(),i=useRef(createAnimatedValue(0)).current;return useEffect(()=>{const t=Animated.timing(i,{toValue:1,duration:220,delay:e,easing:Easing.out(Easing.cubic),useNativeDriver:!0});return t.start(),()=>t.stop()},[e,i]),_jsx(Animated.View,{style:[groupStyles.item,{marginLeft:t,borderRadius:a.radius.pill,borderColor:r,borderWidth:o,opacity:i}],children:s})},AvatarGroup=e=>{const{children:t,max:r=4,size:o="md",spacing:s="normal",overflowVariant:a="count",accessibilityLabel:i,style:n,testID:l,labels:c}=e;warnInvalidValue("AvatarGroup","spacing",e.spacing,["tight","normal","loose"]),warnInvalidValue("AvatarGroup","overflowVariant",e.overflowVariant,["count","plus"]),warnInvalidValue("AvatarGroup","size",e.size,Object.keys(sizeMap));const u=useMemo(()=>c?{...DEFAULT_AVATAR_LABELS,...c}:DEFAULT_AVATAR_LABELS,[c]),d=useTheme(),m=useMemo(()=>Children.toArray(t).filter(e=>isValidElement(e)),[t]),g=m.length,h=m.slice(0,r),p=Math.max(0,g-r),b=p>0,v=-d.space[SPACING_OFFSET[s]],f=d.colors.surface,y=i??u.groupOf(g),A=useMemo(()=>resolveSize(o),[o]),x=Math.max(d.text.xs.size,Math.round(.34*A));return _jsxs(View,{style:[groupStyles.row,n],accessible:!0,accessibilityLabel:y,accessibilityRole:"summary",testID:l,children:[h.map((e,t)=>{const r=e.key??`avatar-${t}`,s=cloneElement(e,{size:o,labels:e.props.labels??c});return _jsx(AvatarGroupItem,{delay:50*t,marginLeft:0===t?0:v,borderColor:f,borderWidth:1.5,children:s},r)}),b?_jsx(AvatarGroupItem,{delay:50*h.length,marginLeft:0===h.length?0:v,borderColor:f,borderWidth:1.5,children:_jsx(View,{style:[groupStyles.overflow,{width:A,height:A,borderRadius:A/2,...smoothCorners,backgroundColor:d.colors["surface-disabled"]}],accessible:!0,accessibilityRole:"text",accessibilityLabel:"count"===a?u.moreCount(p):u.moreAvatars,children:_jsx(Text,{variant:"label",weight:"semibold",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{fontSize:x,lineHeight:Math.round(x*d.leading.body)},children:"count"===a?`+${p}`:"+"})})},"avatar-overflow"):null]})},groupStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},item:{...smoothCorners},overflow:{alignItems:"center",justifyContent:"center"}});export{Avatar,AvatarGroup};export default Avatar;
|
|
1
|
+
"use strict";import{Image}from"expo-image";import{Children,cloneElement,forwardRef,isValidElement,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{AuthedImage}from"../AuthedImage/AuthedImage.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const SOFT_FILL_OPACITY=.14,MIN_TOUCH_TARGET=44,PRESSED_OPACITY=.7,INITIALS_MAX_FONT_SCALE=1.2;export const AVATAR_COLORS=["avatar-1","avatar-2","avatar-3","avatar-4","avatar-5","avatar-6","avatar-7","avatar-8"];export const avatarToneColors=(e,t)=>{const soft=(e,t)=>tintOf(e,.14,t);switch(t){case"primary":return{background:soft(e.colors.primary,e.colors["primary-soft"]),color:e.colors["primary-text"]};case"success":return{background:soft(e.colors.success,e.colors["bg-subtle"]),color:e.colors["success-text"]};case"warning":return{background:soft(e.colors.warning,e.colors["bg-subtle"]),color:e.colors["warning-text"]};case"danger":return{background:soft(e.colors.danger,e.colors["bg-subtle"]),color:e.colors["danger-text"]};case"info":return{background:soft(e.colors.info,e.colors["bg-subtle"]),color:e.colors["info-text"]};default:return{background:e.colors["bg-muted"],color:e.colors["text-body"]}}};export const DEFAULT_AVATAR_LABELS=Object.freeze({avatar:"Avatar",avatarOf:e=>`${e}'s avatar`,verified:"verified",pendingVerification:"pending verification",groupOf:e=>`Group of ${e} ${1===e?"person":"people"}`,moreCount:e=>`${e} more`,moreAvatars:"More avatars"});const sizeMap={xs:24,sm:32,md:48,lg:64,xl:80},resolveSize=e=>sizeMap[e],resolveRadius=(e,t,r,o)=>{switch(t){case"circle":return r/2;case"rounded":return o?e.radius[o]:Math.max(e.radius.sm,Math.round(.22*r));default:return 0}},initialsFromName=e=>{if(!e)return"";const t=e.trim().split(/\s+/u).filter(Boolean);return 0===t.length?"":1===t.length?t[0].charAt(0).toUpperCase():(t[0].charAt(0)+t[1].charAt(0)).toUpperCase()},hashColor=(e,t)=>{if(!e)return t[0];let r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t[Math.abs(r)%t.length]},RING_WIDTH=1.5,keyOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:e,uriOfSource=e=>"object"==typeof e&&null!==e&&"uri"in e&&"string"==typeof e.uri?e.uri:void 0,isRingStatus=e=>"verified"===e||"pending"===e,statusColor=(e,t)=>{switch(t){case"online":case"verified":return e.colors.success;case"busy":return e.colors.danger;case"away":case"pending":return e.colors.warning;default:return e.colors["text-subtle"]}},Avatar=forwardRef((e,t)=>{const{source:r,ImageComponent:o,imageClient:s,name:a,size:i="md",shape:n="circle",dimension:l,radius:c,border:u=!1,contentFit:d="cover",placeholderIcon:m,status:g=null,statusPosition:h="bottomRight",tone:p,backgroundColor:b,color:f,fontSize:v,loading:y=!1,accessibilityLabel:A,onPress:x,onLongPress:S,haptic:C,hitSlop:V,style:_,textStyle:I,testID:R,labels:j}=e;assertValidValue("Avatar","size",e.size,Object.keys(sizeMap)),assertValidValue("Avatar","shape",e.shape,["circle","square","rounded"]),assertValidValue("Avatar","radius",e.radius,["sm","md","lg"]),assertValidValue("Avatar","contentFit",e.contentFit,["cover","contain"]),assertValidValue("Avatar","status",e.status,["online","offline","busy","away","verified","pending"]),assertValidValue("Avatar","statusPosition",e.statusPosition,["topRight","bottomRight"]),assertValidValue("Avatar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const M=useMemo(()=>j?{...DEFAULT_AVATAR_LABELS,...j}:DEFAULT_AVATAR_LABELS,[j]),w=useTheme(),[T,L]=useState(null),E=useMemo(()=>l??resolveSize(i),[l,i]),k=useMemo(()=>resolveRadius(w,n,E,c),[w,n,E,c]),z=u?w.size.border:0,O=w.colors.border,F=w.colors.surface,D=useMemo(()=>initialsFromName(a),[a]),G=useMemo(()=>p?avatarToneColors(w,p):null,[w,p]),P=useMemo(()=>b||(G?.background??w.colors[hashColor(a??"",AVATAR_COLORS)]),[b,G,a,w]),N=f??G?.color??w.colors["on-primary"],$=r?keyOfSource(r):null,B=null!==$&&$!==T,H=!B&&""===D&&null!=m,U=f??G?.color??w.colors["text-subtle"],W=v??Math.max(w.text.xs.size,Math.round(.4*E)),Y=Math.max(8,Math.round(.25*E)),q=isRingStatus(g),X=E-2*(q?3:z),J=q?resolveRadius(w,n,X,c):Math.max(0,k-z),K=H?renderSlotIcon(m,{color:U,size:Math.round(.45*X),disabled:!1}):null,Q=q?statusColor(w,g):"transparent",Z=Math.max(12,Math.round(.32*E)),ee=Math.max(10,Z-4),te=b??G?.background??w.colors["bg-muted"],re=B?"contain"===d?"transparent":w.colors["bg-muted"]:H?te:P,oe=R??"avatar",se=a?M.avatarOf(a):M.avatar,ae="verified"===g?`, ${M.verified}`:"pending"===g?`, ${M.pendingVerification}`:"",ie=A??`${se}${ae}`,ne="function"==typeof x||"function"==typeof S,le=A??`${a||se}${ae}`,ce=Math.max(0,Math.ceil((44-E)/2)),ue=V??ce,de=[styles.root,{width:E,height:E,borderRadius:k,...smoothCorners,borderWidth:q?0:z,borderColor:O,backgroundColor:q?"transparent":re},_],me=_jsxs(_Fragment,{children:[q?_jsx(View,{style:[styles.ring,{borderRadius:k,...smoothCorners,borderWidth:1.5,borderColor:Q}],accessible:!1,pointerEvents:"none",testID:`${oe}-ring`}):null,_jsx(View,{style:[styles.picture,{width:X,height:X,borderRadius:J,...smoothCorners,borderWidth:q?z:0,borderColor:O,backgroundColor:q?re:"transparent"}],children:B?(()=>{const e={width:X,height:X,borderRadius:J,...smoothCorners},onError=()=>L($),t=uriOfSource(r);return o?_jsx(o,{source:r,onError:onError,style:e,contentFit:d,resizeMode:d,accessibilityIgnoresInvertColors:!0}):s&&void 0!==t?_jsx(AuthedImage,{uri:t,client:s,onError:onError,style:e,contentFit:d,placeholder:null,fallback:null,accessibilityIgnoresInvertColors:!0}):_jsx(Image,{source:r,onError:onError,style:e,contentFit:d,accessibilityIgnoresInvertColors:!0})})():K||_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,maxFontSizeMultiplier:1.2,style:[styles.initials,{color:N,fontSize:W,lineHeight:Math.round(W*w.leading.body)},I],children:D??" "})}),"verified"===g?_jsx(View,{style:[styles.status,"topRight"===h?styles.badgeTopRight:styles.badgeBottomRight,{width:Z,height:Z,borderRadius:Z/2,...smoothCorners,backgroundColor:F}],accessible:!1,pointerEvents:"none",testID:`${oe}-badge`,children:_jsx(AppIcon,{name:"verify",variant:"bold",size:ee,color:Q})}):null,g&&!q?_jsx(View,{style:[styles.status,"topRight"===h?styles.statusTopRight:styles.statusBottomRight,{width:Y,height:Y,borderRadius:Y/2,...smoothCorners,backgroundColor:statusColor(w,g),borderWidth:2,borderColor:F}],accessible:!1,pointerEvents:"none"}):null]}),ge=ne?_jsx(Pressable,{ref:t,onPress:x?e=>{const t=resolveHaptic(C,"selection");t&&triggerHaptic(t),x?.(e)}:void 0,onLongPress:S?e=>{const t=resolveHaptic(C,"longPress");t&&triggerHaptic(t),S?.(e)}:void 0,hitSlop:ue,...hitSlopMarker(ue),accessibilityRole:"button",accessibilityLabel:le,testID:R,style:({pressed:e})=>[de,e?styles.pressed:null],children:me}):_jsx(View,{ref:t,style:de,accessible:!0,accessibilityRole:"image",accessibilityLabel:ie,testID:R,children:me});return y?_jsx(AvatarSkeleton,{...e}):ge});Avatar.displayName="Avatar";const AvatarSkeleton=({size:e="md",shape:t="circle",dimension:r,style:o})=>{const s=r??resolveSize(e);return _jsx(Skeleton,{shape:"circle"===t?"circle":"rounded"===t?"rounded":"rect",width:s,height:s,style:o})};AvatarSkeleton.displayName="AvatarSkeleton",Avatar.Skeleton=AvatarSkeleton;const styles=StyleSheet.create({root:{alignItems:"center",justifyContent:"center",overflow:"visible",position:"relative"},pressed:{opacity:.7},initials:{textAlign:"center"},ring:{position:"absolute",top:0,right:0,bottom:0,left:0},picture:{alignItems:"center",justifyContent:"center",overflow:"hidden"},status:{position:"absolute"},badgeTopRight:{top:-2,right:-2,alignItems:"center",justifyContent:"center"},badgeBottomRight:{bottom:-2,right:-2,alignItems:"center",justifyContent:"center"},statusTopRight:{top:0,right:0},statusBottomRight:{bottom:0,right:0}}),SPACING_OFFSET={tight:"lg",normal:"md",loose:"sm"},STAGGER_MS=50,ENTRANCE_DURATION_MS=220,AvatarGroupItem=({delay:e,marginLeft:t,borderColor:r,borderWidth:o,children:s})=>{const a=useTheme(),i=useRef(createAnimatedValue(0)).current;return useEffect(()=>{const t=Animated.timing(i,{toValue:1,duration:220,delay:e,easing:Easing.out(Easing.cubic),useNativeDriver:!0});return t.start(),()=>t.stop()},[e,i]),_jsx(Animated.View,{style:[groupStyles.item,{marginLeft:t,borderRadius:a.radius.pill,borderColor:r,borderWidth:o,opacity:i}],children:s})},AvatarGroup=e=>{const{children:t,max:r=4,size:o="md",spacing:s="normal",overflowVariant:a="count",accessibilityLabel:i,style:n,testID:l,labels:c}=e;assertValidValue("AvatarGroup","spacing",e.spacing,["tight","normal","loose"]),assertValidValue("AvatarGroup","overflowVariant",e.overflowVariant,["count","plus"]),assertValidValue("AvatarGroup","size",e.size,Object.keys(sizeMap));const u=useMemo(()=>c?{...DEFAULT_AVATAR_LABELS,...c}:DEFAULT_AVATAR_LABELS,[c]),d=useTheme(),m=useMemo(()=>Children.toArray(t).filter(e=>isValidElement(e)),[t]),g=m.length,h=m.slice(0,r),p=Math.max(0,g-r),b=p>0,f=-d.space[SPACING_OFFSET[s]],v=d.colors.surface,y=i??u.groupOf(g),A=useMemo(()=>resolveSize(o),[o]),x=Math.max(d.text.xs.size,Math.round(.34*A));return _jsxs(View,{style:[groupStyles.row,n],accessible:!0,accessibilityLabel:y,accessibilityRole:"summary",testID:l,children:[h.map((e,t)=>{const r=e.key??`avatar-${t}`,s=cloneElement(e,{size:o,labels:e.props.labels??c});return _jsx(AvatarGroupItem,{delay:50*t,marginLeft:0===t?0:f,borderColor:v,borderWidth:1.5,children:s},r)}),b?_jsx(AvatarGroupItem,{delay:50*h.length,marginLeft:0===h.length?0:f,borderColor:v,borderWidth:1.5,children:_jsx(View,{style:[groupStyles.overflow,{width:A,height:A,borderRadius:A/2,...smoothCorners,backgroundColor:d.colors["surface-disabled"]}],accessible:!0,accessibilityRole:"text",accessibilityLabel:"count"===a?u.moreCount(p):u.moreAvatars,children:_jsx(Text,{variant:"label",weight:"semibold",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{fontSize:x,lineHeight:Math.round(x*d.leading.body)},children:"count"===a?`+${p}`:"+"})})},"avatar-overflow"):null]})},groupStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},item:{...smoothCorners},overflow:{alignItems:"center",justifyContent:"center"}});export{Avatar,AvatarGroup};export default Avatar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveBadgeSize,setNativeValue,useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveBadgeSize,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BADGE_LABELS=Object.freeze({indicator:"Notification indicator",unread:e=>`${e} unread`});const toneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors.primary,text:e.colors["on-primary"]};case"success":return{background:e.colors.success,text:e.colors["on-success"]};case"warning":return{background:e.colors.warning,text:e.colors["on-warning"]};case"info":return{background:e.colors.info,text:e.colors["on-info"]};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-body"]};default:return{background:e.colors.danger,text:e.colors["on-danger"]}}},softToneFor=(e,t)=>{switch(t){case"primary":return{background:e.colors["primary-soft"],text:e.colors.primary};case"success":return{background:e.colors["success-soft"],text:e.colors.success};case"warning":return{background:e.colors["warning-soft"],text:e.colors.warning};case"info":return{background:e.colors["info-soft"],text:e.colors.info};case"neutral":return{background:e.colors["bg-muted"],text:e.colors["text-muted"]};default:return{background:e.colors["danger-soft"],text:e.colors.danger}}},anchorPosition=(e,t)=>{const o=-t;switch(e){case"topLeft":return{top:o,left:o};case"bottomRight":return{bottom:o,right:o};case"bottomLeft":return{bottom:o,left:o};default:return{top:o,right:o}}},formatValue=(e,t)=>{if(null==e)return null;if("number"==typeof e)return e<=0?null:e>t?`${t}+`:String(e);const o=String(e);return 0===o.length?null:o},Badge=forwardRef((e,t)=>{const{value:o,max:r=99,variant:s="standard",tone:i="danger",size:n="sm",fill:a="solid",accessible:l=!0,invisible:d=!1,loading:c=!1,children:u,anchor:g="topRight",pulse:h=!1,accessibilityLabel:m,labels:f,style:b,badgeStyle:p,textStyle:x,testID:y}=e;assertValidValue("Badge","variant",e.variant,["standard","dot"]),assertValidValue("Badge","tone",e.tone,["primary","success","warning","danger","neutral","info"]),assertValidValue("Badge","size",e.size,["sm","md"]),assertValidValue("Badge","anchor",e.anchor,["topRight","topLeft","bottomRight","bottomLeft"]),assertValidValue("Badge","fill",e.fill,["solid","soft"]);const w=useMemo(()=>({...DEFAULT_BADGE_LABELS,...f}),[f]),V=useTheme(),S=useMemo(()=>"soft"===a?softToneFor(V,i):toneFor(V,i),[V,i,a]),k=resolveBadgeSize(V,n),v=V.components.badge["border-width"],B=V.components.badge["anchor-offset"],j="dot"===s?null:formatValue(o,r),z=!d&&("dot"===s||null!==j),A=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!h||!z)return void setNativeValue(A,1);const e=Animated.loop(Animated.sequence([Animated.timing(A,{toValue:1.15,duration:V.motion.duration.slow,easing:Easing.bezier(...V.motion.ease["in-out"]),useNativeDriver:!0}),Animated.timing(A,{toValue:1,duration:V.motion.duration.slow,easing:Easing.bezier(...V.motion.ease["in-out"]),useNativeDriver:!0})]));return e.start(),()=>{e.stop()}},[h,z,A,V]);const _="dot"===s,L=_?"image":"text",E=m??(_?w.indicator:j?w.unread(j):void 0),R=z?_jsx(Animated.View,{style:[styles.badge,_?{width:k["dot-size"],height:k["dot-size"],borderRadius:k["dot-size"]/2,...smoothCorners,paddingHorizontal:0}:{minWidth:k["min-width"],minHeight:k.height,borderRadius:V.radius.pill,...smoothCorners,paddingHorizontal:k["padding-x"]},{backgroundColor:S.background,transform:[{scale:A}]},u?{position:"absolute",borderWidth:v,borderColor:V.colors.surface,...anchorPosition(g,B)}:null,p],accessible:l,importantForAccessibility:l?void 0:"no-hide-descendants",accessibilityElementsHidden:!l||void 0,accessibilityRole:l?L:void 0,accessibilityLabel:l?E:void 0,children:_||null===j?null:_jsx(Text,{variant:"caption",weight:"soft"===a?"semibold":"bold",numberOfLines:1,style:[styles.text,{color:S.text,fontSize:k.text,lineHeight:Math.round(k.text*V.leading.body)},x],children:j??" "})}):null,D=u?_jsxs(View,{ref:t,style:[styles.wrapper,b],testID:y,children:[u,R]}):_jsx(View,{ref:t,style:b,testID:y,children:R});return c?_jsx(BadgeSkeleton,{...e}):D});Badge.displayName="Badge";const BadgeSkeleton=({variant:e="standard",size:t="md",children:o,anchor:r,style:s,badgeStyle:i})=>{const n=useTheme(),a=resolveBadgeSize(n,t);if("dot"===e)return _jsx(Skeleton,{shape:"circle",width:a["dot-size"],height:a["dot-size"],style:[i,s]});const l=a.height/2;if(void 0!==o){const e="topLeft"===r?{top:-a.height/2,left:-a.height/2}:"bottomRight"===r?{bottom:-a.height/2,right:-a.height/2}:"bottomLeft"===r?{bottom:-a.height/2,left:-a.height/2}:{top:-a.height/2,right:-a.height/2};return _jsxs(View,{style:[styles.wrapper,s],children:[o,_jsx(View,{style:[{position:"absolute"},e],children:_jsx(Skeleton,{width:a["min-width"]+a["padding-x"],height:a.height,radius:l,style:i})})]})}return _jsx(Skeleton,{width:a["min-width"]+a["padding-x"],height:a.height,radius:l,style:[i,s]})};BadgeSkeleton.displayName="BadgeSkeleton",Badge.Skeleton=BadgeSkeleton;const styles=StyleSheet.create({wrapper:{position:"relative",alignSelf:"flex-start"},badge:{alignItems:"center",justifyContent:"center",flexDirection:"row"},text:{textAlign:"center",includeFontPadding:!1}});export{Badge};export default Badge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{
|
|
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{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 Banner=forwardRef((e,t)=>{const{title:r,message:s,tone:o="neutral",variant:n="bar",icon:i,actions:a,dismissible:l=!1,onClose:c,haptic:d,open:u=!0,animateMount:m=!0,loading:p=!1,accessibilityRole:g="alert",accessibilityLabel:h,labels:y,style:b,containerStyle:x,iconCircleStyle:f,tintBarStyle:w,closeButtonStyle:j,actionButtonStyle:S,testID:B}=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 V=useTheme(),k=usePresenceMotion(),C=useMemo(()=>buildStyles(V),[V]),_=useMemo(()=>tintFor(V,o),[V,o]),R=useMemo(()=>({...DEFAULT_BANNER_LABELS,...y}),[y]),[v,I]=k.range(-20,0),A=useRef(createAnimatedValue(m&&u?v:0)).current,T=useRef(createAnimatedValue(m&&u?0:u?1:0)).current,[L,D]=useState(u),H=useRef(!0);if(useEffect(()=>{if(H.current&&(H.current=!1,!m))return;let e;return u?(D(!0),e=Animated.parallel([Animated.timing(A,{toValue:I,duration:V.motion.duration.default,useNativeDriver:!0}),Animated.timing(T,{toValue:1,duration:k.duration("default"),useNativeDriver:!0})]),e.start()):L&&(e=Animated.parallel([Animated.timing(A,{toValue:v,duration:V.motion.duration.fast,useNativeDriver:!0}),Animated.timing(T,{toValue:0,duration:k.duration("fast"),useNativeDriver:!0})]),e.start(()=>{D(!1)})),()=>e?.stop()},[u]),!L)return null;const E=r??" ",M="string"==typeof s?s??" ":"",N="wash"===n,z="bar"!==n,P="alert"===g?"danger"===o?"assertive":"polite":"none",W=_jsxs(Animated.View,{ref:t,accessibilityRole:g,accessibilityLiveRegion:P,accessibilityLabel:h,testID:B,style:[C.container,{backgroundColor:z?_.soft:V.colors["bg-subtle"],borderRadius:N?V.radius.sm:V.radius.md,...smoothCorners,padding:V.space.md,opacity:T,transform:[{translateY:A}]},x,b],children:[!N&&V.components.banner["tint-bar-width"]>0?_jsx(View,{style:[C.tintBar,{backgroundColor:_.bar},w]}):null,_jsxs(View,{style:[C.row,void 0===r&&C.rowCentred],children:[!1===i?null:i?_jsx(View,{style:C.iconWrap,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(i,{color:_.ink,size:V.text.xl.size,disabled:!1})}):_jsx(IconBadge,{dimension:ICON_CIRCLE_SIZE,color:_.bar,icon:_jsx(Text,{variant:"body",weight:"bold",accessible:!1,style:[C.iconGlyph,{color:_.ink}],children:_.glyph}),style:[C.iconCircle,f]}),_jsxs(View,{style:C.textBlock,children:[r||p?_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:2,style:{lineHeight:20,...N?{color:_.ink}:null},children:E}):null,"string"==typeof s||p?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{lineHeight:18,marginTop:r?V.space.xxs:0},children:M||" "}):_jsx(View,{style:{marginTop:r?V.space.xxs:0},children:s})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:R.dismiss,onPress:()=>{const e=resolveHaptic(d,"selection");e&&triggerHaptic(e),c?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[C.closeBtn,{backgroundColor:e?V.colors["surface-pressed"]:"transparent"},j],children:_jsx(Text,{variant:"title",weight:"bold",color:"secondary",accessible:!1,style:{lineHeight:17},children:"×"})}):null]}),a&&a.length>0?_jsx(View,{style:C.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",s=e.variant??"ghost",o="primary"===r?_.glyphColor:"neutral"===r?V.colors["text-muted"]:V.colors[r],n="primary"===r?_.ink:"neutral"===r?V.colors["text-muted"]:V.colors[`${r}-text`],i="primary"===r?_.on:"neutral"===r?V.colors["on-neutral-strong"]:V.colors[`on-${r}`],a="solid"===s;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})=>[C.actionBtn,"md"===e.size&&C.actionBtnMd,"outline"===s&&{borderWidth:1,borderColor:n},{backgroundColor:a?o:t?V.colors["surface-pressed"]:"transparent",opacity:a&&t?.85:1},S],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:a?i:n},children:e.label})},`${e.label}-${t}`)})}):null]});return p?_jsx(BannerSkeleton,{...e}):W});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:s,style:o})=>{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},s,o],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",Banner.Skeleton=BannerSkeleton;const tintFor=(e,t)=>{switch(t){case"success":return{soft:e.colors["success-soft"],bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{soft:e.colors["warning-soft"],bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{soft:e.colors["danger-soft"],bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{soft:e.colors["bg-subtle"],bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};case"primary":return{soft:e.colors["primary-soft"],bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"};case"info":return{soft:e.colors["info-soft"],bar:e.colors.info,glyphColor:e.colors.info,ink:e.colors["info-text"],on:e.colors["on-info"],glyph:"i"};default:return tintFor(e,"neutral")}},ICON_CIRCLE_SIZE=28,buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},rowCentred:{alignItems:"center"},iconWrap:{marginRight:r},iconCircle:{marginRight:r},iconGlyph:{lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}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{
|
|
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{Gesture,GestureDetector}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,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:b,testID:y}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...f}),[f]),g=useTheme(),S=r.length,[j,w]=useState(0),[T,C]=useControllableState({value:h,defaultValue:d,onChange:p}),M=null!==T&&T>=0&&T<S?T:null,R=useRef(M);R.current=M;const A=useRef(-1),V=resolveHaptic(x,"tick"),v=useCallback(()=>{V&&triggerHaptic(V)},[V]),L=m??(S>0&&S<=7),D=void 0!==o&&o.length>0,E=useMemo(()=>D?o.map((e,t)=>e.tone??STACK_TONES[t%STACK_TONES.length]):[],[D,o]),I=useMemo(()=>D?o.map(e=>e.key):[],[D,o]),$=useMemo(()=>D?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,D]),k=useMemo(()=>$?$.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,$]),B=useMemo(()=>$?$.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):k,[$,k]),H=useMemo(()=>barScale(B),[B]),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)+g.space.xs,P=S>0?j/S:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useCallback(e=>{const t=r[e];return t.accessibilityLabel?t.accessibilityLabel:$&&o?`${t.label}, ${o.map((t,r)=>`${t.label} ${c($[e][r])}`).join(", ")}`:`${t.label}, ${c(k[e])}`},[r,c,k,$,o]),J=useMemo(()=>{let e=-1;return k.forEach((t,r)=>{(-1===e||t>k[e])&&(e=r)}),e},[k]),Y=n??(J>=0?_.highest(r[J].label,c(k[J])):""),Z=useRef({fire:v,setSelected:C,count:S,plotWidth:j});Z.current={fire:v,setSelected:C,count:S,plotWidth:j};const q=useMemo(()=>{const indexAt=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)))},scrubTo=e=>{const t=indexAt(e);t<0||t===A.current||(A.current=t,Z.current.fire(),Z.current.setSelected(t))},e=Gesture.Pan().runOnJS(!0).activeOffsetX([-8,8]).failOffsetY([-12,12]).onStart(e=>{A.current=R.current??-1,scrubTo(e.x)}).onUpdate(e=>scrubTo(e.x)).withTestId(y?`${y}-pan`:"bar-chart-pan"),t=Gesture.Tap().runOnJS(!0).onEnd((e,t)=>{if(!t)return;const r=indexAt(e.x);r<0||(Z.current.fire(),A.current=r,Z.current.setSelected(r===R.current?null:r))}).withTestId(y?`${y}-tap`:"bar-chart-tap");return Gesture.Race(e,t)},[y]),Q=useCallback(e=>{if(0===S)return;const t=R.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(S-1,t+1):null===t?S-1:Math.max(0,t-1);r!==t&&(v(),C(r))},[S,v,C]),ee=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);w(e=>e===t?e:t)},[]),te=a??toneColor(g,s),re=g.radius.sm,se=l??_.chart,ae=0===S?`${se}, ${_.noData}`:Y?`${se}, ${Y}`:se,oe=null===M?Y:K(M),ie=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:y?`${y}-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(g,E[r])}},I[r]))}),_jsx(View,{testID:y?`${y}-bar-${t}`:void 0,style:{position:"absolute",left:(P-ie)/2,top:o,width:ie,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:re,borderTopRightRadius:re}:null,...a<0?{borderBottomLeftRadius:re,borderBottomRightRadius:re}:null},children:i})},le=k.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:[j>0&&$?renderStack($[t],t,o):null,j>0&&!$&&a>0?_jsx(View,{testID:y?`${y}-bar-${t}`:void 0,style:{position:"absolute",left:(P-ie)/2,top:s,width:ie,height:a,backgroundColor:te,opacity:o?.4:1,...smoothCorners,...e>=0?{borderTopLeftRadius:re,borderTopRightRadius:re}:{borderBottomLeftRadius:re,borderBottomRightRadius:re}}}):null,L&&j>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?($?G(B[2*t]):r)-20+2:($?G(B[2*t+1]):r)+2},children:u(e)}):null]},t)});return 0===S?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ae,testID:y,style:[styles.root,b],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ae,accessibilityValue:{min:0,max:S-1,now:M??0,text:oe},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:y,style:[styles.root,b],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:g.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:r[M].label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:y?`${y}-callout`:void 0,children:c(k[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:g.space.xs,left:0,top:G(e)-8},children:U[t]},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:q,children:_jsxs(View,{style:{height:i},onLayout:ee,testID:y?`${y}-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?g.colors["text-subtle"]:g.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:le})]})}),_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:g.space.sm,columnGap:g.space.md,rowGap:g.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:g.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:g.radius.sm,...smoothCorners,backgroundColor:toneColor(g,E[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;
|