react-native-paper-dates 0.11.9 → 0.11.10
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/lib/commonjs/Date/DatePickerInput.js +12 -3
- package/lib/commonjs/Date/DatePickerInput.js.map +1 -1
- package/lib/commonjs/Date/DatePickerInput.shared.js.map +1 -1
- package/lib/commonjs/Date/DatePickerInputWithoutModal.js +21 -11
- package/lib/commonjs/Date/DatePickerInputWithoutModal.js.map +1 -1
- package/lib/commonjs/Date/inputUtils.js +12 -4
- package/lib/commonjs/Date/inputUtils.js.map +1 -1
- package/lib/commonjs/TextInputMask.js +4 -0
- package/lib/commonjs/TextInputMask.js.map +1 -1
- package/lib/module/Date/DatePickerInput.js +12 -3
- package/lib/module/Date/DatePickerInput.js.map +1 -1
- package/lib/module/Date/DatePickerInput.shared.js.map +1 -1
- package/lib/module/Date/DatePickerInputWithoutModal.js +21 -11
- package/lib/module/Date/DatePickerInputWithoutModal.js.map +1 -1
- package/lib/module/Date/inputUtils.js +12 -4
- package/lib/module/Date/inputUtils.js.map +1 -1
- package/lib/module/TextInputMask.js +4 -0
- package/lib/module/TextInputMask.js.map +1 -1
- package/lib/typescript/Date/DatePickerInput.d.ts +1 -1
- package/lib/typescript/Date/DatePickerInput.shared.d.ts +8 -0
- package/lib/typescript/Date/DatePickerInputWithoutModal.d.ts +13 -1
- package/lib/typescript/Date/inputUtils.d.ts +2 -1
- package/package.json +1 -1
- package/src/Date/DatePickerInput.shared.tsx +8 -0
- package/src/Date/DatePickerInput.tsx +16 -1
- package/src/Date/DatePickerInputWithoutModal.tsx +36 -11
- package/src/Date/inputUtils.ts +16 -9
- package/src/TextInputMask.tsx +4 -0
|
@@ -51,14 +51,19 @@ function DatePickerInput(_ref, ref) {
|
|
|
51
51
|
style: styles.calendarButton,
|
|
52
52
|
icon: calendarIcon,
|
|
53
53
|
onPress: () => setVisible(true)
|
|
54
|
-
}) : null
|
|
54
|
+
}) : null // eslint-disable-next-line react/no-unstable-nested-components
|
|
55
|
+
,
|
|
55
56
|
modal: _ref3 => {
|
|
56
57
|
let {
|
|
57
58
|
value,
|
|
58
59
|
locale,
|
|
59
60
|
inputMode,
|
|
60
61
|
validRange,
|
|
61
|
-
saveLabel
|
|
62
|
+
saveLabel,
|
|
63
|
+
saveLabelDisabled,
|
|
64
|
+
uppercase,
|
|
65
|
+
startYear,
|
|
66
|
+
endYear
|
|
62
67
|
} = _ref3;
|
|
63
68
|
return withModal ? /*#__PURE__*/React.createElement(_DatePickerModal.default, {
|
|
64
69
|
date: value,
|
|
@@ -69,7 +74,11 @@ function DatePickerInput(_ref, ref) {
|
|
|
69
74
|
locale: locale,
|
|
70
75
|
dateMode: inputMode,
|
|
71
76
|
validRange: validRange,
|
|
72
|
-
saveLabel: saveLabel
|
|
77
|
+
saveLabel: saveLabel,
|
|
78
|
+
saveLabelDisabled: saveLabelDisabled ?? false,
|
|
79
|
+
uppercase: uppercase ?? true,
|
|
80
|
+
startYear: startYear ?? 1800,
|
|
81
|
+
endYear: endYear ?? 2200
|
|
73
82
|
}) : null;
|
|
74
83
|
}
|
|
75
84
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DatePickerInput","ref","withModal","calendarIcon","rest","visible","setVisible","React","useState","onDismiss","useCallback","onChangeRef","useLatest","onChange","onInnerConfirm","date","current","styles","calendarButton","value","locale","inputMode","validRange","saveLabel","StyleSheet","create","position","right","zIndex","forwardRef"],"sources":["DatePickerInput.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { IconButton } from 'react-native-paper'\nimport { StyleSheet } from 'react-native'\nimport DatePickerModal from './DatePickerModal'\nimport { useLatest } from '../utils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\nimport DatePickerInputWithoutModal from './DatePickerInputWithoutModal'\n\nfunction DatePickerInput(\n {\n withModal = true,\n calendarIcon = 'calendar',\n ...rest\n }: DatePickerInputProps,\n ref: any\n) {\n const [visible, setVisible] = React.useState<boolean>(false)\n const onDismiss = React.useCallback(() => {\n setVisible(false)\n }, [setVisible])\n const onChangeRef = useLatest(rest.onChange)\n const onInnerConfirm = React.useCallback(\n ({ date }: any) => {\n setVisible(false)\n onChangeRef.current(date)\n },\n [setVisible, onChangeRef]\n )\n\n return (\n <DatePickerInputWithoutModal\n ref={ref}\n {...rest}\n inputButtons={\n withModal ? (\n <IconButton\n size={24}\n style={styles.calendarButton}\n icon={calendarIcon}\n onPress={() => setVisible(true)}\n />\n ) : null\n }\n modal={({
|
|
1
|
+
{"version":3,"names":["DatePickerInput","ref","withModal","calendarIcon","rest","visible","setVisible","React","useState","onDismiss","useCallback","onChangeRef","useLatest","onChange","onInnerConfirm","date","current","styles","calendarButton","value","locale","inputMode","validRange","saveLabel","saveLabelDisabled","uppercase","startYear","endYear","StyleSheet","create","position","right","zIndex","forwardRef"],"sources":["DatePickerInput.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { IconButton } from 'react-native-paper'\nimport { StyleSheet } from 'react-native'\nimport DatePickerModal from './DatePickerModal'\nimport { useLatest } from '../utils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\nimport DatePickerInputWithoutModal from './DatePickerInputWithoutModal'\n\nfunction DatePickerInput(\n {\n withModal = true,\n calendarIcon = 'calendar',\n ...rest\n }: DatePickerInputProps,\n ref: any\n) {\n const [visible, setVisible] = React.useState<boolean>(false)\n const onDismiss = React.useCallback(() => {\n setVisible(false)\n }, [setVisible])\n const onChangeRef = useLatest(rest.onChange)\n const onInnerConfirm = React.useCallback(\n ({ date }: any) => {\n setVisible(false)\n onChangeRef.current(date)\n },\n [setVisible, onChangeRef]\n )\n\n return (\n <DatePickerInputWithoutModal\n ref={ref}\n {...rest}\n inputButtons={\n withModal ? (\n <IconButton\n size={24}\n style={styles.calendarButton}\n icon={calendarIcon}\n onPress={() => setVisible(true)}\n />\n ) : null\n }\n // eslint-disable-next-line react/no-unstable-nested-components\n modal={({\n value,\n locale,\n inputMode,\n validRange,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n }) =>\n withModal ? (\n <DatePickerModal\n date={value}\n mode=\"single\"\n visible={visible}\n onDismiss={onDismiss}\n onConfirm={onInnerConfirm}\n locale={locale}\n dateMode={inputMode}\n validRange={validRange}\n saveLabel={saveLabel}\n saveLabelDisabled={saveLabelDisabled ?? false}\n uppercase={uppercase ?? true}\n startYear={startYear ?? 1800}\n endYear={endYear ?? 2200}\n />\n ) : null\n }\n />\n )\n}\n\nconst styles = StyleSheet.create({\n calendarButton: { position: 'absolute', right: 0, zIndex: 10 },\n})\n\nexport default React.forwardRef(DatePickerInput)\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;AAEA,SAASA,eAAT,OAMEC,GANF,EAOE;EAAA,IANA;IACEC,SAAS,GAAG,IADd;IAEEC,YAAY,GAAG,UAFjB;IAGE,GAAGC;EAHL,CAMA;EACA,MAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBC,KAAK,CAACC,QAAN,CAAwB,KAAxB,CAA9B;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,WAAN,CAAkB,MAAM;IACxCJ,UAAU,CAAC,KAAD,CAAV;EACD,CAFiB,EAEf,CAACA,UAAD,CAFe,CAAlB;EAGA,MAAMK,WAAW,GAAG,IAAAC,gBAAA,EAAUR,IAAI,CAACS,QAAf,CAApB;EACA,MAAMC,cAAc,GAAGP,KAAK,CAACG,WAAN,CACrB,SAAmB;IAAA,IAAlB;MAAEK;IAAF,CAAkB;IACjBT,UAAU,CAAC,KAAD,CAAV;IACAK,WAAW,CAACK,OAAZ,CAAoBD,IAApB;EACD,CAJoB,EAKrB,CAACT,UAAD,EAAaK,WAAb,CALqB,CAAvB;EAQA,oBACE,oBAAC,oCAAD;IACE,GAAG,EAAEV;EADP,GAEMG,IAFN;IAGE,YAAY,EACVF,SAAS,gBACP,oBAAC,4BAAD;MACE,IAAI,EAAE,EADR;MAEE,KAAK,EAAEe,MAAM,CAACC,cAFhB;MAGE,IAAI,EAAEf,YAHR;MAIE,OAAO,EAAE,MAAMG,UAAU,CAAC,IAAD;IAJ3B,EADO,GAOL,IAXR,CAaE;IAbF;IAcE,KAAK,EAAE;MAAA,IAAC;QACNa,KADM;QAENC,MAFM;QAGNC,SAHM;QAINC,UAJM;QAKNC,SALM;QAMNC,iBANM;QAONC,SAPM;QAQNC,SARM;QASNC;MATM,CAAD;MAAA,OAWLzB,SAAS,gBACP,oBAAC,wBAAD;QACE,IAAI,EAAEiB,KADR;QAEE,IAAI,EAAC,QAFP;QAGE,OAAO,EAAEd,OAHX;QAIE,SAAS,EAAEI,SAJb;QAKE,SAAS,EAAEK,cALb;QAME,MAAM,EAAEM,MANV;QAOE,QAAQ,EAAEC,SAPZ;QAQE,UAAU,EAAEC,UARd;QASE,SAAS,EAAEC,SATb;QAUE,iBAAiB,EAAEC,iBAAiB,IAAI,KAV1C;QAWE,SAAS,EAAEC,SAAS,IAAI,IAX1B;QAYE,SAAS,EAAEC,SAAS,IAAI,IAZ1B;QAaE,OAAO,EAAEC,OAAO,IAAI;MAbtB,EADO,GAgBL,IA3BC;IAAA;EAdT,GADF;AA8CD;;AAED,MAAMV,MAAM,GAAGW,uBAAA,CAAWC,MAAX,CAAkB;EAC/BX,cAAc,EAAE;IAAEY,QAAQ,EAAE,UAAZ;IAAwBC,KAAK,EAAE,CAA/B;IAAkCC,MAAM,EAAE;EAA1C;AADe,CAAlB,CAAf;;4BAIezB,KAAK,CAAC0B,UAAN,CAAiBjC,eAAjB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DatePickerInput.shared.tsx"],"sourcesContent":["import type { ValidRangeType } from './Calendar'\nimport type * as React from 'react'\nimport type { TextInput } from 'react-native-paper'\n\nexport type DatePickerInputProps = {\n inputMode: 'start' | 'end'\n locale: string\n onChange: (date: Date | undefined) => void\n value: Date | undefined\n validRange?: ValidRangeType | undefined\n withModal?: boolean\n withDateFormatInLabel?: boolean\n calendarIcon?: string\n saveLabel?: string\n} & Omit<\n React.ComponentProps<typeof TextInput>,\n 'value' | 'onChange' | 'onChangeText'\n>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["DatePickerInput.shared.tsx"],"sourcesContent":["import type { ValidRangeType } from './Calendar'\nimport type * as React from 'react'\nimport type { TextInput } from 'react-native-paper'\n\nexport type DatePickerInputProps = {\n inputMode: 'start' | 'end'\n locale: string\n onChange: (date: Date | undefined) => void\n value: Date | undefined\n validRange?: ValidRangeType | undefined\n withModal?: boolean\n withDateFormatInLabel?: boolean\n hideValidationErrors?: boolean\n hasError?: boolean\n onValidationError?: ((error: string | null) => void) | undefined\n calendarIcon?: string\n saveLabel?: string\n saveLabelDisabled?: boolean\n uppercase?: boolean\n startYear?: number\n endYear?: number\n onChangeText?: (text: string | undefined) => void\n} & Omit<\n React.ComponentProps<typeof TextInput>,\n 'value' | 'onChange' | 'onChangeText'\n>\n"],"mappings":""}
|
|
@@ -33,23 +33,32 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
33
33
|
validRange,
|
|
34
34
|
inputMode,
|
|
35
35
|
withDateFormatInLabel = true,
|
|
36
|
+
hasError,
|
|
37
|
+
hideValidationErrors,
|
|
38
|
+
onValidationError,
|
|
36
39
|
modal,
|
|
37
40
|
inputButtons,
|
|
38
41
|
saveLabel,
|
|
42
|
+
saveLabelDisabled,
|
|
43
|
+
uppercase,
|
|
44
|
+
startYear,
|
|
45
|
+
endYear,
|
|
46
|
+
onChangeText,
|
|
39
47
|
...rest
|
|
40
48
|
} = _ref;
|
|
41
49
|
const theme = (0, _reactNativePaper.useTheme)();
|
|
42
50
|
const {
|
|
43
51
|
formattedValue,
|
|
44
52
|
inputFormat,
|
|
45
|
-
onChangeText,
|
|
53
|
+
onChangeText: onDateInputChangeText,
|
|
46
54
|
error
|
|
47
55
|
} = (0, _inputUtils.default)({
|
|
48
56
|
locale,
|
|
49
57
|
value,
|
|
50
58
|
validRange,
|
|
51
59
|
inputMode,
|
|
52
|
-
onChange
|
|
60
|
+
onChange,
|
|
61
|
+
onValidationError
|
|
53
62
|
});
|
|
54
63
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
55
64
|
style: styles.root
|
|
@@ -64,15 +73,14 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
64
73
|
withDateFormatInLabel
|
|
65
74
|
}),
|
|
66
75
|
value: formattedValue,
|
|
67
|
-
keyboardType: 'number-pad',
|
|
68
|
-
placeholder: inputFormat,
|
|
76
|
+
keyboardType: rest.keyboardType ?? 'number-pad',
|
|
69
77
|
mask: inputFormat,
|
|
70
|
-
onChangeText:
|
|
78
|
+
onChangeText: onDateInputChangeText,
|
|
79
|
+
onChange: e => onChangeText && onChangeText(e.nativeEvent.text),
|
|
71
80
|
keyboardAppearance: theme.dark ? 'dark' : 'default',
|
|
72
|
-
error: !!error,
|
|
81
|
+
error: !!error && !hideValidationErrors || !!hasError,
|
|
73
82
|
style: [styles.input, style]
|
|
74
|
-
})), inputButtons), error ? /*#__PURE__*/React.createElement(_reactNativePaper.HelperText, {
|
|
75
|
-
style: styles.helperText,
|
|
83
|
+
})), inputButtons), error && !hideValidationErrors ? /*#__PURE__*/React.createElement(_reactNativePaper.HelperText, {
|
|
76
84
|
type: "error",
|
|
77
85
|
visible: !!error
|
|
78
86
|
}, error) : null), modal === null || modal === void 0 ? void 0 : modal({
|
|
@@ -80,7 +88,11 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
80
88
|
locale,
|
|
81
89
|
inputMode,
|
|
82
90
|
validRange,
|
|
83
|
-
saveLabel
|
|
91
|
+
saveLabel,
|
|
92
|
+
saveLabelDisabled,
|
|
93
|
+
uppercase,
|
|
94
|
+
startYear,
|
|
95
|
+
endYear
|
|
84
96
|
}));
|
|
85
97
|
}
|
|
86
98
|
|
|
@@ -110,8 +122,6 @@ const styles = _reactNative.StyleSheet.create({
|
|
|
110
122
|
},
|
|
111
123
|
input: {
|
|
112
124
|
flexGrow: 1
|
|
113
|
-
},
|
|
114
|
-
helperText: {// flex: 1,
|
|
115
125
|
}
|
|
116
126
|
});
|
|
117
127
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DatePickerInputWithoutModal","ref","label","value","onChange","style","locale","validRange","inputMode","withDateFormatInLabel","modal","inputButtons","saveLabel","rest","theme","useTheme","formattedValue","inputFormat","
|
|
1
|
+
{"version":3,"names":["DatePickerInputWithoutModal","ref","label","value","onChange","style","locale","validRange","inputMode","withDateFormatInLabel","hasError","hideValidationErrors","onValidationError","modal","inputButtons","saveLabel","saveLabelDisabled","uppercase","startYear","endYear","onChangeText","rest","theme","useTheme","formattedValue","inputFormat","onDateInputChangeText","error","useDateInput","styles","root","inputContainer","getLabel","keyboardType","e","nativeEvent","text","dark","input","StyleSheet","create","flexGrow","flexDirection","alignItems","justifyContent","React","forwardRef"],"sources":["DatePickerInputWithoutModal.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport TextInputWithMask from '../TextInputMask'\nimport { HelperText, useTheme } from 'react-native-paper'\nimport { View, StyleSheet } from 'react-native'\nimport useDateInput from './inputUtils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\n\nfunction DatePickerInputWithoutModal(\n {\n label,\n value,\n onChange,\n style,\n locale,\n validRange,\n inputMode,\n withDateFormatInLabel = true,\n hasError,\n hideValidationErrors,\n onValidationError,\n modal,\n inputButtons,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n onChangeText,\n ...rest\n }: DatePickerInputProps & {\n modal?: (params: {\n value: DatePickerInputProps['value']\n locale: DatePickerInputProps['locale']\n inputMode: DatePickerInputProps['inputMode']\n validRange: DatePickerInputProps['validRange']\n saveLabel: DatePickerInputProps['saveLabel']\n saveLabelDisabled: DatePickerInputProps['saveLabelDisabled']\n uppercase: DatePickerInputProps['uppercase']\n startYear: DatePickerInputProps['startYear']\n endYear: DatePickerInputProps['endYear']\n }) => any\n inputButtons?: any\n },\n ref: any\n) {\n const theme = useTheme()\n const {\n formattedValue,\n inputFormat,\n onChangeText: onDateInputChangeText,\n error,\n } = useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n onValidationError,\n })\n\n return (\n <>\n <View style={styles.root}>\n <View style={styles.inputContainer}>\n <TextInputWithMask\n {...rest}\n ref={ref}\n label={getLabel({\n // TODO: support label components?\n label: label as any,\n inputFormat,\n withDateFormatInLabel,\n })}\n value={formattedValue}\n keyboardType={rest.keyboardType ?? 'number-pad'}\n mask={inputFormat}\n onChangeText={onDateInputChangeText}\n onChange={(e) => onChangeText && onChangeText(e.nativeEvent.text)}\n keyboardAppearance={theme.dark ? 'dark' : 'default'}\n error={(!!error && !hideValidationErrors) || !!hasError}\n style={[styles.input, style]}\n />\n {inputButtons}\n </View>\n {error && !hideValidationErrors ? (\n <HelperText type=\"error\" visible={!!error}>\n {error}\n </HelperText>\n ) : null}\n </View>\n {modal?.({\n value,\n locale,\n inputMode,\n validRange,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n })}\n </>\n )\n}\n\nfunction getLabel({\n withDateFormatInLabel,\n inputFormat,\n label,\n}: {\n withDateFormatInLabel: boolean\n inputFormat: string\n label: string | undefined\n}) {\n if (withDateFormatInLabel) {\n return label ? `${label} (${inputFormat})` : inputFormat\n }\n return label || ''\n}\n\nconst styles = StyleSheet.create({\n root: {\n flexGrow: 1,\n },\n inputContainer: {\n flexGrow: 1,\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'flex-start',\n },\n input: {\n flexGrow: 1,\n },\n})\nexport default React.forwardRef(DatePickerInputWithoutModal)\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;;;AAGA,SAASA,2BAAT,OAoCEC,GApCF,EAqCE;EAAA,IApCA;IACEC,KADF;IAEEC,KAFF;IAGEC,QAHF;IAIEC,KAJF;IAK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,CADF,EAsBGa,KAAK,IAAI,CAAChB,oBAAV,gBACC,oBAAC,4BAAD;IAAY,IAAI,EAAC,OAAjB;IAAyB,OAAO,EAAE,CAAC,CAACgB;EAApC,GACGA,KADH,CADD,GAIG,IA1BN,CADF,EA6BGd,KA7BH,aA6BGA,KA7BH,uBA6BGA,KAAK,CAAG;IACPV,KADO;IAEPG,MAFO;IAGPE,SAHO;IAIPD,UAJO;IAKPQ,SALO;IAMPC,iBANO;IAOPC,SAPO;IAQPC,SARO;IASPC;EATO,CAAH,CA7BR,CADF;AA2CD;;AAED,SAASa,QAAT,QAQG;EAAA,IARe;IAChBvB,qBADgB;IAEhBgB,WAFgB;IAGhBvB;EAHgB,CAQf;;EACD,IAAIO,qBAAJ,EAA2B;IACzB,OAAOP,KAAK,GAAI,GAAEA,KAAM,KAAIuB,WAAY,GAA5B,GAAiCA,WAA7C;EACD;;EACD,OAAOvB,KAAK,IAAI,EAAhB;AACD;;AAED,MAAM2B,MAAM,GAAGU,uBAAA,CAAWC,MAAX,CAAkB;EAC/BV,IAAI,EAAE;IACJW,QAAQ,EAAE;EADN,CADyB;EAI/BV,cAAc,EAAE;IACdU,QAAQ,EAAE,CADI;IAEdC,aAAa,EAAE,KAFD;IAGdC,UAAU,EAAE,QAHE;IAIdC,cAAc,EAAE;EAJF,CAJe;EAU/BN,KAAK,EAAE;IACLG,QAAQ,EAAE;EADL;AAVwB,CAAlB,CAAf;;4BAceI,KAAK,CAACC,UAAN,CAAiB9C,2BAAjB,C"}
|
|
@@ -21,7 +21,8 @@ function useDateInput(_ref) {
|
|
|
21
21
|
value,
|
|
22
22
|
validRange,
|
|
23
23
|
inputMode,
|
|
24
|
-
onChange
|
|
24
|
+
onChange,
|
|
25
|
+
onValidationError
|
|
25
26
|
} = _ref;
|
|
26
27
|
const {
|
|
27
28
|
isDisabled,
|
|
@@ -37,7 +38,7 @@ function useDateInput(_ref) {
|
|
|
37
38
|
formatter,
|
|
38
39
|
locale
|
|
39
40
|
});
|
|
40
|
-
const formattedValue = value
|
|
41
|
+
const formattedValue = value ? formatter.format(value) : '';
|
|
41
42
|
|
|
42
43
|
const onChangeText = date => {
|
|
43
44
|
const dayIndex = inputFormat.indexOf('DD');
|
|
@@ -48,24 +49,31 @@ function useDateInput(_ref) {
|
|
|
48
49
|
const month = Number(date.slice(monthIndex, monthIndex + 2));
|
|
49
50
|
|
|
50
51
|
if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {
|
|
51
|
-
|
|
52
|
+
const inputError = (0, _utils.getTranslation)(locale, 'notAccordingToDateFormat', () => 'notAccordingToDateFormat')(inputFormat);
|
|
53
|
+
setError(inputError);
|
|
54
|
+
onValidationError && onValidationError(inputError);
|
|
52
55
|
return;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
const finalDate = inputMode === 'end' ? new Date(year, month - 1, day, 23, 59, 59) : new Date(year, month - 1, day);
|
|
56
59
|
|
|
57
60
|
if (isDisabled(finalDate)) {
|
|
58
|
-
|
|
61
|
+
const inputError = (0, _utils.getTranslation)(locale, 'dateIsDisabled');
|
|
62
|
+
setError(inputError);
|
|
63
|
+
onValidationError && onValidationError(inputError);
|
|
59
64
|
return;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
if (!isWithinValidRange(finalDate)) {
|
|
63
68
|
let errors = validStart && validEnd ? [`${(0, _utils.getTranslation)(locale, 'mustBeBetween', () => 'mustBeBetween')(formatter.format(validStart), formatter.format(validEnd))}`] : [validStart ? (0, _utils.getTranslation)(locale, 'mustBeHigherThan', () => 'mustBeHigherThan')(formatter.format(validStart)) : '', validEnd ? (0, _utils.getTranslation)(locale, 'mustBeLowerThan', () => 'mustBeLowerThan')(formatter.format(validEnd)) : ''];
|
|
69
|
+
const inputError = errors.filter(n => n).join(' ');
|
|
64
70
|
setError(errors.filter(n => n).join(' '));
|
|
71
|
+
onValidationError && onValidationError(inputError);
|
|
65
72
|
return;
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
setError(null);
|
|
76
|
+
onValidationError && onValidationError(null);
|
|
69
77
|
|
|
70
78
|
if (inputMode === 'end') {
|
|
71
79
|
onChange(finalDate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","useRangeChecker","error","setError","React","useState","formatter","useInputFormatter","inputFormat","useInputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","getTranslation","finalDate","Date","errors","filter","n","join"],"sources":["inputUtils.ts"],"sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from '../translations/utils'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = value
|
|
1
|
+
{"version":3,"names":["useDateInput","locale","value","validRange","inputMode","onChange","onValidationError","isDisabled","isWithinValidRange","validStart","validEnd","useRangeChecker","error","setError","React","useState","formatter","useInputFormatter","inputFormat","useInputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","inputError","getTranslation","finalDate","Date","errors","filter","n","join"],"sources":["inputUtils.ts"],"sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from '../translations/utils'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n onValidationError,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n onValidationError?: ((error: string | null) => void) | undefined\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = value ? formatter.format(value) : ''\n const onChangeText = (date: string) => {\n const dayIndex = inputFormat.indexOf('DD')\n const monthIndex = inputFormat.indexOf('MM')\n const yearIndex =\n locale === 'pt'\n ? inputFormat.indexOf('AAAA')\n : inputFormat.indexOf('YYYY')\n\n const day = Number(date.slice(dayIndex, dayIndex + 2))\n const year = Number(date.slice(yearIndex, yearIndex + 4))\n const month = Number(date.slice(monthIndex, monthIndex + 2))\n\n if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {\n const inputError = getTranslation(\n locale,\n 'notAccordingToDateFormat',\n () => 'notAccordingToDateFormat'\n )(inputFormat)\n setError(inputError)\n onValidationError && onValidationError(inputError)\n return\n }\n\n const finalDate =\n inputMode === 'end'\n ? new Date(year, month - 1, day, 23, 59, 59)\n : new Date(year, month - 1, day)\n\n if (isDisabled(finalDate)) {\n const inputError = getTranslation(locale, 'dateIsDisabled')\n setError(inputError)\n onValidationError && onValidationError(inputError)\n return\n }\n if (!isWithinValidRange(finalDate)) {\n let errors =\n validStart && validEnd\n ? [\n `${getTranslation(\n locale,\n 'mustBeBetween',\n () => 'mustBeBetween'\n )(formatter.format(validStart), formatter.format(validEnd))}`,\n ]\n : [\n validStart\n ? getTranslation(\n locale,\n 'mustBeHigherThan',\n () => 'mustBeHigherThan'\n )(formatter.format(validStart))\n : '',\n validEnd\n ? getTranslation(\n locale,\n 'mustBeLowerThan',\n () => 'mustBeLowerThan'\n )(formatter.format(validEnd))\n : '',\n ]\n const inputError = errors.filter((n) => n).join(' ')\n setError(errors.filter((n) => n).join(' '))\n onValidationError && onValidationError(inputError)\n return\n }\n\n setError(null)\n onValidationError && onValidationError(null)\n if (inputMode === 'end') {\n onChange(finalDate)\n } else {\n onChange(finalDate)\n }\n }\n return {\n onChange,\n error,\n formattedValue,\n onChangeText,\n inputFormat,\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;;;AAEe,SAASA,YAAT,OAcZ;EAAA,IAdkC;IACnCC,MADmC;IAEnCC,KAFmC;IAGnCC,UAHmC;IAInCC,SAJmC;IAKnCC,QALmC;IAMnCC;EANmC,CAclC;EACD,MAAM;IAAEC,UAAF;IAAcC,kBAAd;IAAkCC,UAAlC;IAA8CC;EAA9C,IACJ,IAAAC,0BAAA,EAAgBR,UAAhB,CADF;EAEA,MAAM,CAACS,KAAD,EAAQC,QAAR,IAAoBC,KAAK,CAACC,QAAN,CAA8B,IAA9B,CAA1B;EACA,MAAMC,SAAS,GAAG,IAAAC,4BAAA,EAAkB;IAAEhB;EAAF,CAAlB,CAAlB;EACA,MAAMiB,WAAW,GAAG,IAAAC,yBAAA,EAAe;IAAEH,SAAF;IAAaf;EAAb,CAAf,CAApB;EACA,MAAMmB,cAAc,GAAGlB,KAAK,GAAGc,SAAS,CAACK,MAAV,CAAiBnB,KAAjB,CAAH,GAA6B,EAAzD;;EACA,MAAMoB,YAAY,GAAIC,IAAD,IAAkB;IACrC,MAAMC,QAAQ,GAAGN,WAAW,CAACO,OAAZ,CAAoB,IAApB,CAAjB;IACA,MAAMC,UAAU,GAAGR,WAAW,CAACO,OAAZ,CAAoB,IAApB,CAAnB;IACA,MAAME,SAAS,GACb1B,MAAM,KAAK,IAAX,GACIiB,WAAW,CAACO,OAAZ,CAAoB,MAApB,CADJ,GAEIP,WAAW,CAACO,OAAZ,CAAoB,MAApB,CAHN;IAKA,MAAMG,GAAG,GAAGC,MAAM,CAACN,IAAI,CAACO,KAAL,CAAWN,QAAX,EAAqBA,QAAQ,GAAG,CAAhC,CAAD,CAAlB;IACA,MAAMO,IAAI,GAAGF,MAAM,CAACN,IAAI,CAAC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S,CAACK,MAAV,CAAiBX,QAAjB,CAJ7B,CAIyD,EAL9D,CADJ,GAQI,CACED,UAAU,GACN,IAAA0B,qBAAA,EACElC,MADF,EAEE,kBAFF,EAGE,MAAM,kBAHR,EAIEe,SAAS,CAACK,MAAV,CAAiBZ,UAAjB,CAJF,CADM,GAMN,EAPN,EAQEC,QAAQ,GACJ,IAAAyB,qBAAA,EACElC,MADF,EAEE,iBAFF,EAGE,MAAM,iBAHR,EAIEe,SAAS,CAACK,MAAV,CAAiBX,QAAjB,CAJF,CADI,GAMJ,EAdN,CATN;MAyBA,MAAMwB,UAAU,GAAGI,MAAM,CAACC,MAAP,CAAeC,CAAD,IAAOA,CAArB,EAAwBC,IAAxB,CAA6B,GAA7B,CAAnB;MACA5B,QAAQ,CAACyB,MAAM,CAACC,MAAP,CAAeC,CAAD,IAAOA,CAArB,EAAwBC,IAAxB,CAA6B,GAA7B,CAAD,CAAR;MACAnC,iBAAiB,IAAIA,iBAAiB,CAAC4B,UAAD,CAAtC;MACA;IACD;;IAEDrB,QAAQ,CAAC,IAAD,CAAR;IACAP,iBAAiB,IAAIA,iBAAiB,CAAC,IAAD,CAAtC;;IACA,IAAIF,SAAS,KAAK,KAAlB,EAAyB;MACvBC,QAAQ,CAAC+B,SAAD,CAAR;IACD,CAFD,MAEO;MACL/B,QAAQ,CAAC+B,SAAD,CAAR;IACD;EACF,CAzED;;EA0EA,OAAO;IACL/B,QADK;IAELO,KAFK;IAGLQ,cAHK;IAILE,YAJK;IAKLJ;EALK,CAAP;AAOD"}
|
|
@@ -70,6 +70,7 @@ function enhanceTextWithMask(text, mask, previousValue) {
|
|
|
70
70
|
function TextInputWithMask(_ref, ref) {
|
|
71
71
|
let {
|
|
72
72
|
onChangeText,
|
|
73
|
+
onChange,
|
|
73
74
|
value,
|
|
74
75
|
mask,
|
|
75
76
|
...rest
|
|
@@ -97,6 +98,9 @@ function TextInputWithMask(_ref, ref) {
|
|
|
97
98
|
}, rest, {
|
|
98
99
|
value: controlledValue,
|
|
99
100
|
onChangeText: onInnerChange,
|
|
101
|
+
onChange: e => {
|
|
102
|
+
onChange && onChange(e);
|
|
103
|
+
},
|
|
100
104
|
onBlur: onInnerBlur
|
|
101
105
|
}));
|
|
102
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["splitCharacters","detectCharacter","mask","c","find","ch","includes","enhanceTextWithMask","text","previousValue","isBackSpace","length","splitCharacter","maskParts","split","textParts","finalString","maskPartIndex","partString","maskPart","textPart","maskDigitIndex","currentCharacter","undefined","character","push","join","lastPart","lastMaskPart","TextInputWithMask","ref","onChangeText","value","rest","controlledValue","setControlledValue","React","useState","onInnerChange","onInnerBlur","enhancedText","useEffect","forwardRef"],"sources":["TextInputMask.tsx"],"sourcesContent":["import * as React from 'react'\nimport { TextInput } from 'react-native-paper'\n\nconst splitCharacters = ['-', '/', '.', '年', ' ']\nfunction detectCharacter(mask: string): string {\n const c = splitCharacters.find((ch) => mask.includes(ch))\n return c || ''\n}\n\nfunction enhanceTextWithMask(\n text: string,\n mask: string,\n previousValue: string\n): string {\n const isBackSpace = previousValue.length > text.length\n const splitCharacter = detectCharacter(mask)\n\n const maskParts = mask.split(splitCharacter)\n const textParts = text.split(splitCharacter)\n\n let finalString: string[] = []\n for (let maskPartIndex = 0; maskPartIndex < mask.length; maskPartIndex++) {\n let partString: string[] = []\n\n const maskPart = maskParts[maskPartIndex]\n const textPart = textParts[maskPartIndex]\n if (!textPart) {\n continue\n }\n\n for (\n let maskDigitIndex = 0;\n maskDigitIndex < maskPart.length;\n maskDigitIndex++\n ) {\n const currentCharacter = textPart[maskDigitIndex]\n\n if (isBackSpace && currentCharacter === undefined) {\n continue\n }\n\n const character = textPart[maskDigitIndex]\n\n if (character !== undefined) {\n partString.push(character)\n }\n }\n\n finalString.push(partString.join(''))\n }\n\n const lastPart = finalString[finalString.length - 1]\n const lastMaskPart = maskParts[finalString.length - 1]\n if (\n // if mask is completed\n finalString.length !== maskParts.length &&\n // or ...\n lastPart &&\n lastMaskPart &&\n lastPart.length === lastMaskPart.length\n ) {\n return (\n finalString.join(splitCharacter) + (isBackSpace ? '' : splitCharacter)\n )\n }\n return finalString.join(splitCharacter)\n}\n\nfunction TextInputWithMask(\n {\n onChangeText,\n value,\n mask,\n ...rest\n }: React.ComponentProps<typeof TextInput> & { mask: string; value: string },\n ref: any\n) {\n const [controlledValue, setControlledValue] = React.useState<string>(\n value || ''\n )\n\n const onInnerChange = (text: string) => {\n if (text.length === mask.length) {\n onChangeText && onChangeText(text)\n }\n setControlledValue(text)\n }\n\n const onInnerBlur = () => {\n const enhancedText = enhanceTextWithMask(value, mask, controlledValue)\n setControlledValue(enhancedText)\n }\n\n React.useEffect(() => {\n setControlledValue(value || '')\n }, [value])\n\n return (\n <TextInput\n ref={ref}\n {...rest}\n value={controlledValue}\n onChangeText={onInnerChange}\n onBlur={onInnerBlur}\n />\n )\n}\n\nexport default React.forwardRef(TextInputWithMask)\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAEA,MAAMA,eAAe,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,GAArB,CAAxB;;AACA,SAASC,eAAT,CAAyBC,IAAzB,EAA+C;EAC7C,MAAMC,CAAC,GAAGH,eAAe,CAACI,IAAhB,CAAsBC,EAAD,IAAQH,IAAI,CAACI,QAAL,CAAcD,EAAd,CAA7B,CAAV;EACA,OAAOF,CAAC,IAAI,EAAZ;AACD;;AAED,SAASI,mBAAT,CACEC,IADF,EAEEN,IAFF,EAGEO,aAHF,EAIU;EACR,MAAMC,WAAW,GAAGD,aAAa,CAACE,MAAd,GAAuBH,IAAI,CAACG,MAAhD;EACA,MAAMC,cAAc,GAAGX,eAAe,CAACC,IAAD,CAAtC;EAEA,MAAMW,SAAS,GAAGX,IAAI,CAACY,KAAL,CAAWF,cAAX,CAAlB;EACA,MAAMG,SAAS,GAAGP,IAAI,CAACM,KAAL,CAAWF,cAAX,CAAl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,cAAjB,CAAP;AACD;;AAED,SAASiB,iBAAT,
|
|
1
|
+
{"version":3,"names":["splitCharacters","detectCharacter","mask","c","find","ch","includes","enhanceTextWithMask","text","previousValue","isBackSpace","length","splitCharacter","maskParts","split","textParts","finalString","maskPartIndex","partString","maskPart","textPart","maskDigitIndex","currentCharacter","undefined","character","push","join","lastPart","lastMaskPart","TextInputWithMask","ref","onChangeText","onChange","value","rest","controlledValue","setControlledValue","React","useState","onInnerChange","onInnerBlur","enhancedText","useEffect","e","forwardRef"],"sources":["TextInputMask.tsx"],"sourcesContent":["import * as React from 'react'\nimport { TextInput } from 'react-native-paper'\n\nconst splitCharacters = ['-', '/', '.', '年', ' ']\nfunction detectCharacter(mask: string): string {\n const c = splitCharacters.find((ch) => mask.includes(ch))\n return c || ''\n}\n\nfunction enhanceTextWithMask(\n text: string,\n mask: string,\n previousValue: string\n): string {\n const isBackSpace = previousValue.length > text.length\n const splitCharacter = detectCharacter(mask)\n\n const maskParts = mask.split(splitCharacter)\n const textParts = text.split(splitCharacter)\n\n let finalString: string[] = []\n for (let maskPartIndex = 0; maskPartIndex < mask.length; maskPartIndex++) {\n let partString: string[] = []\n\n const maskPart = maskParts[maskPartIndex]\n const textPart = textParts[maskPartIndex]\n if (!textPart) {\n continue\n }\n\n for (\n let maskDigitIndex = 0;\n maskDigitIndex < maskPart.length;\n maskDigitIndex++\n ) {\n const currentCharacter = textPart[maskDigitIndex]\n\n if (isBackSpace && currentCharacter === undefined) {\n continue\n }\n\n const character = textPart[maskDigitIndex]\n\n if (character !== undefined) {\n partString.push(character)\n }\n }\n\n finalString.push(partString.join(''))\n }\n\n const lastPart = finalString[finalString.length - 1]\n const lastMaskPart = maskParts[finalString.length - 1]\n if (\n // if mask is completed\n finalString.length !== maskParts.length &&\n // or ...\n lastPart &&\n lastMaskPart &&\n lastPart.length === lastMaskPart.length\n ) {\n return (\n finalString.join(splitCharacter) + (isBackSpace ? '' : splitCharacter)\n )\n }\n return finalString.join(splitCharacter)\n}\n\nfunction TextInputWithMask(\n {\n onChangeText,\n onChange,\n value,\n mask,\n ...rest\n }: React.ComponentProps<typeof TextInput> & { mask: string; value: string },\n ref: any\n) {\n const [controlledValue, setControlledValue] = React.useState<string>(\n value || ''\n )\n\n const onInnerChange = (text: string) => {\n if (text.length === mask.length) {\n onChangeText && onChangeText(text)\n }\n setControlledValue(text)\n }\n\n const onInnerBlur = () => {\n const enhancedText = enhanceTextWithMask(value, mask, controlledValue)\n setControlledValue(enhancedText)\n }\n\n React.useEffect(() => {\n setControlledValue(value || '')\n }, [value])\n\n return (\n <TextInput\n ref={ref}\n {...rest}\n value={controlledValue}\n onChangeText={onInnerChange}\n onChange={(e) => {\n onChange && onChange(e)\n }}\n onBlur={onInnerBlur}\n />\n )\n}\n\nexport default React.forwardRef(TextInputWithMask)\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAEA,MAAMA,eAAe,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,GAArB,CAAxB;;AACA,SAASC,eAAT,CAAyBC,IAAzB,EAA+C;EAC7C,MAAMC,CAAC,GAAGH,eAAe,CAACI,IAAhB,CAAsBC,EAAD,IAAQH,IAAI,CAACI,QAAL,CAAcD,EAAd,CAA7B,CAAV;EACA,OAAOF,CAAC,IAAI,EAAZ;AACD;;AAED,SAASI,mBAAT,CACEC,IADF,EAEEN,IAFF,EAGEO,aAHF,EAIU;EACR,MAAMC,WAAW,GAAGD,aAAa,CAACE,MAAd,GAAuBH,IAAI,CAACG,MAAhD;EACA,MAAMC,cAAc,GAAGX,eAAe,CAACC,IAAD,CAAtC;EAEA,MAAMW,SAAS,GAAGX,IAAI,CAACY,KAAL,CAAWF,cAAX,CAAlB;EACA,MAAMG,SAAS,GAAGP,IAAI,CAACM,KAAL,CAAWF,cAAX,CAAlB;EAEA,IAAII,WAAqB,GAAG,EAA5B;;EACA,KAAK,IAAIC,aAAa,GAAG,CAAzB,EAA4BA,aAAa,GA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;IAGEC,KAHF;IAIE/B,IAJF;IAKE,GAAGgC;EALL,CAQA;EACA,MAAM,CAACC,eAAD,EAAkBC,kBAAlB,IAAwCC,KAAK,CAACC,QAAN,CAC5CL,KAAK,IAAI,EADmC,CAA9C;;EAIA,MAAMM,aAAa,GAAI/B,IAAD,IAAkB;IACtC,IAAIA,IAAI,CAACG,MAAL,KAAgBT,IAAI,CAACS,MAAzB,EAAiC;MAC/BoB,YAAY,IAAIA,YAAY,CAACvB,IAAD,CAA5B;IACD;;IACD4B,kBAAkB,CAAC5B,IAAD,CAAlB;EACD,CALD;;EAOA,MAAMgC,WAAW,GAAG,MAAM;IACxB,MAAMC,YAAY,GAAGlC,mBAAmB,CAAC0B,KAAD,EAAQ/B,IAAR,EAAciC,eAAd,CAAxC;IACAC,kBAAkB,CAACK,YAAD,CAAlB;EACD,CAHD;;EAKAJ,KAAK,CAACK,SAAN,CAAgB,MAAM;IACpBN,kBAAkB,CAACH,KAAK,IAAI,EAAV,CAAlB;EACD,CAFD,EAEG,CAACA,KAAD,CAFH;EAIA,oBACE,oBAAC,2BAAD;IACE,GAAG,EAAEH;EADP,GAEMI,IAFN;IAGE,KAAK,EAAEC,eAHT;IAIE,YAAY,EAAEI,aAJhB;IAKE,QAAQ,EAAGI,CAAD,IAAO;MACfX,QAAQ,IAAIA,QAAQ,CAACW,CAAD,CAApB;IACD,CAPH;IAQE,MAAM,EAAEH;EARV,GADF;AAYD;;4BAEcH,KAAK,CAACO,UAAN,CAAiBf,iBAAjB,C"}
|
|
@@ -33,14 +33,19 @@ function DatePickerInput(_ref, ref) {
|
|
|
33
33
|
style: styles.calendarButton,
|
|
34
34
|
icon: calendarIcon,
|
|
35
35
|
onPress: () => setVisible(true)
|
|
36
|
-
}) : null
|
|
36
|
+
}) : null // eslint-disable-next-line react/no-unstable-nested-components
|
|
37
|
+
,
|
|
37
38
|
modal: _ref3 => {
|
|
38
39
|
let {
|
|
39
40
|
value,
|
|
40
41
|
locale,
|
|
41
42
|
inputMode,
|
|
42
43
|
validRange,
|
|
43
|
-
saveLabel
|
|
44
|
+
saveLabel,
|
|
45
|
+
saveLabelDisabled,
|
|
46
|
+
uppercase,
|
|
47
|
+
startYear,
|
|
48
|
+
endYear
|
|
44
49
|
} = _ref3;
|
|
45
50
|
return withModal ? /*#__PURE__*/React.createElement(DatePickerModal, {
|
|
46
51
|
date: value,
|
|
@@ -51,7 +56,11 @@ function DatePickerInput(_ref, ref) {
|
|
|
51
56
|
locale: locale,
|
|
52
57
|
dateMode: inputMode,
|
|
53
58
|
validRange: validRange,
|
|
54
|
-
saveLabel: saveLabel
|
|
59
|
+
saveLabel: saveLabel,
|
|
60
|
+
saveLabelDisabled: saveLabelDisabled ?? false,
|
|
61
|
+
uppercase: uppercase ?? true,
|
|
62
|
+
startYear: startYear ?? 1800,
|
|
63
|
+
endYear: endYear ?? 2200
|
|
55
64
|
}) : null;
|
|
56
65
|
}
|
|
57
66
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","IconButton","StyleSheet","DatePickerModal","useLatest","DatePickerInputWithoutModal","DatePickerInput","ref","withModal","calendarIcon","rest","visible","setVisible","useState","onDismiss","useCallback","onChangeRef","onChange","onInnerConfirm","date","current","styles","calendarButton","value","locale","inputMode","validRange","saveLabel","create","position","right","zIndex","forwardRef"],"sources":["DatePickerInput.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { IconButton } from 'react-native-paper'\nimport { StyleSheet } from 'react-native'\nimport DatePickerModal from './DatePickerModal'\nimport { useLatest } from '../utils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\nimport DatePickerInputWithoutModal from './DatePickerInputWithoutModal'\n\nfunction DatePickerInput(\n {\n withModal = true,\n calendarIcon = 'calendar',\n ...rest\n }: DatePickerInputProps,\n ref: any\n) {\n const [visible, setVisible] = React.useState<boolean>(false)\n const onDismiss = React.useCallback(() => {\n setVisible(false)\n }, [setVisible])\n const onChangeRef = useLatest(rest.onChange)\n const onInnerConfirm = React.useCallback(\n ({ date }: any) => {\n setVisible(false)\n onChangeRef.current(date)\n },\n [setVisible, onChangeRef]\n )\n\n return (\n <DatePickerInputWithoutModal\n ref={ref}\n {...rest}\n inputButtons={\n withModal ? (\n <IconButton\n size={24}\n style={styles.calendarButton}\n icon={calendarIcon}\n onPress={() => setVisible(true)}\n />\n ) : null\n }\n modal={({
|
|
1
|
+
{"version":3,"names":["React","IconButton","StyleSheet","DatePickerModal","useLatest","DatePickerInputWithoutModal","DatePickerInput","ref","withModal","calendarIcon","rest","visible","setVisible","useState","onDismiss","useCallback","onChangeRef","onChange","onInnerConfirm","date","current","styles","calendarButton","value","locale","inputMode","validRange","saveLabel","saveLabelDisabled","uppercase","startYear","endYear","create","position","right","zIndex","forwardRef"],"sources":["DatePickerInput.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { IconButton } from 'react-native-paper'\nimport { StyleSheet } from 'react-native'\nimport DatePickerModal from './DatePickerModal'\nimport { useLatest } from '../utils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\nimport DatePickerInputWithoutModal from './DatePickerInputWithoutModal'\n\nfunction DatePickerInput(\n {\n withModal = true,\n calendarIcon = 'calendar',\n ...rest\n }: DatePickerInputProps,\n ref: any\n) {\n const [visible, setVisible] = React.useState<boolean>(false)\n const onDismiss = React.useCallback(() => {\n setVisible(false)\n }, [setVisible])\n const onChangeRef = useLatest(rest.onChange)\n const onInnerConfirm = React.useCallback(\n ({ date }: any) => {\n setVisible(false)\n onChangeRef.current(date)\n },\n [setVisible, onChangeRef]\n )\n\n return (\n <DatePickerInputWithoutModal\n ref={ref}\n {...rest}\n inputButtons={\n withModal ? (\n <IconButton\n size={24}\n style={styles.calendarButton}\n icon={calendarIcon}\n onPress={() => setVisible(true)}\n />\n ) : null\n }\n // eslint-disable-next-line react/no-unstable-nested-components\n modal={({\n value,\n locale,\n inputMode,\n validRange,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n }) =>\n withModal ? (\n <DatePickerModal\n date={value}\n mode=\"single\"\n visible={visible}\n onDismiss={onDismiss}\n onConfirm={onInnerConfirm}\n locale={locale}\n dateMode={inputMode}\n validRange={validRange}\n saveLabel={saveLabel}\n saveLabelDisabled={saveLabelDisabled ?? false}\n uppercase={uppercase ?? true}\n startYear={startYear ?? 1800}\n endYear={endYear ?? 2200}\n />\n ) : null\n }\n />\n )\n}\n\nconst styles = StyleSheet.create({\n calendarButton: { position: 'absolute', right: 0, zIndex: 10 },\n})\n\nexport default React.forwardRef(DatePickerInput)\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,SAASC,UAAT,QAA2B,oBAA3B;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAOC,2BAAP,MAAwC,+BAAxC;;AAEA,SAASC,eAAT,OAMEC,GANF,EAOE;EAAA,IANA;IACEC,SAAS,GAAG,IADd;IAEEC,YAAY,GAAG,UAFjB;IAGE,GAAGC;EAHL,CAMA;EACA,MAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBZ,KAAK,CAACa,QAAN,CAAwB,KAAxB,CAA9B;EACA,MAAMC,SAAS,GAAGd,KAAK,CAACe,WAAN,CAAkB,MAAM;IACxCH,UAAU,CAAC,KAAD,CAAV;EACD,CAFiB,EAEf,CAACA,UAAD,CAFe,CAAlB;EAGA,MAAMI,WAAW,GAAGZ,SAAS,CAACM,IAAI,CAACO,QAAN,CAA7B;EACA,MAAMC,cAAc,GAAGlB,KAAK,CAACe,WAAN,CACrB,SAAmB;IAAA,IAAlB;MAAEI;IAAF,CAAkB;IACjBP,UAAU,CAAC,KAAD,CAAV;IACAI,WAAW,CAACI,OAAZ,CAAoBD,IAApB;EACD,CAJoB,EAKrB,CAACP,UAAD,EAAaI,WAAb,CALqB,CAAvB;EAQA,oBACE,oBAAC,2BAAD;IACE,GAAG,EAAET;EADP,GAEMG,IAFN;IAGE,YAAY,EACVF,SAAS,gBACP,oBAAC,UAAD;MACE,IAAI,EAAE,EADR;MAEE,KAAK,EAAEa,MAAM,CAACC,cAFhB;MAGE,IAAI,EAAEb,YAHR;MAIE,OAAO,EAAE,MAAMG,UAAU,CAAC,IAAD;IAJ3B,EADO,GAOL,IAXR,CAaE;IAbF;IAcE,KAAK,EAAE;MAAA,IAAC;QACNW,KADM;QAENC,MAFM;QAGNC,SAHM;QAINC,UAJM;QAKNC,SALM;QAMNC,iBANM;QAONC,SAPM;QAQNC,SARM;QASNC;MATM,CAAD;MAAA,OAWLvB,SAAS,gBACP,oBAAC,eAAD;QACE,IAAI,EAAEe,KADR;QAEE,IAAI,EAAC,QAFP;QAGE,OAAO,EAAEZ,OAHX;QAIE,SAAS,EAAEG,SAJb;QAKE,SAAS,EAAEI,cALb;QAME,MAAM,EAAEM,MANV;QAOE,QAAQ,EAAEC,SAPZ;QAQE,UAAU,EAAEC,UARd;QASE,SAAS,EAAEC,SATb;QAUE,iBAAiB,EAAEC,iBAAiB,IAAI,KAV1C;QAWE,SAAS,EAAEC,SAAS,IAAI,IAX1B;QAYE,SAAS,EAAEC,SAAS,IAAI,IAZ1B;QAaE,OAAO,EAAEC,OAAO,IAAI;MAbtB,EADO,GAgBL,IA3BC;IAAA;EAdT,GADF;AA8CD;;AAED,MAAMV,MAAM,GAAGnB,UAAU,CAAC8B,MAAX,CAAkB;EAC/BV,cAAc,EAAE;IAAEW,QAAQ,EAAE,UAAZ;IAAwBC,KAAK,EAAE,CAA/B;IAAkCC,MAAM,EAAE;EAA1C;AADe,CAAlB,CAAf;AAIA,4BAAenC,KAAK,CAACoC,UAAN,CAAiB9B,eAAjB,CAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["DatePickerInput.shared.tsx"],"sourcesContent":["import type { ValidRangeType } from './Calendar'\nimport type * as React from 'react'\nimport type { TextInput } from 'react-native-paper'\n\nexport type DatePickerInputProps = {\n inputMode: 'start' | 'end'\n locale: string\n onChange: (date: Date | undefined) => void\n value: Date | undefined\n validRange?: ValidRangeType | undefined\n withModal?: boolean\n withDateFormatInLabel?: boolean\n calendarIcon?: string\n saveLabel?: string\n} & Omit<\n React.ComponentProps<typeof TextInput>,\n 'value' | 'onChange' | 'onChangeText'\n>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["DatePickerInput.shared.tsx"],"sourcesContent":["import type { ValidRangeType } from './Calendar'\nimport type * as React from 'react'\nimport type { TextInput } from 'react-native-paper'\n\nexport type DatePickerInputProps = {\n inputMode: 'start' | 'end'\n locale: string\n onChange: (date: Date | undefined) => void\n value: Date | undefined\n validRange?: ValidRangeType | undefined\n withModal?: boolean\n withDateFormatInLabel?: boolean\n hideValidationErrors?: boolean\n hasError?: boolean\n onValidationError?: ((error: string | null) => void) | undefined\n calendarIcon?: string\n saveLabel?: string\n saveLabelDisabled?: boolean\n uppercase?: boolean\n startYear?: number\n endYear?: number\n onChangeText?: (text: string | undefined) => void\n} & Omit<\n React.ComponentProps<typeof TextInput>,\n 'value' | 'onChange' | 'onChangeText'\n>\n"],"mappings":""}
|
|
@@ -16,23 +16,32 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
16
16
|
validRange,
|
|
17
17
|
inputMode,
|
|
18
18
|
withDateFormatInLabel = true,
|
|
19
|
+
hasError,
|
|
20
|
+
hideValidationErrors,
|
|
21
|
+
onValidationError,
|
|
19
22
|
modal,
|
|
20
23
|
inputButtons,
|
|
21
24
|
saveLabel,
|
|
25
|
+
saveLabelDisabled,
|
|
26
|
+
uppercase,
|
|
27
|
+
startYear,
|
|
28
|
+
endYear,
|
|
29
|
+
onChangeText,
|
|
22
30
|
...rest
|
|
23
31
|
} = _ref;
|
|
24
32
|
const theme = useTheme();
|
|
25
33
|
const {
|
|
26
34
|
formattedValue,
|
|
27
35
|
inputFormat,
|
|
28
|
-
onChangeText,
|
|
36
|
+
onChangeText: onDateInputChangeText,
|
|
29
37
|
error
|
|
30
38
|
} = useDateInput({
|
|
31
39
|
locale,
|
|
32
40
|
value,
|
|
33
41
|
validRange,
|
|
34
42
|
inputMode,
|
|
35
|
-
onChange
|
|
43
|
+
onChange,
|
|
44
|
+
onValidationError
|
|
36
45
|
});
|
|
37
46
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
|
|
38
47
|
style: styles.root
|
|
@@ -47,15 +56,14 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
47
56
|
withDateFormatInLabel
|
|
48
57
|
}),
|
|
49
58
|
value: formattedValue,
|
|
50
|
-
keyboardType: 'number-pad',
|
|
51
|
-
placeholder: inputFormat,
|
|
59
|
+
keyboardType: rest.keyboardType ?? 'number-pad',
|
|
52
60
|
mask: inputFormat,
|
|
53
|
-
onChangeText:
|
|
61
|
+
onChangeText: onDateInputChangeText,
|
|
62
|
+
onChange: e => onChangeText && onChangeText(e.nativeEvent.text),
|
|
54
63
|
keyboardAppearance: theme.dark ? 'dark' : 'default',
|
|
55
|
-
error: !!error,
|
|
64
|
+
error: !!error && !hideValidationErrors || !!hasError,
|
|
56
65
|
style: [styles.input, style]
|
|
57
|
-
})), inputButtons), error ? /*#__PURE__*/React.createElement(HelperText, {
|
|
58
|
-
style: styles.helperText,
|
|
66
|
+
})), inputButtons), error && !hideValidationErrors ? /*#__PURE__*/React.createElement(HelperText, {
|
|
59
67
|
type: "error",
|
|
60
68
|
visible: !!error
|
|
61
69
|
}, error) : null), modal === null || modal === void 0 ? void 0 : modal({
|
|
@@ -63,7 +71,11 @@ function DatePickerInputWithoutModal(_ref, ref) {
|
|
|
63
71
|
locale,
|
|
64
72
|
inputMode,
|
|
65
73
|
validRange,
|
|
66
|
-
saveLabel
|
|
74
|
+
saveLabel,
|
|
75
|
+
saveLabelDisabled,
|
|
76
|
+
uppercase,
|
|
77
|
+
startYear,
|
|
78
|
+
endYear
|
|
67
79
|
}));
|
|
68
80
|
}
|
|
69
81
|
|
|
@@ -93,8 +105,6 @@ const styles = StyleSheet.create({
|
|
|
93
105
|
},
|
|
94
106
|
input: {
|
|
95
107
|
flexGrow: 1
|
|
96
|
-
},
|
|
97
|
-
helperText: {// flex: 1,
|
|
98
108
|
}
|
|
99
109
|
});
|
|
100
110
|
export default /*#__PURE__*/React.forwardRef(DatePickerInputWithoutModal);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","TextInputWithMask","HelperText","useTheme","View","StyleSheet","useDateInput","DatePickerInputWithoutModal","ref","label","value","onChange","style","locale","validRange","inputMode","withDateFormatInLabel","modal","inputButtons","saveLabel","rest","theme","formattedValue","inputFormat","
|
|
1
|
+
{"version":3,"names":["React","TextInputWithMask","HelperText","useTheme","View","StyleSheet","useDateInput","DatePickerInputWithoutModal","ref","label","value","onChange","style","locale","validRange","inputMode","withDateFormatInLabel","hasError","hideValidationErrors","onValidationError","modal","inputButtons","saveLabel","saveLabelDisabled","uppercase","startYear","endYear","onChangeText","rest","theme","formattedValue","inputFormat","onDateInputChangeText","error","styles","root","inputContainer","getLabel","keyboardType","e","nativeEvent","text","dark","input","create","flexGrow","flexDirection","alignItems","justifyContent","forwardRef"],"sources":["DatePickerInputWithoutModal.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport TextInputWithMask from '../TextInputMask'\nimport { HelperText, useTheme } from 'react-native-paper'\nimport { View, StyleSheet } from 'react-native'\nimport useDateInput from './inputUtils'\nimport type { DatePickerInputProps } from './DatePickerInput.shared'\n\nfunction DatePickerInputWithoutModal(\n {\n label,\n value,\n onChange,\n style,\n locale,\n validRange,\n inputMode,\n withDateFormatInLabel = true,\n hasError,\n hideValidationErrors,\n onValidationError,\n modal,\n inputButtons,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n onChangeText,\n ...rest\n }: DatePickerInputProps & {\n modal?: (params: {\n value: DatePickerInputProps['value']\n locale: DatePickerInputProps['locale']\n inputMode: DatePickerInputProps['inputMode']\n validRange: DatePickerInputProps['validRange']\n saveLabel: DatePickerInputProps['saveLabel']\n saveLabelDisabled: DatePickerInputProps['saveLabelDisabled']\n uppercase: DatePickerInputProps['uppercase']\n startYear: DatePickerInputProps['startYear']\n endYear: DatePickerInputProps['endYear']\n }) => any\n inputButtons?: any\n },\n ref: any\n) {\n const theme = useTheme()\n const {\n formattedValue,\n inputFormat,\n onChangeText: onDateInputChangeText,\n error,\n } = useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n onValidationError,\n })\n\n return (\n <>\n <View style={styles.root}>\n <View style={styles.inputContainer}>\n <TextInputWithMask\n {...rest}\n ref={ref}\n label={getLabel({\n // TODO: support label components?\n label: label as any,\n inputFormat,\n withDateFormatInLabel,\n })}\n value={formattedValue}\n keyboardType={rest.keyboardType ?? 'number-pad'}\n mask={inputFormat}\n onChangeText={onDateInputChangeText}\n onChange={(e) => onChangeText && onChangeText(e.nativeEvent.text)}\n keyboardAppearance={theme.dark ? 'dark' : 'default'}\n error={(!!error && !hideValidationErrors) || !!hasError}\n style={[styles.input, style]}\n />\n {inputButtons}\n </View>\n {error && !hideValidationErrors ? (\n <HelperText type=\"error\" visible={!!error}>\n {error}\n </HelperText>\n ) : null}\n </View>\n {modal?.({\n value,\n locale,\n inputMode,\n validRange,\n saveLabel,\n saveLabelDisabled,\n uppercase,\n startYear,\n endYear,\n })}\n </>\n )\n}\n\nfunction getLabel({\n withDateFormatInLabel,\n inputFormat,\n label,\n}: {\n withDateFormatInLabel: boolean\n inputFormat: string\n label: string | undefined\n}) {\n if (withDateFormatInLabel) {\n return label ? `${label} (${inputFormat})` : inputFormat\n }\n return label || ''\n}\n\nconst styles = StyleSheet.create({\n root: {\n flexGrow: 1,\n },\n inputContainer: {\n flexGrow: 1,\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'flex-start',\n },\n input: {\n flexGrow: 1,\n },\n})\nexport default React.forwardRef(DatePickerInputWithoutModal)\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ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 +7,8 @@ export default function useDateInput(_ref) {
|
|
|
7
7
|
value,
|
|
8
8
|
validRange,
|
|
9
9
|
inputMode,
|
|
10
|
-
onChange
|
|
10
|
+
onChange,
|
|
11
|
+
onValidationError
|
|
11
12
|
} = _ref;
|
|
12
13
|
const {
|
|
13
14
|
isDisabled,
|
|
@@ -23,7 +24,7 @@ export default function useDateInput(_ref) {
|
|
|
23
24
|
formatter,
|
|
24
25
|
locale
|
|
25
26
|
});
|
|
26
|
-
const formattedValue = value
|
|
27
|
+
const formattedValue = value ? formatter.format(value) : '';
|
|
27
28
|
|
|
28
29
|
const onChangeText = date => {
|
|
29
30
|
const dayIndex = inputFormat.indexOf('DD');
|
|
@@ -34,24 +35,31 @@ export default function useDateInput(_ref) {
|
|
|
34
35
|
const month = Number(date.slice(monthIndex, monthIndex + 2));
|
|
35
36
|
|
|
36
37
|
if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {
|
|
37
|
-
|
|
38
|
+
const inputError = getTranslation(locale, 'notAccordingToDateFormat', () => 'notAccordingToDateFormat')(inputFormat);
|
|
39
|
+
setError(inputError);
|
|
40
|
+
onValidationError && onValidationError(inputError);
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
const finalDate = inputMode === 'end' ? new Date(year, month - 1, day, 23, 59, 59) : new Date(year, month - 1, day);
|
|
42
45
|
|
|
43
46
|
if (isDisabled(finalDate)) {
|
|
44
|
-
|
|
47
|
+
const inputError = getTranslation(locale, 'dateIsDisabled');
|
|
48
|
+
setError(inputError);
|
|
49
|
+
onValidationError && onValidationError(inputError);
|
|
45
50
|
return;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
if (!isWithinValidRange(finalDate)) {
|
|
49
54
|
let errors = validStart && validEnd ? [`${getTranslation(locale, 'mustBeBetween', () => 'mustBeBetween')(formatter.format(validStart), formatter.format(validEnd))}`] : [validStart ? getTranslation(locale, 'mustBeHigherThan', () => 'mustBeHigherThan')(formatter.format(validStart)) : '', validEnd ? getTranslation(locale, 'mustBeLowerThan', () => 'mustBeLowerThan')(formatter.format(validEnd)) : ''];
|
|
55
|
+
const inputError = errors.filter(n => n).join(' ');
|
|
50
56
|
setError(errors.filter(n => n).join(' '));
|
|
57
|
+
onValidationError && onValidationError(inputError);
|
|
51
58
|
return;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
setError(null);
|
|
62
|
+
onValidationError && onValidationError(null);
|
|
55
63
|
|
|
56
64
|
if (inputMode === 'end') {
|
|
57
65
|
onChange(finalDate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useInputFormat","useInputFormatter","useRangeChecker","React","getTranslation","useDateInput","locale","value","validRange","inputMode","onChange","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","finalDate","Date","errors","filter","n","join"],"sources":["inputUtils.ts"],"sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from '../translations/utils'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = value
|
|
1
|
+
{"version":3,"names":["useInputFormat","useInputFormatter","useRangeChecker","React","getTranslation","useDateInput","locale","value","validRange","inputMode","onChange","onValidationError","isDisabled","isWithinValidRange","validStart","validEnd","error","setError","useState","formatter","inputFormat","formattedValue","format","onChangeText","date","dayIndex","indexOf","monthIndex","yearIndex","day","Number","slice","year","month","isNaN","inputError","finalDate","Date","errors","filter","n","join"],"sources":["inputUtils.ts"],"sourcesContent":["import { useInputFormat, useInputFormatter, useRangeChecker } from './dateUtils'\nimport * as React from 'react'\nimport type { ValidRangeType } from './Calendar'\nimport { getTranslation } from '../translations/utils'\n\nexport default function useDateInput({\n locale,\n value,\n validRange,\n inputMode,\n onChange,\n onValidationError,\n}: {\n onChange: (d: Date) => void\n locale: undefined | string\n value: Date | undefined\n validRange: ValidRangeType | undefined\n inputMode: 'start' | 'end'\n onValidationError?: ((error: string | null) => void) | undefined\n}) {\n const { isDisabled, isWithinValidRange, validStart, validEnd } =\n useRangeChecker(validRange)\n const [error, setError] = React.useState<null | string>(null)\n const formatter = useInputFormatter({ locale })\n const inputFormat = useInputFormat({ formatter, locale })\n const formattedValue = value ? formatter.format(value) : ''\n const onChangeText = (date: string) => {\n const dayIndex = inputFormat.indexOf('DD')\n const monthIndex = inputFormat.indexOf('MM')\n const yearIndex =\n locale === 'pt'\n ? inputFormat.indexOf('AAAA')\n : inputFormat.indexOf('YYYY')\n\n const day = Number(date.slice(dayIndex, dayIndex + 2))\n const year = Number(date.slice(yearIndex, yearIndex + 4))\n const month = Number(date.slice(monthIndex, monthIndex + 2))\n\n if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {\n const inputError = getTranslation(\n locale,\n 'notAccordingToDateFormat',\n () => 'notAccordingToDateFormat'\n )(inputFormat)\n setError(inputError)\n onValidationError && onValidationError(inputError)\n return\n }\n\n const finalDate =\n inputMode === 'end'\n ? new Date(year, month - 1, day, 23, 59, 59)\n : new Date(year, month - 1, day)\n\n if (isDisabled(finalDate)) {\n const inputError = getTranslation(locale, 'dateIsDisabled')\n setError(inputError)\n onValidationError && onValidationError(inputError)\n return\n }\n if (!isWithinValidRange(finalDate)) {\n let errors =\n validStart && validEnd\n ? [\n `${getTranslation(\n locale,\n 'mustBeBetween',\n () => 'mustBeBetween'\n )(formatter.format(validStart), formatter.format(validEnd))}`,\n ]\n : [\n validStart\n ? getTranslation(\n locale,\n 'mustBeHigherThan',\n () => 'mustBeHigherThan'\n )(formatter.format(validStart))\n : '',\n validEnd\n ? getTranslation(\n locale,\n 'mustBeLowerThan',\n () => 'mustBeLowerThan'\n )(formatter.format(validEnd))\n : '',\n ]\n const inputError = errors.filter((n) => n).join(' ')\n setError(errors.filter((n) => n).join(' '))\n onValidationError && onValidationError(inputError)\n return\n }\n\n setError(null)\n onValidationError && onValidationError(null)\n if (inputMode === 'end') {\n onChange(finalDate)\n } else {\n onChange(finalDate)\n }\n }\n return {\n onChange,\n error,\n formattedValue,\n onChangeText,\n inputFormat,\n }\n}\n"],"mappings":"AAAA,SAASA,cAAT,EAAyBC,iBAAzB,EAA4CC,eAA5C,QAAmE,aAAnE;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,SAASC,cAAT,QAA+B,uBAA/B;AAEA,eAAe,SAASC,YAAT,OAcZ;EAAA,IAdkC;IACnCC,MADmC;IAEnCC,KAFmC;IAGnCC,UAHmC;IAInCC,SAJmC;IAKnCC,QALmC;IAMnCC;EANmC,CAclC;EACD,MAAM;IAAEC,UAAF;IAAcC,kBAAd;IAAkCC,UAAlC;IAA8CC;EAA9C,IACJb,eAAe,CAACM,UAAD,CADjB;EAEA,MAAM,CAACQ,KAAD,EAAQC,QAAR,IAAoBd,KAAK,CAACe,QAAN,CAA8B,IAA9B,CAA1B;EACA,MAAMC,SAAS,GAAGlB,iBAAiB,CAAC;IAAEK;EAAF,CAAD,CAAnC;EACA,MAAMc,WAAW,GAAGpB,cAAc,CAAC;IAAEmB,SAAF;IAAab;EAAb,CAAD,CAAlC;EACA,MAAMe,cAAc,GAAGd,KAAK,GAAGY,SAAS,CAACG,MAAV,CAAiBf,KAAjB,CAAH,GAA6B,EAAzD;;EACA,MAAMgB,YAAY,GAAIC,IAAD,IAAkB;IACrC,MAAMC,QAAQ,GAAGL,WAAW,CAACM,OAAZ,CAAoB,IAApB,CAAjB;IACA,MAAMC,UAAU,GAAGP,WAA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;IAKLH;EALK,CAAP;AAOD"}
|
|
@@ -57,6 +57,7 @@ function enhanceTextWithMask(text, mask, previousValue) {
|
|
|
57
57
|
function TextInputWithMask(_ref, ref) {
|
|
58
58
|
let {
|
|
59
59
|
onChangeText,
|
|
60
|
+
onChange,
|
|
60
61
|
value,
|
|
61
62
|
mask,
|
|
62
63
|
...rest
|
|
@@ -84,6 +85,9 @@ function TextInputWithMask(_ref, ref) {
|
|
|
84
85
|
}, rest, {
|
|
85
86
|
value: controlledValue,
|
|
86
87
|
onChangeText: onInnerChange,
|
|
88
|
+
onChange: e => {
|
|
89
|
+
onChange && onChange(e);
|
|
90
|
+
},
|
|
87
91
|
onBlur: onInnerBlur
|
|
88
92
|
}));
|
|
89
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","TextInput","splitCharacters","detectCharacter","mask","c","find","ch","includes","enhanceTextWithMask","text","previousValue","isBackSpace","length","splitCharacter","maskParts","split","textParts","finalString","maskPartIndex","partString","maskPart","textPart","maskDigitIndex","currentCharacter","undefined","character","push","join","lastPart","lastMaskPart","TextInputWithMask","ref","onChangeText","value","rest","controlledValue","setControlledValue","useState","onInnerChange","onInnerBlur","enhancedText","useEffect","forwardRef"],"sources":["TextInputMask.tsx"],"sourcesContent":["import * as React from 'react'\nimport { TextInput } from 'react-native-paper'\n\nconst splitCharacters = ['-', '/', '.', '年', ' ']\nfunction detectCharacter(mask: string): string {\n const c = splitCharacters.find((ch) => mask.includes(ch))\n return c || ''\n}\n\nfunction enhanceTextWithMask(\n text: string,\n mask: string,\n previousValue: string\n): string {\n const isBackSpace = previousValue.length > text.length\n const splitCharacter = detectCharacter(mask)\n\n const maskParts = mask.split(splitCharacter)\n const textParts = text.split(splitCharacter)\n\n let finalString: string[] = []\n for (let maskPartIndex = 0; maskPartIndex < mask.length; maskPartIndex++) {\n let partString: string[] = []\n\n const maskPart = maskParts[maskPartIndex]\n const textPart = textParts[maskPartIndex]\n if (!textPart) {\n continue\n }\n\n for (\n let maskDigitIndex = 0;\n maskDigitIndex < maskPart.length;\n maskDigitIndex++\n ) {\n const currentCharacter = textPart[maskDigitIndex]\n\n if (isBackSpace && currentCharacter === undefined) {\n continue\n }\n\n const character = textPart[maskDigitIndex]\n\n if (character !== undefined) {\n partString.push(character)\n }\n }\n\n finalString.push(partString.join(''))\n }\n\n const lastPart = finalString[finalString.length - 1]\n const lastMaskPart = maskParts[finalString.length - 1]\n if (\n // if mask is completed\n finalString.length !== maskParts.length &&\n // or ...\n lastPart &&\n lastMaskPart &&\n lastPart.length === lastMaskPart.length\n ) {\n return (\n finalString.join(splitCharacter) + (isBackSpace ? '' : splitCharacter)\n )\n }\n return finalString.join(splitCharacter)\n}\n\nfunction TextInputWithMask(\n {\n onChangeText,\n value,\n mask,\n ...rest\n }: React.ComponentProps<typeof TextInput> & { mask: string; value: string },\n ref: any\n) {\n const [controlledValue, setControlledValue] = React.useState<string>(\n value || ''\n )\n\n const onInnerChange = (text: string) => {\n if (text.length === mask.length) {\n onChangeText && onChangeText(text)\n }\n setControlledValue(text)\n }\n\n const onInnerBlur = () => {\n const enhancedText = enhanceTextWithMask(value, mask, controlledValue)\n setControlledValue(enhancedText)\n }\n\n React.useEffect(() => {\n setControlledValue(value || '')\n }, [value])\n\n return (\n <TextInput\n ref={ref}\n {...rest}\n value={controlledValue}\n onChangeText={onInnerChange}\n onBlur={onInnerBlur}\n />\n )\n}\n\nexport default React.forwardRef(TextInputWithMask)\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA,MAAMC,eAAe,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,GAArB,CAAxB;;AACA,SAASC,eAAT,CAAyBC,IAAzB,EAA+C;EAC7C,MAAMC,CAAC,GAAGH,eAAe,CAACI,IAAhB,CAAsBC,EAAD,IAAQH,IAAI,CAACI,QAAL,CAAcD,EAAd,C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AY,GAAGf,SAAS,CAACG,WAAW,CAACL,MAAZ,GAAqB,CAAtB,CAA9B;;EACA,KACE;EACAK,WAAW,CAACL,MAAZ,KAAuBE,SAAS,CAACF,MAAjC,IACA;EACAgB,QAFA,IAGAC,YAHA,IAIAD,QAAQ,CAAChB,MAAT,KAAoBiB,YAAY,CAACjB,MANnC,EAOE;IACA,OACEK,WAAW,CAACU,IAAZ,CAAiBd,cAAjB,KAAoCF,WAAW,GAAG,EAAH,GAAQE,cAAvD,CADF;EAGD;;EACD,OAAOI,WAAW,CAACU,IAAZ,CAAiBd,cAAjB,CAAP;AACD;;AAED,SAASiB,iBAAT,
|
|
1
|
+
{"version":3,"names":["React","TextInput","splitCharacters","detectCharacter","mask","c","find","ch","includes","enhanceTextWithMask","text","previousValue","isBackSpace","length","splitCharacter","maskParts","split","textParts","finalString","maskPartIndex","partString","maskPart","textPart","maskDigitIndex","currentCharacter","undefined","character","push","join","lastPart","lastMaskPart","TextInputWithMask","ref","onChangeText","onChange","value","rest","controlledValue","setControlledValue","useState","onInnerChange","onInnerBlur","enhancedText","useEffect","e","forwardRef"],"sources":["TextInputMask.tsx"],"sourcesContent":["import * as React from 'react'\nimport { TextInput } from 'react-native-paper'\n\nconst splitCharacters = ['-', '/', '.', '年', ' ']\nfunction detectCharacter(mask: string): string {\n const c = splitCharacters.find((ch) => mask.includes(ch))\n return c || ''\n}\n\nfunction enhanceTextWithMask(\n text: string,\n mask: string,\n previousValue: string\n): string {\n const isBackSpace = previousValue.length > text.length\n const splitCharacter = detectCharacter(mask)\n\n const maskParts = mask.split(splitCharacter)\n const textParts = text.split(splitCharacter)\n\n let finalString: string[] = []\n for (let maskPartIndex = 0; maskPartIndex < mask.length; maskPartIndex++) {\n let partString: string[] = []\n\n const maskPart = maskParts[maskPartIndex]\n const textPart = textParts[maskPartIndex]\n if (!textPart) {\n continue\n }\n\n for (\n let maskDigitIndex = 0;\n maskDigitIndex < maskPart.length;\n maskDigitIndex++\n ) {\n const currentCharacter = textPart[maskDigitIndex]\n\n if (isBackSpace && currentCharacter === undefined) {\n continue\n }\n\n const character = textPart[maskDigitIndex]\n\n if (character !== undefined) {\n partString.push(character)\n }\n }\n\n finalString.push(partString.join(''))\n }\n\n const lastPart = finalString[finalString.length - 1]\n const lastMaskPart = maskParts[finalString.length - 1]\n if (\n // if mask is completed\n finalString.length !== maskParts.length &&\n // or ...\n lastPart &&\n lastMaskPart &&\n lastPart.length === lastMaskPart.length\n ) {\n return (\n finalString.join(splitCharacter) + (isBackSpace ? '' : splitCharacter)\n )\n }\n return finalString.join(splitCharacter)\n}\n\nfunction TextInputWithMask(\n {\n onChangeText,\n onChange,\n value,\n mask,\n ...rest\n }: React.ComponentProps<typeof TextInput> & { mask: string; value: string },\n ref: any\n) {\n const [controlledValue, setControlledValue] = React.useState<string>(\n value || ''\n )\n\n const onInnerChange = (text: string) => {\n if (text.length === mask.length) {\n onChangeText && onChangeText(text)\n }\n setControlledValue(text)\n }\n\n const onInnerBlur = () => {\n const enhancedText = enhanceTextWithMask(value, mask, controlledValue)\n setControlledValue(enhancedText)\n }\n\n React.useEffect(() => {\n setControlledValue(value || '')\n }, [value])\n\n return (\n <TextInput\n ref={ref}\n {...rest}\n value={controlledValue}\n onChangeText={onInnerChange}\n onChange={(e) => {\n onChange && onChange(e)\n }}\n onBlur={onInnerBlur}\n />\n )\n}\n\nexport default React.forwardRef(TextInputWithMask)\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA,MAAMC,eAAe,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,GAArB,CAAxB;;AACA,SAASC,eAAT,CAAyBC,IAAzB,EAA+C;EAC7C,MAAMC,CAAC,GAAGH,eAAe,CAACI,IAAhB,CAAsBC,EAAD,IAAQH,IAAI,CAACI,QAAL,CAAcD,EAAd,CAA7B,CAAV;EACA,OAAOF,CAAC,IAAI,E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IA,QAAQ,CAACU,CAAD,CAApB;IACD,CAPH;IAQE,MAAM,EAAEH;EARV,GADF;AAYD;;AAED,4BAAezC,KAAK,CAAC6C,UAAN,CAAiBd,iBAAjB,CAAf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { DatePickerInputProps } from './DatePickerInput.shared';
|
|
3
|
-
declare const _default: React.ForwardRefExoticComponent<Pick<DatePickerInputProps, "label" | "style" | "children" | "pointerEvents" | "allowFontScaling" | "numberOfLines" | "onLayout" | "onPressIn" | "onPressOut" | "testID" | "nativeID" | "maxFontSizeMultiplier" | "disabled" | "selectionColor" | "textBreakStrategy" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLabelledBy" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityLanguage" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "left" | "right" | "key" | "hitSlop" | "removeClippedSubviews" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerUp" | "onPointerUpCapture" | "value" | "mode" | "error" | "placeholder" | "onFocus" | "onBlur" | "onChange" | "onKeyPress" | "onScroll" | "defaultValue" | "spellCheck" | "autoCapitalize" | "autoCorrect" | "autoFocus" | "autoComplete" | "maxLength" | "textAlign" | "textAlignVertical" | "multiline" | "onContentSizeChange" | "scrollEnabled" | "textColor" | "dense" | "render" | "blurOnSubmit" | "caretHidden" | "contextMenuHidden" | "editable" | "keyboardType" | "onEndEditing" | "onSelectionChange" | "onSubmitEditing" | "onTextInput" | "placeholderTextColor" | "returnKeyType" | "secureTextEntry" | "selectTextOnFocus" | "selection" | "inputAccessoryViewID" | "clearButtonMode" | "clearTextOnFocus" | "dataDetectorTypes" | "enablesReturnKeyAutomatically" | "keyboardAppearance" | "passwordRules" | "rejectResponderTermination" | "selectionState" | "textContentType" | "cursorColor" | "importantForAutofill" | "disableFullscreenUI" | "inlineImageLeft" | "inlineImagePadding" | "returnKeyLabel" | "underlineColorAndroid" | "showSoftInputOnFocus" | "underlineColor" | "activeUnderlineColor" | "outlineColor" | "activeOutlineColor" | "outlineStyle" | "underlineStyle" | "theme" | "locale" | "validRange" | "calendarIcon" | "inputMode" | "saveLabel" | "withDateFormatInLabel" | "withModal"> & React.RefAttributes<unknown>>;
|
|
3
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<DatePickerInputProps, "label" | "style" | "children" | "pointerEvents" | "allowFontScaling" | "numberOfLines" | "onLayout" | "onPressIn" | "onPressOut" | "testID" | "nativeID" | "maxFontSizeMultiplier" | "disabled" | "selectionColor" | "textBreakStrategy" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLabelledBy" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityLanguage" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "left" | "right" | "key" | "hitSlop" | "removeClippedSubviews" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerUp" | "onPointerUpCapture" | "value" | "mode" | "error" | "placeholder" | "onFocus" | "onBlur" | "onChange" | "onKeyPress" | "onScroll" | "defaultValue" | "spellCheck" | "autoCapitalize" | "autoCorrect" | "autoFocus" | "autoComplete" | "maxLength" | "textAlign" | "textAlignVertical" | "multiline" | "onContentSizeChange" | "scrollEnabled" | "textColor" | "dense" | "render" | "blurOnSubmit" | "caretHidden" | "contextMenuHidden" | "editable" | "keyboardType" | "onChangeText" | "onEndEditing" | "onSelectionChange" | "onSubmitEditing" | "onTextInput" | "placeholderTextColor" | "returnKeyType" | "secureTextEntry" | "selectTextOnFocus" | "selection" | "inputAccessoryViewID" | "clearButtonMode" | "clearTextOnFocus" | "dataDetectorTypes" | "enablesReturnKeyAutomatically" | "keyboardAppearance" | "passwordRules" | "rejectResponderTermination" | "selectionState" | "textContentType" | "cursorColor" | "importantForAutofill" | "disableFullscreenUI" | "inlineImageLeft" | "inlineImagePadding" | "returnKeyLabel" | "underlineColorAndroid" | "showSoftInputOnFocus" | "underlineColor" | "activeUnderlineColor" | "outlineColor" | "activeOutlineColor" | "outlineStyle" | "underlineStyle" | "theme" | "locale" | "uppercase" | "validRange" | "startYear" | "endYear" | "calendarIcon" | "inputMode" | "onValidationError" | "saveLabel" | "saveLabelDisabled" | "withDateFormatInLabel" | "hasError" | "hideValidationErrors" | "withModal"> & React.RefAttributes<unknown>>;
|
|
4
4
|
export default _default;
|
|
@@ -9,6 +9,14 @@ export type DatePickerInputProps = {
|
|
|
9
9
|
validRange?: ValidRangeType | undefined;
|
|
10
10
|
withModal?: boolean;
|
|
11
11
|
withDateFormatInLabel?: boolean;
|
|
12
|
+
hideValidationErrors?: boolean;
|
|
13
|
+
hasError?: boolean;
|
|
14
|
+
onValidationError?: ((error: string | null) => void) | undefined;
|
|
12
15
|
calendarIcon?: string;
|
|
13
16
|
saveLabel?: string;
|
|
17
|
+
saveLabelDisabled?: boolean;
|
|
18
|
+
uppercase?: boolean;
|
|
19
|
+
startYear?: number;
|
|
20
|
+
endYear?: number;
|
|
21
|
+
onChangeText?: (text: string | undefined) => void;
|
|
14
22
|
} & Omit<React.ComponentProps<typeof TextInput>, 'value' | 'onChange' | 'onChangeText'>;
|
|
@@ -7,8 +7,16 @@ declare const _default: React.ForwardRefExoticComponent<Pick<{
|
|
|
7
7
|
validRange?: import("./Calendar").ValidRangeType | undefined;
|
|
8
8
|
withModal?: boolean | undefined;
|
|
9
9
|
withDateFormatInLabel?: boolean | undefined;
|
|
10
|
+
hideValidationErrors?: boolean | undefined;
|
|
11
|
+
hasError?: boolean | undefined;
|
|
12
|
+
onValidationError?: ((error: string | null) => void) | undefined;
|
|
10
13
|
calendarIcon?: string | undefined;
|
|
11
14
|
saveLabel?: string | undefined;
|
|
15
|
+
saveLabelDisabled?: boolean | undefined;
|
|
16
|
+
uppercase?: boolean | undefined;
|
|
17
|
+
startYear?: number | undefined;
|
|
18
|
+
endYear?: number | undefined;
|
|
19
|
+
onChangeText?: ((text: string | undefined) => void) | undefined;
|
|
12
20
|
} & Omit<Pick<import("react-native").TextInputProps & React.RefAttributes<import("react-native").TextInput> & {
|
|
13
21
|
mode?: "flat" | "outlined" | undefined;
|
|
14
22
|
left?: React.ReactNode;
|
|
@@ -51,7 +59,11 @@ declare const _default: React.ForwardRefExoticComponent<Pick<{
|
|
|
51
59
|
inputMode: "end" | "start";
|
|
52
60
|
validRange: import("./Calendar").ValidRangeType | undefined;
|
|
53
61
|
saveLabel: string | undefined;
|
|
62
|
+
saveLabelDisabled: boolean | undefined;
|
|
63
|
+
uppercase: boolean | undefined;
|
|
64
|
+
startYear: number | undefined;
|
|
65
|
+
endYear: number | undefined;
|
|
54
66
|
}) => any) | undefined;
|
|
55
67
|
inputButtons?: any;
|
|
56
|
-
}, "label" | "style" | "children" | "pointerEvents" | "allowFontScaling" | "numberOfLines" | "onLayout" | "onPressIn" | "onPressOut" | "testID" | "nativeID" | "maxFontSizeMultiplier" | "disabled" | "selectionColor" | "textBreakStrategy" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLabelledBy" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityLanguage" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "left" | "right" | "key" | "hitSlop" | "removeClippedSubviews" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerUp" | "onPointerUpCapture" | "value" | "mode" | "error" | "placeholder" | "onFocus" | "onBlur" | "onChange" | "onKeyPress" | "onScroll" | "defaultValue" | "spellCheck" | "autoCapitalize" | "autoCorrect" | "autoFocus" | "autoComplete" | "maxLength" | "textAlign" | "textAlignVertical" | "multiline" | "onContentSizeChange" | "scrollEnabled" | "textColor" | "dense" | "render" | "blurOnSubmit" | "caretHidden" | "contextMenuHidden" | "editable" | "keyboardType" | "onEndEditing" | "onSelectionChange" | "onSubmitEditing" | "onTextInput" | "placeholderTextColor" | "returnKeyType" | "secureTextEntry" | "selectTextOnFocus" | "selection" | "inputAccessoryViewID" | "clearButtonMode" | "clearTextOnFocus" | "dataDetectorTypes" | "enablesReturnKeyAutomatically" | "keyboardAppearance" | "passwordRules" | "rejectResponderTermination" | "selectionState" | "textContentType" | "cursorColor" | "importantForAutofill" | "disableFullscreenUI" | "inlineImageLeft" | "inlineImagePadding" | "returnKeyLabel" | "underlineColorAndroid" | "showSoftInputOnFocus" | "underlineColor" | "activeUnderlineColor" | "outlineColor" | "activeOutlineColor" | "outlineStyle" | "underlineStyle" | "theme" | "locale" | "validRange" | "calendarIcon" | "inputMode" | "saveLabel" | "withDateFormatInLabel" | "modal" | "inputButtons" | "withModal"> & React.RefAttributes<unknown>>;
|
|
68
|
+
}, "label" | "style" | "children" | "pointerEvents" | "allowFontScaling" | "numberOfLines" | "onLayout" | "onPressIn" | "onPressOut" | "testID" | "nativeID" | "maxFontSizeMultiplier" | "disabled" | "selectionColor" | "textBreakStrategy" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLabelledBy" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityLanguage" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "left" | "right" | "key" | "hitSlop" | "removeClippedSubviews" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerUp" | "onPointerUpCapture" | "value" | "mode" | "error" | "placeholder" | "onFocus" | "onBlur" | "onChange" | "onKeyPress" | "onScroll" | "defaultValue" | "spellCheck" | "autoCapitalize" | "autoCorrect" | "autoFocus" | "autoComplete" | "maxLength" | "textAlign" | "textAlignVertical" | "multiline" | "onContentSizeChange" | "scrollEnabled" | "textColor" | "dense" | "render" | "blurOnSubmit" | "caretHidden" | "contextMenuHidden" | "editable" | "keyboardType" | "onChangeText" | "onEndEditing" | "onSelectionChange" | "onSubmitEditing" | "onTextInput" | "placeholderTextColor" | "returnKeyType" | "secureTextEntry" | "selectTextOnFocus" | "selection" | "inputAccessoryViewID" | "clearButtonMode" | "clearTextOnFocus" | "dataDetectorTypes" | "enablesReturnKeyAutomatically" | "keyboardAppearance" | "passwordRules" | "rejectResponderTermination" | "selectionState" | "textContentType" | "cursorColor" | "importantForAutofill" | "disableFullscreenUI" | "inlineImageLeft" | "inlineImagePadding" | "returnKeyLabel" | "underlineColorAndroid" | "showSoftInputOnFocus" | "underlineColor" | "activeUnderlineColor" | "outlineColor" | "activeOutlineColor" | "outlineStyle" | "underlineStyle" | "theme" | "locale" | "uppercase" | "validRange" | "startYear" | "endYear" | "calendarIcon" | "inputMode" | "onValidationError" | "saveLabel" | "saveLabelDisabled" | "withDateFormatInLabel" | "hasError" | "hideValidationErrors" | "modal" | "inputButtons" | "withModal"> & React.RefAttributes<unknown>>;
|
|
57
69
|
export default _default;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ValidRangeType } from './Calendar';
|
|
2
|
-
export default function useDateInput({ locale, value, validRange, inputMode, onChange, }: {
|
|
2
|
+
export default function useDateInput({ locale, value, validRange, inputMode, onChange, onValidationError, }: {
|
|
3
3
|
onChange: (d: Date) => void;
|
|
4
4
|
locale: undefined | string;
|
|
5
5
|
value: Date | undefined;
|
|
6
6
|
validRange: ValidRangeType | undefined;
|
|
7
7
|
inputMode: 'start' | 'end';
|
|
8
|
+
onValidationError?: ((error: string | null) => void) | undefined;
|
|
8
9
|
}): {
|
|
9
10
|
onChange: (d: Date) => void;
|
|
10
11
|
error: string | null;
|
package/package.json
CHANGED
|
@@ -10,8 +10,16 @@ export type DatePickerInputProps = {
|
|
|
10
10
|
validRange?: ValidRangeType | undefined
|
|
11
11
|
withModal?: boolean
|
|
12
12
|
withDateFormatInLabel?: boolean
|
|
13
|
+
hideValidationErrors?: boolean
|
|
14
|
+
hasError?: boolean
|
|
15
|
+
onValidationError?: ((error: string | null) => void) | undefined
|
|
13
16
|
calendarIcon?: string
|
|
14
17
|
saveLabel?: string
|
|
18
|
+
saveLabelDisabled?: boolean
|
|
19
|
+
uppercase?: boolean
|
|
20
|
+
startYear?: number
|
|
21
|
+
endYear?: number
|
|
22
|
+
onChangeText?: (text: string | undefined) => void
|
|
15
23
|
} & Omit<
|
|
16
24
|
React.ComponentProps<typeof TextInput>,
|
|
17
25
|
'value' | 'onChange' | 'onChangeText'
|
|
@@ -42,7 +42,18 @@ function DatePickerInput(
|
|
|
42
42
|
/>
|
|
43
43
|
) : null
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
46
|
+
modal={({
|
|
47
|
+
value,
|
|
48
|
+
locale,
|
|
49
|
+
inputMode,
|
|
50
|
+
validRange,
|
|
51
|
+
saveLabel,
|
|
52
|
+
saveLabelDisabled,
|
|
53
|
+
uppercase,
|
|
54
|
+
startYear,
|
|
55
|
+
endYear,
|
|
56
|
+
}) =>
|
|
46
57
|
withModal ? (
|
|
47
58
|
<DatePickerModal
|
|
48
59
|
date={value}
|
|
@@ -54,6 +65,10 @@ function DatePickerInput(
|
|
|
54
65
|
dateMode={inputMode}
|
|
55
66
|
validRange={validRange}
|
|
56
67
|
saveLabel={saveLabel}
|
|
68
|
+
saveLabelDisabled={saveLabelDisabled ?? false}
|
|
69
|
+
uppercase={uppercase ?? true}
|
|
70
|
+
startYear={startYear ?? 1800}
|
|
71
|
+
endYear={endYear ?? 2200}
|
|
57
72
|
/>
|
|
58
73
|
) : null
|
|
59
74
|
}
|
|
@@ -16,9 +16,17 @@ function DatePickerInputWithoutModal(
|
|
|
16
16
|
validRange,
|
|
17
17
|
inputMode,
|
|
18
18
|
withDateFormatInLabel = true,
|
|
19
|
+
hasError,
|
|
20
|
+
hideValidationErrors,
|
|
21
|
+
onValidationError,
|
|
19
22
|
modal,
|
|
20
23
|
inputButtons,
|
|
21
24
|
saveLabel,
|
|
25
|
+
saveLabelDisabled,
|
|
26
|
+
uppercase,
|
|
27
|
+
startYear,
|
|
28
|
+
endYear,
|
|
29
|
+
onChangeText,
|
|
22
30
|
...rest
|
|
23
31
|
}: DatePickerInputProps & {
|
|
24
32
|
modal?: (params: {
|
|
@@ -27,18 +35,28 @@ function DatePickerInputWithoutModal(
|
|
|
27
35
|
inputMode: DatePickerInputProps['inputMode']
|
|
28
36
|
validRange: DatePickerInputProps['validRange']
|
|
29
37
|
saveLabel: DatePickerInputProps['saveLabel']
|
|
38
|
+
saveLabelDisabled: DatePickerInputProps['saveLabelDisabled']
|
|
39
|
+
uppercase: DatePickerInputProps['uppercase']
|
|
40
|
+
startYear: DatePickerInputProps['startYear']
|
|
41
|
+
endYear: DatePickerInputProps['endYear']
|
|
30
42
|
}) => any
|
|
31
43
|
inputButtons?: any
|
|
32
44
|
},
|
|
33
45
|
ref: any
|
|
34
46
|
) {
|
|
35
47
|
const theme = useTheme()
|
|
36
|
-
const {
|
|
48
|
+
const {
|
|
49
|
+
formattedValue,
|
|
50
|
+
inputFormat,
|
|
51
|
+
onChangeText: onDateInputChangeText,
|
|
52
|
+
error,
|
|
53
|
+
} = useDateInput({
|
|
37
54
|
locale,
|
|
38
55
|
value,
|
|
39
56
|
validRange,
|
|
40
57
|
inputMode,
|
|
41
58
|
onChange,
|
|
59
|
+
onValidationError,
|
|
42
60
|
})
|
|
43
61
|
|
|
44
62
|
return (
|
|
@@ -55,23 +73,33 @@ function DatePickerInputWithoutModal(
|
|
|
55
73
|
withDateFormatInLabel,
|
|
56
74
|
})}
|
|
57
75
|
value={formattedValue}
|
|
58
|
-
keyboardType={'number-pad'}
|
|
59
|
-
placeholder={inputFormat}
|
|
76
|
+
keyboardType={rest.keyboardType ?? 'number-pad'}
|
|
60
77
|
mask={inputFormat}
|
|
61
|
-
onChangeText={
|
|
78
|
+
onChangeText={onDateInputChangeText}
|
|
79
|
+
onChange={(e) => onChangeText && onChangeText(e.nativeEvent.text)}
|
|
62
80
|
keyboardAppearance={theme.dark ? 'dark' : 'default'}
|
|
63
|
-
error={!!error}
|
|
81
|
+
error={(!!error && !hideValidationErrors) || !!hasError}
|
|
64
82
|
style={[styles.input, style]}
|
|
65
83
|
/>
|
|
66
84
|
{inputButtons}
|
|
67
85
|
</View>
|
|
68
|
-
{error ? (
|
|
69
|
-
<HelperText
|
|
86
|
+
{error && !hideValidationErrors ? (
|
|
87
|
+
<HelperText type="error" visible={!!error}>
|
|
70
88
|
{error}
|
|
71
89
|
</HelperText>
|
|
72
90
|
) : null}
|
|
73
91
|
</View>
|
|
74
|
-
{modal?.({
|
|
92
|
+
{modal?.({
|
|
93
|
+
value,
|
|
94
|
+
locale,
|
|
95
|
+
inputMode,
|
|
96
|
+
validRange,
|
|
97
|
+
saveLabel,
|
|
98
|
+
saveLabelDisabled,
|
|
99
|
+
uppercase,
|
|
100
|
+
startYear,
|
|
101
|
+
endYear,
|
|
102
|
+
})}
|
|
75
103
|
</>
|
|
76
104
|
)
|
|
77
105
|
}
|
|
@@ -104,8 +132,5 @@ const styles = StyleSheet.create({
|
|
|
104
132
|
input: {
|
|
105
133
|
flexGrow: 1,
|
|
106
134
|
},
|
|
107
|
-
helperText: {
|
|
108
|
-
// flex: 1,
|
|
109
|
-
},
|
|
110
135
|
})
|
|
111
136
|
export default React.forwardRef(DatePickerInputWithoutModal)
|
package/src/Date/inputUtils.ts
CHANGED
|
@@ -9,19 +9,21 @@ export default function useDateInput({
|
|
|
9
9
|
validRange,
|
|
10
10
|
inputMode,
|
|
11
11
|
onChange,
|
|
12
|
+
onValidationError,
|
|
12
13
|
}: {
|
|
13
14
|
onChange: (d: Date) => void
|
|
14
15
|
locale: undefined | string
|
|
15
16
|
value: Date | undefined
|
|
16
17
|
validRange: ValidRangeType | undefined
|
|
17
18
|
inputMode: 'start' | 'end'
|
|
19
|
+
onValidationError?: ((error: string | null) => void) | undefined
|
|
18
20
|
}) {
|
|
19
21
|
const { isDisabled, isWithinValidRange, validStart, validEnd } =
|
|
20
22
|
useRangeChecker(validRange)
|
|
21
23
|
const [error, setError] = React.useState<null | string>(null)
|
|
22
24
|
const formatter = useInputFormatter({ locale })
|
|
23
25
|
const inputFormat = useInputFormat({ formatter, locale })
|
|
24
|
-
const formattedValue = value
|
|
26
|
+
const formattedValue = value ? formatter.format(value) : ''
|
|
25
27
|
const onChangeText = (date: string) => {
|
|
26
28
|
const dayIndex = inputFormat.indexOf('DD')
|
|
27
29
|
const monthIndex = inputFormat.indexOf('MM')
|
|
@@ -35,13 +37,13 @@ export default function useDateInput({
|
|
|
35
37
|
const month = Number(date.slice(monthIndex, monthIndex + 2))
|
|
36
38
|
|
|
37
39
|
if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
40
|
+
const inputError = getTranslation(
|
|
41
|
+
locale,
|
|
42
|
+
'notAccordingToDateFormat',
|
|
43
|
+
() => 'notAccordingToDateFormat'
|
|
44
|
+
)(inputFormat)
|
|
45
|
+
setError(inputError)
|
|
46
|
+
onValidationError && onValidationError(inputError)
|
|
45
47
|
return
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -51,7 +53,9 @@ export default function useDateInput({
|
|
|
51
53
|
: new Date(year, month - 1, day)
|
|
52
54
|
|
|
53
55
|
if (isDisabled(finalDate)) {
|
|
54
|
-
|
|
56
|
+
const inputError = getTranslation(locale, 'dateIsDisabled')
|
|
57
|
+
setError(inputError)
|
|
58
|
+
onValidationError && onValidationError(inputError)
|
|
55
59
|
return
|
|
56
60
|
}
|
|
57
61
|
if (!isWithinValidRange(finalDate)) {
|
|
@@ -80,11 +84,14 @@ export default function useDateInput({
|
|
|
80
84
|
)(formatter.format(validEnd))
|
|
81
85
|
: '',
|
|
82
86
|
]
|
|
87
|
+
const inputError = errors.filter((n) => n).join(' ')
|
|
83
88
|
setError(errors.filter((n) => n).join(' '))
|
|
89
|
+
onValidationError && onValidationError(inputError)
|
|
84
90
|
return
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
setError(null)
|
|
94
|
+
onValidationError && onValidationError(null)
|
|
88
95
|
if (inputMode === 'end') {
|
|
89
96
|
onChange(finalDate)
|
|
90
97
|
} else {
|
package/src/TextInputMask.tsx
CHANGED
|
@@ -69,6 +69,7 @@ function enhanceTextWithMask(
|
|
|
69
69
|
function TextInputWithMask(
|
|
70
70
|
{
|
|
71
71
|
onChangeText,
|
|
72
|
+
onChange,
|
|
72
73
|
value,
|
|
73
74
|
mask,
|
|
74
75
|
...rest
|
|
@@ -101,6 +102,9 @@ function TextInputWithMask(
|
|
|
101
102
|
{...rest}
|
|
102
103
|
value={controlledValue}
|
|
103
104
|
onChangeText={onInnerChange}
|
|
105
|
+
onChange={(e) => {
|
|
106
|
+
onChange && onChange(e)
|
|
107
|
+
}}
|
|
104
108
|
onBlur={onInnerBlur}
|
|
105
109
|
/>
|
|
106
110
|
)
|