@webority/mobile-ui 0.133.0 → 0.134.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/canvas-kit/kit.js +2162 -2048
  2. package/dist/canvas-kit/manifest.json +2 -2
  3. package/dist/canvas-kit/release.json +6 -6
  4. package/lib/commonjs/components/AppIcon/slotIcon.js +1 -1
  5. package/lib/commonjs/components/Banner/Banner.js +1 -1
  6. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  7. package/lib/commonjs/components/Button/Button.js +1 -1
  8. package/lib/commonjs/components/Card/Card.js +1 -1
  9. package/lib/commonjs/components/Chip/Chip.js +1 -1
  10. package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
  11. package/lib/commonjs/components/DateSeparator/DateSeparator.js +1 -1
  12. package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
  13. package/lib/commonjs/components/IconButton/IconButton.js +1 -1
  14. package/lib/commonjs/components/Input/Input.js +1 -1
  15. package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
  16. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  17. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  18. package/lib/commonjs/components/SearchBar/SearchPanel.js +1 -1
  19. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  20. package/lib/commonjs/components/Select/Select.js +1 -1
  21. package/lib/commonjs/components/StatTile/StatTile.js +1 -1
  22. package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
  23. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  24. package/lib/module/components/AppIcon/slotIcon.js +1 -1
  25. package/lib/module/components/Banner/Banner.js +1 -1
  26. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  27. package/lib/module/components/Button/Button.js +1 -1
  28. package/lib/module/components/Card/Card.js +1 -1
  29. package/lib/module/components/Chip/Chip.js +1 -1
  30. package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
  31. package/lib/module/components/DateSeparator/DateSeparator.js +1 -1
  32. package/lib/module/components/Dialog/OverlayActions.js +1 -1
  33. package/lib/module/components/IconButton/IconButton.js +1 -1
  34. package/lib/module/components/Input/Input.js +1 -1
  35. package/lib/module/components/Menu/MenuSurface.js +1 -1
  36. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  37. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  38. package/lib/module/components/SearchBar/SearchPanel.js +1 -1
  39. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  40. package/lib/module/components/Select/Select.js +1 -1
  41. package/lib/module/components/StatTile/StatTile.js +1 -1
  42. package/lib/module/components/Swipeable/Swipeable.js +1 -1
  43. package/lib/module/components/Tabs/Tabs.js +1 -1
  44. package/lib/typescript/commonjs/components/AppIcon/slotIcon.d.ts +8 -0
  45. package/lib/typescript/commonjs/components/DateSeparator/DateSeparator.d.ts +2 -3
  46. package/lib/typescript/module/components/AppIcon/slotIcon.d.ts +8 -0
  47. package/lib/typescript/module/components/DateSeparator/DateSeparator.d.ts +2 -3
  48. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=React.memo(forwardRef((e,t)=>{const{children:i,variant:o,elevation:s="card",radius:a,padding:r,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:x=!1,onCollapsedChange:f,collapsedSummary:S,onRemove:v,separatorHeight:j=StyleSheet.hairlineWidth,footer:C,imageSource:w,imageHeight:_=160,imageAspectRatio:R,imageOverlay:A,loading:F=!1,gradient:T,onPress:k,haptic:I,contextMenu:V,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:P,style:H,containerStyle:z,headerStyle:M,bodyStyle:D,footerStyle:q,testID:E,labels:O,onLayout:W,...N}=e;warnInvalidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),warnInvalidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),warnInvalidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),warnInvalidValue("Card","titleFont",e.titleFont,["sans","serif"]),warnInvalidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=o??U?.defaultVariant??"elevated",$=a??U?.defaultRadius??"lg",J=r??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...O}),[O]),Y=l||"function"==typeof k,Z=useContextMenu(V,{haptic:I||!1,testID:E,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:oe,pressOut:se}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),ae=stylesFor(G),re=Boolean(w),le=G.space[paddingMap[J]],ne=useMemo(()=>T?"string"==typeof T?G.settings.gradients[T]??null:T:null,[T,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:x,onChange:f}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!re&&!ne&&!de,ce,W),xe=StyleSheet.flatten([z,H])??{},fe=xe.backgroundColor,Se=xe.borderColor,ve=fe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),je="outline"===K?G.size.border:0,Ce=Se??G.colors.border,we="none"===s?void 0:G.shadow[s],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Fe=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Te=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:re||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:j,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,re,le,ye.active,ye.size,Re,Ae,ue,j]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:_},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,_]),Ie=u??"",Ve=_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:ae.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:ae.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:I}):p?_jsx(View,{style:ae.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${Ie}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:I}):null,v?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:v,color:G.colors["danger-text"],haptic:I}):null]}),Be=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[ae.header,!c&&ae.headerRow,pe&&ae.headerFolded,M],children:c??Ve}):null,pe?null:_jsx(View,{style:[be||C?ae.body:null,D],children:i}),C&&!pe?_jsx(View,{style:[ae.footer,q],children:C}):null]}),Le=re?_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:ae.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Be})]}):Be,Pe=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Le]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:ve,stroke:je?Ce:void 0,strokeWidth:je}),_jsx(View,{style:[ae.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Le})]}):Le;let He;if(te){const handlePress=e=>{Y&&(I&&triggerHaptic(I),k?.(e))};He=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:oe,onPressOut:se,accessibilityRole:P??(Y?"button":void 0),accessibilityLabel:B,accessibilityHint:L,testID:E,onLayout:ye.onLayout,style:[Te,z,H,Fe],...N,...Z.hostProps,children:Pe})})}else He=_jsx(View,{ref:t,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:P,testID:E,onLayout:ye.onLayout,style:[Te,z,H,Fe],...N,children:Pe});return F?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[He,Z.renderSurface(_jsx(View,{style:[Te,z,H,Fe,ae.preview],children:Pe}))]}):He}));Card.displayName="Card";const CardSkeleton=({variant:e,elevation:t,radius:i,padding:o,bg:s,header:a,footer:r,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),x=y.settings.components.card,f=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",v=o??x?.defaultPadding??"md",j={...DEFAULT_CARD_LABELS,...g},C=paddingMap[v],w=y.space[C],_="flat"===f?y.radius.none:y.radius[S],R=void 0!==a||hasBuiltInHeaderContent(b),A=resolveBackground(y,s)??y.colors.surface,F="outline"===f?1:0,T="outline"===f?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:_,...smoothCorners,borderWidth:F,borderColor:T,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:j.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:w,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:w},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==r?_jsx(View,{style:[{padding:w,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:o,color:s,haptic:a})=>{const r=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===o?void 0:{expanded:o},"aria-expanded":o,onPress:()=>{a&&triggerHaptic(a),i()},style:iconActionStyle,children:_jsx(AppIcon,{name:e,size:20,color:s??r.colors["text-body"]})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return BACKGROUND_TOKENS.includes(t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
1
+ "use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=React.memo(forwardRef((e,t)=>{const{children:i,variant:o,elevation:s="card",radius:a,padding:r,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:x=!1,onCollapsedChange:f,collapsedSummary:S,onRemove:v,separatorHeight:j=StyleSheet.hairlineWidth,footer:C,imageSource:w,imageHeight:_=160,imageAspectRatio:R,imageOverlay:A,loading:F=!1,gradient:T,onPress:k,haptic:V,contextMenu:I,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:H,style:P,containerStyle:z,headerStyle:M,bodyStyle:D,footerStyle:E,testID:q,labels:O,onLayout:W,...N}=e;warnInvalidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),warnInvalidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),warnInvalidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),warnInvalidValue("Card","titleFont",e.titleFont,["sans","serif"]),warnInvalidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=o??U?.defaultVariant??"elevated",$=a??U?.defaultRadius??"lg",J=r??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...O}),[O]),Y=l||"function"==typeof k,Z=useContextMenu(I,{haptic:V||!1,testID:q,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:oe,pressOut:se}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),ae=stylesFor(G),re=Boolean(w),le=G.space[paddingMap[J]],ne=useMemo(()=>T?"string"==typeof T?G.settings.gradients[T]??null:T:null,[T,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:x,onChange:f}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!re&&!ne&&!de,ce,W),xe=StyleSheet.flatten([z,P])??{},fe=xe.backgroundColor,Se=xe.borderColor,ve=fe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),je="outline"===K?G.size.border:0,Ce=Se??G.colors.border,we="none"===s?void 0:G.shadow[s],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Fe=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Te=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:re||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:j,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,re,le,ye.active,ye.size,Re,Ae,ue,j]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:_},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,_]),Ve=u??"",Ie=_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:ae.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:ae.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:V}):p?_jsx(View,{style:ae.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${Ve}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:V}):null,v?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:v,color:G.colors["danger-text"],haptic:V}):null]}),Be=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[ae.header,!c&&ae.headerRow,pe&&ae.headerFolded,M],children:c??Ie}):null,pe?null:_jsx(View,{style:[be||C?ae.body:null,D],children:i}),C&&!pe?_jsx(View,{style:[ae.footer,E],children:C}):null]}),Le=re?_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:ae.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Be})]}):Be,He=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Le]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:ve,stroke:je?Ce:void 0,strokeWidth:je}),_jsx(View,{style:[ae.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Le})]}):Le;let Pe;if(te){const handlePress=e=>{Y&&(V&&triggerHaptic(V),k?.(e))};Pe=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:oe,onPressOut:se,accessibilityRole:H??(Y?"button":void 0),accessibilityLabel:B,accessibilityHint:L,testID:q,onLayout:ye.onLayout,style:[Te,z,P,Fe],...N,...Z.hostProps,children:He})})}else Pe=_jsx(View,{ref:t,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:H,testID:q,onLayout:ye.onLayout,style:[Te,z,P,Fe],...N,children:He});return F?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[Pe,Z.renderSurface(_jsx(View,{style:[Te,z,P,Fe,ae.preview],children:He}))]}):Pe}));Card.displayName="Card";const CardSkeleton=({variant:e,elevation:t,radius:i,padding:o,bg:s,header:a,footer:r,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),x=y.settings.components.card,f=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",v=o??x?.defaultPadding??"md",j={...DEFAULT_CARD_LABELS,...g},C=paddingMap[v],w=y.space[C],_="flat"===f?y.radius.none:y.radius[S],R=void 0!==a||hasBuiltInHeaderContent(b),A=resolveBackground(y,s)??y.colors.surface,F="outline"===f?1:0,T="outline"===f?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:_,...smoothCorners,borderWidth:F,borderColor:T,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:j.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:w,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:w},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==r?_jsx(View,{style:[{padding:w,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:o,color:s,haptic:a})=>{const r=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===o?void 0:{expanded:o},"aria-expanded":o,onPress:()=>{a&&triggerHaptic(a),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:s??r.colors["text-body"]})})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return BACKGROUND_TOKENS.includes(t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{resolveChipSize,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{renderSlotIcon}from"../AppIcon/slotIcon.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_CHIP_LABELS=Object.freeze({remove:e=>`Remove ${e}`});const toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors["primary-soft"],on:e.colors.primary,ink:e.colors["primary-text"],border:e.colors.primary,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"success":return{base:e.colors["bg-muted"],on:e.colors.success,ink:e.colors["success-text"],border:e.colors.success,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"warning":return{base:e.colors["bg-muted"],on:e.colors.warning,ink:e.colors["warning-text"],border:e.colors.warning,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"danger":return{base:e.colors["bg-muted"],on:e.colors.danger,ink:e.colors["danger-text"],border:e.colors.danger,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"info":return{base:e.colors["bg-muted"],on:e.colors.info,ink:e.colors["info-text"],border:e.colors.info,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};default:return{base:e.colors["bg-muted"],on:e.colors["text-body"],ink:e.colors["text-body"],border:e.colors.border,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,r)=>{const{label:s,count:t,selected:o=!1,selectionMode:i="single",onPress:l,onRemove:n,leftIcon:a,iconVariant:c,variant:d="soft",tone:p="neutral",size:m="md",disabled:u=!1,loading:h=!1,accessibilityLabel:b,haptic:y,style:g,textStyle:f,containerStyle:x,countStyle:S,closeButtonStyle:C,closeIconStyle:I,labels:k,removeTestID:v,testID:j}=e;warnInvalidValue("Chip","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("Chip","tone",e.tone,["primary","neutral","success","warning","danger","info"]),warnInvalidValue("Chip","size",e.size,["sm","md"]),warnInvalidValue("Chip","selectionMode",e.selectionMode,["single","multiple","radio"]);const w=useTheme(),_=useMemo(()=>({...DEFAULT_CHIP_LABELS,...k}),[k]),z=!!l&&!u,L="radio"===i,B=!!l&&(!u||L),O=hasChipCount(t),{style:M,pressIn:T,pressOut:P}=usePressAnimation({enabled:z}),V=useMemo(()=>toneFor(w,p),[w,p]),A=useMemo(()=>resolveChipSize(w,m),[w,m]),R=Math.max(0,Math.ceil((44-A["min-height"])/2)),H=L?{top:R,bottom:R}:void 0,D="solid"===d,F="soft"===d,E=(()=>{if(F){const e=o?V.selectedOn:V.on;return tintOf(e,o?.24:.14,o?V.selectedBg:V.base)}return o?D?V.selectedBg:"transparent":D?V.base:"transparent"})(),U=F?"transparent":o?V.selectedBorder:D?"transparent":V.border,$=u?w.colors["text-disabled"]:o?F?w.colors["text-body"]:V.selectedInk:V.ink,N=D||F?0:w.size.border,handlePress=()=>{if(!z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),l?.()},Y=b??(O?`${s}, ${t}`:s),W=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:A.gap},children:renderSlotIcon(a,{color:$,size:A.icon,disabled:u},c)}):null,_jsx(Text,{variant:"label",weight:"medium",numberOfLines:1,style:[styles.label,{color:$,fontSize:A.text,lineHeight:Math.round(A.text*w.leading.body)},f],children:s??" "}),O?_jsx(Text,{variant:"caption",numberOfLines:1,style:[styles.count,{color:$,fontSize:Math.min(w.text.xs.size,A.text),marginLeft:w.space.xs},S],children:t}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==y&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:_.remove(s),accessibilityState:{disabled:u},"aria-disabled":u,testID:v,hitSlop:6,...hitSlopMarker(6),style:({pressed:e})=>[styles.close,{width:A["close-size"],height:A["close-size"],borderRadius:A["close-size"]/2,...smoothCorners,marginLeft:A.gap,backgroundColor:e?w.colors["surface-pressed"]:w.colors["surface-hover"]},C],children:_jsx(Text,{variant:"label",weight:"bold",maxFontSizeMultiplier:1,style:[{color:$,fontSize:A["close-text"],lineHeight:A["close-text"]+2},I],children:"×"})}):null]}),q={paddingHorizontal:A["padding-x"],paddingVertical:A["padding-y"],minHeight:A["min-height"],borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden",backgroundColor:E,borderWidth:N,borderColor:U,opacity:u?.55:1};let G;return G=B?_jsx(Animated.View,{style:[M,{alignSelf:"flex-start",borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden"}],children:_jsx(Pressable,{ref:r,onPress:handlePress,onPressIn:T,onPressOut:P,disabled:!z,accessibilityRole:L?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:Y,accessibilityState:L||"multiple"===i?{checked:o,disabled:u}:{selected:o,disabled:u},"aria-checked":L||"multiple"===i?o:void 0,"aria-selected":L||"multiple"===i?void 0:o,"aria-disabled":u,hitSlop:H,...H?hitSlopMarker(H):{},android_ripple:{color:w.colors["surface-pressed"],borderless:!1},testID:j,style:({pressed:e})=>[styles.base,q,e&&"outline"===d?{backgroundColor:w.colors["surface-pressed"]}:null,x,g],children:W})}):_jsx(View,{ref:r,style:[styles.base,q,x,g],accessible:!0,accessibilityRole:"text",accessibilityLabel:Y,accessibilityState:{selected:o,disabled:u},"aria-selected":o,"aria-disabled":u,testID:j,children:W}),h?_jsx(ChipSkeleton,{...e}):G});Chip.displayName="Chip";const ChipSkeleton=({label:e,count:r,size:s="md",leftIcon:t,onRemove:o,style:i,containerStyle:l})=>{const n=useTheme(),a=resolveChipSize(n,s),c=Math.max(40,Math.min(120,7*(e??"").length)),d=a["min-height"],p=d/2,m=c+2*a["padding-x"]+(hasChipCount(r)?a.gap/2+7*String(r).length:0)+(void 0!==t?a.gap+14:0)+(void 0!==o?a.gap+a["close-size"]:0);return _jsx(Skeleton,{width:m,height:d,radius:p,style:[{alignSelf:"flex-start"},l,i]})};ChipSkeleton.displayName="ChipSkeleton",Chip.Skeleton=ChipSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},row:{flexDirection:"row",alignItems:"center"},label:{flexShrink:1,textAlign:"center"},count:{flexShrink:0,fontVariant:["tabular-nums"]},close:{alignItems:"center",justifyContent:"center"}});export{Chip};export default Chip;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{resolveChipSize,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{renderSlotIcon}from"../AppIcon/slotIcon.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_CHIP_LABELS=Object.freeze({remove:e=>`Remove ${e}`});const toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors["primary-soft"],on:e.colors.primary,ink:e.colors["primary-text"],border:e.colors.primary,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"success":return{base:e.colors["bg-muted"],on:e.colors.success,ink:e.colors["success-text"],border:e.colors.success,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"warning":return{base:e.colors["bg-muted"],on:e.colors.warning,ink:e.colors["warning-text"],border:e.colors.warning,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"danger":return{base:e.colors["bg-muted"],on:e.colors.danger,ink:e.colors["danger-text"],border:e.colors.danger,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"info":return{base:e.colors["bg-muted"],on:e.colors.info,ink:e.colors["info-text"],border:e.colors.info,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};default:return{base:e.colors["bg-muted"],on:e.colors["text-body"],ink:e.colors["text-body"],border:e.colors.border,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,r)=>{const{label:s,count:t,selected:o=!1,selectionMode:i="single",onPress:l,onRemove:n,leftIcon:a,iconVariant:c,variant:d="soft",tone:p="neutral",size:m="md",disabled:u=!1,loading:h=!1,accessibilityLabel:b,haptic:y,style:g,textStyle:f,containerStyle:x,countStyle:S,closeButtonStyle:C,closeIconStyle:I,labels:k,removeTestID:v,testID:j}=e;warnInvalidValue("Chip","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("Chip","tone",e.tone,["primary","neutral","success","warning","danger","info"]),warnInvalidValue("Chip","size",e.size,["sm","md"]),warnInvalidValue("Chip","selectionMode",e.selectionMode,["single","multiple","radio"]);const w=useTheme(),_=useMemo(()=>({...DEFAULT_CHIP_LABELS,...k}),[k]),z=!!l&&!u,L="radio"===i,B=!!l&&(!u||L),O=hasChipCount(t),{style:M,pressIn:T,pressOut:P}=usePressAnimation({enabled:z}),A=useMemo(()=>toneFor(w,p),[w,p]),V=useMemo(()=>resolveChipSize(w,m),[w,m]),H=Math.max(0,Math.ceil((44-V["min-height"])/2)),R=L?{top:H,bottom:H}:void 0,D="solid"===d,F="soft"===d,E=(()=>{if(F){const e=o?A.selectedOn:A.on;return tintOf(e,o?.24:.14,o?A.selectedBg:A.base)}return o?D?A.selectedBg:"transparent":D?A.base:"transparent"})(),U=F?"transparent":o?A.selectedBorder:D?"transparent":A.border,$=u?w.colors["text-disabled"]:o?F?w.colors["text-body"]:A.selectedInk:A.ink,N=D||F?0:w.size.border,handlePress=()=>{if(!z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),l?.()},Y=b??(O?`${s}, ${t}`:s),W=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:V.gap},accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(a,{color:$,size:V.icon,disabled:u},c)}):null,_jsx(Text,{variant:"label",weight:"medium",numberOfLines:1,style:[styles.label,{color:$,fontSize:V.text,lineHeight:Math.round(V.text*w.leading.body)},f],children:s??" "}),O?_jsx(Text,{variant:"caption",numberOfLines:1,style:[styles.count,{color:$,fontSize:Math.min(w.text.xs.size,V.text),marginLeft:w.space.xs},S],children:t}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==y&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:_.remove(s),accessibilityState:{disabled:u},"aria-disabled":u,testID:v,hitSlop:6,...hitSlopMarker(6),style:({pressed:e})=>[styles.close,{width:V["close-size"],height:V["close-size"],borderRadius:V["close-size"]/2,...smoothCorners,marginLeft:V.gap,backgroundColor:e?w.colors["surface-pressed"]:w.colors["surface-hover"]},C],children:_jsx(Text,{variant:"label",weight:"bold",maxFontSizeMultiplier:1,style:[{color:$,fontSize:V["close-text"],lineHeight:V["close-text"]+2},I],children:"×"})}):null]}),q={paddingHorizontal:V["padding-x"],paddingVertical:V["padding-y"],minHeight:V["min-height"],borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden",backgroundColor:E,borderWidth:N,borderColor:U,opacity:u?.55:1};let G;return G=B?_jsx(Animated.View,{style:[M,{alignSelf:"flex-start",borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden"}],children:_jsx(Pressable,{ref:r,onPress:handlePress,onPressIn:T,onPressOut:P,disabled:!z,accessibilityRole:L?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:Y,accessibilityState:L||"multiple"===i?{checked:o,disabled:u}:{selected:o,disabled:u},"aria-checked":L||"multiple"===i?o:void 0,"aria-selected":L||"multiple"===i?void 0:o,"aria-disabled":u,hitSlop:R,...R?hitSlopMarker(R):{},android_ripple:{color:w.colors["surface-pressed"],borderless:!1},testID:j,style:({pressed:e})=>[styles.base,q,e&&"outline"===d?{backgroundColor:w.colors["surface-pressed"]}:null,x,g],children:W})}):_jsx(View,{ref:r,style:[styles.base,q,x,g],accessible:!0,accessibilityRole:"text",accessibilityLabel:Y,accessibilityState:{selected:o,disabled:u},"aria-selected":o,"aria-disabled":u,testID:j,children:W}),h?_jsx(ChipSkeleton,{...e}):G});Chip.displayName="Chip";const ChipSkeleton=({label:e,count:r,size:s="md",leftIcon:t,onRemove:o,style:i,containerStyle:l})=>{const n=useTheme(),a=resolveChipSize(n,s),c=Math.max(40,Math.min(120,7*(e??"").length)),d=a["min-height"],p=d/2,m=c+2*a["padding-x"]+(hasChipCount(r)?a.gap/2+7*String(r).length:0)+(void 0!==t?a.gap+14:0)+(void 0!==o?a.gap+a["close-size"]:0);return _jsx(Skeleton,{width:m,height:d,radius:p,style:[{alignSelf:"flex-start"},l,i]})};ChipSkeleton.displayName="ChipSkeleton",Chip.Skeleton=ChipSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},row:{flexDirection:"row",alignItems:"center"},label:{flexShrink:1,textAlign:"center"},count:{flexShrink:0,fontVariant:["tabular-nums"]},close:{alignItems:"center",justifyContent:"center"}});export{Chip};export default Chip;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),ChoiceGroup=forwardRef((e,i)=>{const{options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:l,getOptionDescription:a,getOptionIcon:s,getOptionColor:n,renderOption:d,variant:c="card",indicatorPosition:p="trailing",direction:u="row",gap:m,wrap:g=!1,fullWidth:h,disabled:x=!1,size:b="md",labelLines:f,descriptionLines:y=2,haptic:z,accessibilityLabel:C,style:j,optionStyle:S,description:v,helperText:w,error:H,testID:V}=e,T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),k=useMemo(()=>sizeTokensOf(T)[b],[T,b]);warnInvalidValue("ChoiceGroup","variant",e.variant,["card","chip"]),warnInvalidValue("ChoiceGroup","size",e.size,["sm","md","lg"]),warnInvalidValue("ChoiceGroup","direction",e.direction,["row","column"]),warnInvalidValue("ChoiceGroup","indicatorPosition",e.indicatorPosition,["leading","trailing"]),warnInvalidValue("ChoiceGroup","selectionMode",e.selectionMode,["single","multiple"]);const I=useCallback(e=>t?t(e):e.label??"",[t]),D=useCallback(e=>r?r(e):e.value,[r]),O=useCallback(e=>l?l(e):!0===e.disabled,[l]),G=useCallback(e=>a?a(e):e.description,[a]),L=useCallback(e=>s?s(e):e.icon,[s]),M=useCallback(e=>n?n(e):e.color,[n]),P="multiple"===e.selectionMode,{min:R,max:F}=e,[W,B]=useControllableState({value:e.value,defaultValue:e.defaultValue??(P?[]:void 0),onChange:e.onChange}),A=Array.isArray(W)?W:[],$=useCallback(e=>{const i=D(e);if(P){const e=A.includes(i);if(e&&null!=R&&A.length<=R)return;if(!e&&null!=F&&A.length>=F)return;const o=resolveHaptic(z,"selection");return o&&triggerHaptic(o),void B(e?A.filter(e=>e!==i):[...A,i])}const o=resolveHaptic(z,"selection");o&&triggerHaptic(o),B(i)},[z,P,R,F,A,B,D]),N=h??("card"===c&&"row"===u&&!g),q=g||N&&"row"===u,E=T.radius.md,surfaceFor=(e,i,o)=>i?{borderColor:T.colors.border,backgroundColor:T.colors["surface-disabled"]}:{borderColor:e?o:T.colors.border,backgroundColor:e?tintOf(o,.12,T.colors["surface-selected"]):T.colors.bg},renderIcon=(e,i,o,t)=>{const r=L(e);if(null==r)return null;return renderSlotIcon("string"==typeof r&&i?{name:r,variant:"bold"}:r,{color:o,size:k.iconSize,disabled:t})},renderChip=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=t?T.colors["text-disabled"]:o?r:T.colors["text-body"],a=renderIcon(i,o,l,t);return _jsxs(View,{style:[_.chip,{minHeight:k.minHeight,paddingHorizontal:k.chipPaddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:T.radius.pill,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.xs}],children:[a?_jsx(View,{children:a}):null,_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:l,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)})]})},renderDefaultCard=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=M(i),a=t?T.colors["text-disabled"]:l??T.colors["text-body"],s=G(i),n=renderIcon(i,o,a,t),d=_jsx(RadioDot,{selected:o,color:r,disabled:t,size:b});return _jsxs(View,{style:[_.card,{minHeight:k.minHeight,paddingHorizontal:k.paddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:E,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.sm}],children:["leading"===p?d:null,n?_jsx(View,{children:n}):null,_jsxs(View,{style:_.cardTextWrap,children:[_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:a,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)}),s?_jsx(Text,{numberOfLines:y,ellipsizeMode:"tail",style:[_.cardDescription,{color:o?T.colors["text-muted"]:T.colors["text-subtle"],fontSize:T.text.xs.size,lineHeight:Math.round(T.text.xs.size*T.leading.body)}],children:s}):null]}),"trailing"===p?d:null]})},J="string"==typeof H&&""!==H?H:void 0,K=!0===H||void 0!==J?null:w,Q=_jsx(View,{ref:i,accessibilityRole:P?void 0:"radiogroup",accessibilityLabel:C,accessibilityState:{disabled:x},"aria-disabled":x,testID:V,style:[{flexDirection:u,gap:m??T.space.sm,flexWrap:q?"wrap":"nowrap"},j],children:o.map((e,i)=>{const o=D(e),t=P?A.includes(o):W===o,r=P&&null!=F&&!t&&A.length>=F,l=x||r||O(e),a=M(e)??T.colors.primary,s=d||"card"!==c?void 0:G(e);return _jsx(Pressable,{testID:e.testID,onPress:()=>{l||$(e)},disabled:l,accessibilityRole:P?"checkbox":"radio",accessibilityLabel:s?`${I(e)}, ${s}`:I(e),accessibilityState:{checked:t,disabled:l},"aria-checked":t,"aria-disabled":l,style:[N?_.stretchOption:null,{opacity:l&&d?.55:1},S],children:({pressed:o})=>{const r={option:e,index:i,selected:t,pressed:o&&!l,disabled:l,color:a};return _jsx(_Fragment,{children:d?d(r):"chip"===c?renderChip(r):renderDefaultCard(r)})}},String(o))})});return hasChoiceDetail({description:v,error:J,helperText:K??void 0})?_jsxs(View,{children:[v?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginBottom:T.space.xs},children:v}):null,Q,void 0!==J?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",style:{marginTop:T.space.xs},children:J}):K?_jsx(Text,{variant:"caption",color:"tertiary",style:{marginTop:T.space.xs},children:K}):null]}):Q});ChoiceGroup.displayName="ChoiceGroup";const buildStyles=e=>StyleSheet.create({stretchOption:{flexGrow:1,flexShrink:0,flexBasis:"auto"},card:{flexDirection:"row",alignItems:"center"},chip:{flexDirection:"row",alignItems:"center",justifyContent:"center"},cardTextWrap:{flexGrow:1,flexShrink:1,flexBasis:"auto"},cardLabel:{includeFontPadding:!1},cardDescription:{includeFontPadding:!1,marginTop:e.space.xxs}});export{ChoiceGroup};export default ChoiceGroup;
1
+ "use strict";import{forwardRef,useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),ChoiceGroup=forwardRef((e,i)=>{const{options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:l,getOptionDescription:s,getOptionIcon:a,getOptionColor:n,renderOption:d,variant:c="card",indicatorPosition:p="trailing",direction:u="row",gap:m,wrap:h=!1,fullWidth:g,disabled:b=!1,size:x="md",labelLines:f,descriptionLines:y=2,haptic:z,accessibilityLabel:C,style:j,optionStyle:S,description:v,helperText:w,error:H,testID:V}=e,T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),k=useMemo(()=>sizeTokensOf(T)[x],[T,x]);warnInvalidValue("ChoiceGroup","variant",e.variant,["card","chip"]),warnInvalidValue("ChoiceGroup","size",e.size,["sm","md","lg"]),warnInvalidValue("ChoiceGroup","direction",e.direction,["row","column"]),warnInvalidValue("ChoiceGroup","indicatorPosition",e.indicatorPosition,["leading","trailing"]),warnInvalidValue("ChoiceGroup","selectionMode",e.selectionMode,["single","multiple"]);const I=useCallback(e=>t?t(e):e.label??"",[t]),D=useCallback(e=>r?r(e):e.value,[r]),O=useCallback(e=>l?l(e):!0===e.disabled,[l]),G=useCallback(e=>s?s(e):e.description,[s]),L=useCallback(e=>a?a(e):e.icon,[a]),M=useCallback(e=>n?n(e):e.color,[n]),P="multiple"===e.selectionMode,{min:R,max:F}=e,[W,A]=useControllableState({value:e.value,defaultValue:e.defaultValue??(P?[]:void 0),onChange:e.onChange}),B=Array.isArray(W)?W:[],E=useCallback(e=>{const i=D(e);if(P){const e=B.includes(i);if(e&&null!=R&&B.length<=R)return;if(!e&&null!=F&&B.length>=F)return;const o=resolveHaptic(z,"selection");return o&&triggerHaptic(o),void A(e?B.filter(e=>e!==i):[...B,i])}const o=resolveHaptic(z,"selection");o&&triggerHaptic(o),A(i)},[z,P,R,F,B,A,D]),$=g??("card"===c&&"row"===u&&!h),N=h||$&&"row"===u,q=T.radius.md,surfaceFor=(e,i,o)=>i?{borderColor:T.colors.border,backgroundColor:T.colors["surface-disabled"]}:{borderColor:e?o:T.colors.border,backgroundColor:e?tintOf(o,.12,T.colors["surface-selected"]):T.colors.bg},renderIcon=(e,i,o,t)=>{const r=L(e);if(null==r)return null;return renderSlotIcon("string"==typeof r&&i?{name:r,variant:"bold"}:r,{color:o,size:k.iconSize,disabled:t})},renderChip=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=t?T.colors["text-disabled"]:o?r:T.colors["text-body"],s=renderIcon(i,o,l,t);return _jsxs(View,{style:[_.chip,{minHeight:k.minHeight,paddingHorizontal:k.chipPaddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:T.radius.pill,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.xs}],children:[s?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:l,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)})]})},renderDefaultCard=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=M(i),s=t?T.colors["text-disabled"]:l??T.colors["text-body"],a=G(i),n=renderIcon(i,o,s,t),d=_jsx(RadioDot,{selected:o,color:r,disabled:t,size:x});return _jsxs(View,{style:[_.card,{minHeight:k.minHeight,paddingHorizontal:k.paddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:q,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.sm}],children:["leading"===p?d:null,n?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:n}):null,_jsxs(View,{style:_.cardTextWrap,children:[_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:s,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)}),a?_jsx(Text,{numberOfLines:y,ellipsizeMode:"tail",style:[_.cardDescription,{color:o?T.colors["text-muted"]:T.colors["text-subtle"],fontSize:T.text.xs.size,lineHeight:Math.round(T.text.xs.size*T.leading.body)}],children:a}):null]}),"trailing"===p?d:null]})},J="string"==typeof H&&""!==H?H:void 0,K=!0===H||void 0!==J?null:w,Q=_jsx(View,{ref:i,accessibilityRole:P?void 0:"radiogroup",accessibilityLabel:C,accessibilityState:{disabled:b},"aria-disabled":b,testID:V,style:[{flexDirection:u,gap:m??T.space.sm,flexWrap:N?"wrap":"nowrap"},j],children:o.map((e,i)=>{const o=D(e),t=P?B.includes(o):W===o,r=P&&null!=F&&!t&&B.length>=F,l=b||r||O(e),s=M(e)??T.colors.primary,a=d||"card"!==c?void 0:G(e);return _jsx(Pressable,{testID:e.testID,onPress:()=>{l||E(e)},disabled:l,accessibilityRole:P?"checkbox":"radio",accessibilityLabel:a?`${I(e)}, ${a}`:I(e),accessibilityState:{checked:t,disabled:l},"aria-checked":t,"aria-disabled":l,style:[$?_.stretchOption:null,{opacity:l&&d?.55:1},S],children:({pressed:o})=>{const r={option:e,index:i,selected:t,pressed:o&&!l,disabled:l,color:s};return _jsx(_Fragment,{children:d?d(r):"chip"===c?renderChip(r):renderDefaultCard(r)})}},String(o))})});return hasChoiceDetail({description:v,error:J,helperText:K??void 0})?_jsxs(View,{children:[v?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginBottom:T.space.xs},children:v}):null,Q,void 0!==J?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",style:{marginTop:T.space.xs},children:J}):K?_jsx(Text,{variant:"caption",color:"tertiary",style:{marginTop:T.space.xs},children:K}):null]}):Q});ChoiceGroup.displayName="ChoiceGroup";const buildStyles=e=>StyleSheet.create({stretchOption:{flexGrow:1,flexShrink:0,flexBasis:"auto"},card:{flexDirection:"row",alignItems:"center"},chip:{flexDirection:"row",alignItems:"center",justifyContent:"center"},cardTextWrap:{flexGrow:1,flexShrink:1,flexBasis:"auto"},cardLabel:{includeFontPadding:!1},cardDescription:{includeFontPadding:!1,marginTop:e.space.xxs}});export{ChoiceGroup};export default ChoiceGroup;
@@ -1 +1 @@
1
- "use strict";import{formatDate}from"@webority/mobile-core";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DATE_SEPARATOR_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday"});const DAY_MS=864e5;export const dayLabel=(e,t={})=>{const r=formatDate(e,{empty:""});if(!r)return"";const o={...DEFAULT_DATE_SEPARATOR_LABELS,...t.labels},s=t.now??new Date;return r===formatDate(s)?o.today:r===formatDate(new Date(s.getTime()-DAY_MS))?o.yesterday:r};export const DateSeparator=({date:e,label:t,emphasis:r=!1,labels:o,now:s,style:a,testID:i})=>{const l=useTheme(),m=useMemo(()=>buildStyles(l),[l]),c=t??(void 0===e?"":dayLabel(e,{now:s,labels:o})),n=r?l.colors.primary:l.colors["border-subtle"];return _jsxs(View,{style:[m.row,a],testID:i,children:[_jsx(View,{style:[m.rule,{backgroundColor:n}]}),_jsx(Text,{variant:"caption",weight:r?"semibold":"medium",color:r?void 0:"secondary",style:r?{color:l.colors["primary-text"]}:void 0,accessibilityRole:"header",children:c}),_jsx(View,{style:[m.rule,{backgroundColor:n}]})]})};const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:e.space.sm,paddingVertical:e.space.sm},rule:{flex:1,height:StyleSheet.hairlineWidth}});export default DateSeparator;
1
+ "use strict";import{formatDate}from"@webority/mobile-core";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DATE_SEPARATOR_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday"});const DAY_MS=864e5;export const dayLabel=(e,t={})=>{const r=formatDate(e,{empty:""});if(!r)return"";const o={...DEFAULT_DATE_SEPARATOR_LABELS,...t.labels},s=t.now??new Date;return r===formatDate(s)?o.today:r===formatDate(new Date(s.getTime()-DAY_MS))?o.yesterday:r};export const DateSeparator=({date:e,label:t,emphasis:r=!1,labels:o,now:s,style:a,testID:i})=>{const l=useTheme(),m=useMemo(()=>buildStyles(l),[l]),n=t??(void 0===e?"":dayLabel(e,{now:s,labels:o})),c=r?l.colors.primary:l.colors["border-subtle"];return _jsxs(View,{style:[m.row,a],testID:i,children:[_jsx(View,{style:[m.rule,{backgroundColor:c}]}),_jsx(Text,{variant:"caption",weight:r?"semibold":"medium",color:r?void 0:"secondary",style:r?{color:l.colors["primary-text"]}:void 0,children:n}),_jsx(View,{style:[m.rule,{backgroundColor:c}]})]})};const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:e.space.sm,paddingVertical:e.space.sm},rule:{flex:1,height:StyleSheet.hairlineWidth}});export default DateSeparator;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo,useRef,useState}from"react";import{ActivityIndicator,Pressable,StyleSheet,Text,View}from"react-native";import{fontFor,resolveButtonSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const OVERLAY_TONES=["primary","success","warning","danger","info","neutral"];export const ACTIONS_LAYOUTS=["auto","row","stacked"];const OverlayActions=({actions:o,layout:e,testID:r,stackedLabels:t,rowStyle:n,buttonStyle:l,textStyle:a})=>{const s=useTheme(),i=useMemo(()=>buildStyles(s),[s]),c=s.components.dialog["action-button-min-height"],d=resolveButtonSize(s,"md").icon,u=s.text.base.size*s.leading.body,b=o.map(o=>o.label).join("\n"),m=useState(null),[y,g]=t??m,p="stacked"===e||"row"!==e&&(null!==y&&y===b),x=useRef(null),C=useCallback(o=>{o.nativeEvent.layout.height>1.5*u&&g(b)},[u,b,g]),h=useCallback(o=>{const e=o.nativeEvent.layout.width,r=x.current;x.current=e,null!==r&&Math.abs(r-e)>.5&&g(null)},[g]),f=new Map;return _jsx(View,{testID:r,style:[i.actionsRow,p?i.actionsRowStacked:null,n],onLayout:h,children:o.map((e,r)=>{const t=(f.get(e.label)??0)+1;f.set(e.label,t),warnInvalidValue("OverlayActions","actions[].tone",e.tone,OVERLAY_TONES);const n=e.tone??"primary",u=Boolean(e.disabled),b=actionStyleFor(s,n,u),m=r===o.length-1;return _jsx(Pressable,{onPress:e.onPress,disabled:e.loading||u,accessibilityRole:"button",accessibilityLabel:e.label,accessibilityState:{busy:e.loading,disabled:Boolean(e.loading)||u},"aria-busy":e.loading,"aria-disabled":Boolean(e.loading)||u,style:({pressed:o})=>[i.actionButton,{flex:p?0:1,minHeight:c,backgroundColor:b.backgroundColor,borderColor:b.borderColor,borderWidth:b.borderWidth,borderRadius:s.radius.md,...smoothCorners,paddingVertical:s.space.sm,paddingHorizontal:s.space.md,marginRight:m||p?0:s.space.sm,opacity:e.loading?.7:o&&!u?.85:1},l],children:e.loading?_jsx(ActivityIndicator,{size:"small",color:b.textColor}):_jsxs(View,{style:i.labelRow,children:[e.icon?_jsx(View,{style:i.labelIcon,children:renderSlotIcon(e.icon,{color:b.textColor,size:d,disabled:u},"linear")}):null,_jsx(View,{onLayout:C,children:_jsx(Text,{style:[{color:b.textColor,fontSize:s.text.base.size,...fontFor(s,"semibold"),textAlign:"center"},a],children:e.label})})]})},`${e.label}-${t}`)})})};OverlayActions.displayName="OverlayActions";const actionStyleFor=(o,e,r)=>{if(r)return{backgroundColor:"neutral"===e?"transparent":o.colors["surface-disabled"],borderColor:"neutral"===e?o.colors.border:"transparent",borderWidth:"neutral"===e?1:0,textColor:o.colors["text-disabled"]};switch(e){case"primary":return{backgroundColor:o.colors.primary,borderColor:"transparent",borderWidth:0,textColor:o.colors["on-primary"]};case"info":return{backgroundColor:o.colors.info,borderColor:"transparent",borderWidth:0,textColor:o.colors["on-info"]};case"success":return{backgroundColor:o.colors.success,borderColor:"transparent",borderWidth:0,textColor:o.colors["on-success"]};case"warning":return{backgroundColor:o.colors.warning,borderColor:"transparent",borderWidth:0,textColor:o.colors["on-warning"]};case"danger":return{backgroundColor:o.colors.danger,borderColor:"transparent",borderWidth:0,textColor:o.colors["on-danger"]};default:return{backgroundColor:"transparent",borderColor:o.colors.border,borderWidth:1,textColor:o.colors["text-body"]}}},buildStyles=o=>StyleSheet.create({actionsRow:{flexDirection:"row",justifyContent:"flex-end",alignItems:"stretch"},actionsRowStacked:{flexDirection:"column",rowGap:o.space.sm},actionButton:{alignItems:"center",justifyContent:"center"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},labelIcon:{marginRight:o.space.xs}});export{OverlayActions};
1
+ "use strict";import{useCallback,useMemo,useRef,useState}from"react";import{ActivityIndicator,Pressable,StyleSheet,Text,View}from"react-native";import{fontFor,resolveButtonSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const OVERLAY_TONES=["primary","success","warning","danger","info","neutral"];export const ACTIONS_LAYOUTS=["auto","row","stacked"];const OverlayActions=({actions:e,layout:o,testID:r,stackedLabels:t,rowStyle:n,buttonStyle:l,textStyle:s})=>{const a=useTheme(),i=useMemo(()=>buildStyles(a),[a]),c=a.components.dialog["action-button-min-height"],d=resolveButtonSize(a,"md").icon,u=a.text.base.size*a.leading.body,b=e.map(e=>e.label).join("\n"),m=useState(null),[y,g]=t??m,p="stacked"===o||"row"!==o&&(null!==y&&y===b),x=useRef(null),C=useCallback(e=>{e.nativeEvent.layout.height>1.5*u&&g(b)},[u,b,g]),h=useCallback(e=>{const o=e.nativeEvent.layout.width,r=x.current;x.current=o,null!==r&&Math.abs(r-o)>.5&&g(null)},[g]),f=new Map;return _jsx(View,{testID:r,style:[i.actionsRow,p?i.actionsRowStacked:null,n],onLayout:h,children:e.map((o,r)=>{const t=(f.get(o.label)??0)+1;f.set(o.label,t),warnInvalidValue("OverlayActions","actions[].tone",o.tone,OVERLAY_TONES);const n=o.tone??"primary",u=Boolean(o.disabled),b=actionStyleFor(a,n,u),m=r===e.length-1;return _jsx(Pressable,{onPress:o.onPress,disabled:o.loading||u,accessibilityRole:"button",accessibilityLabel:o.label,accessibilityState:{busy:o.loading,disabled:Boolean(o.loading)||u},"aria-busy":o.loading,"aria-disabled":Boolean(o.loading)||u,style:({pressed:e})=>[i.actionButton,{flex:p?0:1,minHeight:c,backgroundColor:b.backgroundColor,borderColor:b.borderColor,borderWidth:b.borderWidth,borderRadius:a.radius.md,...smoothCorners,paddingVertical:a.space.sm,paddingHorizontal:a.space.md,marginRight:m||p?0:a.space.sm,opacity:o.loading?.7:e&&!u?.85:1},l],children:o.loading?_jsx(ActivityIndicator,{size:"small",color:b.textColor}):_jsxs(View,{style:i.labelRow,children:[o.icon?_jsx(View,{style:i.labelIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(o.icon,{color:b.textColor,size:d,disabled:u},"linear")}):null,_jsx(View,{onLayout:C,children:_jsx(Text,{style:[{color:b.textColor,fontSize:a.text.base.size,...fontFor(a,"semibold"),textAlign:"center"},s],children:o.label})})]})},`${o.label}-${t}`)})})};OverlayActions.displayName="OverlayActions";const actionStyleFor=(e,o,r)=>{if(r)return{backgroundColor:"neutral"===o?"transparent":e.colors["surface-disabled"],borderColor:"neutral"===o?e.colors.border:"transparent",borderWidth:"neutral"===o?1:0,textColor:e.colors["text-disabled"]};switch(o){case"primary":return{backgroundColor:e.colors.primary,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-primary"]};case"info":return{backgroundColor:e.colors.info,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-info"]};case"success":return{backgroundColor:e.colors.success,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-success"]};case"warning":return{backgroundColor:e.colors.warning,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-warning"]};case"danger":return{backgroundColor:e.colors.danger,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-danger"]};default:return{backgroundColor:"transparent",borderColor:e.colors.border,borderWidth:1,textColor:e.colors["text-body"]}}},buildStyles=e=>StyleSheet.create({actionsRow:{flexDirection:"row",justifyContent:"flex-end",alignItems:"stretch"},actionsRowStacked:{flexDirection:"column",rowGap:e.space.sm},actionButton:{alignItems:"center",justifyContent:"center"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},labelIcon:{marginRight:e.space.xs}});export{OverlayActions};
@@ -1 +1 @@
1
- "use strict";import{forwardRef}from"react";import{Animated,Pressable,StyleSheet}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,o)=>{switch(o){case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=forwardRef((e,o)=>{const{icon:s,iconVariant:r,onPress:t,accessibilityLabel:n,accessibilityHint:i,accessibilityState:a,tone:l="primary",variant:c="solid",size:d="md",shape:u="circle",active:m=!1,disabled:b=!1,loading:p=!1,haptic:f,style:g,testID:I}=e;warnInvalidValue("IconButton","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("IconButton","variant",e.variant,["solid","soft","outline","ghost","glass"]),warnInvalidValue("IconButton","size",e.size,["sm","md","lg"]),warnInvalidValue("IconButton","shape",e.shape,["circle","rounded"]),warnInvalidValue("IconButton","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]);const y=useTheme(),h=SIZE_MAP[d],S=b||p,{style:x,pressIn:w,pressOut:j}=usePressAnimation({scaleTo:.92,enabled:!S}),{base:v,outline:P,on:V,fg:_}=toneFor(y,l),A=m?"solid":c,B=m||!0===a?.selected,H={...a,disabled:S,selected:B};let C="transparent",O="transparent",T=0,k=S?y.colors["text-disabled"]:_;"solid"===A?(C=S?y.colors["surface-disabled"]:v,k=S?y.colors["text-disabled"]:V):"soft"===A?C=S?y.colors["surface-disabled"]:tintOf(v,.14,y.colors["bg-subtle"]):"outline"===A?(O=S?y.colors.border:P,T=y.size.border):"glass"===A&&(C=y.colors["glass-fill"],O=y.colors["glass-border"],T=1,k=S?y.colors["text-disabled"]:y.colors["on-glass"]);const z={color:k,size:h.icon,disabled:S},F="circle"===u?h.diameter/2:y.radius.md;return _jsx(Pressable,{ref:o,onPress:e=>{if(S)return;const o=resolveHaptic(f,"selection");o&&triggerHaptic(o),t?.(e)},onPressIn:w,onPressOut:j,disabled:S,accessibilityRole:"button",accessibilityLabel:n,accessibilityHint:i,accessibilityState:H,...ariaFromState(H),"aria-disabled":S,"aria-selected":B,hitSlop:6,...hitSlopMarker(6),testID:I,style:({pressed:e})=>[styles.base,{width:h.diameter,height:h.diameter,borderRadius:F,...smoothCorners,backgroundColor:C,borderColor:O,borderWidth:T,opacity:e&&"solid"!==A?.7:1},g],children:_jsx(Animated.View,{style:[styles.content,x],children:p?_jsx(Spinner,{size:"sm",color:k}):renderSlotIcon(s,z,r)})})});IconButton.displayName="IconButton";const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},content:{alignItems:"center",justifyContent:"center"}});export{IconButton};export default IconButton;
1
+ "use strict";import{forwardRef}from"react";import{Animated,Pressable,StyleSheet}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,o)=>{switch(o){case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=forwardRef((e,o)=>{const{icon:s,iconVariant:t,onPress:r,accessibilityLabel:n,accessibilityHint:i,accessibilityState:a,tone:l="primary",variant:c="solid",size:d="md",shape:u="circle",active:m=!1,disabled:b=!1,loading:p=!1,haptic:f,style:g,testID:I}=e;warnInvalidValue("IconButton","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("IconButton","variant",e.variant,["solid","soft","outline","ghost","glass"]),warnInvalidValue("IconButton","size",e.size,["sm","md","lg"]),warnInvalidValue("IconButton","shape",e.shape,["circle","rounded"]),warnInvalidValue("IconButton","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]);const y=useTheme(),h=SIZE_MAP[d],S=b||p,{style:x,pressIn:w,pressOut:j}=usePressAnimation({scaleTo:.92,enabled:!S}),{base:v,outline:P,on:A,fg:V}=toneFor(y,l),_=m?"solid":c,B=m||!0===a?.selected,H={...a,disabled:S,selected:B};let C="transparent",F="transparent",O=0,T=S?y.colors["text-disabled"]:V;"solid"===_?(C=S?y.colors["surface-disabled"]:v,T=S?y.colors["text-disabled"]:A):"soft"===_?C=S?y.colors["surface-disabled"]:tintOf(v,.14,y.colors["bg-subtle"]):"outline"===_?(F=S?y.colors.border:P,O=y.size.border):"glass"===_&&(C=y.colors["glass-fill"],F=y.colors["glass-border"],O=1,T=S?y.colors["text-disabled"]:y.colors["on-glass"]);const k={color:T,size:h.icon,disabled:S},z="circle"===u?h.diameter/2:y.radius.md;return _jsx(Pressable,{ref:o,onPress:e=>{if(S)return;const o=resolveHaptic(f,"selection");o&&triggerHaptic(o),r?.(e)},onPressIn:w,onPressOut:j,disabled:S,accessibilityRole:"button",accessibilityLabel:n,accessibilityHint:i,accessibilityState:H,...ariaFromState(H),"aria-disabled":S,"aria-selected":B,hitSlop:6,...hitSlopMarker(6),testID:I,style:({pressed:e})=>[styles.base,{width:h.diameter,height:h.diameter,borderRadius:z,...smoothCorners,backgroundColor:C,borderColor:F,borderWidth:O,opacity:e&&"solid"!==_?.7:1},g],children:_jsx(Animated.View,{style:[styles.content,x],accessibilityElementsHidden:!p,importantForAccessibility:p?"auto":"no-hide-descendants","aria-hidden":!p,children:p?_jsx(Spinner,{size:"sm",color:T}):renderSlotIcon(s,k,t)})})});IconButton.displayName="IconButton";const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},content:{alignItems:"center",justifyContent:"center"}});export{IconButton};export default IconButton;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:x,rightIcon:m,unit:g,unitStyle:h,prefix:y,prefixStyle:v,readOnly:b=!1,action:S,actionStyle:w,size:T="md",variant:I,labelMode:j,required:F=!1,maxLength:V,showCounter:_=!0,textAlign:A,format:R,parse:z,style:L,containerStyle:k,inputStyle:P,labelStyle:C,messageStyle:D,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;warnInvalidValue("Input","variant",I,["outline","filled","underline"]),warnInvalidValue("Input","size",e.size,["sm","md","lg"]),warnInvalidValue("Input","labelMode",j,["float","top"]),warnInvalidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,T),J=W.components.input[T]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=I??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=j??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(y),xe=!p&&!1!==q,me=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ye=useCallback(()=>{xe&&ge.current?.focus()},[xe]),ve=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Te=W.settings.components.input?.shakeOnError??!1,Ie=useRef(de);useEffect(()=>{if(!Te)return void(Ie.current=de);let e;return de&&!Ie.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:!0})]),e.start()),triggerHaptic("notificationError")),Ie.current=de,()=>e?.stop()},[de,be,Te,we]);const je=useCallback(e=>{ee(!0),E?.(e)},[E]),Fe=useCallback(e=>{ee(!1),B?.(e)},[B]),Ve=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,ze=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],Le=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ke=Boolean(m)||Boolean(g)||oe,Pe="underline"===Q,Ce=x?X.icon+W.space.md+1+W.space.md:0,De=useFloatingLabel({label:i,enabled:ve,floated:me,required:F,variant:Q,sizeTokens:X,leadingOffset:Ce,trailingOffset:ke?X.icon+W.space.sm:0,textAlign:A,paddingLeft:Pe?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:ze,style:C}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=F&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof V&&"string"==typeof l?`${l.length} / ${V}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(D,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Ve,disabled:!xe,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=m?_jsx(View,{children:renderSlot(m)}):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=x?_jsx(View,{children:renderSlot(x)}):null,Ke=StyleSheet.flatten(v),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},v],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},v],children:_jsx(TextInkContext.Provider,{value:Ze,children:y})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:T,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:Le}]},L],children:[pe&&!ve?_jsx(FieldLabel,{size:T,required:F,help:n,color:ze,style:C,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:T,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=x,paddingLeft:Pe?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:De.topNotch,onPress:ye,pressFeedback:!1,style:k,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:Pe?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},P],textAlign:A,placeholder:ve&&!me||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(z?z(e):e)},onFocus:je,onBlur:Fe,editable:xe,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:V,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),De.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},D],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:y,prefixStyle:v,readOnly:b=!1,action:S,actionStyle:w,size:I="md",variant:T,labelMode:j,required:F=!1,maxLength:V,showCounter:_=!0,textAlign:A,format:R,parse:z,style:L,containerStyle:k,inputStyle:P,labelStyle:C,messageStyle:D,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;warnInvalidValue("Input","variant",T,["outline","filled","underline"]),warnInvalidValue("Input","size",e.size,["sm","md","lg"]),warnInvalidValue("Input","labelMode",j,["float","top"]),warnInvalidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,I),J=W.components.input[I]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=T??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=j??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(y),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ye=useCallback(()=>{me&&ge.current?.focus()},[me]),ve=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Ie=W.settings.components.input?.shakeOnError??!1,Te=useRef(de);useEffect(()=>{if(!Ie)return void(Te.current=de);let e;return de&&!Te.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:!0})]),e.start()),triggerHaptic("notificationError")),Te.current=de,()=>e?.stop()},[de,be,Ie,we]);const je=useCallback(e=>{ee(!0),E?.(e)},[E]),Fe=useCallback(e=>{ee(!1),B?.(e)},[B]),Ve=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,ze=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],Le=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ke=Boolean(x)||Boolean(g)||oe,Pe="underline"===Q,Ce=m?X.icon+W.space.md+1+W.space.md:0,De=useFloatingLabel({label:i,enabled:ve,floated:xe,required:F,variant:Q,sizeTokens:X,leadingOffset:Ce,trailingOffset:ke?X.icon+W.space.sm:0,textAlign:A,paddingLeft:Pe?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:ze,style:C}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=F&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof V&&"string"==typeof l?`${l.length} / ${V}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(D,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Ve,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(v),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},v],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},v],children:_jsx(TextInkContext.Provider,{value:Ze,children:y})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:I,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:Le}]},L],children:[pe&&!ve?_jsx(FieldLabel,{size:I,required:F,help:n,color:ze,style:C,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:I,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:Pe?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:De.topNotch,onPress:ye,pressFeedback:!1,style:k,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:Pe?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},P],textAlign:A,placeholder:ve&&!xe||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(z?z(e):e)},onFocus:je,onBlur:Fe,editable:me,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:V,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),De.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},D],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:o,title:i,topActions:n,placement:r,presentation:l,unavailable:a,context:c=!1,preview:u,onClose:d,restoreFocusTo:m,haptic:p,accessibilityLabel:f,labels:b,testID:h}=e,x=useTheme(),y=useMemo(()=>buildStyles(x),[x]),g=useSafeAreaInsets(),[v,_]=useModalInsets(),w=useMemo(()=>({...g,top:v.top,bottom:v.bottom}),[g,v]),j=useWindowDimensions(),A=usePresenceMotion(),I=A.duration("fast"),k=useMemo(()=>visibleGroups(o,a),[o,a]),S=useMemo(()=>visibleTopActions(n,a),[n,a]),E="sheet"===l||"auto"===l&&j.width<Breakpoints.lg&&wantsSheet(k,S),[M,C]=useState(null),[D,R]=useState(null),T=useRef(d);T.current=d;const L=useRef(m);L.current=m;const O=useRef(null),P=useRef(!1),V=useRef(!1),H=useRef(new Map),N=useRef(null),B=useCallback(()=>{if(!P.current)return;P.current=!1;const e=O.current;O.current=null,e?e():focusHost(L.current?.())},[]);useEffect(()=>{if(t)return V.current=!0,P.current=!1,O.current=null,claimAnchoredSurface(()=>T.current());V.current&&(V.current=!1,P.current=!0,C(null),R(null))},[t]);const F=useCallback(e=>{if(e.disabled)return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),e.key!==BACK_KEY?e.submenu?C(e):(O.current=e.onPress??null,T.current()):C(null)},[p]),K=useMemo(()=>({width:j.width,height:j.height,insets:w}),[j.width,j.height,w]),$=useMemo(()=>{if(!s||!D)return null;const e=s.x+s.width/2>K.width/2?"end":"start";return computePlacement(s,D,K,r,{align:e})},[s,D,K,r]);let z=K.height-w.top-w.bottom-2*PLACEMENT_MARGIN;if(s&&$){const e=placementRoom(s,K);z="top"===$.placement?e.above:e.below}const G=Math.min(280,K.width-w.left-w.right-2*PLACEMENT_MARGIN),W=t&&null!==$,Y=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!W)return setNativeValue(Y,0),void setNativeValue(U,1);const e=[Animated.timing(Y,{toValue:1,duration:I,easing:Easing.bezier(...x.motion.ease.decelerate),useNativeDriver:!0})];c&&!A.reduced&&e.push(Animated.spring(U,{toValue:1.02,damping:x.motion.spring.snappy.damping,stiffness:x.motion.spring.snappy.stiffness,mass:x.motion.spring.snappy.mass,useNativeDriver:!0}));const t=Animated.parallel(e);return t.start(),()=>t.stop()},[W,c,A.reduced,Y,U,x.motion,I]);const X=useCallback(e=>{const{width:t,height:s}=e.nativeEvent.layout;R(e=>e&&e.width===t&&e.height===s?e:{width:t,height:s})},[]),Z=c&&"top"===$?.placement,q=M?.submenu?[M.submenu]:k,J=Z?[...q].reverse().map(e=>[...e].reverse()):q,Q=[];if(M)Q.push({key:BACK_KEY,label:M.label});else for(const e of S)Q.push({key:`${TOP_PREFIX}${e.key}`,label:e.label,item:e});for(const e of J)for(const t of e)Q.push({key:t.key,label:t.label,item:t});const ee=Q[0]?.key;useEffect(()=>{if(!W||E||!ee)return;const e=setTimeout(()=>focusHost(H.current.get(ee)),FOCUS_DELAY_MS);return()=>clearTimeout(e)},[W,E,ee]);const setItemRef=e=>t=>{t?H.current.set(e,t):H.current.delete(e)},te=webOnly({onKeyDown:e=>{const t=e.key??e.nativeEvent?.key??"",s=Q.length,o=Q.findIndex(e=>e.key===N.current);let i=-1;if("ArrowDown"===t)i=(o+1)%s;else if("ArrowUp"===t)i=o<=0?s-1:o-1;else if("Home"===t)i=0;else if("End"===t)i=s-1;else{if("ArrowLeft"===t&&M)return e.preventDefault?.(),void C(null);if("ArrowRight"===t&&Q[o]?.item?.submenu)return e.preventDefault?.(),void F(Q[o].item);if(1===t.length&&""!==t.trim()){const e=t.toLowerCase();for(let t=1;t<=s;t+=1){const n=(o+t)%s;if(Q[n].label.toLowerCase().startsWith(e)){i=n;break}}}}i>=0&&(e.preventDefault?.(),(e=>{const t=Q[e];t&&focusHost(H.current.get(t.key))})(i))}});if(E){const e=M?.submenu?[{key:BACK_KEY,label:b.back,icon:"chevron-left"},...M.submenu]:[...S,...k.flat()],s=[...new Set(e.filter(e=>e.checked).map(e=>e.key))];return _jsx(OptionSheet,{open:t,onClose:d,onAfterClose:B,title:M?.label??i,options:e,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,isOptionDisabled:e=>Boolean(e.disabled),destructiveOf:e=>Boolean(e.destructive),getOptionDescription:e=>e.description,getOptionIcon:e=>{const t=e;return renderSlotIcon(t.icon,{color:t.destructive?x.colors["danger-text"]:x.colors["text-muted"],size:20,disabled:Boolean(t.disabled)})},value:s,onChange:(e,t)=>F(t),accessibilityLabel:f??i,testID:h?`${h}-sheet`:void 0})}const inkFor=e=>e.disabled?x.colors["text-disabled"]:e.destructive?x.colors["danger-text"]:x.colors["text-body"],inkRoleFor=e=>e.disabled?"disabled":e.destructive?"danger":"primary",se=_jsxs(_Fragment,M?{children:[_jsx(ListItem,{ref:setItemRef(BACK_KEY),variant:"menu",onPress:()=>C(null),onFocus:()=>{N.current=BACK_KEY},accessibilityLabel:`${b.back}, ${M.label}`,leading:_jsx(View,{style:y.icon,children:_jsx(AppIcon,{name:"chevron-left",size:20,color:x.colors["text-muted"]})}),title:_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:1,children:M.label})}),_jsx(Divider,{spacing:"none"})]}:{children:[i?_jsx(Text,{variant:"caption",color:"secondary",accessibilityRole:"header",numberOfLines:2,style:y.title,children:i}):null,S.length>0?_jsxs(_Fragment,{children:[_jsx(View,{style:y.topRow,children:S.map(e=>{const t=`${TOP_PREFIX}${e.key}`,s=Boolean(e.disabled),o=inkFor(e);return _jsxs(Pressable,{ref:setItemRef(t),onPress:()=>F(e),onFocus:()=>{N.current=t},disabled:s,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityState:{disabled:s},"aria-disabled":s,testID:e.testID,style:({pressed:e})=>[y.topAction,e?y.pressed:null],children:[renderSlotIcon(e.icon,{color:o,size:20,disabled:s}),_jsx(Text,{variant:"caption",color:inkRoleFor(e),numberOfLines:1,children:e.label})]},t)})}),_jsx(Divider,{spacing:"none"})]}):null]});return _jsxs(Modal,{open:t,onClose:d,presentation:"fullScreen",bare:!0,backdropOpacity:c?void 0:0,haptic:!1,labels:{close:b.close},onInsetsChange:_,onDismissed:B,testID:h?`${h}-modal`:void 0,children:[c&&u&&s?_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[y.preview,{left:s.x,top:s.y,width:s.width,height:s.height,transform:[{scale:U}]}],children:u}):null,_jsx(Animated.View,{accessibilityRole:"menu",accessibilityLabel:M?.label??f??i,onLayout:X,testID:h?`${h}-menu`:void 0,...te,style:[y.anchored,{left:$?.x??0,top:$?.y??0,maxWidth:G,opacity:W?Y:0}],children:_jsx(View,{style:y.surface,children:_jsxs(View,{style:[y.clip,{maxHeight:z}],children:[se,_jsx(ScrollView,{style:y.scroll,bounces:!1,keyboardShouldPersistTaps:"handled",children:J.map((e,t)=>{const s=e.some(e=>null!=e.icon);return _jsxs(View,{children:[t>0?_jsx(Divider,{spacing:"none"}):null,e.map(e=>((e,t)=>{const s=Boolean(e.disabled),o=inkFor(e),i=e.detail||e.checked||e.submenu?_jsxs(Row,{gap:"md",children:[e.detail?_jsx(Text,{variant:"caption",color:"tertiary",children:e.detail}):null,e.checked?_jsx(AppIcon,{name:"check",size:20,color:x.colors.primary}):null,e.submenu?_jsx(AppIcon,{name:"chevron-right",size:20,color:x.colors["text-subtle"]}):null]}):void 0;return _jsx(ListItem,{ref:setItemRef(e.key),variant:"menu",onPress:()=>F(e),onFocus:()=>{N.current=e.key},disabled:s,checked:e.checked,accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,rightPlacement:"side",leading:t?_jsx(View,{style:y.icon,children:renderSlotIcon(e.icon,{color:o,size:20,disabled:s})}):void 0,title:_jsx(Text,{variant:"body",color:inkRoleFor(e),numberOfLines:2,children:e.label}),subtitle:e.description?_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:2,children:e.description}):void 0,trailing:i},e.key)})(e,s))]},e[0].key)})})]})})})]})};const buildStyles=e=>StyleSheet.create({preview:{position:"absolute"},anchored:{position:"absolute",minWidth:180},surface:{backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,...e.shadow.popover},clip:{borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},scroll:{flexGrow:0,flexShrink:1},title:{paddingHorizontal:e.space.md,paddingTop:e.space.sm,paddingBottom:e.space.xs},pressed:{backgroundColor:e.colors["surface-pressed"]},icon:{width:20,alignItems:"center"},topRow:{flexDirection:"row",padding:e.space.xs,gap:e.space.xs},topAction:{flexGrow:1,flexBasis:0,alignItems:"center",justifyContent:"center",gap:e.space.xs,minHeight:64,borderRadius:e.radius.sm,...smoothCorners}});
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:i,title:o,topActions:n,placement:r,presentation:l,unavailable:a,context:c=!1,preview:d,onClose:u,restoreFocusTo:m,haptic:p,accessibilityLabel:b,labels:h,testID:f}=e,x=useTheme(),y=useMemo(()=>buildStyles(x),[x]),g=useSafeAreaInsets(),[v,_]=useModalInsets(),w=useMemo(()=>({...g,top:v.top,bottom:v.bottom}),[g,v]),j=useWindowDimensions(),A=usePresenceMotion(),I=A.duration("fast"),k=useMemo(()=>visibleGroups(i,a),[i,a]),S=useMemo(()=>visibleTopActions(n,a),[n,a]),E="sheet"===l||"auto"===l&&j.width<Breakpoints.lg&&wantsSheet(k,S),[M,C]=useState(null),[D,R]=useState(null),T=useRef(u);T.current=u;const L=useRef(m);L.current=m;const O=useRef(null),P=useRef(!1),V=useRef(!1),H=useRef(new Map),F=useRef(null),N=useCallback(()=>{if(!P.current)return;P.current=!1;const e=O.current;O.current=null,e?e():focusHost(L.current?.())},[]);useEffect(()=>{if(t)return V.current=!0,P.current=!1,O.current=null,claimAnchoredSurface(()=>T.current());V.current&&(V.current=!1,P.current=!0,C(null),R(null))},[t]);const B=useCallback(e=>{if(e.disabled)return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),e.key!==BACK_KEY?e.submenu?C(e):(O.current=e.onPress??null,T.current()):C(null)},[p]),K=useMemo(()=>({width:j.width,height:j.height,insets:w}),[j.width,j.height,w]),$=useMemo(()=>{if(!s||!D)return null;const e=s.x+s.width/2>K.width/2?"end":"start";return computePlacement(s,D,K,r,{align:e})},[s,D,K,r]);let z=K.height-w.top-w.bottom-2*PLACEMENT_MARGIN;if(s&&$){const e=placementRoom(s,K);z="top"===$.placement?e.above:e.below}const G=Math.min(280,K.width-w.left-w.right-2*PLACEMENT_MARGIN),W=t&&null!==$,Y=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!W)return setNativeValue(Y,0),void setNativeValue(U,1);const e=[Animated.timing(Y,{toValue:1,duration:I,easing:Easing.bezier(...x.motion.ease.decelerate),useNativeDriver:!0})];c&&!A.reduced&&e.push(Animated.spring(U,{toValue:1.02,damping:x.motion.spring.snappy.damping,stiffness:x.motion.spring.snappy.stiffness,mass:x.motion.spring.snappy.mass,useNativeDriver:!0}));const t=Animated.parallel(e);return t.start(),()=>t.stop()},[W,c,A.reduced,Y,U,x.motion,I]);const X=useCallback(e=>{const{width:t,height:s}=e.nativeEvent.layout;R(e=>e&&e.width===t&&e.height===s?e:{width:t,height:s})},[]),Z=c&&"top"===$?.placement,q=M?.submenu?[M.submenu]:k,J=Z?[...q].reverse().map(e=>[...e].reverse()):q,Q=[];if(M)Q.push({key:BACK_KEY,label:M.label});else for(const e of S)Q.push({key:`${TOP_PREFIX}${e.key}`,label:e.label,item:e});for(const e of J)for(const t of e)Q.push({key:t.key,label:t.label,item:t});const ee=Q[0]?.key;useEffect(()=>{if(!W||E||!ee)return;const e=setTimeout(()=>focusHost(H.current.get(ee)),FOCUS_DELAY_MS);return()=>clearTimeout(e)},[W,E,ee]);const setItemRef=e=>t=>{t?H.current.set(e,t):H.current.delete(e)},te=webOnly({onKeyDown:e=>{const t=e.key??e.nativeEvent?.key??"",s=Q.length,i=Q.findIndex(e=>e.key===F.current);let o=-1;if("ArrowDown"===t)o=(i+1)%s;else if("ArrowUp"===t)o=i<=0?s-1:i-1;else if("Home"===t)o=0;else if("End"===t)o=s-1;else{if("ArrowLeft"===t&&M)return e.preventDefault?.(),void C(null);if("ArrowRight"===t&&Q[i]?.item?.submenu)return e.preventDefault?.(),void B(Q[i].item);if(1===t.length&&""!==t.trim()){const e=t.toLowerCase();for(let t=1;t<=s;t+=1){const n=(i+t)%s;if(Q[n].label.toLowerCase().startsWith(e)){o=n;break}}}}o>=0&&(e.preventDefault?.(),(e=>{const t=Q[e];t&&focusHost(H.current.get(t.key))})(o))}});if(E){const e=M?.submenu?[{key:BACK_KEY,label:h.back,icon:"chevron-left"},...M.submenu]:[...S,...k.flat()],s=[...new Set(e.filter(e=>e.checked).map(e=>e.key))];return _jsx(OptionSheet,{open:t,onClose:u,onAfterClose:N,title:M?.label??o,options:e,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,isOptionDisabled:e=>Boolean(e.disabled),destructiveOf:e=>Boolean(e.destructive),getOptionDescription:e=>e.description,getOptionIcon:e=>{const t=e;return renderSlotIcon(t.icon,{color:t.destructive?x.colors["danger-text"]:x.colors["text-muted"],size:20,disabled:Boolean(t.disabled)})},value:s,onChange:(e,t)=>B(t),accessibilityLabel:b??o,testID:f?`${f}-sheet`:void 0})}const inkFor=e=>e.disabled?x.colors["text-disabled"]:e.destructive?x.colors["danger-text"]:x.colors["text-body"],inkRoleFor=e=>e.disabled?"disabled":e.destructive?"danger":"primary",se=_jsxs(_Fragment,M?{children:[_jsx(ListItem,{ref:setItemRef(BACK_KEY),variant:"menu",onPress:()=>C(null),onFocus:()=>{F.current=BACK_KEY},accessibilityLabel:`${h.back}, ${M.label}`,leading:_jsx(View,{style:y.icon,children:_jsx(AppIcon,{name:"chevron-left",size:20,color:x.colors["text-muted"]})}),title:_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:1,children:M.label})}),_jsx(Divider,{spacing:"none"})]}:{children:[o?_jsx(Text,{variant:"caption",color:"secondary",accessibilityRole:"header",numberOfLines:2,style:y.title,children:o}):null,S.length>0?_jsxs(_Fragment,{children:[_jsx(View,{style:y.topRow,children:S.map(e=>{const t=`${TOP_PREFIX}${e.key}`,s=Boolean(e.disabled),i=inkFor(e);return _jsxs(Pressable,{ref:setItemRef(t),onPress:()=>B(e),onFocus:()=>{F.current=t},disabled:s,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityState:{disabled:s},"aria-disabled":s,testID:e.testID,style:({pressed:e})=>[y.topAction,e?y.pressed:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}),_jsx(Text,{variant:"caption",color:inkRoleFor(e),numberOfLines:1,children:e.label})]},t)})}),_jsx(Divider,{spacing:"none"})]}):null]});return _jsxs(Modal,{open:t,onClose:u,presentation:"fullScreen",bare:!0,backdropOpacity:c?void 0:0,haptic:!1,labels:{close:h.close},onInsetsChange:_,onDismissed:N,testID:f?`${f}-modal`:void 0,children:[c&&d&&s?_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[y.preview,{left:s.x,top:s.y,width:s.width,height:s.height,transform:[{scale:U}]}],children:d}):null,_jsx(Animated.View,{accessibilityRole:"menu",accessibilityLabel:M?.label??b??o,onLayout:X,testID:f?`${f}-menu`:void 0,...te,style:[y.anchored,{left:$?.x??0,top:$?.y??0,maxWidth:G,opacity:W?Y:0}],children:_jsx(View,{style:y.surface,children:_jsxs(View,{style:[y.clip,{maxHeight:z}],children:[se,_jsx(ScrollView,{style:y.scroll,bounces:!1,keyboardShouldPersistTaps:"handled",children:J.map((e,t)=>{const s=e.some(e=>null!=e.icon);return _jsxs(View,{children:[t>0?_jsx(Divider,{spacing:"none"}):null,e.map(e=>((e,t)=>{const s=Boolean(e.disabled),i=inkFor(e),o=e.detail||e.checked||e.submenu?_jsxs(Row,{gap:"md",children:[e.detail?_jsx(Text,{variant:"caption",color:"tertiary",children:e.detail}):null,e.checked?_jsx(AppIcon,{name:"check",size:20,color:x.colors.primary}):null,e.submenu?_jsx(AppIcon,{name:"chevron-right",size:20,color:x.colors["text-subtle"]}):null]}):void 0;return _jsx(ListItem,{ref:setItemRef(e.key),variant:"menu",onPress:()=>B(e),onFocus:()=>{F.current=e.key},disabled:s,checked:e.checked,accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,rightPlacement:"side",leading:t?_jsx(View,{style:y.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}):void 0,title:_jsx(Text,{variant:"body",color:inkRoleFor(e),numberOfLines:2,children:e.label}),subtitle:e.description?_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:2,children:e.description}):void 0,trailing:o},e.key)})(e,s))]},e[0].key)})})]})})})]})};const buildStyles=e=>StyleSheet.create({preview:{position:"absolute"},anchored:{position:"absolute",minWidth:180},surface:{backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,...e.shadow.popover},clip:{borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},scroll:{flexGrow:0,flexShrink:1},title:{paddingHorizontal:e.space.md,paddingTop:e.space.sm,paddingBottom:e.space.xs},pressed:{backgroundColor:e.colors["surface-pressed"]},icon:{width:20,alignItems:"center"},topRow:{flexDirection:"row",padding:e.space.xs,gap:e.space.xs},topAction:{flexGrow:1,flexBasis:0,alignItems:"center",justifyContent:"center",gap:e.space.xs,minHeight:64,borderRadius:e.radius.sm,...smoothCorners}});
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.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_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."});const DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,o)=>Math.min(o,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,o)=>{const t=toneFor(e,r),s=t.base,i=e.colors.bg,n="neutral"===r;let l;switch(o){case"soft":l={fill:n?e.colors["bg-muted"]:blendOf(s,.14,i,e.colors["bg-subtle"]),ring:i,icon:s};break;case"outline":l={fill:i,ring:n?e.colors.border:s,icon:s};break;default:l={fill:s,ring:i,icon:t.on}}return l},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__",ProfilePicker=forwardRef((e,r)=>{const{value:o,name:t,sources:s,onPick:i,onRemove:n,loading:l=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:f,avatarTone:h,avatarBackgroundColor:b,avatarColor:y,label:x,required:v=!1,helperText:k,error:C,layout:I="stacked",title:_,subtitle:j,ImageComponent:P,labels:S,haptic:T,onError:w,accessibilityLabel:E,style:F,testID:A}=e;warnInvalidValue("ProfilePicker","size",e.size,["sm","md","lg"]),warnInvalidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),warnInvalidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const L=useTheme(),R=L.settings.components["profile-picker"],V=g??R?.defaultTone??"primary",M=f??R?.defaultVariant??"solid",O=useMemo(()=>badgeLookFor(L,V,M),[L,V,M]),D=h??R?.defaultAvatarTone,z=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...S}),[S]),[H,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(o);o!==Z&&(G(o),B(null));const K=l||a,N=H??o??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==H||Boolean(o)&&Boolean(n)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),oe=re*(1-Math.SQRT1_2),te=clamp(Math.round(.28*ee),24,44),se=oe-te/2,ie=Math.max(0,-se),ne=useCallback(e=>{$(e),w?.(e),!1!==T&&triggerHaptic("notificationError")},[w,T]),le=useCallback(async e=>{let r;try{r=await e.pick()}catch(e){return void ne(e instanceof Error?e.message:String(e))}const o=r?.[0];if(!o)return;if("number"==typeof d&&"number"==typeof o.size&&o.size>1024*d*1024)return void ne(z.errorTooLarge(d));if(o.type&&!matchesAccept(o.type,c))return void ne(z.errorWrongType);$(null),B(o.uri);const t=resolveHaptic(T,"selection");t&&triggerHaptic(t),i?.(o)},[d,c,z,T,i,ne]),ae=useCallback(()=>{K||(ue.current=null,1!==s.length||Y?(s.length>0||Y)&&W(!0):le(s[0]))},[K,s,Y,le]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),n?.()},[T,n]),de=useMemo(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(le);pe.current=le;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),fe=A??"profile-picker",he=E??(J?z.pick:t),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:ie,marginRight:ie},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:he,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:l}:{busy:l},"aria-disabled":J?K:void 0,"aria-busy":l,testID:`${fe}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{dimension:ee,shape:m,name:t||void 0,source:X,ImageComponent:P,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),l?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:L.colors.scrim}],testID:`${fe}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:L.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${fe}-badge`,style:[styles.badge,{width:te,height:te,borderRadius:L.radius.pill,...smoothCorners,right:se,bottom:se,backgroundColor:O.fill,borderColor:O.ring}],children:renderSlotIcon(p,{color:O.icon,size:Math.round(.55*te),disabled:!1})}):null]})}),ye="stacked"!==I?_jsxs(View,{style:[styles.meta,"profile"===I?styles.metaCentred:null],children:[_?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===I?styles.textCentred:null],children:_}):null,j?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===I?styles.textCentred:null,{marginTop:L.space.xxs}],children:j}):null,_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:F,testID:A,children:[x?_jsx(FieldLabel,{required:v,children:x}):null,_jsxs(View,{style:"inline"===I?[styles.row,{columnGap:L.space.md}]:["profile"===I?styles.columnCentred:styles.column,{rowGap:L.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:T,onClose:()=>W(!1),onAfterClose:ge,title:z.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?z.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?_jsx(AppIcon,{name:"trash",size:20,color:L.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})});ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});export{ProfilePicker};export default ProfilePicker;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.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_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."});const DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,o)=>Math.min(o,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,o)=>{const t=toneFor(e,r),i=t.base,s=e.colors.bg,n="neutral"===r;let l;switch(o){case"soft":l={fill:n?e.colors["bg-muted"]:blendOf(i,.14,s,e.colors["bg-subtle"]),ring:s,icon:i};break;case"outline":l={fill:s,ring:n?e.colors.border:i,icon:i};break;default:l={fill:i,ring:s,icon:t.on}}return l},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__",ProfilePicker=forwardRef((e,r)=>{const{value:o,name:t,sources:i,onPick:s,onRemove:n,loading:l=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:h,avatarTone:f,avatarBackgroundColor:b,avatarColor:y,label:x,required:v=!1,helperText:k,error:C,layout:I="stacked",title:_,subtitle:j,ImageComponent:P,labels:S,haptic:T,onError:w,accessibilityLabel:E,style:F,testID:A}=e;warnInvalidValue("ProfilePicker","size",e.size,["sm","md","lg"]),warnInvalidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),warnInvalidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const L=useTheme(),R=L.settings.components["profile-picker"],V=g??R?.defaultTone??"primary",M=h??R?.defaultVariant??"solid",O=useMemo(()=>badgeLookFor(L,V,M),[L,V,M]),D=f??R?.defaultAvatarTone,H=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...S}),[S]),[z,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(o);o!==Z&&(G(o),B(null));const K=l||a,N=z??o??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==z||Boolean(o)&&Boolean(n)),J=i.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),oe=re*(1-Math.SQRT1_2),te=clamp(Math.round(.28*ee),24,44),ie=oe-te/2,se=Math.max(0,-ie),ne=useCallback(e=>{$(e),w?.(e),!1!==T&&triggerHaptic("notificationError")},[w,T]),le=useCallback(async e=>{let r;try{r=await e.pick()}catch(e){return void ne(e instanceof Error?e.message:String(e))}const o=r?.[0];if(!o)return;if("number"==typeof d&&"number"==typeof o.size&&o.size>1024*d*1024)return void ne(H.errorTooLarge(d));if(o.type&&!matchesAccept(o.type,c))return void ne(H.errorWrongType);$(null),B(o.uri);const t=resolveHaptic(T,"selection");t&&triggerHaptic(t),s?.(o)},[d,c,H,T,s,ne]),ae=useCallback(()=>{K||(ue.current=null,1!==i.length||Y?(i.length>0||Y)&&W(!0):le(i[0]))},[K,i,Y,le]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),n?.()},[T,n]),de=useMemo(()=>{const e=i.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[i,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(le);pe.current=le;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),he=A??"profile-picker",fe=E??(J?H.pick:t),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:se,marginRight:se},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:fe,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:l}:{busy:l},"aria-disabled":J?K:void 0,"aria-busy":l,testID:`${he}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{dimension:ee,shape:m,name:t||void 0,source:X,ImageComponent:P,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),l?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:L.colors.scrim}],testID:`${he}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:L.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${he}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:te,height:te,borderRadius:L.radius.pill,...smoothCorners,right:ie,bottom:ie,backgroundColor:O.fill,borderColor:O.ring}],children:renderSlotIcon(p,{color:O.icon,size:Math.round(.55*te),disabled:!1})}):null]})}),ye="stacked"!==I?_jsxs(View,{style:[styles.meta,"profile"===I?styles.metaCentred:null],children:[_?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===I?styles.textCentred:null],children:_}):null,j?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===I?styles.textCentred:null,{marginTop:L.space.xxs}],children:j}):null,_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:F,testID:A,children:[x?_jsx(FieldLabel,{required:v,children:x}):null,_jsxs(View,{style:"inline"===I?[styles.row,{columnGap:L.space.md}]:["profile"===I?styles.columnCentred:styles.column,{rowGap:L.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:T,onClose:()=>W(!1),onAfterClose:ge,title:H.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?H.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?_jsx(AppIcon,{name:"trash",size:20,color:L.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})});ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});export{ProfilePicker};export default ProfilePicker;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldBase,FieldLabel,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{normalizeSuggestion,SearchRecents,SearchScopeBar,SearchSuggestions}from"./SearchPanel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SEARCH_BAR_LABELS=Object.freeze({placeholder:"Search…",recents:"Recent searches",clearAll:"Clear all",clearAllRecents:"Clear all recent searches",searchAgain:"Searches again",removeRecent:e=>`Remove ${e} from recent searches`,scope:"Search scope",clearSearch:"Clear search",searching:e=>`Searching ${e}`,suggestionCount:e=>1===e?"1 suggestion":`${e} suggestions`,removed:e=>`Removed ${e}`,recentsCleared:"Recent searches cleared"});const DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=forwardRef((e,l)=>{const{value:s,onChangeText:a,onSubmit:o,onFocus:t,onBlur:r,placeholder:n,autoFocus:i=!1,disabled:c=!1,onClear:u,leftIcon:d,debounceMs:p,size:h="md",variant:b,radius:m,label:f,labelMode:S="top",labelStyle:g,scopes:v,scope:C,onScopeChange:x,recents:R,maxRecents:j=DEFAULT_PANEL_ROWS,onSelectRecent:y,onRemove:F,onClearRecents:_,suggestions:L,maxSuggestions:k=DEFAULT_PANEL_ROWS,onSelect:B,haptic:E,labels:A,style:I,inputStyle:T,accessibilityLabel:w,testID:z,...V}=e;warnInvalidValue("SearchBar","size",e.size,["sm","md","lg"]),warnInvalidValue("SearchBar","variant",e.variant,["outline","filled","underline"]),warnInvalidValue("SearchBar","labelMode",e.labelMode,["top","float"]);const H=useTheme(),M=useMemo(()=>({...DEFAULT_SEARCH_BAR_LABELS,...A}),[A]),D=n??M.placeholder,P=b??H.settings.components["search-bar"]?.defaultVariant??H.settings.components.field?.defaultVariant??"filled",O="underline"===P,N=resolveFieldSize(H,h),U=m??H.components["search-bar"][h].radius,W=resolveFieldTextStyle(H,{disabled:c}),$=useRef(null),q=useMemo(()=>mergeRefs($,l),[l]),K=useCallback(()=>{c||$.current?.focus()},[c]),G=useMemo(()=>buildStyles(H),[H]),J="string"==typeof s?s:"",[Q,X]=useState(!1),Y=useCallback(e=>{X(!0),t?.(e)},[t]),Z=useCallback(e=>{X(!1),r?.(e)},[r]),[ee,le]=useState(J),se=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==ee&&le(J)},[J,p]);const ae=useRef(J);useEffect(()=>{void 0!==p&&se!==ae.current&&(ae.current=se,a(se))},[se,p,a]);const oe=useCallback(e=>{void 0===p?a(e):le(e)},[p,a]),te=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(le(""),ae.current=""),a(""),u?.()},[E,p,a,u]),re=useCallback(()=>{o?.(void 0!==p?ee:J)},[o,p,ee,J]),ne=void 0!==p?ee:J,ie=ne.length>0,[ce,ue]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),de=useCallback(e=>{ue(e);const l=v?.find(l=>l.value===e)?.label;l&&announce(M.searching(l))},[v,ue,M]),[pe,he]=useState(!1),be=useRef(null),me=useCallback(()=>{be.current&&(clearTimeout(be.current),be.current=null)},[]),fe=useCallback(()=>{me(),he(!0)},[me]),Se=useCallback(()=>{me(),be.current=setTimeout(()=>he(!1),50)},[me]);useEffect(()=>me,[me]);const ge=!c&&(Q||pe),ve=useMemo(()=>(R??[]).slice(0,j),[R,j]),Ce=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),xe=ge&&!ie&&ve.length>0,Re=ge&&ie&&Ce.length>0,je=Re?Ce.length:0,ye=je>0?M.suggestionCount(je):"";useEffect(()=>{ye&&announce(ye)},[ye]);const Fe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),Le=useCallback(e=>{Fe(),$.current?.blur(),he(!1),y?.(e)},[Fe,y]),ke=useCallback(e=>{Fe(),$.current?.blur(),he(!1),B?.(e)},[Fe,B]),Be=useCallback(e=>{Fe(),F?.(e),announce(M.removed(e)),K()},[Fe,F,K,M]),Ee=useCallback(()=>{Fe(),_?.(),announce(M.recentsCleared),K()},[Fe,_,K,M]),Ae={size:N.icon,color:c?H.colors["text-disabled"]:H.colors["text-subtle"],disabled:c},Ie=d?renderSlotIcon(d,Ae):(H.settings.icons.search??defaultIcons.search)(Ae),Te=Boolean(f)&&"float"===S,we=useFloatingLabel({label:f,enabled:Te,floated:Q||ie,variant:P,sizeTokens:N,leadingOffset:N.icon+H.space.md,trailingOffset:ie?N.icon+H.space.md:0,paddingLeft:O?H.space.none:N["padding-x"],color:H.colors["field-label"],style:g}),ze=ie&&!c?_jsx(Pressable,{onPress:te,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:M.clearSearch,children:(H.settings.icons.close??defaultIcons.close)({size:N.icon,color:H.colors["text-muted"]})}):null;return _jsxs(View,{style:I,testID:z,children:[f&&!Te?_jsx(FieldLabel,{size:h,style:g,children:f}):null,_jsx(View,{style:G.root,children:_jsxs(View,{style:G.fieldWrap,children:[_jsx(FieldBase,{size:h,variant:P,focused:Q,disabled:c,filled:ie,minHeight:N["min-height"],paddingHorizontal:O?H.space.none:N["padding-x"],radius:U,leading:Ie,trailing:ze,topNotch:we.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:w??D,children:_jsx(TextInput,{ref:q,style:[G.input,{fontSize:N.text,color:W.color,...W.weightStyle},T],value:ne,onChangeText:oe,onSubmitEditing:re,onFocus:Y,onBlur:Z,placeholder:!Te||Q||ie?D:void 0,placeholderTextColor:W.placeholderColor,autoFocus:i,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(H,P).borderFocusedRepresentative,accessibilityLabel:w??D,accessibilityState:{disabled:c},"aria-disabled":c,...V})}),we.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ce||(v[0]?.value??""),disabled:c,haptic:E,labels:M,onChange:de}):null,xe?_jsx(SearchRecents,{recents:ve,labels:M,onSelect:Le,onRemove:F?Be:void 0,onClear:_?Ee:void 0,onHold:fe,onRelease:Se}):null,Re?_jsx(SearchSuggestions,{suggestions:Ce,query:ne,onSelect:ke,onHold:fe,onRelease:Se}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>StyleSheet.create({root:{flexDirection:"row",alignItems:"center",width:"100%",position:"relative",overflow:"visible"},fieldWrap:{flex:1,position:"relative",overflow:"visible"},input:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});export{SearchBar};export default SearchBar;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldBase,FieldLabel,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{normalizeSuggestion,SearchRecents,SearchScopeBar,SearchSuggestions}from"./SearchPanel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SEARCH_BAR_LABELS=Object.freeze({placeholder:"Search…",recents:"Recent searches",clearAll:"Clear all",clearAllRecents:"Clear all recent searches",searchAgain:"Searches again",removeRecent:e=>`Remove ${e} from recent searches`,scope:"Search scope",clearSearch:"Clear search",searching:e=>`Searching ${e}`,suggestionCount:e=>1===e?"1 suggestion":`${e} suggestions`,removed:e=>`Removed ${e}`,recentsCleared:"Recent searches cleared"});const DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=forwardRef((e,l)=>{const{value:s,onChangeText:a,onSubmit:o,onFocus:t,onBlur:r,placeholder:n,autoFocus:i=!1,disabled:c=!1,onClear:u,leftIcon:d,debounceMs:p,size:h="md",variant:b,radius:m,label:f,labelMode:S="top",labelStyle:g,scopes:v,scope:C,onScopeChange:x,recents:R,maxRecents:j=DEFAULT_PANEL_ROWS,onSelectRecent:y,onRemove:F,onClearRecents:_,suggestions:L,maxSuggestions:k=DEFAULT_PANEL_ROWS,onSelect:B,haptic:E,labels:A,style:I,inputStyle:T,accessibilityLabel:w,testID:z,...V}=e;warnInvalidValue("SearchBar","size",e.size,["sm","md","lg"]),warnInvalidValue("SearchBar","variant",e.variant,["outline","filled","underline"]),warnInvalidValue("SearchBar","labelMode",e.labelMode,["top","float"]);const H=useTheme(),M=useMemo(()=>({...DEFAULT_SEARCH_BAR_LABELS,...A}),[A]),D=n??M.placeholder,P=b??H.settings.components["search-bar"]?.defaultVariant??H.settings.components.field?.defaultVariant??"filled",O="underline"===P,N=resolveFieldSize(H,h),U=m??H.components["search-bar"][h].radius,W=resolveFieldTextStyle(H,{disabled:c}),$=useRef(null),q=useMemo(()=>mergeRefs($,l),[l]),K=useCallback(()=>{c||$.current?.focus()},[c]),G=useMemo(()=>buildStyles(H),[H]),J="string"==typeof s?s:"",[Q,X]=useState(!1),Y=useCallback(e=>{X(!0),t?.(e)},[t]),Z=useCallback(e=>{X(!1),r?.(e)},[r]),[ee,le]=useState(J),se=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==ee&&le(J)},[J,p]);const ae=useRef(J);useEffect(()=>{void 0!==p&&se!==ae.current&&(ae.current=se,a(se))},[se,p,a]);const oe=useCallback(e=>{void 0===p?a(e):le(e)},[p,a]),te=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(le(""),ae.current=""),a(""),u?.()},[E,p,a,u]),re=useCallback(()=>{o?.(void 0!==p?ee:J)},[o,p,ee,J]),ne=void 0!==p?ee:J,ie=ne.length>0,[ce,ue]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),de=useCallback(e=>{ue(e);const l=v?.find(l=>l.value===e)?.label;l&&announce(M.searching(l))},[v,ue,M]),[pe,he]=useState(!1),be=useRef(null),me=useCallback(()=>{be.current&&(clearTimeout(be.current),be.current=null)},[]),fe=useCallback(()=>{me(),he(!0)},[me]),Se=useCallback(()=>{me(),be.current=setTimeout(()=>he(!1),50)},[me]);useEffect(()=>me,[me]);const ge=!c&&(Q||pe),ve=useMemo(()=>(R??[]).slice(0,j),[R,j]),Ce=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),xe=ge&&!ie&&ve.length>0,Re=ge&&ie&&Ce.length>0,je=Re?Ce.length:0,ye=je>0?M.suggestionCount(je):"";useEffect(()=>{ye&&announce(ye)},[ye]);const Fe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),Le=useCallback(e=>{Fe(),$.current?.blur(),he(!1),y?.(e)},[Fe,y]),ke=useCallback(e=>{Fe(),$.current?.blur(),he(!1),B?.(e)},[Fe,B]),Be=useCallback(e=>{Fe(),F?.(e),announce(M.removed(e)),K()},[Fe,F,K,M]),Ee=useCallback(()=>{Fe(),_?.(),announce(M.recentsCleared),K()},[Fe,_,K,M]),Ae={size:N.icon,color:c?H.colors["text-disabled"]:H.colors["text-subtle"],disabled:c},Ie=d?renderSlotIcon(d,Ae):(H.settings.icons.search??defaultIcons.search)(Ae),Te=_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Ie}),we=Boolean(f)&&"float"===S,ze=useFloatingLabel({label:f,enabled:we,floated:Q||ie,variant:P,sizeTokens:N,leadingOffset:N.icon+H.space.md,trailingOffset:ie?N.icon+H.space.md:0,paddingLeft:O?H.space.none:N["padding-x"],color:H.colors["field-label"],style:g}),Ve=ie&&!c?_jsx(Pressable,{onPress:te,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:M.clearSearch,children:(H.settings.icons.close??defaultIcons.close)({size:N.icon,color:H.colors["text-muted"]})}):null;return _jsxs(View,{style:I,testID:z,children:[f&&!we?_jsx(FieldLabel,{size:h,style:g,children:f}):null,_jsx(View,{style:G.root,children:_jsxs(View,{style:G.fieldWrap,children:[_jsx(FieldBase,{size:h,variant:P,focused:Q,disabled:c,filled:ie,minHeight:N["min-height"],paddingHorizontal:O?H.space.none:N["padding-x"],radius:U,leading:Te,trailing:Ve,topNotch:ze.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:w??D,children:_jsx(TextInput,{ref:q,style:[G.input,{fontSize:N.text,color:W.color,...W.weightStyle},T],value:ne,onChangeText:oe,onSubmitEditing:re,onFocus:Y,onBlur:Z,placeholder:!we||Q||ie?D:void 0,placeholderTextColor:W.placeholderColor,autoFocus:i,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(H,P).borderFocusedRepresentative,accessibilityLabel:w??D,accessibilityState:{disabled:c},"aria-disabled":c,...V})}),ze.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ce||(v[0]?.value??""),disabled:c,haptic:E,labels:M,onChange:de}):null,xe?_jsx(SearchRecents,{recents:ve,labels:M,onSelect:Le,onRemove:F?Be:void 0,onClear:_?Ee:void 0,onHold:fe,onRelease:Se}):null,Re?_jsx(SearchSuggestions,{suggestions:Ce,query:ne,onSelect:ke,onHold:fe,onRelease:Se}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>StyleSheet.create({root:{flexDirection:"row",alignItems:"center",width:"100%",position:"relative",overflow:"visible"},fieldWrap:{flex:1,position:"relative",overflow:"visible"},input:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});export{SearchBar};export default SearchBar;
@@ -1 +1 @@
1
- "use strict";import{memo,useMemo}from"react";import{Pressable,ScrollView,StyleSheet,View}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Chip}from"../Chip/index.js";import{Text}from"../Text/index.js";import{splitHighlight}from"./highlight.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TOUCH=44,ICON=18;export const normalizeSuggestion=e=>"string"==typeof e?{text:e}:e;export const SearchScopeBar=({scopes:e,scope:s,disabled:t,haptic:o,labels:l,onChange:i})=>{const r=useTheme(),n=useMemo(()=>buildStyles(r),[r]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,keyboardShouldPersistTaps:"handled",contentContainerStyle:n.scopes,accessibilityLabel:l.scope,children:e.map(e=>_jsx(Chip,{label:e.label,selected:e.value===s,disabled:t,haptic:o,onPress:()=>i(e.value),containerStyle:n.scopeChip},e.value))})};export const SearchRecents=({recents:e,labels:s,onSelect:t,onRemove:o,onClear:l,onHold:i,onRelease:r})=>{const n=useTheme(),c=useMemo(()=>buildStyles(n),[n]);return _jsxs(View,{style:c.list,children:[_jsxs(View,{style:c.header,children:[_jsx(Text,{variant:"label",accessibilityRole:"header",style:c.headerTitle,children:s.recents}),l?_jsx(Pressable,{onPress:l,onPressIn:i,onPressOut:r,accessibilityRole:"button",accessibilityLabel:s.clearAllRecents,style:c.clearAll,children:_jsx(Text,{variant:"label",color:"link",children:s.clearAll})}):null]}),e.map(e=>_jsxs(View,{style:c.row,children:[_jsxs(Pressable,{onPress:()=>t(e),onPressIn:i,onPressOut:r,accessibilityRole:"button",accessibilityLabel:e,accessibilityHint:s.searchAgain,android_ripple:{color:n.colors["surface-pressed"]},style:({pressed:e})=>[c.rowMain,e?{backgroundColor:n.colors["surface-pressed"]}:null],children:[_jsx(AppIcon,{name:"history",size:18,color:n.colors["text-subtle"]}),_jsx(Text,{variant:"body",numberOfLines:1,style:c.rowText,children:e})]}),o?_jsx(Pressable,{onPress:()=>o(e),onPressIn:i,onPressOut:r,accessibilityRole:"button",accessibilityLabel:s.removeRecent(e),style:c.remove,children:_jsx(AppIcon,{name:"x",size:18,color:n.colors["text-muted"]})}):null]},e))]})};const SuggestionRow=memo(({item:e,query:s,onSelect:t,onHold:o,onRelease:l,theme:i,styles:r})=>{const n=splitHighlight(e.text,s),c=e.icon?renderSlotIcon(e.icon,{size:18,color:i.colors["text-subtle"],disabled:!1}):_jsx(AppIcon,{name:"search",size:18,color:i.colors["text-subtle"]});return _jsxs(Pressable,{onPress:()=>t(e),onPressIn:o,onPressOut:l,accessibilityRole:"button",accessibilityLabel:e.subtitle?`${e.text}, ${e.subtitle}`:e.text,android_ripple:{color:i.colors["surface-pressed"]},style:({pressed:e})=>[r.rowMain,r.suggestion,e?{backgroundColor:i.colors["surface-pressed"]}:null],children:[c,_jsxs(View,{style:r.rowText,children:[_jsx(Text,{variant:"body",color:"secondary",numberOfLines:1,children:n.map(e=>_jsx(Text,{variant:"body",color:"secondary",style:e.match?r.match:void 0,children:e.text},e.start))}),e.subtitle?_jsx(Text,{variant:"caption",numberOfLines:1,children:e.subtitle}):null]})]})});SuggestionRow.displayName="SuggestionRow";export const SearchSuggestions=({suggestions:e,query:s,onSelect:t,onHold:o,onRelease:l})=>{const i=useTheme(),r=useMemo(()=>buildStyles(i),[i]);return _jsx(View,{style:r.list,children:e.map(e=>_jsx(SuggestionRow,{item:e,query:s,onSelect:t,onHold:o,onRelease:l,theme:i,styles:r},e.id??e.text))})};const buildStyles=e=>({...StyleSheet.create({scopes:{flexDirection:"row",alignItems:"center",gap:e.space.sm,paddingTop:e.space.sm},scopeChip:{minHeight:44},list:{width:"100%",paddingTop:e.space.xs},header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",minHeight:44,paddingHorizontal:e.space.xs},headerTitle:{flex:1},clearAll:{minHeight:44,minWidth:44,justifyContent:"center",alignItems:"flex-end"},row:{flexDirection:"row",alignItems:"center"},rowMain:{flex:1,flexDirection:"row",alignItems:"center",gap:e.space.md,minHeight:44,paddingHorizontal:e.space.xs},suggestion:{paddingVertical:e.space.xs},rowText:{flex:1},remove:{width:44,height:44,alignItems:"center",justifyContent:"center"}}),match:{...fontFor(e,"bold"),color:e.colors["text-body"]}});
1
+ "use strict";import{memo,useMemo}from"react";import{Pressable,ScrollView,StyleSheet,View}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Chip}from"../Chip/index.js";import{Text}from"../Text/index.js";import{splitHighlight}from"./highlight.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TOUCH=44,ICON=18;export const normalizeSuggestion=e=>"string"==typeof e?{text:e}:e;export const SearchScopeBar=({scopes:e,scope:s,disabled:t,haptic:i,labels:o,onChange:n})=>{const l=useTheme(),r=useMemo(()=>buildStyles(l),[l]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,keyboardShouldPersistTaps:"handled",contentContainerStyle:r.scopes,accessibilityLabel:o.scope,children:e.map(e=>_jsx(Chip,{label:e.label,selected:e.value===s,disabled:t,haptic:i,onPress:()=>n(e.value),containerStyle:r.scopeChip},e.value))})};export const SearchRecents=({recents:e,labels:s,onSelect:t,onRemove:i,onClear:o,onHold:n,onRelease:l})=>{const r=useTheme(),c=useMemo(()=>buildStyles(r),[r]);return _jsxs(View,{style:c.list,children:[_jsxs(View,{style:c.header,children:[_jsx(Text,{variant:"label",accessibilityRole:"header",style:c.headerTitle,children:s.recents}),o?_jsx(Pressable,{onPress:o,onPressIn:n,onPressOut:l,accessibilityRole:"button",accessibilityLabel:s.clearAllRecents,style:c.clearAll,children:_jsx(Text,{variant:"label",color:"link",children:s.clearAll})}):null]}),e.map(e=>_jsxs(View,{style:c.row,children:[_jsxs(Pressable,{onPress:()=>t(e),onPressIn:n,onPressOut:l,accessibilityRole:"button",accessibilityLabel:e,accessibilityHint:s.searchAgain,android_ripple:{color:r.colors["surface-pressed"]},style:({pressed:e})=>[c.rowMain,e?{backgroundColor:r.colors["surface-pressed"]}:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:"history",size:18,color:r.colors["text-subtle"]})}),_jsx(Text,{variant:"body",numberOfLines:1,style:c.rowText,children:e})]}),i?_jsx(Pressable,{onPress:()=>i(e),onPressIn:n,onPressOut:l,accessibilityRole:"button",accessibilityLabel:s.removeRecent(e),style:c.remove,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:"x",size:18,color:r.colors["text-muted"]})})}):null]},e))]})};const SuggestionRow=memo(({item:e,query:s,onSelect:t,onHold:i,onRelease:o,theme:n,styles:l})=>{const r=splitHighlight(e.text,s),c=e.icon?renderSlotIcon(e.icon,{size:18,color:n.colors["text-subtle"],disabled:!1}):_jsx(AppIcon,{name:"search",size:18,color:n.colors["text-subtle"]});return _jsxs(Pressable,{onPress:()=>t(e),onPressIn:i,onPressOut:o,accessibilityRole:"button",accessibilityLabel:e.subtitle?`${e.text}, ${e.subtitle}`:e.text,android_ripple:{color:n.colors["surface-pressed"]},style:({pressed:e})=>[l.rowMain,l.suggestion,e?{backgroundColor:n.colors["surface-pressed"]}:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:c}),_jsxs(View,{style:l.rowText,children:[_jsx(Text,{variant:"body",color:"secondary",numberOfLines:1,children:r.map(e=>_jsx(Text,{variant:"body",color:"secondary",style:e.match?l.match:void 0,children:e.text},e.start))}),e.subtitle?_jsx(Text,{variant:"caption",numberOfLines:1,children:e.subtitle}):null]})]})});SuggestionRow.displayName="SuggestionRow";export const SearchSuggestions=({suggestions:e,query:s,onSelect:t,onHold:i,onRelease:o})=>{const n=useTheme(),l=useMemo(()=>buildStyles(n),[n]);return _jsx(View,{style:l.list,children:e.map(e=>_jsx(SuggestionRow,{item:e,query:s,onSelect:t,onHold:i,onRelease:o,theme:n,styles:l},e.id??e.text))})};const buildStyles=e=>({...StyleSheet.create({scopes:{flexDirection:"row",alignItems:"center",gap:e.space.sm,paddingTop:e.space.sm},scopeChip:{minHeight:44},list:{width:"100%",paddingTop:e.space.xs},header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",minHeight:44,paddingHorizontal:e.space.xs},headerTitle:{flex:1},clearAll:{minHeight:44,minWidth:44,justifyContent:"center",alignItems:"flex-end"},row:{flexDirection:"row",alignItems:"center"},rowMain:{flex:1,flexDirection:"row",alignItems:"center",gap:e.space.md,minHeight:44,paddingHorizontal:e.space.xs},suggestion:{paddingVertical:e.space.xs},rowText:{flex:1},remove:{width:44,height:44,alignItems:"center",justifyContent:"center"}}),match:{...fontFor(e,"bold"),color:e.colors["text-body"]}});
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:r,label:i,helperText:s,error:l,value:n,defaultValue:o,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:b,style:x,containerStyle:S,segmentStyle:y,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;warnInvalidValue("SegmentedControl","size",e.size,["sm","md","lg"]),warnInvalidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[I,V]=useControllableState({value:n,defaultValue:o??r[0]?.value,onChange:a}),k=useTheme(),F=k.components["segmented-control"],L=useMemo(()=>buildStyles(k),[k]),_=useMemo(()=>resolveSegmentedControlSize(k,d),[k,d]),z=p>=2?2:1,M=z>1,R="segmented"===h,T="underline"===h,A="pills"===h,E=R?k.space[F["track-padding"]]:0,H=Math.ceil(1.25*_.text)*(z-1),q=F["underline-height"],D=k.space[F["pill-inset"]],B="number"==typeof g?g:g?k.radius[g]:void 0,W=B??k.radius.md,P=void 0===B?k.radius.sm:Math.max(B-E,0),N=B??k.radius.pill,G=B??k.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,r.findIndex(e=>e.value===I)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=k.motion.spring.snappy,r=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!0});return r.start(),r},[k.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===r.length||0===e.length?e:[])},[r.length]);const Z=useRef(null);useEffect(()=>{if(void 0===U)return;const e=null!==Z.current&&Z.current!==K;if(Z.current=K,!e)return void J.setValue(U);const t=Y(U);return()=>t.stop()},[K,U,Y,J]);const $=useCallback((e,t)=>{const{x:r,width:i}=t.nativeEvent.layout;X(t=>{const s=t[e];if(s&&s.x===r&&s.width===i)return t;const l=t.slice();return l[e]={x:r,width:i},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===I)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),V(e.value)},[u,V,I,f]),te=R?k.colors.thumb:A?k.colors["primary-soft"]:k.colors.primary,re=R?P:A?N:G,ie=activeInkFor(k,m),se=k.colors["bg-muted"],le=useSquircle(R,W),ne=!0===l||hasFieldText(l),oe=ne&&!u,ae=k.colors["field-border-error"],de=k.size.border,ce=hasFieldText(i),ue=ne?l:s,me=hasFieldText(ue),he=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof i?i:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+H}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},R?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":se,padding:E}:T?{borderBottomColor:oe?ae:k.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,S,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:se,stroke:oe?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,R?M?{top:0,bottom:0}:{top:0,height:_.height-2*E}:A?{top:D,bottom:D,left:D}:{bottom:0,height:q},{width:A?Math.max(Q.width-2*D,0):Q.width,borderRadius:re,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},v]}):null,r.map((e,t)=>{const r=e.value===I,i=r?ie:k.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:i,size:_.icon,selected:r,disabled:u});return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:r,selected:r,disabled:u},"aria-checked":r,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!r?.7:1},y],children:[s?_jsx(View,{style:L.segmentIcon,children:s}):null,_jsx(Text,{variant:"label",weight:r?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:i,fontSize:_.text},w,C],numberOfLines:z,children:e.label})]},String(e.value))})]}),!oe||T||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:R?W:N,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:i}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:ne}):null]}):he});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:r,label:i,helperText:s,error:l,value:n,defaultValue:o,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:b,style:x,containerStyle:y,segmentStyle:S,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;warnInvalidValue("SegmentedControl","size",e.size,["sm","md","lg"]),warnInvalidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[I,V]=useControllableState({value:n,defaultValue:o??r[0]?.value,onChange:a}),k=useTheme(),F=k.components["segmented-control"],L=useMemo(()=>buildStyles(k),[k]),_=useMemo(()=>resolveSegmentedControlSize(k,d),[k,d]),z=p>=2?2:1,M=z>1,R="segmented"===h,T="underline"===h,A="pills"===h,E=R?k.space[F["track-padding"]]:0,H=Math.ceil(1.25*_.text)*(z-1),q=F["underline-height"],D=k.space[F["pill-inset"]],B="number"==typeof g?g:g?k.radius[g]:void 0,W=B??k.radius.md,P=void 0===B?k.radius.sm:Math.max(B-E,0),N=B??k.radius.pill,G=B??k.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,r.findIndex(e=>e.value===I)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=k.motion.spring.snappy,r=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!0});return r.start(),r},[k.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===r.length||0===e.length?e:[])},[r.length]);const Z=useRef(null);useEffect(()=>{if(void 0===U)return;const e=null!==Z.current&&Z.current!==K;if(Z.current=K,!e)return void J.setValue(U);const t=Y(U);return()=>t.stop()},[K,U,Y,J]);const $=useCallback((e,t)=>{const{x:r,width:i}=t.nativeEvent.layout;X(t=>{const s=t[e];if(s&&s.x===r&&s.width===i)return t;const l=t.slice();return l[e]={x:r,width:i},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===I)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),V(e.value)},[u,V,I,f]),te=R?k.colors.thumb:A?k.colors["primary-soft"]:k.colors.primary,re=R?P:A?N:G,ie=activeInkFor(k,m),se=k.colors["bg-muted"],le=useSquircle(R,W),ne=!0===l||hasFieldText(l),oe=ne&&!u,ae=k.colors["field-border-error"],de=k.size.border,ce=hasFieldText(i),ue=ne?l:s,me=hasFieldText(ue),he=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof i?i:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+H}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},R?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":se,padding:E}:T?{borderBottomColor:oe?ae:k.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,y,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:se,stroke:oe?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,R?M?{top:0,bottom:0}:{top:0,height:_.height-2*E}:A?{top:D,bottom:D,left:D}:{bottom:0,height:q},{width:A?Math.max(Q.width-2*D,0):Q.width,borderRadius:re,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},v]}):null,r.map((e,t)=>{const r=e.value===I,i=r?ie:k.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:i,size:_.icon,selected:r,disabled:u});return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:r,selected:r,disabled:u},"aria-checked":r,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!r?.7:1},S],children:[s?_jsx(View,{style:L.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{variant:"label",weight:r?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:i,fontSize:_.text},w,C],numberOfLines:z,children:e.label})]},String(e.value))})]}),!oe||T||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:R?W:N,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:i}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:ne}):null]}):he});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Chevron}from"../FieldBase/Chevron.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{DEFAULT_OPTION_SHEET_LABELS,OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{TextInkContext}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SELECT_LABELS={placeholder:"Select…",noSelection:"No selection",selected:e=>`Selected: ${e}`,fallbackName:"Select",sheetName:"Options",searchPlaceholder:DEFAULT_OPTION_SHEET_LABELS.searchPlaceholder,empty:DEFAULT_OPTION_SHEET_LABELS.empty};const sameSelectValue=(e,t)=>String(e)===String(t),containsValue=(e,t)=>e.some(e=>sameSelectValue(e,t)),Select=forwardRef((e,t)=>{warnInvalidValue("Select","size",e.size,["sm","md","lg"]),warnInvalidValue("Select","variant",e.variant,["outline","filled","underline"]);const{options:l,getOptionLabel:i,getOptionValue:o,isOptionDisabled:n,getOptionDescription:r,getOptionIcon:s,placeholder:a,onOpenChange:c,searchable:d=!1,haptic:p,labels:u,label:h,help:x,title:S,required:m=!1,error:f,helperText:g,prefix:b,numberOfLines:v=1,disabled:y=!1,size:T="md",variant:C,leftIcon:j,rightIcon:L,chevronColor:_,chevronSize:O,radius:F,accessibilityLabel:E,labelStyle:V,style:I,triggerStyle:k,textStyle:z,optionStyle:A,selectedOptionStyle:H,optionTextStyle:w,selectedOptionTextStyle:P,testID:D}=e,B=!0===e.multi,N=u?{...DEFAULT_SELECT_LABELS,...u}:DEFAULT_SELECT_LABELS,M=useCallback(e=>i?i(e):e.label??"",[i]),R=useCallback(e=>o?o(e):e.value,[o]),U=useCallback(e=>n?n(e):!0===e.disabled,[n]),q=useCallback(e=>r?r(e):e.description,[r]),$=useCallback(e=>s?s(e):e.icon,[s]),G=useTheme(),J=useMemo(()=>buildStyles(G),[G]),K=resolveFieldSize(G,T),Q=resolveFieldTextStyle(G,{disabled:y}),W=C??G.settings.components.select?.defaultVariant??G.settings.components.field?.defaultVariant??"outline",[X,Y]=useState(!1),Z=useMemo(()=>{if(B){const t=e.value??[];return l.filter(e=>containsValue(t,R(e)))}const t=e.value;if(null==t)return[];const i=l.find(e=>sameSelectValue(R(e),t));return i?[i]:[]},[B,l,e.value,R]),ee=useCallback(()=>{if(y)return;const e=resolveHaptic(p,"selection");e&&triggerHaptic(e),Y(!0)},[y,p]),te=useCallback(()=>{Y(!1)},[]),le=useCallback(t=>{if(U(t))return;const l=R(t),i=resolveHaptic(p,"selection");if(i&&triggerHaptic(i),B){const t=e.value??[],i=containsValue(t,l)?t.filter(e=>!sameSelectValue(e,l)):[...t,l];return void e.onChange(i)}e.onChange(l),te()},[B,e,te,U,R,p]),ie=0===Z.length?a??N.placeholder:Z.map(e=>M(e)).join(", "),oe=0===Z.length,ne=!0===f||hasFieldText(f),re=hasFieldText(h),se=fieldTextAsString(h),ae=Math.round(1.4*K.text),ce=useMemo(()=>({fontSize:K.text,color:Q.placeholderColor}),[K.text,Q.placeholderColor]),de={color:y?G.colors["field-icon-disabled"]:X?G.colors["field-icon-focus"]:G.colors["field-icon"],size:K.icon,disabled:y,focused:X,error:ne},pe=0===Z.length?a??N.noSelection:N.selected(Z.map(e=>M(e)).join(", ")),ue=E??`${se??N.fallbackName}. ${pe}`;return _jsxs(View,{style:[J.container,I],testID:D,children:[re?_jsx(FieldLabel,{size:T,required:m,help:x,style:V,children:h}):null,_jsx(View,{ref:t,collapsable:!1,children:_jsxs(FieldBase,{size:T,variant:W,disabled:y,error:ne,filled:Z.length>0,onPress:ee,radius:F,paddingHorizontal:"underline"===W?G.space.none:void 0,accessibilityRole:"button",accessibilityLabel:ue,accessibilityState:{disabled:y,expanded:X},"aria-disabled":y,"aria-expanded":X,style:k,slotAlign:1===v?"center":"top",slotLineHeight:1===v?void 0:ae,leading:j?_jsx(View,{children:renderSlotIcon(j,de)}):null,trailing:L?_jsx(View,{children:renderSlotIcon(L,de)}):_jsx(Chevron,{color:_??(y?G.colors["text-disabled"]:G.colors["text-subtle"]),size:O??K.icon,open:X,style:J.chevron}),children:[hasFieldText(b)?"string"==typeof b||"number"==typeof b?_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===v?void 0:ae,marginRight:G.space.xs}],children:b}):_jsx(View,{style:[J.prefixNode,{minHeight:1===v?void 0:ae,justifyContent:"center",marginRight:G.space.xs}],children:_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===v?void 0:ae}],children:_jsx(TextInkContext.Provider,{value:ce,children:b})})}):null,_jsxs(Text,{variant:"body",style:[J.triggerText,{color:oe?Q.placeholderColor:Q.color,fontSize:K.text,lineHeight:1===v?void 0:ae,...Q.weightStyle},z],numberOfLines:v,children:[ie,oe&&m&&!re?_jsx(RequiredMark,{}):null]})]})}),_jsx(FieldMessage,{size:T,error:ne,text:ne?f:g}),_jsx(OptionSheet,{open:X,onClose:te,onOpenChange:c,haptic:p,title:S??se,accessibilityLabel:se??(re?S:void 0)??a??N.sheetName,options:l,getOptionLabel:M,getOptionValue:R,isOptionDisabled:U,getOptionDescription:q,getOptionIcon:$,value:e.value,onChange:(e,t)=>le(t),multi:B,searchable:d,labels:{searchPlaceholder:N.searchPlaceholder,empty:N.empty},optionStyle:A,selectedOptionStyle:H,optionTextStyle:w,selectedOptionTextStyle:P,searchSelectionColor:resolveVariantColors(G,W).borderFocusedRepresentative})]})});Select.displayName="Select";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},label:{includeFontPadding:!1},triggerText:{flex:1,includeFontPadding:!1},errorText:{includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},chevron:{marginLeft:e.space.sm}});export{Select};export default Select;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Chevron}from"../FieldBase/Chevron.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{DEFAULT_OPTION_SHEET_LABELS,OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{TextInkContext}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SELECT_LABELS={placeholder:"Select…",noSelection:"No selection",selected:e=>`Selected: ${e}`,fallbackName:"Select",sheetName:"Options",searchPlaceholder:DEFAULT_OPTION_SHEET_LABELS.searchPlaceholder,empty:DEFAULT_OPTION_SHEET_LABELS.empty};const sameSelectValue=(e,t)=>String(e)===String(t),containsValue=(e,t)=>e.some(e=>sameSelectValue(e,t)),Select=forwardRef((e,t)=>{warnInvalidValue("Select","size",e.size,["sm","md","lg"]),warnInvalidValue("Select","variant",e.variant,["outline","filled","underline"]);const{options:l,getOptionLabel:i,getOptionValue:o,isOptionDisabled:n,getOptionDescription:r,getOptionIcon:s,placeholder:a,onOpenChange:c,searchable:d=!1,haptic:p,labels:u,label:h,help:x,title:S,required:m=!1,error:f,helperText:g,prefix:b,numberOfLines:v=1,disabled:y=!1,size:T="md",variant:C,leftIcon:L,rightIcon:j,chevronColor:_,chevronSize:O,radius:F,accessibilityLabel:E,labelStyle:I,style:V,triggerStyle:k,textStyle:z,optionStyle:A,selectedOptionStyle:w,optionTextStyle:H,selectedOptionTextStyle:P,testID:D}=e,B=!0===e.multi,N=u?{...DEFAULT_SELECT_LABELS,...u}:DEFAULT_SELECT_LABELS,M=useCallback(e=>i?i(e):e.label??"",[i]),R=useCallback(e=>o?o(e):e.value,[o]),U=useCallback(e=>n?n(e):!0===e.disabled,[n]),q=useCallback(e=>r?r(e):e.description,[r]),$=useCallback(e=>s?s(e):e.icon,[s]),G=useTheme(),J=useMemo(()=>buildStyles(G),[G]),K=resolveFieldSize(G,T),Q=resolveFieldTextStyle(G,{disabled:y}),W=C??G.settings.components.select?.defaultVariant??G.settings.components.field?.defaultVariant??"outline",[X,Y]=useState(!1),Z=useMemo(()=>{if(B){const t=e.value??[];return l.filter(e=>containsValue(t,R(e)))}const t=e.value;if(null==t)return[];const i=l.find(e=>sameSelectValue(R(e),t));return i?[i]:[]},[B,l,e.value,R]),ee=useCallback(()=>{if(y)return;const e=resolveHaptic(p,"selection");e&&triggerHaptic(e),Y(!0)},[y,p]),te=useCallback(()=>{Y(!1)},[]),le=useCallback(t=>{if(U(t))return;const l=R(t),i=resolveHaptic(p,"selection");if(i&&triggerHaptic(i),B){const t=e.value??[],i=containsValue(t,l)?t.filter(e=>!sameSelectValue(e,l)):[...t,l];return void e.onChange(i)}e.onChange(l),te()},[B,e,te,U,R,p]),ie=0===Z.length?a??N.placeholder:Z.map(e=>M(e)).join(", "),oe=0===Z.length,ne=!0===f||hasFieldText(f),re=hasFieldText(h),se=fieldTextAsString(h),ae=Math.round(1.4*K.text),ce=useMemo(()=>({fontSize:K.text,color:Q.placeholderColor}),[K.text,Q.placeholderColor]),de={color:y?G.colors["field-icon-disabled"]:X?G.colors["field-icon-focus"]:G.colors["field-icon"],size:K.icon,disabled:y,focused:X,error:ne},pe=0===Z.length?a??N.noSelection:N.selected(Z.map(e=>M(e)).join(", ")),ue=E??`${se??N.fallbackName}. ${pe}`;return _jsxs(View,{style:[J.container,V],testID:D,children:[re?_jsx(FieldLabel,{size:T,required:m,help:x,style:I,children:h}):null,_jsx(View,{ref:t,collapsable:!1,children:_jsxs(FieldBase,{size:T,variant:W,disabled:y,error:ne,filled:Z.length>0,onPress:ee,radius:F,paddingHorizontal:"underline"===W?G.space.none:void 0,accessibilityRole:"button",accessibilityLabel:ue,accessibilityState:{disabled:y,expanded:X},"aria-disabled":y,"aria-expanded":X,style:k,slotAlign:1===v?"center":"top",slotLineHeight:1===v?void 0:ae,leading:L?slotIconView(L,renderSlotIcon(L,de)):null,trailing:j?slotIconView(j,renderSlotIcon(j,de)):_jsx(Chevron,{color:_??(y?G.colors["text-disabled"]:G.colors["text-subtle"]),size:O??K.icon,open:X,style:J.chevron}),children:[hasFieldText(b)?"string"==typeof b||"number"==typeof b?_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===v?void 0:ae,marginRight:G.space.xs}],children:b}):_jsx(View,{style:[J.prefixNode,{minHeight:1===v?void 0:ae,justifyContent:"center",marginRight:G.space.xs}],children:_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===v?void 0:ae}],children:_jsx(TextInkContext.Provider,{value:ce,children:b})})}):null,_jsxs(Text,{variant:"body",style:[J.triggerText,{color:oe?Q.placeholderColor:Q.color,fontSize:K.text,lineHeight:1===v?void 0:ae,...Q.weightStyle},z],numberOfLines:v,children:[ie,oe&&m&&!re?_jsx(RequiredMark,{}):null]})]})}),_jsx(FieldMessage,{size:T,error:ne,text:ne?f:g}),_jsx(OptionSheet,{open:X,onClose:te,onOpenChange:c,haptic:p,title:S??se,accessibilityLabel:se??(re?S:void 0)??a??N.sheetName,options:l,getOptionLabel:M,getOptionValue:R,isOptionDisabled:U,getOptionDescription:q,getOptionIcon:$,value:e.value,onChange:(e,t)=>le(t),multi:B,searchable:d,labels:{searchPlaceholder:N.searchPlaceholder,empty:N.empty},optionStyle:A,selectedOptionStyle:w,optionTextStyle:H,selectedOptionTextStyle:P,searchSelectionColor:resolveVariantColors(G,W).borderFocusedRepresentative})]})});Select.displayName="Select";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},label:{includeFontPadding:!1},triggerText:{flex:1,includeFontPadding:!1},errorText:{includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},chevron:{marginLeft:e.space.sm}});export{Select};export default Select;
@@ -1 +1 @@
1
- "use strict";import{formatPercent}from"@webority/mobile-core";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Card}from"../Card/index.js";import{IconBadge}from"../IconBadge/index.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_STAT_TILE_LABELS=Object.freeze({trendUp:"up",trendDown:"down",trendFlat:"no change"});const isText=e=>"string"==typeof e||"number"==typeof e,TREND_ICON={up:"arrow-up",down:"arrow-down",flat:"minus"},TREND_SIGN={up:"+",down:"-",flat:""},percentText=e=>formatPercent(Math.abs(e),{scale:"percent",maximumFractionDigits:1}),trendFigure=e=>"number"==typeof e.value?`${TREND_SIGN[e.direction]}${percentText(e.value)}`:e.value,trendSpoken=(e,t)=>{const n=[{up:t.trendUp,down:t.trendDown,flat:t.trendFlat}[e.direction]];return"flat"!==e.direction&&n.push("number"==typeof e.value?percentText(e.value):e.value),e.period&&n.push(e.period),n.join(" ")},StatTile=forwardRef((e,t)=>{const{label:n,value:r,icon:i,iconVariant:o,tone:s="primary",caption:a,trend:l,sparkline:c,onPress:d,loading:p=!1,accessibilityLabel:x,labels:u,style:m,testID:f}=e,h=useTheme();warnInvalidValue("StatTile","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("StatTile","trend.direction",l?.direction,["up","down","flat"]),warnInvalidValue("StatTile","trend.goodWhen",l?.goodWhen,["up","down"]);const T=useMemo(()=>({...DEFAULT_STAT_TILE_LABELS,...u}),[u]),w=l?`, ${trendSpoken(l,T)}`:"",y=isText(n)?`${n}, `:"",j=x??(isText(r)?`${y}${r}${w}`:void 0),_=!!l&&l.direction===(l.goodWhen??"up"),S=l&&"flat"!==l.direction?_?"success":"danger":"secondary",v="secondary"===S?h.colors["text-muted"]:h.colors[`${S}-text`];return _jsx(Card,p?{ref:t,variant:"outline",style:m,testID:f,children:_jsxs(View,{style:[styles.row,{columnGap:h.space.md}],children:[void 0===i?null:_jsx(Skeleton,{shape:"circle",width:40,height:40}),_jsxs(View,{style:styles.text,children:[_jsx(Skeleton,{shape:"text",width:"50%",height:12}),_jsx(Skeleton,{shape:"text",width:"35%",height:24,style:{marginTop:h.space.xs}})]})]})}:{ref:t,variant:"outline",onPress:d,accessibilityLabel:j,style:m,testID:f,children:_jsxs(View,{style:[styles.row,{columnGap:h.space.md}],children:[void 0===i?null:_jsx(IconBadge,{icon:i,iconVariant:o,tone:s}),_jsxs(View,{style:styles.text,children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:n}),isText(r)?_jsx(Text,{variant:"h3",numberOfLines:1,children:r}):r,l?_jsxs(View,{style:[styles.trend,{columnGap:h.space.xxs}],testID:f?`${f}-trend`:void 0,children:[_jsx(AppIcon,{name:TREND_ICON[l.direction],size:"xs",color:v}),_jsxs(Text,{variant:"caption",color:S,numberOfLines:2,style:styles.text,children:[trendFigure(l),l.period?_jsx(Text,{variant:"caption",color:"tertiary",children:` ${l.period}`}):null]})]}):null,null==a||""===a?null:isText(a)?_jsx(Text,{variant:"caption",color:"tertiary",numberOfLines:1,children:a}):a,null==c?null:_jsx(View,{style:{marginTop:h.space.sm},children:c})]})]})})});StatTile.displayName="StatTile";const styles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},text:{flex:1,minWidth:0},trend:{flexDirection:"row",alignItems:"center"}});export{StatTile};export default StatTile;
1
+ "use strict";import{formatPercent}from"@webority/mobile-core";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Card}from"../Card/index.js";import{IconBadge}from"../IconBadge/index.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_STAT_TILE_LABELS=Object.freeze({trendUp:"up",trendDown:"down",trendFlat:"no change"});const isText=e=>"string"==typeof e||"number"==typeof e,TREND_ICON={up:"arrow-up",down:"arrow-down",flat:"minus"},TREND_SIGN={up:"+",down:"-",flat:""},percentText=e=>formatPercent(Math.abs(e),{scale:"percent",maximumFractionDigits:1}),trendFigure=e=>"number"==typeof e.value?`${TREND_SIGN[e.direction]}${percentText(e.value)}`:e.value,trendSpoken=(e,t)=>{const n=[{up:t.trendUp,down:t.trendDown,flat:t.trendFlat}[e.direction]];return"flat"!==e.direction&&n.push("number"==typeof e.value?percentText(e.value):e.value),e.period&&n.push(e.period),n.join(" ")},StatTile=forwardRef((e,t)=>{const{label:n,value:r,icon:i,iconVariant:o,tone:s="primary",caption:a,trend:l,sparkline:d,onPress:c,loading:p=!1,accessibilityLabel:x,labels:m,style:u,testID:h}=e,f=useTheme();warnInvalidValue("StatTile","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("StatTile","trend.direction",l?.direction,["up","down","flat"]),warnInvalidValue("StatTile","trend.goodWhen",l?.goodWhen,["up","down"]);const T=useMemo(()=>({...DEFAULT_STAT_TILE_LABELS,...m}),[m]),y=l?`, ${trendSpoken(l,T)}`:"",w=isText(n)?`${n}, `:"",j=x??(isText(r)?`${w}${r}${y}`:void 0),_=!!l&&l.direction===(l.goodWhen??"up"),S=l&&"flat"!==l.direction?_?"success":"danger":"secondary",v="secondary"===S?f.colors["text-muted"]:f.colors[`${S}-text`];return _jsx(Card,p?{ref:t,variant:"outline",style:u,testID:h,children:_jsxs(View,{style:[styles.row,{columnGap:f.space.md}],children:[void 0===i?null:_jsx(Skeleton,{shape:"circle",width:40,height:40}),_jsxs(View,{style:styles.text,children:[_jsx(Skeleton,{shape:"text",width:"50%",height:12}),_jsx(Skeleton,{shape:"text",width:"35%",height:24,style:{marginTop:f.space.xs}})]})]})}:{ref:t,variant:"outline",onPress:c,accessibilityLabel:j,style:u,testID:h,children:_jsxs(View,{style:[styles.row,{columnGap:f.space.md}],children:[void 0===i?null:_jsx(IconBadge,{icon:i,iconVariant:o,tone:s}),_jsxs(View,{style:styles.text,children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:n}),isText(r)?_jsx(Text,{variant:"h3",numberOfLines:1,children:r}):r,l?_jsxs(View,{style:[styles.trend,{columnGap:f.space.xxs}],testID:h?`${h}-trend`:void 0,children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:TREND_ICON[l.direction],size:"xs",color:v})}),_jsxs(Text,{variant:"caption",color:S,numberOfLines:2,style:styles.text,children:[trendFigure(l),l.period?_jsx(Text,{variant:"caption",color:"tertiary",children:` ${l.period}`}):null]})]}):null,null==a||""===a?null:isText(a)?_jsx(Text,{variant:"caption",color:"tertiary",numberOfLines:1,children:a}):a,null==d?null:_jsx(View,{style:{marginTop:f.space.sm},children:d})]})]})})});StatTile.displayName="StatTile";const styles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},text:{flex:1,minWidth:0},trend:{flexDirection:"row",alignItems:"center"}});export{StatTile};export default StatTile;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:o,threshold:i,fullSwipeThreshold:r,onSwipeOpen:s,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),w=i??80,b=r??200,f=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,v=!!o&&o.length>0,x=Dimensions.get("window").width,I=y?w*(n?.length??0):0,A=v?w*(o?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,s?.(e))},[s]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:o,i=t?.[0];i&&(!1!==c&&triggerHaptic("notificationSuccess"),i.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,o,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=I,t=A,n=b,o=-b,i=x,r=-x,s=w,a=y,c=v;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const o=C.value+n.translationX;_.value=o>0&&!a||o<0&&!c?0:o>e&&a?e+.35*(o-e):o<-t&&c?.35*(o+t)-t:o}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(i,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=o?(_.value=withSpring(r,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=s?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-s?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,b,y,v,I,G,j,A,x,w,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,_.value/I)):0}),[I,_]),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,-_.value/A)):0}),[A,_]),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),o?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,o]),D=useCallback(e=>{const t=e.nativeEvent.actionName,i=[...n??[],...o??[]].find(e=>e.key===t);i&&(!1!==c&&triggerHaptic("selection"),i.onPress())},[n,o,c]);return y||v?_jsxs(View,{style:[f.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[f.actionsRow,f.actionsLeft,{width:I},m,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,v?_jsx(Animated.View,{style:[f.actionsRow,f.actionsRight,{width:A},m,V],pointerEvents:"box-none",children:o?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[f.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:o,onPress:i})=>{warnInvalidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const r=e.tone??"neutral",s=toneToBg(t,r),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,r),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>i(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:o,backgroundColor:s,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,r)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:i,threshold:o,fullSwipeThreshold:s,onSwipeOpen:r,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),w=o??80,b=s??200,f=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,v=!!i&&i.length>0,x=Dimensions.get("window").width,I=y?w*(n?.length??0):0,A=v?w*(i?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,r?.(e))},[r]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:i,o=t?.[0];o&&(!1!==c&&triggerHaptic("notificationSuccess"),o.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,i,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=I,t=A,n=b,i=-b,o=x,s=-x,r=w,a=y,c=v;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const i=C.value+n.translationX;_.value=i>0&&!a||i<0&&!c?0:i>e&&a?e+.35*(i-e):i<-t&&c?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(o,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=i?(_.value=withSpring(s,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=r?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-r?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,b,y,v,I,G,j,A,x,w,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,_.value/I)):0}),[I,_]),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,-_.value/A)):0}),[A,_]),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,i]),D=useCallback(e=>{const t=e.nativeEvent.actionName,o=[...n??[],...i??[]].find(e=>e.key===t);o&&(!1!==c&&triggerHaptic("selection"),o.onPress())},[n,i,c]);return y||v?_jsxs(View,{style:[f.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[f.actionsRow,f.actionsLeft,{width:I},m,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,v?_jsx(Animated.View,{style:[f.actionsRow,f.actionsRight,{width:A},m,V],pointerEvents:"box-none",children:i?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[f.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:i,onPress:o})=>{warnInvalidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const s=e.tone??"neutral",r=toneToBg(t,s),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,s),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>o(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:i,backgroundColor:r,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,s)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;