@jobber/components-native 0.45.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +2 -2
- package/dist/src/InputDate/InputDate.js +3 -8
- package/dist/src/InputTime/InputTime.js +3 -6
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.js +7 -3
- package/dist/src/hooks/useAtlantisI18n/utils/dateFormatter.js +20 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.d.ts +17 -0
- package/dist/types/src/hooks/useAtlantisI18n/utils/dateFormatter.d.ts +6 -0
- package/package.json +2 -2
- package/src/InputDate/InputDate.tsx +3 -8
- package/src/InputTime/InputTime.tsx +4 -7
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.test.ts +82 -2
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.ts +40 -4
- package/src/hooks/useAtlantisI18n/utils/dateFormatter.ts +31 -0
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react-native-reanimated": "^2.17.0",
|
|
85
85
|
"react-native-safe-area-context": "^4.5.2"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "6ff59b16b38fdf784fa15bcfa41eb97181d2f6b0"
|
|
88
88
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import React, { useMemo, useState } from "react";
|
|
2
2
|
import DateTimePicker from "react-native-modal-datetime-picker";
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
|
-
import { utcToZonedTime } from "date-fns-tz";
|
|
5
|
-
import { format as formatDate } from "date-fns";
|
|
6
4
|
import { FormField } from "../FormField";
|
|
7
5
|
import { InputPressable } from "../InputPressable";
|
|
8
|
-
import { useAtlantisContext } from "../AtlantisContext";
|
|
9
6
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
10
7
|
function formatInvalidState(error, invalid) {
|
|
11
8
|
if (invalid)
|
|
@@ -32,8 +29,7 @@ export function InputDate(props) {
|
|
|
32
29
|
}
|
|
33
30
|
function InternalInputDate({ clearable = "always", disabled, emptyValueLabel, invalid, maxDate, minDate, placeholder, value, name, onChange, accessibilityLabel, accessibilityHint, }) {
|
|
34
31
|
const [showPicker, setShowPicker] = useState(false);
|
|
35
|
-
const { t, locale } = useAtlantisI18n();
|
|
36
|
-
const { timeZone, dateFormat } = useAtlantisContext();
|
|
32
|
+
const { t, locale, formatDate } = useAtlantisI18n();
|
|
37
33
|
const date = useMemo(() => {
|
|
38
34
|
if (typeof value === "string")
|
|
39
35
|
return new Date(value);
|
|
@@ -41,11 +37,10 @@ function InternalInputDate({ clearable = "always", disabled, emptyValueLabel, in
|
|
|
41
37
|
}, [value]);
|
|
42
38
|
const formattedDate = useMemo(() => {
|
|
43
39
|
if (date) {
|
|
44
|
-
|
|
45
|
-
return formatDate(zonedTime, dateFormat);
|
|
40
|
+
return formatDate(date);
|
|
46
41
|
}
|
|
47
42
|
return emptyValueLabel;
|
|
48
|
-
}, [date, emptyValueLabel
|
|
43
|
+
}, [date, emptyValueLabel]);
|
|
49
44
|
const canClearDate = formattedDate === emptyValueLabel ? "never" : clearable;
|
|
50
45
|
const placeholderLabel = placeholder !== null && placeholder !== void 0 ? placeholder : t("date");
|
|
51
46
|
return (React.createElement(React.Fragment, null,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React, { useMemo, useState } from "react";
|
|
2
2
|
import DateTimePicker from "react-native-modal-datetime-picker";
|
|
3
3
|
import { View } from "react-native";
|
|
4
|
-
import { utcToZonedTime } from "date-fns-tz";
|
|
5
|
-
import { format as formatTime } from "date-fns";
|
|
6
4
|
import { styles } from "./InputTime.style";
|
|
7
5
|
import { getTimeZoneOffsetInMinutes, roundUpToNearestMinutes } from "./utils";
|
|
8
6
|
import { useAtlantisContext } from "../AtlantisContext";
|
|
@@ -32,17 +30,16 @@ export function InputTime(props) {
|
|
|
32
30
|
}
|
|
33
31
|
function InternalInputTime({ clearable = "always", disabled, emptyValueLabel, invalid, placeholder, value, name, type = "scheduling", onChange, showIcon = true, }) {
|
|
34
32
|
const [showPicker, setShowPicker] = useState(false);
|
|
35
|
-
const { t } = useAtlantisI18n();
|
|
33
|
+
const { t, formatTime } = useAtlantisI18n();
|
|
36
34
|
const { timeZone, timeFormat } = useAtlantisContext();
|
|
37
35
|
const is24Hour = timeFormat === "HH:mm";
|
|
38
36
|
const dateTime = useMemo(() => (typeof value === "string" ? new Date(value) : value), [value]);
|
|
39
37
|
const formattedTime = useMemo(() => {
|
|
40
38
|
if (dateTime) {
|
|
41
|
-
|
|
42
|
-
return formatTime(zonedTime, timeFormat);
|
|
39
|
+
return formatTime(dateTime);
|
|
43
40
|
}
|
|
44
41
|
return emptyValueLabel;
|
|
45
|
-
}, [dateTime, emptyValueLabel
|
|
42
|
+
}, [dateTime, emptyValueLabel]);
|
|
46
43
|
const canClearTime = formattedTime === emptyValueLabel ? "never" : clearable;
|
|
47
44
|
return (React.createElement(View, { style: styles.container },
|
|
48
45
|
React.createElement(InputPressable, { clearable: canClearTime, disabled: disabled, invalid: invalid, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t("time"), prefix: showIcon ? { icon: "timer" } : undefined, value: formattedTime, onClear: handleClear, onPress: showDatePicker }),
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
1
2
|
import en from "./locales/en.json";
|
|
2
3
|
import es from "./locales/es.json";
|
|
4
|
+
import { dateFormatter } from "./utils/dateFormatter";
|
|
3
5
|
import { useAtlantisContext } from "../../AtlantisContext";
|
|
4
6
|
export function useAtlantisI18n() {
|
|
5
|
-
const { locale } = useAtlantisContext();
|
|
6
|
-
const t = (messageKey, values) => formatMessage(messageKey, values, locale);
|
|
7
|
-
|
|
7
|
+
const { locale, dateFormat, timeFormat, timeZone } = useAtlantisContext();
|
|
8
|
+
const t = useCallback((messageKey, values) => formatMessage(messageKey, values, locale), [formatMessage, locale]);
|
|
9
|
+
const formatDate = useCallback((date) => dateFormatter(date, dateFormat, { locale, timeZone }), [dateFormatter, locale]);
|
|
10
|
+
const formatTime = useCallback((date) => dateFormatter(date, timeFormat, { locale, timeZone }), [dateFormatter, locale]);
|
|
11
|
+
return { locale, t, formatDate, formatTime };
|
|
8
12
|
}
|
|
9
13
|
function getLocalizedStrings(locale) {
|
|
10
14
|
switch (locale) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { format } from "date-fns";
|
|
2
|
+
import { utcToZonedTime } from "date-fns-tz";
|
|
3
|
+
import { es } from "date-fns/locale";
|
|
4
|
+
export function dateFormatter(date, dateTimeFormat, { locale, timeZone }) {
|
|
5
|
+
const zonedTime = utcToZonedTime(date, timeZone);
|
|
6
|
+
return format(zonedTime, dateTimeFormat, {
|
|
7
|
+
locale: getDateFnsLocale(locale),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Change locale string to date-fns locale object.
|
|
12
|
+
*/
|
|
13
|
+
function getDateFnsLocale(locale) {
|
|
14
|
+
switch (locale) {
|
|
15
|
+
case "es":
|
|
16
|
+
return es;
|
|
17
|
+
default:
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|