@webority/mobile-ui 0.168.0 → 0.169.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 +10 -10
- package/dist/canvas-kit/manifest.json +85 -1
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/Composer/Composer.js +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/DecimalInput/DecimalInput.js +1 -1
- package/lib/commonjs/components/IdleTimeoutDialog/IdleTimeoutDialog.js +1 -0
- package/lib/commonjs/components/IdleTimeoutDialog/index.js +1 -0
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/PagedList/PagedList.js +1 -0
- package/lib/commonjs/components/PagedList/index.js +1 -0
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/commonjs/components/Screen/Screen.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
- package/lib/commonjs/components/SliderField/SliderField.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
- package/lib/commonjs/components/index.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/text/phone/idleTimeoutDialog.g.js +1 -0
- package/lib/commonjs/text/phone/index.g.js +1 -1
- package/lib/module/components/Composer/Composer.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/DecimalInput/DecimalInput.js +1 -1
- package/lib/module/components/IdleTimeoutDialog/IdleTimeoutDialog.js +1 -0
- package/lib/module/components/IdleTimeoutDialog/index.js +1 -0
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/NumberInput/NumberInput.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/PagedList/PagedList.js +1 -0
- package/lib/module/components/PagedList/index.js +1 -0
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/module/components/Screen/Screen.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.js +1 -1
- package/lib/module/components/SliderField/SliderField.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/WheelPicker/Wheel.js +1 -1
- package/lib/module/components/index.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/text/phone/idleTimeoutDialog.g.js +1 -0
- package/lib/module/text/phone/index.g.js +1 -1
- package/lib/text/en.json +6 -0
- package/lib/typescript/commonjs/components/IdleTimeoutDialog/IdleTimeoutDialog.d.ts +14 -0
- package/lib/typescript/commonjs/components/IdleTimeoutDialog/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/PagedList/PagedList.d.ts +34 -0
- package/lib/typescript/commonjs/components/PagedList/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/index.d.ts +4 -0
- package/lib/typescript/commonjs/index.d.ts +1 -1
- package/lib/typescript/commonjs/text/phone/catalogue.g.d.ts +2 -0
- package/lib/typescript/commonjs/text/phone/idleTimeoutDialog.g.d.ts +8 -0
- package/lib/typescript/commonjs/text/phone/index.g.d.ts +1 -0
- package/lib/typescript/module/components/IdleTimeoutDialog/IdleTimeoutDialog.d.ts +14 -0
- package/lib/typescript/module/components/IdleTimeoutDialog/index.d.ts +3 -0
- package/lib/typescript/module/components/PagedList/PagedList.d.ts +34 -0
- package/lib/typescript/module/components/PagedList/index.d.ts +3 -0
- package/lib/typescript/module/components/index.d.ts +4 -0
- package/lib/typescript/module/index.d.ts +1 -1
- package/lib/typescript/module/text/phone/catalogue.g.d.ts +2 -0
- package/lib/typescript/module/text/phone/idleTimeoutDialog.g.d.ts +8 -0
- package/lib/typescript/module/text/phone/index.g.d.ts +1 -0
- package/package.json +9 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"kind": "WeborityPhone",
|
|
3
3
|
"library": {
|
|
4
4
|
"name": "@webority/mobile-ui",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.169.1"
|
|
6
6
|
},
|
|
7
7
|
"rendererProtocolVersion": 14,
|
|
8
8
|
"platform": "Phone",
|
|
@@ -8187,6 +8187,45 @@
|
|
|
8187
8187
|
]
|
|
8188
8188
|
}
|
|
8189
8189
|
},
|
|
8190
|
+
{
|
|
8191
|
+
"name": "IdleTimeoutDialog",
|
|
8192
|
+
"marker": null,
|
|
8193
|
+
"acceptsChildren": false,
|
|
8194
|
+
"props": [
|
|
8195
|
+
{
|
|
8196
|
+
"name": "open",
|
|
8197
|
+
"type": "boolean",
|
|
8198
|
+
"required": true,
|
|
8199
|
+
"description": "Shows the warning. True while the idle timer is in its warning phase."
|
|
8200
|
+
},
|
|
8201
|
+
{
|
|
8202
|
+
"name": "remainingMs",
|
|
8203
|
+
"type": "number",
|
|
8204
|
+
"required": true,
|
|
8205
|
+
"description": "Time left before sign-out, in milliseconds. Drawn as minutes and seconds."
|
|
8206
|
+
}
|
|
8207
|
+
],
|
|
8208
|
+
"itemsTakeAction": [],
|
|
8209
|
+
"takesAction": [],
|
|
8210
|
+
"source": "@webority/mobile-ui",
|
|
8211
|
+
"usage": {
|
|
8212
|
+
"when": [
|
|
8213
|
+
"A session is about to end for lack of activity and the person must choose to stay signed in or sign out."
|
|
8214
|
+
],
|
|
8215
|
+
"whenNot": [
|
|
8216
|
+
{
|
|
8217
|
+
"text": "A message that needs no answer.",
|
|
8218
|
+
"instead": "Toast"
|
|
8219
|
+
}
|
|
8220
|
+
],
|
|
8221
|
+
"do": [],
|
|
8222
|
+
"dont": [],
|
|
8223
|
+
"a11y": [
|
|
8224
|
+
"The dialog sets the alert role and its title is its accessible name.",
|
|
8225
|
+
"The hardware back button does not answer the warning; only Stay signed in or Sign out does."
|
|
8226
|
+
]
|
|
8227
|
+
}
|
|
8228
|
+
},
|
|
8190
8229
|
{
|
|
8191
8230
|
"name": "ImageGallery",
|
|
8192
8231
|
"marker": null,
|
|
@@ -11222,6 +11261,51 @@
|
|
|
11222
11261
|
]
|
|
11223
11262
|
}
|
|
11224
11263
|
},
|
|
11264
|
+
{
|
|
11265
|
+
"name": "PagedList",
|
|
11266
|
+
"marker": null,
|
|
11267
|
+
"acceptsChildren": false,
|
|
11268
|
+
"props": [
|
|
11269
|
+
{
|
|
11270
|
+
"name": "errorTitle",
|
|
11271
|
+
"type": "string",
|
|
11272
|
+
"required": false,
|
|
11273
|
+
"description": "Title of the error placeholder when the first page fails to load."
|
|
11274
|
+
},
|
|
11275
|
+
{
|
|
11276
|
+
"name": "progressViewOffset",
|
|
11277
|
+
"type": "number",
|
|
11278
|
+
"required": false,
|
|
11279
|
+
"description": "Moves the pull-to-refresh spinner down, so it shows below a header drawn over the list."
|
|
11280
|
+
},
|
|
11281
|
+
{
|
|
11282
|
+
"name": "refreshing",
|
|
11283
|
+
"type": "boolean",
|
|
11284
|
+
"required": false,
|
|
11285
|
+
"description": "Shows the pull-to-refresh spinner for rows given as data.",
|
|
11286
|
+
"default": false
|
|
11287
|
+
}
|
|
11288
|
+
],
|
|
11289
|
+
"itemsTakeAction": [],
|
|
11290
|
+
"takesAction": [],
|
|
11291
|
+
"source": "@webority/mobile-ui",
|
|
11292
|
+
"usage": {
|
|
11293
|
+
"when": [
|
|
11294
|
+
"A paged list outside the screen shell: in a tab, a sheet or a pane."
|
|
11295
|
+
],
|
|
11296
|
+
"whenNot": [
|
|
11297
|
+
{
|
|
11298
|
+
"text": "The list is the whole screen.",
|
|
11299
|
+
"instead": "NavigationScreen list"
|
|
11300
|
+
}
|
|
11301
|
+
],
|
|
11302
|
+
"do": [],
|
|
11303
|
+
"dont": [],
|
|
11304
|
+
"a11y": [
|
|
11305
|
+
"The loading spinner is announced with the loading label, and a failed page with its retry button."
|
|
11306
|
+
]
|
|
11307
|
+
}
|
|
11308
|
+
},
|
|
11225
11309
|
{
|
|
11226
11310
|
"name": "PagedListFooter",
|
|
11227
11311
|
"marker": null,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webority-phone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.169.1",
|
|
4
4
|
"platform": "Phone",
|
|
5
5
|
"kitModuleVersion": 2,
|
|
6
6
|
"rendererProtocolVersion": 14,
|
|
7
7
|
"library": {
|
|
8
8
|
"name": "@webority/mobile-ui",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.169.1"
|
|
10
10
|
},
|
|
11
11
|
"files": {
|
|
12
12
|
"manifest.json": {
|
|
13
|
-
"sha256": "
|
|
14
|
-
"bytes":
|
|
13
|
+
"sha256": "408cb291a5235b12ab22d71fad15d3d7e537ff54511d690e1f1a6f9328958447",
|
|
14
|
+
"bytes": 671459
|
|
15
15
|
},
|
|
16
16
|
"kit.js": {
|
|
17
|
-
"sha256": "
|
|
18
|
-
"bytes":
|
|
17
|
+
"sha256": "2a70a3ee7175e4478769b63378ea38435f8e34687667b9cd70dc8d6343d22a84",
|
|
18
|
+
"bytes": 5672283
|
|
19
19
|
},
|
|
20
20
|
"kit.css": {
|
|
21
21
|
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Composer=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useControllableState=require("../../hooks/useControllableState.js"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../text/index.js"),_composerG=require("../../text/phone/composer.g.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index3=require("../IconButton/index.js"),_jsxRuntime=require("react/jsx-runtime");const MIN_BOX=44,RING_MS=900,RING_WIDTH=1.5,Composer=exports.Composer=(0,_react.forwardRef)(({onSend:e,value:t,onChangeText:a,placeholder:o,accessibilityLabel:i,hint:r,labels:s,loading:n=!1,onStop:l,stopLabel:d,disabled:c=!1,canSend:u,ring:b=!1,sendReveal:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Composer=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useControllableState=require("../../hooks/useControllableState.js"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../text/index.js"),_composerG=require("../../text/phone/composer.g.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index3=require("../IconButton/index.js"),_jsxRuntime=require("react/jsx-runtime");const MIN_BOX=44,RING_MS=900,RING_WIDTH=1.5,Composer=exports.Composer=(0,_react.forwardRef)(({onSend:e,value:t,onChangeText:a,placeholder:o,accessibilityLabel:i,hint:r,labels:s,loading:n=!1,onStop:l,stopLabel:d,disabled:c=!1,canSend:u,ring:b=!1,sendReveal:_="always",sendIcon:p="send",maxLength:m,maxLines:x=5,leading:v,trailing:g,above:h,below:C,keyboardAware:y=!0,keyboardOffset:f,safeArea:N=!0,autoFocus:S,haptic:j,style:R,testID:w},I)=>{const q=(0,_index2.useTheme)(),M=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),A=(0,_react.useMemo)(()=>buildStyles(q),[q]),T=(0,_index.useMobileUiText)("composer",_composerG.COMPOSER_TEXT),k=(0,_react.useMemo)(()=>({...T,...s}),[T,s]),[D,V]=(0,_useControllableState.useControllableState)({value:t,defaultValue:"",onChange:a}),O=D.trim(),B=n&&void 0!==l,E=n||c||!(u??""!==O),F=N?M.bottom:0,H=f??F,L=(0,_FieldBase.resolveFieldTextStyle)(q,{disabled:c}),z=q.text.base.size,P=Math.round(z*q.leading.body),G=(44-P)/2,W=P*x+2*G,[K,$]=(0,_react.useState)(void 0),X=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentSize.height+2*G;$(Math.min(Math.max(t,44),W))},[G,W]),U=(0,_useReducedMotion.useReducedMotion)(),J=(0,_react.useRef)(new _reactNative.Animated.Value(0)).current;(0,_react.useEffect)(()=>{if(!b||U)return void J.setValue(b?1:0);const e=_reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(J,{toValue:1,duration:900,easing:_reactNative.Easing.inOut(_reactNative.Easing.ease),useNativeDriver:!1}),_reactNative.Animated.timing(J,{toValue:0,duration:900,easing:_reactNative.Easing.inOut(_reactNative.Easing.ease),useNativeDriver:!1})]));return e.start(),()=>e.stop()},[b,U,J]);const Q=b?{borderWidth:1.5,borderColor:J.interpolate({inputRange:[0,1],outputRange:[q.colors["border-subtle"],q.colors.primary]})}:null,Y="always"===_||n||""!==D||!0===u,Z=(0,_react.useCallback)(()=>{B?l?.():E||(V(""),e(O))},[B,l,E,V,e,O]),ee=(0,_react.useCallback)(e=>{(0,_mobileCore.reportIdleActivity)(),V(e)},[V]),te=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[A.bar,{paddingBottom:q.space.sm+F},R],testID:w,children:[h,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:A.row,children:[v,(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[A.box,c?A.boxDisabled:null,Q],testID:w?`${w}-box`:void 0,children:(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:I,value:D,onChangeText:ee,multiline:!0,maxLength:m,editable:!c,autoFocus:S,placeholder:o??k.message,placeholderTextColor:L.placeholderColor,selectionColor:q.colors["field-caret"],accessibilityLabel:i??o??k.message,accessibilityHint:r,accessibilityState:{disabled:c},"aria-disabled":c,onContentSizeChange:"web"===_reactNative.Platform.OS?X:void 0,style:[A.input,{color:L.color,...L.weightStyle,fontSize:z,lineHeight:P,paddingVertical:G,maxHeight:W,height:"web"===_reactNative.Platform.OS?K:void 0}],testID:w?`${w}-input`:void 0})}),g,Y?(0,_jsxRuntime.jsx)(_index3.IconButton,{icon:B?"stop":p,accessibilityLabel:B?d??k.stopLabel:k.send,variant:"solid",tone:"primary",disabled:B?c:E,loading:n&&!B,haptic:j,onPress:Z,testID:w?`${w}-send`:void 0}):null]}),C]});return y?(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardStickyView,{offset:{closed:0,opened:H},children:te}):te});Composer.displayName="Composer";const buildStyles=e=>_reactNative.StyleSheet.create({bar:{gap:e.space.xs,paddingHorizontal:e.space.md,paddingTop:e.space.sm,backgroundColor:e.colors.bg,borderTopWidth:_reactNative.StyleSheet.hairlineWidth,borderTopColor:e.colors["border-subtle"]},row:{flexDirection:"row",alignItems:"flex-end",gap:e.space.sm},box:{flex:1,minHeight:44,justifyContent:"center",backgroundColor:e.colors["field-bg"],borderRadius:e.radius.pill,..._corners.smoothCorners,paddingHorizontal:e.space.md},boxDisabled:{backgroundColor:e.colors["field-bg-disabled"]},input:{margin:e.space.none,paddingHorizontal:e.space.none,includeFontPadding:!1,textAlignVertical:"top"}});var _default=exports.default=Composer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=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("../../text/index.js"),_datePickerG=require("../../text/phone/datePicker.g.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../Calendar/index.js"),_index5=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index6=require("../PickerTrigger/index.js"),_index7=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,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,sheetStyle:_,headerLabelStyle:g,navButtonStyle:m,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:M,trailing:P,triggerStyle:k,valueStyle:I,labelStyle:V,messageStyle:A,accessibilityLabel:L,triggerLabels:z,formatValue:B}=e,F=l?"inline":"modal",q=(0,_index.useMobileUiText)("datePicker",_datePickerG.DATE_PICKER_TEXT),H=(0,_react.useMemo)(()=>u?{...q,...u}:q,[q,u]),Y=void 0!==e.open,[O,E]=(0,_react.useState)(!1),$=void 0!==e.open?e.open:O,G=Y?b:b?`${b}-calendar`:void 0,W=(0,_index2.useTheme)(),U=(0,_usePresenceMotion.usePresenceMotion)(),[X,Z]=(0,_ModalSafeArea.useModalInsets)(),K=(0,_react.useMemo)(()=>buildStyles(W),[W]),[J,Q]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{$&&Q(startOfDay(new Date))},[$]);const ee=t?startOfDay(t):J,[te,ae]=(0,_react.useState)(ee),[re,ie]=(0,_react.useState)(t?startOfDay(t):null),[se,ne]=(0,_react.useState)("days"),le=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,oe=(0,_react.useRef)(0),ce=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current,de=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current,ue=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);ie(e),ae(e)}else ie(null)},[t]);const xe=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),ge=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),me=(0,_react.useMemo)(()=>buildYearCells(te.getFullYear()),[te]),he=(0,_react.useMemo)(()=>buildDecadeCells(te.getFullYear()),[te]),ye=(0,_react.useMemo)(()=>{const e=te.getFullYear();if("years"===se)return`${e-4} - ${e+7}`;const t=decadeStartFor(e)-40;return`${t} - ${t+110+9}`},[te,se]),be=(0,_react.useCallback)(e=>!!(xe&&e<xe.getFullYear())||!!(ge&&e>ge.getFullYear()),[xe,ge]),pe=(0,_react.useCallback)(e=>!!(xe&&e+10-1<xe.getFullYear())||!!(ge&&e>ge.getFullYear()),[xe,ge]),ve=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("impactLight"),ae("years"===se?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[se,y]),fe=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("impactLight"),ae("years"===se?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[se,y]),je=(0,_react.useCallback)(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):W.motion.duration.default;(0,_index2.setNativeValue)(ce,0),(0,_index2.setNativeValue)(de,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ce,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(de,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:_nativeDriver.nativeDriver})]).start()},[ce,de,U,W.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(y,"selection");if(e&&(0,_index3.triggerHaptic)(e),!U.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ue,{toValue:.96,duration:e,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(ue,{toValue:1,duration:t,useNativeDriver:_nativeDriver.nativeDriver})]).start()}ne(e=>"days"===e?"years":"years"===e?"decades":"years"),je()},[je,ue,y,U.reduced]),De=(0,_react.useCallback)(e=>{const t=(0,_index3.resolveHaptic)(y,"selection");t&&(0,_index3.triggerHaptic)(t),ae(t=>new Date(e,t.getMonth(),1)),ne("days"),je()},[je,y]),we=(0,_react.useCallback)(e=>{const t=(0,_index3.resolveHaptic)(y,"selection");t&&(0,_index3.triggerHaptic)(t),ae(t=>new Date(e+4,t.getMonth(),1)),ne("years"),je()},[je,y]),Ce=(0,_react.useCallback)(e=>{ie(e.start)},[]),Se=(0,_react.useCallback)(()=>{Y||E(!1),r?.()},[Y,r]),{handleGesture:Ne,opacity:Te}=(0,_useDragToDismiss.useDragToDismiss)({drag:le,travel:()=>oe.current||320,onDismiss:Se});(0,_react.useEffect)(()=>{$&&"modal"===F&&((0,_index2.setNativeValue)(le,0),(0,_index2.setNativeValue)(Te,1))},[$,F,le,Te]);const Me=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("selection"),Se()},[Se,y]),Pe=(0,_react.useCallback)(()=>{re&&(!1!==y&&(0,_index3.triggerHaptic)("notificationSuccess"),a?.(re),Se())},[Se,a,re,y]),ke=(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.titleRow,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.title,variant:"title",accessibilityRole:"header",children:d??H.title})}),Ie=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[K.card,_],accessibilityRole:"modal"===F?void 0:"none",accessible:!1,testID:G,children:["modal"===F?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Ne,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.handle}),ke]})}):ke,"days"!==se?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ve,style:({pressed:e})=>[K.navBtn,e&&K.navBtnPressed,m],accessibilityRole:"button",accessibilityLabel:"years"===se?H.previousYears:H.previousDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.navText,variant:"title",children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[K.headerLabelWrap,g],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===se?H.switchToDecades:H.switchToYears}`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[K.headerLabelInner,{transform:[{scale:ue}]}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[K.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.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:fe,style:({pressed:e})=>[K.navBtn,e&&K.navBtnPressed,m],accessibilityRole:"button",accessibilityLabel:"years"===se?H.nextYears:H.nextDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.navText,variant:"title",children:"›"})})]}):null,"days"===se?(0,_jsxRuntime.jsx)(_index4.Calendar,{selectionMode:"single",value:re?{start:re}:null,onChange:Ce,month:te,onMonthChange:ae,minDate:i,maxDate:s,disabledDates:n,weekStartsOn:c,locale:o,haptic:y,headerLabelStyle:g,navButtonStyle:m,onTitlePress:Re,labels:{previousMonth:H.previousMonth,nextMonth:H.nextMonth},testID:G?`${G}-grid`:void 0}):"years"===se?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.yearGrid,{opacity:ce,transform:[{scale:de}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.gridRow,children:e.map(e=>{const t=be(e),a=!!re&&re.getFullYear()===e,r=J.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:()=>De(e),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(H.year,{year:e}),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:K.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[K.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:l}],children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.yearText,{color:n}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e.join("-")}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.yearGrid,{opacity:ce,transform:[{scale:de}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.gridRow,children:e.map(e=>{const t=e+10-1,a=pe(e),r=!!re&&decadeStartFor(re.getFullYear())===e,i=decadeStartFor(J.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:()=>we(e),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(H.decade,{start:e,end:t}),accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:K.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[K.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:o}],children:[(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.yearText,{color:l}],variant:"body",children:`${e}s`}),(0,_jsxRuntime.jsx)(_index7.Text,{variant:"caption",style:[K.decadeRangeText,{color:r?W.colors["on-primary"]:W.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e.join("-")}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Me,style:({pressed:e})=>[K.footerBtn,K.footerCancel,e&&K.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:H.cancel,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.footerBtnText,{color:W.colors["text-muted"]}],variant:"label",weight:"semibold",children:H.cancel})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,disabled:!re,style:({pressed:e})=>[K.footerBtn,K.footerConfirm,{backgroundColor:W.colors.primary,opacity:re?1:.5},e&&{backgroundColor:W.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:H.confirm,accessibilityState:{disabled:!re},"aria-disabled":!re,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.footerBtnText,{color:W.colors["on-primary"]}],variant:"label",weight:"semibold",children:H.confirm})})]})]}),Ve=t?(B??(e=>e.toLocaleDateString()))(t):void 0,Ae=!Y,Le={label:p,help:v,placeholder:f,helperText:j,error:R,required:D,disabled:w,size:C,variant:S,clearable:N,onClear:T,leftIcon:M,trailing:P,triggerStyle:k,valueStyle:I,labelStyle:V,messageStyle:A,accessibilityLabel:L,labels:z,style:x};if("inline"===F)return $||Ae?Ae?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index6.PickerTrigger,{...Le,value:Ve,onPress:()=>E(!0),testID:b}),$?Ie:null]}):Ie:null;const ze=(0,_jsxRuntime.jsx)(_index5.Modal,{open:$,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:H.dismiss},onInsetsChange:Z,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:K.gestureRoot,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.sheetWrap,{paddingBottom:Math.max(X.bottom,W.space.lg),opacity:Te,transform:[{translateY:le}]}],onLayout:e=>{oe.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ie})})});return Ae?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index6.PickerTrigger,{...Le,value:Ve,onPress:()=>E(!0),testID:b}),ze]}):ze};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:Math.round(e.text["2xl"].size*e.leading.heading),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=void 0;var _mobileCore=require("@webority/mobile-core"),_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("../../text/index.js"),_datePickerG=require("../../text/phone/datePicker.g.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../Calendar/index.js"),_index5=require("../Modal/index.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index6=require("../PickerTrigger/index.js"),_index7=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,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,sheetStyle:_,headerLabelStyle:m,navButtonStyle:g,footerButtonStyle:h,haptic:y,testID:b,label:v,help:p,placeholder:f,helperText:j,error:R,required:D,disabled:w,size:C,variant:S,clearable:N,onClear:T,leftIcon:M,trailing:P,triggerStyle:k,valueStyle:I,labelStyle:V,messageStyle:A,accessibilityLabel:z,triggerLabels:q,formatValue:B}=e,F=l?"inline":"modal",L=(0,_index.useMobileUiText)("datePicker",_datePickerG.DATE_PICKER_TEXT),H=(0,_react.useMemo)(()=>u?{...L,...u}:L,[L,u]),Y=void 0!==e.open,[O,E]=(0,_react.useState)(!1),$=void 0!==e.open?e.open:O,G=Y?b:b?`${b}-calendar`:void 0,W=(0,_index2.useTheme)(),U=(0,_usePresenceMotion.usePresenceMotion)(),[X,Z]=(0,_ModalSafeArea.useModalInsets)(),K=(0,_react.useMemo)(()=>buildStyles(W),[W]),[J,Q]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{$&&Q(startOfDay(new Date))},[$]);const ee=t?startOfDay(t):J,[te,ae]=(0,_react.useState)(ee),[re,ie]=(0,_react.useState)(t?startOfDay(t):null),[se,ne]=(0,_react.useState)("days"),le=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,oe=(0,_react.useRef)(0),ce=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current,de=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current,ue=(0,_react.useRef)((0,_index2.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);ie(e),ae(e)}else ie(null)},[t]);const xe=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),me=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),ge=(0,_react.useMemo)(()=>buildYearCells(te.getFullYear()),[te]),he=(0,_react.useMemo)(()=>buildDecadeCells(te.getFullYear()),[te]),ye=(0,_react.useMemo)(()=>{const e=te.getFullYear();if("years"===se)return`${e-4} - ${e+7}`;const t=decadeStartFor(e)-40;return`${t} - ${t+110+9}`},[te,se]),be=(0,_react.useCallback)(e=>!!(xe&&e<xe.getFullYear())||!!(me&&e>me.getFullYear()),[xe,me]),ve=(0,_react.useCallback)(e=>!!(xe&&e+10-1<xe.getFullYear())||!!(me&&e>me.getFullYear()),[xe,me]),pe=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("impactLight"),ae("years"===se?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[se,y]),fe=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("impactLight"),ae("years"===se?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[se,y]),je=(0,_react.useCallback)(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):W.motion.duration.default;(0,_index2.setNativeValue)(ce,0),(0,_index2.setNativeValue)(de,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ce,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(de,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:_nativeDriver.nativeDriver})]).start()},[ce,de,U,W.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(y,"selection");if(e&&(0,_index3.triggerHaptic)(e),!U.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ue,{toValue:.96,duration:e,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(ue,{toValue:1,duration:t,useNativeDriver:_nativeDriver.nativeDriver})]).start()}ne(e=>"days"===e?"years":"years"===e?"decades":"years"),je()},[je,ue,y,U.reduced]),De=(0,_react.useCallback)(e=>{const t=(0,_index3.resolveHaptic)(y,"selection");t&&(0,_index3.triggerHaptic)(t),ae(t=>new Date(e,t.getMonth(),1)),ne("days"),je()},[je,y]),we=(0,_react.useCallback)(e=>{const t=(0,_index3.resolveHaptic)(y,"selection");t&&(0,_index3.triggerHaptic)(t),ae(t=>new Date(e+4,t.getMonth(),1)),ne("years"),je()},[je,y]),Ce=(0,_react.useCallback)(e=>{ie(e.start)},[]),Se=(0,_react.useCallback)(()=>{Y||E(!1),r?.()},[Y,r]),{handleGesture:Ne,opacity:Te}=(0,_useDragToDismiss.useDragToDismiss)({drag:le,travel:()=>oe.current||320,onDismiss:Se});(0,_react.useEffect)(()=>{$&&"modal"===F&&((0,_index2.setNativeValue)(le,0),(0,_index2.setNativeValue)(Te,1))},[$,F,le,Te]);const Me=(0,_react.useCallback)(()=>{!1!==y&&(0,_index3.triggerHaptic)("selection"),Se()},[Se,y]),Pe=(0,_react.useCallback)(()=>{re&&(!1!==y&&(0,_index3.triggerHaptic)("notificationSuccess"),a?.(re),Se())},[Se,a,re,y]),ke=(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.titleRow,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.title,variant:"title",accessibilityRole:"header",children:d??H.title})}),Ie=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[K.card,_],accessibilityRole:"modal"===F?void 0:"none",accessible:!1,testID:G,children:["modal"===F?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Ne,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.handle}),ke]})}):ke,"days"!==se?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:pe,style:({pressed:e})=>[K.navBtn,e&&K.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===se?H.previousYears:H.previousDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.navText,variant:"title",children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[K.headerLabelWrap,m],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===se?H.switchToDecades:H.switchToYears}`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[K.headerLabelInner,{transform:[{scale:ue}]}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[K.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.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:fe,style:({pressed:e})=>[K.navBtn,e&&K.navBtnPressed,g],accessibilityRole:"button",accessibilityLabel:"years"===se?H.nextYears:H.nextDecades,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index7.Text,{style:K.navText,variant:"title",children:"›"})})]}):null,"days"===se?(0,_jsxRuntime.jsx)(_index4.Calendar,{selectionMode:"single",value:re?{start:re}:null,onChange:Ce,month:te,onMonthChange:ae,minDate:i,maxDate:s,disabledDates:n,weekStartsOn:c,locale:o,haptic:y,headerLabelStyle:m,navButtonStyle:g,onTitlePress:Re,labels:{previousMonth:H.previousMonth,nextMonth:H.nextMonth},testID:G?`${G}-grid`:void 0}):"years"===se?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.yearGrid,{opacity:ce,transform:[{scale:de}]}],children:Array.from({length:3},(e,t)=>ge.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.gridRow,children:e.map(e=>{const t=be(e),a=!!re&&re.getFullYear()===e,r=J.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:()=>De(e),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(H.year,{year:e}),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:K.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[K.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:l}],children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.yearText,{color:n}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e.join("-")}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.yearGrid,{opacity:ce,transform:[{scale:de}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:K.gridRow,children:e.map(e=>{const t=e+10-1,a=ve(e),r=!!re&&decadeStartFor(re.getFullYear())===e,i=decadeStartFor(J.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:()=>we(e),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(H.decade,{start:e,end:t}),accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:K.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[K.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:o}],children:[(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.yearText,{color:l}],variant:"body",children:`${e}s`}),(0,_jsxRuntime.jsx)(_index7.Text,{variant:"caption",style:[K.decadeRangeText,{color:r?W.colors["on-primary"]:W.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e.join("-")}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:K.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Me,style:({pressed:e})=>[K.footerBtn,K.footerCancel,e&&K.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:H.cancel,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.footerBtnText,{color:W.colors["text-muted"]}],variant:"label",weight:"semibold",children:H.cancel})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,disabled:!re,style:({pressed:e})=>[K.footerBtn,K.footerConfirm,{backgroundColor:W.colors.primary,opacity:re?1:.5},e&&{backgroundColor:W.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:H.confirm,accessibilityState:{disabled:!re},"aria-disabled":!re,children:(0,_jsxRuntime.jsx)(_index7.Text,{style:[K.footerBtnText,{color:W.colors["on-primary"]}],variant:"label",weight:"semibold",children:H.confirm})})]})]}),Ve=t?(B??(e=>(0,_mobileCore.formatDate)(e,{zone:"viewer"})))(t):void 0,Ae=!Y,ze={label:v,help:p,placeholder:f,helperText:j,error:R,required:D,disabled:w,size:C,variant:S,clearable:N,onClear:T,leftIcon:M,trailing:P,triggerStyle:k,valueStyle:I,labelStyle:V,messageStyle:A,accessibilityLabel:z,labels:q,style:x};if("inline"===F)return $||Ae?Ae?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index6.PickerTrigger,{...ze,value:Ve,onPress:()=>E(!0),testID:b}),$?Ie:null]}):Ie:null;const qe=(0,_jsxRuntime.jsx)(_index5.Modal,{open:$,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:H.dismiss},onInsetsChange:Z,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:K.gestureRoot,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[K.sheetWrap,{paddingBottom:Math.max(X.bottom,W.space.lg),opacity:Te,transform:[{translateY:le}]}],onLayout:e=>{oe.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ie})})});return Ae?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index6.PickerTrigger,{...ze,value:Ve,onPress:()=>E(!0),testID:b}),qe]}):qe};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:Math.round(e.text["2xl"].size*e.leading.heading),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.DecimalInput=void 0,exports.cleanDecimalText=cleanDecimalText,exports.default=void 0,exports.isUnclearDecimalComma=isUnclearDecimalComma,exports.parseDecimalText=parseDecimalText,exports.pointDecimalText=pointDecimalText;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../text/index.js"),_decimalInputG=require("../../text/phone/decimalInput.g.js"),_index2=require("../Input/index.js"),_jsxRuntime=require("react/jsx-runtime");function cleanDecimalText(e,{whole:t,signed:a,decimals:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DecimalInput=void 0,exports.cleanDecimalText=cleanDecimalText,exports.default=void 0,exports.isUnclearDecimalComma=isUnclearDecimalComma,exports.parseDecimalText=parseDecimalText,exports.pointDecimalText=pointDecimalText;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../text/index.js"),_decimalInputG=require("../../text/phone/decimalInput.g.js"),_index2=require("../Input/index.js"),_jsxRuntime=require("react/jsx-runtime");function cleanDecimalText(e,{whole:t,signed:a,decimals:i,allowExponent:r}={}){const n=String(e??"");if(r)return n.replace(/[^\d.eE+-]/g,"");const l=Boolean(a)&&n.replace(/[^\d.,-]/g,"").startsWith("-");let o=n.replace(t?/\D/g:/[^\d.,]/g,"");const c=o.search(/[.,]/);if(-1!==c){const e=o.slice(c+1).replace(/[.,]/g,"");o=o.slice(0,c+1)+(null==i?e:e.slice(0,i))}return(l?"-":"")+o}function isUnclearDecimalComma(e){return/,\d{3}$/.test(String(e??""))}function pointDecimalText(e){return isUnclearDecimalComma(e)?e:e.replace(",",".")}function parseDecimalText(e){if(isUnclearDecimalComma(e))return"";const t=pointDecimalText(e);if(""===t||"-"===t||"."===t||"-."===t)return"";const a=Number(t);return Number.isFinite(a)?a:""}const textOf=e=>null==e?"":String(e),toNull=e=>""===e?null:e;function keyboardFor({whole:e,signed:t,allowExponent:a}){return a?"ios"===_reactNative.Platform.OS?"numbers-and-punctuation":"default":t?"numeric":e?"number-pad":"decimal-pad"}const DecimalInput=exports.DecimalInput=(0,_react.forwardRef)((e,t)=>{const{symbol:a,value:i,onChange:r,onBlur:n,min:l,max:o,whole:c=!1,signed:u=!1,decimals:s,allowExponent:m=!1,labels:p,error:d,readOnly:x=!1,disabled:D=!1,...f}=e,_=(0,_index.useMobileUiText)("decimalInput",_decimalInputG.DECIMAL_INPUT_TEXT),T=(0,_react.useMemo)(()=>({..._,...p}),[_,p]),[b,g]=(0,_react.useState)(textOf(i));(0,_react.useEffect)(()=>{g(e=>toNull(parseDecimalText(e))===(i??null)?e:textOf(i))},[i]);const I=x||D,v={whole:c,signed:u,decimals:s,allowExponent:m},C=b;return(0,_jsxRuntime.jsx)(_index2.Input,{prefix:a,keyboardType:keyboardFor(v),autoCapitalize:"none",autoCorrect:!1,readOnly:x,disabled:D,...f,ref:t,error:d??(isUnclearDecimalComma(C)?T.unclearComma:void 0),value:C,onChangeText:I?void 0:e=>{(0,_mobileCore.reportIdleActivity)();const t=cleanDecimalText(e,v),a=m?""===t?"":Number(t):parseDecimalText(t);""!==a&&Number.isFinite(a)&&(null!=o&&a>o||null!=l&&a<l)||(g(t),r?.(toNull(parseDecimalText(t))))},onBlur:I?void 0:e=>{const t=pointDecimalText(C);t!==C&&g(t),n?.(e)}})});DecimalInput.displayName="DecimalInput";var _default=exports.default=DecimalInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IdleTimeoutDialog=IdleTimeoutDialog;var _react=require("react"),_index=require("../../text/index.js"),_idleTimeoutDialogG=require("../../text/phone/idleTimeoutDialog.g.js"),_textStore=require("../../text/textStore.js"),_index2=require("../Dialog/index.js"),_jsxRuntime=require("react/jsx-runtime");const noop=()=>{},formatRemaining=e=>{if(!Number.isFinite(e)||e<0)throw new RangeError("IdleTimeoutDialog remainingMs must be a finite number of milliseconds, zero or more");const t=Math.ceil(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`};function IdleTimeoutDialog({open:e,remainingMs:t,onStay:i,onSignOut:o,labels:n,testID:r}){const s=(0,_index.useMobileUiText)("idleTimeoutDialog",_idleTimeoutDialogG.IDLE_TIMEOUT_DIALOG_TEXT),a=(0,_react.useMemo)(()=>({...s,...n}),[s,n]),l=formatRemaining(t);return(0,_jsxRuntime.jsx)(_index2.Dialog,{open:e,onClose:noop,tone:"warning",title:a.title,message:(0,_textStore.fillText)(a.message,{time:l}),actionsLayout:"stacked",dismissOnAction:!1,actions:[{label:a.stay,onPress:i,tone:"primary"},{label:a.signOut,onPress:o,tone:"neutral"}],testID:r})}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"IdleTimeoutDialog",{enumerable:!0,get:function(){return _IdleTimeoutDialog.IdleTimeoutDialog}});var _IdleTimeoutDialog=require("./IdleTimeoutDialog.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_inputG=require("../../text/phone/input.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index5=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_textInk=require("../Text/textInk.js"),_jsxRuntime=require("react/jsx-runtime");const Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:r,onChangeText:s,error:l,helperText:o,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:_,rightIcon:f,unit:g,unitStyle:m,prefix:v,prefixStyle:h,readOnly:y=!1,action:j,actionStyle:b,size:I="md",variant:R,labelMode:S,required:V=!1,maxLength:N,showCounter:w=!0,textAlign:T,format:F,parse:D,style:k,fieldStyle:q,inputStyle:z,labelStyle:A,messageStyle:B,radius:P,onFocus:C,onBlur:L,accessibilityLabel:M,labels:H,testID:E,editable:O,...G}=e;(0,_assertValidValue.assertValidValue)("Input","variant",R,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("Input","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Input","labelMode",S,["float","top"]),(0,_assertValidValue.assertValidValue)("Input","type",e.type,["input","password","textarea"]);const W=(0,_index2.useMobileUiText)("input",_inputG.INPUT_TEXT),$=(0,_react.useMemo)(()=>({...W,...H}),[W,H]),U=(0,_index3.useTheme)(),X=(0,_react.useMemo)(()=>buildStyles(U),[U]),J=(0,_index3.resolveFieldSize)(U,I),K=U.components.input[I]["multiline-min-height"],Q=Math.round(J.text*U.leading.body),Y=R??U.settings.components.input?.defaultVariant??U.settings.components.field?.defaultVariant??"outline",Z=S??U.settings.components.input?.defaultLabelMode??"top",[ee,te]=(0,_react.useState)(!1),[ie,ne]=(0,_react.useState)(!1),ae="password"===d||u||c,re="password"===d||u,se="textarea"===d||p,le=se?Math.round(.1*J.text):0,oe="string"==typeof r&&r.length>0,de=(0,_FieldBase.hasFieldText)(l),ce=!0===l||de,ue=(0,_FieldBase.hasFieldText)(o),xe=de||!ce&&ue,pe=(0,_FieldBase.hasFieldText)(i),fe=(0,_FieldBase.hasFieldText)(v),ge=!x&&!1!==O,me=ee||oe||fe,ve=(0,_react.useRef)(null),he=(0,_react.useMemo)(()=>(0,_index4.mergeRefs)(ve,t),[t]),ye=(0,_react.useCallback)(()=>{ge&&ve.current?.focus()},[ge]),je=pe&&"float"===Z,be=(0,_react.useRef)((0,_index3.createAnimatedValue)(0)).current,Ie=(0,_react.useRef)((0,_index3.createAnimatedValue)(xe?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.timing(Ie,{toValue:xe?1:0,duration:U.motion.duration.fast,easing:_reactNative.Easing.bezier(...U.motion.ease["in-out"]),useNativeDriver:_nativeDriver.nativeDriver});return e.start(),()=>e.stop()},[xe,Ie,U.motion.duration.fast,U.motion.ease["in-out"]]);const Re=(0,_index.useReducedMotion)(),Se=U.settings.components.input?.shakeOnError??!1,Ve=(0,_react.useRef)(ce);(0,_react.useEffect)(()=>{if(!Se)return void(Ve.current=ce);let e;return ce&&!Ve.current&&(Re||((0,_index3.setNativeValue)(be,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(be,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:0,duration:100,useNativeDriver:_nativeDriver.nativeDriver})]),e.start()),(0,_index4.triggerHaptic)("notificationError")),Ve.current=ce,()=>e?.stop()},[ce,be,Se,Re]);const Ne=(0,_react.useCallback)(e=>{te(!0),C?.(e)},[C]),we=(0,_react.useCallback)(e=>{te(!1),L?.(e)},[L]),Te=(0,_react.useCallback)(()=>{(0,_index4.triggerHaptic)("selection"),ne(e=>!e)},[]),Fe=U.colors["field-caret"],De=U.settings.components.input?.tintLabelOnFocus??!1,ke=ee&&De?U.colors["field-border-focus"]:U.colors["field-label"],qe=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ze=Boolean(f)||Boolean(g)||re,Ae="underline"===Y,Be=_?J.icon+U.space.md+1+U.space.md:0,Pe=(0,_useFloatingLabel.useFloatingLabel)({label:i,enabled:je,floated:me,required:V,variant:Y,sizeTokens:J,leadingOffset:Be,trailingOffset:ze?J.icon+U.space.sm:0,textAlign:"center"===T||"right"===T?T:"left",paddingLeft:Ae?U.space.none:J["padding-x"],lineHeight:se?Q:void 0,restNudge:le,floatTrim:se?2:0,color:ke,style:A}),Ce=(0,_FieldBase.resolveFieldTextStyle)(U,{disabled:x}),Le=Ce.color,Me=Ce.placeholderColor,He=V&&!pe&&!oe&&"string"==typeof a&&a.length>0,Ee=ce?l:o,Oe=w&&"number"==typeof N&&"string"==typeof r?`${r.length} / ${N}`:null,Ge=ce?U.colors["field-message"]:U.colors["text-muted"],We=(0,_textInk.useTextInk)(B,J["message-text"],Ge),$e=M??(0,_FieldBase.fieldTextAsString)(i)??a,Ue=x?U.colors["field-icon-disabled"]:ee?U.colors["field-icon-focus"]:U.colors["field-icon"],Xe={focused:ee,disabled:x,error:ce,color:Ue,size:J.icon},renderSlot=e=>(0,_slotIcon.renderSlotIcon)(e,Xe),Je=(()=>{if(re){const e=(ie?U.settings.icons.eyeOff:U.settings.icons.eye)??(ie?_defaultIcons.defaultIcons.eyeOff:_defaultIcons.defaultIcons.eye);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,disabled:!ge,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:ie?$.hidePassword:$.showPassword,children:e({size:J.icon,color:Ue})})}const e=g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.unit,{fontSize:J.text,color:Me},m],children:g}):null,t=f?(0,_slotIcon.slotIconView)(f,renderSlot(f)):null;return e&&t?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.trailingRow,children:[e,t]}):e??t})(),Ke=_?(0,_slotIcon.slotIconView)(_,renderSlot(_)):null,Qe=_reactNative.StyleSheet.flatten(h),Ye=Qe?.fontSize??J.text,Ze=Qe?.color??Me,et=(0,_react.useMemo)(()=>({fontSize:Ye,color:Ze}),[Ye,Ze]),tt=fe?"string"==typeof v||"number"==typeof v?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.prefix,{fontSize:J.text,color:Me,marginRight:U.space.xs,lineHeight:se?Q:void 0,paddingTop:se?le:void 0},h],children:v}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[X.prefixNode,{marginRight:U.space.xs,minHeight:se?Q:void 0,justifyContent:"center",paddingTop:se?le:void 0}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.prefix,{fontSize:J.text,color:Me,lineHeight:se?Q:void 0},h],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:et,children:v})})}):null,it=j?(0,_jsxRuntime.jsx)(_index5.Button,{variant:j.variant??"outline",tone:j.tone??"primary",size:I,label:j.label,leftIcon:j.icon,loading:j.loading,disabled:x||j.disabled,onPress:j.onPress,pressAnimation:!1,testID:j.testID,style:[X.action,{minHeight:J["min-height"],alignSelf:se?"flex-start":"stretch"},b]}):null;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[X.container,{transform:[{translateX:qe}]},k],children:[pe&&!je?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:I,required:V,help:n,color:ke,style:A,children:i}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[X.fieldRow,{columnGap:U.space.sm,alignItems:se?"flex-start":"stretch"}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.fieldWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{testID:E?`${E}-field`:void 0,size:I,variant:Y,focused:ee,disabled:x,error:ce,filled:oe,minHeight:se?K:void 0,radius:P,leading:Ke,leadingDivider:null!=_,paddingLeft:Ae?U.space.none:void 0,trailing:Je,slotAlign:se?"top":"center",slotLineHeight:se?Q:void 0,topNotch:Pe.topNotch,onPress:ye,pressFeedback:!1,style:q,children:[tt,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:he,style:[X.input,{color:Le,fontSize:J.text,...Ce.weightStyle,paddingLeft:Ae?U.space.none:void 0,minHeight:se?K-2*J["padding-y"]:void 0,lineHeight:se?Q:void 0,paddingTop:se?le:void 0,textAlignVertical:se?"top":"center"},z],textAlign:T,placeholder:je&&!me||He?void 0:a,placeholderTextColor:Me,value:F&&null!=r?F(r):r,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:Ne,onBlur:we,editable:ge,readOnly:y,secureTextEntry:ae&&!ie,multiline:se,autoCapitalize:ae?"none":void 0,autoCorrect:!ae&&void 0,maxLength:N,selectionColor:Fe,accessibilityLabel:$e,accessibilityState:{disabled:x},"aria-disabled":x,testID:E,...G}),He&&"string"==typeof a?(0,_jsxRuntime.jsx)(_FieldBase.RequiredPlaceholder,{text:a,color:Me,fontSize:J.text,weightStyle:Ce.weightStyle,align:se?"top":"center",paddingTop:se?le:void 0,textAlign:T}):null]})]}),Pe.node]}),it]}),xe||Oe?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[X.footerRow,{marginTop:J["message-gap"]}],children:[xe?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[X.messageRow,{columnGap:U.space.xs,opacity:Ie}],accessibilityLiveRegion:ce?"polite":"none",children:[ce?(0,_jsxRuntime.jsx)(_FieldBase.FieldErrorGlyph,{size:J["message-text"],color:Ge}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.messageText,{color:Ge,fontSize:J["message-text"],...(0,_index3.fontFor)(U,"normal")},B],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:We,children:Ee})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:X.footerSpacer}),Oe?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.counterText,{color:U.colors["text-subtle"],fontSize:J["message-text"],...(0,_index3.fontFor)(U,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>_reactNative.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}});var _default=exports.default=Input;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_inputG=require("../../text/phone/input.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index5=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_textInk=require("../Text/textInk.js"),_jsxRuntime=require("react/jsx-runtime");const Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:r,onChangeText:s,error:l,helperText:o,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:_,rightIcon:f,unit:g,unitStyle:m,prefix:v,prefixStyle:h,readOnly:y=!1,action:j,actionStyle:b,size:I="md",variant:R,labelMode:S,required:V=!1,maxLength:N,showCounter:w=!0,textAlign:T,format:F,parse:D,style:q,fieldStyle:k,inputStyle:z,labelStyle:A,messageStyle:B,radius:C,onFocus:P,onBlur:L,accessibilityLabel:M,labels:H,testID:E,editable:O,...G}=e;(0,_assertValidValue.assertValidValue)("Input","variant",R,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("Input","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Input","labelMode",S,["float","top"]),(0,_assertValidValue.assertValidValue)("Input","type",e.type,["input","password","textarea"]);const W=(0,_index2.useMobileUiText)("input",_inputG.INPUT_TEXT),$=(0,_react.useMemo)(()=>({...W,...H}),[W,H]),U=(0,_index3.useTheme)(),X=(0,_react.useMemo)(()=>buildStyles(U),[U]),J=(0,_index3.resolveFieldSize)(U,I),K=U.components.input[I]["multiline-min-height"],Q=Math.round(J.text*U.leading.body),Y=R??U.settings.components.input?.defaultVariant??U.settings.components.field?.defaultVariant??"outline",Z=S??U.settings.components.input?.defaultLabelMode??"top",[ee,te]=(0,_react.useState)(!1),[ie,ne]=(0,_react.useState)(!1),ae="password"===d||u||c,re="password"===d||u,se="textarea"===d||p,le=se?Math.round(.1*J.text):0,oe="string"==typeof r&&r.length>0,de=(0,_FieldBase.hasFieldText)(l),ce=!0===l||de,ue=(0,_FieldBase.hasFieldText)(o),xe=de||!ce&&ue,pe=(0,_FieldBase.hasFieldText)(i),fe=(0,_FieldBase.hasFieldText)(v),ge=!x&&!1!==O,me=ee||oe||fe,ve=(0,_react.useRef)(null),he=(0,_react.useMemo)(()=>(0,_index4.mergeRefs)(ve,t),[t]),ye=(0,_react.useCallback)(()=>{ge&&ve.current?.focus()},[ge]),je=pe&&"float"===Z,be=(0,_react.useRef)((0,_index3.createAnimatedValue)(0)).current,Ie=(0,_react.useRef)((0,_index3.createAnimatedValue)(xe?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.timing(Ie,{toValue:xe?1:0,duration:U.motion.duration.fast,easing:_reactNative.Easing.bezier(...U.motion.ease["in-out"]),useNativeDriver:_nativeDriver.nativeDriver});return e.start(),()=>e.stop()},[xe,Ie,U.motion.duration.fast,U.motion.ease["in-out"]]);const Re=(0,_index.useReducedMotion)(),Se=U.settings.components.input?.shakeOnError??!1,Ve=(0,_react.useRef)(ce);(0,_react.useEffect)(()=>{if(!Se)return void(Ve.current=ce);let e;return ce&&!Ve.current&&(Re||((0,_index3.setNativeValue)(be,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(be,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(be,{toValue:0,duration:100,useNativeDriver:_nativeDriver.nativeDriver})]),e.start()),(0,_index4.triggerHaptic)("notificationError")),Ve.current=ce,()=>e?.stop()},[ce,be,Se,Re]);const Ne=(0,_react.useCallback)(e=>{te(!0),P?.(e)},[P]),we=(0,_react.useCallback)(e=>{te(!1),L?.(e)},[L]),Te=(0,_react.useCallback)(()=>{(0,_index4.triggerHaptic)("selection"),ne(e=>!e)},[]),Fe=U.colors["field-caret"],De=U.settings.components.input?.tintLabelOnFocus??!1,qe=ee&&De?U.colors["field-border-focus"]:U.colors["field-label"],ke=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ze=Boolean(f)||Boolean(g)||re,Ae="underline"===Y,Be=_?J.icon+U.space.md+1+U.space.md:0,Ce=(0,_useFloatingLabel.useFloatingLabel)({label:i,enabled:je,floated:me,required:V,variant:Y,sizeTokens:J,leadingOffset:Be,trailingOffset:ze?J.icon+U.space.sm:0,textAlign:"center"===T||"right"===T?T:"left",paddingLeft:Ae?U.space.none:J["padding-x"],lineHeight:se?Q:void 0,restNudge:le,floatTrim:se?2:0,color:qe,style:A}),Pe=(0,_FieldBase.resolveFieldTextStyle)(U,{disabled:x}),Le=Pe.color,Me=Pe.placeholderColor,He=V&&!pe&&!oe&&"string"==typeof a&&a.length>0,Ee=ce?l:o,Oe=w&&"number"==typeof N&&"string"==typeof r?`${r.length} / ${N}`:null,Ge=ce?U.colors["field-message"]:U.colors["text-muted"],We=(0,_textInk.useTextInk)(B,J["message-text"],Ge),$e=M??(0,_FieldBase.fieldTextAsString)(i)??a,Ue=x?U.colors["field-icon-disabled"]:ee?U.colors["field-icon-focus"]:U.colors["field-icon"],Xe={focused:ee,disabled:x,error:ce,color:Ue,size:J.icon},renderSlot=e=>(0,_slotIcon.renderSlotIcon)(e,Xe),Je=(()=>{if(re){const e=(ie?U.settings.icons.eyeOff:U.settings.icons.eye)??(ie?_defaultIcons.defaultIcons.eyeOff:_defaultIcons.defaultIcons.eye);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,disabled:!ge,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:ie?$.hidePassword:$.showPassword,children:e({size:J.icon,color:Ue})})}const e=g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.unit,{fontSize:J.text,color:Me},m],children:g}):null,t=f?(0,_slotIcon.slotIconView)(f,renderSlot(f)):null;return e&&t?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.trailingRow,children:[e,t]}):e??t})(),Ke=_?(0,_slotIcon.slotIconView)(_,renderSlot(_)):null,Qe=_reactNative.StyleSheet.flatten(h),Ye=Qe?.fontSize??J.text,Ze=Qe?.color??Me,et=(0,_react.useMemo)(()=>({fontSize:Ye,color:Ze}),[Ye,Ze]),tt=fe?"string"==typeof v||"number"==typeof v?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.prefix,{fontSize:J.text,color:Me,marginRight:U.space.xs,lineHeight:se?Q:void 0,paddingTop:se?le:void 0},h],children:v}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[X.prefixNode,{marginRight:U.space.xs,minHeight:se?Q:void 0,justifyContent:"center",paddingTop:se?le:void 0}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.prefix,{fontSize:J.text,color:Me,lineHeight:se?Q:void 0},h],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:et,children:v})})}):null,it=j?(0,_jsxRuntime.jsx)(_index5.Button,{variant:j.variant??"outline",tone:j.tone??"primary",size:I,label:j.label,leftIcon:j.icon,loading:j.loading,disabled:x||j.disabled,onPress:j.onPress,pressAnimation:!1,testID:j.testID,style:[X.action,{minHeight:J["min-height"],alignSelf:se?"flex-start":"stretch"},b]}):null;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[X.container,{transform:[{translateX:ke}]},q],children:[pe&&!je?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:I,required:V,help:n,color:qe,style:A,children:i}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[X.fieldRow,{columnGap:U.space.sm,alignItems:se?"flex-start":"stretch"}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.fieldWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{testID:E?`${E}-field`:void 0,size:I,variant:Y,focused:ee,disabled:x,error:ce,filled:oe,minHeight:se?K:void 0,radius:C,leading:Ke,leadingDivider:null!=_,paddingLeft:Ae?U.space.none:void 0,trailing:Je,slotAlign:se?"top":"center",slotLineHeight:se?Q:void 0,topNotch:Ce.topNotch,onPress:ye,pressFeedback:!1,style:k,children:[tt,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:he,style:[X.input,{color:Le,fontSize:J.text,...Pe.weightStyle,paddingLeft:Ae?U.space.none:void 0,minHeight:se?K-2*J["padding-y"]:void 0,lineHeight:se?Q:void 0,paddingTop:se?le:void 0,textAlignVertical:se?"top":"center"},z],textAlign:T,placeholder:je&&!me||He?void 0:a,placeholderTextColor:Me,value:F&&null!=r?F(r):r,onChangeText:e=>{(0,_mobileCore.reportIdleActivity)(),s&&s(D?D(e):e)},onFocus:Ne,onBlur:we,editable:ge,readOnly:y,secureTextEntry:ae&&!ie,multiline:se,autoCapitalize:ae?"none":void 0,autoCorrect:!ae&&void 0,maxLength:N,selectionColor:Fe,accessibilityLabel:$e,accessibilityState:{disabled:x},"aria-disabled":x,testID:E,...G}),He&&"string"==typeof a?(0,_jsxRuntime.jsx)(_FieldBase.RequiredPlaceholder,{text:a,color:Me,fontSize:J.text,weightStyle:Pe.weightStyle,align:se?"top":"center",paddingTop:se?le:void 0,textAlign:T}):null]})]}),Ce.node]}),it]}),xe||Oe?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[X.footerRow,{marginTop:J["message-gap"]}],children:[xe?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[X.messageRow,{columnGap:U.space.xs,opacity:Ie}],accessibilityLiveRegion:ce?"polite":"none",children:[ce?(0,_jsxRuntime.jsx)(_FieldBase.FieldErrorGlyph,{size:J["message-text"],color:Ge}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.messageText,{color:Ge,fontSize:J["message-text"],...(0,_index3.fontFor)(U,"normal")},B],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:We,children:Ee})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:X.footerSpacer}),Oe?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[X.counterText,{color:U.colors["text-subtle"],fontSize:J["message-text"],...(0,_index3.fontFor)(U,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>_reactNative.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}});var _default=exports.default=Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NumberInput=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_numberInputG=require("../../text/phone/numberInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(n,r,i):n[r]=e[r]);return n}const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"],DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=exports.NumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,min:n=Number.NEGATIVE_INFINITY,max:s=Number.POSITIVE_INFINITY,step:l=1,allowDecimal:c=!1,precision:u=0,label:o,help:d,helperText:_,error:b,disabled:m=!1,size:x="md",variant:p="inline",unit:f,haptic:h,labels:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NumberInput=void 0;var cache,_mobileCore=require("@webority/mobile-core"),_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_numberInputG=require("../../text/phone/numberInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(n,r,i):n[r]=e[r]);return n}const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"],DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=exports.NumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,min:n=Number.NEGATIVE_INFINITY,max:s=Number.POSITIVE_INFINITY,step:l=1,allowDecimal:c=!1,precision:u=0,label:o,help:d,helperText:_,error:b,disabled:m=!1,size:x="md",variant:p="inline",unit:f,haptic:h,labels:y,accessibilityLabel:N,style:I,inputStyle:j,buttonStyle:g,unitStyle:T,labelStyle:v,textInputProps:S,testID:R}=e;(0,_assertValidValue.assertValidValue)("NumberInput","size",e.size,NUMBER_INPUT_SIZES),(0,_assertValidValue.assertValidValue)("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const F=(0,_index2.useMobileUiText)("numberInput",_numberInputG.NUMBER_INPUT_TEXT),V=(0,_react.useMemo)(()=>({...F,...y}),[F,y]),[P,C]=(0,_index.useControllableState)({value:i,defaultValue:r??e.min??0,onChange:a}),w=(0,_index3.useTheme)(),E=(0,_index3.resolveFieldSize)(w,x),z=(0,_FieldBase.resolveFieldTextStyle)(w,{disabled:m}),B=(0,_react.useMemo)(()=>buildStyles(w),[w]),M=(0,_react.useRef)(null),[k,q]=(0,_react.useState)(formatValue(P,c,u)),[A,L]=(0,_react.useState)(!1),[U,D]=(0,_react.useState)(!1),O=(0,_react.useCallback)(()=>{m||M.current?.focus()},[m]),W=(0,_react.useRef)(null),H=(0,_react.useRef)(null),G=(0,_react.useCallback)(()=>{null!==W.current&&(clearTimeout(W.current),W.current=null),null!==H.current&&(clearInterval(H.current),H.current=null)},[]);(0,_react.useEffect)(()=>G,[G]),(0,_react.useEffect)(()=>{A||q(formatValue(P,c,u))},[P,c,u,A]);const Y=P<=n,$=P>=s,Z=!m,X=(0,_react.useCallback)(e=>{const t=roundToPrecision(e,c?u:0),i=clamp(t,n,s);i!==P&&C(i)},[c,s,n,C,u,P]),J=(0,_react.useCallback)(()=>{if(!Z||Y)return;const e=(0,_index4.resolveHaptic)(h,"selection");e&&(0,_index4.triggerHaptic)(e),X(P-l)},[Y,Z,h,X,l,P]),K=(0,_react.useCallback)(()=>{if(!Z||$)return;const e=(0,_index4.resolveHaptic)(h,"selection");e&&(0,_index4.triggerHaptic)(e),X(P+l)},[$,Z,h,X,l,P]);_react.default.useImperativeHandle(t,()=>({focus:()=>M.current?.focus(),blur:()=>M.current?.blur(),clear:()=>{q(""),Number.isFinite(n)&&n>0?C(n):C(0<n?n:Math.min(s,0))}}),[s,n,C]);const Q=(0,_react.useCallback)(e=>{Z&&(G(),W.current=setTimeout(()=>{H.current=setInterval(()=>{"inc"===e?K():J()},80)},500))},[G,J,K,Z]),ee=(0,_react.useCallback)(e=>{(0,_mobileCore.reportIdleActivity)();const t=sanitizeTyped(e,c);q(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=n&&i<=s&&i!==P&&C(roundToPrecision(i,c?u:0))},[c,s,n,C,u,P]),te=(0,_react.useCallback)(()=>{L(!1),D(!1);const e=Number(k);if(""===k||!Number.isFinite(e))return void q(formatValue(P,c,u));const t=roundToPrecision(e,c?u:0),i=clamp(t,n,s);i!==P&&C(i),q(formatValue(i,c,u))},[c,k,s,n,C,u,P]),ie=(0,_react.useCallback)(()=>{L(!0),D(!0)},[]),re=Y||m?w.colors["text-disabled"]:w.colors["text-body"],ae=$||m?w.colors["text-disabled"]:w.colors["text-body"],ne=E.icon+8,renderStepper=(e,t,i,r,a,n)=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:t,onLongPress:()=>Q(e),onPressOut:G,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:ne,height:ne,alignItems:"center",justifyContent:"center",borderRadius:w.radius.pill,..._corners.smoothCorners},e&&!i?{backgroundColor:w.colors["surface-pressed"]}:null,g],testID:`${R??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",weight:"semibold",style:{fontSize:E.icon,color:a,fontWeight:w.weight.semibold,lineHeight:E.icon+2},children:n})}),se=N??(0,_FieldBase.fieldTextAsString)(o)??V.input,le=!0===b||(0,_FieldBase.hasFieldText)(b),ce=(0,_jsxRuntime.jsx)(_FieldBase.FieldBase,{testID:R?`${R}-field`:void 0,size:x,disabled:m,error:le,filled:!0,focused:U,onPress:O,pressFeedback:!1,leading:renderStepper("dec",J,Y||m,V.decrease,re,"−"),trailing:renderStepper("inc",K,$||m,V.increase,ae,"+"),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:B.inputRow,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:M,value:k,onChangeText:ee,onFocus:ie,onBlur:te,editable:!m,keyboardType:c?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:se,accessibilityValue:{now:Number.isFinite(P)?P:0},accessibilityState:{disabled:m},"aria-disabled":m,accessibilityActions:[{name:"increment",label:V.increase},{name:"decrement",label:V.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&K(),"decrement"===e.nativeEvent.actionName&&J()},style:[B.input,{fontSize:E.text,color:z.color,...z.weightStyle},j],...S}),f?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"bodySmall",style:[B.unit,{fontSize:E.text,color:z.placeholderColor},T],children:f}):null]})}),ue=(0,_FieldBase.hasFieldText)(o)?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:x,help:d,style:v,children:o}):null,oe=(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:x,error:le,text:le?b:_});return"horizontal"===p?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[B.horizontalContainer,I],testID:R,accessibilityState:{disabled:m},"aria-disabled":m,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:B.horizontalLabelWrap,children:ue}),(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[ce,oe]})]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[I],testID:R,accessibilityState:{disabled:m},"aria-disabled":m,children:[ue,ce,oe]})});NumberInput.displayName="NumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});var _default=exports.default=NumberInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_otpInputG=require("../../text/phone/otpInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const cellAt=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`OTP cell ${t} is outside the ${e.length} cells.`);return i},sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,onComplete:n,length:s=6,keyboardType:l="number-pad",autoFocus:o=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:p=!1,haptic:m,labels:v,onFocus:x,accessibilityLabel:g,style:h,cellStyle:f,textStyle:b,testID:y}=e;(0,_assertValidValue.assertValidValue)("OTPInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=(0,_index2.useMobileUiText)("otpInput",_otpInputG.OTP_INPUT_TEXT),T=(0,_react.useMemo)(()=>({...j,...v}),[j,v]),[N,V]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:a}),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_otpInputG=require("../../text/phone/otpInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const cellAt=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`OTP cell ${t} is outside the ${e.length} cells.`);return i},sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,onComplete:n,length:s=6,keyboardType:l="number-pad",autoFocus:o=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:p=!1,haptic:m,labels:v,onFocus:x,accessibilityLabel:g,style:h,cellStyle:f,textStyle:b,testID:y}=e;(0,_assertValidValue.assertValidValue)("OTPInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=(0,_index2.useMobileUiText)("otpInput",_otpInputG.OTP_INPUT_TEXT),T=(0,_react.useMemo)(()=>({...j,...v}),[j,v]),[N,V]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:a}),C=(0,_index3.useTheme)(),k=(0,_react.useMemo)(()=>buildStyles(C),[C]),D=(0,_index3.resolveOtpInputSize)(C,_),I=C.components["otp-input"][_].radius,R=(0,_react.useRef)([]),[A,w]=(0,_react.useState)(-1),[E,F]=(0,_react.useState)(0),O=(0,_react.useRef)(null),M=(0,_react.useRef)((0,_index3.createAnimatedValue)(0)).current,q=(0,_react.useRef)(new Map),P=(0,_react.useMemo)(()=>{const e=q.current,t=[];for(let i=0;i<s;i+=1){let r=e.get(i);r||(r=new _reactNative.Animated.Value(0),e.set(i,r)),t.push(r)}for(const t of Array.from(e.keys()))t>=s&&e.delete(t);return t},[s]),S=(0,_react.useRef)(-1),z=C.settings.components["otp-input"]?.shakeOnError??!1,B=(0,_index.useReducedMotion)(),H=!0===d||(0,_FieldBase.hasFieldText)(d);(0,_react.useEffect)(()=>{let e;return null===O.current||!H||O.current||(m&&(0,_index4.triggerHaptic)("notificationError"),z&&!B&&((0,_index3.setNativeValue)(M,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(M,{toValue:1,duration:C.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(M,{toValue:-1,duration:C.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(M,{toValue:1,duration:C.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(M,{toValue:0,duration:C.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:_nativeDriver.nativeDriver})]),e.start())),O.current=H,()=>e?.stop()},[H,M,z,m,B,C.motion.duration.instant]),(0,_react.useEffect)(()=>{const e=S.current;if(S.current=A,e===A)return;if(-1===e&&-1===A)return;const t=[];return P.forEach((i,r)=>{const a=r===A?1:0;if(r!==A&&r!==e)return;const n=_reactNative.Animated.timing(i,{toValue:a,duration:C.motion.duration.fast,easing:_reactNative.Easing.bezier(...C.motion.ease["in-out"]),useNativeDriver:_nativeDriver.nativeDriver});n.start(),t.push(n)}),()=>t.forEach(e=>{e.stop()})},[A,P,C]);const L=(0,_react.useCallback)(e=>{const t=R.current[e];t&&t.focus()},[]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>L(0),blur:()=>{const e=R.current[Math.max(A,0)];e?.blur()},clear:()=>{V(""),L(0)}}),[L,A,V]),(0,_react.useEffect)(()=>{if(o&&!u){const e=setTimeout(()=>L(0),c);return()=>clearTimeout(e)}},[o,c,u,L]);const W=(0,_react.useMemo)(()=>{const e=new Array(s).fill("");for(let t=0;t<Math.min(N.length,s);t+=1)e[t]=N.charAt(t);return e},[N,s]),G=(0,_react.useMemo)(()=>W.map((e,t)=>({key:`otp-cell-${t}`,index:t,char:e})),[W]),$=(0,_react.useCallback)(e=>{const t=e.slice(0,s);t!==N&&(V(t),t.length===s&&n&&n(t))},[s,V,n,N]),U=(0,_react.useCallback)((e,t)=>{const i=t.replace(/\u200B/g,""),r=sanitizeChar(i,l);if(!r){const t=W.slice(),i=cellAt(W,e).length>0;if(t[e]="",$(t.join("").slice(0,s)),!i&&e>0){const t=W.slice();t[e-1]="",$(t.join("")),L(e-1)}return}const a=cellAt(W,e),n=a&&r.length>s&&r.startsWith(a)?r.slice(a.length):r;if(n.length>=s){const t=n.slice(0,s),i=N.length;return $(t),t.length!==i&&m&&(0,_index4.triggerHaptic)(m),void R.current[e]?.blur()}const o=W.slice();let c=e;for(let e=0;e<r.length&&c<s;e+=1)o[c]=r.charAt(e),c+=1;const u=o.join("").slice(0,s),d=N.length;$(u),u.length!==d&&m&&(0,_index4.triggerHaptic)(m);const _=Math.min(c,s-1);c>=s?R.current[e]?.blur():L(_)},[W,L,l,s,m,$,N]),X=(0,_react.useCallback)((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===cellAt(W,e).length){if(e>0){const t=W.slice();t[e-1]="",$(t.join("")),L(e-1)}}else{const t=W.slice();t[e]="",$(t.join(""))}},[W,L,$]),K=(0,_react.useCallback)((e,t)=>{w(e),x?.(t)},[x]),J=(0,_react.useCallback)(()=>{w(-1)},[]),Q=(0,_react.useCallback)(()=>{if(u)return;const e=W.indexOf("");L(-1===e?s-1:e)},[W,u,L,s]),Y=(0,_react.useCallback)(e=>{F(e.nativeEvent.layout.width)},[]),Z=g??(0,_index2.fillText)(T.field,{length:s}),ee=E>0?Math.max(24,Math.min(D.cell,Math.floor((E-D.gap*(s-1))/s))):D.cell,te=M.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:h,onLayout:Y,accessible:!0,accessibilityRole:"none",accessibilityLabel:Z,accessibilityValue:{text:i},accessibilityState:{disabled:u},"aria-disabled":u,testID:y,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Q,disabled:u,accessible:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[k.row,{columnGap:D.gap,transform:[{translateX:te}]}],children:G.map(({key:e,index:t,char:i})=>{const r=A===t,a=i.length>0,n=H?C.colors["danger-border"]:C.colors["focus-ring"],o=P[t];if(!o)return null;const c=p&&a?"●":i;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:k.cellWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:_,width:ee,height:ee,radius:I,borderWidth:1.5,focused:r,error:H,filled:a,disabled:u,paddingHorizontal:C.space.none,paddingVertical:C.space.none,gap:C.space.none,style:f,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:e=>{R.current[t]=e},value:(p&&a?"":i)||"",onChangeText:e=>{(0,_mobileCore.reportIdleActivity)(),U(t,e)},onKeyPress:e=>X(t,e),onFocus:e=>K(t,e),onBlur:J,keyboardType:l,editable:!u,selectTextOnFocus:!0,caretHidden:a,maxLength:s+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[k.input,{fontSize:D.text,color:C.colors["text-body"],...(0,_index3.fontFor)(C,"semibold")},b]}),p&&a?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:k.maskOverlay,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",weight:"semibold",style:[{fontSize:D.text},b],children:c})}):null]}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[k.underline,{backgroundColor:n,opacity:o}]})]},e)})})}),(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:_,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,..._corners.smoothCorners}});var _default=exports.default=OTPInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OptionSheet=OptionSheet,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../text/index.js"),_optionSheetG=require("../../text/phone/optionSheet.g.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Modal/index.js"),_index4=require("../Text/index.js"),_optionAccessors=require("./optionAccessors.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:s,sections:r,renderSectionHeader:o,renderOption:n,alphabetIndex:a=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:x,getOptionAction:m,value:_,onChange:g,multi:b=!1,searchable:y=!1,searchSelectionColor:j,accessibilityLabel:f,optionStyle:R,selectedOptionStyle:S,optionTextStyle:v,selectedOptionTextStyle:T,testID:w}=e,C=c??_optionAccessors.selectOptionLabel,N=d??_optionAccessors.selectOptionValue,I=u??_optionAccessors.selectOptionDescription,k=p??_optionAccessors.selectOptionDisabled,O=h??_optionAccessors.selectOptionIcon,L=m??_optionAccessors.selectOptionAction,V=(0,_index2.useTheme)(),D=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),H=(0,_react.useMemo)(()=>buildStyles(V),[V]),[P,A]=(0,_react.useState)(""),M=_reactNative.Dimensions.get("window").height,B=Math.round(.7*M),q=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,{handleGesture:z,opacity:W}=(0,_useDragToDismiss.useDragToDismiss)({drag:q,travel:B,onDismiss:t,testID:w}),G=(0,_reactNativeGestureHandler.useNativeGesture)(),F=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),E=Math.max(0,Math.round(F)),K=Math.max(D.top,_reactNative.StatusBar.currentHeight??0)+V.space.sm,U=E>0,$=U?Math.max(0,Math.min(B,M-E-K)):B,Y=(0,_react.useMemo)(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||C(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!r)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return r.forEach((e,i)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:i})}}),t},[y,P,s,r,C,I]),Z=(0,_react.useCallback)(()=>{t()},[t]),X=(0,_react.useRef)(null),J=(0,_react.useMemo)(()=>{const e=new Map;if(!a)return e;let t=0;if(r)for(const[e,i]of Y.entries())"header"===i.kind&&(t=e+1);for(const[i,s]of Y.entries()){if(i<t||"option"!==s.kind)continue;const r=C(s.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(r)?r:"#";e.has(o)||e.set(o,i)}return e},[a,Y,r,C]),Q=a&&J.size>0&&0===P.trim().length,ee=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...J.has("#")?["#"]:[]],[J]),te=(0,_react.useCallback)(e=>{const t=J.get(e);void 0!==t&&X.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[J]),ie=(0,_react.useRef)(null),se=(0,_react.useCallback)(()=>{null!==ie.current&&(clearTimeout(ie.current),ie.current=null)},[]),re=(0,_react.useCallback)(e=>{X.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),ie.current=setTimeout(()=>{ie.current=null,X.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);(0,_react.useEffect)(()=>se,[se]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:H.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:w,accessibilityViewIsModal:!0,accessibilityLabel:f??i??l.fallbackName,style:[H.sheet,{maxHeight:$,marginBottom:E,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,..._corners.smoothCorners,opacity:W,transform:[{translateY:q}],...V.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:z,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.sheetHandle,{backgroundColor:V.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"title",style:[H.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:i}):null]})}),y?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[H.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,..._corners.smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:P,onChangeText:A,placeholder:l.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:j??V.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[H.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>A(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(V.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[H.listWrap,Q?H.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:G,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:X,data:Y,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(N(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[H.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:H.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,s=C(i),r=N(i),a=I(i),l=O(i),c=(d=r,Array.isArray(_)?_.some(e=>String(e)===String(d)):null!=_&&String(_)===String(d));var d;const u=k(i),p=x?.(i)??!1,h=L(i);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{if(h)return h(),void Z();g(r,i)},disabled:u,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[H.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},R,c?S:null],children:[n?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.optionTextWrap,children:n({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:H.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[H.optionLabel,v,c?T:null],children:s}),a?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:H.optionDescription,children:a}):null]})]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.singleSelectedIcon,children:(V.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:re,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?H.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:l.empty})})}),Q?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=J.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(l.jumpTo,{letter:e}),accessibilityState:{disabled:!t},"aria-disabled":!t,style:H.railLetter,children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[H.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Z,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[H.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,..._corners.smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:s,labels:r,onClose:o,haptic:n,...a}=e,l=(0,_index.useMobileUiText)("optionSheet",_optionSheetG.OPTION_SHEET_TEXT),c=(0,_react.useMemo)(()=>({...l,...r}),[l,r]),d=(0,_react.useRef)(i);d.current=i;const u=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{u.current!==t&&(u.current=t,d.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index3.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:s,haptic:n,contentStyle:hostStyle,labels:{close:c.closePicker},accessibilityLabel:a.accessibilityLabel??a.title??c.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...a,onClose:o,labels:c})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OptionSheet=OptionSheet,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../text/index.js"),_optionSheetG=require("../../text/phone/optionSheet.g.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Modal/index.js"),_index4=require("../Text/index.js"),_optionAccessors=require("./optionAccessors.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:r,sections:s,renderSectionHeader:o,renderOption:a,alphabetIndex:n=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:x,getOptionAction:m,value:_,onChange:b,multi:g=!1,searchable:y=!1,searchSelectionColor:j,accessibilityLabel:f,optionStyle:R,selectedOptionStyle:v,optionTextStyle:S,selectedOptionTextStyle:T,testID:w}=e,C=c??_optionAccessors.selectOptionLabel,N=d??_optionAccessors.selectOptionValue,I=u??_optionAccessors.selectOptionDescription,k=p??_optionAccessors.selectOptionDisabled,O=h??_optionAccessors.selectOptionIcon,L=m??_optionAccessors.selectOptionAction,V=(0,_index2.useTheme)(),D=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),H=(0,_react.useMemo)(()=>buildStyles(V),[V]),[A,P]=(0,_react.useState)(""),M=(0,_react.useCallback)(e=>{(0,_mobileCore.reportIdleActivity)(),P(e)},[]),q=_reactNative.Dimensions.get("window").height,B=Math.round(.7*q),z=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,{handleGesture:W,opacity:G}=(0,_useDragToDismiss.useDragToDismiss)({drag:z,travel:B,onDismiss:t,testID:w}),F=(0,_reactNativeGestureHandler.useNativeGesture)(),E=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),K=Math.max(0,Math.round(E)),U=Math.max(D.top,_reactNative.StatusBar.currentHeight??0)+V.space.sm,$=K>0,Y=$?Math.max(0,Math.min(B,q-K-U)):B,Z=(0,_react.useMemo)(()=>{const e=y?A.trim().toLowerCase():"",matches=t=>0===e.length||C(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!s)return r.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return s.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[y,A,r,s,C,I]),X=(0,_react.useCallback)(()=>{t()},[t]),J=(0,_react.useRef)(null),Q=(0,_react.useMemo)(()=>{const e=new Map;if(!n)return e;let t=0;if(s)for(const[e,i]of Z.entries())"header"===i.kind&&(t=e+1);for(const[i,r]of Z.entries()){if(i<t||"option"!==r.kind)continue;const s=C(r.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(s)?s:"#";e.has(o)||e.set(o,i)}return e},[n,Z,s,C]),ee=n&&Q.size>0&&0===A.trim().length,te=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Q.has("#")?["#"]:[]],[Q]),ie=(0,_react.useCallback)(e=>{const t=Q.get(e);void 0!==t&&J.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Q]),re=(0,_react.useRef)(null),se=(0,_react.useCallback)(()=>{null!==re.current&&(clearTimeout(re.current),re.current=null)},[]),oe=(0,_react.useCallback)(e=>{J.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),re.current=setTimeout(()=>{re.current=null,J.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);(0,_react.useEffect)(()=>se,[se]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:H.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:w,accessibilityViewIsModal:!0,accessibilityLabel:f??i??l.fallbackName,style:[H.sheet,{maxHeight:Y,marginBottom:K,paddingBottom:$?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,..._corners.smoothCorners,opacity:G,transform:[{translateY:z}],...V.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:W,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.sheetHandle,{backgroundColor:V.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"title",style:[H.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:i}):null]})}),y?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[H.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,..._corners.smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:A,onChangeText:M,placeholder:l.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:j??V.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[H.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),A.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>P(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(V.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[H.listWrap,ee?H.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:F,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:J,data:Z,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(N(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[H.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:H.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,r=C(i),s=N(i),n=I(i),l=O(i),c=(d=s,Array.isArray(_)?_.some(e=>String(e)===String(d)):null!=_&&String(_)===String(d));var d;const u=k(i),p=x?.(i)??!1,h=L(i);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{if(h)return h(),void X();b(s,i)},disabled:u,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[H.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},R,c?v:null],children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.optionTextWrap,children:a({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:H.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[H.optionLabel,S,c?T:null],children:r}),n?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:H.optionDescription,children:n}):null]})]}),g?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H.singleSelectedIcon,children:(V.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!ee,style:ee?H.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:l.empty})})}),ee?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:te.map(e=>{const t=Q.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>ie(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:(0,_index.fillText)(l.jumpTo,{letter:e}),accessibilityState:{disabled:!t},"aria-disabled":!t,style:H.railLetter,children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[H.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),g?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[H.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:X,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[H.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,..._corners.smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:r,labels:s,onClose:o,haptic:a,...n}=e,l=(0,_index.useMobileUiText)("optionSheet",_optionSheetG.OPTION_SHEET_TEXT),c=(0,_react.useMemo)(()=>({...l,...s}),[l,s]),d=(0,_react.useRef)(i);d.current=i;const u=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{u.current!==t&&(u.current=t,d.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index3.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:r,haptic:a,contentStyle:hostStyle,labels:{close:c.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??c.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...n,onClose:o,labels:c})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PagedList=PagedList;var _react=require("react"),_reactNative=require("react-native"),_useRefreshControl=require("../../hooks/useRefreshControl.js"),_index=require("../../text/index.js"),_asyncBlockG=require("../../text/phone/asyncBlock.g.js"),_index2=require("../AsyncBlock/index.js"),_index3=require("../EmptyState/index.js"),_index4=require("../PagedListFooter/index.js"),_jsxRuntime=require("react/jsx-runtime");const noop=()=>{},styles=_reactNative.StyleSheet.create({flex:{flex:1},grow:{flexGrow:1}}),isElementFooter=e=>(0,_react.isValidElement)(e);function renderFooter(e){if(null==e)return null;if(isElementFooter(e))return e;const t=e;return(0,_jsxRuntime.jsx)(t,{})}function PagedList(e){const{state:t,paging:r,empty:s,skeleton:n,errorTitle:o,data:i,placeholderStyle:l,onRefresh:a,refreshing:d,progressViewOffset:u,ref:x,onEndReached:c,ListFooterComponent:_,style:f,contentContainerStyle:y,...h}=e,m=(0,_index.useMobileUiText)("asyncBlock",_asyncBlockG.ASYNC_BLOCK_TEXT),j="data"===t?.status||"empty"===t?.status?t:void 0,{refreshControl:p}=(0,_useRefreshControl.useRefreshControl)({onRefresh:j?j.refresh:a??noop,refreshing:j?j.refreshing:d}),g=a||j?void 0===u?p:(0,_react.cloneElement)(p,{progressViewOffset:u}):void 0,handleEndReached=e=>{r?.hasMore&&!r.loadingMore&&null==r.errorMore&&r.loadMore(),c?.(e)},renderList=(e,t)=>(0,_jsxRuntime.jsx)(_reactNative.FlatList,{data:e,keyboardShouldPersistTaps:"handled",onEndReachedThreshold:r?.5:void 0,...h,ref:x,refreshControl:g,onEndReached:r?handleEndReached:c,ListEmptyComponent:t,ListFooterComponent:r||_?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[renderFooter(_),r?(0,_jsxRuntime.jsx)(_index4.PagedListFooter,{paging:r}):null]}):void 0,style:[styles.flex,f],contentContainerStyle:[y,t?styles.grow:void 0]});return"empty"===t?.status?renderList([],(0,_jsxRuntime.jsx)(_index3.EmptyState,{...s??{title:m.emptyTitle}})):t?(0,_jsxRuntime.jsx)(_index2.AsyncBlock,{state:t,skeleton:n,errorTitle:o,style:[styles.flex,l],children:e=>renderList(e,void 0)}):renderList(i,s?(0,_jsxRuntime.jsx)(_index3.EmptyState,{...s}):void 0)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"PagedList",{enumerable:!0,get:function(){return _PagedList.PagedList}});var _PagedList=require("./PagedList.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_phoneNumberInputG=require("../../text/phone/phoneNumberInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index5=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,a=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;a=o.slice(r.length)}const l=t.filter(e=>e.code===r),s=l.find(e=>e.iso===i)?.iso??l.find(e=>e.iso===n?.country)?.iso??n?.country??l[0]?.iso??"";return{callingCode:r,nationalNumber:a,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:a,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:b=ALL_CALLING_CODES,popularCountries:p,hiddenCountries:m,showFlag:_=!0,renderFlag:h,renderCountry:f,showAlphabetIndex:g,defaultCountry:x,validation:C="any",maxLength:N,formatAsYouType:v=!0,countryLocked:y=!1,label:S,labelMode:I="top",labelStyle:L,placeholder:j,helperText:E,error:T,invalidMessage:V,required:F,disabled:O=!1,size:P="md",variant:A,radius:R,labels:D,haptic:q,accessibilityLabel:M,countryAccessibilityLabel:w,onFocus:k,onBlur:z,style:U,testID:B}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const $=(0,_index3.useTheme)(),G=(0,_react.useMemo)(()=>buildStyles($),[$]),W=(0,_react.useRef)(null),H=(0,_index2.useMobileUiText)("phoneNumberInput",_phoneNumberInputG.PHONE_NUMBER_INPUT_TEXT),Y=(0,_react.useMemo)(()=>({...H,...D}),[H,D]),K=j??Y.placeholder,X=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),Z=(0,_react.useMemo)(()=>m?.length?b.filter(e=>!m.includes(e.iso)):b,[b,m]),J=(0,_react.useMemo)(()=>{if(!p?.length)return;const e=p.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:Z}]:void 0},[p,Y.popular,Y.allCountries,Z]),Q=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(h)return h(e);if(!_)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index6.Text,{variant:"body",style:[G.flag,{fontSize:t}],testID:i,children:o}):null},[h,_,G.flag]),ee=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(i,N):i},[N,C]),te=(0,_react.useCallback)((e,t)=>e.slice(0,ee(t)),[ee]),ie=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=b.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:te(o.nationalNumber,n),iso:r?.iso??n}},[b,te]);(0,_react.useState)(()=>assertDefaultCountryVisible(x,Z));const oe=(0,_react.useMemo)(()=>{const e=Z.find(e=>e.iso===(x??X))??Z[0]??b[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?ie(o,t.iso)??t:o??t},[b,Z,x,X,o,ie]),ne=(0,_react.useCallback)(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[re,ae]=(0,_react.useState)(oe.iso),le=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,b,re):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=b.find(e=>e.iso===re);return{callingCode:t?.code??oe.callingCode,nationalNumber:"",iso:re}},[r,b,re,oe.callingCode,te]),se=(0,_react.useCallback)(e=>{ae(e.iso),n?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:b.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ne(e)})},[n,a,b,ne]),[ue,de]=(0,_index.useControllableState)({value:i??le,defaultValue:oe,onChange:se}),[ce,be]=(0,_react.useState)(!1),pe=(0,_react.useCallback)(()=>{O||W.current?.focus()},[O]),[me,he]=(0,_react.useState)(!1),[fe,ge]=(0,_react.useState)(!1),[xe,Ce]=(0,_react.useState)(!1),Ne=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{xe||(Ne.current=!1)},[xe]);const ve=(0,_index3.resolveFieldSize)($,P),ye=(0,_index5.resolveFieldTextStyle)($,{disabled:O}),Se=A??$.settings.components.field?.defaultVariant??"outline",Ie="underline"===Se,Le=$.space.md,[je,Ee]=(0,_react.useState)(0),Te=je+Le+1+Le,Ve=ue.nationalNumber.length>0,Fe=F&&!S&&!Ve&&K.length>0,Oe=ce||Ve,Pe=Boolean(S)&&"float"===I&&je>0,Ae=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Pe,floated:Oe,required:F,variant:Se,sizeTokens:ve,leadingOffset:Te,paddingLeft:Ie?$.space.none:ve["padding-x"],color:$.colors["field-label"],style:L}),Re=(0,_react.useMemo)(()=>b.find(e=>e.iso===ue.iso),[b,ue.iso]),De=planOf(ue.iso),qe=v&&De?(0,_mobileCore.formatPhoneAsTyped)(ue.nationalNumber,De):ue.nationalNumber,Me=ee(ue.iso),we=0===ue.nationalNumber.length||me||!Number.isFinite(Me)?void 0:qe.length+Math.max(0,Me-ue.nationalNumber.length),ke=ne(ue);(0,_react.useEffect)(()=>{Ve||ge(!1)},[Ve]);const ze=De?(0,_mobileCore.maxNationalNumberLength)(De,!1===C?"any":C):Number.POSITIVE_INFINITY,Ue=ue.nationalNumber.length>=ze,Be=!1!==C&&!1!==V&&Ve&&!ke&&(fe||Ue),$e="mobile"===C?Y.invalidMobile:Y.invalid,Ge=(0,_index5.hasFieldText)(T)?T:Be?V||$e:void 0,We=!0===T||(0,_index5.hasFieldText)(Ge),He=(0,_react.useRef)(ke),Ye=(0,_react.useRef)(ue);Ye.current=ue,(0,_react.useEffect)(()=>{He.current!==ke&&(He.current=ke,c?.(ke),ke&&d?.(formatE164(Ye.current)))},[ke,d,c]);const Ke=(0,_react.useCallback)(e=>{if(e.includes("+")){const t=ie(e,ue.iso);if(t&&!y&&Z.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[Z,y,ue,ie,te,de]),Xe=(0,_react.useCallback)(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),Ce(!1);const t=(0,_index4.resolveHaptic)(q,"selection");t&&(0,_index4.triggerHaptic)(t)},[ue,q,te,de]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>W.current?.focus(),blur:()=>W.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>W.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>ne(Ye.current),getCountry:()=>b.find(e=>e.iso===Ye.current.iso)}),[b,ne,de]);const Ze=O||y,Je=(0,_jsxRuntime.jsx)(_index5.FieldBase,{testID:B?`${B}-field`:void 0,size:P,variant:Se,radius:R,topNotch:Ae.topNotch,focused:ce,disabled:O,error:We,filled:Ve,onPress:pe,pressFeedback:!1,leadingDivider:!0,paddingLeft:Ie?$.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Ze||(Ne.current=!0,Ce(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:w??(0,_index2.fillText)(Y.countryButton,{callingCode:ue.callingCode}),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ee(e=>e===t?e:t)},style:G.codeTrigger,testID:B?`${B}-code`:void 0,children:[Q(Re,ve.text,B?`${B}-flag`:void 0),(0,_jsxRuntime.jsx)(_index6.Text,{variant:"body",style:[G.codeText,{color:ye.color,fontSize:ve.text}],children:`+${ue.callingCode}`}),y?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:O?$.colors["field-icon-disabled"]:$.colors["field-icon"],size:ve.icon,open:xe})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:W,value:qe,maxLength:we,onChangeText:Ke,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;he(t!==i)},onFocus:()=>{be(!0),k?.()},onBlur:()=>{be(!1),Ve&&!Ne.current&&ge(!0),z?.()},editable:!O,placeholder:Pe&&!Oe||Fe?void 0:K,placeholderTextColor:ye.placeholderColor,accessibilityLabel:M??S??K,selectionColor:$.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[G.input,{color:ye.color,fontSize:ve.text,...ye.weightStyle,paddingLeft:Ie?$.space.none:void 0}],testID:B?`${B}-input`:void 0}),Fe?(0,_jsxRuntime.jsx)(_index5.RequiredPlaceholder,{text:K,color:ye.placeholderColor,fontSize:ve.text,weightStyle:ye.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:U,testID:B,children:[S&&"top"===I?(0,_jsxRuntime.jsx)(_index5.FieldLabel,{size:P,required:F,children:S}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrapper,children:[Je,Ae.node]}),(0,_jsxRuntime.jsx)(_index5.FieldMessage,{size:P,error:We,text:We?Ge:E}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:xe,haptic:q,onClose:()=>Ce(!1),title:Y.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,$.text.lg.size),renderOption:f?({option:e,selected:t})=>f(e,{selected:t}):void 0,value:Re?.iso,onChange:(e,t)=>Xe(t),searchable:Z.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:g??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index3.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../text/index.js"),_phoneNumberInputG=require("../../text/phone/phoneNumberInput.g.js"),_index3=require("../../theme/index.js"),_index4=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index5=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index6=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,l=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;l=o.slice(r.length)}const a=t.filter(e=>e.code===r),s=a.find(e=>e.iso===i)?.iso??a.find(e=>e.iso===n?.country)?.iso??n?.country??a[0]?.iso??"";return{callingCode:r,nationalNumber:l,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:l,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:b=ALL_CALLING_CODES,popularCountries:p,hiddenCountries:m,showFlag:_=!0,renderFlag:h,renderCountry:f,showAlphabetIndex:g,defaultCountry:x,validation:C="any",maxLength:N,formatAsYouType:v=!0,countryLocked:y=!1,label:S,labelMode:I="top",labelStyle:L,placeholder:j,helperText:E,error:T,invalidMessage:V,required:F,disabled:A=!1,size:O="md",variant:P,radius:R,labels:D,haptic:q,accessibilityLabel:M,countryAccessibilityLabel:w,onFocus:k,onBlur:z,style:U,testID:B}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const $=(0,_index3.useTheme)(),G=(0,_react.useMemo)(()=>buildStyles($),[$]),W=(0,_react.useRef)(null),H=(0,_index2.useMobileUiText)("phoneNumberInput",_phoneNumberInputG.PHONE_NUMBER_INPUT_TEXT),Y=(0,_react.useMemo)(()=>({...H,...D}),[H,D]),K=j??Y.placeholder,X=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),Z=(0,_react.useMemo)(()=>m?.length?b.filter(e=>!m.includes(e.iso)):b,[b,m]),J=(0,_react.useMemo)(()=>{if(!p?.length)return;const e=p.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:Z}]:void 0},[p,Y.popular,Y.allCountries,Z]),Q=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(h)return h(e);if(!_)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index6.Text,{variant:"body",style:[G.flag,{fontSize:t}],testID:i,children:o}):null},[h,_,G.flag]),ee=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(i,N):i},[N,C]),te=(0,_react.useCallback)((e,t)=>e.slice(0,ee(t)),[ee]),ie=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=b.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:te(o.nationalNumber,n),iso:r?.iso??n}},[b,te]);(0,_react.useState)(()=>assertDefaultCountryVisible(x,Z));const oe=(0,_react.useMemo)(()=>{const e=Z.find(e=>e.iso===(x??X))??Z[0]??b[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?ie(o,t.iso)??t:o??t},[b,Z,x,X,o,ie]),ne=(0,_react.useCallback)(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[re,le]=(0,_react.useState)(oe.iso),ae=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,b,re):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=b.find(e=>e.iso===re);return{callingCode:t?.code??oe.callingCode,nationalNumber:"",iso:re}},[r,b,re,oe.callingCode,te]),se=(0,_react.useCallback)(e=>{le(e.iso),n?.(e),l?.(e.nationalNumber?formatE164(e):"",{country:b.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ne(e)})},[n,l,b,ne]),[ue,de]=(0,_index.useControllableState)({value:i??ae,defaultValue:oe,onChange:se}),[ce,be]=(0,_react.useState)(!1),pe=(0,_react.useCallback)(()=>{A||W.current?.focus()},[A]),[me,he]=(0,_react.useState)(!1),[fe,ge]=(0,_react.useState)(!1),[xe,Ce]=(0,_react.useState)(!1),Ne=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{xe||(Ne.current=!1)},[xe]);const ve=(0,_index3.resolveFieldSize)($,O),ye=(0,_index5.resolveFieldTextStyle)($,{disabled:A}),Se=P??$.settings.components.field?.defaultVariant??"outline",Ie="underline"===Se,Le=$.space.md,[je,Ee]=(0,_react.useState)(0),Te=je+Le+1+Le,Ve=ue.nationalNumber.length>0,Fe=F&&!S&&!Ve&&K.length>0,Ae=ce||Ve,Oe=Boolean(S)&&"float"===I&&je>0,Pe=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Oe,floated:Ae,required:F,variant:Se,sizeTokens:ve,leadingOffset:Te,paddingLeft:Ie?$.space.none:ve["padding-x"],color:$.colors["field-label"],style:L}),Re=(0,_react.useMemo)(()=>b.find(e=>e.iso===ue.iso),[b,ue.iso]),De=planOf(ue.iso),qe=v&&De?(0,_mobileCore.formatPhoneAsTyped)(ue.nationalNumber,De):ue.nationalNumber,Me=ee(ue.iso),we=0===ue.nationalNumber.length||me||!Number.isFinite(Me)?void 0:qe.length+Math.max(0,Me-ue.nationalNumber.length),ke=ne(ue);(0,_react.useEffect)(()=>{Ve||ge(!1)},[Ve]);const ze=De?(0,_mobileCore.maxNationalNumberLength)(De,!1===C?"any":C):Number.POSITIVE_INFINITY,Ue=ue.nationalNumber.length>=ze,Be=!1!==C&&!1!==V&&Ve&&!ke&&(fe||Ue),$e="mobile"===C?Y.invalidMobile:Y.invalid,Ge=(0,_index5.hasFieldText)(T)?T:Be?V||$e:void 0,We=!0===T||(0,_index5.hasFieldText)(Ge),He=(0,_react.useRef)(ke),Ye=(0,_react.useRef)(ue);Ye.current=ue,(0,_react.useEffect)(()=>{He.current!==ke&&(He.current=ke,c?.(ke),ke&&d?.(formatE164(Ye.current)))},[ke,d,c]);const Ke=(0,_react.useCallback)(e=>{if((0,_mobileCore.reportIdleActivity)(),e.includes("+")){const t=ie(e,ue.iso);if(t&&!y&&Z.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[Z,y,ue,ie,te,de]),Xe=(0,_react.useCallback)(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),Ce(!1);const t=(0,_index4.resolveHaptic)(q,"selection");t&&(0,_index4.triggerHaptic)(t)},[ue,q,te,de]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>W.current?.focus(),blur:()=>W.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>W.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>ne(Ye.current),getCountry:()=>b.find(e=>e.iso===Ye.current.iso)}),[b,ne,de]);const Ze=A||y,Je=(0,_jsxRuntime.jsx)(_index5.FieldBase,{testID:B?`${B}-field`:void 0,size:O,variant:Se,radius:R,topNotch:Pe.topNotch,focused:ce,disabled:A,error:We,filled:Ve,onPress:pe,pressFeedback:!1,leadingDivider:!0,paddingLeft:Ie?$.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Ze||(Ne.current=!0,Ce(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:w??(0,_index2.fillText)(Y.countryButton,{callingCode:ue.callingCode}),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ee(e=>e===t?e:t)},style:G.codeTrigger,testID:B?`${B}-code`:void 0,children:[Q(Re,ve.text,B?`${B}-flag`:void 0),(0,_jsxRuntime.jsx)(_index6.Text,{variant:"body",style:[G.codeText,{color:ye.color,fontSize:ve.text}],children:`+${ue.callingCode}`}),y?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:A?$.colors["field-icon-disabled"]:$.colors["field-icon"],size:ve.icon,open:xe})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:W,value:qe,maxLength:we,onChangeText:Ke,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;he(t!==i)},onFocus:()=>{be(!0),k?.()},onBlur:()=>{be(!1),Ve&&!Ne.current&&ge(!0),z?.()},editable:!A,placeholder:Oe&&!Ae||Fe?void 0:K,placeholderTextColor:ye.placeholderColor,accessibilityLabel:M??S??K,selectionColor:$.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[G.input,{color:ye.color,fontSize:ve.text,...ye.weightStyle,paddingLeft:Ie?$.space.none:void 0}],testID:B?`${B}-input`:void 0}),Fe?(0,_jsxRuntime.jsx)(_index5.RequiredPlaceholder,{text:K,color:ye.placeholderColor,fontSize:ve.text,weightStyle:ye.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:U,testID:B,children:[S&&"top"===I?(0,_jsxRuntime.jsx)(_index5.FieldLabel,{size:O,required:F,children:S}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrapper,children:[Je,Pe.node]}),(0,_jsxRuntime.jsx)(_index5.FieldMessage,{size:O,error:We,text:We?Ge:E}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:xe,haptic:q,onClose:()=>Ce(!1),title:Y.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,$.text.lg.size),renderOption:f?({option:e,selected:t})=>f(e,{selected:t}):void 0,value:Re?.iso,onChange:(e,t)=>Xe(t),searchable:Z.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:g??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index3.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
|