@jobber/components-native 0.45.1 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +2 -2
- package/dist/src/AtlantisContext/AtlantisContext.js +2 -2
- package/dist/src/Form/context/AtlantisFormContext.js +2 -2
- package/dist/src/InputDate/InputDate.js +3 -8
- package/dist/src/InputText/context/InputAccessoriesContext.js +2 -2
- 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/AtlantisContext/AtlantisContext.d.ts +1 -1
- package/dist/types/src/Form/context/AtlantisFormContext.d.ts +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/AtlantisContext/AtlantisContext.test.tsx +3 -2
- package/src/AtlantisContext/AtlantisContext.tsx +2 -2
- package/src/ButtonGroup/ButtonGroup.test.tsx +2 -2
- package/src/Form/Form.test.tsx +2 -2
- package/src/Form/components/FormErrorBanner/FormErrorBanner.test.tsx +2 -2
- package/src/Form/context/AtlantisFormContext.test.tsx +2 -3
- package/src/Form/context/AtlantisFormContext.tsx +4 -3
- package/src/InputCurrency/InputCurrency.test.tsx +2 -2
- package/src/InputDate/InputDate.test.tsx +4 -4
- package/src/InputDate/InputDate.tsx +3 -8
- package/src/InputText/context/InputAccessoriesContext.ts +4 -2
- package/src/InputTime/InputTime.test.tsx +3 -3
- package/src/InputTime/InputTime.tsx +4 -7
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.test.ts +105 -4
- 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.1",
|
|
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": "ebd19569f57d6c7ef08de4992894952452dfe583"
|
|
88
88
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import { createContext, useContext } from "react";
|
|
3
3
|
import { DEFAULT_CURRENCY_SYMBOL } from "../InputCurrency/constants";
|
|
4
|
-
export const
|
|
4
|
+
export const atlantisContextDefaultValues = {
|
|
5
5
|
dateFormat: "PP",
|
|
6
6
|
// The system time is "p"
|
|
7
7
|
timeFormat: "p",
|
|
@@ -18,7 +18,7 @@ export const defaultValues = {
|
|
|
18
18
|
return;
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
-
export const AtlantisContext = createContext(
|
|
21
|
+
export const AtlantisContext = createContext(atlantisContextDefaultValues);
|
|
22
22
|
export function useAtlantisContext() {
|
|
23
23
|
return useContext(AtlantisContext);
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext, useRef } from "react";
|
|
2
|
-
export const
|
|
2
|
+
export const atlantisFormContextDefaultValues = {
|
|
3
3
|
useConfirmBeforeBack: () => {
|
|
4
4
|
const ref = useRef(() => undefined);
|
|
5
5
|
return ref;
|
|
@@ -9,7 +9,7 @@ export const defaultValues = {
|
|
|
9
9
|
removeLocalCache: () => undefined,
|
|
10
10
|
}),
|
|
11
11
|
};
|
|
12
|
-
export const AtlantisFormContext = createContext(
|
|
12
|
+
export const AtlantisFormContext = createContext(atlantisFormContextDefaultValues);
|
|
13
13
|
export function useAtlantisFormContext() {
|
|
14
14
|
return useContext(AtlantisFormContext);
|
|
15
15
|
}
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
-
const
|
|
2
|
+
const inputAccessoriesContextDefaultValues = {
|
|
3
3
|
elements: {},
|
|
4
4
|
focusedInput: "",
|
|
5
5
|
canFocusNext: false,
|
|
@@ -11,7 +11,7 @@ const defaultValues = {
|
|
|
11
11
|
onFocusPrevious: () => undefined,
|
|
12
12
|
setFocusedInput: () => undefined,
|
|
13
13
|
};
|
|
14
|
-
export const InputAccessoriesContext = createContext(
|
|
14
|
+
export const InputAccessoriesContext = createContext(inputAccessoriesContextDefaultValues);
|
|
15
15
|
export function useInputAccessoriesContext() {
|
|
16
16
|
return useContext(InputAccessoriesContext);
|
|
17
17
|
}
|
|
@@ -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
|
+
}
|