@webority/mobile-ui 0.133.0 → 0.134.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-kit/kit.js +2196 -2074
- package/dist/canvas-kit/manifest.json +2 -2
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/AppIcon/slotIcon.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/Button/Button.js +1 -1
- package/lib/commonjs/components/Card/Card.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/commonjs/components/DateSeparator/DateSeparator.js +1 -1
- package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
- package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchPanel.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/Select/Select.js +1 -1
- package/lib/commonjs/components/StatTile/StatTile.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/Tabs/Tabs.js +1 -1
- package/lib/module/components/AppIcon/slotIcon.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/Button/Button.js +1 -1
- package/lib/module/components/Card/Card.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/module/components/DateSeparator/DateSeparator.js +1 -1
- package/lib/module/components/Dialog/OverlayActions.js +1 -1
- package/lib/module/components/IconButton/IconButton.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/Menu/MenuSurface.js +1 -1
- package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.js +1 -1
- package/lib/module/components/SearchBar/SearchPanel.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/Select/Select.js +1 -1
- package/lib/module/components/StatTile/StatTile.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/Tabs/Tabs.js +1 -1
- package/lib/typescript/commonjs/components/AppIcon/slotIcon.d.ts +8 -0
- package/lib/typescript/commonjs/components/DateSeparator/DateSeparator.d.ts +2 -3
- package/lib/typescript/module/components/AppIcon/slotIcon.d.ts +8 -0
- package/lib/typescript/module/components/DateSeparator/DateSeparator.d.ts +2 -3
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:w,indicatorStyle:I,labelStyle:A,labelMaxFontScale:E,labels:R,testID:v}=e;warnInvalidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),warnInvalidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>R?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...R}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[R]),L=useTheme(),j=useSafeAreaInsets(),V=useMemo(()=>buildStyles(L),[L]),B=m??18,C=B+4+8,M=L.space.lg,D=L.space.lg,k=L.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+L.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-M,64):0,we=ge>0?(ge-Se)/2:0,Ie=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:L.space.xs+(B+4)/2,Re=Ee-14-24,ve=Math.max(0,ae-4),Te=K?2:Ee-C/2,Le=useRef(ie);useEffect(()=>{if(Le.current===ie)return;Le.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:!0});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Ve=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),Ce=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?Ce?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,Ce]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:!0}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:!0})]).start()},Me=useRef(new Animated.Value(1)).current,{colors:De}=L,ke=ee?De.primary:De.surface,Ne=ee?De["on-primary"]:De.primary,Pe=ee?De["on-primary"]:K?De["text-body"]:De["text-subtle"],ze=ee?De["on-primary"]:De["primary-soft"],Fe=ee?De.primary:J?De["on-primary"]:Ne,He=h??D,Oe=g??(q?D:0),We=Oe>0,Ue=f??L.space.sm,$e=b??(q?L.space.sm:L.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+L.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:L.radius.pill:c??(K?L.radius.pill:q?k:L.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:L.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?De.primary:De.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[V.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Me),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[V.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(v?`${v}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:n.content}):_jsx(View,{style:[V.centerCircle,{width:ue,height:ue,borderRadius:L.radius.pill,...smoothCorners,backgroundColor:n.color??De.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??De["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&<.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??L.settings.maxFontSizeMultiplier??1.2,style:[V.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?V.accessoryInline:V.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:v?`${v}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[V.tabRow,V.tabRowInline]:V.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||ve>0)?_jsx(Animated.View,{pointerEvents:"none",style:[V.pill,{width:Se,height:K?ve:C,left:we,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(ve,ve/2):activeBgRadius(C,L.radius.pill),...smoothCorners,transform:[{translateX:Ve}]},I]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[V.bubble,L.shadow.elevated,{width:48,height:48,borderRadius:L.radius.pill,...smoothCorners,left:Ie,top:Re,backgroundColor:De.primary,borderColor:De.surface,transform:[{translateX:Ve}]},I]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key],u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?De.primary:De.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[V.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1}),u?_jsx(Badge,{variant:u,value:"standard"===u?e.badge:void 0,tone:"danger",accessible:!1,style:"dot"===u?V.badgeDotPosition:V.badgePillPosition,badgeStyle:["dot"===u?V.badgeDot:V.badgePill,{borderColor:h}],textStyle:V.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??L.settings.maxFontSizeMultiplier??1.2,style:[V.label,Q?V.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?L.weight.semibold:L.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[V.tab,K?V.tabTile:null,e?{opacity:.85}:null],testID:v?`${v}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[V.expandPill,{height:C,paddingHorizontal:t&&g?L.space.md:Math.max(0,(C-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[V.expandFill,{borderRadius:activeBgRadius(C,C/2),...smoothCorners,backgroundColor:t?De["primary-soft"]:"transparent"},t?I:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[V.underline,"top"===d?V.underlineTop:V.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:De.primary,transform:[{translateX:Ve}]},I]}):null]});var ut;return _jsx(View,{ref:t,testID:v,accessibilityRole:"tablist",style:[V.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},w],children:_jsxs(View,{style:[q?V.floatingBar:V.dockedBar,X?V.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:13}});export{BottomNavigation};export default BottomNavigation;
|
|
1
|
+
"use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:w,indicatorStyle:I,labelStyle:A,labelMaxFontScale:E,labels:R,testID:v}=e;warnInvalidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),warnInvalidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>R?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...R}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[R]),L=useTheme(),j=useSafeAreaInsets(),V=useMemo(()=>buildStyles(L),[L]),B=m??18,C=B+4+8,M=L.space.lg,D=L.space.lg,k=L.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+L.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-M,64):0,we=ge>0?(ge-Se)/2:0,Ie=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:L.space.xs+(B+4)/2,Re=Ee-14-24,ve=Math.max(0,ae-4),Te=K?2:Ee-C/2,Le=useRef(ie);useEffect(()=>{if(Le.current===ie)return;Le.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:!0});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Ve=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),Ce=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?Ce?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,Ce]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:!0}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:!0})]).start()},Me=useRef(new Animated.Value(1)).current,{colors:De}=L,ke=ee?De.primary:De.surface,Ne=ee?De["on-primary"]:De.primary,Pe=ee?De["on-primary"]:K?De["text-body"]:De["text-subtle"],ze=ee?De["on-primary"]:De["primary-soft"],Fe=ee?De.primary:J?De["on-primary"]:Ne,He=h??D,Oe=g??(q?D:0),We=Oe>0,Ue=f??L.space.sm,$e=b??(q?L.space.sm:L.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+L.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:L.radius.pill:c??(K?L.radius.pill:q?k:L.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:L.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?De.primary:De.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[V.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Me),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[V.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(v?`${v}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:n.content}):_jsx(View,{style:[V.centerCircle,{width:ue,height:ue,borderRadius:L.radius.pill,...smoothCorners,backgroundColor:n.color??De.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??De["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&<.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??L.settings.maxFontSizeMultiplier??1.2,style:[V.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?V.accessoryInline:V.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:v?`${v}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[V.tabRow,V.tabRowInline]:V.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||ve>0)?_jsx(Animated.View,{pointerEvents:"none",style:[V.pill,{width:Se,height:K?ve:C,left:we,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(ve,ve/2):activeBgRadius(C,L.radius.pill),...smoothCorners,transform:[{translateX:Ve}]},I]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[V.bubble,L.shadow.elevated,{width:48,height:48,borderRadius:L.radius.pill,...smoothCorners,left:Ie,top:Re,backgroundColor:De.primary,borderColor:De.surface,transform:[{translateX:Ve}]},I]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key],u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?De.primary:De.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[V.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1})}),u?_jsx(Badge,{variant:u,value:"standard"===u?e.badge:void 0,tone:"danger",accessible:!1,style:"dot"===u?V.badgeDotPosition:V.badgePillPosition,badgeStyle:["dot"===u?V.badgeDot:V.badgePill,{borderColor:h}],textStyle:V.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??L.settings.maxFontSizeMultiplier??1.2,style:[V.label,Q?V.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?L.weight.semibold:L.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[V.tab,K?V.tabTile:null,e?{opacity:.85}:null],testID:v?`${v}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[V.expandPill,{height:C,paddingHorizontal:t&&g?L.space.md:Math.max(0,(C-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[V.expandFill,{borderRadius:activeBgRadius(C,C/2),...smoothCorners,backgroundColor:t?De["primary-soft"]:"transparent"},t?I:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[V.underline,"top"===d?V.underlineTop:V.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:De.primary,transform:[{translateX:Ve}]},I]}):null]});var ut;return _jsx(View,{ref:t,testID:v,accessibilityRole:"tablist",style:[V.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},w],children:_jsxs(View,{style:[q?V.floatingBar:V.dockedBar,X?V.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:13}});export{BottomNavigation};export default BottomNavigation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{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{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,
|
|
1
|
+
"use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{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{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,t)=>{const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,containerStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:C,accessibilityHint:I,accessibilityState:_,testID:v,onLayout:w,labels:T,...j}=e;warnInvalidValue("Button","variant",e.variant,["solid","soft","outline","ghost","link","glass"]),warnInvalidValue("Button","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Button","size",e.size,["xs","sm","md","lg","xl"]);const k=useTheme(),F=k.settings.components.button,L=r??F?.defaultVariant??"solid",A=i??F?.defaultSize??"md",O=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...T}),[T]),R=!l&&!n,V={..._,disabled:!R,busy:n},B="link"===L,E=y??F?.defaultPressAnimation??(!B&&"scale"),P=usePressAnimation({preset:E||"scale",enabled:!1!==E&&R}),z=useFlickGuard(),H=useMemo(()=>buildStyles(k),[k]),W=useMemo(()=>resolveButtonSize(k,A),[k,A]),D=useMemo(()=>toneFor(k,s),[k,s]),N=useMemo(()=>variantFor(k,L,D,l),[k,L,D,l]),M=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?k.settings.gradients[m]??null:m,[m,l,L,k.settings.gradients]),U=StyleSheet.flatten(f)?.borderRadius,q=B?0:"number"==typeof U?U:p?k.radius.pill:W.radius,G=useSquircle(!M&&"link"!==L,q,w),K=useRef(createAnimatedValue(0)).current,[X,Y]=useState(0),[J,Q]=useState(null),Z=B?e=>Y(e.nativeEvent.layout.width):void 0,$=C??o,ee="outline"===L||"ghost"===L,te=!ee&&!B,oe={color:N.textColor,size:W.icon,disabled:l},re=b&&!B&&Boolean(d),se=k.space.xs,ie=W["min-height"]-2*se-2*N.borderWidth,ne={color:N.badgeInk,size:W["badge-icon"],disabled:l},le=n?_jsx(Spinner,{variant:"circular",size:"sm",color:re?N.badgeInk:N.textColor,accessibilityLabel:O.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,re?ne:oe,u)}):null,ae=_jsxs(View,{style:H.contentRow,children:[re?_jsx(View,{testID:"button-icon-badge",style:[H.iconLeft,H.iconBadge,{width:ie,height:ie,borderRadius:ie/2,backgroundColor:N.badgeFill}],children:le}):le?_jsx(View,{style:H.iconLeft,children:le}):null,_jsxs(View,{onLayout:Z,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[H.label,{color:N.textColor,fontSize:W.text,lineHeight:Math.round(W.text*k.leading.body)},x],children:o}),B?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[H.linkUnderline,{backgroundColor:N.textColor,transform:[{translateX:K.interpolate({inputRange:[0,1],outputRange:[-X/2,0]})},{scaleX:K.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:H.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,oe,u)}):null]}),de=B?null===J?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(J)):touchSlopFor(W["min-height"]),ce={top:de,bottom:de,left:B?LINK_HIT_SLOP:0,right:B?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[P.style,a?H.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!R||z.isFlick(e))return;P.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),S?.(e)},onPressIn:e=>{z.onPressIn(e),P.pressIn(),B&&R&&(K.stopAnimation(),K.setValue(0),Animated.timing(K,{toValue:1,duration:k.motion.duration.slower,easing:Easing.bezier(...k.motion.ease.decelerate),useNativeDriver:!0}).start())},onPressOut:()=>{P.pressOut()},disabled:!R,hitSlop:ce,...hitSlopMarker(ce),accessibilityRole:"button",accessibilityLabel:$,accessibilityHint:I,accessibilityState:V,...ariaFromState(V),testID:v,onLayout:e=>{G.onLayout(e),B&&Q(e.nativeEvent.layout.height)},style:({pressed:e})=>[H.base,{paddingHorizontal:B?0:W["padding-x"],paddingVertical:B?0:re?se:W["padding-y"],paddingLeft:re?se:void 0,minHeight:B?void 0:W["min-height"],borderRadius:q,...smoothCorners,backgroundColor:M||G.active?"transparent":N.backgroundColor,borderWidth:N.borderWidth,borderColor:G.active?"transparent":N.borderColor,opacity:n?.55:1,overflow:G.active||B?"visible":"hidden"},e&&ee&&!G.active?{backgroundColor:k.colors["surface-pressed"]}:null,a?H.fullWidth:null,f],...j,"aria-disabled":!R,"aria-busy":n,children:({pressed:e})=>_jsxs(_Fragment,{children:[G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:e&&ee?k.colors["surface-pressed"]:N.backgroundColor,stroke:N.borderColor,strokeWidth:N.borderWidth}):null,M?_jsx(Gradient,{gradient:M,style:[StyleSheet.absoluteFill,{borderRadius:q,...smoothCorners}]}):null,e&&te?G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:N.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[H.pressedOverlay,{borderRadius:q,backgroundColor:N.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,ae]})})})});Button.displayName="Button";const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};default: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:1},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,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=React.memo(forwardRef((e,t)=>{const{children:i,variant:o,elevation:s="card",radius:a,padding:r,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:x=!1,onCollapsedChange:f,collapsedSummary:S,onRemove:v,separatorHeight:j=StyleSheet.hairlineWidth,footer:C,imageSource:w,imageHeight:_=160,imageAspectRatio:R,imageOverlay:A,loading:F=!1,gradient:T,onPress:k,haptic:I,contextMenu:V,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:P,style:H,containerStyle:z,headerStyle:M,bodyStyle:D,footerStyle:q,testID:E,labels:O,onLayout:W,...N}=e;warnInvalidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),warnInvalidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),warnInvalidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),warnInvalidValue("Card","titleFont",e.titleFont,["sans","serif"]),warnInvalidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=o??U?.defaultVariant??"elevated",$=a??U?.defaultRadius??"lg",J=r??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...O}),[O]),Y=l||"function"==typeof k,Z=useContextMenu(V,{haptic:I||!1,testID:E,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:oe,pressOut:se}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),ae=stylesFor(G),re=Boolean(w),le=G.space[paddingMap[J]],ne=useMemo(()=>T?"string"==typeof T?G.settings.gradients[T]??null:T:null,[T,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:x,onChange:f}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!re&&!ne&&!de,ce,W),xe=StyleSheet.flatten([z,H])??{},fe=xe.backgroundColor,Se=xe.borderColor,ve=fe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),je="outline"===K?G.size.border:0,Ce=Se??G.colors.border,we="none"===s?void 0:G.shadow[s],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Fe=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Te=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:re||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:j,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,re,le,ye.active,ye.size,Re,Ae,ue,j]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:_},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,_]),Ie=u??"",Ve=_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:ae.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:ae.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:I}):p?_jsx(View,{style:ae.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${Ie}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:I}):null,v?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:v,color:G.colors["danger-text"],haptic:I}):null]}),Be=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[ae.header,!c&&ae.headerRow,pe&&ae.headerFolded,M],children:c??Ve}):null,pe?null:_jsx(View,{style:[be||C?ae.body:null,D],children:i}),C&&!pe?_jsx(View,{style:[ae.footer,q],children:C}):null]}),Le=re?_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:ae.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Be})]}):Be,Pe=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Le]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:ve,stroke:je?Ce:void 0,strokeWidth:je}),_jsx(View,{style:[ae.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Le})]}):Le;let He;if(te){const handlePress=e=>{Y&&(I&&triggerHaptic(I),k?.(e))};He=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:oe,onPressOut:se,accessibilityRole:P??(Y?"button":void 0),accessibilityLabel:B,accessibilityHint:L,testID:E,onLayout:ye.onLayout,style:[Te,z,H,Fe],...N,...Z.hostProps,children:Pe})})}else He=_jsx(View,{ref:t,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:P,testID:E,onLayout:ye.onLayout,style:[Te,z,H,Fe],...N,children:Pe});return F?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[He,Z.renderSurface(_jsx(View,{style:[Te,z,H,Fe,ae.preview],children:Pe}))]}):He}));Card.displayName="Card";const CardSkeleton=({variant:e,elevation:t,radius:i,padding:o,bg:s,header:a,footer:r,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),x=y.settings.components.card,f=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",v=o??x?.defaultPadding??"md",j={...DEFAULT_CARD_LABELS,...g},C=paddingMap[v],w=y.space[C],_="flat"===f?y.radius.none:y.radius[S],R=void 0!==a||hasBuiltInHeaderContent(b),A=resolveBackground(y,s)??y.colors.surface,F="outline"===f?1:0,T="outline"===f?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:_,...smoothCorners,borderWidth:F,borderColor:T,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:j.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:w,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:w},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==r?_jsx(View,{style:[{padding:w,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:o,color:s,haptic:a})=>{const r=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===o?void 0:{expanded:o},"aria-expanded":o,onPress:()=>{a&&triggerHaptic(a),i()},style:iconActionStyle,children:_jsx(AppIcon,{name:e,size:20,color:s??r.colors["text-body"]})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return BACKGROUND_TOKENS.includes(t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
|
|
1
|
+
"use strict";import React,{forwardRef,useMemo}from"react";import{Animated,Image,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{fontFor,Gradient,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{squircleHostRadius}from"../../utils/squircle.js";import{themeStyles}from"../../utils/themeStyles.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const BACKGROUND_TOKENS=["bg","bg-subtle","bg-muted","surface","scrim","surface-inverse","primary-wash"];export const DEFAULT_CARD_LABELS=Object.freeze({remove:"Remove",show:"Show",hide:"Hide",loading:"Loading"});const paddingMap={none:"none",sm:"sm",md:"lg",lg:"xl",xl:"2xl"},Card=React.memo(forwardRef((e,t)=>{const{children:i,variant:o,elevation:s="card",radius:a,padding:r,interactive:l=!1,pressAnimation:n="scale",bg:d,header:c,title:u,titleFont:m,lead:h,action:p,headerActions:g,collapsible:b=!1,collapsed:y,defaultCollapsed:x=!1,onCollapsedChange:f,collapsedSummary:S,onRemove:v,separatorHeight:j=StyleSheet.hairlineWidth,footer:C,imageSource:w,imageHeight:_=160,imageAspectRatio:R,imageOverlay:A,loading:F=!1,gradient:T,onPress:k,haptic:V,contextMenu:I,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:H,style:P,containerStyle:z,headerStyle:M,bodyStyle:D,footerStyle:E,testID:q,labels:O,onLayout:W,...N}=e;warnInvalidValue("Card","variant",e.variant,["elevated","outline","filled","flat"]),warnInvalidValue("Card","radius",e.radius,["sm","md","lg","xl","pill"]),warnInvalidValue("Card","padding",e.padding,["none","sm","md","lg","xl"]),warnInvalidValue("Card","titleFont",e.titleFont,["sans","serif"]),warnInvalidValue("Card","pressAnimation",e.pressAnimation,["scale","bounce","fade","sink","pulse","dim","false"]);const G=useTheme(),U=G.settings.components.card,K=o??U?.defaultVariant??"elevated",$=a??U?.defaultRadius??"lg",J=r??U?.defaultPadding??"md",Q=m??U?.defaultTitleFont??"sans",X=useMemo(()=>({...DEFAULT_CARD_LABELS,...O}),[O]),Y=l||"function"==typeof k,Z=useContextMenu(I,{haptic:V||!1,testID:q,accessibilityActions:N.accessibilityActions,onAccessibilityAction:N.onAccessibilityAction}),ee=useMemo(()=>mergeRefs(t,Z.hostRef),[t,Z.hostRef]),te=Y||Z.enabled,{style:ie,pressIn:oe,pressOut:se}=usePressAnimation({preset:n||"scale",enabled:te&&!1!==n}),ae=stylesFor(G),re=Boolean(w),le=G.space[paddingMap[J]],ne=useMemo(()=>T?"string"==typeof T?G.settings.gradients[T]??null:T:null,[T,G.settings.gradients]),de="flat"===K,ce=de?G.radius.none:G.radius[$],ue=resolveBackground(G,d),[me,he]=useControllableState({value:y,defaultValue:x,onChange:f}),pe=b&&me,ge=hasBuiltInHeaderContent(e),be=Boolean(c)||ge,ye=useSquircle(!re&&!ne&&!de,ce,W),xe=StyleSheet.flatten([z,P])??{},fe=xe.backgroundColor,Se=xe.borderColor,ve=fe??ue??("filled"===K?G.colors["bg-subtle"]:G.colors.surface),je="outline"===K?G.size.border:0,Ce=Se??G.colors.border,we="none"===s?void 0:G.shadow[s],Re="elevated"===K&&supportsBoxShadow()&&we?toBoxShadow(we):void 0,Ae=ye.active&&"elevated"===K&&!Re,Fe=ye.active&&!Ae?{backgroundColor:"transparent",borderColor:"transparent"}:null,Te=useMemo(()=>{const e={borderRadius:Ae&&ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce,...smoothCorners,padding:re||ye.active?G.space.none:le,overflow:ye.active?"visible":"hidden"};switch(K){case"flat":return{...e,backgroundColor:ue??G.colors.surface,borderBottomWidth:j,borderBottomColor:G.colors.border};case"outline":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors.surface,borderWidth:G.size.border,borderColor:ye.active?"transparent":G.colors.border};case"filled":return{...e,backgroundColor:ye.active?"transparent":ue??G.colors["bg-subtle"]};default:return{...e,backgroundColor:ue??G.colors.surface,...Re?{boxShadow:Re}:we}}},[G,K,we,ce,re,le,ye.active,ye.size,Re,Ae,ue,j]),ke=useMemo(()=>({..."number"==typeof R?{width:"100%",aspectRatio:R}:{width:"100%",height:_},borderTopLeftRadius:ce,borderTopRightRadius:ce,borderBottomLeftRadius:G.radius.none,borderBottomRightRadius:G.radius.none,...smoothCorners}),[G,ce,R,_]),Ve=u??"",Ie=_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.titleColumn,children:[u?_jsx(Text,{variant:"title",accessibilityRole:"header",style:titleFaceFor(G,Q),children:u}):null,h?_jsx(Text,{variant:"bodySmall",style:ae.lead,children:h}):null,pe&&S?_jsx(Text,{variant:"caption",style:ae.lead,children:S}):null]}),isCardTextAction(p)?_jsx(CardTextActionButton,{action:p,haptic:V}):p?_jsx(View,{style:ae.actionNode,children:p}):null,g,b?_jsx(CardIconAction,{icon:pe?"chevron-down":"chevron-up",label:`${pe?X.show:X.hide} ${Ve}`.trim(),expanded:!pe,onPress:()=>he(!pe),haptic:V}):null,v?_jsx(CardIconAction,{icon:"trash",label:X.remove,onPress:v,color:G.colors["danger-text"],haptic:V}):null]}),Be=_jsxs(_Fragment,{children:[be?_jsx(View,{style:[ae.header,!c&&ae.headerRow,pe&&ae.headerFolded,M],children:c??Ie}):null,pe?null:_jsx(View,{style:[be||C?ae.body:null,D],children:i}),C&&!pe?_jsx(View,{style:[ae.footer,E],children:C}):null]}),Le=re?_jsxs(_Fragment,{children:[_jsxs(View,{style:ae.imageWrapper,children:[_jsx(Image,{source:w,resizeMode:"cover",style:ke,accessibilityLabel:"",accessible:!1}),A?_jsx(View,{pointerEvents:"box-none",style:ae.imageOverlay,children:A}):null]}),_jsx(View,{style:{padding:le},children:Be})]}):Be,He=ne?_jsxs(_Fragment,{children:[_jsx(Gradient,{gradient:ne,style:StyleSheet.absoluteFill}),Le]}):ye.active&&ye.size?_jsxs(_Fragment,{children:[_jsx(SquircleFill,{width:ye.size.width,height:ye.size.height,radius:ce,fill:ve,stroke:je?Ce:void 0,strokeWidth:je}),_jsx(View,{style:[ae.squircleClip,{padding:le,borderRadius:ye.size?squircleHostRadius(ye.size.width,ye.size.height,ce):ce}],children:Le})]}):Le;let Pe;if(te){const handlePress=e=>{Y&&(V&&triggerHaptic(V),k?.(e))};Pe=_jsx(Animated.View,{style:ie,children:_jsx(Pressable,{ref:ee,onPress:handlePress,onPressIn:oe,onPressOut:se,accessibilityRole:H??(Y?"button":void 0),accessibilityLabel:B,accessibilityHint:L,testID:q,onLayout:ye.onLayout,style:[Te,z,P,Fe],...N,...Z.hostProps,children:He})})}else Pe=_jsx(View,{ref:t,accessibilityLabel:B,accessibilityHint:L,accessibilityRole:H,testID:q,onLayout:ye.onLayout,style:[Te,z,P,Fe],...N,children:He});return F?_jsx(CardSkeleton,{...e}):Z.enabled?_jsxs(_Fragment,{children:[Pe,Z.renderSurface(_jsx(View,{style:[Te,z,P,Fe,ae.preview],children:He}))]}):Pe}));Card.displayName="Card";const CardSkeleton=({variant:e,elevation:t,radius:i,padding:o,bg:s,header:a,footer:r,imageSource:l,imageHeight:n=160,imageAspectRatio:d,containerStyle:c,headerStyle:u,bodyStyle:m,footerStyle:h,style:p,labels:g,...b})=>{const y=useTheme(),x=y.settings.components.card,f=e??x?.defaultVariant??"elevated",S=i??x?.defaultRadius??"lg",v=o??x?.defaultPadding??"md",j={...DEFAULT_CARD_LABELS,...g},C=paddingMap[v],w=y.space[C],_="flat"===f?y.radius.none:y.radius[S],R=void 0!==a||hasBuiltInHeaderContent(b),A=resolveBackground(y,s)??y.colors.surface,F="outline"===f?1:0,T="outline"===f?y.colors.border:void 0;return _jsxs(View,{style:[{backgroundColor:A,borderRadius:_,...smoothCorners,borderWidth:F,borderColor:T,overflow:"hidden"},c,p],accessibilityRole:"progressbar",accessibilityLabel:j.loading,accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==l?_jsx(Skeleton,{width:"100%",height:d?void 0:n,style:d?{aspectRatio:d,width:"100%"}:void 0}):null,R?_jsx(View,{style:[{padding:w,paddingBottom:y.space.sm},u],children:_jsx(Skeleton,{shape:"text",width:"60%",height:18})}):null,_jsx(View,{style:[{padding:w},m],children:_jsx(SkeletonText,{lines:3,fontSize:y.text.base.size,lastLineWidth:"55%"})}),void 0!==r?_jsx(View,{style:[{padding:w,paddingTop:y.space.sm,flexDirection:"row"},h],children:_jsx(Skeleton,{width:88,height:32,shape:"rounded"})}):null]})};CardSkeleton.displayName="CardSkeleton",Card.Skeleton=CardSkeleton;const hasBuiltInHeaderContent=e=>Boolean(e.title||e.lead||e.action||e.headerActions||e.collapsible||e.onRemove),isCardTextAction=e=>"object"==typeof e&&null!==e&&!React.isValidElement(e)&&"label"in e&&"onPress"in e,HIT_TARGET=44,CardIconAction=({icon:e,label:t,onPress:i,expanded:o,color:s,haptic:a})=>{const r=useTheme();return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:t,accessibilityState:void 0===o?void 0:{expanded:o},"aria-expanded":o,onPress:()=>{a&&triggerHaptic(a),i()},style:iconActionStyle,children:_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:e,size:20,color:s??r.colors["text-body"]})})})},CardTextActionButton=({action:e,haptic:t})=>_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.accessibilityLabel??e.label,onPress:()=>{t&&triggerHaptic(t),e.onPress()},style:textActionStyle,children:_jsx(Text,{variant:"label",weight:"semibold",color:"brand",children:e.label})}),iconActionStyle={width:44,height:44,alignItems:"center",justifyContent:"center"},textActionStyle={minWidth:44,minHeight:44,alignItems:"center",justifyContent:"center"},titleFaceFor=(e,t)=>"serif"===t?fontFor(e,"semibold","display"):{fontFamily:void 0,...fontFor(e,"semibold")},resolveBackground=(e,t)=>{if(null!=t)return BACKGROUND_TOKENS.includes(t)?e.colors[t]:t},buildStyles=e=>StyleSheet.create({header:{marginBottom:e.space.md},headerRow:{flexDirection:"row",alignItems:"center",gap:e.space.sm},headerFolded:{marginBottom:e.space.none},titleColumn:{flex:1},lead:{marginTop:e.space.xs},actionNode:{flexShrink:0},body:{flexShrink:1},footer:{marginTop:e.space.md},imageWrapper:{position:"relative"},imageOverlay:{...StyleSheet.absoluteFill},squircleClip:{flexGrow:1,overflow:"hidden",...smoothCorners},preview:{margin:e.space.none,marginTop:e.space.none,marginBottom:e.space.none,marginLeft:e.space.none,marginRight:e.space.none,marginStart:e.space.none,marginEnd:e.space.none,marginHorizontal:e.space.none,marginVertical:e.space.none,position:"relative",top:0,left:0,width:"100%",height:"100%"}}),stylesFor=themeStyles(buildStyles);export{Card};export default Card;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{resolveChipSize,useTheme}from"../../theme/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CHIP_LABELS=Object.freeze({remove:e=>`Remove ${e}`});const toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors["primary-soft"],on:e.colors.primary,ink:e.colors["primary-text"],border:e.colors.primary,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"success":return{base:e.colors["bg-muted"],on:e.colors.success,ink:e.colors["success-text"],border:e.colors.success,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"warning":return{base:e.colors["bg-muted"],on:e.colors.warning,ink:e.colors["warning-text"],border:e.colors.warning,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"danger":return{base:e.colors["bg-muted"],on:e.colors.danger,ink:e.colors["danger-text"],border:e.colors.danger,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"info":return{base:e.colors["bg-muted"],on:e.colors.info,ink:e.colors["info-text"],border:e.colors.info,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};default:return{base:e.colors["bg-muted"],on:e.colors["text-body"],ink:e.colors["text-body"],border:e.colors.border,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,r)=>{const{label:s,count:t,selected:o=!1,selectionMode:i="single",onPress:l,onRemove:n,leftIcon:a,iconVariant:c,variant:d="soft",tone:p="neutral",size:m="md",disabled:u=!1,loading:h=!1,accessibilityLabel:b,haptic:y,style:g,textStyle:f,containerStyle:x,countStyle:S,closeButtonStyle:C,closeIconStyle:I,labels:k,removeTestID:v,testID:j}=e;warnInvalidValue("Chip","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("Chip","tone",e.tone,["primary","neutral","success","warning","danger","info"]),warnInvalidValue("Chip","size",e.size,["sm","md"]),warnInvalidValue("Chip","selectionMode",e.selectionMode,["single","multiple","radio"]);const w=useTheme(),_=useMemo(()=>({...DEFAULT_CHIP_LABELS,...k}),[k]),z=!!l&&!u,L="radio"===i,B=!!l&&(!u||L),O=hasChipCount(t),{style:M,pressIn:T,pressOut:P}=usePressAnimation({enabled:z}),
|
|
1
|
+
"use strict";import{forwardRef,useMemo}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{resolveChipSize,useTheme}from"../../theme/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CHIP_LABELS=Object.freeze({remove:e=>`Remove ${e}`});const toneFor=(e,r)=>{switch(r){case"primary":return{base:e.colors["primary-soft"],on:e.colors.primary,ink:e.colors["primary-text"],border:e.colors.primary,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"success":return{base:e.colors["bg-muted"],on:e.colors.success,ink:e.colors["success-text"],border:e.colors.success,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"warning":return{base:e.colors["bg-muted"],on:e.colors.warning,ink:e.colors["warning-text"],border:e.colors.warning,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"danger":return{base:e.colors["bg-muted"],on:e.colors.danger,ink:e.colors["danger-text"],border:e.colors.danger,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};case"info":return{base:e.colors["bg-muted"],on:e.colors.info,ink:e.colors["info-text"],border:e.colors.info,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary};default:return{base:e.colors["bg-muted"],on:e.colors["text-body"],ink:e.colors["text-body"],border:e.colors.border,selectedBg:e.colors["primary-soft"],selectedOn:e.colors.primary,selectedInk:e.colors["primary-text"],selectedBorder:e.colors.primary}}},SOFT_FILL_OPACITY=.14,SOFT_SELECTED_FILL_OPACITY=.24,hasChipCount=e=>null!=e&&""!==e,Chip=forwardRef((e,r)=>{const{label:s,count:t,selected:o=!1,selectionMode:i="single",onPress:l,onRemove:n,leftIcon:a,iconVariant:c,variant:d="soft",tone:p="neutral",size:m="md",disabled:u=!1,loading:h=!1,accessibilityLabel:b,haptic:y,style:g,textStyle:f,containerStyle:x,countStyle:S,closeButtonStyle:C,closeIconStyle:I,labels:k,removeTestID:v,testID:j}=e;warnInvalidValue("Chip","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("Chip","tone",e.tone,["primary","neutral","success","warning","danger","info"]),warnInvalidValue("Chip","size",e.size,["sm","md"]),warnInvalidValue("Chip","selectionMode",e.selectionMode,["single","multiple","radio"]);const w=useTheme(),_=useMemo(()=>({...DEFAULT_CHIP_LABELS,...k}),[k]),z=!!l&&!u,L="radio"===i,B=!!l&&(!u||L),O=hasChipCount(t),{style:M,pressIn:T,pressOut:P}=usePressAnimation({enabled:z}),A=useMemo(()=>toneFor(w,p),[w,p]),V=useMemo(()=>resolveChipSize(w,m),[w,m]),H=Math.max(0,Math.ceil((44-V["min-height"])/2)),R=L?{top:H,bottom:H}:void 0,D="solid"===d,F="soft"===d,E=(()=>{if(F){const e=o?A.selectedOn:A.on;return tintOf(e,o?.24:.14,o?A.selectedBg:A.base)}return o?D?A.selectedBg:"transparent":D?A.base:"transparent"})(),U=F?"transparent":o?A.selectedBorder:D?"transparent":A.border,$=u?w.colors["text-disabled"]:o?F?w.colors["text-body"]:A.selectedInk:A.ink,N=D||F?0:w.size.border,handlePress=()=>{if(!z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),l?.()},Y=b??(O?`${s}, ${t}`:s),W=_jsxs(View,{style:styles.row,children:[a?_jsx(View,{style:{marginRight:V.gap},accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(a,{color:$,size:V.icon,disabled:u},c)}):null,_jsx(Text,{variant:"label",weight:"medium",numberOfLines:1,style:[styles.label,{color:$,fontSize:V.text,lineHeight:Math.round(V.text*w.leading.body)},f],children:s??" "}),O?_jsx(Text,{variant:"caption",numberOfLines:1,style:[styles.count,{color:$,fontSize:Math.min(w.text.xs.size,V.text),marginLeft:w.space.xs},S],children:t}):null,n?_jsx(Pressable,{onPress:()=>{u||(!1!==y&&triggerHaptic("impactLight"),n?.())},disabled:u,accessibilityRole:"button",accessibilityLabel:_.remove(s),accessibilityState:{disabled:u},"aria-disabled":u,testID:v,hitSlop:6,...hitSlopMarker(6),style:({pressed:e})=>[styles.close,{width:V["close-size"],height:V["close-size"],borderRadius:V["close-size"]/2,...smoothCorners,marginLeft:V.gap,backgroundColor:e?w.colors["surface-pressed"]:w.colors["surface-hover"]},C],children:_jsx(Text,{variant:"label",weight:"bold",maxFontSizeMultiplier:1,style:[{color:$,fontSize:V["close-text"],lineHeight:V["close-text"]+2},I],children:"×"})}):null]}),q={paddingHorizontal:V["padding-x"],paddingVertical:V["padding-y"],minHeight:V["min-height"],borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden",backgroundColor:E,borderWidth:N,borderColor:U,opacity:u?.55:1};let G;return G=B?_jsx(Animated.View,{style:[M,{alignSelf:"flex-start",borderRadius:w.radius.pill,...smoothCorners,overflow:"hidden"}],children:_jsx(Pressable,{ref:r,onPress:handlePress,onPressIn:T,onPressOut:P,disabled:!z,accessibilityRole:L?"radio":"multiple"===i?"checkbox":"button",accessibilityLabel:Y,accessibilityState:L||"multiple"===i?{checked:o,disabled:u}:{selected:o,disabled:u},"aria-checked":L||"multiple"===i?o:void 0,"aria-selected":L||"multiple"===i?void 0:o,"aria-disabled":u,hitSlop:R,...R?hitSlopMarker(R):{},android_ripple:{color:w.colors["surface-pressed"],borderless:!1},testID:j,style:({pressed:e})=>[styles.base,q,e&&"outline"===d?{backgroundColor:w.colors["surface-pressed"]}:null,x,g],children:W})}):_jsx(View,{ref:r,style:[styles.base,q,x,g],accessible:!0,accessibilityRole:"text",accessibilityLabel:Y,accessibilityState:{selected:o,disabled:u},"aria-selected":o,"aria-disabled":u,testID:j,children:W}),h?_jsx(ChipSkeleton,{...e}):G});Chip.displayName="Chip";const ChipSkeleton=({label:e,count:r,size:s="md",leftIcon:t,onRemove:o,style:i,containerStyle:l})=>{const n=useTheme(),a=resolveChipSize(n,s),c=Math.max(40,Math.min(120,7*(e??"").length)),d=a["min-height"],p=d/2,m=c+2*a["padding-x"]+(hasChipCount(r)?a.gap/2+7*String(r).length:0)+(void 0!==t?a.gap+14:0)+(void 0!==o?a.gap+a["close-size"]:0);return _jsx(Skeleton,{width:m,height:d,radius:p,style:[{alignSelf:"flex-start"},l,i]})};ChipSkeleton.displayName="ChipSkeleton",Chip.Skeleton=ChipSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},row:{flexDirection:"row",alignItems:"center"},label:{flexShrink:1,textAlign:"center"},count:{flexShrink:0,fontVariant:["tabular-nums"]},close:{alignItems:"center",justifyContent:"center"}});export{Chip};export default Chip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),ChoiceGroup=forwardRef((e,i)=>{const{options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:l,getOptionDescription:
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useMemo}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"../Radio/RadioDot.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const sizeTokensOf=e=>({sm:{paddingHorizontal:e.space.sm,chipPaddingHorizontal:e.space.md,paddingVertical:e.space.xs,fontSize:e.text.sm.size,minHeight:32,iconSize:14},md:{paddingHorizontal:e.space.md,chipPaddingHorizontal:e.space.lg,paddingVertical:e.space.sm,fontSize:e.text.base.size,minHeight:40,iconSize:16},lg:{paddingHorizontal:e.space.lg,chipPaddingHorizontal:e.space.xl,paddingVertical:e.space.md,fontSize:e.text.lg.size,minHeight:48,iconSize:18}}),ChoiceGroup=forwardRef((e,i)=>{const{options:o,getOptionLabel:t,getOptionValue:r,isOptionDisabled:l,getOptionDescription:s,getOptionIcon:a,getOptionColor:n,renderOption:d,variant:c="card",indicatorPosition:p="trailing",direction:u="row",gap:m,wrap:h=!1,fullWidth:g,disabled:b=!1,size:x="md",labelLines:f,descriptionLines:y=2,haptic:z,accessibilityLabel:C,style:j,optionStyle:S,description:v,helperText:w,error:H,testID:V}=e,T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),k=useMemo(()=>sizeTokensOf(T)[x],[T,x]);warnInvalidValue("ChoiceGroup","variant",e.variant,["card","chip"]),warnInvalidValue("ChoiceGroup","size",e.size,["sm","md","lg"]),warnInvalidValue("ChoiceGroup","direction",e.direction,["row","column"]),warnInvalidValue("ChoiceGroup","indicatorPosition",e.indicatorPosition,["leading","trailing"]),warnInvalidValue("ChoiceGroup","selectionMode",e.selectionMode,["single","multiple"]);const I=useCallback(e=>t?t(e):e.label??"",[t]),D=useCallback(e=>r?r(e):e.value,[r]),O=useCallback(e=>l?l(e):!0===e.disabled,[l]),G=useCallback(e=>s?s(e):e.description,[s]),L=useCallback(e=>a?a(e):e.icon,[a]),M=useCallback(e=>n?n(e):e.color,[n]),P="multiple"===e.selectionMode,{min:R,max:F}=e,[W,A]=useControllableState({value:e.value,defaultValue:e.defaultValue??(P?[]:void 0),onChange:e.onChange}),B=Array.isArray(W)?W:[],E=useCallback(e=>{const i=D(e);if(P){const e=B.includes(i);if(e&&null!=R&&B.length<=R)return;if(!e&&null!=F&&B.length>=F)return;const o=resolveHaptic(z,"selection");return o&&triggerHaptic(o),void A(e?B.filter(e=>e!==i):[...B,i])}const o=resolveHaptic(z,"selection");o&&triggerHaptic(o),A(i)},[z,P,R,F,B,A,D]),$=g??("card"===c&&"row"===u&&!h),N=h||$&&"row"===u,q=T.radius.md,surfaceFor=(e,i,o)=>i?{borderColor:T.colors.border,backgroundColor:T.colors["surface-disabled"]}:{borderColor:e?o:T.colors.border,backgroundColor:e?tintOf(o,.12,T.colors["surface-selected"]):T.colors.bg},renderIcon=(e,i,o,t)=>{const r=L(e);if(null==r)return null;return renderSlotIcon("string"==typeof r&&i?{name:r,variant:"bold"}:r,{color:o,size:k.iconSize,disabled:t})},renderChip=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=t?T.colors["text-disabled"]:o?r:T.colors["text-body"],s=renderIcon(i,o,l,t);return _jsxs(View,{style:[_.chip,{minHeight:k.minHeight,paddingHorizontal:k.chipPaddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:T.radius.pill,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.xs}],children:[s?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:l,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)})]})},renderDefaultCard=e=>{const{option:i,selected:o,disabled:t,color:r}=e,l=M(i),s=t?T.colors["text-disabled"]:l??T.colors["text-body"],a=G(i),n=renderIcon(i,o,s,t),d=_jsx(RadioDot,{selected:o,color:r,disabled:t,size:x});return _jsxs(View,{style:[_.card,{minHeight:k.minHeight,paddingHorizontal:k.paddingHorizontal,paddingVertical:k.paddingVertical,borderRadius:q,...smoothCorners,borderWidth:T.size.border,...surfaceFor(o,t,r),columnGap:T.space.sm}],children:["leading"===p?d:null,n?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:n}):null,_jsxs(View,{style:_.cardTextWrap,children:[_jsx(Text,{weight:"medium",numberOfLines:f,ellipsizeMode:"tail",style:[_.cardLabel,{color:s,fontSize:k.fontSize,lineHeight:Math.round(k.fontSize*T.leading.body)}],children:I(i)}),a?_jsx(Text,{numberOfLines:y,ellipsizeMode:"tail",style:[_.cardDescription,{color:o?T.colors["text-muted"]:T.colors["text-subtle"],fontSize:T.text.xs.size,lineHeight:Math.round(T.text.xs.size*T.leading.body)}],children:a}):null]}),"trailing"===p?d:null]})},J="string"==typeof H&&""!==H?H:void 0,K=!0===H||void 0!==J?null:w,Q=_jsx(View,{ref:i,accessibilityRole:P?void 0:"radiogroup",accessibilityLabel:C,accessibilityState:{disabled:b},"aria-disabled":b,testID:V,style:[{flexDirection:u,gap:m??T.space.sm,flexWrap:N?"wrap":"nowrap"},j],children:o.map((e,i)=>{const o=D(e),t=P?B.includes(o):W===o,r=P&&null!=F&&!t&&B.length>=F,l=b||r||O(e),s=M(e)??T.colors.primary,a=d||"card"!==c?void 0:G(e);return _jsx(Pressable,{testID:e.testID,onPress:()=>{l||E(e)},disabled:l,accessibilityRole:P?"checkbox":"radio",accessibilityLabel:a?`${I(e)}, ${a}`:I(e),accessibilityState:{checked:t,disabled:l},"aria-checked":t,"aria-disabled":l,style:[$?_.stretchOption:null,{opacity:l&&d?.55:1},S],children:({pressed:o})=>{const r={option:e,index:i,selected:t,pressed:o&&!l,disabled:l,color:s};return _jsx(_Fragment,{children:d?d(r):"chip"===c?renderChip(r):renderDefaultCard(r)})}},String(o))})});return hasChoiceDetail({description:v,error:J,helperText:K??void 0})?_jsxs(View,{children:[v?_jsx(Text,{variant:"bodySmall",color:"secondary",style:{marginBottom:T.space.xs},children:v}):null,Q,void 0!==J?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",style:{marginTop:T.space.xs},children:J}):K?_jsx(Text,{variant:"caption",color:"tertiary",style:{marginTop:T.space.xs},children:K}):null]}):Q});ChoiceGroup.displayName="ChoiceGroup";const buildStyles=e=>StyleSheet.create({stretchOption:{flexGrow:1,flexShrink:0,flexBasis:"auto"},card:{flexDirection:"row",alignItems:"center"},chip:{flexDirection:"row",alignItems:"center",justifyContent:"center"},cardTextWrap:{flexGrow:1,flexShrink:1,flexBasis:"auto"},cardLabel:{includeFontPadding:!1},cardDescription:{includeFontPadding:!1,marginTop:e.space.xxs}});export{ChoiceGroup};export default ChoiceGroup;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Calendar}from"../Calendar/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36;export const DEFAULT_DATE_PICKER_LABELS=Object.freeze({title:"Select Date",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss",previousMonth:"Previous month",nextMonth:"Next month",previousYears:"Previous years",nextYears:"Next years",previousDecades:"Previous decades",nextDecades:"Next decades",switchToYears:"switch to year selection",switchToDecades:"switch to decade selection",year:e=>`Year ${e}`,decade:(e,t)=>`Decade ${e} to ${t}`});const GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:s,minDate:r,maxDate:i,disabledDates:o,inline:l=!1,locale:n="en-IN",weekStartsOn:c=0,title:d,labels:u,style:g,containerStyle:m,headerLabelStyle:h,navButtonStyle:y,footerButtonStyle:b,haptic:p,testID:x,label:f,help:D,placeholder:v,helperText:C,error:w,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:P,leftIcon:R,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,triggerLabels:E,formatValue:F}=e,Y=l?"inline":"modal",z=useMemo(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),H=void 0!==e.open,[$,N]=useState(!1),O=H?e.open:$,W=H?x:x?`${x}-calendar`:void 0,G=useTheme(),U=usePresenceMotion(),[q,K]=useModalInsets(),Z=useMemo(()=>buildStyles(G),[G]),[X,J]=useState(()=>startOfDay(new Date));useEffect(()=>{O&&J(startOfDay(new Date))},[O]);const Q=t?startOfDay(t):X,[ee,te]=useState(Q),[ae,se]=useState(t?startOfDay(t):null),[re,ie]=useState("days"),oe=useRef(createAnimatedValue(0)).current,le=useRef(0),ne=useRef(createAnimatedValue(1)).current,ce=useRef(createAnimatedValue(1)).current,de=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);se(e),te(e)}else se(null)},[t]);const ue=useMemo(()=>r?startOfDay(r):null,[r]),ge=useMemo(()=>i?startOfDay(i):null,[i]),me=useMemo(()=>buildYearCells(ee.getFullYear()),[ee]),he=useMemo(()=>buildDecadeCells(ee.getFullYear()),[ee]),ye=useMemo(()=>{if("years"===re){return`${me[0]} - ${me[me.length-1]}`}return`${he[0]} - ${he[he.length-1]+9}`},[he,re,me]),be=useCallback(e=>!!(ue&&e<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),pe=useCallback(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),xe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[re,p]),fe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[re,p]),De=useCallback(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):G.motion.duration.default;setNativeValue(ne,0),setNativeValue(ce,e),Animated.parallel([Animated.timing(ne,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ce,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[ne,ce,U,G.motion.duration.default]),ve=useCallback(()=>{const e=resolveHaptic(p,"selection");if(e&&triggerHaptic(e),!U.reduced){const e=80,t=100;Animated.sequence([Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(de,{toValue:1,duration:t,useNativeDriver:!0})]).start()}ie(e=>"days"===e?"years":"years"===e?"decades":"years"),De()},[De,de,p,U.reduced]),Ce=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e,t.getMonth(),1)),ie("days"),De()},[De,p]),we=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e+4,t.getMonth(),1)),ie("years"),De()},[De,p]),je=useCallback(e=>{se(e.start)},[]),Se=useCallback(()=>{H||N(!1),s?.()},[H,s]),{handleGesture:Te,opacity:Me}=useDragToDismiss({drag:oe,travel:()=>le.current||320,onDismiss:Se});useEffect(()=>{O&&"modal"===Y&&(setNativeValue(oe,0),setNativeValue(Me,1))},[O,Y,oe,Me]);const Pe=useCallback(()=>{!1!==p&&triggerHaptic("selection"),Se()},[Se,p]),Re=useCallback(()=>{ae&&(!1!==p&&triggerHaptic("notificationSuccess"),a?.(ae),Se())},[Se,a,ae,p]),ke=_jsx(View,{style:Z.titleRow,children:_jsx(Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??z.title})}),Ae=_jsxs(View,{style:[Z.card,m,g],accessibilityRole:"modal"===Y?void 0:"none",accessible:!1,testID:W,children:["modal"===Y?_jsx(GestureDetector,{gesture:Te,children:_jsxs(View,{style:Z.grabArea,children:[_jsx(View,{style:Z.handle}),ke]})}):ke,"days"!==re?_jsxs(View,{style:Z.headerRow,children:[_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.previousYears:z.previousDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"‹"})}),_jsx(Pressable,{onPress:ve,style:[Z.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===re?z.switchToDecades:z.switchToYears}`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[_jsx(Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),_jsx(View,{style:Z.headerCaret,children:(G.settings.icons.chevronDown??defaultIcons.chevronDown)({size:G.text.sm.size,color:G.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:fe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.nextYears:z.nextDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===re?_jsx(Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:je,month:ee,onMonthChange:te,minDate:r,maxDate:i,disabledDates:o,weekStartsOn:c,locale:n,haptic:p,headerLabelStyle:h,navButtonStyle:y,onTitlePress:ve,labels:{previousMonth:z.previousMonth,nextMonth:z.nextMonth},testID:W?`${W}-grid`:void 0}):_jsx(Animated.View,"years"===re?{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=be(e),a=!!ae&&ae.getFullYear()===e,s=X.getFullYear()===e,r=a?G.colors.primary:"transparent",i=s&&!a?G.colors.primary:"transparent",o=a?G.colors["on-primary"]:t?G.colors["text-disabled"]:G.colors["text-body"],l=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:z.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:_jsx(View,{style:[Z.yearInner,{backgroundColor:r,borderColor:i,borderWidth:s&&!a?1.5:0,opacity:l}],children:_jsx(Text,{style:[Z.yearText,{color:o}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e[0]}`))}:{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=pe(e),s=!!ae&&decadeStartFor(ae.getFullYear())===e,r=decadeStartFor(X.getFullYear())===e,i=s?G.colors.primary:"transparent",o=r&&!s?G.colors.primary:"transparent",l=s?G.colors["on-primary"]:a?G.colors["text-disabled"]:G.colors["text-body"],n=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:z.decade(e,t),accessibilityState:{selected:s,disabled:a},"aria-selected":s,"aria-disabled":a,style:Z.yearCell,children:_jsxs(View,{style:[Z.yearInner,{backgroundColor:i,borderColor:o,borderWidth:r&&!s?1.5:0,opacity:n}],children:[_jsx(Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),_jsx(Text,{variant:"caption",style:[Z.decadeRangeText,{color:s?G.colors["on-primary"]:G.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e[0]}`))}),_jsxs(View,{style:Z.footer,children:[_jsx(Pressable,{onPress:Pe,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:z.cancel,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["text-muted"]}],variant:"label",weight:"semibold",children:z.cancel})}),_jsx(Pressable,{onPress:Re,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:G.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:G.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:z.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["on-primary"]}],variant:"label",weight:"semibold",children:z.confirm})})]})]}),Ie=t?(F??(e=>e.toLocaleDateString()))(t):void 0,Ve=!H,Le={label:f,help:D,placeholder:v,helperText:C,error:w,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:P,leftIcon:R,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,labels:E};if("inline"===Y)return O||Ve?Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),O?Ae:null]}):Ae:null;const Be=_jsx(Modal,{open:O,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:z.dismiss},onInsetsChange:K,children:_jsx(GestureHandlerRootView,{children:_jsx(Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(q.bottom,G.space.lg),opacity:Me,transform:[{translateY:oe}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ae})})});return Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),Be]}):Be},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,lineHeight:Math.round(e.text.lg.size*e.leading.body),fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},gridRow:{flexDirection:"row"},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,lineHeight:Math.round(e.text.base.size*e.leading.body),fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,lineHeight:Math.round(e.text.xs.size*e.leading.body),fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Calendar}from"../Calendar/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36;export const DEFAULT_DATE_PICKER_LABELS=Object.freeze({title:"Select Date",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss",previousMonth:"Previous month",nextMonth:"Next month",previousYears:"Previous years",nextYears:"Next years",previousDecades:"Previous decades",nextDecades:"Next decades",switchToYears:"switch to year selection",switchToDecades:"switch to decade selection",year:e=>`Year ${e}`,decade:(e,t)=>`Decade ${e} to ${t}`});const GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:s,minDate:r,maxDate:i,disabledDates:o,inline:l=!1,locale:n="en-IN",weekStartsOn:c=0,title:d,labels:u,style:g,containerStyle:m,headerLabelStyle:h,navButtonStyle:y,footerButtonStyle:b,haptic:p,testID:x,label:f,help:D,placeholder:v,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,triggerLabels:E,formatValue:F}=e,Y=l?"inline":"modal",z=useMemo(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),H=void 0!==e.open,[$,N]=useState(!1),O=H?e.open:$,W=H?x:x?`${x}-calendar`:void 0,G=useTheme(),U=usePresenceMotion(),[q,K]=useModalInsets(),Z=useMemo(()=>buildStyles(G),[G]),[X,J]=useState(()=>startOfDay(new Date));useEffect(()=>{O&&J(startOfDay(new Date))},[O]);const Q=t?startOfDay(t):X,[ee,te]=useState(Q),[ae,se]=useState(t?startOfDay(t):null),[re,ie]=useState("days"),oe=useRef(createAnimatedValue(0)).current,le=useRef(0),ne=useRef(createAnimatedValue(1)).current,ce=useRef(createAnimatedValue(1)).current,de=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);se(e),te(e)}else se(null)},[t]);const ue=useMemo(()=>r?startOfDay(r):null,[r]),ge=useMemo(()=>i?startOfDay(i):null,[i]),me=useMemo(()=>buildYearCells(ee.getFullYear()),[ee]),he=useMemo(()=>buildDecadeCells(ee.getFullYear()),[ee]),ye=useMemo(()=>{if("years"===re){return`${me[0]} - ${me[me.length-1]}`}return`${he[0]} - ${he[he.length-1]+9}`},[he,re,me]),be=useCallback(e=>!!(ue&&e<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),pe=useCallback(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),xe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[re,p]),fe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[re,p]),De=useCallback(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):G.motion.duration.default;setNativeValue(ne,0),setNativeValue(ce,e),Animated.parallel([Animated.timing(ne,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ce,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[ne,ce,U,G.motion.duration.default]),ve=useCallback(()=>{const e=resolveHaptic(p,"selection");if(e&&triggerHaptic(e),!U.reduced){const e=80,t=100;Animated.sequence([Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(de,{toValue:1,duration:t,useNativeDriver:!0})]).start()}ie(e=>"days"===e?"years":"years"===e?"decades":"years"),De()},[De,de,p,U.reduced]),we=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e,t.getMonth(),1)),ie("days"),De()},[De,p]),Ce=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e+4,t.getMonth(),1)),ie("years"),De()},[De,p]),je=useCallback(e=>{se(e.start)},[]),Se=useCallback(()=>{H||N(!1),s?.()},[H,s]),{handleGesture:Te,opacity:Me}=useDragToDismiss({drag:oe,travel:()=>le.current||320,onDismiss:Se});useEffect(()=>{O&&"modal"===Y&&(setNativeValue(oe,0),setNativeValue(Me,1))},[O,Y,oe,Me]);const Re=useCallback(()=>{!1!==p&&triggerHaptic("selection"),Se()},[Se,p]),Pe=useCallback(()=>{ae&&(!1!==p&&triggerHaptic("notificationSuccess"),a?.(ae),Se())},[Se,a,ae,p]),ke=_jsx(View,{style:Z.titleRow,children:_jsx(Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??z.title})}),Ae=_jsxs(View,{style:[Z.card,m,g],accessibilityRole:"modal"===Y?void 0:"none",accessible:!1,testID:W,children:["modal"===Y?_jsx(GestureDetector,{gesture:Te,children:_jsxs(View,{style:Z.grabArea,children:[_jsx(View,{style:Z.handle}),ke]})}):ke,"days"!==re?_jsxs(View,{style:Z.headerRow,children:[_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.previousYears:z.previousDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"‹"})}),_jsx(Pressable,{onPress:ve,style:[Z.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===re?z.switchToDecades:z.switchToYears}`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[_jsx(Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),_jsx(View,{style:Z.headerCaret,children:(G.settings.icons.chevronDown??defaultIcons.chevronDown)({size:G.text.sm.size,color:G.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:fe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.nextYears:z.nextDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===re?_jsx(Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:je,month:ee,onMonthChange:te,minDate:r,maxDate:i,disabledDates:o,weekStartsOn:c,locale:n,haptic:p,headerLabelStyle:h,navButtonStyle:y,onTitlePress:ve,labels:{previousMonth:z.previousMonth,nextMonth:z.nextMonth},testID:W?`${W}-grid`:void 0}):_jsx(Animated.View,"years"===re?{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=be(e),a=!!ae&&ae.getFullYear()===e,s=X.getFullYear()===e,r=a?G.colors.primary:"transparent",i=s&&!a?G.colors.primary:"transparent",o=a?G.colors["on-primary"]:t?G.colors["text-disabled"]:G.colors["text-body"],l=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:z.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:_jsx(View,{style:[Z.yearInner,{backgroundColor:r,borderColor:i,borderWidth:s&&!a?1.5:0,opacity:l}],children:_jsx(Text,{style:[Z.yearText,{color:o}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e[0]}`))}:{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=pe(e),s=!!ae&&decadeStartFor(ae.getFullYear())===e,r=decadeStartFor(X.getFullYear())===e,i=s?G.colors.primary:"transparent",o=r&&!s?G.colors.primary:"transparent",l=s?G.colors["on-primary"]:a?G.colors["text-disabled"]:G.colors["text-body"],n=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:z.decade(e,t),accessibilityState:{selected:s,disabled:a},"aria-selected":s,"aria-disabled":a,style:Z.yearCell,children:_jsxs(View,{style:[Z.yearInner,{backgroundColor:i,borderColor:o,borderWidth:r&&!s?1.5:0,opacity:n}],children:[_jsx(Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),_jsx(Text,{variant:"caption",style:[Z.decadeRangeText,{color:s?G.colors["on-primary"]:G.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e[0]}`))}),_jsxs(View,{style:Z.footer,children:[_jsx(Pressable,{onPress:Re,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:z.cancel,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["text-muted"]}],variant:"label",weight:"semibold",children:z.cancel})}),_jsx(Pressable,{onPress:Pe,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:G.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:G.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:z.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["on-primary"]}],variant:"label",weight:"semibold",children:z.confirm})})]})]}),Ie=t?(F??(e=>e.toLocaleDateString()))(t):void 0,Ve=!H,Le={label:f,help:D,placeholder:v,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,labels:E};if("inline"===Y)return O||Ve?Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),O?Ae:null]}):Ae:null;const Be=_jsx(Modal,{open:O,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:z.dismiss},onInsetsChange:K,children:_jsx(GestureHandlerRootView,{style:Z.gestureRoot,children:_jsx(Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(q.bottom,G.space.lg),opacity:Me,transform:[{translateY:oe}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ae})})});return Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),Be]}):Be},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,lineHeight:Math.round(e.text.lg.size*e.leading.body),fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},gridRow:{flexDirection:"row"},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,lineHeight:Math.round(e.text.base.size*e.leading.body),fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,lineHeight:Math.round(e.text.xs.size*e.leading.body),fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Calendar}from"../Calendar/index.js";import{daysBetween,startOfDay,startOfMonth}from"../Calendar/calendarDates.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_DATE_RANGE_PICKER_LABELS=Object.freeze({title:"Select Date Range",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss"});const formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=forwardRef((e,t)=>{const{open:a,value:s,onChange:r,onClose:o,label:i,help:l,placeholder:n,helperText:d,error:c,required:m,disabled:u,size:g,variant:f,clearable:h,onClear:p,leftIcon:b,trailing:y,triggerStyle:x,valueStyle:D,labelStyle:S,messageStyle:C,accessibilityLabel:
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Calendar}from"../Calendar/index.js";import{daysBetween,startOfDay,startOfMonth}from"../Calendar/calendarDates.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_DATE_RANGE_PICKER_LABELS=Object.freeze({title:"Select Date Range",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss"});const formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=forwardRef((e,t)=>{const{open:a,value:s,onChange:r,onClose:o,label:i,help:l,placeholder:n,helperText:d,error:c,required:m,disabled:u,size:g,variant:f,clearable:h,onClear:p,leftIcon:b,trailing:y,triggerStyle:x,valueStyle:D,labelStyle:S,messageStyle:C,accessibilityLabel:w,triggerLabels:j,formatValue:R,minDate:v,maxDate:_,disabledDates:T,marks:k,locale:M="en-IN",weekStartsOn:P=0,title:B,labels:L,maxRange:V,haptic:A,style:I,containerStyle:O,headerLabelStyle:z,navButtonStyle:E,footerButtonStyle:H,testID:G}=e,N={label:i,help:l,placeholder:n,helperText:d,error:c,required:m,disabled:u,size:g,variant:f,clearable:h,onClear:p,leftIcon:b,trailing:y,triggerStyle:x,valueStyle:D,labelStyle:S,messageStyle:C,accessibilityLabel:w},$=void 0!==a,[F,W]=useState(!1),q=$?a:F,K=$?G:G?`${G}-calendar`:void 0,U=useTheme(),[Y,J]=useModalInsets(),Q=useMemo(()=>buildStyles(U),[U]),X=useMemo(()=>({...DEFAULT_DATE_RANGE_PICKER_LABELS,...L}),[L]),[Z,ee]=useState(()=>startOfMonth(s.start??new Date)),[te,ae]=useState(s.start?startOfDay(s.start):null),[se,re]=useState(s.end?startOfDay(s.end):null),oe=useRef(createAnimatedValue(0)).current,ie=useRef(0);useEffect(()=>{if(s.start){const e=startOfDay(s.start);ae(e),ee(startOfMonth(e))}else ae(null);s.end?re(startOfDay(s.end)):re(null)},[s.start,s.end]);const le=useCallback(e=>{if(e.end&&V&&daysBetween(e.start,e.end)+1>V)return!1!==A&&triggerHaptic("notificationWarning"),ae(e.end),void re(null);ae(e.start),re(e.end??null)},[V,A]),ne=useCallback(()=>{$?o?.():W(!1)},[$,o]),{handleGesture:de,opacity:ce}=useDragToDismiss({drag:oe,travel:()=>ie.current||320,onDismiss:ne});useEffect(()=>{q&&(setNativeValue(oe,0),setNativeValue(ce,1))},[q,oe,ce]);const me=useCallback(()=>{!1!==A&&triggerHaptic("selection"),ne()},[ne,A]),ue=useCallback(()=>{te&&se&&(!1!==A&&triggerHaptic("notificationSuccess"),r?.({start:te,end:se}),ne())},[ne,r,te,se,A]),ge=useMemo(()=>te&&se?`${formatRangePart(te,M)} — ${formatRangePart(se,M)}`:te?`${formatRangePart(te,M)} — …`:"—",[te,se,M]),fe=!te||!se,he=_jsxs(View,{style:[Q.card,O,I],ref:t,accessible:!1,testID:K,children:[_jsx(GestureDetector,{gesture:de,children:_jsxs(View,{style:Q.grabArea,children:[_jsx(View,{style:Q.handle}),_jsxs(View,{style:Q.titleRow,children:[_jsx(Text,{variant:"title",style:Q.title,accessibilityRole:"header",children:B??X.title}),_jsx(Text,{variant:"bodySmall",style:Q.subtitle,accessibilityLiveRegion:"polite",children:ge})]})]})}),_jsx(Calendar,{selectionMode:"range",value:te?{start:te,end:se??void 0}:null,onChange:le,month:Z,onMonthChange:ee,minDate:v,maxDate:_,disabledDates:T,marks:k,weekStartsOn:P,locale:M,haptic:A,headerLabelStyle:z,navButtonStyle:E,testID:K?`${K}-grid`:void 0}),_jsxs(View,{style:Q.footer,children:[_jsx(Pressable,{onPress:me,style:({pressed:e})=>[Q.footerBtn,Q.footerCancel,e&&Q.footerBtnPressed,H],accessibilityRole:"button",accessibilityLabel:X.cancel,children:_jsx(Text,{variant:"label",weight:"semibold",style:[Q.footerBtnText,{color:U.colors["text-muted"]}],children:X.cancel})}),_jsx(Pressable,{onPress:ue,disabled:fe,style:({pressed:e})=>[Q.footerBtn,Q.footerConfirm,{backgroundColor:U.colors.primary,opacity:fe?.5:1},e&&{backgroundColor:U.colors["primary-hover"]},H],accessibilityRole:"button",accessibilityLabel:X.confirm,accessibilityState:{disabled:fe},"aria-disabled":fe,children:_jsx(Text,{variant:"label",weight:"semibold",style:[Q.footerBtnText,{color:U.colors["on-primary"]}],children:X.confirm})})]})]}),pe=useMemo(()=>{if(!s.start||!s.end)return"";const e={start:s.start,end:s.end};return R?R(e):`${e.start.toLocaleDateString()} – ${e.end.toLocaleDateString()}`},[s.start,s.end,R]);return _jsxs(_Fragment,{children:[$?null:_jsx(PickerTrigger,{...N,labels:j,value:pe,onPress:()=>W(!0),testID:G}),_jsx(Modal,{open:q,onClose:ne,presentation:"bottom",bare:!0,haptic:!1,labels:{close:X.dismiss},onInsetsChange:J,children:_jsx(GestureHandlerRootView,{style:Q.gestureRoot,children:_jsx(Animated.View,{style:[Q.sheetWrap,{paddingBottom:Math.max(Y.bottom,U.space.lg),opacity:ce,transform:[{translateY:oe}]}],onLayout:e=>{ie.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:he})})})]})});DateRangePicker.displayName="DateRangePicker";const buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,lineHeight:Math.round(e.text.lg.size*e.leading.body),fontWeight:e.weight.semibold,color:e.colors["text-body"]},subtitle:{marginTop:e.space.xxs,fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),color:e.colors["text-muted"]},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),fontWeight:e.weight.semibold}})};export{DateRangePicker};export default DateRangePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatDate}from"@webority/mobile-core";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DATE_SEPARATOR_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday"});const DAY_MS=864e5;export const dayLabel=(e,t={})=>{const r=formatDate(e,{empty:""});if(!r)return"";const o={...DEFAULT_DATE_SEPARATOR_LABELS,...t.labels},s=t.now??new Date;return r===formatDate(s)?o.today:r===formatDate(new Date(s.getTime()-DAY_MS))?o.yesterday:r};export const DateSeparator=({date:e,label:t,emphasis:r=!1,labels:o,now:s,style:a,testID:i})=>{const l=useTheme(),m=useMemo(()=>buildStyles(l),[l]),
|
|
1
|
+
"use strict";import{formatDate}from"@webority/mobile-core";import{useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DATE_SEPARATOR_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday"});const DAY_MS=864e5;export const dayLabel=(e,t={})=>{const r=formatDate(e,{empty:""});if(!r)return"";const o={...DEFAULT_DATE_SEPARATOR_LABELS,...t.labels},s=t.now??new Date;return r===formatDate(s)?o.today:r===formatDate(new Date(s.getTime()-DAY_MS))?o.yesterday:r};export const DateSeparator=({date:e,label:t,emphasis:r=!1,labels:o,now:s,style:a,testID:i})=>{const l=useTheme(),m=useMemo(()=>buildStyles(l),[l]),n=t??(void 0===e?"":dayLabel(e,{now:s,labels:o})),c=r?l.colors.primary:l.colors["border-subtle"];return _jsxs(View,{style:[m.row,a],testID:i,children:[_jsx(View,{style:[m.rule,{backgroundColor:c}]}),_jsx(Text,{variant:"caption",weight:r?"semibold":"medium",color:r?void 0:"secondary",style:r?{color:l.colors["primary-text"]}:void 0,children:n}),_jsx(View,{style:[m.rule,{backgroundColor:c}]})]})};const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:e.space.sm,paddingVertical:e.space.sm},rule:{flex:1,height:StyleSheet.hairlineWidth}});export default DateSeparator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useMemo,useRef,useState}from"react";import{ActivityIndicator,Pressable,StyleSheet,Text,View}from"react-native";import{fontFor,resolveButtonSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const OVERLAY_TONES=["primary","success","warning","danger","info","neutral"];export const ACTIONS_LAYOUTS=["auto","row","stacked"];const OverlayActions=({actions:
|
|
1
|
+
"use strict";import{useCallback,useMemo,useRef,useState}from"react";import{ActivityIndicator,Pressable,StyleSheet,Text,View}from"react-native";import{fontFor,resolveButtonSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const OVERLAY_TONES=["primary","success","warning","danger","info","neutral"];export const ACTIONS_LAYOUTS=["auto","row","stacked"];const OverlayActions=({actions:e,layout:o,testID:r,stackedLabels:t,rowStyle:n,buttonStyle:l,textStyle:s})=>{const a=useTheme(),i=useMemo(()=>buildStyles(a),[a]),c=a.components.dialog["action-button-min-height"],d=resolveButtonSize(a,"md").icon,u=a.text.base.size*a.leading.body,b=e.map(e=>e.label).join("\n"),m=useState(null),[y,g]=t??m,p="stacked"===o||"row"!==o&&(null!==y&&y===b),x=useRef(null),C=useCallback(e=>{e.nativeEvent.layout.height>1.5*u&&g(b)},[u,b,g]),h=useCallback(e=>{const o=e.nativeEvent.layout.width,r=x.current;x.current=o,null!==r&&Math.abs(r-o)>.5&&g(null)},[g]),f=new Map;return _jsx(View,{testID:r,style:[i.actionsRow,p?i.actionsRowStacked:null,n],onLayout:h,children:e.map((o,r)=>{const t=(f.get(o.label)??0)+1;f.set(o.label,t),warnInvalidValue("OverlayActions","actions[].tone",o.tone,OVERLAY_TONES);const n=o.tone??"primary",u=Boolean(o.disabled),b=actionStyleFor(a,n,u),m=r===e.length-1;return _jsx(Pressable,{onPress:o.onPress,disabled:o.loading||u,accessibilityRole:"button",accessibilityLabel:o.label,accessibilityState:{busy:o.loading,disabled:Boolean(o.loading)||u},"aria-busy":o.loading,"aria-disabled":Boolean(o.loading)||u,style:({pressed:e})=>[i.actionButton,{flex:p?0:1,minHeight:c,backgroundColor:b.backgroundColor,borderColor:b.borderColor,borderWidth:b.borderWidth,borderRadius:a.radius.md,...smoothCorners,paddingVertical:a.space.sm,paddingHorizontal:a.space.md,marginRight:m||p?0:a.space.sm,opacity:o.loading?.7:e&&!u?.85:1},l],children:o.loading?_jsx(ActivityIndicator,{size:"small",color:b.textColor}):_jsxs(View,{style:i.labelRow,children:[o.icon?_jsx(View,{style:i.labelIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(o.icon,{color:b.textColor,size:d,disabled:u},"linear")}):null,_jsx(View,{onLayout:C,children:_jsx(Text,{style:[{color:b.textColor,fontSize:a.text.base.size,...fontFor(a,"semibold"),textAlign:"center"},s],children:o.label})})]})},`${o.label}-${t}`)})})};OverlayActions.displayName="OverlayActions";const actionStyleFor=(e,o,r)=>{if(r)return{backgroundColor:"neutral"===o?"transparent":e.colors["surface-disabled"],borderColor:"neutral"===o?e.colors.border:"transparent",borderWidth:"neutral"===o?1:0,textColor:e.colors["text-disabled"]};switch(o){case"primary":return{backgroundColor:e.colors.primary,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-primary"]};case"info":return{backgroundColor:e.colors.info,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-info"]};case"success":return{backgroundColor:e.colors.success,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-success"]};case"warning":return{backgroundColor:e.colors.warning,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-warning"]};case"danger":return{backgroundColor:e.colors.danger,borderColor:"transparent",borderWidth:0,textColor:e.colors["on-danger"]};default:return{backgroundColor:"transparent",borderColor:e.colors.border,borderWidth:1,textColor:e.colors["text-body"]}}},buildStyles=e=>StyleSheet.create({actionsRow:{flexDirection:"row",justifyContent:"flex-end",alignItems:"stretch"},actionsRowStacked:{flexDirection:"column",rowGap:e.space.sm},actionButton:{alignItems:"center",justifyContent:"center"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},labelIcon:{marginRight:e.space.xs}});export{OverlayActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef}from"react";import{Animated,Pressable,StyleSheet}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,o)=>{switch(o){case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=forwardRef((e,o)=>{const{icon:s,iconVariant:
|
|
1
|
+
"use strict";import{forwardRef}from"react";import{Animated,Pressable,StyleSheet}from"react-native";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{ariaFromState}from"../../utils/ariaState.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,o)=>{switch(o){case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=forwardRef((e,o)=>{const{icon:s,iconVariant:t,onPress:r,accessibilityLabel:n,accessibilityHint:i,accessibilityState:a,tone:l="primary",variant:c="solid",size:d="md",shape:u="circle",active:m=!1,disabled:b=!1,loading:p=!1,haptic:f,style:g,testID:I}=e;warnInvalidValue("IconButton","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("IconButton","variant",e.variant,["solid","soft","outline","ghost","glass"]),warnInvalidValue("IconButton","size",e.size,["sm","md","lg"]),warnInvalidValue("IconButton","shape",e.shape,["circle","rounded"]),warnInvalidValue("IconButton","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]);const y=useTheme(),h=SIZE_MAP[d],S=b||p,{style:x,pressIn:w,pressOut:j}=usePressAnimation({scaleTo:.92,enabled:!S}),{base:v,outline:P,on:A,fg:V}=toneFor(y,l),_=m?"solid":c,B=m||!0===a?.selected,H={...a,disabled:S,selected:B};let C="transparent",F="transparent",O=0,T=S?y.colors["text-disabled"]:V;"solid"===_?(C=S?y.colors["surface-disabled"]:v,T=S?y.colors["text-disabled"]:A):"soft"===_?C=S?y.colors["surface-disabled"]:tintOf(v,.14,y.colors["bg-subtle"]):"outline"===_?(F=S?y.colors.border:P,O=y.size.border):"glass"===_&&(C=y.colors["glass-fill"],F=y.colors["glass-border"],O=1,T=S?y.colors["text-disabled"]:y.colors["on-glass"]);const k={color:T,size:h.icon,disabled:S},z="circle"===u?h.diameter/2:y.radius.md;return _jsx(Pressable,{ref:o,onPress:e=>{if(S)return;const o=resolveHaptic(f,"selection");o&&triggerHaptic(o),r?.(e)},onPressIn:w,onPressOut:j,disabled:S,accessibilityRole:"button",accessibilityLabel:n,accessibilityHint:i,accessibilityState:H,...ariaFromState(H),"aria-disabled":S,"aria-selected":B,hitSlop:6,...hitSlopMarker(6),testID:I,style:({pressed:e})=>[styles.base,{width:h.diameter,height:h.diameter,borderRadius:z,...smoothCorners,backgroundColor:C,borderColor:F,borderWidth:O,opacity:e&&"solid"!==_?.7:1},g],children:_jsx(Animated.View,{style:[styles.content,x],accessibilityElementsHidden:!p,importantForAccessibility:p?"auto":"no-hide-descendants","aria-hidden":!p,children:p?_jsx(Spinner,{size:"sm",color:T}):renderSlotIcon(s,k,t)})})});IconButton.displayName="IconButton";const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},content:{alignItems:"center",justifyContent:"center"}});export{IconButton};export default IconButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:y,prefixStyle:v,readOnly:b=!1,action:S,actionStyle:w,size:I="md",variant:T,labelMode:j,required:F=!1,maxLength:V,showCounter:_=!0,textAlign:A,format:R,parse:z,style:L,containerStyle:k,inputStyle:P,labelStyle:C,messageStyle:D,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;warnInvalidValue("Input","variant",T,["outline","filled","underline"]),warnInvalidValue("Input","size",e.size,["sm","md","lg"]),warnInvalidValue("Input","labelMode",j,["float","top"]),warnInvalidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,I),J=W.components.input[I]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=T??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=j??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(y),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ye=useCallback(()=>{me&&ge.current?.focus()},[me]),ve=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Ie=W.settings.components.input?.shakeOnError??!1,Te=useRef(de);useEffect(()=>{if(!Ie)return void(Te.current=de);let e;return de&&!Te.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:!0})]),e.start()),triggerHaptic("notificationError")),Te.current=de,()=>e?.stop()},[de,be,Ie,we]);const je=useCallback(e=>{ee(!0),E?.(e)},[E]),Fe=useCallback(e=>{ee(!1),B?.(e)},[B]),Ve=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,ze=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],Le=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ke=Boolean(x)||Boolean(g)||oe,Pe="underline"===Q,Ce=m?X.icon+W.space.md+1+W.space.md:0,De=useFloatingLabel({label:i,enabled:ve,floated:xe,required:F,variant:Q,sizeTokens:X,leadingOffset:Ce,trailingOffset:ke?X.icon+W.space.sm:0,textAlign:A,paddingLeft:Pe?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:ze,style:C}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=F&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof V&&"string"==typeof l?`${l.length} / ${V}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(D,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Ve,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(v),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},v],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},v],children:_jsx(TextInkContext.Provider,{value:Ze,children:y})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:I,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:Le}]},L],children:[pe&&!ve?_jsx(FieldLabel,{size:I,required:F,help:n,color:ze,style:C,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:I,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:Pe?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:De.topNotch,onPress:ye,pressFeedback:!1,style:k,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:Pe?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},P],textAlign:A,placeholder:ve&&!xe||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(z?z(e):e)},onFocus:je,onBlur:Fe,editable:me,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:V,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),De.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},D],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:i,title:o,topActions:n,placement:r,presentation:l,unavailable:a,context:c=!1,preview:d,onClose:u,restoreFocusTo:m,haptic:p,accessibilityLabel:b,labels:h,testID:f}=e,x=useTheme(),y=useMemo(()=>buildStyles(x),[x]),g=useSafeAreaInsets(),[v,_]=useModalInsets(),w=useMemo(()=>({...g,top:v.top,bottom:v.bottom}),[g,v]),j=useWindowDimensions(),A=usePresenceMotion(),I=A.duration("fast"),k=useMemo(()=>visibleGroups(i,a),[i,a]),S=useMemo(()=>visibleTopActions(n,a),[n,a]),E="sheet"===l||"auto"===l&&j.width<Breakpoints.lg&&wantsSheet(k,S),[M,C]=useState(null),[D,R]=useState(null),T=useRef(u);T.current=u;const L=useRef(m);L.current=m;const O=useRef(null),P=useRef(!1),V=useRef(!1),H=useRef(new Map),F=useRef(null),N=useCallback(()=>{if(!P.current)return;P.current=!1;const e=O.current;O.current=null,e?e():focusHost(L.current?.())},[]);useEffect(()=>{if(t)return V.current=!0,P.current=!1,O.current=null,claimAnchoredSurface(()=>T.current());V.current&&(V.current=!1,P.current=!0,C(null),R(null))},[t]);const B=useCallback(e=>{if(e.disabled)return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),e.key!==BACK_KEY?e.submenu?C(e):(O.current=e.onPress??null,T.current()):C(null)},[p]),K=useMemo(()=>({width:j.width,height:j.height,insets:w}),[j.width,j.height,w]),$=useMemo(()=>{if(!s||!D)return null;const e=s.x+s.width/2>K.width/2?"end":"start";return computePlacement(s,D,K,r,{align:e})},[s,D,K,r]);let z=K.height-w.top-w.bottom-2*PLACEMENT_MARGIN;if(s&&$){const e=placementRoom(s,K);z="top"===$.placement?e.above:e.below}const G=Math.min(280,K.width-w.left-w.right-2*PLACEMENT_MARGIN),W=t&&null!==$,Y=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!W)return setNativeValue(Y,0),void setNativeValue(U,1);const e=[Animated.timing(Y,{toValue:1,duration:I,easing:Easing.bezier(...x.motion.ease.decelerate),useNativeDriver:!0})];c&&!A.reduced&&e.push(Animated.spring(U,{toValue:1.02,damping:x.motion.spring.snappy.damping,stiffness:x.motion.spring.snappy.stiffness,mass:x.motion.spring.snappy.mass,useNativeDriver:!0}));const t=Animated.parallel(e);return t.start(),()=>t.stop()},[W,c,A.reduced,Y,U,x.motion,I]);const X=useCallback(e=>{const{width:t,height:s}=e.nativeEvent.layout;R(e=>e&&e.width===t&&e.height===s?e:{width:t,height:s})},[]),Z=c&&"top"===$?.placement,q=M?.submenu?[M.submenu]:k,J=Z?[...q].reverse().map(e=>[...e].reverse()):q,Q=[];if(M)Q.push({key:BACK_KEY,label:M.label});else for(const e of S)Q.push({key:`${TOP_PREFIX}${e.key}`,label:e.label,item:e});for(const e of J)for(const t of e)Q.push({key:t.key,label:t.label,item:t});const ee=Q[0]?.key;useEffect(()=>{if(!W||E||!ee)return;const e=setTimeout(()=>focusHost(H.current.get(ee)),FOCUS_DELAY_MS);return()=>clearTimeout(e)},[W,E,ee]);const setItemRef=e=>t=>{t?H.current.set(e,t):H.current.delete(e)},te=webOnly({onKeyDown:e=>{const t=e.key??e.nativeEvent?.key??"",s=Q.length,i=Q.findIndex(e=>e.key===F.current);let o=-1;if("ArrowDown"===t)o=(i+1)%s;else if("ArrowUp"===t)o=i<=0?s-1:i-1;else if("Home"===t)o=0;else if("End"===t)o=s-1;else{if("ArrowLeft"===t&&M)return e.preventDefault?.(),void C(null);if("ArrowRight"===t&&Q[i]?.item?.submenu)return e.preventDefault?.(),void B(Q[i].item);if(1===t.length&&""!==t.trim()){const e=t.toLowerCase();for(let t=1;t<=s;t+=1){const n=(i+t)%s;if(Q[n].label.toLowerCase().startsWith(e)){o=n;break}}}}o>=0&&(e.preventDefault?.(),(e=>{const t=Q[e];t&&focusHost(H.current.get(t.key))})(o))}});if(E){const e=M?.submenu?[{key:BACK_KEY,label:h.back,icon:"chevron-left"},...M.submenu]:[...S,...k.flat()],s=[...new Set(e.filter(e=>e.checked).map(e=>e.key))];return _jsx(OptionSheet,{open:t,onClose:u,onAfterClose:N,title:M?.label??o,options:e,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,isOptionDisabled:e=>Boolean(e.disabled),destructiveOf:e=>Boolean(e.destructive),getOptionDescription:e=>e.description,getOptionIcon:e=>{const t=e;return renderSlotIcon(t.icon,{color:t.destructive?x.colors["danger-text"]:x.colors["text-muted"],size:20,disabled:Boolean(t.disabled)})},value:s,onChange:(e,t)=>B(t),accessibilityLabel:b??o,testID:f?`${f}-sheet`:void 0})}const inkFor=e=>e.disabled?x.colors["text-disabled"]:e.destructive?x.colors["danger-text"]:x.colors["text-body"],inkRoleFor=e=>e.disabled?"disabled":e.destructive?"danger":"primary",se=_jsxs(_Fragment,M?{children:[_jsx(ListItem,{ref:setItemRef(BACK_KEY),variant:"menu",onPress:()=>C(null),onFocus:()=>{F.current=BACK_KEY},accessibilityLabel:`${h.back}, ${M.label}`,leading:_jsx(View,{style:y.icon,children:_jsx(AppIcon,{name:"chevron-left",size:20,color:x.colors["text-muted"]})}),title:_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:1,children:M.label})}),_jsx(Divider,{spacing:"none"})]}:{children:[o?_jsx(Text,{variant:"caption",color:"secondary",accessibilityRole:"header",numberOfLines:2,style:y.title,children:o}):null,S.length>0?_jsxs(_Fragment,{children:[_jsx(View,{style:y.topRow,children:S.map(e=>{const t=`${TOP_PREFIX}${e.key}`,s=Boolean(e.disabled),i=inkFor(e);return _jsxs(Pressable,{ref:setItemRef(t),onPress:()=>B(e),onFocus:()=>{F.current=t},disabled:s,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityState:{disabled:s},"aria-disabled":s,testID:e.testID,style:({pressed:e})=>[y.topAction,e?y.pressed:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}),_jsx(Text,{variant:"caption",color:inkRoleFor(e),numberOfLines:1,children:e.label})]},t)})}),_jsx(Divider,{spacing:"none"})]}):null]});return _jsxs(Modal,{open:t,onClose:u,presentation:"fullScreen",bare:!0,backdropOpacity:c?void 0:0,haptic:!1,labels:{close:h.close},onInsetsChange:_,onDismissed:N,testID:f?`${f}-modal`:void 0,children:[c&&d&&s?_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[y.preview,{left:s.x,top:s.y,width:s.width,height:s.height,transform:[{scale:U}]}],children:d}):null,_jsx(Animated.View,{accessibilityRole:"menu",accessibilityLabel:M?.label??b??o,onLayout:X,testID:f?`${f}-menu`:void 0,...te,style:[y.anchored,{left:$?.x??0,top:$?.y??0,maxWidth:G,opacity:W?Y:0}],children:_jsx(View,{style:y.surface,children:_jsxs(View,{style:[y.clip,{maxHeight:z}],children:[se,_jsx(ScrollView,{style:y.scroll,bounces:!1,keyboardShouldPersistTaps:"handled",children:J.map((e,t)=>{const s=e.some(e=>null!=e.icon);return _jsxs(View,{children:[t>0?_jsx(Divider,{spacing:"none"}):null,e.map(e=>((e,t)=>{const s=Boolean(e.disabled),i=inkFor(e),o=e.detail||e.checked||e.submenu?_jsxs(Row,{gap:"md",children:[e.detail?_jsx(Text,{variant:"caption",color:"tertiary",children:e.detail}):null,e.checked?_jsx(AppIcon,{name:"check",size:20,color:x.colors.primary}):null,e.submenu?_jsx(AppIcon,{name:"chevron-right",size:20,color:x.colors["text-subtle"]}):null]}):void 0;return _jsx(ListItem,{ref:setItemRef(e.key),variant:"menu",onPress:()=>B(e),onFocus:()=>{F.current=e.key},disabled:s,checked:e.checked,accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,rightPlacement:"side",leading:t?_jsx(View,{style:y.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}):void 0,title:_jsx(Text,{variant:"body",color:inkRoleFor(e),numberOfLines:2,children:e.label}),subtitle:e.description?_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:2,children:e.description}):void 0,trailing:o},e.key)})(e,s))]},e[0].key)})})]})})})]})};const buildStyles=e=>StyleSheet.create({preview:{position:"absolute"},anchored:{position:"absolute",minWidth:180},surface:{backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,...e.shadow.popover},clip:{borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},scroll:{flexGrow:0,flexShrink:1},title:{paddingHorizontal:e.space.md,paddingTop:e.space.sm,paddingBottom:e.space.xs},pressed:{backgroundColor:e.colors["surface-pressed"]},icon:{width:20,alignItems:"center"},topRow:{flexDirection:"row",padding:e.space.xs,gap:e.space.xs},topAction:{flexGrow:1,flexBasis:0,alignItems:"center",justifyContent:"center",gap:e.space.xs,minHeight:64,borderRadius:e.radius.sm,...smoothCorners}});
|