@webority/mobile-ui 0.134.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 +35 -27
- package/dist/canvas-kit/manifest.json +1 -1
- package/dist/canvas-kit/release.json +5 -5
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
- package/package.json +7 -7
package/dist/canvas-kit/kit.js
CHANGED
|
@@ -22902,19 +22902,22 @@ var Qb = (e) => L.create({
|
|
|
22902
22902
|
haptic: !1,
|
|
22903
22903
|
labels: { close: G.dismiss },
|
|
22904
22904
|
onInsetsChange: ce,
|
|
22905
|
-
children: K(ft, {
|
|
22906
|
-
style:
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
22915
|
-
|
|
22916
|
-
|
|
22917
|
-
|
|
22905
|
+
children: K(ft, {
|
|
22906
|
+
style: le.gestureRoot,
|
|
22907
|
+
children: K(b.View, {
|
|
22908
|
+
style: [le.sheetWrap, {
|
|
22909
|
+
paddingBottom: Math.max(se.bottom, ae.space.lg),
|
|
22910
|
+
opacity: Be,
|
|
22911
|
+
transform: [{ translateY: ye }]
|
|
22912
|
+
}],
|
|
22913
|
+
onLayout: (e) => {
|
|
22914
|
+
be.current = e.nativeEvent.layout.height;
|
|
22915
|
+
},
|
|
22916
|
+
accessibilityViewIsModal: !0,
|
|
22917
|
+
accessibilityRole: "none",
|
|
22918
|
+
children: We
|
|
22919
|
+
})
|
|
22920
|
+
})
|
|
22918
22921
|
});
|
|
22919
22922
|
return Ke ? q(ie, { children: [K(Zb, {
|
|
22920
22923
|
...qe,
|
|
@@ -22925,6 +22928,7 @@ var Qb = (e) => L.create({
|
|
|
22925
22928
|
}, ax = (e) => {
|
|
22926
22929
|
let t = e.shadow.popover;
|
|
22927
22930
|
return L.create({
|
|
22931
|
+
gestureRoot: { width: "100%" },
|
|
22928
22932
|
sheetWrap: {
|
|
22929
22933
|
paddingHorizontal: e.space.md,
|
|
22930
22934
|
paddingBottom: e.space.lg
|
|
@@ -23248,25 +23252,29 @@ var Qb = (e) => L.create({
|
|
|
23248
23252
|
haptic: !1,
|
|
23249
23253
|
labels: { close: ue.dismiss },
|
|
23250
23254
|
onInsetsChange: ce,
|
|
23251
|
-
children: K(ft, {
|
|
23252
|
-
style:
|
|
23253
|
-
|
|
23254
|
-
|
|
23255
|
-
|
|
23256
|
-
|
|
23257
|
-
|
|
23258
|
-
|
|
23259
|
-
|
|
23260
|
-
|
|
23261
|
-
|
|
23262
|
-
|
|
23263
|
-
|
|
23255
|
+
children: K(ft, {
|
|
23256
|
+
style: le.gestureRoot,
|
|
23257
|
+
children: K(b.View, {
|
|
23258
|
+
style: [le.sheetWrap, {
|
|
23259
|
+
paddingBottom: Math.max(se.bottom, oe.space.lg),
|
|
23260
|
+
opacity: Se,
|
|
23261
|
+
transform: [{ translateY: _e }]
|
|
23262
|
+
}],
|
|
23263
|
+
onLayout: (e) => {
|
|
23264
|
+
ve.current = e.nativeEvent.layout.height;
|
|
23265
|
+
},
|
|
23266
|
+
accessibilityViewIsModal: !0,
|
|
23267
|
+
accessibilityRole: "none",
|
|
23268
|
+
children: De
|
|
23269
|
+
})
|
|
23270
|
+
})
|
|
23264
23271
|
})] });
|
|
23265
23272
|
});
|
|
23266
23273
|
cx.displayName = "DateRangePicker";
|
|
23267
23274
|
var lx = (e) => {
|
|
23268
23275
|
let t = e.shadow.popover;
|
|
23269
23276
|
return L.create({
|
|
23277
|
+
gestureRoot: { width: "100%" },
|
|
23270
23278
|
sheetWrap: {
|
|
23271
23279
|
paddingHorizontal: e.space.md,
|
|
23272
23280
|
paddingBottom: e.space.lg
|
|
@@ -37279,7 +37287,7 @@ var Ck = L.create({
|
|
|
37279
37287
|
kind: "WeborityPhone",
|
|
37280
37288
|
library: {
|
|
37281
37289
|
name: "@webority/mobile-ui",
|
|
37282
|
-
version: "0.134.
|
|
37290
|
+
version: "0.134.1"
|
|
37283
37291
|
},
|
|
37284
37292
|
rendererProtocolVersion: 13,
|
|
37285
37293
|
platform: "Phone",
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webority-phone",
|
|
3
|
-
"version": "0.134.
|
|
3
|
+
"version": "0.134.1",
|
|
4
4
|
"platform": "Phone",
|
|
5
5
|
"kitModuleVersion": 2,
|
|
6
6
|
"rendererProtocolVersion": 13,
|
|
7
7
|
"library": {
|
|
8
8
|
"name": "@webority/mobile-ui",
|
|
9
|
-
"version": "0.134.
|
|
9
|
+
"version": "0.134.1"
|
|
10
10
|
},
|
|
11
11
|
"files": {
|
|
12
12
|
"manifest.json": {
|
|
13
|
-
"sha256": "
|
|
13
|
+
"sha256": "9251e121aba6f0e52dc2315b6c12b2e5997726218d915bef7b693abba1a6899b",
|
|
14
14
|
"bytes": 663799
|
|
15
15
|
},
|
|
16
16
|
"kit.js": {
|
|
17
|
-
"sha256": "
|
|
18
|
-
"bytes":
|
|
17
|
+
"sha256": "00cc7f46611e8de82b2a3c05fc0e7153963754cefda48f34cb3c2d27a0bdd298",
|
|
18
|
+
"bytes": 6115148
|
|
19
19
|
},
|
|
20
20
|
"kit.css": {
|
|
21
21
|
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=exports.DEFAULT_DATE_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Calendar/index.js"),_index4=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index5=require("../PickerTrigger/index.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,DEFAULT_DATE_PICKER_LABELS=exports.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}`}),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:r,minDate:i,maxDate:s,disabledDates:n,inline:l=!1,locale:o="en-IN",weekStartsOn:c=0,title:d,labels:u,style:x,containerStyle:_,headerLabelStyle:m,navButtonStyle:g,footerButtonStyle:h,haptic:y,testID:b,label:p,help:v,placeholder:f,helperText:j,error:R,required:D,disabled:C,size:w,variant:S,clearable:N,onClear:T,leftIcon:A,trailing:M,triggerStyle:P,valueStyle:L,labelStyle:I,messageStyle:k,accessibilityLabel:E,triggerLabels:V,formatValue:B}=e,F=l?"inline":"modal",Y=(0,_react.useMemo)(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),z=void 0!==e.open,[H,q]=(0,_react.useState)(!1),$=z?e.open:H,O=z?b:b?`${b}-calendar`:void 0,W=(0,_index.useTheme)(),G=(0,_usePresenceMotion.usePresenceMotion)(),[U,K]=(0,_ModalSafeArea.useModalInsets)(),Z=(0,_react.useMemo)(()=>buildStyles(W),[W]),[X,J]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{$&&J(startOfDay(new Date))},[$]);const Q=t?startOfDay(t):X,[ee,te]=(0,_react.useState)(Q),[ae,re]=(0,_react.useState)(t?startOfDay(t):null),[ie,se]=(0,_react.useState)("days"),ne=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,le=(0,_react.useRef)(0),oe=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ce=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,de=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);re(e),te(e)}else re(null)},[t]);const ue=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),xe=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),me=(0,_react.useMemo)(()=>buildYearCells(ee.getFullYear()),[ee]),ge=(0,_react.useMemo)(()=>buildDecadeCells(ee.getFullYear()),[ee]),he=(0,_react.useMemo)(()=>{if("years"===ie){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[ge,ie,me]),ye=(0,_react.useCallback)(e=>!!(ue&&e<ue.getFullYear())||!!(xe&&e>xe.getFullYear()),[ue,xe]),be=(0,_react.useCallback)(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(xe&&e>xe.getFullYear()),[ue,xe]),pe=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("impactLight"),te("years"===ie?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[ie,y]),ve=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("impactLight"),te("years"===ie?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[ie,y]),fe=(0,_react.useCallback)(()=>{const[e]=G.range(.9,1),t=G.reduced?G.duration("default"):W.motion.duration.default;(0,_index.setNativeValue)(oe,0),(0,_index.setNativeValue)(ce,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(oe,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ce,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[oe,ce,G,W.motion.duration.default]),je=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(y,"selection");if(e&&(0,_index2.triggerHaptic)(e),!G.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(de,{toValue:1,duration:t,useNativeDriver:!0})]).start()}se(e=>"days"===e?"years":"years"===e?"decades":"years"),fe()},[fe,de,y,G.reduced]),Re=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),te(t=>new Date(e,t.getMonth(),1)),se("days"),fe()},[fe,y]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),te(t=>new Date(e+4,t.getMonth(),1)),se("years"),fe()},[fe,y]),Ce=(0,_react.useCallback)(e=>{re(e.start)},[]),we=(0,_react.useCallback)(()=>{z||q(!1),r?.()},[z,r]),{handleGesture:Se,opacity:Ne}=(0,_useDragToDismiss.useDragToDismiss)({drag:ne,travel:()=>le.current||320,onDismiss:we});(0,_react.useEffect)(()=>{$&&"modal"===F&&((0,_index.setNativeValue)(ne,0),(0,_index.setNativeValue)(Ne,1))},[$,F,ne,Ne]);const Te=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("selection"),we()},[we,y]),Ae=(0,_react.useCallback)(()=>{ae&&(!1!==y&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(ae),we())},[we,a,ae,y]),Me=(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.titleRow,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??Y.title})}),Pe=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[Z.card,_,x],accessibilityRole:"modal"===F?void 0:"none",accessible:!1,testID:O,children:["modal"===F?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Se,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.handle}),Me]})}):Me,"days"!==ie?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:pe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===ie?Y.previousYears:Y.previousDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.navText,variant:"title",children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:[Z.headerLabelWrap,m],accessibilityRole:"button",accessibilityLabel:`${he}, ${"years"===ie?Y.switchToDecades:Y.switchToYears}`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.headerCaret,children:(W.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:W.text.sm.size,color:W.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ve,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===ie?Y.nextYears:Y.nextDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===ie?(0,_jsxRuntime.jsx)(_index3.Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:Ce,month:ee,onMonthChange:te,minDate:i,maxDate:s,disabledDates:n,weekStartsOn:c,locale:o,haptic:y,headerLabelStyle:m,navButtonStyle:g,onTitlePress:je,labels:{previousMonth:Y.previousMonth,nextMonth:Y.nextMonth},testID:O?`${O}-grid`:void 0}):"years"===ie?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.yearGrid,{opacity:oe,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.gridRow,children:e.map(e=>{const t=ye(e),a=!!ae&&ae.getFullYear()===e,r=X.getFullYear()===e,i=a?W.colors.primary:"transparent",s=r&&!a?W.colors.primary:"transparent",n=a?W.colors["on-primary"]:t?W.colors["text-disabled"]:W.colors["text-body"],l=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Re(e),accessibilityRole:"button",accessibilityLabel:Y.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[Z.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:l}],children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.yearText,{color:n}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e[0]}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.yearGrid,{opacity:oe,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>ge.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=be(e),r=!!ae&&decadeStartFor(ae.getFullYear())===e,i=decadeStartFor(X.getFullYear())===e,s=r?W.colors.primary:"transparent",n=i&&!r?W.colors.primary:"transparent",l=r?W.colors["on-primary"]:a?W.colors["text-disabled"]:W.colors["text-body"],o=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:Y.decade(e,t),accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:Z.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[Z.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:o}],children:[(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),(0,_jsxRuntime.jsx)(_index6.Text,{variant:"caption",style:[Z.decadeRangeText,{color:r?W.colors["on-primary"]:W.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e[0]}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:Y.cancel,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.footerBtnText,{color:W.colors["text-muted"]}],variant:"label",weight:"semibold",children:Y.cancel})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ae,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:W.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:W.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:Y.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.footerBtnText,{color:W.colors["on-primary"]}],variant:"label",weight:"semibold",children:Y.confirm})})]})]}),Le=t?(B??(e=>e.toLocaleDateString()))(t):void 0,Ie=!z,ke={label:p,help:v,placeholder:f,helperText:j,error:R,required:D,disabled:C,size:w,variant:S,clearable:N,onClear:T,leftIcon:A,trailing:M,triggerStyle:P,valueStyle:L,labelStyle:I,messageStyle:k,accessibilityLabel:E,labels:V};if("inline"===F)return $||Ie?Ie?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index5.PickerTrigger,{...ke,value:Le,onPress:()=>q(!0),testID:b}),$?Pe:null]}):Pe:null;const Ee=(0,_jsxRuntime.jsx)(_index4.Modal,{open:$,onClose:we,presentation:"bottom",bare:!0,haptic:!1,labels:{close:Y.dismiss},onInsetsChange:K,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(U.bottom,W.space.lg),opacity:Ne,transform:[{translateY:ne}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Pe})})});return Ie?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index5.PickerTrigger,{...ke,value:Le,onPress:()=>q(!0),testID:b}),Ee]}):Ee};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.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,..._corners.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,..._corners.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,..._corners.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,..._corners.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}})};var _default=exports.default=DatePicker;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=exports.DEFAULT_DATE_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Calendar/index.js"),_index4=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index5=require("../PickerTrigger/index.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,DEFAULT_DATE_PICKER_LABELS=exports.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}`}),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:r,minDate:i,maxDate:s,disabledDates:n,inline:l=!1,locale:o="en-IN",weekStartsOn:c=0,title:d,labels:u,style:x,containerStyle:_,headerLabelStyle:m,navButtonStyle:g,footerButtonStyle:h,haptic:y,testID:b,label:p,help:v,placeholder:f,helperText:j,error:R,required:D,disabled:w,size:C,variant:S,clearable:N,onClear:T,leftIcon:A,trailing:M,triggerStyle:P,valueStyle:L,labelStyle:I,messageStyle:k,accessibilityLabel:E,triggerLabels:V,formatValue:B}=e,F=l?"inline":"modal",Y=(0,_react.useMemo)(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),z=void 0!==e.open,[H,q]=(0,_react.useState)(!1),$=z?e.open:H,O=z?b:b?`${b}-calendar`:void 0,W=(0,_index.useTheme)(),G=(0,_usePresenceMotion.usePresenceMotion)(),[U,K]=(0,_ModalSafeArea.useModalInsets)(),Z=(0,_react.useMemo)(()=>buildStyles(W),[W]),[X,J]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{$&&J(startOfDay(new Date))},[$]);const Q=t?startOfDay(t):X,[ee,te]=(0,_react.useState)(Q),[ae,re]=(0,_react.useState)(t?startOfDay(t):null),[ie,se]=(0,_react.useState)("days"),ne=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,le=(0,_react.useRef)(0),oe=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ce=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,de=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);re(e),te(e)}else re(null)},[t]);const ue=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),xe=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),me=(0,_react.useMemo)(()=>buildYearCells(ee.getFullYear()),[ee]),ge=(0,_react.useMemo)(()=>buildDecadeCells(ee.getFullYear()),[ee]),he=(0,_react.useMemo)(()=>{if("years"===ie){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[ge,ie,me]),ye=(0,_react.useCallback)(e=>!!(ue&&e<ue.getFullYear())||!!(xe&&e>xe.getFullYear()),[ue,xe]),be=(0,_react.useCallback)(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(xe&&e>xe.getFullYear()),[ue,xe]),pe=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("impactLight"),te("years"===ie?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[ie,y]),ve=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("impactLight"),te("years"===ie?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[ie,y]),fe=(0,_react.useCallback)(()=>{const[e]=G.range(.9,1),t=G.reduced?G.duration("default"):W.motion.duration.default;(0,_index.setNativeValue)(oe,0),(0,_index.setNativeValue)(ce,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(oe,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ce,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[oe,ce,G,W.motion.duration.default]),je=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(y,"selection");if(e&&(0,_index2.triggerHaptic)(e),!G.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(de,{toValue:1,duration:t,useNativeDriver:!0})]).start()}se(e=>"days"===e?"years":"years"===e?"decades":"years"),fe()},[fe,de,y,G.reduced]),Re=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),te(t=>new Date(e,t.getMonth(),1)),se("days"),fe()},[fe,y]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(y,"selection");t&&(0,_index2.triggerHaptic)(t),te(t=>new Date(e+4,t.getMonth(),1)),se("years"),fe()},[fe,y]),we=(0,_react.useCallback)(e=>{re(e.start)},[]),Ce=(0,_react.useCallback)(()=>{z||q(!1),r?.()},[z,r]),{handleGesture:Se,opacity:Ne}=(0,_useDragToDismiss.useDragToDismiss)({drag:ne,travel:()=>le.current||320,onDismiss:Ce});(0,_react.useEffect)(()=>{$&&"modal"===F&&((0,_index.setNativeValue)(ne,0),(0,_index.setNativeValue)(Ne,1))},[$,F,ne,Ne]);const Te=(0,_react.useCallback)(()=>{!1!==y&&(0,_index2.triggerHaptic)("selection"),Ce()},[Ce,y]),Ae=(0,_react.useCallback)(()=>{ae&&(!1!==y&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(ae),Ce())},[Ce,a,ae,y]),Me=(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.titleRow,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??Y.title})}),Pe=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[Z.card,_,x],accessibilityRole:"modal"===F?void 0:"none",accessible:!1,testID:O,children:["modal"===F?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Se,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.handle}),Me]})}):Me,"days"!==ie?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:pe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===ie?Y.previousYears:Y.previousDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.navText,variant:"title",children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:[Z.headerLabelWrap,m],accessibilityRole:"button",accessibilityLabel:`${he}, ${"years"===ie?Y.switchToDecades:Y.switchToYears}`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.headerCaret,children:(W.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:W.text.sm.size,color:W.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ve,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===ie?Y.nextYears:Y.nextDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index6.Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===ie?(0,_jsxRuntime.jsx)(_index3.Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:we,month:ee,onMonthChange:te,minDate:i,maxDate:s,disabledDates:n,weekStartsOn:c,locale:o,haptic:y,headerLabelStyle:m,navButtonStyle:g,onTitlePress:je,labels:{previousMonth:Y.previousMonth,nextMonth:Y.nextMonth},testID:O?`${O}-grid`:void 0}):"years"===ie?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.yearGrid,{opacity:oe,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.gridRow,children:e.map(e=>{const t=ye(e),a=!!ae&&ae.getFullYear()===e,r=X.getFullYear()===e,i=a?W.colors.primary:"transparent",s=r&&!a?W.colors.primary:"transparent",n=a?W.colors["on-primary"]:t?W.colors["text-disabled"]:W.colors["text-body"],l=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Re(e),accessibilityRole:"button",accessibilityLabel:Y.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[Z.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:l}],children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.yearText,{color:n}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e[0]}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.yearGrid,{opacity:oe,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>ge.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=be(e),r=!!ae&&decadeStartFor(ae.getFullYear())===e,i=decadeStartFor(X.getFullYear())===e,s=r?W.colors.primary:"transparent",n=i&&!r?W.colors.primary:"transparent",l=r?W.colors["on-primary"]:a?W.colors["text-disabled"]:W.colors["text-body"],o=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:Y.decade(e,t),accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:Z.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[Z.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:o}],children:[(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),(0,_jsxRuntime.jsx)(_index6.Text,{variant:"caption",style:[Z.decadeRangeText,{color:r?W.colors["on-primary"]:W.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e[0]}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Z.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:Y.cancel,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.footerBtnText,{color:W.colors["text-muted"]}],variant:"label",weight:"semibold",children:Y.cancel})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ae,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:W.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:W.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:Y.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:(0,_jsxRuntime.jsx)(_index6.Text,{style:[Z.footerBtnText,{color:W.colors["on-primary"]}],variant:"label",weight:"semibold",children:Y.confirm})})]})]}),Le=t?(B??(e=>e.toLocaleDateString()))(t):void 0,Ie=!z,ke={label:p,help:v,placeholder:f,helperText:j,error:R,required:D,disabled:w,size:C,variant:S,clearable:N,onClear:T,leftIcon:A,trailing:M,triggerStyle:P,valueStyle:L,labelStyle:I,messageStyle:k,accessibilityLabel:E,labels:V};if("inline"===F)return $||Ie?Ie?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index5.PickerTrigger,{...ke,value:Le,onPress:()=>q(!0),testID:b}),$?Pe:null]}):Pe:null;const Ee=(0,_jsxRuntime.jsx)(_index4.Modal,{open:$,onClose:Ce,presentation:"bottom",bare:!0,haptic:!1,labels:{close:Y.dismiss},onInsetsChange:K,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:Z.gestureRoot,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(U.bottom,W.space.lg),opacity:Ne,transform:[{translateY:ne}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Pe})})});return Ie?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index5.PickerTrigger,{...ke,value:Le,onPress:()=>q(!0),testID:b}),Ee]}):Ee};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.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,..._corners.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,..._corners.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,..._corners.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,..._corners.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}})};var _default=exports.default=DatePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DateRangePicker=exports.DEFAULT_DATE_RANGE_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_index3=require("../Calendar/index.js"),_calendarDates=require("../Calendar/calendarDates.js"),_index4=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index5=require("../PickerTrigger/index.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_DATE_RANGE_PICKER_LABELS=exports.DEFAULT_DATE_RANGE_PICKER_LABELS=Object.freeze({title:"Select Date Range",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss"}),formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=exports.DateRangePicker=(0,_react.forwardRef)((e,t)=>{const{open:a,value:r,onChange:s,onClose:i,label:n,help:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DateRangePicker=exports.DEFAULT_DATE_RANGE_PICKER_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_index3=require("../Calendar/index.js"),_calendarDates=require("../Calendar/calendarDates.js"),_index4=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index5=require("../PickerTrigger/index.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_DATE_RANGE_PICKER_LABELS=exports.DEFAULT_DATE_RANGE_PICKER_LABELS=Object.freeze({title:"Select Date Range",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss"}),formatRangePart=(e,t)=>new Intl.DateTimeFormat(t,{weekday:"short",day:"numeric",month:"short"}).format(e),DateRangePicker=exports.DateRangePicker=(0,_react.forwardRef)((e,t)=>{const{open:a,value:r,onChange:s,onClose:i,label:n,help:o,placeholder:l,helperText:c,error:d,required:u,disabled:_,size:m,variant:x,clearable:g,onClear:h,leftIcon:b,trailing:f,triggerStyle:y,valueStyle:p,labelStyle:R,messageStyle:D,accessibilityLabel:j,triggerLabels:v,formatValue:S,minDate:C,maxDate:w,disabledDates:T,marks:A,locale:P="en-IN",weekStartsOn:k=0,title:E,labels:L,maxRange:M,haptic:N,style:B,containerStyle:I,headerLabelStyle:q,navButtonStyle:z,footerButtonStyle:O,testID:H}=e,V={label:n,help:o,placeholder:l,helperText:c,error:d,required:u,disabled:_,size:m,variant:x,clearable:g,onClear:h,leftIcon:b,trailing:f,triggerStyle:y,valueStyle:p,labelStyle:R,messageStyle:D,accessibilityLabel:j},G=void 0!==a,[$,F]=(0,_react.useState)(!1),W=G?a:$,K=G?H:H?`${H}-calendar`:void 0,U=(0,_index.useTheme)(),[Y,J]=(0,_ModalSafeArea.useModalInsets)(),Q=(0,_react.useMemo)(()=>buildStyles(U),[U]),X=(0,_react.useMemo)(()=>({...DEFAULT_DATE_RANGE_PICKER_LABELS,...L}),[L]),[Z,ee]=(0,_react.useState)(()=>(0,_calendarDates.startOfMonth)(r.start??new Date)),[te,ae]=(0,_react.useState)(r.start?(0,_calendarDates.startOfDay)(r.start):null),[re,se]=(0,_react.useState)(r.end?(0,_calendarDates.startOfDay)(r.end):null),ie=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ne=(0,_react.useRef)(0);(0,_react.useEffect)(()=>{if(r.start){const e=(0,_calendarDates.startOfDay)(r.start);ae(e),ee((0,_calendarDates.startOfMonth)(e))}else ae(null);r.end?se((0,_calendarDates.startOfDay)(r.end)):se(null)},[r.start,r.end]);const oe=(0,_react.useCallback)(e=>{if(e.end&&M&&(0,_calendarDates.daysBetween)(e.start,e.end)+1>M)return!1!==N&&(0,_index2.triggerHaptic)("notificationWarning"),ae(e.end),void se(null);ae(e.start),se(e.end??null)},[M,N]),le=(0,_react.useCallback)(()=>{G?i?.():F(!1)},[G,i]),{handleGesture:ce,opacity:de}=(0,_useDragToDismiss.useDragToDismiss)({drag:ie,travel:()=>ne.current||320,onDismiss:le});(0,_react.useEffect)(()=>{W&&((0,_index.setNativeValue)(ie,0),(0,_index.setNativeValue)(de,1))},[W,ie,de]);const ue=(0,_react.useCallback)(()=>{!1!==N&&(0,_index2.triggerHaptic)("selection"),le()},[le,N]),me=(0,_react.useCallback)(()=>{te&&re&&(!1!==N&&(0,_index2.triggerHaptic)("notificationSuccess"),s?.({start:te,end:re}),le())},[le,s,te,re,N]),xe=(0,_react.useMemo)(()=>te&&re?`${formatRangePart(te,P)} — ${formatRangePart(re,P)}`:te?`${formatRangePart(te,P)} — …`:"—",[te,re,P]),ge=!te||!re,he=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[Q.card,I,B],ref:t,accessible:!1,testID:K,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ce,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Q.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:Q.handle}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Q.titleRow,children:[(0,_jsxRuntime.jsx)(_index6.Text,{variant:"title",style:Q.title,accessibilityRole:"header",children:E??X.title}),(0,_jsxRuntime.jsx)(_index6.Text,{variant:"bodySmall",style:Q.subtitle,accessibilityLiveRegion:"polite",children:xe})]})]})}),(0,_jsxRuntime.jsx)(_index3.Calendar,{selectionMode:"range",value:te?{start:te,end:re??void 0}:null,onChange:oe,month:Z,onMonthChange:ee,minDate:C,maxDate:w,disabledDates:T,marks:A,weekStartsOn:k,locale:P,haptic:N,headerLabelStyle:q,navButtonStyle:z,testID:K?`${K}-grid`:void 0}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:Q.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ue,style:({pressed:e})=>[Q.footerBtn,Q.footerCancel,e&&Q.footerBtnPressed,O],accessibilityRole:"button",accessibilityLabel:X.cancel,children:(0,_jsxRuntime.jsx)(_index6.Text,{variant:"label",weight:"semibold",style:[Q.footerBtnText,{color:U.colors["text-muted"]}],children:X.cancel})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:me,disabled:ge,style:({pressed:e})=>[Q.footerBtn,Q.footerConfirm,{backgroundColor:U.colors.primary,opacity:ge?.5:1},e&&{backgroundColor:U.colors["primary-hover"]},O],accessibilityRole:"button",accessibilityLabel:X.confirm,accessibilityState:{disabled:ge},"aria-disabled":ge,children:(0,_jsxRuntime.jsx)(_index6.Text,{variant:"label",weight:"semibold",style:[Q.footerBtnText,{color:U.colors["on-primary"]}],children:X.confirm})})]})]}),be=(0,_react.useMemo)(()=>{if(!r.start||!r.end)return"";const e={start:r.start,end:r.end};return S?S(e):`${e.start.toLocaleDateString()} – ${e.end.toLocaleDateString()}`},[r.start,r.end,S]);return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[G?null:(0,_jsxRuntime.jsx)(_index5.PickerTrigger,{...V,labels:v,value:be,onPress:()=>F(!0),testID:H}),(0,_jsxRuntime.jsx)(_index4.Modal,{open:W,onClose:le,presentation:"bottom",bare:!0,haptic:!1,labels:{close:X.dismiss},onInsetsChange:J,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:Q.gestureRoot,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[Q.sheetWrap,{paddingBottom:Math.max(Y.bottom,U.space.lg),opacity:de,transform:[{translateY:ie}]}],onLayout:e=>{ne.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:he})})})]})});DateRangePicker.displayName="DateRangePicker";const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.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,..._corners.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,..._corners.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}})};var _default=exports.default=DateRangePicker;
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-ui",
|
|
3
|
-
"version": "0.134.
|
|
3
|
+
"version": "0.134.1",
|
|
4
4
|
"description": "Beautiful, animated, accessible React Native components, theme and form engine for Webority projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -115,13 +115,13 @@
|
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"@webority/markdown-core": "0.134.
|
|
118
|
+
"@webority/markdown-core": "0.134.1"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
121
|
"@react-navigation/bottom-tabs": ">=7.0.0",
|
|
122
122
|
"@react-navigation/native": ">=7.0.0",
|
|
123
|
-
"@webority/canvas-kit": "0.134.
|
|
124
|
-
"@webority/mobile-core": "0.134.
|
|
123
|
+
"@webority/canvas-kit": "0.134.1",
|
|
124
|
+
"@webority/mobile-core": "0.134.1",
|
|
125
125
|
"expo": ">=57.0.0",
|
|
126
126
|
"expo-file-system": ">=57.0.0",
|
|
127
127
|
"expo-haptics": ">=57.0.0",
|
|
@@ -185,10 +185,10 @@
|
|
|
185
185
|
"@types/node": "25.6.0",
|
|
186
186
|
"@types/react": "19.2.18",
|
|
187
187
|
"@types/react-test-renderer": "19.1.0",
|
|
188
|
-
"@webority/canvas-kit": "0.134.
|
|
189
|
-
"@webority/mobile-core": "0.134.
|
|
188
|
+
"@webority/canvas-kit": "0.134.1",
|
|
189
|
+
"@webority/mobile-core": "0.134.1",
|
|
190
190
|
"@webority/mobile-dev": "0.0.0",
|
|
191
|
-
"@webority/tokens": "0.134.
|
|
191
|
+
"@webority/tokens": "0.134.1",
|
|
192
192
|
"expo": "57.0.31",
|
|
193
193
|
"expo-file-system": "57.0.7",
|
|
194
194
|
"expo-haptics": "57.0.3",
|