@webority/mobile-ui 0.183.0 → 0.185.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 (44) hide show
  1. package/dist/canvas-kit/kit.js +4 -4
  2. package/dist/canvas-kit/manifest.json +8 -1
  3. package/dist/canvas-kit/release.json +6 -6
  4. package/lib/commonjs/components/Box/Box.js +1 -1
  5. package/lib/commonjs/components/Button/Button.js +1 -1
  6. package/lib/commonjs/components/Card/Card.js +1 -1
  7. package/lib/commonjs/components/Chip/Chip.js +1 -1
  8. package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
  9. package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
  10. package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
  11. package/lib/commonjs/components/Modal/Modal.js +1 -1
  12. package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
  13. package/lib/commonjs/components/Screen/Screen.js +1 -1
  14. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  15. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  16. package/lib/commonjs/components/SquircleFill/SquircleFill.js +1 -1
  17. package/lib/commonjs/components/SquircleView/SquircleView.js +1 -1
  18. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  19. package/lib/commonjs/theme/merge.js +1 -1
  20. package/lib/module/components/Box/Box.js +1 -1
  21. package/lib/module/components/Button/Button.js +1 -1
  22. package/lib/module/components/Card/Card.js +1 -1
  23. package/lib/module/components/Chip/Chip.js +1 -1
  24. package/lib/module/components/EmptyState/EmptyState.js +1 -1
  25. package/lib/module/components/FieldBase/FieldBase.js +1 -1
  26. package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
  27. package/lib/module/components/Modal/Modal.js +1 -1
  28. package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
  29. package/lib/module/components/Screen/Screen.js +1 -1
  30. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  31. package/lib/module/components/Spinner/Spinner.js +1 -1
  32. package/lib/module/components/SquircleFill/SquircleFill.js +1 -1
  33. package/lib/module/components/SquircleView/SquircleView.js +1 -1
  34. package/lib/module/components/Tabs/Tabs.js +1 -1
  35. package/lib/module/theme/merge.js +1 -1
  36. package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +3 -3
  37. package/lib/typescript/commonjs/components/Screen/Screen.d.ts +2 -0
  38. package/lib/typescript/commonjs/components/SquircleFill/SquircleFill.d.ts +7 -1
  39. package/lib/typescript/commonjs/theme/types.d.ts +2 -0
  40. package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +3 -3
  41. package/lib/typescript/module/components/Screen/Screen.d.ts +2 -0
  42. package/lib/typescript/module/components/SquircleFill/SquircleFill.d.ts +7 -1
  43. package/lib/typescript/module/theme/types.d.ts +2 -0
  44. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SquircleFill=SquircleFill,exports.useSquircle=useSquircle;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../theme/index.js"),_squircle=require("../../utils/squircle.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,c={__proto__:null,default:e};if(Object(e)!==e)return c;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,c)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(c,r,i):c[r]=e[r]);return c}const AnimatedPath=_reactNative.Animated.createAnimatedComponent(_reactNativeSvg.Path);function SquircleFill({width:e,height:t,radius:i,fill:r,stroke:a,strokeWidth:c=0,testID:n}){const s=c>0&&void 0!==a&&"transparent"!==a,l=s?c/2:0,u=(0,_index.useTheme)().cornerSmoothing,o=(0,_squircle.squirclePath)({width:e,height:t,radius:i,inset:l,smoothing:u});return(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:styles.overlay,testID:n,children:(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:e,height:t,viewBox:`0 0 ${e} ${t}`,children:(0,_jsxRuntime.jsx)(AnimatedPath,{d:o,fill:r,...s?{stroke:a,strokeWidth:c}:{}})})})}function useSquircle(e,t,i){const[r,a]=(0,_react.useState)(null),c=e&&"android"===_reactNative.Platform.OS;return{onLayout:(0,_react.useCallback)(e=>{if(c){const{width:t,height:i}=e.nativeEvent.layout;a(e=>e&&e.width===t&&e.height===i?e:{width:t,height:i})}i?.(e)},[c,i]),size:r,active:c&&null!==r&&(0,_squircle.squircleApplies)(r.width,r.height,t)}}SquircleFill.displayName="SquircleFill";const styles=_reactNative.StyleSheet.create({overlay:{position:"absolute",top:0,left:0,right:0,bottom:0}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SquircleFill=SquircleFill,exports.useSquircle=useSquircle;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../theme/index.js"),_squircle=require("../../utils/squircle.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,c={__proto__:null,default:e};if(Object(e)!==e)return c;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,c)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(c,r,i):c[r]=e[r]);return c}const AnimatedPath=_reactNative.Animated.createAnimatedComponent(_reactNativeSvg.Path);function SquircleFill({width:e,height:t,radius:i,fill:r,stroke:a,strokeWidth:c=0,hostBorderWidth:n,testID:s}){const l=c>0&&void 0!==a&&"transparent"!==a,o=l?c/2:0,u=(0,_index.useTheme)().cornerSmoothing,h=(0,_squircle.squirclePath)({width:e,height:t,radius:i,inset:o,smoothing:u});return(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:[styles.overlay,n>0?{top:-n,left:-n,right:-n,bottom:-n}:null],testID:s,children:(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:"100%",height:"100%",viewBox:`0 0 ${e} ${t}`,preserveAspectRatio:"none",children:(0,_jsxRuntime.jsx)(AnimatedPath,{d:h,fill:r,...l?{stroke:a,strokeWidth:c}:{}})})})}function useSquircle(e,t,i){const[r,a]=(0,_react.useState)(null),c=e&&"android"===_reactNative.Platform.OS;return{onLayout:(0,_react.useCallback)(e=>{if(c){const{width:t,height:i}=e.nativeEvent.layout;a(e=>e&&e.width===t&&e.height===i?e:{width:t,height:i})}i?.(e)},[c,i]),size:r,active:c&&null!==r&&(0,_squircle.squircleApplies)(r.width,r.height,t)}}SquircleFill.displayName="SquircleFill";const styles=_reactNative.StyleSheet.create({overlay:{position:"absolute",top:0,left:0,right:0,bottom:0}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SquircleView=SquircleView,exports.default=void 0;var _reactNative=require("react-native"),_corners=require("../../utils/corners.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_jsxRuntime=require("react/jsx-runtime");const PER_EDGE_KEYS=["borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","borderTopStartRadius","borderTopEndRadius","borderBottomStartRadius","borderBottomEndRadius","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStartWidth","borderEndWidth","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","borderStartColor","borderEndColor"],readShape=r=>{const{borderRadius:e,backgroundColor:t,borderColor:o,borderWidth:i=0,borderStyle:d}=r;if("number"!=typeof e||e<=0||"hidden"===r.overflow||(r.elevation??0)>0||void 0!==d&&"solid"!==d||PER_EDGE_KEYS.some(e=>void 0!==r[e]))return null;const l="string"==typeof t&&"transparent"!==t,s=i>0&&"string"==typeof o&&"transparent"!==o;return void 0!==t&&"string"!=typeof t||i>0&&void 0!==o&&"string"!=typeof o||!l&&!s?null:{radius:e,fill:l?t:"transparent",stroke:s?o:void 0,strokeWidth:s?i:0}};function SquircleView({style:r,children:e,onLayout:t,ref:o,...i}){const d=_reactNative.StyleSheet.flatten(r)??{},l=readShape(d),s="number"==typeof d.borderRadius?d.borderRadius:0,a=(0,_SquircleFill.useSquircle)(s>0,s,t),n=a.active?a.size:null,u=null!==l&&null!==n;return(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:o,...i,onLayout:a.onLayout,style:[s>0?_corners.smoothCorners:null,r,u?styles.hostTransparent:null],children:[l&&n?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:n.width,height:n.height,radius:l.radius,fill:l.fill,stroke:l.stroke,strokeWidth:l.strokeWidth}):null,e]})}SquircleView.displayName="SquircleView";const styles=_reactNative.StyleSheet.create({hostTransparent:{backgroundColor:"transparent",borderColor:"transparent"}});var _default=exports.default=SquircleView;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SquircleView=SquircleView,exports.default=void 0;var _reactNative=require("react-native"),_corners=require("../../utils/corners.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_jsxRuntime=require("react/jsx-runtime");const PER_EDGE_KEYS=["borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","borderTopStartRadius","borderTopEndRadius","borderBottomStartRadius","borderBottomEndRadius","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStartWidth","borderEndWidth","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","borderStartColor","borderEndColor"],readShape=r=>{const{borderRadius:e,backgroundColor:t,borderColor:o,borderWidth:i=0,borderStyle:d}=r;if("number"!=typeof e||e<=0||"hidden"===r.overflow||(r.elevation??0)>0||void 0!==d&&"solid"!==d||PER_EDGE_KEYS.some(e=>void 0!==r[e]))return null;const l="string"==typeof t&&"transparent"!==t,s=i>0&&"string"==typeof o&&"transparent"!==o;return void 0!==t&&"string"!=typeof t||i>0&&void 0!==o&&"string"!=typeof o||!l&&!s?null:{radius:e,fill:l?t:"transparent",stroke:s?o:void 0,strokeWidth:s?i:0}};function SquircleView({style:r,children:e,onLayout:t,ref:o,...i}){const d=_reactNative.StyleSheet.flatten(r)??{},l=readShape(d),s="number"==typeof d.borderRadius?d.borderRadius:0,a=(0,_SquircleFill.useSquircle)(s>0,s,t),n=a.active?a.size:null,u=null!==l&&null!==n;return(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:o,...i,onLayout:a.onLayout,style:[s>0?_corners.smoothCorners:null,r,u?styles.hostTransparent:null],children:[l&&n?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:n.width,height:n.height,radius:l.radius,fill:l.fill,stroke:l.stroke,strokeWidth:l.strokeWidth,hostBorderWidth:"number"==typeof d.borderWidth?d.borderWidth:0}):null,e]})}SquircleView.displayName="SquircleView";const styles=_reactNative.StyleSheet.create({hostTransparent:{backgroundColor:"transparent",borderColor:"transparent"}});var _default=exports.default=SquircleView;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tabs=Tabs,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Badge/index.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_index4=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const measuredLayout=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`Tabs: tab "${t}" has no measured layout while its progress signal drives the indicator`);return i};function Tabs({ref:e,...t}){const{tabs:i,activeKey:a,onChange:r,variant:s="underline",radius:n,size:l="md",scrollable:o=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:b,tabBadgeStyle:p,dividerStyle:_,indicatorStyle:x,progress:g,pages:h,haptic:y,accessibilityLabel:f,testID:v}=t;(0,_assertValidValue.assertValidValue)("Tabs","variant",t.variant,["underline","pills","segmented"]),(0,_assertValidValue.assertValidValue)("Tabs","size",t.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Tabs","align",t.align,["left","center"]);const j=(0,_index.useTheme)(),S=(0,_react.useMemo)(()=>buildStyles(j),[j]),R=j.components.tabs,V=(0,_react.useMemo)(()=>(0,_index.resolveTabsSize)(j,l),[j,l]),w=o?V["scrollable-padding-x"]:V["padding-x"],k=V["padding-y"],q=V.text,N=j.space[R["icon-gap"]],T=V.icon,z=R["underline-height"],C=j.space[R["pill-inset"]],I=R["disabled-opacity"],L=j.space[R["badge-gap"]],E="segmented"===s,F=(0,_react.useMemo)(()=>(0,_index.resolveSegmentedControlSize)(j,l),[j,l]),A=j.space[R["track-padding"]],M="number"==typeof n?n:n?j.radius[n]:void 0,D=M??j.radius.md,H=void 0===M?j.radius.sm:Math.max(M-A,0),B=M??j.radius.pill,P=M??j.radius.none,O=j.colors["bg-muted"],$=(0,_SquircleFill.useSquircle)(E,D),[W,U]=(0,_react.useState)({}),K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,X=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,[G,J]=(0,_react.useState)(0),Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Y=(0,_react.useRef)(null),Z=(0,_react.useRef)(0),ee=W[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=(0,_react.useMemo)(()=>h&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[h,G,Q])??g,ae=i.every(e=>void 0!==W[e.key]),re=void 0!==ie&&ae&&i.length>1,se=(0,_react.useMemo)(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).x),extrapolate:"clamp"}):null,[re,ie,i,W]),ne=(0,_react.useMemo)(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).width),extrapolate:"clamp"}):null,[re,ie,i,W]),le=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!ee)return;if(re)return;const e=null!==le.current&&le.current!==a;if(le.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=j.motion.spring.snappy,i=_reactNative.Animated.parallel([_reactNative.Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),_reactNative.Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,j.motion.spring.snappy,re]),(0,_react.useEffect)(()=>{h&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[h,G,te]);const oe=h?.length;(0,_react.useEffect)(()=>{__DEV__&&void 0!==oe&&oe!==i.length&&_mobileCore.Logger.warn(`[@webority/mobile-ui] Tabs pages has ${oe} entries for ${i.length} tabs; each tab needs one page.`)},[oe,i.length]);const de=(0,_react.useCallback)(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const r=t[e];return r&&r.x===i&&r.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=(0,_react.useCallback)(e=>{if(e.disabled)return;if(e.key===a)return;const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),r(e.key)},[a,r,y]),ue="pills"===s,me=(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{pointerEvents:"none",style:[E?S.indicatorThumb:ue?S.indicatorPill:S.indicatorUnderline,E?null:ue?{top:C,bottom:C}:{height:z},{width:ne??X,transform:[{translateX:se??K}],backgroundColor:E?j.colors.surface:ue?j.colors["primary-soft"]:j.colors.primary,borderRadius:E?H:ue?B:P,..._corners.smoothCorners},x]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,r=t?j.colors.primary:j.colors["text-subtle"],s=(0,_slotIcon.renderSlotIcon)(e.icon,{color:r,size:T,focused:t,disabled:i}),n=Boolean(s);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:E?void 0:{color:j.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[S.tab,o?null:S.tabFlex,E?{paddingHorizontal:F["padding-x"],height:F.height-2*A}:{paddingHorizontal:w,paddingVertical:k},{opacity:i?I:e&&E&&!t?.7:1,backgroundColor:e&&!E?j.colors["surface-pressed"]:"transparent"},u],children:[n?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[S.tabIcon,{marginRight:N},b],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,(0,_jsxRuntime.jsx)(_index4.Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[S.tabLabel,{fontSize:E?F.text:q},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?(0,_jsxRuntime.jsx)(_index3.Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:L},badgeStyle:[S.tabBadge,p]}):null]},e.key)}),be={flexDirection:"row",alignItems:"stretch",justifyContent:o?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},pe=E?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[me,renderTabs()]}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[renderTabs(),me]}),xe=(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:e,style:[S.container,{borderBottomColor:j.colors["border-subtle"],borderBottomWidth:"underline"===s?_reactNative.StyleSheet.hairlineWidth:0},"underline"===s?_:null,E?{padding:A,borderRadius:D,..._corners.smoothCorners,backgroundColor:$.active?"transparent":O}:null,c],onLayout:$.onLayout,accessibilityRole:"tablist",accessibilityLabel:f,testID:v,children:[$.active&&$.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:$.size.width,height:$.size.height,radius:D,fill:O}):null,o?(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[be],keyboardShouldPersistTaps:"handled",children:pe}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:be,children:pe})]});return h?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:S.root,children:[xe,(0,_jsxRuntime.jsx)(_reactNative.Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:_reactNative.Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),s=i[t];s?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,s&&s.key!==a&&r(s.key))},style:S.pager,testID:v?`${v}-pages`:void 0,children:i.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:h[t]},e.key))})]}):xe}const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});var _default=exports.default=Tabs;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tabs=Tabs,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Badge/index.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_index4=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const measuredLayout=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`Tabs: tab "${t}" has no measured layout while its progress signal drives the indicator`);return i};function Tabs({ref:e,...t}){const{tabs:i,activeKey:a,onChange:r,variant:s="underline",radius:n,size:l="md",scrollable:o=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:b,tabBadgeStyle:p,dividerStyle:_,indicatorStyle:x,progress:g,pages:h,haptic:y,accessibilityLabel:f,testID:v}=t;(0,_assertValidValue.assertValidValue)("Tabs","variant",t.variant,["underline","pills","segmented"]),(0,_assertValidValue.assertValidValue)("Tabs","size",t.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Tabs","align",t.align,["left","center"]);const j=(0,_index.useTheme)(),S=(0,_react.useMemo)(()=>buildStyles(j),[j]),R=j.components.tabs,V=(0,_react.useMemo)(()=>(0,_index.resolveTabsSize)(j,l),[j,l]),w=o?V["scrollable-padding-x"]:V["padding-x"],k=V["padding-y"],q=V.text,N=j.space[R["icon-gap"]],T=V.icon,z=R["underline-height"],C=j.space[R["pill-inset"]],I=R["disabled-opacity"],L=j.space[R["badge-gap"]],E="segmented"===s,F=(0,_react.useMemo)(()=>(0,_index.resolveSegmentedControlSize)(j,l),[j,l]),A=j.space[R["track-padding"]],M="number"==typeof n?n:n?j.radius[n]:void 0,B=M??j.radius.md,D=void 0===M?j.radius.sm:Math.max(M-A,0),H=M??j.radius.pill,P=M??j.radius.none,O=j.colors["bg-muted"],W=(0,_SquircleFill.useSquircle)(E,B),[$,U]=(0,_react.useState)({}),K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,X=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,[G,J]=(0,_react.useState)(0),Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Y=(0,_react.useRef)(null),Z=(0,_react.useRef)(0),ee=$[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=(0,_react.useMemo)(()=>h&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[h,G,Q])??g,ae=i.every(e=>void 0!==$[e.key]),re=void 0!==ie&&ae&&i.length>1,se=(0,_react.useMemo)(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout($,e.key).x),extrapolate:"clamp"}):null,[re,ie,i,$]),ne=(0,_react.useMemo)(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout($,e.key).width),extrapolate:"clamp"}):null,[re,ie,i,$]),le=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!ee)return;if(re)return;const e=null!==le.current&&le.current!==a;if(le.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=j.motion.spring.snappy,i=_reactNative.Animated.parallel([_reactNative.Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),_reactNative.Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,j.motion.spring.snappy,re]),(0,_react.useEffect)(()=>{h&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[h,G,te]);const oe=h?.length;(0,_react.useEffect)(()=>{__DEV__&&void 0!==oe&&oe!==i.length&&_mobileCore.Logger.warn(`[@webority/mobile-ui] Tabs pages has ${oe} entries for ${i.length} tabs; each tab needs one page.`)},[oe,i.length]);const de=(0,_react.useCallback)(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const r=t[e];return r&&r.x===i&&r.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=(0,_react.useCallback)(e=>{if(e.disabled)return;if(e.key===a)return;const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),r(e.key)},[a,r,y]),ue="pills"===s,me=(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{pointerEvents:"none",style:[E?S.indicatorThumb:ue?S.indicatorPill:S.indicatorUnderline,E?null:ue?{top:C,bottom:C}:{height:z},{width:ne??X,transform:[{translateX:se??K}],backgroundColor:E?j.colors.surface:ue?j.colors["primary-soft"]:j.colors.primary,borderRadius:E?D:ue?H:P,..._corners.smoothCorners},x]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,r=t?j.colors.primary:j.colors["text-subtle"],s=(0,_slotIcon.renderSlotIcon)(e.icon,{color:r,size:T,focused:t,disabled:i}),n=Boolean(s);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:E?void 0:{color:j.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[S.tab,o?null:S.tabFlex,E?{paddingHorizontal:F["padding-x"],height:F.height-2*A}:{paddingHorizontal:w,paddingVertical:k},{opacity:i?I:e&&E&&!t?.7:1,backgroundColor:e&&!E?j.colors["surface-pressed"]:"transparent"},u],children:[n?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[S.tabIcon,{marginRight:N},b],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,(0,_jsxRuntime.jsx)(_index4.Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[S.tabLabel,{fontSize:E?F.text:q},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?(0,_jsxRuntime.jsx)(_index3.Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:L},badgeStyle:[S.tabBadge,p]}):null]},e.key)}),be={flexDirection:"row",alignItems:"stretch",justifyContent:o?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},pe=E?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[me,renderTabs()]}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[renderTabs(),me]}),xe=(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:e,style:[S.container,{borderBottomColor:j.colors["border-subtle"],borderBottomWidth:"underline"===s?_reactNative.StyleSheet.hairlineWidth:0},"underline"===s?_:null,E?{padding:A,borderRadius:B,..._corners.smoothCorners,backgroundColor:W.active?"transparent":O}:null,c],onLayout:W.onLayout,accessibilityRole:"tablist",accessibilityLabel:f,testID:v,children:[W.active&&W.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:W.size.width,height:W.size.height,radius:B,fill:O,hostBorderWidth:0}):null,o?(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[be],keyboardShouldPersistTaps:"handled",children:pe}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:be,children:pe})]});return h?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:S.root,children:[xe,(0,_jsxRuntime.jsx)(_reactNative.Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:_reactNative.Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),s=i[t];s?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,s&&s.key!==a&&r(s.key))},style:S.pager,testID:v?`${v}-pages`:void 0,children:i.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:h[t]},e.key))})]}):xe}const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});var _default=exports.default=Tabs;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeBrand=void 0;var _guards=require("../utils/guards.js"),_componentSizes=require("./componentSizes.js"),_tokensGenerated=require("./tokens.generated.js"),_toneInk=require("./toneInk.js");const BRAND_KEYS=["colors","descriptions","radius","font"],COLOR_MODES=["light","dark"],FIXED_RADII=["none","pill"],RADIUS_ALLOWED="sm, md, lg, xl",SETTINGS_KEYS=["icons","gradients","textVariants","maxFontSizeMultiplier","components"],COMPONENT_SETTING_KEYS={field:{defaultVariant:!0,requiredMarker:!0},input:{defaultVariant:!0,defaultLabelMode:!0,tintLabelOnFocus:!0,shakeOnError:!0},"search-bar":{defaultVariant:!0},select:{defaultVariant:!0},"otp-input":{shakeOnError:!0},"option-sheet":{selectedMarker:!0},"profile-picker":{defaultTone:!0,defaultVariant:!0,defaultAvatarTone:!0},slider:{thumbPressAnimation:!0},rating:{pulseOnPress:!0},stepper:{pulseAnimation:!0},tooltip:{enableScaleAnimation:!0},toast:{enableSwipeDismiss:!0,defaultDurationMs:!0},button:{defaultVariant:!0,defaultSize:!0,defaultPressAnimation:!0},card:{defaultVariant:!0,defaultPadding:!0,defaultRadius:!0,defaultTitleFont:!0},"section-header":{defaultVariant:!0,defaultFlush:!0},"empty-state":{defaultSize:!0,defaultVariant:!0},screen:{tabBarFloats:!0,headerShadowOnScroll:!0}},isPlainObject=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),validateBrand=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`A brand is an object of colors, radius and font; got ${typeof e}.`);for(const o of Object.keys(e))if(!BRAND_KEYS.includes(o))throw new Error(`A brand sets colors, descriptions, radius and font only; ${o} is not allowed (allowed: colors, descriptions, radius, font).`);const o=e.descriptions;if(void 0!==o){if(!isPlainObject(o))throw new Error(`A brand's descriptions is an object of colour names to a description; got ${typeof o}.`);for(const e of Object.keys(o)){const t=o[e];if("string"!=typeof t||""===t)throw new Error(`description of colour ${e} must be a non-empty string.`)}}const t=e.colors;if(void 0!==t&&!isPlainObject(t))throw new Error(`A brand's colors is an object of light and dark; got ${typeof t}.`);if((0,_guards.isRecord)(t))for(const e of Object.keys(t)){if(!COLOR_MODES.includes(e))throw new Error(`A brand sets colours under light and dark only; ${e} is not allowed (allowed: light, dark).`);const r=t[e];if(void 0===r)throw new Error(`A brand's ${e} colours are missing.`);if(!(0,_guards.isRecord)(r))throw new Error(`A brand's ${e} colours is an object of colour names; got ${typeof r}.`);for(const e of Object.keys(r)){const t=(0,_guards.isRecord)(o)&&"string"==typeof o[e];if(!(0,_guards.isOneOf)(_tokensGenerated.COLOR_NAMES,e)&&!t)throw new Error(`unknown colour ${e}; allowed: ${_tokensGenerated.COLOR_NAMES.join(", ")}.`);if(void 0!==r[e]&&"string"!=typeof r[e])throw new Error(`colour ${e} must be a string; got ${typeof r[e]}.`)}}const r=e.radius;if(void 0!==r){if(!isPlainObject(r))throw new Error(`A brand's radius is an object of radius names; got ${typeof r}.`);for(const e of Object.keys(r)){const o=r[e];if(!(0,_guards.isOneOf)(_tokensGenerated.RADIUS_NAMES,e))throw new Error(`unknown radius ${e}; allowed: ${RADIUS_ALLOWED}.`);if(FIXED_RADII.includes(e))throw new Error(`radius ${e} is fixed by the library; allowed: ${RADIUS_ALLOWED}.`);if("number"!=typeof o||!Number.isFinite(o))throw new Error(`radius ${e} must be a number; got ${typeof o}.`)}}const n=e.font;if(void 0!==n){if(!isPlainObject(n))throw new Error(`A brand's font is an object of font names; got ${typeof n}.`);for(const e of Object.keys(n)){if(!(0,_guards.isOneOf)(_tokensGenerated.FONT_NAMES,e))throw new Error(`unknown font ${e}; allowed: ${_tokensGenerated.FONT_NAMES.join(", ")}.`);const o=n[e];if(!isPlainObject(o))throw new Error(`font ${e} must be an object of weights; got ${typeof o}.`);for(const t of Object.keys(o)){if(!(0,_guards.isOneOf)(_tokensGenerated.WEIGHT_NAMES,t))throw new Error(`unknown font weight ${t} in font ${e}; allowed: ${_tokensGenerated.WEIGHT_NAMES.join(", ")}.`);const r=o[t];if("string"!=typeof r||0===r.length)throw new Error(`font ${e} weight ${t} must be a non-empty string.`)}}}},validateSettings=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`Theme settings is an object; got ${typeof e}.`);for(const o of Object.keys(e))if(!(0,_guards.isOneOf)(SETTINGS_KEYS,o))throw new Error(`Theme settings take ${SETTINGS_KEYS.join(", ")} only; ${o} is not allowed.`);const o=e.components;if(void 0!==o){if(!isPlainObject(o))throw new Error(`Theme settings components is an object of component names; got ${typeof o}.`);for(const e of Object.keys(o)){if(!(0,_guards.hasKey)(COMPONENT_SETTING_KEYS,e))throw new Error(`unknown component ${e} in theme settings; allowed: ${Object.keys(COMPONENT_SETTING_KEYS).join(", ")}.`);const t=o[e];if(void 0===t)continue;if(!isPlainObject(t))throw new Error(`theme settings for ${e} is an object; got ${typeof t}.`);const r=COMPONENT_SETTING_KEYS[e];for(const o of Object.keys(t))if(!(o in r))throw new Error(`unknown setting ${o} for ${e}; allowed: ${Object.keys(r).join(", ")}.`)}}},TONES=["primary","success","warning","danger","info"],setComponentSettings=(e,o,t)=>{e[o]=t},mergeComponentSettings=(e,o,t)=>({...(0,_guards.hasKey)(e,t)?e[t]:void 0,...void 0!==o&&(0,_guards.hasKey)(o,t)?o[t]:void 0}),mergeBrand=(e,o,t)=>{validateBrand(o),validateSettings(t);const r={};for(const[t,n]of Object.entries(o?.colors?.[e.mode]??{}))void 0!==n&&(r[t]=n);const n={...e.colors,...r},colorOf=e=>{const o=n[e];if(void 0===o)throw new Error(`The theme has no colour ${e}.`);return o},s={...e.radius,...o?.radius},i={...e.font};if(void 0!==o?.font)for(const t of(0,_guards.keysOf)(o.font))i[t]={...e.font[t],...o.font[t]};const a=[colorOf("bg"),colorOf("bg-subtle"),colorOf("bg-muted")],d={};for(const o of TONES){const t="string"==typeof r[o];let n=colorOf(o);if(t||"string"==typeof r[`on-${o}`]){const e=(0,_toneInk.deriveSolidFill)(n,colorOf(`on-${o}`));e!==n&&(d[o]=e,n=e)}if(t&&"string"!=typeof r[`${o}-text`]&&(d[`${o}-text`]=(0,_toneInk.deriveToneInk)(n,a,e.mode)),"primary"===o&&(t||void 0!==d.primary)){const o=(0,_toneInk.deriveStateFills)(n,colorOf("on-primary"),{fill:e.colors.primary,hover:e.colors["primary-hover"],pressed:e.colors["primary-pressed"]});"string"!=typeof r["primary-hover"]&&(d["primary-hover"]=o.hover),"string"!=typeof r["primary-pressed"]&&(d["primary-pressed"]=o.pressed)}}const f=e.settings.components,c=t?.components,l={},u=new Set([...(0,_guards.keysOf)(f),...void 0===c?[]:(0,_guards.keysOf)(c)]);for(const e of u)setComponentSettings(l,e,mergeComponentSettings(f,c,e));const g=t?.maxFontSizeMultiplier??e.settings.maxFontSizeMultiplier,p={icons:{...e.settings.icons,...t?.icons},gradients:{...e.settings.gradients,...t?.gradients},textVariants:{...e.settings.textVariants,...t?.textVariants},components:l,...void 0===g?{}:{maxFontSizeMultiplier:g}},w={...e.colors,...Object.fromEntries(Object.entries(r).filter(([e])=>!(0,_guards.isOneOf)(_tokensGenerated.COLOR_NAMES,e))),...Object.fromEntries(_tokensGenerated.COLOR_NAMES.map(e=>[e,d[e]??colorOf(e)]))},O={...e,colors:w,radius:s,font:i,settings:p};return(0,_componentSizes.validateComponentTokens)(O),O};exports.mergeBrand=mergeBrand;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeBrand=void 0;var _guards=require("../utils/guards.js"),_componentSizes=require("./componentSizes.js"),_tokensGenerated=require("./tokens.generated.js"),_toneInk=require("./toneInk.js");const BRAND_KEYS=["colors","descriptions","radius","font"],COLOR_MODES=["light","dark"],FIXED_RADII=["none","pill"],RADIUS_ALLOWED="sm, md, lg, xl",SETTINGS_KEYS=["icons","gradients","textVariants","maxFontSizeMultiplier","components"],COMPONENT_SETTING_KEYS={field:{defaultVariant:!0,requiredMarker:!0,requiredMarkerSpace:!0},input:{defaultVariant:!0,defaultLabelMode:!0,tintLabelOnFocus:!0,shakeOnError:!0},"search-bar":{defaultVariant:!0},select:{defaultVariant:!0},"otp-input":{shakeOnError:!0},"option-sheet":{selectedMarker:!0},"profile-picker":{defaultTone:!0,defaultVariant:!0,defaultAvatarTone:!0},slider:{thumbPressAnimation:!0},rating:{pulseOnPress:!0},stepper:{pulseAnimation:!0},tooltip:{enableScaleAnimation:!0},toast:{enableSwipeDismiss:!0,defaultDurationMs:!0},button:{defaultVariant:!0,defaultSize:!0,defaultPressAnimation:!0},card:{defaultVariant:!0,defaultPadding:!0,defaultRadius:!0,defaultTitleFont:!0},"section-header":{defaultVariant:!0,defaultFlush:!0},"empty-state":{defaultSize:!0,defaultVariant:!0},screen:{tabBarFloats:!0,headerShadowOnScroll:!0}},isPlainObject=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),validateBrand=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`A brand is an object of colors, radius and font; got ${typeof e}.`);for(const o of Object.keys(e))if(!BRAND_KEYS.includes(o))throw new Error(`A brand sets colors, descriptions, radius and font only; ${o} is not allowed (allowed: colors, descriptions, radius, font).`);const o=e.descriptions;if(void 0!==o){if(!isPlainObject(o))throw new Error(`A brand's descriptions is an object of colour names to a description; got ${typeof o}.`);for(const e of Object.keys(o)){const t=o[e];if("string"!=typeof t||""===t)throw new Error(`description of colour ${e} must be a non-empty string.`)}}const t=e.colors;if(void 0!==t&&!isPlainObject(t))throw new Error(`A brand's colors is an object of light and dark; got ${typeof t}.`);if((0,_guards.isRecord)(t))for(const e of Object.keys(t)){if(!COLOR_MODES.includes(e))throw new Error(`A brand sets colours under light and dark only; ${e} is not allowed (allowed: light, dark).`);const r=t[e];if(void 0===r)throw new Error(`A brand's ${e} colours are missing.`);if(!(0,_guards.isRecord)(r))throw new Error(`A brand's ${e} colours is an object of colour names; got ${typeof r}.`);for(const e of Object.keys(r)){const t=(0,_guards.isRecord)(o)&&"string"==typeof o[e];if(!(0,_guards.isOneOf)(_tokensGenerated.COLOR_NAMES,e)&&!t)throw new Error(`unknown colour ${e}; allowed: ${_tokensGenerated.COLOR_NAMES.join(", ")}.`);if(void 0!==r[e]&&"string"!=typeof r[e])throw new Error(`colour ${e} must be a string; got ${typeof r[e]}.`)}}const r=e.radius;if(void 0!==r){if(!isPlainObject(r))throw new Error(`A brand's radius is an object of radius names; got ${typeof r}.`);for(const e of Object.keys(r)){const o=r[e];if(!(0,_guards.isOneOf)(_tokensGenerated.RADIUS_NAMES,e))throw new Error(`unknown radius ${e}; allowed: ${RADIUS_ALLOWED}.`);if(FIXED_RADII.includes(e))throw new Error(`radius ${e} is fixed by the library; allowed: ${RADIUS_ALLOWED}.`);if("number"!=typeof o||!Number.isFinite(o))throw new Error(`radius ${e} must be a number; got ${typeof o}.`)}}const n=e.font;if(void 0!==n){if(!isPlainObject(n))throw new Error(`A brand's font is an object of font names; got ${typeof n}.`);for(const e of Object.keys(n)){if(!(0,_guards.isOneOf)(_tokensGenerated.FONT_NAMES,e))throw new Error(`unknown font ${e}; allowed: ${_tokensGenerated.FONT_NAMES.join(", ")}.`);const o=n[e];if(!isPlainObject(o))throw new Error(`font ${e} must be an object of weights; got ${typeof o}.`);for(const t of Object.keys(o)){if(!(0,_guards.isOneOf)(_tokensGenerated.WEIGHT_NAMES,t))throw new Error(`unknown font weight ${t} in font ${e}; allowed: ${_tokensGenerated.WEIGHT_NAMES.join(", ")}.`);const r=o[t];if("string"!=typeof r||0===r.length)throw new Error(`font ${e} weight ${t} must be a non-empty string.`)}}}},validateSettings=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`Theme settings is an object; got ${typeof e}.`);for(const o of Object.keys(e))if(!(0,_guards.isOneOf)(SETTINGS_KEYS,o))throw new Error(`Theme settings take ${SETTINGS_KEYS.join(", ")} only; ${o} is not allowed.`);const o=e.components;if(void 0!==o){if(!isPlainObject(o))throw new Error(`Theme settings components is an object of component names; got ${typeof o}.`);for(const e of Object.keys(o)){if(!(0,_guards.hasKey)(COMPONENT_SETTING_KEYS,e))throw new Error(`unknown component ${e} in theme settings; allowed: ${Object.keys(COMPONENT_SETTING_KEYS).join(", ")}.`);const t=o[e];if(void 0===t)continue;if(!isPlainObject(t))throw new Error(`theme settings for ${e} is an object; got ${typeof t}.`);const r=COMPONENT_SETTING_KEYS[e];for(const o of Object.keys(t))if(!(o in r))throw new Error(`unknown setting ${o} for ${e}; allowed: ${Object.keys(r).join(", ")}.`)}}},TONES=["primary","success","warning","danger","info"],setComponentSettings=(e,o,t)=>{e[o]=t},mergeComponentSettings=(e,o,t)=>({...(0,_guards.hasKey)(e,t)?e[t]:void 0,...void 0!==o&&(0,_guards.hasKey)(o,t)?o[t]:void 0}),mergeBrand=(e,o,t)=>{validateBrand(o),validateSettings(t);const r={};for(const[t,n]of Object.entries(o?.colors?.[e.mode]??{}))void 0!==n&&(r[t]=n);const n={...e.colors,...r},colorOf=e=>{const o=n[e];if(void 0===o)throw new Error(`The theme has no colour ${e}.`);return o},s={...e.radius,...o?.radius},i={...e.font};if(void 0!==o?.font)for(const t of(0,_guards.keysOf)(o.font))i[t]={...e.font[t],...o.font[t]};const a=[colorOf("bg"),colorOf("bg-subtle"),colorOf("bg-muted")],d={};for(const o of TONES){const t="string"==typeof r[o];let n=colorOf(o);if(t||"string"==typeof r[`on-${o}`]){const e=(0,_toneInk.deriveSolidFill)(n,colorOf(`on-${o}`));e!==n&&(d[o]=e,n=e)}if(t&&"string"!=typeof r[`${o}-text`]&&(d[`${o}-text`]=(0,_toneInk.deriveToneInk)(n,a,e.mode)),"primary"===o&&(t||void 0!==d.primary)){const o=(0,_toneInk.deriveStateFills)(n,colorOf("on-primary"),{fill:e.colors.primary,hover:e.colors["primary-hover"],pressed:e.colors["primary-pressed"]});"string"!=typeof r["primary-hover"]&&(d["primary-hover"]=o.hover),"string"!=typeof r["primary-pressed"]&&(d["primary-pressed"]=o.pressed)}}const f=e.settings.components,c=t?.components,l={},u=new Set([...(0,_guards.keysOf)(f),...void 0===c?[]:(0,_guards.keysOf)(c)]);for(const e of u)setComponentSettings(l,e,mergeComponentSettings(f,c,e));const p=t?.maxFontSizeMultiplier??e.settings.maxFontSizeMultiplier,g={icons:{...e.settings.icons,...t?.icons},gradients:{...e.settings.gradients,...t?.gradients},textVariants:{...e.settings.textVariants,...t?.textVariants},components:l,...void 0===p?{}:{maxFontSizeMultiplier:p}},w={...e.colors,...Object.fromEntries(Object.entries(r).filter(([e])=>!(0,_guards.isOneOf)(_tokensGenerated.COLOR_NAMES,e))),...Object.fromEntries(_tokensGenerated.COLOR_NAMES.map(e=>[e,d[e]??colorOf(e)]))},O={...e,colors:w,radius:s,font:i,settings:g};return(0,_componentSizes.validateComponentTokens)(O),O};exports.mergeBrand=mergeBrand;
@@ -1 +1 @@
1
- "use strict";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{radiusOf,spaceOf}from"../../theme/scale.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],space=(r,e)=>null==e?void 0:spaceOf(r,e);export const resolveBoxStyle=(r,e)=>({...null!=e.p?{padding:space(r,e.p)}:{},...null!=e.px?{paddingHorizontal:space(r,e.px)}:{},...null!=e.py?{paddingVertical:space(r,e.py)}:{},...null!=e.pt?{paddingTop:space(r,e.pt)}:{},...null!=e.pr?{paddingRight:space(r,e.pr)}:{},...null!=e.pb?{paddingBottom:space(r,e.pb)}:{},...null!=e.pl?{paddingLeft:space(r,e.pl)}:{},...null!=e.m?{margin:space(r,e.m)}:{},...null!=e.mx?{marginHorizontal:space(r,e.mx)}:{},...null!=e.my?{marginVertical:space(r,e.my)}:{},...null!=e.mt?{marginTop:space(r,e.mt)}:{},...null!=e.mr?{marginRight:space(r,e.mr)}:{},...null!=e.mb?{marginBottom:space(r,e.mb)}:{},...null!=e.ml?{marginLeft:space(r,e.ml)}:{},...null!=e.gap?{gap:space(r,e.gap)}:{},...null!=e.bg?{backgroundColor:isOneOf(BACKGROUND_TOKENS,e.bg)?r.colors[e.bg]:e.bg}:{},...null!=e.radius?{borderRadius:radiusOf(r,e.radius),borderCurve:smoothCorners.borderCurve}:{},...e.border?{borderWidth:r.size.border,borderColor:r.colors.border}:{},...null!=e.flex?{flex:e.flex}:{},...null!=e.align?{alignItems:e.align}:{},...null!=e.justify?{justifyContent:e.justify}:{},...null!=e.direction?{flexDirection:e.direction}:{},...e.wrap?{flexWrap:"wrap"}:{}});function Box(r){const e=useTheme(),{p:l,px:o,py:t,pt:i,pr:s,pb:n,pl:a,m:p,mx:u,my:c,mt:m,mr:d,mb:g,ml:f,gap:b,bg:x,radius:y,border:h,flex:j,align:S,justify:w,direction:C,wrap:O,style:B,children:v,ref:_,...R}=r,k=resolveBoxStyle(e,{p:l,px:o,py:t,pt:i,pr:s,pb:n,pl:a,m:p,mx:u,my:c,mt:m,mr:d,mb:g,ml:f,gap:b,bg:x,radius:y,border:h,flex:j,align:S,justify:w,direction:C,wrap:O}),z="number"==typeof k.borderRadius?k.borderRadius:0,T="string"==typeof k.backgroundColor?k.backgroundColor:"transparent",q="string"==typeof k.borderColor?k.borderColor:void 0,D="number"==typeof k.borderWidth?k.borderWidth:0,V=useSquircle(null!=y&&(null!=x||Boolean(h)),z,R.onLayout),L=V.active?{...k,backgroundColor:"transparent",borderColor:"transparent"}:k;return _jsxs(View,{ref:_,...R,onLayout:V.onLayout,style:[L,B],children:[V.active&&V.size?_jsx(SquircleFill,{width:V.size.width,height:V.size.height,radius:z,fill:T,stroke:q,strokeWidth:D}):null,v]})}function Stack({gap:r="md",ref:e,...l}){return _jsx(Box,{ref:e,direction:"column",gap:r,...l})}function Row({gap:r="sm",align:e="center",ref:l,...o}){return _jsx(Box,{ref:l,direction:"row",gap:r,align:e,...o})}const Spacer=({size:r,style:e,testID:l})=>{const o=useTheme();if(null!=r){const t=spaceOf(o,r);return _jsx(View,{testID:l,style:[{width:t,height:t},e]})}return _jsx(View,{testID:l,style:[{flex:1},e]})};Spacer.displayName="Spacer";export{Box,Row,Spacer,Stack};export default Box;
1
+ "use strict";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{radiusOf,spaceOf}from"../../theme/scale.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],space=(r,e)=>null==e?void 0:spaceOf(r,e);export const resolveBoxStyle=(r,e)=>({...null!=e.p?{padding:space(r,e.p)}:{},...null!=e.px?{paddingHorizontal:space(r,e.px)}:{},...null!=e.py?{paddingVertical:space(r,e.py)}:{},...null!=e.pt?{paddingTop:space(r,e.pt)}:{},...null!=e.pr?{paddingRight:space(r,e.pr)}:{},...null!=e.pb?{paddingBottom:space(r,e.pb)}:{},...null!=e.pl?{paddingLeft:space(r,e.pl)}:{},...null!=e.m?{margin:space(r,e.m)}:{},...null!=e.mx?{marginHorizontal:space(r,e.mx)}:{},...null!=e.my?{marginVertical:space(r,e.my)}:{},...null!=e.mt?{marginTop:space(r,e.mt)}:{},...null!=e.mr?{marginRight:space(r,e.mr)}:{},...null!=e.mb?{marginBottom:space(r,e.mb)}:{},...null!=e.ml?{marginLeft:space(r,e.ml)}:{},...null!=e.gap?{gap:space(r,e.gap)}:{},...null!=e.bg?{backgroundColor:isOneOf(BACKGROUND_TOKENS,e.bg)?r.colors[e.bg]:e.bg}:{},...null!=e.radius?{borderRadius:radiusOf(r,e.radius),borderCurve:smoothCorners.borderCurve}:{},...e.border?{borderWidth:r.size.border,borderColor:r.colors.border}:{},...null!=e.flex?{flex:e.flex}:{},...null!=e.align?{alignItems:e.align}:{},...null!=e.justify?{justifyContent:e.justify}:{},...null!=e.direction?{flexDirection:e.direction}:{},...e.wrap?{flexWrap:"wrap"}:{}});function Box(r){const e=useTheme(),{p:l,px:o,py:t,pt:i,pr:s,pb:n,pl:a,m:p,mx:u,my:d,mt:c,mr:m,mb:g,ml:f,gap:b,bg:x,radius:y,border:h,flex:j,align:S,justify:w,direction:C,wrap:B,style:O,children:v,ref:_,...R}=r,k=resolveBoxStyle(e,{p:l,px:o,py:t,pt:i,pr:s,pb:n,pl:a,m:p,mx:u,my:d,mt:c,mr:m,mb:g,ml:f,gap:b,bg:x,radius:y,border:h,flex:j,align:S,justify:w,direction:C,wrap:B}),z="number"==typeof k.borderRadius?k.borderRadius:0,T="string"==typeof k.backgroundColor?k.backgroundColor:"transparent",q="string"==typeof k.borderColor?k.borderColor:void 0,D="number"==typeof k.borderWidth?k.borderWidth:0,V=useSquircle(null!=y&&(null!=x||Boolean(h)),z,R.onLayout),W=V.active?{...k,backgroundColor:"transparent",borderColor:"transparent"}:k;return _jsxs(View,{ref:_,...R,onLayout:V.onLayout,style:[W,O],children:[V.active&&V.size?_jsx(SquircleFill,{width:V.size.width,height:V.size.height,radius:z,fill:T,stroke:q,strokeWidth:D,hostBorderWidth:D}):null,v]})}function Stack({gap:r="md",ref:e,...l}){return _jsx(Box,{ref:e,direction:"column",gap:r,...l})}function Row({gap:r="sm",align:e="center",ref:l,...o}){return _jsx(Box,{ref:l,direction:"row",gap:r,align:e,...o})}const Spacer=({size:r,style:e,testID:l})=>{const o=useTheme();if(null!=r){const t=spaceOf(o,r);return _jsx(View,{testID:l,style:[{width:t,height:t},e]})}return _jsx(View,{testID:l,style:[{flex:1},e]})};Spacer.displayName="Spacer";export{Box,Row,Spacer,Stack};export default Box;
@@ -1 +1 @@
1
- "use strict";import{useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useMobileUiText}from"../../text/index.js";import{BUTTON_TEXT}from"../../text/phone/button.g.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const BUTTON_VARIANTS=["solid","soft","outline","ghost","link","glass"];export const BUTTON_TONES=["primary","success","warning","danger","info","neutral"];export function isButtonVariant(e){return BUTTON_VARIANTS.some(t=>t===e)}export function isButtonTone(e){return BUTTON_TONES.some(t=>t===e)}function Button({ref:e,...t}){const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,wrapperStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:T,accessibilityHint:C,accessibilityState:_,testID:I,onLayout:v,labels:j,...k}=t;assertValidValue("Button","variant",t.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",t.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",t.size,["xs","sm","md","lg","xl"]);const w=useTheme(),F=w.settings.components.button,V=r??F?.defaultVariant??"solid",O=i??F?.defaultSize??"md",L=useMobileUiText("button",BUTTON_TEXT),A=useMemo(()=>({...L,...j}),[L,j]),[R,B]=useState(!1),N=useRef(!1),P=n||R,E=!l&&!P,z={..._,disabled:!E,busy:P},H="link"===V,W=y??F?.defaultPressAnimation??(!H&&"scale"),D=usePressAnimation({preset:W||"scale",enabled:!1!==W&&E}),M=useFlickGuard(),U=useMemo(()=>buildStyles(w),[w]),q=useMemo(()=>resolveButtonSize(w,O),[w,O]),G=useMemo(()=>toneFor(w,s),[w,s]),K=useMemo(()=>variantFor(w,V,G,l),[w,V,G,l]),X=useMemo(()=>!m||l||"solid"!==V?null:"string"==typeof m?w.settings.gradients[m]??null:m,[m,l,V,w.settings.gradients]),Y=StyleSheet.flatten(f)?.borderRadius,J=H?0:"number"==typeof Y?Y:p?w.radius.pill:q.radius,Q=useSquircle(!X&&"link"!==V,J,v),Z=useRef(createAnimatedValue(0)).current,[$,ee]=useState(0),[te,oe]=useState(null),re=H?e=>ee(e.nativeEvent.layout.width):void 0,settlePending=()=>{N.current=!1,B(!1)},se=T??o,ie="outline"===V||"ghost"===V,ne=!ie&&!H,le={color:K.textColor,size:q.icon,disabled:l},ae=b&&!H&&Boolean(d),de=w.space.xs,ce=q["min-height"]-2*de-2*K.borderWidth,ue={color:K.badgeInk,size:q["badge-icon"],disabled:l},be=P?_jsx(Spinner,{variant:"circular",size:"sm",color:ae?K.badgeInk:K.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,ae?ue:le,u)}):null,ge=_jsxs(View,{style:U.contentRow,children:[ae?_jsx(View,{testID:"button-icon-badge",style:[U.iconLeft,U.iconBadge,{width:ce,height:ce,borderRadius:ce/2,backgroundColor:K.badgeFill}],children:be}):be?_jsx(View,{style:U.iconLeft,children:be}):null,_jsxs(View,{onLayout:re,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[U.label,{color:K.textColor,fontSize:q.text,lineHeight:Math.round(q.text*w.leading.body)},x],children:o}),H?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[U.linkUnderline,{backgroundColor:K.textColor,transform:[{translateX:Z.interpolate({inputRange:[0,1],outputRange:[-$/2,0]})},{scaleX:Z.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:U.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,le,u)}):null]}),pe=H?null===te?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(te)):touchSlopFor(q["min-height"]),me={top:pe,bottom:pe,left:H?LINK_HIT_SLOP:0,right:H?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[D.style,a?U.fullWidth:null,h],children:_jsx(Pressable,{ref:e,onPress:e=>{if(!E||N.current||M.isFlick(e))return;D.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t);const o=S?.(e);return o instanceof Promise?(N.current=!0,B(!0),o.then(settlePending,e=>{throw settlePending(),e})):void 0},onPressIn:e=>{M.onPressIn(e),D.pressIn(),H&&E&&(Z.stopAnimation(),Z.setValue(0),Animated.timing(Z,{toValue:1,duration:w.motion.duration.slower,easing:Easing.bezier(...w.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{D.pressOut()},disabled:!E,hitSlop:me,...hitSlopMarker(me),accessibilityRole:"button",accessibilityLabel:se,accessibilityHint:C,accessibilityState:z,...ariaFromState(z),testID:I,onLayout:e=>{Q.onLayout(e),H&&oe(e.nativeEvent.layout.height)},style:({pressed:e})=>[U.base,{paddingHorizontal:H?0:q["padding-x"],paddingVertical:H?0:ae?de:q["padding-y"],paddingLeft:ae?de:void 0,minHeight:H?void 0:q["min-height"],borderRadius:J,...smoothCorners,backgroundColor:X||Q.active?"transparent":K.backgroundColor,borderWidth:K.borderWidth,borderColor:Q.active?"transparent":K.borderColor,opacity:P?.55:1,overflow:Q.active||H?"visible":"hidden"},e&&ie&&!Q.active?{backgroundColor:w.colors["surface-pressed"]}:null,a?U.fullWidth:null,f],...k,"aria-disabled":!E,"aria-busy":P,children:({pressed:e})=>_jsxs(_Fragment,{children:[Q.active&&Q.size?_jsx(SquircleFill,{width:Q.size.width,height:Q.size.height,radius:J,fill:e&&ie?w.colors["surface-pressed"]:K.backgroundColor,stroke:K.borderColor,strokeWidth:K.borderWidth}):null,X?_jsx(Gradient,{gradient:X,style:[StyleSheet.absoluteFill,{borderRadius:J,...smoothCorners}]}):null,e&&ne?Q.active&&Q.size?_jsx(SquircleFill,{width:Q.size.width,height:Q.size.height,radius:J,fill:K.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[U.pressedOverlay,{borderRadius:J,backgroundColor:K.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,ge]})})})}const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:e.size.border},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
1
+ "use strict";import{useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useMobileUiText}from"../../text/index.js";import{BUTTON_TEXT}from"../../text/phone/button.g.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const BUTTON_VARIANTS=["solid","soft","outline","ghost","link","glass"];export const BUTTON_TONES=["primary","success","warning","danger","info","neutral"];export function isButtonVariant(e){return BUTTON_VARIANTS.some(t=>t===e)}export function isButtonTone(e){return BUTTON_TONES.some(t=>t===e)}function Button({ref:e,...t}){const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:h,wrapperStyle:f,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:T,accessibilityHint:C,accessibilityState:_,testID:I,onLayout:v,labels:j,...k}=t;assertValidValue("Button","variant",t.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",t.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",t.size,["xs","sm","md","lg","xl"]);const w=useTheme(),F=w.settings.components.button,V=r??F?.defaultVariant??"solid",O=i??F?.defaultSize??"md",L=useMobileUiText("button",BUTTON_TEXT),A=useMemo(()=>({...L,...j}),[L,j]),[R,B]=useState(!1),N=useRef(!1),P=n||R,W=!l&&!P,E={..._,disabled:!W,busy:P},z="link"===V,H=y??F?.defaultPressAnimation??(!z&&"scale"),D=usePressAnimation({preset:H||"scale",enabled:!1!==H&&W}),M=useFlickGuard(),U=useMemo(()=>buildStyles(w),[w]),q=useMemo(()=>resolveButtonSize(w,O),[w,O]),G=useMemo(()=>toneFor(w,s),[w,s]),K=useMemo(()=>variantFor(w,V,G,l),[w,V,G,l]),X=useMemo(()=>!m||l||"solid"!==V?null:"string"==typeof m?w.settings.gradients[m]??null:m,[m,l,V,w.settings.gradients]),Y=StyleSheet.flatten(h)?.borderRadius,J=z?0:"number"==typeof Y?Y:p?w.radius.pill:q.radius,Q=useSquircle(!X&&"link"!==V,J,v),Z=useRef(createAnimatedValue(0)).current,[$,ee]=useState(0),[te,oe]=useState(null),re=z?e=>ee(e.nativeEvent.layout.width):void 0,settlePending=()=>{N.current=!1,B(!1)},se=T??o,ie="outline"===V||"ghost"===V,ne=!ie&&!z,le={color:K.textColor,size:q.icon,disabled:l},ae=b&&!z&&Boolean(d),de=w.space.xs,ce=q["min-height"]-2*de-2*K.borderWidth,ue={color:K.badgeInk,size:q["badge-icon"],disabled:l},be=P?_jsx(Spinner,{variant:"circular",size:"sm",color:ae?K.badgeInk:K.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,ae?ue:le,u)}):null,ge=_jsxs(View,{style:U.contentRow,children:[ae?_jsx(View,{testID:"button-icon-badge",style:[U.iconLeft,U.iconBadge,{width:ce,height:ce,borderRadius:ce/2,backgroundColor:K.badgeFill}],children:be}):be?_jsx(View,{style:U.iconLeft,children:be}):null,_jsxs(View,{onLayout:re,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[U.label,{color:K.textColor,fontSize:q.text,lineHeight:Math.round(q.text*w.leading.body)},x],children:o}),z?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[U.linkUnderline,{backgroundColor:K.textColor,transform:[{translateX:Z.interpolate({inputRange:[0,1],outputRange:[-$/2,0]})},{scaleX:Z.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:U.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,le,u)}):null]}),pe=z?null===te?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(te)):touchSlopFor(q["min-height"]),me={top:pe,bottom:pe,left:z?LINK_HIT_SLOP:0,right:z?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[D.style,a?U.fullWidth:null,f],children:_jsx(Pressable,{ref:e,onPress:e=>{if(!W||N.current||M.isFlick(e))return;D.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t);const o=S?.(e);return o instanceof Promise?(N.current=!0,B(!0),o.then(settlePending,e=>{throw settlePending(),e})):void 0},onPressIn:e=>{M.onPressIn(e),D.pressIn(),z&&W&&(Z.stopAnimation(),Z.setValue(0),Animated.timing(Z,{toValue:1,duration:w.motion.duration.slower,easing:Easing.bezier(...w.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{D.pressOut()},disabled:!W,hitSlop:me,...hitSlopMarker(me),accessibilityRole:"button",accessibilityLabel:se,accessibilityHint:C,accessibilityState:E,...ariaFromState(E),testID:I,onLayout:e=>{Q.onLayout(e),z&&oe(e.nativeEvent.layout.height)},style:({pressed:e})=>[U.base,{paddingHorizontal:z?0:q["padding-x"],paddingVertical:z?0:ae?de:q["padding-y"],paddingLeft:ae?de:void 0,minHeight:z?void 0:q["min-height"],borderRadius:J,...smoothCorners,backgroundColor:X||Q.active?"transparent":K.backgroundColor,borderWidth:K.borderWidth,borderColor:Q.active?"transparent":K.borderColor,opacity:P?.55:1,overflow:Q.active||z?"visible":"hidden"},e&&ie&&!Q.active?{backgroundColor:w.colors["surface-pressed"]}:null,a?U.fullWidth:null,h],...k,"aria-disabled":!W,"aria-busy":P,children:({pressed:e})=>_jsxs(_Fragment,{children:[Q.active&&Q.size?_jsx(SquircleFill,{width:Q.size.width,height:Q.size.height,radius:J,fill:e&&ie?w.colors["surface-pressed"]:K.backgroundColor,stroke:K.borderColor,strokeWidth:K.borderWidth,hostBorderWidth:K.borderWidth}):null,X?_jsx(Gradient,{gradient:X,style:[StyleSheet.absoluteFill,{borderRadius:J,...smoothCorners}]}):null,e&&ne?Q.active&&Q.size?_jsx(SquircleFill,{width:Q.size.width,height:Q.size.height,radius:J,fill:K.pressedTint,hostBorderWidth:K.borderWidth,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[U.pressedOverlay,{borderRadius:J,backgroundColor:K.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,ge]})})})}const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:e.size.border},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
@@ -1 +1 @@
1
- "use strict";import React,{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{useMobileUiText}from"../../text/index.js";import{CARD_TEXT}from"../../text/phone/card.g.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.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{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 OUTER_LAYOUT_KEYS=new Set(["flex","flexGrow","flexShrink","flexBasis","alignSelf","width","height","minWidth","maxWidth","minHeight","maxHeight","position","top","right","bottom","left","start","end","zIndex"]),splitOuterLayout=e=>{const t={},i={};for(const[s,o]of Object.entries(StyleSheet.flatten(e)??{}))(OUTER_LAYOUT_KEYS.has(s)||s.startsWith("margin")?t:i)[s]=o;return{outer:t,inner:i}},flexStyleOf=e=>void 0===e?[]:[{flex:e}],BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},CardRoot=React.memo(function CardRoot({ref:e,...t}){const{children:i,variant:s,elevation:o="card",radius:r,padding:l,interactive:a=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:f,defaultCollapsed:x=!1,onCollapsedChange:y,collapsedSummary:S,onRemove:j,separatorHeight:C=StyleSheet.hairlineWidth,footer:v,imageSource:_,imageHeight:w=160,imageAspectRatio:R,imageOverlay:A,loading:T=!1,gradient:V,onPress:F,haptic:k,contextMenu:B,accessibilityLabel:O,accessibilityHint:I,accessibilityRole:H,flex:L,style:P,headerStyle:z,bodyStyle:M,footerStyle:E,testID:q,labels:W,onLayout:D,...U}=t;assertValidValue("Card","variant",t.variant,["elevated","outline","filled","flat"]),assertValidValue("Card","radius",t.radius,["sm","md","lg","xl","pill"]),assertValidValue("Card","padding",t.padding,["none","sm","md","lg","xl"]),assertValidValue("Card","titleFont",t.titleFont,["sans","serif"]),assertValidValue("Card","pressAnimation",t.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const N=useTheme(),G=N.settings.components.card,K=s??G?.defaultVariant??"elevated",Y=r??G?.defaultRadius??"lg",X=l??G?.defaultPadding??"md",$=m??G?.defaultTitleFont??"sans",J=useMobileUiText("card",CARD_TEXT),Q=useMemo(()=>({...J,...W}),[J,W]),Z=a||"function"==typeof F,ee=useContextMenu(B,{haptic:k||!1,testID:q,accessibilityActions:U.accessibilityActions,onAccessibilityAction:U.onAccessibilityAction}),te=useMemo(()=>mergeRefs(e,ee.hostRef),[e,ee.hostRef]),ie=Z||ee.enabled,{style:se,pressIn:oe,pressOut:re}=usePressAnimation({preset:n||"scale",enabled:ie&&!1!==n}),le=stylesFor(N),ae=Boolean(_),ne=N.space[paddingMap[X]],de=useMemo(()=>V?"string"==typeof V?N.settings.gradients[V]??null:V:null,[V,N.settings.gradients]),ce="flat"===K,ue=ce?N.radius.none:N.radius[Y],me=resolveBackground(N,d),[he,pe]=useControllableState({value:f,defaultValue:x,onChange:y}),ge=b&&he,be=hasBuiltInHeaderContent(t),fe=Boolean(c)||be,xe=useSquircle(!ae&&!de&&!ce,ue,D),ye=StyleSheet.flatten(P)??{},Se="string"==typeof ye.backgroundColor?ye.backgroundColor:void 0,je="string"==typeof ye.borderColor?ye.borderColor:void 0,Ce=Se??me??("filled"===K?N.colors["bg-subtle"]:N.colors.surface),ve="outline"===K?N.size.border:0,we=je??N.colors.border,Re="none"===o?void 0:N.shadow[o],Ae="elevated"===K&&supportsBoxShadow()&&Re?toBoxShadow(Re):void 0,Te=xe.active&&"elevated"===K&&!Ae,Ve=xe.active&&!Te?{backgroundColor:"transparent",borderColor:"transparent"}:null,Fe=useMemo(()=>{const e={borderRadius:Te&&xe.size?squircleHostRadius(xe.size.width,xe.size.height,ue):ue,...smoothCorners,padding:ae||xe.active?N.space.none:ne,overflow:xe.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:me??N.colors.surface,borderBottomWidth:C,borderBottomColor:N.colors.border};case"outline":return{...e,backgroundColor:xe.active?"transparent":me??N.colors.surface,borderWidth:N.size.border,borderColor:xe.active?"transparent":N.colors.border};case"filled":return{...e,backgroundColor:xe.active?"transparent":me??N.colors["bg-subtle"]};default:return{...e,backgroundColor:me??N.colors.surface,...Ae?{boxShadow:Ae}:Re}}},[N,K,Re,ue,ae,ne,xe.active,xe.size,Ae,Te,me,C]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:w},borderTopLeftRadius:ue,borderTopRightRadius:ue,borderBottomLeftRadius:N.radius.none,borderBottomRightRadius:N.radius.none,...smoothCorners}),[N,ue,R,w]),Be=u??"",Oe=_jsxs(_Fragment,{children:[_jsxs(View,{style:le.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(N,$),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:le.lead,children:h}):null,ge&&S?_jsx(Text,{variant:"caption",style:le.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:k}):p?_jsx(View,{style:le.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:ge?"chevron-down":"chevron-up",label:`${ge?Q.show:Q.hide} ${Be}`.trim(),expanded:!ge,onPress:()=>pe(!ge),haptic:k}):null,j?_jsx(CardIconAction,{icon:"trash",label:Q.remove,onPress:j,color:N.colors["danger-text"],haptic:k}):null]}),Ie=_jsxs(_Fragment,{children:[fe?_jsx(View,{style:[le.header,!c&&le.headerRow,ge&&le.headerFolded,z],children:c??Oe}):null,ge?null:_jsx(View,{style:[fe||v?le.body:null,M],children:i}),v&&!ge?_jsx(View,{style:[le.footer,E],children:v}):null]}),He=_?_jsxs(_Fragment,{children:[_jsxs(View,{style:le.imageWrapper,children:[_jsx(Image,{source:_,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:le.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:ne},children:Ie})]}):Ie,Le=de?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:de,style:StyleSheet.absoluteFill}),He]}):xe.active&&xe.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:xe.size.width,height:xe.size.height,radius:ue,fill:Ce,stroke:ve?we:void 0,strokeWidth:ve}),_jsx(View,{style:[le.squircleClip,{padding:ne,borderRadius:xe.size?squircleHostRadius(xe.size.width,xe.size.height,ue):ue}],children:He})]}):He,{outer:Pe,inner:ze}=splitOuterLayout(P);let Me;if(ie){const handlePress=e=>{Z&&(k&&triggerHaptic(k),F?.(e))};Me=_jsx(Animated.View,{style:[se,...flexStyleOf(L),Pe],children:_jsx(Pressable,{ref:te,onPress:handlePress,onPressIn:oe,onPressOut:re,accessibilityRole:H??(Z?"button":void 0),accessibilityLabel:O,accessibilityHint:I,testID:q,onLayout:xe.onLayout,style:[Fe,ze,Ve,le.pressFill],...U,...ee.hostProps,children:Le})})}else Me=_jsx(View,{ref:e,accessibilityLabel:O,accessibilityHint:I,accessibilityRole:H,testID:q,onLayout:xe.onLayout,style:[Fe,...flexStyleOf(L),P,Ve],...U,children:Le});return T?_jsx(CardSkeleton,{...t}):ee.enabled?_jsxs(_Fragment,{children:[Me,ee.renderSurface(_jsx(View,{style:[Fe,P,Ve,le.preview],children:Le}))]}):Me}),CardSkeleton=({variant:e,elevation:t,radius:i,padding:s,bg:o,header:r,footer:l,imageSource:a,imageHeight:n=160,imageAspectRatio:d,headerStyle:c,bodyStyle:u,footerStyle:m,flex:h,style:p,labels:g,...b})=>{const f=useTheme(),x=f.settings.components.card,y=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",j=s??x?.defaultPadding??"md",C={...useMobileUiText("card",CARD_TEXT),...g},v=paddingMap[j],_=f.space[v],w="flat"===y?f.radius.none:f.radius[S],R=void 0!==r||hasBuiltInHeaderContent(b),A=resolveBackground(f,o)??f.colors.surface,T="outline"===y?1:0,V="outline"===y?f.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:w,...smoothCorners,borderWidth:T,borderColor:V,overflow:"hidden"},...flexStyleOf(h),p],accessibilityRole:"progressbar",accessibilityLabel:C.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==a?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:_,paddingBottom:f.space.sm},c],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:_},u],children:_jsx(SkeletonText,{lines:3,fontSize:f.text.base.size,lastLineWidth:"55%"})}),void 0!==l?_jsx(View,{style:[{padding:_,paddingTop:f.space.sm,flexDirection:"row"},m],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton";const Card=Object.assign(CardRoot,{Skeleton:CardSkeleton});Card.displayName="Card";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:s,color:o,haptic:r})=>{const l=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===s?void 0:{expanded:s},"aria-expanded":s,onPress:()=>{r&&triggerHaptic(r),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:o??l.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 isOneOf(BACKGROUND_TOKENS,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:{overflow:"hidden",...smoothCorners},pressFill:{flexGrow:1},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,{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{useMobileUiText}from"../../text/index.js";import{CARD_TEXT}from"../../text/phone/card.g.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{isOneOf}from"../../utils/guards.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{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 OUTER_LAYOUT_KEYS=new Set(["flex","flexGrow","flexShrink","flexBasis","alignSelf","width","height","minWidth","maxWidth","minHeight","maxHeight","position","top","right","bottom","left","start","end","zIndex"]),splitOuterLayout=e=>{const t={},i={};for(const[s,o]of Object.entries(StyleSheet.flatten(e)??{}))(OUTER_LAYOUT_KEYS.has(s)||s.startsWith("margin")?t:i)[s]=o;return{outer:t,inner:i}},flexStyleOf=e=>void 0===e?[]:[{flex:e}],BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"],paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},CardRoot=React.memo(function CardRoot({ref:e,...t}){const{children:i,variant:s,elevation:o="card",radius:r,padding:l,interactive:a=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:f,defaultCollapsed:x=!1,onCollapsedChange:y,collapsedSummary:S,onRemove:j,separatorHeight:C=StyleSheet.hairlineWidth,footer:v,imageSource:_,imageHeight:w=160,imageAspectRatio:R,imageOverlay:A,loading:T=!1,gradient:V,onPress:F,haptic:k,contextMenu:B,accessibilityLabel:O,accessibilityHint:I,accessibilityRole:H,flex:L,style:P,headerStyle:z,bodyStyle:M,footerStyle:E,testID:W,labels:q,onLayout:D,...U}=t;assertValidValue("Card","variant",t.variant,["elevated","outline","filled","flat"]),assertValidValue("Card","radius",t.radius,["sm","md","lg","xl","pill"]),assertValidValue("Card","padding",t.padding,["none","sm","md","lg","xl"]),assertValidValue("Card","titleFont",t.titleFont,["sans","serif"]),assertValidValue("Card","pressAnimation",t.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const N=useTheme(),G=N.settings.components.card,K=s??G?.defaultVariant??"elevated",Y=r??G?.defaultRadius??"lg",X=l??G?.defaultPadding??"md",$=m??G?.defaultTitleFont??"sans",J=useMobileUiText("card",CARD_TEXT),Q=useMemo(()=>({...J,...q}),[J,q]),Z=a||"function"==typeof F,ee=useContextMenu(B,{haptic:k||!1,testID:W,accessibilityActions:U.accessibilityActions,onAccessibilityAction:U.onAccessibilityAction}),te=useMemo(()=>mergeRefs(e,ee.hostRef),[e,ee.hostRef]),ie=Z||ee.enabled,{style:se,pressIn:oe,pressOut:re}=usePressAnimation({preset:n||"scale",enabled:ie&&!1!==n}),le=stylesFor(N),ae=Boolean(_),ne=N.space[paddingMap[X]],de=useMemo(()=>V?"string"==typeof V?N.settings.gradients[V]??null:V:null,[V,N.settings.gradients]),ce="flat"===K,ue=ce?N.radius.none:N.radius[Y],me=resolveBackground(N,d),[he,pe]=useControllableState({value:f,defaultValue:x,onChange:y}),ge=b&&he,be=hasBuiltInHeaderContent(t),fe=Boolean(c)||be,xe=useSquircle(!ae&&!de&&!ce,ue,D),ye=StyleSheet.flatten(P)??{},Se="string"==typeof ye.backgroundColor?ye.backgroundColor:void 0,je="string"==typeof ye.borderColor?ye.borderColor:void 0,Ce=Se??me??("filled"===K?N.colors["bg-subtle"]:N.colors.surface),ve="outline"===K?N.size.border:0,we=je??N.colors.border,Re="none"===o?void 0:N.shadow[o],Ae="elevated"===K&&supportsBoxShadow()&&Re?toBoxShadow(Re):void 0,Te=xe.active&&"elevated"===K&&!Ae,Ve=xe.active&&!Te?{backgroundColor:"transparent",borderColor:"transparent"}:null,Fe=useMemo(()=>{const e={borderRadius:Te&&xe.size?squircleHostRadius(xe.size.width,xe.size.height,ue):ue,...smoothCorners,padding:ae||xe.active?N.space.none:ne,overflow:xe.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:me??N.colors.surface,borderBottomWidth:C,borderBottomColor:N.colors.border};case"outline":return{...e,backgroundColor:xe.active?"transparent":me??N.colors.surface,borderWidth:N.size.border,borderColor:xe.active?"transparent":N.colors.border};case"filled":return{...e,backgroundColor:xe.active?"transparent":me??N.colors["bg-subtle"]};default:return{...e,backgroundColor:me??N.colors.surface,...Ae?{boxShadow:Ae}:Re}}},[N,K,Re,ue,ae,ne,xe.active,xe.size,Ae,Te,me,C]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:w},borderTopLeftRadius:ue,borderTopRightRadius:ue,borderBottomLeftRadius:N.radius.none,borderBottomRightRadius:N.radius.none,...smoothCorners}),[N,ue,R,w]),Be=u??"",Oe=_jsxs(_Fragment,{children:[_jsxs(View,{style:le.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(N,$),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:le.lead,children:h}):null,ge&&S?_jsx(Text,{variant:"caption",style:le.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:k}):p?_jsx(View,{style:le.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:ge?"chevron-down":"chevron-up",label:`${ge?Q.show:Q.hide} ${Be}`.trim(),expanded:!ge,onPress:()=>pe(!ge),haptic:k}):null,j?_jsx(CardIconAction,{icon:"trash",label:Q.remove,onPress:j,color:N.colors["danger-text"],haptic:k}):null]}),Ie=_jsxs(_Fragment,{children:[fe?_jsx(View,{style:[le.header,!c&&le.headerRow,ge&&le.headerFolded,z],children:c??Oe}):null,ge?null:_jsx(View,{style:[fe||v?le.body:null,M],children:i}),v&&!ge?_jsx(View,{style:[le.footer,E],children:v}):null]}),He=_?_jsxs(_Fragment,{children:[_jsxs(View,{style:le.imageWrapper,children:[_jsx(Image,{source:_,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:le.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:ne},children:Ie})]}):Ie,Le=de?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:de,style:StyleSheet.absoluteFill}),He]}):xe.active&&xe.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:xe.size.width,height:xe.size.height,radius:ue,fill:Ce,stroke:ve?we:void 0,strokeWidth:ve,hostBorderWidth:ve}),_jsx(View,{style:[le.squircleClip,{padding:ne,borderRadius:xe.size?squircleHostRadius(xe.size.width,xe.size.height,ue):ue}],children:He})]}):He,{outer:Pe,inner:ze}=splitOuterLayout(P);let Me;if(ie){const handlePress=e=>{Z&&(k&&triggerHaptic(k),F?.(e))};Me=_jsx(Animated.View,{style:[se,...flexStyleOf(L),Pe],children:_jsx(Pressable,{ref:te,onPress:handlePress,onPressIn:oe,onPressOut:re,accessibilityRole:H??(Z?"button":void 0),accessibilityLabel:O,accessibilityHint:I,testID:W,onLayout:xe.onLayout,style:[Fe,ze,Ve,le.pressFill],...U,...ee.hostProps,children:Le})})}else Me=_jsx(View,{ref:e,accessibilityLabel:O,accessibilityHint:I,accessibilityRole:H,testID:W,onLayout:xe.onLayout,style:[Fe,...flexStyleOf(L),P,Ve],...U,children:Le});return T?_jsx(CardSkeleton,{...t}):ee.enabled?_jsxs(_Fragment,{children:[Me,ee.renderSurface(_jsx(View,{style:[Fe,P,Ve,le.preview],children:Le}))]}):Me}),CardSkeleton=({variant:e,elevation:t,radius:i,padding:s,bg:o,header:r,footer:l,imageSource:a,imageHeight:n=160,imageAspectRatio:d,headerStyle:c,bodyStyle:u,footerStyle:m,flex:h,style:p,labels:g,...b})=>{const f=useTheme(),x=f.settings.components.card,y=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",j=s??x?.defaultPadding??"md",C={...useMobileUiText("card",CARD_TEXT),...g},v=paddingMap[j],_=f.space[v],w="flat"===y?f.radius.none:f.radius[S],R=void 0!==r||hasBuiltInHeaderContent(b),A=resolveBackground(f,o)??f.colors.surface,T="outline"===y?1:0,V="outline"===y?f.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:w,...smoothCorners,borderWidth:T,borderColor:V,overflow:"hidden"},...flexStyleOf(h),p],accessibilityRole:"progressbar",accessibilityLabel:C.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==a?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:_,paddingBottom:f.space.sm},c],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:_},u],children:_jsx(SkeletonText,{lines:3,fontSize:f.text.base.size,lastLineWidth:"55%"})}),void 0!==l?_jsx(View,{style:[{padding:_,paddingTop:f.space.sm,flexDirection:"row"},m],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton";const Card=Object.assign(CardRoot,{Skeleton:CardSkeleton});Card.displayName="Card";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:s,color:o,haptic:r})=>{const l=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===s?void 0:{expanded:s},"aria-expanded":s,onPress:()=>{r&&triggerHaptic(r),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:o??l.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 isOneOf(BACKGROUND_TOKENS,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:{overflow:"hidden",...smoothCorners},pressFill:{flexGrow:1},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{useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fillText,useMobileUiText}from"../../text/index.js";import{CHIP_TEXT}from"../../text/phone/chip.g.js";import{resolveChipSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{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";const toneFor=(e,s)=>{switch(s){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;function ChipRoot({ref:e,...s}){const{label:t,count:r,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:x,countStyle:f,closeButtonStyle:S,closeIconStyle:C,labels:k,removeTestID:j,testID:I}=s;assertValidValue("Chip","variant",s.variant,["solid","soft","outline"]),assertValidValue("Chip","tone",s.tone,["primary","neutral","success","warning","danger","info"]),assertValidValue("Chip","size",s.size,["sm","md"]),assertValidValue("Chip","selectionMode",s.selectionMode,["single","multiple","radio"]);const v=useTheme(),T=useMobileUiText("chip",CHIP_TEXT),w=useMemo(()=>({...T,...k}),[T,k]),_=!!l&&!u,V="radio"===i,z=!!l&&(!u||V),M=hasChipCount(r),{style:O,pressIn:B,pressOut:P}=usePressAnimation({enabled:_}),L=useMemo(()=>toneFor(v,p),[v,p]),H=useMemo(()=>resolveChipSize(v,m),[v,m]),R=Math.max(0,Math.ceil((44-H["min-height"])/2)),A=V?{top:R,bottom:R}:void 0,D="solid"===d,F="soft"===d,E=(()=>{if(F){const e=o?L.selectedOn:L.on;return tintOf(e,o?.24:.14,o?L.selectedBg:L.base)}return o?D?L.selectedBg:"transparent":D?L.base:"transparent"})(),U=F?"transparent":o?L.selectedBorder:D?"transparent":L.border,N=u?v.colors["text-disabled"]:o?F?v.colors["text-body"]:L.selectedInk:L.ink,X=D||F?0:v.size.border,handlePress=()=>{if(!_)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),l?.()},Y=b??(M?`${t}, ${r}`:t),$=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:H.gap},accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(a,{color:N,size:H.icon,disabled:u},c)}):null,_jsx(Text,{variant:"label",weight:"medium",numberOfLines:1,style:[styles.label,{color:N,fontSize:H.text,lineHeight:Math.round(H.text*v.leading.body)},x],children:t??" "}),M?_jsx(Text,{variant:"caption",numberOfLines:1,style:[styles.count,{color:N,fontSize:Math.min(v.text.xs.size,H.text),marginLeft:v.space.xs},f],children:r}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==y&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:fillText(w.removeText,{content:t}),accessibilityState:{disabled:u},"aria-disabled":u,testID:j,hitSlop:6,...hitSlopMarker(6),style:({pressed:e})=>[styles.close,{width:H["close-size"],height:H["close-size"],borderRadius:H["close-size"]/2,...smoothCorners,marginLeft:H.gap,backgroundColor:e?v.colors["surface-pressed"]:v.colors["surface-hover"]},S],children:_jsx(Text,{variant:"label",weight:"bold",maxFontSizeMultiplier:1,style:[{color:N,fontSize:H["close-text"],lineHeight:H["close-text"]+2},C],children:"×"})}):null]}),W={paddingHorizontal:H["padding-x"],paddingVertical:H["padding-y"],minHeight:H["min-height"],borderRadius:v.radius.pill,...smoothCorners,overflow:"hidden",backgroundColor:E,borderWidth:X,borderColor:U,opacity:u?.55:1};let q;return q=z?_jsx(Animated.View,{style:[O,{alignSelf:"flex-start",borderRadius:v.radius.pill,...smoothCorners,overflow:"hidden"}],children:_jsx(Pressable,{ref:e,onPress:handlePress,onPressIn:B,onPressOut:P,disabled:!_,accessibilityRole:V?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:Y,accessibilityState:V||"multiple"===i?{checked:o,disabled:u}:{selected:o,disabled:u},"aria-checked":V||"multiple"===i?o:void 0,"aria-selected":V||"multiple"===i?void 0:o,"aria-disabled":u,hitSlop:A,...A?hitSlopMarker(A):{},android_ripple:{color:v.colors["surface-pressed"],borderless:!1},testID:I,style:({pressed:e})=>[styles.base,W,e&&"outline"===d?{backgroundColor:v.colors["surface-pressed"]}:null,g],children:$})}):_jsx(View,{ref:e,style:[styles.base,W,g],accessible:!0,accessibilityRole:"text",accessibilityLabel:Y,accessibilityState:{selected:o,disabled:u},"aria-selected":o,"aria-disabled":u,testID:I,children:$}),h?_jsx(ChipSkeleton,{...s}):q}const ChipSkeleton=({label:e,count:s,size:t="md",leftIcon:r,onRemove:o,style:i})=>{const l=useTheme(),n=resolveChipSize(l,t),a=Math.max(40,Math.min(120,7*(e??"").length)),c=n["min-height"],d=c/2,p=a+2*n["padding-x"]+(hasChipCount(s)?n.gap/2+7*String(s).length:0)+(void 0!==r?n.gap+14:0)+(void 0!==o?n.gap+n["close-size"]:0);return _jsx(Skeleton,{width:p,height:c,radius:d,style:[{alignSelf:"flex-start"},i]})};ChipSkeleton.displayName="ChipSkeleton";const Chip=Object.assign(ChipRoot,{Skeleton:ChipSkeleton});Chip.displayName="Chip";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{useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fillText,useMobileUiText}from"../../text/index.js";import{CHIP_TEXT}from"../../text/phone/chip.g.js";import{resolveChipSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{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";const toneFor=(e,s)=>{switch(s){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;function ChipRoot({ref:e,...s}){const{label:t,count:r,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:x,countStyle:f,closeButtonStyle:S,closeIconStyle:C,labels:k,removeTestID:j,testID:I}=s;assertValidValue("Chip","variant",s.variant,["solid","soft","outline"]),assertValidValue("Chip","tone",s.tone,["primary","neutral","success","warning","danger","info"]),assertValidValue("Chip","size",s.size,["sm","md"]),assertValidValue("Chip","selectionMode",s.selectionMode,["single","multiple","radio"]);const v=useTheme(),T=useMobileUiText("chip",CHIP_TEXT),w=useMemo(()=>({...T,...k}),[T,k]),_=!!l&&!u,V="radio"===i,z=!!l&&(!u||V),M=hasChipCount(r),{style:O,pressIn:B,pressOut:P}=usePressAnimation({enabled:_}),L=useMemo(()=>toneFor(v,p),[v,p]),H=useMemo(()=>resolveChipSize(v,m),[v,m]),R=Math.max(0,Math.ceil((44-H["min-height"])/2)),A=V?{top:R,bottom:R}:void 0,D="solid"===d,F="soft"===d,E=(()=>{if(F){const e=o?L.selectedOn:L.on;return tintOf(e,o?.24:.14,o?L.selectedBg:L.base)}return o?L.selectedBg:D?L.base:"transparent"})(),U=F?"transparent":o?D?L.selectedBorder:tintOf(L.selectedBorder,.3,L.selectedBorder):D?"transparent":L.border,N=u?v.colors["text-disabled"]:o?F?v.colors["text-body"]:L.selectedInk:L.ink,X=D||F?0:v.size.border,handlePress=()=>{if(!_)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),l?.()},Y=b??(M?`${t}, ${r}`:t),$=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:H.gap},accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(a,{color:N,size:H.icon,disabled:u},c)}):null,_jsx(Text,{variant:"label",weight:"medium",numberOfLines:1,style:[styles.label,{color:N,fontSize:H.text,lineHeight:Math.round(H.text*v.leading.body)},x],children:t??" "}),M?_jsx(Text,{variant:"caption",numberOfLines:1,style:[styles.count,{color:N,fontSize:Math.min(v.text.xs.size,H.text),marginLeft:v.space.xs},f],children:r}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==y&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:fillText(w.removeText,{content:t}),accessibilityState:{disabled:u},"aria-disabled":u,testID:j,hitSlop:6,...hitSlopMarker(6),style:({pressed:e})=>[styles.close,{width:H["close-size"],height:H["close-size"],borderRadius:H["close-size"]/2,...smoothCorners,marginLeft:H.gap,backgroundColor:e?v.colors["surface-pressed"]:v.colors["surface-hover"]},S],children:_jsx(Text,{variant:"label",weight:"bold",maxFontSizeMultiplier:1,style:[{color:N,fontSize:H["close-text"],lineHeight:H["close-text"]+2},C],children:"×"})}):null]}),W={paddingHorizontal:H["padding-x"],paddingVertical:H["padding-y"],minHeight:H["min-height"],borderRadius:v.radius.pill,...smoothCorners,overflow:"hidden",backgroundColor:E,borderWidth:X,borderColor:U,opacity:u?.55:1};let q;return q=z?_jsx(Animated.View,{style:[O,{alignSelf:"flex-start",borderRadius:v.radius.pill,...smoothCorners,overflow:"hidden"}],children:_jsx(Pressable,{ref:e,onPress:handlePress,onPressIn:B,onPressOut:P,disabled:!_,accessibilityRole:V?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:Y,accessibilityState:V||"multiple"===i?{checked:o,disabled:u}:{selected:o,disabled:u},"aria-checked":V||"multiple"===i?o:void 0,"aria-selected":V||"multiple"===i?void 0:o,"aria-disabled":u,hitSlop:A,...A?hitSlopMarker(A):{},android_ripple:{color:v.colors["surface-pressed"],borderless:!1},testID:I,style:({pressed:e})=>[styles.base,W,e&&"outline"===d?{backgroundColor:v.colors["surface-pressed"]}:null,g],children:$})}):_jsx(View,{ref:e,style:[styles.base,W,g],accessible:!0,accessibilityRole:"text",accessibilityLabel:Y,accessibilityState:{selected:o,disabled:u},"aria-selected":o,"aria-disabled":u,testID:I,children:$}),h?_jsx(ChipSkeleton,{...s}):q}const ChipSkeleton=({label:e,count:s,size:t="md",leftIcon:r,onRemove:o,style:i})=>{const l=useTheme(),n=resolveChipSize(l,t),a=Math.max(40,Math.min(120,7*(e??"").length)),c=n["min-height"],d=c/2,p=a+2*n["padding-x"]+(hasChipCount(s)?n.gap/2+7*String(s).length:0)+(void 0!==r?n.gap+14:0)+(void 0!==o?n.gap+n["close-size"]:0);return _jsx(Skeleton,{width:p,height:c,radius:d,style:[{alignSelf:"flex-start"},i]})};ChipSkeleton.displayName="ChipSkeleton";const Chip=Object.assign(ChipRoot,{Skeleton:ChipSkeleton});Chip.displayName="Chip";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{isValidElement,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,Text,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,resolveEmptyStateSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text as UiText}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const ActionButton=({action:e,variant:t})=>{const i=useTheme(),{style:r,pressIn:s,pressOut:o}=usePressAnimation({enabled:!0}),n=useMemo(()=>buildActionStyles(i),[i]),l="primary"===t,a=useSquircle(!0,i.radius.md),fillFor=e=>l?e?i.colors["primary-hover"]:i.colors.primary:e?i.colors["surface-pressed"]:"transparent";return _jsx(Animated.View,{style:r,children:_jsx(Pressable,{onPress:()=>{triggerHaptic("selection"),e.onPress()},onPressIn:s,onPressOut:o,accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityHint:e.accessibilityHint,testID:e.testID,onLayout:a.onLayout,style:({pressed:e})=>[n.button,l?n.buttonPrimary:n.buttonSecondary,e&&!a.active?l?n.buttonPrimaryPressed:n.buttonSecondaryPressed:null,a.active?n.buttonSquircleHost:null],children:({pressed:t})=>_jsxs(_Fragment,{children:[a.active&&a.size?_jsx(SquircleFill,{width:a.size.width,height:a.size.height,radius:i.radius.md,fill:fillFor(t),stroke:l?void 0:i.colors.border,strokeWidth:l?0:1}):null,_jsx(Text,{style:[n.buttonText,l?n.buttonTextPrimary:n.buttonTextSecondary],numberOfLines:1,children:e.label})]})})})};function EmptyState({ref:e,...t}){const i=useTheme(),r=Object.keys(i.components["empty-state"]);assertValidValue("EmptyState","size",t.size,r),assertValidValue("EmptyState","variant",t.variant,["block","inline"]);const{icon:s,illustration:o,title:n,description:l,action:a,secondaryAction:c,size:d,variant:u,fill:m=!1,style:y,testID:p}=t,b=i.settings.components["empty-state"],x=d??b?.defaultSize??"md",g=u??b?.defaultVariant??"block",h=r.includes(x)?x:"md",f=useMemo(()=>resolveEmptyStateSize(i,h),[i,h]),S=useMemo(()=>buildStyles(i),[i]);return"inline"===g?_jsx(View,{ref:e,accessibilityRole:"summary",testID:p,style:[S.inline,m?S.fill:null,y],children:_jsx(UiText,{variant:"caption",weight:"medium",color:"secondary",align:"center",children:n})}):_jsxs(View,{ref:e,accessibilityRole:"summary",testID:p,style:[S.root,{paddingVertical:f["padding-y"]},m?S.fill:null,y],children:[null!=o?_jsx(View,{style:{marginBottom:f["title-gap"]},children:isValidElement(o)?o:_jsx(Image,{source:o,style:{width:f["illustration-size"],height:f["illustration-size"]},resizeMode:"contain",accessibilityIgnoresInvertColors:!0})}):s?_jsx(View,{style:[S.iconCircle,{width:f.icon,height:f.icon,marginBottom:f["title-gap"],borderRadius:i.radius.pill,...smoothCorners}],children:s}):null,_jsx(Text,{style:[S.title,{fontSize:f["title-text"],...fontFor(i,"semibold")}],children:n}),l?_jsx(Text,{style:[S.description,{fontSize:f["description-text"],marginTop:f["description-gap"]}],children:l}):null,a||c?_jsxs(View,{style:S.actions,children:[a?_jsx(ActionButton,{action:a,variant:"primary"}):null,c?_jsx(ActionButton,{action:c,variant:"secondary"}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},inline:{alignItems:"center",justifyContent:"center"},fill:{flexGrow:1},iconCircle:{backgroundColor:e.colors["surface-disabled"],alignItems:"center",justifyContent:"center"},title:{color:e.colors["text-body"],textAlign:"center"},description:{color:e.colors["text-muted"],textAlign:"center",maxWidth:320,lineHeight:e.text.base.size*e.leading.body},actions:{flexDirection:"row",alignItems:"center",gap:e.space.sm,marginTop:e.space.lg}}),buildActionStyles=e=>StyleSheet.create({button:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,minHeight:42,borderRadius:e.radius.md,...smoothCorners,overflow:"hidden",alignItems:"center",justifyContent:"center",flexDirection:"row"},buttonPrimary:{backgroundColor:e.colors.primary},buttonPrimaryPressed:{backgroundColor:e.colors["primary-hover"]},buttonSecondary:{backgroundColor:"transparent",borderWidth:1,borderColor:e.colors.border},buttonSecondaryPressed:{backgroundColor:e.colors["surface-pressed"]},buttonSquircleHost:{backgroundColor:"transparent",borderColor:"transparent",overflow:"visible"},buttonText:{fontSize:e.text.base.size,...fontFor(e,"semibold")},buttonTextPrimary:{color:e.colors["on-primary"]},buttonTextSecondary:{color:e.colors["text-body"]}});export{EmptyState};export default EmptyState;
1
+ "use strict";import{isValidElement,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,Text,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,resolveEmptyStateSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text as UiText}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const ActionButton=({action:e,variant:t})=>{const i=useTheme(),{style:r,pressIn:s,pressOut:o}=usePressAnimation({enabled:!0}),n=useMemo(()=>buildActionStyles(i),[i]),l="primary"===t,a=useSquircle(!0,i.radius.md),fillFor=e=>l?e?i.colors["primary-hover"]:i.colors.primary:e?i.colors["surface-pressed"]:"transparent";return _jsx(Animated.View,{style:r,children:_jsx(Pressable,{onPress:()=>{triggerHaptic("selection"),e.onPress()},onPressIn:s,onPressOut:o,accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityHint:e.accessibilityHint,testID:e.testID,onLayout:a.onLayout,style:({pressed:e})=>[n.button,l?n.buttonPrimary:n.buttonSecondary,e&&!a.active?l?n.buttonPrimaryPressed:n.buttonSecondaryPressed:null,a.active?n.buttonSquircleHost:null],children:({pressed:t})=>_jsxs(_Fragment,{children:[a.active&&a.size?_jsx(SquircleFill,{width:a.size.width,height:a.size.height,radius:i.radius.md,fill:fillFor(t),stroke:l?void 0:i.colors.border,strokeWidth:l?0:1,hostBorderWidth:l?0:1}):null,_jsx(Text,{style:[n.buttonText,l?n.buttonTextPrimary:n.buttonTextSecondary],numberOfLines:1,children:e.label})]})})})};function EmptyState({ref:e,...t}){const i=useTheme(),r=Object.keys(i.components["empty-state"]);assertValidValue("EmptyState","size",t.size,r),assertValidValue("EmptyState","variant",t.variant,["block","inline"]);const{icon:s,illustration:o,title:n,description:l,action:a,secondaryAction:c,size:d,variant:u,fill:m=!1,style:y,testID:p}=t,b=i.settings.components["empty-state"],x=d??b?.defaultSize??"md",g=u??b?.defaultVariant??"block",h=r.includes(x)?x:"md",f=useMemo(()=>resolveEmptyStateSize(i,h),[i,h]),S=useMemo(()=>buildStyles(i),[i]);return"inline"===g?_jsx(View,{ref:e,accessibilityRole:"summary",testID:p,style:[S.inline,m?S.fill:null,y],children:_jsx(UiText,{variant:"caption",weight:"medium",color:"secondary",align:"center",children:n})}):_jsxs(View,{ref:e,accessibilityRole:"summary",testID:p,style:[S.root,{paddingVertical:f["padding-y"]},m?S.fill:null,y],children:[null!=o?_jsx(View,{style:{marginBottom:f["title-gap"]},children:isValidElement(o)?o:_jsx(Image,{source:o,style:{width:f["illustration-size"],height:f["illustration-size"]},resizeMode:"contain",accessibilityIgnoresInvertColors:!0})}):s?_jsx(View,{style:[S.iconCircle,{width:f.icon,height:f.icon,marginBottom:f["title-gap"],borderRadius:i.radius.pill,...smoothCorners}],children:s}):null,_jsx(Text,{style:[S.title,{fontSize:f["title-text"],...fontFor(i,"semibold")}],children:n}),l?_jsx(Text,{style:[S.description,{fontSize:f["description-text"],marginTop:f["description-gap"]}],children:l}):null,a||c?_jsxs(View,{style:S.actions,children:[a?_jsx(ActionButton,{action:a,variant:"primary"}):null,c?_jsx(ActionButton,{action:c,variant:"secondary"}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},inline:{alignItems:"center",justifyContent:"center"},fill:{flexGrow:1},iconCircle:{backgroundColor:e.colors["surface-disabled"],alignItems:"center",justifyContent:"center"},title:{color:e.colors["text-body"],textAlign:"center"},description:{color:e.colors["text-muted"],textAlign:"center",maxWidth:320,lineHeight:e.text.base.size*e.leading.body},actions:{flexDirection:"row",alignItems:"center",gap:e.space.sm,marginTop:e.space.lg}}),buildActionStyles=e=>StyleSheet.create({button:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,minHeight:42,borderRadius:e.radius.md,...smoothCorners,overflow:"hidden",alignItems:"center",justifyContent:"center",flexDirection:"row"},buttonPrimary:{backgroundColor:e.colors.primary},buttonPrimaryPressed:{backgroundColor:e.colors["primary-hover"]},buttonSecondary:{backgroundColor:"transparent",borderWidth:1,borderColor:e.colors.border},buttonSecondaryPressed:{backgroundColor:e.colors["surface-pressed"]},buttonSquircleHost:{backgroundColor:"transparent",borderColor:"transparent",overflow:"visible"},buttonText:{fontSize:e.text.base.size,...fontFor(e,"semibold")},buttonTextPrimary:{color:e.colors["on-primary"]},buttonTextSecondary:{color:e.colors["text-body"]}});export{EmptyState};export default EmptyState;
@@ -1 +1 @@
1
- "use strict";import{useEffect,useMemo,useRef}from"react";import{Animated,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import{useFieldErrorAnchor}from"../../hooks/useFieldErrorScroll.js";import{createAnimatedValue,fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const expandColorSides=e=>"string"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??"transparent",right:e.right??"transparent",bottom:e.bottom??"transparent",left:e.left??"transparent"},expandWidthSides=e=>"number"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0};export const pickRepresentativeBorderColor=e=>{for(const t of["bottom","top","left","right"]){const o=e[t];if(o&&"transparent"!==o)return o}return e.bottom};export const resolveFieldTextStyle=(e,t={})=>{const{disabled:o=!1}=t;return{color:o?e.colors["field-text-disabled"]:e.colors["field-text"],placeholderColor:o?e.colors["field-placeholder-disabled"]:e.colors["field-placeholder"],weightStyle:fontFor(e,"normal")}};export const RequiredMark=()=>{const e=useTheme();return _jsx(Text,{style:{color:e.colors["danger-text"]},..."web"===Platform.OS?{"aria-hidden":!0}:null,children:` ${e.settings.components.field?.requiredMarker??"*"}`})};export const RequiredPlaceholder=({text:e,color:t,fontSize:o,weightStyle:r,align:i="center",paddingTop:l,textAlign:s})=>_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{justifyContent:"top"===i?"flex-start":"center",paddingTop:l}],children:_jsxs(Text,{accessible:!1,numberOfLines:1,style:{color:t,fontSize:o,...r,includeFontPadding:!1,textAlign:s},children:[e,_jsx(RequiredMark,{})]})});export const FieldErrorGlyph=({size:e,color:t})=>{const o=useTheme().settings.icons.error??defaultIcons.error;return _jsx(_Fragment,{children:o({size:e,color:t})})};export const hasFieldText=e=>null!=e&&!1!==e&&!0!==e&&""!==e;export const fieldTextAsString=e=>"string"==typeof e?e:void 0;export const FieldLabel=({children:e,size:t="md",required:o=!1,help:r,color:i,style:l})=>{const s=useTheme(),n=resolveFieldSize(s,t),d=hasFieldText(r),a=useTextInk(l,n["label-text"],i??s.colors["field-label"]),c=_jsxs(Text,{style:[familyStyles.label,{color:i??s.colors["field-label"],fontSize:n["label-text"],...fontFor(s,"semibold"),marginBottom:d?s.space.none:n["label-gap"]},d?familyStyles.labelShrink:null,l],children:[_jsx(TextInkContext,{value:a,children:e}),o?_jsx(RequiredMark,{}):null]});return d?_jsxs(View,{style:[familyStyles.labelRow,{marginBottom:n["label-gap"]}],children:[c,_jsx(View,{style:[familyStyles.help,{marginLeft:s.space.xs}],children:"string"==typeof r||"number"==typeof r?_jsx(Text,{style:[familyStyles.helpText,{color:s.colors["text-muted"],fontSize:n["message-text"],...fontFor(s,"normal")}],children:r}):r})]}):c};export const FieldMessage=({text:e,error:t=!1,size:o="md",style:r})=>{const i=useTheme(),l=resolveFieldSize(i,o),s=t?i.colors["field-message"]:i.colors["text-muted"],n=useTextInk(r,l["message-text"],s);return hasFieldText(e)?_jsxs(View,{style:[familyStyles.messageRow,{marginTop:l["message-gap"],columnGap:i.space.xs}],accessibilityLiveRegion:t?"polite":"none",children:[t?_jsx(FieldErrorGlyph,{size:l["message-text"],color:s}):null,_jsx(Text,{style:[familyStyles.messageText,{color:s,fontSize:l["message-text"],...fontFor(i,"normal")},r],children:_jsx(TextInkContext,{value:n,children:e})})]}):null};const familyStyles=StyleSheet.create({label:{includeFontPadding:!1},labelShrink:{flexShrink:1},labelRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0,alignItems:"center",justifyContent:"center"},helpText:{includeFontPadding:!1},messageRow:{flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1}});export const resolveVariantColors=(e,t)=>{let o,r,i,l,s;"outline"===t?(o=e.colors["field-bg"],r=e.colors["field-bg-focus"],i=e.colors["field-bg-disabled"],l=e.colors["field-border"],s=e.size.border):"underline"===t?(o="transparent",r=void 0,i="transparent",l={bottom:e.colors["field-border"]},s={bottom:e.size.border}):(o=e.colors["field-bg"],r=void 0,i=e.colors["field-bg-disabled"],l="transparent",s=0);const wrapToIdleShape=e=>"string"==typeof l?e:{bottom:e},n=expandColorSides(l),d=expandColorSides(wrapToIdleShape(e.colors["field-border-focus"]));return{backgroundIdleEmpty:o,backgroundIdleFilled:o,backgroundFocused:r,backgroundError:void 0,backgroundDisabled:i,borderIdle:n,borderFocused:d,borderError:expandColorSides(wrapToIdleShape(e.colors["field-border-error"])),borderDisabled:expandColorSides(l),borderWidth:expandWidthSides(s),borderFocusedRepresentative:pickRepresentativeBorderColor(d)}};export const FieldBase=e=>{assertValidValue("FieldBase","variant",e.variant,["outline","filled","underline"]),assertValidValue("FieldBase","size",e.size,["sm","md","lg"]);const{size:t="md",variant:o,focused:r=!1,disabled:i=!1,error:l=!1,filled:s=!1,leading:n,leadingDivider:d=!1,trailing:a,slotAlign:c="center",slotLineHeight:u,topNotch:b,children:p,onPress:m,pressFeedback:g=!0,minHeight:f,maxHeight:h,width:x,height:y,paddingHorizontal:S,paddingLeft:F,paddingRight:T,paddingVertical:j,radius:v,borderTopLeftRadius:R,borderTopRightRadius:k,borderBottomLeftRadius:C,borderBottomRightRadius:w,borderWidth:_,borderTopWidth:I,borderRightWidth:V,borderBottomWidth:z,borderLeftWidth:L,gap:B,flushBottom:D=!1,style:E,testID:W,accessibilityRole:A,accessibilityLabel:q,accessibilityState:P,accessibilityHint:M}=e,H=useTheme(),G=useFieldErrorAnchor(l),N=useMemo(()=>buildStyles(),[]),O=o??H.settings.components.field?.defaultVariant??"outline",$=resolveFieldSize(H,t),J=useMemo(()=>resolveVariantColors(H,O),[H,O]),K=l?2:r?1:0,Q=useRef(createAnimatedValue(K)).current;useEffect(()=>{const e=Animated.timing(Q,{toValue:K,duration:H.motion.duration.fast,easing:Easing.bezier(...H.motion.ease["in-out"]),useNativeDriver:!1});return e.start(),()=>e.stop()},[K,Q,H.motion.duration.fast,H.motion.ease["in-out"]]);const U=[0,1,2],X=s?J.backgroundIdleFilled:J.backgroundIdleEmpty,Y=J.backgroundFocused??X,Z=J.backgroundError??X,ee=i?J.backgroundDisabled:Q.interpolate({inputRange:U,outputRange:[X,Y,Z]}),te=J.borderIdle,oe=J.borderFocused,re=J.borderError,ie={top:I,right:V,bottom:z,left:L},le={top:ie.top??_??J.borderWidth.top,right:ie.right??_??J.borderWidth.right,bottom:ie.bottom??_??J.borderWidth.bottom,left:ie.left??_??J.borderWidth.left},se="underline"===O,ne=se?H.radius.none:v?H.radius[v]:$.radius,de=se?{tl:H.radius.none,tr:H.radius.none,bl:H.radius.none,br:H.radius.none}:{tl:R??ne,tr:k??ne,bl:C??ne,br:w??ne},sideColor=e=>Q.interpolate({inputRange:U,outputRange:[te[e],oe[e],re[e]]}),sameOnEverySide=e=>e.top===e.right&&e.top===e.bottom&&e.top===e.left,ae=!se&&de.tl===de.tr&&de.tl===de.bl&&de.tl===de.br&&sameOnEverySide(le)&&sameOnEverySide(te)&&sameOnEverySide(oe)&&sameOnEverySide(re)&&sameOnEverySide(J.borderDisabled),ce=useSquircle(ae,de.tl),ue=ce.active?{borderTopColor:"transparent",borderRightColor:"transparent",borderBottomColor:"transparent",borderLeftColor:"transparent"}:i?{borderTopColor:J.borderDisabled.top,borderRightColor:J.borderDisabled.right,borderBottomColor:J.borderDisabled.bottom,borderLeftColor:J.borderDisabled.left}:{borderTopColor:sideColor("top"),borderRightColor:sideColor("right"),borderBottomColor:sideColor("bottom"),borderLeftColor:sideColor("left")},be=i?J.borderDisabled.top:sideColor("top"),pe={minHeight:y??f??$["min-height"],maxHeight:h,paddingHorizontal:S??$["padding-x"],paddingVertical:j??$["padding-y"],paddingLeft:F??S??$["padding-x"],paddingRight:T??S??$["padding-x"],backgroundColor:ce.active?"transparent":ee,columnGap:B??H.space.md,alignItems:"top"===c?"flex-start":"center",borderTopLeftRadius:de.tl,borderTopRightRadius:de.tr,borderBottomLeftRadius:de.bl,borderBottomRightRadius:de.br,borderCurve:smoothCorners.borderCurve,borderTopWidth:le.top,borderRightWidth:le.right,borderBottomWidth:le.bottom,borderLeftWidth:le.left,...ue,...void 0!==x?{width:x}:null,...void 0!==y?{height:y}:null},me=useRef(K);me.current=K,useEffect(()=>{Q.setValue(me.current)},[J,Q]);const ge=D?{marginBottom:H.space.none}:void 0,fe={disabled:i,...P},he="top"===c,xe=he?{alignSelf:"flex-start",marginTop:Math.max(0,((u??$.icon)-$.icon)/2)}:null,ye=y??f??$["min-height"],Se=(()=>{if(!b)return 0;const e=Math.min(de.tl,ye/2),t=b.left;return e<=0||t>=e?0:Math.ceil(e-Math.sqrt(e*e-(e-t)*(e-t)))})(),Fe=b&&le.top>0?_jsx(Animated.View,{pointerEvents:"none",style:{position:"absolute",top:-le.top,left:b.left-le.left,width:b.width,height:le.top+Se,backgroundColor:ee}}):null,renderInner=e=>_jsxs(_Fragment,{children:[ce.active&&ce.size?_jsx(SquircleFill,{width:ce.size.width,height:ce.size.height,radius:de.tl,fill:e&&!i?H.colors["surface-pressed"]:ee,stroke:be,strokeWidth:le.top}):null,Fe,null!=n?_jsx(View,{style:[N.slot,xe],children:n}):null,null!=n&&d?_jsx(View,{pointerEvents:"none",style:[N.divider,xe,{height:$.icon,backgroundColor:H.colors["field-border"]}]}):null,_jsx(View,{style:[N.content,he?N.contentTop:null],children:p}),null!=a?_jsx(View,{style:[N.slot,xe],children:a}):null]}),Te=_jsx(Animated.View,{ref:G,onLayout:ce.onLayout,style:[N.box,pe,m?null:ge,E],accessibilityRole:A,accessibilityLabel:q,accessibilityHint:M,accessibilityState:fe,...ariaFromState(fe),testID:W,children:renderInner(!1)});return m&&!g?_jsx(Pressable,{onPress:m,disabled:i,accessible:!1,style:ge,testID:W?`${W}-press`:void 0,children:Te}):m?_jsx(Pressable,{onPress:m,disabled:i,style:ge,accessibilityRole:A??"button",accessibilityLabel:q,accessibilityHint:M,accessibilityState:fe,...ariaFromState(fe),testID:W,children:({pressed:e})=>_jsx(Animated.View,{ref:G,onLayout:ce.onLayout,style:[N.box,pe,!e||i||ce.active?null:{backgroundColor:H.colors["surface-pressed"]},E],children:renderInner(e)})}):Te};FieldBase.displayName="FieldBase";const buildStyles=()=>StyleSheet.create({box:{flexDirection:"row",alignItems:"center",overflow:"visible"},slot:{alignItems:"center",justifyContent:"center"},divider:{width:1,alignSelf:"center"},content:{flex:1,flexDirection:"row",alignItems:"center"},contentTop:{alignItems:"flex-start"}});export default FieldBase;
1
+ "use strict";import{useEffect,useMemo,useRef}from"react";import{Animated,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import{useFieldErrorAnchor}from"../../hooks/useFieldErrorScroll.js";import{createAnimatedValue,fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const expandColorSides=e=>"string"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??"transparent",right:e.right??"transparent",bottom:e.bottom??"transparent",left:e.left??"transparent"},expandWidthSides=e=>"number"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0};export const pickRepresentativeBorderColor=e=>{for(const t of["bottom","top","left","right"]){const o=e[t];if(o&&"transparent"!==o)return o}return e.bottom};export const resolveFieldTextStyle=(e,t={})=>{const{disabled:o=!1}=t;return{color:o?e.colors["field-text-disabled"]:e.colors["field-text"],placeholderColor:o?e.colors["field-placeholder-disabled"]:e.colors["field-placeholder"],weightStyle:fontFor(e,"normal")}};export const RequiredMark=()=>{const e=useTheme(),t=!1===e.settings.components.field?.requiredMarkerSpace?"⁠":" ";return _jsx(Text,{style:{color:e.colors["danger-text"]},..."web"===Platform.OS?{"aria-hidden":!0}:null,children:`${t}${e.settings.components.field?.requiredMarker??"*"}`})};export const RequiredPlaceholder=({text:e,color:t,fontSize:o,weightStyle:r,align:i="center",paddingTop:l,textAlign:s})=>_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{justifyContent:"top"===i?"flex-start":"center",paddingTop:l}],children:_jsxs(Text,{accessible:!1,numberOfLines:1,style:{color:t,fontSize:o,...r,includeFontPadding:!1,textAlign:s},children:[e,_jsx(RequiredMark,{})]})});export const FieldErrorGlyph=({size:e,color:t})=>{const o=useTheme().settings.icons.error??defaultIcons.error;return _jsx(_Fragment,{children:o({size:e,color:t})})};export const hasFieldText=e=>null!=e&&!1!==e&&!0!==e&&""!==e;export const fieldTextAsString=e=>"string"==typeof e?e:void 0;export const FieldLabel=({children:e,size:t="md",required:o=!1,help:r,color:i,style:l})=>{const s=useTheme(),n=resolveFieldSize(s,t),d=hasFieldText(r),a=useTextInk(l,n["label-text"],i??s.colors["field-label"]),c=_jsxs(Text,{style:[familyStyles.label,{color:i??s.colors["field-label"],fontSize:n["label-text"],...fontFor(s,"semibold"),marginBottom:d?s.space.none:n["label-gap"]},d?familyStyles.labelShrink:null,l],children:[_jsx(TextInkContext,{value:a,children:e}),o?_jsx(RequiredMark,{}):null]});return d?_jsxs(View,{style:[familyStyles.labelRow,{marginBottom:n["label-gap"]}],children:[c,_jsx(View,{style:[familyStyles.help,{marginLeft:s.space.xs}],children:"string"==typeof r||"number"==typeof r?_jsx(Text,{style:[familyStyles.helpText,{color:s.colors["text-muted"],fontSize:n["message-text"],...fontFor(s,"normal")}],children:r}):r})]}):c};export const FieldMessage=({text:e,error:t=!1,size:o="md",style:r})=>{const i=useTheme(),l=resolveFieldSize(i,o),s=t?i.colors["field-message"]:i.colors["text-muted"],n=useTextInk(r,l["message-text"],s);return hasFieldText(e)?_jsxs(View,{style:[familyStyles.messageRow,{marginTop:l["message-gap"],columnGap:i.space.xs}],accessibilityLiveRegion:t?"polite":"none",children:[t?_jsx(FieldErrorGlyph,{size:l["message-text"],color:s}):null,_jsx(Text,{style:[familyStyles.messageText,{color:s,fontSize:l["message-text"],...fontFor(i,"normal")},r],children:_jsx(TextInkContext,{value:n,children:e})})]}):null};const familyStyles=StyleSheet.create({label:{includeFontPadding:!1},labelShrink:{flexShrink:1},labelRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0,alignItems:"center",justifyContent:"center"},helpText:{includeFontPadding:!1},messageRow:{flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1}});export const resolveVariantColors=(e,t)=>{let o,r,i,l,s;"outline"===t?(o=e.colors["field-bg"],r=e.colors["field-bg-focus"],i=e.colors["field-bg-disabled"],l=e.colors["field-border"],s=e.size.border):"underline"===t?(o="transparent",r=void 0,i="transparent",l={bottom:e.colors["field-border"]},s={bottom:e.size.border}):(o=e.colors["field-bg"],r=void 0,i=e.colors["field-bg-disabled"],l="transparent",s=0);const wrapToIdleShape=e=>"string"==typeof l?e:{bottom:e},n=expandColorSides(l),d=expandColorSides(wrapToIdleShape(e.colors["field-border-focus"]));return{backgroundIdleEmpty:o,backgroundIdleFilled:o,backgroundFocused:r,backgroundError:void 0,backgroundDisabled:i,borderIdle:n,borderFocused:d,borderError:expandColorSides(wrapToIdleShape(e.colors["field-border-error"])),borderDisabled:expandColorSides(l),borderWidth:expandWidthSides(s),borderFocusedRepresentative:pickRepresentativeBorderColor(d)}};export const FieldBase=e=>{assertValidValue("FieldBase","variant",e.variant,["outline","filled","underline"]),assertValidValue("FieldBase","size",e.size,["sm","md","lg"]);const{size:t="md",variant:o,focused:r=!1,disabled:i=!1,error:l=!1,filled:s=!1,leading:n,leadingDivider:d=!1,trailing:a,slotAlign:c="center",slotLineHeight:u,topNotch:b,children:p,onPress:m,pressFeedback:g=!0,minHeight:f,maxHeight:h,width:x,height:y,paddingHorizontal:S,paddingLeft:F,paddingRight:T,paddingVertical:j,radius:v,borderTopLeftRadius:R,borderTopRightRadius:k,borderBottomLeftRadius:C,borderBottomRightRadius:w,borderWidth:_,borderTopWidth:I,borderRightWidth:V,borderBottomWidth:z,borderLeftWidth:L,gap:B,flushBottom:D=!1,style:E,testID:W,accessibilityRole:q,accessibilityLabel:A,accessibilityState:M,accessibilityHint:P}=e,H=useTheme(),G=useFieldErrorAnchor(l),N=useMemo(()=>buildStyles(),[]),$=o??H.settings.components.field?.defaultVariant??"outline",O=resolveFieldSize(H,t),J=useMemo(()=>resolveVariantColors(H,$),[H,$]),K=l?2:r?1:0,Q=useRef(createAnimatedValue(K)).current;useEffect(()=>{const e=Animated.timing(Q,{toValue:K,duration:H.motion.duration.fast,easing:Easing.bezier(...H.motion.ease["in-out"]),useNativeDriver:!1});return e.start(),()=>e.stop()},[K,Q,H.motion.duration.fast,H.motion.ease["in-out"]]);const U=[0,1,2],X=s?J.backgroundIdleFilled:J.backgroundIdleEmpty,Y=J.backgroundFocused??X,Z=J.backgroundError??X,ee=i?J.backgroundDisabled:Q.interpolate({inputRange:U,outputRange:[X,Y,Z]}),te=J.borderIdle,oe=J.borderFocused,re=J.borderError,ie={top:I,right:V,bottom:z,left:L},le={top:ie.top??_??J.borderWidth.top,right:ie.right??_??J.borderWidth.right,bottom:ie.bottom??_??J.borderWidth.bottom,left:ie.left??_??J.borderWidth.left},se="underline"===$,ne=se?H.radius.none:v?H.radius[v]:O.radius,de=se?{tl:H.radius.none,tr:H.radius.none,bl:H.radius.none,br:H.radius.none}:{tl:R??ne,tr:k??ne,bl:C??ne,br:w??ne},sideColor=e=>Q.interpolate({inputRange:U,outputRange:[te[e],oe[e],re[e]]}),sameOnEverySide=e=>e.top===e.right&&e.top===e.bottom&&e.top===e.left,ae=!se&&de.tl===de.tr&&de.tl===de.bl&&de.tl===de.br&&sameOnEverySide(le)&&sameOnEverySide(te)&&sameOnEverySide(oe)&&sameOnEverySide(re)&&sameOnEverySide(J.borderDisabled),ce=useSquircle(ae,de.tl),ue=ce.active?{borderTopColor:"transparent",borderRightColor:"transparent",borderBottomColor:"transparent",borderLeftColor:"transparent"}:i?{borderTopColor:J.borderDisabled.top,borderRightColor:J.borderDisabled.right,borderBottomColor:J.borderDisabled.bottom,borderLeftColor:J.borderDisabled.left}:{borderTopColor:sideColor("top"),borderRightColor:sideColor("right"),borderBottomColor:sideColor("bottom"),borderLeftColor:sideColor("left")},be=i?J.borderDisabled.top:sideColor("top"),pe={minHeight:y??f??O["min-height"],maxHeight:h,paddingHorizontal:S??O["padding-x"],paddingVertical:j??O["padding-y"],paddingLeft:F??S??O["padding-x"],paddingRight:T??S??O["padding-x"],backgroundColor:ce.active?"transparent":ee,columnGap:B??H.space.md,alignItems:"top"===c?"flex-start":"center",borderTopLeftRadius:de.tl,borderTopRightRadius:de.tr,borderBottomLeftRadius:de.bl,borderBottomRightRadius:de.br,borderCurve:smoothCorners.borderCurve,borderTopWidth:le.top,borderRightWidth:le.right,borderBottomWidth:le.bottom,borderLeftWidth:le.left,...ue,...void 0!==x?{width:x}:null,...void 0!==y?{height:y}:null},me=useRef(K);me.current=K,useEffect(()=>{Q.setValue(me.current)},[J,Q]);const ge=D?{marginBottom:H.space.none}:void 0,fe={disabled:i,...M},he="top"===c,xe=he?{alignSelf:"flex-start",marginTop:Math.max(0,((u??O.icon)-O.icon)/2)}:null,ye=y??f??O["min-height"],Se=(()=>{if(!b)return 0;const e=Math.min(de.tl,ye/2),t=b.left;return e<=0||t>=e?0:Math.ceil(e-Math.sqrt(e*e-(e-t)*(e-t)))})(),Fe=b&&le.top>0?_jsx(Animated.View,{pointerEvents:"none",style:{position:"absolute",top:-le.top,left:b.left-le.left,width:b.width,height:le.top+Se,backgroundColor:ee}}):null,renderInner=e=>_jsxs(_Fragment,{children:[ce.active&&ce.size?_jsx(SquircleFill,{width:ce.size.width,height:ce.size.height,radius:de.tl,fill:e&&!i?H.colors["surface-pressed"]:ee,stroke:be,strokeWidth:le.top,hostBorderWidth:le.top}):null,Fe,null!=n?_jsx(View,{style:[N.slot,xe],children:n}):null,null!=n&&d?_jsx(View,{pointerEvents:"none",style:[N.divider,xe,{height:O.icon,backgroundColor:H.colors["field-border"]}]}):null,_jsx(View,{style:[N.content,he?N.contentTop:null],children:p}),null!=a?_jsx(View,{style:[N.slot,xe],children:a}):null]}),Te=_jsx(Animated.View,{ref:G,onLayout:ce.onLayout,style:[N.box,pe,m?null:ge,E],accessibilityRole:q,accessibilityLabel:A,accessibilityHint:P,accessibilityState:fe,...ariaFromState(fe),testID:W,children:renderInner(!1)});return m&&!g?_jsx(Pressable,{onPress:m,disabled:i,accessible:!1,style:ge,testID:W?`${W}-press`:void 0,children:Te}):m?_jsx(Pressable,{onPress:m,disabled:i,style:ge,accessibilityRole:q??"button",accessibilityLabel:A,accessibilityHint:P,accessibilityState:fe,...ariaFromState(fe),testID:W,children:({pressed:e})=>_jsx(Animated.View,{ref:G,onLayout:ce.onLayout,style:[N.box,pe,!e||i||ce.active?null:{backgroundColor:H.colors["surface-pressed"]},E],children:renderInner(e)})}):Te};FieldBase.displayName="FieldBase";const buildStyles=()=>StyleSheet.create({box:{flexDirection:"row",alignItems:"center",overflow:"visible"},slot:{alignItems:"center",justifyContent:"center"},divider:{width:1,alignSelf:"center"},content:{flex:1,flexDirection:"row",alignItems:"center"},contentTop:{alignItems:"flex-start"}});export default FieldBase;
@@ -1 +1 @@
1
- "use strict";import{memo,useCallback,useEffect,useMemo,useRef}from"react";import{ScrollView,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{jsx as _jsx}from"react/jsx-runtime";const FilterChipRowItem=memo(({itemKey:e,label:t,count:i,disabled:a,testID:o,selected:s,size:r,variant:l,tone:n,haptic:c,onSelect:u,onItemLayout:d})=>{const m=useCallback(()=>u(e),[u,e]),p=useCallback(t=>d(e,t.nativeEvent.layout),[d,e]);return _jsx(View,{onLayout:p,collapsable:!1,children:_jsx(Chip,{label:t,count:i,selected:s,selectionMode:"radio",disabled:a,testID:o,size:r,variant:l,tone:n,haptic:!s&&c,onPress:m})})});function FilterChipRow({ref:e,...t}){const{items:i,value:a,onChange:o,bleed:s=0,size:r,variant:l,tone:n,haptic:c,accessibilityLabel:u,style:d,contentContainerStyle:m,testID:p}=t;assertValidValue("FilterChipRow","size",t.size,["sm","md"]),assertValidValue("FilterChipRow","variant",t.variant,["solid","soft","outline"]),assertValidValue("FilterChipRow","tone",t.tone,["primary","success","warning","danger","info","neutral"]);const h=useTheme(),w=useReducedMotion(),C=useRef(null),f=useRef({viewport:0,content:0,chips:{},revealed:null}),b=useRef(a),y=useRef(o);useEffect(()=>{y.current=o},[o]);const x=useCallback((e,t)=>{const i=f.current,a=i.chips[e];if(!a||0===i.viewport||0===i.content)return;const o=a.x+a.width/2-i.viewport/2,s=Math.min(Math.max(o,0),Math.max(i.content-i.viewport,0));C.current?.scrollTo({x:s,animated:t&&!w}),i.revealed=e},[w]),v=useCallback(()=>{f.current.revealed!==b.current&&x(b.current,!1)},[x]);useEffect(()=>{b.current=a,x(a,!0)},[a,x]);const R=useCallback(e=>{f.current.viewport=e.nativeEvent.layout.width,v()},[v]),V=useCallback(e=>{f.current.content=e,v()},[v]),k=useCallback((e,t)=>{f.current.chips[e]={x:t.x,width:t.width},v()},[v]),I=useCallback(e=>{e!==b.current?y.current(e):x(e,!0)},[x]),S=useMemo(()=>[styles.row,{paddingHorizontal:s,columnGap:h.space.xs},m],[s,h.space.xs,m]);return _jsx(View,{ref:e,accessibilityRole:"radiogroup",accessibilityLabel:u,testID:p,style:[s>0?{marginHorizontal:-s}:null,d],children:_jsx(ScrollView,{ref:C,horizontal:!0,showsHorizontalScrollIndicator:!1,keyboardShouldPersistTaps:"handled",contentContainerStyle:S,onLayout:R,onContentSizeChange:V,children:i.map(e=>_jsx(FilterChipRowItem,{itemKey:e.key,label:e.label,count:e.count,disabled:e.disabled,testID:e.testID,selected:e.key===a,size:r,variant:l,tone:n,haptic:c,onSelect:I,onItemLayout:k},e.key))})})}FilterChipRowItem.displayName="FilterChipRowItem";const styles=StyleSheet.create({row:{alignItems:"center"}});export{FilterChipRow};export default FilterChipRow;
1
+ "use strict";import{memo,useCallback,useEffect,useMemo,useRef}from"react";import{ScrollView,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{jsx as _jsx}from"react/jsx-runtime";const FilterChipRowItem=memo(({itemKey:e,label:t,count:i,disabled:a,testID:o,selected:s,size:r,variant:l,tone:n,haptic:c,onSelect:u,onItemLayout:d})=>{const m=useCallback(()=>u(e),[u,e]),p=useCallback(t=>d(e,t.nativeEvent.layout),[d,e]);return _jsx(View,{onLayout:p,collapsable:!1,children:_jsx(Chip,{label:t,count:i,selected:s,selectionMode:"radio",disabled:a,testID:o,size:r,variant:l,tone:n,haptic:!s&&c,onPress:m})})});function FilterChipRow({ref:e,...t}){const{items:i,value:a,onChange:o,bleed:s=0,size:r,variant:l="outline",tone:n,haptic:c,accessibilityLabel:u,style:d,contentContainerStyle:m,testID:p}=t;assertValidValue("FilterChipRow","size",t.size,["sm","md"]),assertValidValue("FilterChipRow","variant",t.variant,["solid","soft","outline"]),assertValidValue("FilterChipRow","tone",t.tone,["primary","success","warning","danger","info","neutral"]);const h=useTheme(),w=useReducedMotion(),C=useRef(null),f=useRef({viewport:0,content:0,chips:{},revealed:null}),b=useRef(a),y=useRef(o);useEffect(()=>{y.current=o},[o]);const x=useCallback((e,t)=>{const i=f.current,a=i.chips[e];if(!a||0===i.viewport||0===i.content)return;const o=a.x+a.width/2-i.viewport/2,s=Math.min(Math.max(o,0),Math.max(i.content-i.viewport,0));C.current?.scrollTo({x:s,animated:t&&!w}),i.revealed=e},[w]),v=useCallback(()=>{f.current.revealed!==b.current&&x(b.current,!1)},[x]);useEffect(()=>{b.current=a,x(a,!0)},[a,x]);const R=useCallback(e=>{f.current.viewport=e.nativeEvent.layout.width,v()},[v]),V=useCallback(e=>{f.current.content=e,v()},[v]),k=useCallback((e,t)=>{f.current.chips[e]={x:t.x,width:t.width},v()},[v]),I=useCallback(e=>{e!==b.current?y.current(e):x(e,!0)},[x]),S=useMemo(()=>[styles.row,{paddingHorizontal:s,columnGap:h.space.xs},m],[s,h.space.xs,m]);return _jsx(View,{ref:e,accessibilityRole:"radiogroup",accessibilityLabel:u,testID:p,style:[s>0?{marginHorizontal:-s}:null,d],children:_jsx(ScrollView,{ref:C,horizontal:!0,showsHorizontalScrollIndicator:!1,keyboardShouldPersistTaps:"handled",contentContainerStyle:S,onLayout:R,onContentSizeChange:V,children:i.map(e=>_jsx(FilterChipRowItem,{itemKey:e.key,label:e.label,count:e.count,disabled:e.disabled,testID:e.testID,selected:e.key===a,size:r,variant:l,tone:n,haptic:c,onSelect:I,onItemLayout:k},e.key))})})}FilterChipRowItem.displayName="FilterChipRowItem";const styles=StyleSheet.create({row:{alignItems:"center"}});export{FilterChipRow};export default FilterChipRow;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useMobileUiText}from"../../text/index.js";import{MODAL_TEXT}from"../../text/phone/modal.g.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9;function Modal({ref:e,...t}){assertValidValue("Modal","presentation",t.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:x="center",testID:A,bare:y=!1,onInsetsChange:M}=t,C=useTheme(),w=useMobileUiText("modal",MODAL_TEXT),D=useMemo(()=>({...w,...b}),[w,b]),R=usePresenceMotion(),[V,T]=useModalInsets();useEffect(()=>{M?.(V)},[V,M]);const{width:j,height:E}=useWindowDimensions(),[_,I]=useState({width:0,height:0}),k=a??R.duration("default"),H=E,N=useRef(!l&&o),P=N.current,L=useRef(createAnimatedValue(P?1:.9)).current,O=useRef(createAnimatedValue(P?1:0)).current,W=useRef(createAnimatedValue(P?0:H)).current,q=useRef(createAnimatedValue(P?1:0)).current,z=useRef(null),F=useRef(!1),[B,U]=useState(o),K=useMemo(()=>buildStyles(C),[C]),X=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(v,_,e,S,{align:x});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,_,S,x,j,E,V.top,V.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>q.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[q,G]);useEffect(()=>{o&&(Keyboard.dismiss(),U(!0))},[o]),useEffect(()=>{const e=[];if(o&&B&&N.current)N.current=!1;else if(o&&B){const t=Animated.timing(q,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===i){O.setValue(0),W.setValue(0),L.setValue(1);const t=Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){O.setValue(1);const t=Animated.spring(W,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(L,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(B){const t=R.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(O,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=R.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(W,{toValue:H,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(L,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(q,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(W.setValue(H),U(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,B,i,k,L,O,q,W,H,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,R,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{z.current&&AccessibilityInfo.sendAccessibilityEvent(z.current,"focus")},150),F.current=!0):F.current&&(F.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},k))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,k,f]);const $=useRef(h);$.current=h;const J=useRef(!1);useEffect(()=>{if(o)return void(J.current=!0);if(!J.current)return;J.current=!1;const e=setTimeout(()=>$.current?.(),300);return()=>clearTimeout(e)},[o]);const Q=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),ee=useSquircle(!y&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),te=useCallback(e=>{ee.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;I(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[ee.onLayout]),oe=useMemo(()=>y?"bottom"===i?K.bottomContent:"fullScreen"===i?K.fullScreenContent:K.bareCentredContent:"anchored"===i?[K.anchoredContent,{left:X?.x,top:X?.y,maxHeight:X?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[K.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[K.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+V.bottom},C.shadow.modal]:[K.centeredContent,{backgroundColor:C.colors.surface,borderRadius:ee.active&&ee.size?squircleHostRadius(ee.size.width,ee.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,K,V.bottom,ee.active,ee.size,X,y]),re=useMemo(()=>"anchored"===i?K.anchoredWrapper:"bottom"===i?K.bottomWrapper:"fullScreen"===i?K.fullScreenWrapper:K.centeredWrapper,[i,K]),ie=useMemo(()=>"bottom"===i?{opacity:O,transform:[{translateY:W}]}:"fullScreen"===i||"anchored"===i?{opacity:O}:{opacity:O,transform:[{scale:L}]},[i,L,O,W]);if("anchored"===i&&void 0===v)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(y&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:B,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:A,children:_jsx(View,{ref:t=>{z.current=t,"function"==typeof e?e(t):e&&(e.current=t)},style:K.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:T,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,re,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Q,accessibilityRole:n?"button":void 0,accessibilityLabel:n?D.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n,testID:A?`${A}-backdrop`:void 0}),_jsxs(Animated.View,{style:[oe,ie,_.height>0||"anchored"!==i?null:K.unmeasured,m],onLayout:te,pointerEvents:y&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[ee.active&&ee.size?_jsx(SquircleFill,{width:ee.size.width,height:ee.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})}const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useMobileUiText}from"../../text/index.js";import{MODAL_TEXT}from"../../text/phone/modal.g.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9;function Modal({ref:e,...t}){assertValidValue("Modal","presentation",t.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:x="center",testID:A,bare:y=!1,onInsetsChange:M}=t,C=useTheme(),w=useMobileUiText("modal",MODAL_TEXT),D=useMemo(()=>({...w,...b}),[w,b]),R=usePresenceMotion(),[V,T]=useModalInsets();useEffect(()=>{M?.(V)},[V,M]);const{width:j,height:E}=useWindowDimensions(),[_,I]=useState({width:0,height:0}),k=a??R.duration("default"),H=E,N=useRef(!l&&o),P=N.current,L=useRef(createAnimatedValue(P?1:.9)).current,O=useRef(createAnimatedValue(P?1:0)).current,W=useRef(createAnimatedValue(P?0:H)).current,q=useRef(createAnimatedValue(P?1:0)).current,z=useRef(null),F=useRef(!1),[B,U]=useState(o),K=useMemo(()=>buildStyles(C),[C]),X=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(v,_,e,S,{align:x});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,_,S,x,j,E,V.top,V.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>q.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[q,G]);useEffect(()=>{o&&(Keyboard.dismiss(),U(!0))},[o]),useEffect(()=>{const e=[];if(o&&B&&N.current)N.current=!1;else if(o&&B){const t=Animated.timing(q,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===i){O.setValue(0),W.setValue(0),L.setValue(1);const t=Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){O.setValue(1);const t=Animated.spring(W,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(L,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(O,{toValue:1,duration:k,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(B){const t=R.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(O,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=R.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(W,{toValue:H,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(L,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(q,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(W.setValue(H),U(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,B,i,k,L,O,q,W,H,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,R,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{z.current&&AccessibilityInfo.sendAccessibilityEvent(z.current,"focus")},150),F.current=!0):F.current&&(F.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},k))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,k,f]);const $=useRef(h);$.current=h;const J=useRef(!1);useEffect(()=>{if(o)return void(J.current=!0);if(!J.current)return;J.current=!1;const e=setTimeout(()=>$.current?.(),300);return()=>clearTimeout(e)},[o]);const Q=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),ee=useSquircle(!y&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),te=useCallback(e=>{ee.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;I(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[ee.onLayout]),oe=useMemo(()=>y?"bottom"===i?K.bottomContent:"fullScreen"===i?K.fullScreenContent:K.bareCentredContent:"anchored"===i?[K.anchoredContent,{left:X?.x,top:X?.y,maxHeight:X?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[K.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[K.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+V.bottom},C.shadow.modal]:[K.centeredContent,{backgroundColor:C.colors.surface,borderRadius:ee.active&&ee.size?squircleHostRadius(ee.size.width,ee.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,K,V.bottom,ee.active,ee.size,X,y]),re=useMemo(()=>"anchored"===i?K.anchoredWrapper:"bottom"===i?K.bottomWrapper:"fullScreen"===i?K.fullScreenWrapper:K.centeredWrapper,[i,K]),ie=useMemo(()=>"bottom"===i?{opacity:O,transform:[{translateY:W}]}:"fullScreen"===i||"anchored"===i?{opacity:O}:{opacity:O,transform:[{scale:L}]},[i,L,O,W]);if("anchored"===i&&void 0===v)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(y&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:B,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:A,children:_jsx(View,{ref:t=>{z.current=t,"function"==typeof e?e(t):e&&(e.current=t)},style:K.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:T,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,re,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Q,accessibilityRole:n?"button":void 0,accessibilityLabel:n?D.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n,testID:A?`${A}-backdrop`:void 0}),_jsxs(Animated.View,{style:[oe,ie,_.height>0||"anchored"!==i?null:K.unmeasured,m],onLayout:te,pointerEvents:y&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[ee.active&&ee.size?_jsx(SquircleFill,{width:ee.size.width,height:ee.size.height,radius:C.radius.xl,fill:C.colors.surface,hostBorderWidth:0}):null,d]})]}),_jsx(ToastHost,{})]})})})}const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
@@ -1 +1 @@
1
- "use strict";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useMobileUiText}from"../../text/index.js";import{PICKER_TRIGGER_TEXT}from"../../text/phone/pickerTrigger.g.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function PickerTrigger(e){assertValidValue("PickerTrigger","size",e.size,["sm","md","lg"]),assertValidValue("PickerTrigger","variant",e.variant,["outline","filled","underline"]);const{value:i,placeholder:l,label:t,help:r,helperText:s,error:o,required:a=!1,onPress:n,clearable:d=!1,onClear:c,leftIcon:x,trailing:u,disabled:g=!1,size:m="md",variant:b,style:T,triggerStyle:y,valueStyle:h,labelStyle:p,messageStyle:f,accessibilityLabel:j,labels:S,testID:v}=e,F=useMobileUiText("pickerTrigger",PICKER_TRIGGER_TEXT),_=useMemo(()=>({...F,...S}),[F,S]),P=useTheme(),z=useMemo(()=>buildStyles(P),[P]),R=resolveFieldSize(P,m),V=resolveFieldTextStyle(P,{disabled:g}),k="string"==typeof i&&i.length>0,M=!0===o||hasFieldText(o),w=hasFieldText(t),I=k?i:l??_.placeholder,C=k?V.color:V.placeholderColor,E=k?`${fieldTextAsString(t)??_.selection}: ${i}`:l??_.noSelection,L=j??E,q={disabled:g},B=void 0===u,G=d&&k&&!g;return _jsxs(View,{style:[z.root,T],testID:v,children:[w?_jsx(FieldLabel,{size:m,required:a,help:r,style:p,children:t}):null,_jsx(FieldBase,{size:m,variant:b,disabled:g,error:M,filled:k,onPress:n,leading:x,trailing:G||B||null!==u?_jsxs(View,{style:z.trailingRow,children:[G?_jsx(Text,{variant:"body",onPress:()=>{g||c?.()},accessibilityRole:"button",accessibilityLabel:_.clear,style:{fontSize:R.icon,color:P.colors["text-muted"],paddingHorizontal:P.space.xs},children:"×"}):null,void 0!==u?u:B?_jsx(Chevron,{size:R.icon,color:g?P.colors["text-disabled"]:P.colors["text-subtle"]}):null]}):null,accessibilityLabel:L,accessibilityState:q,accessibilityRole:"button",style:y,children:_jsxs(Text,{variant:"body",numberOfLines:1,style:[z.valueText,{color:C,fontSize:R.text,...V.weightStyle},h],children:[I,k||!a||w?null:_jsx(RequiredMark,{})]})}),_jsx(FieldMessage,{size:m,error:M,text:M?o:s,style:f})]})}const buildStyles=e=>StyleSheet.create({root:{width:"100%"},label:{includeFontPadding:!1},valueText:{flex:1,includeFontPadding:!1},message:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center"}});export{PickerTrigger};export default PickerTrigger;
1
+ "use strict";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useMobileUiText}from"../../text/index.js";import{PICKER_TRIGGER_TEXT}from"../../text/phone/pickerTrigger.g.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function PickerTrigger({ref:e,...i}){assertValidValue("PickerTrigger","size",i.size,["sm","md","lg"]),assertValidValue("PickerTrigger","variant",i.variant,["outline","filled","underline"]);const{value:l,placeholder:t,label:r,help:s,helperText:o,error:a,required:n=!1,onPress:d,clearable:c=!1,onClear:x,leftIcon:u,trailing:g,disabled:m=!1,size:b="md",variant:T,style:y,triggerStyle:h,valueStyle:f,labelStyle:p,messageStyle:j,accessibilityLabel:S,labels:v,testID:F}=i,_=useMobileUiText("pickerTrigger",PICKER_TRIGGER_TEXT),P=useMemo(()=>({..._,...v}),[_,v]),z=useTheme(),R=useMemo(()=>buildStyles(z),[z]),V=resolveFieldSize(z,b),k=resolveFieldTextStyle(z,{disabled:m}),M="string"==typeof l&&l.length>0,w=!0===a||hasFieldText(a),I=hasFieldText(r),C=M?l:t??P.placeholder,E=M?k.color:k.placeholderColor,L=M?`${fieldTextAsString(r)??P.selection}: ${l}`:t??P.noSelection,q=S??L,B={disabled:m},G=void 0===g,D=c&&M&&!m;return _jsxs(View,{ref:e,style:[R.root,y],testID:F,children:[I?_jsx(FieldLabel,{size:b,required:n,help:s,style:p,children:r}):null,_jsx(FieldBase,{size:b,variant:T,disabled:m,error:w,filled:M,onPress:d,leading:u,trailing:D||G||null!==g?_jsxs(View,{style:R.trailingRow,children:[D?_jsx(Text,{variant:"body",onPress:()=>{m||x?.()},accessibilityRole:"button",accessibilityLabel:P.clear,style:{fontSize:V.icon,color:z.colors["text-muted"],paddingHorizontal:z.space.xs},children:"×"}):null,void 0!==g?g:G?_jsx(Chevron,{size:V.icon,color:m?z.colors["text-disabled"]:z.colors["text-subtle"]}):null]}):null,accessibilityLabel:q,accessibilityState:B,accessibilityRole:"button",style:h,children:_jsxs(Text,{variant:"body",numberOfLines:1,style:[R.valueText,{color:E,fontSize:V.text,...k.weightStyle},f],children:[C,M||!n||I?null:_jsx(RequiredMark,{})]})}),_jsx(FieldMessage,{size:b,error:w,text:w?a:o,style:j})]})}const buildStyles=e=>StyleSheet.create({root:{width:"100%"},label:{includeFontPadding:!1},valueText:{flex:1,includeFontPadding:!1},message:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center"}});export{PickerTrigger};export default PickerTrigger;
@@ -1 +1 @@
1
- "use strict";import{cloneElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{bottomPaddingOf,topPaddingOf}from"../../utils/contentPadding.js";import{AppBar}from"../AppBar/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedList}from"../PagedList/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},buildStyles=e=>StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:a,rightActions:l,leading:s,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:p=!0,list:m,edges:g=DEFAULT_EDGES,keyboardToolbar:h=!0,bottomInset:S=0,gutter:b,floatingAction:v,scrollRef:y,onScroll:x,contentContainerStyle:C,testID:T}=e,j=useTheme(),E=b??void 0===m,R=j.space[j.components.screen.gutter],w=E?R:0,k=useSafeAreaInsets(),A=useMemo(()=>buildStyles(j),[j]),[L]=useState(()=>new Animated.Value(0)),[O,V]=useState(0),[_,B]=useState(0),P=void 0!==a,z=useRef(a);z.current=a;const D=Boolean(t||o||a||s||i||l?.length),H=n&&void 0!==t,I=H&&(void 0!==m||p),K=I?O:0,M=D&&!I&&(r??j.settings.components.screen?.headerShadowOnScroll??!0),[F,N]=useState(!1),W=useRef(M);W.current=M;const headerGap=e=>e>0?e:D?j.space.lg:0,G=void 0!==f,{refreshControl:U}=useRefreshControl({onRefresh:c??noop,refreshing:u}),Y=c?cloneElement(U,{progressViewOffset:K}):void 0,$=useSharedValue(0),q=useSharedValue(0),J=useSharedValue(0),Q=useSharedValue(0),X=useRef(null),Z=useRef(0),ee=useRef(0),te=useMemo(()=>({top:$,bottom:q,offset:J,maxOffset:Q,scrollTo:e=>{const t=X.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[$,q,J,Q]),oe=useCallback(e=>{X.current=e,"function"==typeof y?y(e):y&&(y.current=e)},[y]),ne=useCallback(()=>{Q.value=Math.max(0,Z.current-ee.current)},[Q]),re=useRef(x);re.current=x;const ae=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:L}}}],{useNativeDriver:!1,listener:e=>{if(J.value=e.nativeEvent.contentOffset.y,W.current){const t=e.nativeEvent.contentOffset.y>0;N(e=>e===t?e:t)}re.current?.(e)}}),[L,J]),le=useCallback(e=>{const{height:t}=e.nativeEvent.layout;V(e=>Math.max(e,t))},[]),se=useCallback(e=>{B(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!P)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(z.current?.(),!0));return()=>e.remove()},[P]);const ie=g.includes("left")?k.left:0,de=g.includes("right")?k.right:0,ce=g.includes("bottom")?k.bottom:0,ue=g.includes("top")&&!D?k.top:0,fe=j.space[j.components["floating-action-button"]["bottom-offset"]],pe=v?.props.bottomOffset??fe,me=v?resolveFloatingActionButtonSize(j,v.props.size??"md").diameter+pe+j.space.lg:0,ge=G?Math.max(0,_-k.bottom):S,he=v?cloneElement(v,{bottomOffset:pe+ge,position:v.props.position??"bottomRight"}):null,Se=G?me:Math.max(ce,v?me+k.bottom:0),be=S+Se-(G?0:ce),ve=g.filter(e=>"top"!==e&&!("bottom"===e&&G)),ye=D?_jsx(View,{style:I?A.overlay:M?A.headerRaised:void 0,onLayout:I?le:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:H?"large":"default",scrollY:I?L:void 0,elevated:M&&F,onBack:a,rightActions:l,leading:s,trailing:i,gutter:R,testID:T?`${T}-app-bar`:void 0})}):null,xe=useCallback(()=>{const e=X.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{ee.current=n,$.value=t+K,q.value=t+n,ne()})},[K,$,q,ne]);useEffect(()=>{xe()},[xe]);const Ce=useCallback((e,t)=>{Z.current=t,ne()},[ne]);let Te;if(void 0!==m){const e=topPaddingOf([m.contentContainerStyle,C]);Te=_jsx(ScrollHostContext,{value:te,children:_jsx(PagedList,{...m,ref:oe,onRefresh:m.state?void 0:c,refreshing:m.state?void 0:u,progressViewOffset:K,placeholderStyle:[A.flex,{paddingTop:K+headerGap(e)}],onScroll:ae,onLayout:e=>{xe(),m.onLayout?.(e)},onContentSizeChange:(e,t)=>{Ce(e,t),m.onContentSizeChange?.(e,t)},scrollEventThrottle:16,style:A.flex,contentContainerStyle:[{paddingTop:K,paddingLeft:ie+w,paddingRight:de+w},m.contentContainerStyle,C,{paddingTop:K+headerGap(e),paddingBottom:bottomPaddingOf([m.contentContainerStyle,C])+S+Se}]})})}else Te=p?_jsx(ScrollHostContext,{value:te,children:_jsxs(KeyboardAwareScrollView,{ref:oe,refreshControl:Y,onScroll:ae,scrollEventThrottle:16,onLayout:xe,onContentSizeChange:Ce,safeAreaEdges:ve,style:A.flex,contentContainerStyle:[{paddingHorizontal:w},C,{paddingTop:K+headerGap(topPaddingOf(C))}],children:[d,be>0?_jsx(View,{style:{height:be}}):null]})}):_jsx(View,{style:[A.flex,{paddingLeft:ie+w,paddingRight:de+w},C,{paddingBottom:bottomPaddingOf(C)+S+Se}],children:d});const je=G?_jsx(KeyboardStickyView,{onLayout:se,style:[A.footer,{paddingLeft:ie+R,paddingRight:de+R,paddingBottom:ce+S}],children:f}):null;return _jsxs(View,{testID:T,style:[A.root,{paddingTop:ue}],children:[I?null:ye,Te,je,he,void 0!==m?d:null,I?ye:null,h?_jsx(KeyboardToolbar,{}):null]})}
1
+ "use strict";import{cloneElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{bottomPaddingOf,topPaddingOf}from"../../utils/contentPadding.js";import{AppBar}from"../AppBar/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedList}from"../PagedList/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},buildStyles=e=>StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:a,rightActions:s,leading:l,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:p=!0,list:m,edges:g=DEFAULT_EDGES,keyboardToolbar:h=!0,footerHugsKeyboard:S=!1,bottomInset:b=0,gutter:v,floatingAction:y,scrollRef:x,onScroll:C,contentContainerStyle:T,testID:j}=e,E=useTheme(),R=v??void 0===m,w=E.space[E.components.screen.gutter],k=R?w:0,A=useSafeAreaInsets(),L=useMemo(()=>buildStyles(E),[E]),[O]=useState(()=>new Animated.Value(0)),[V,_]=useState(0),[B,P]=useState(0),H=void 0!==a,K=useRef(a);K.current=a;const z=Boolean(t||o||a||l||i||s?.length),D=n&&void 0!==t,I=D&&(void 0!==m||p),M=I?V:0,F=z&&!I&&(r??E.settings.components.screen?.headerShadowOnScroll??!0),[N,W]=useState(!1),G=useRef(F);G.current=F;const headerGap=e=>e>0?e:z?E.space.lg:0,U=void 0!==f,{refreshControl:Y}=useRefreshControl({onRefresh:c??noop,refreshing:u}),$=c?cloneElement(Y,{progressViewOffset:M}):void 0,q=useSharedValue(0),J=useSharedValue(0),Q=useSharedValue(0),X=useSharedValue(0),Z=useRef(null),ee=useRef(0),te=useRef(0),oe=useMemo(()=>({top:q,bottom:J,offset:Q,maxOffset:X,scrollTo:e=>{const t=Z.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[q,J,Q,X]),ne=useCallback(e=>{Z.current=e,"function"==typeof x?x(e):x&&(x.current=e)},[x]),re=useCallback(()=>{X.value=Math.max(0,ee.current-te.current)},[X]),ae=useRef(C);ae.current=C;const se=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:O}}}],{useNativeDriver:!1,listener:e=>{if(Q.value=e.nativeEvent.contentOffset.y,G.current){const t=e.nativeEvent.contentOffset.y>0;W(e=>e===t?e:t)}ae.current?.(e)}}),[O,Q]),le=useCallback(e=>{const{height:t}=e.nativeEvent.layout;_(e=>Math.max(e,t))},[]),ie=useCallback(e=>{P(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!H)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(K.current?.(),!0));return()=>e.remove()},[H]);const de=g.includes("left")?A.left:0,ce=g.includes("right")?A.right:0,ue=g.includes("bottom")?A.bottom:0,fe=g.includes("top")&&!z?A.top:0,pe=E.space[E.components["floating-action-button"]["bottom-offset"]],me=y?.props.bottomOffset??pe,ge=y?resolveFloatingActionButtonSize(E,y.props.size??"md").diameter+me+E.space.lg:0,he=U?Math.max(0,B-A.bottom):b,Se=y?cloneElement(y,{bottomOffset:me+he,position:y.props.position??"bottomRight"}):null,be=U?ge:Math.max(ue,y?ge+A.bottom:0),ve=b+be-(U?0:ue),ye=g.filter(e=>"top"!==e&&!("bottom"===e&&U)),xe=z?_jsx(View,{style:I?L.overlay:F?L.headerRaised:void 0,onLayout:I?le:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:D?"large":"default",scrollY:I?O:void 0,elevated:F&&N,onBack:a,rightActions:s,leading:l,trailing:i,gutter:w,testID:j?`${j}-app-bar`:void 0})}):null,Ce=useCallback(()=>{const e=Z.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{te.current=n,q.value=t+M,J.value=t+n,re()})},[M,q,J,re]);useEffect(()=>{Ce()},[Ce]);const Te=useCallback((e,t)=>{ee.current=t,re()},[re]);let je;if(void 0!==m){const e=topPaddingOf([m.contentContainerStyle,T]);je=_jsx(ScrollHostContext,{value:oe,children:_jsx(PagedList,{...m,ref:ne,onRefresh:m.state?void 0:c,refreshing:m.state?void 0:u,progressViewOffset:M,placeholderStyle:[L.flex,{paddingTop:M+headerGap(e)}],onScroll:se,onLayout:e=>{Ce(),m.onLayout?.(e)},onContentSizeChange:(e,t)=>{Te(e,t),m.onContentSizeChange?.(e,t)},scrollEventThrottle:16,style:L.flex,contentContainerStyle:[{paddingTop:M,paddingLeft:de+k,paddingRight:ce+k},m.contentContainerStyle,T,{paddingTop:M+headerGap(e),paddingBottom:bottomPaddingOf([m.contentContainerStyle,T])+b+be}]})})}else je=p?_jsx(ScrollHostContext,{value:oe,children:_jsxs(KeyboardAwareScrollView,{ref:ne,refreshControl:$,onScroll:se,scrollEventThrottle:16,onLayout:Ce,onContentSizeChange:Te,safeAreaEdges:ye,style:L.flex,contentContainerStyle:[{paddingHorizontal:k},T,{paddingTop:M+headerGap(topPaddingOf(T))}],children:[d,ve>0?_jsx(View,{style:{height:ve}}):null]})}):_jsx(View,{style:[L.flex,{paddingLeft:de+k,paddingRight:ce+k},T,{paddingBottom:bottomPaddingOf(T)+b+be}],children:d});const Ee=U?_jsx(KeyboardStickyView,{onLayout:ie,offset:{opened:S?ue+b:0},style:[L.footer,{paddingLeft:de+w,paddingRight:ce+w,paddingBottom:ue+b}],children:f}):null;return _jsxs(View,{testID:j,style:[L.root,{paddingTop:fe}],children:[I?null:xe,je,Ee,Se,void 0!==m?d:null,I?xe:null,h?_jsx(KeyboardToolbar,{}):null]})}
@@ -1 +1 @@
1
- "use strict";import{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{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.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"];case"info":return e.colors["info-text"]}};function SegmentedControl({ref:e,...t}){const{segments:i,label:s,helperText:r,error:l,value:o,defaultValue:n,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,segmentStyle:v,selectedIndicatorStyle:y,textStyle:S,labelStyle:w,testID:j}=t;assertValidValue("SegmentedControl","size",t.size,["sm","md","lg"]),assertValidValue("SegmentedControl","tone",t.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SegmentedControl","variant",t.variant,["underline","pills","segmented"]);const[C]=i;if(void 0===C)throw new Error("SegmentedControl needs at least one segment");const[V,k]=useControllableState({value:o,defaultValue:n??C.value,onChange:e=>{null!==e&&a?.(e)}}),F=useTheme(),I=F.components["segmented-control"],L=useMemo(()=>buildStyles(F),[F]),_=useMemo(()=>resolveSegmentedControlSize(F,d),[F,d]),z=p>=2?2:1,M=z>1,T="segmented"===h,E="underline"===h,A="pills"===h,R=T?F.space[I["track-padding"]]:0,D=Math.ceil(1.25*_.text)*(z-1),H=I["underline-height"],q=F.space[I["pill-inset"]],B="number"==typeof g?g:g?F.radius[g]:void 0,W=B??F.radius.md,P=void 0===B?F.radius.sm:Math.max(B-R,0),G=B??F.radius.pill,N=B??F.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,i.findIndex(e=>e.value===V)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=F.motion.spring.snappy,i=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:nativeDriver});return i.start(),i},[F.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===i.length||0===e.length?e:[])},[i.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:i,width:s}=t.nativeEvent.layout;X(t=>{const r=t[e];if(r&&r.x===i&&r.width===s)return t;const l=t.slice();return l[e]={x:i,width:s},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===V)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),k(e.value)},[u,k,V,f]),te=T?F.colors.thumb:A?F.colors["primary-soft"]:F.colors.primary,ie=T?P:A?G:N,se=activeInkFor(F,m),re=F.colors["bg-muted"],le=useSquircle(T,W),oe=!0===l||hasFieldText(l),ne=oe&&!u,ae=F.colors["field-border-error"],de=F.size.border,ce=hasFieldText(s),ue=oe?l:r,me=hasFieldText(ue),he=_jsxs(View,{ref:e,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof s?s:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+D}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},T?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":re,padding:R}:E?{borderBottomColor:ne?ae:F.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:re,stroke:ne?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,T?M?{top:0,bottom:0}:{top:0,height:_.height-2*R}:A?{top:q,bottom:q,left:q}:{bottom:0,height:H},{width:A?Math.max(Q.width-2*q,0):Q.width,borderRadius:ie,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},y]}):null,i.map((e,t)=>{const i=e.value===V,s=i?se:F.colors["text-subtle"],r=renderSlotIcon(e.icon,{color:s,size:_.icon,selected:i,disabled:u}),l=Boolean(r);return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:i,selected:i,disabled:u},"aria-checked":i,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!i?.7:1},v],children:[l?_jsx(View,{style:L.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:r}):null,_jsx(Text,{variant:"label",weight:i?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:s,fontSize:_.text},S,w],numberOfLines:z,children:e.label})]},String(e.value))})]}),!ne||E||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:T?W:G,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:s}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:oe}):null]}):he}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{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{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.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"];case"info":return e.colors["info-text"]}};function SegmentedControl({ref:e,...t}){const{segments:i,label:s,helperText:r,error:l,value:o,defaultValue:n,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,segmentStyle:v,selectedIndicatorStyle:y,textStyle:S,labelStyle:w,testID:j}=t;assertValidValue("SegmentedControl","size",t.size,["sm","md","lg"]),assertValidValue("SegmentedControl","tone",t.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SegmentedControl","variant",t.variant,["underline","pills","segmented"]);const[C]=i;if(void 0===C)throw new Error("SegmentedControl needs at least one segment");const[V,k]=useControllableState({value:o,defaultValue:n??C.value,onChange:e=>{null!==e&&a?.(e)}}),F=useTheme(),I=F.components["segmented-control"],L=useMemo(()=>buildStyles(F),[F]),_=useMemo(()=>resolveSegmentedControlSize(F,d),[F,d]),z=p>=2?2:1,M=z>1,T="segmented"===h,E="underline"===h,A="pills"===h,R=T?F.space[I["track-padding"]]:0,D=Math.ceil(1.25*_.text)*(z-1),H=I["underline-height"],B=F.space[I["pill-inset"]],q="number"==typeof g?g:g?F.radius[g]:void 0,W=q??F.radius.md,P=void 0===q?F.radius.sm:Math.max(q-R,0),G=q??F.radius.pill,N=q??F.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,i.findIndex(e=>e.value===V)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=F.motion.spring.snappy,i=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:nativeDriver});return i.start(),i},[F.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===i.length||0===e.length?e:[])},[i.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:i,width:s}=t.nativeEvent.layout;X(t=>{const r=t[e];if(r&&r.x===i&&r.width===s)return t;const l=t.slice();return l[e]={x:i,width:s},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===V)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),k(e.value)},[u,k,V,f]),te=T?F.colors.thumb:A?F.colors["primary-soft"]:F.colors.primary,ie=T?P:A?G:N,se=activeInkFor(F,m),re=F.colors["bg-muted"],le=useSquircle(T,W),oe=!0===l||hasFieldText(l),ne=oe&&!u,ae=F.colors["field-border-error"],de=F.size.border,ce=hasFieldText(s),ue=oe?l:r,me=hasFieldText(ue),he=_jsxs(View,{ref:e,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof s?s:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+D}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},T?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":re,padding:R}:E?{borderBottomColor:ne?ae:F.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:re,stroke:ne?ae:void 0,strokeWidth:de,hostBorderWidth:0}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,T?M?{top:0,bottom:0}:{top:0,height:_.height-2*R}:A?{top:B,bottom:B,left:B}:{bottom:0,height:H},{width:A?Math.max(Q.width-2*B,0):Q.width,borderRadius:ie,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},y]}):null,i.map((e,t)=>{const i=e.value===V,s=i?se:F.colors["text-subtle"],r=renderSlotIcon(e.icon,{color:s,size:_.icon,selected:i,disabled:u}),l=Boolean(r);return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:i,selected:i,disabled:u},"aria-checked":i,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!i?.7:1},v],children:[l?_jsx(View,{style:L.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:r}):null,_jsx(Text,{variant:"label",weight:i?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:s,fontSize:_.text},S,w],numberOfLines:z,children:e.label})]},String(e.value))})]}),!ne||E||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:T?W:G,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:s}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:oe}):null]}):he}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;