ferns-ui 0.44.2 → 0.45.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/Common.d.ts +16 -0
- package/dist/DateTimeActionSheet.d.ts +1 -1
- package/dist/DateTimeActionSheet.js +130 -95
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.android.d.ts +1 -1
- package/dist/DateTimeField.android.js +20 -20
- package/dist/DateTimeField.android.js.map +1 -1
- package/dist/DateTimeField.ios.d.ts +1 -1
- package/dist/DateTimeField.ios.js +21 -21
- package/dist/DateTimeField.ios.js.map +1 -1
- package/dist/DateUtilities.d.ts +50 -0
- package/dist/DateUtilities.js +240 -0
- package/dist/DateUtilities.js.map +1 -0
- package/dist/DateUtilities.test.d.ts +1 -0
- package/dist/DateUtilities.test.js +270 -0
- package/dist/DateUtilities.test.js.map +1 -0
- package/dist/Field.d.ts +1 -1
- package/dist/Field.js +2 -2
- package/dist/Field.js.map +1 -1
- package/dist/TextField.d.ts +1 -1
- package/dist/TextField.js +36 -34
- package/dist/TextField.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +1 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/TimezonePicker.d.ts +3 -0
- package/dist/TimezonePicker.js +26 -0
- package/dist/TimezonePicker.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/setupTests.d.ts +0 -0
- package/dist/setupTests.js +3 -0
- package/dist/setupTests.js.map +1 -0
- package/package.json +37 -54
- package/src/Common.ts +19 -0
- package/src/DateTimeActionSheet.tsx +178 -119
- package/src/DateTimeField.android.tsx +18 -17
- package/src/DateTimeField.ios.tsx +19 -18
- package/src/DateUtilities.test.ts +417 -0
- package/src/DateUtilities.tsx +296 -0
- package/src/Field.tsx +2 -0
- package/src/TextField.tsx +34 -31
- package/src/TextFieldNumberActionSheet.tsx +1 -2
- package/src/TimezonePicker.tsx +52 -0
- package/src/index.tsx +1 -0
- package/src/setupTests.ts +1 -0
- package/dist/dayjsExtended.d.ts +0 -2
- package/dist/dayjsExtended.js +0 -10
- package/dist/dayjsExtended.js.map +0 -1
- package/src/dayjsExtended.ts +0 -11
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {DateTime} from "luxon";
|
|
2
|
+
|
|
3
|
+
function getDate(date: string, {timezone}: {timezone?: string} = {}): DateTime {
|
|
4
|
+
if (!date) {
|
|
5
|
+
throw new Error("Passed undefined");
|
|
6
|
+
}
|
|
7
|
+
if (typeof (date as any) !== "string") {
|
|
8
|
+
throw new Error(`Invalid date type: ${typeof date}`);
|
|
9
|
+
}
|
|
10
|
+
const clonedDate = timezone ? DateTime.fromISO(date).setZone(timezone) : DateTime.fromISO(date);
|
|
11
|
+
if (!clonedDate.isValid) {
|
|
12
|
+
throw new Error(`Invalid date: ${date}`);
|
|
13
|
+
}
|
|
14
|
+
return clonedDate;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isTomorrow(date: string, {timezone}: {timezone?: string} = {}): boolean {
|
|
18
|
+
const clonedDate = getDate(date, {timezone});
|
|
19
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
20
|
+
const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
|
|
21
|
+
return diff.days <= -1 && diff.days > -2;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isYesterday(date: string, {timezone}: {timezone?: string} = {}): boolean {
|
|
25
|
+
const clonedDate = getDate(date, {timezone});
|
|
26
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
27
|
+
const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
|
|
28
|
+
return diff.days <= 1 && diff.days > -1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isToday(date: string, {timezone}: {timezone?: string} = {}): boolean {
|
|
32
|
+
const clonedDate = getDate(date, {timezone});
|
|
33
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
34
|
+
const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
|
|
35
|
+
return diff.days === 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isThisYear(date: string, {timezone}: {timezone?: string} = {}): boolean {
|
|
39
|
+
const clonedDate = getDate(date, {timezone});
|
|
40
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
41
|
+
return clonedDate.year === now.year;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isWithinWeek(date: string, {timezone}: {timezone?: string} = {}): boolean {
|
|
45
|
+
const clonedDate = getDate(date, {timezone});
|
|
46
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
47
|
+
const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
|
|
48
|
+
return diff.days > -7 && diff.days < 7;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Prints a human friendly date, e.g. "Tomorrow", "Yesterday", "Monday", "June 19", "December 25,
|
|
52
|
+
// 2022".
|
|
53
|
+
export function humanDate(
|
|
54
|
+
date: string,
|
|
55
|
+
{timezone, dontShowTime}: {timezone?: string; dontShowTime?: boolean} = {}
|
|
56
|
+
): string {
|
|
57
|
+
let clonedDate;
|
|
58
|
+
try {
|
|
59
|
+
clonedDate = getDate(date, {timezone});
|
|
60
|
+
} catch (error: any) {
|
|
61
|
+
throw new Error(`humanDate: ${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
if (isTomorrow(date, {timezone})) {
|
|
64
|
+
return "Tomorrow";
|
|
65
|
+
} else if (isToday(date, {timezone})) {
|
|
66
|
+
if (dontShowTime) {
|
|
67
|
+
return "Today";
|
|
68
|
+
} else {
|
|
69
|
+
return clonedDate.toFormat("h:mm a");
|
|
70
|
+
}
|
|
71
|
+
} else if (isYesterday(date, {timezone})) {
|
|
72
|
+
return "Yesterday";
|
|
73
|
+
} else if (isWithinWeek(date, {timezone})) {
|
|
74
|
+
// E.g. Monday
|
|
75
|
+
return clonedDate.toFormat("EEEE");
|
|
76
|
+
} else if (isThisYear(date, {timezone})) {
|
|
77
|
+
// E.g. June 19
|
|
78
|
+
return clonedDate.toFormat("MMM d");
|
|
79
|
+
} else {
|
|
80
|
+
// December 25, 2022
|
|
81
|
+
return clonedDate.toFormat("MMM d, iiii");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Prints a human friendly date and time, e.g. "Tomorrow 9:00 AM", "Yesterday 9:00 AM", "Monday
|
|
86
|
+
// 9:00 AM", "June 19 9:00 AM", "December 25, 2022 9:00 AM".
|
|
87
|
+
export function humanDateAndTime(
|
|
88
|
+
date: string,
|
|
89
|
+
{timezone, showTimezone = true}: {timezone?: string; showTimezone?: boolean} = {}
|
|
90
|
+
): string {
|
|
91
|
+
let clonedDate;
|
|
92
|
+
try {
|
|
93
|
+
clonedDate = getDate(date, {timezone});
|
|
94
|
+
} catch (error: any) {
|
|
95
|
+
throw new Error(`humanDateAndTime: ${error.message}`);
|
|
96
|
+
}
|
|
97
|
+
// This should maybe use printTime()
|
|
98
|
+
let time = clonedDate.toFormat("h:mm a");
|
|
99
|
+
if (showTimezone) {
|
|
100
|
+
time += ` ${clonedDate.offsetNameShort}`;
|
|
101
|
+
}
|
|
102
|
+
if (isTomorrow(date, {timezone})) {
|
|
103
|
+
return `Tomorrow ${time}`;
|
|
104
|
+
} else if (isToday(date, {timezone})) {
|
|
105
|
+
return time;
|
|
106
|
+
} else if (isYesterday(date, {timezone})) {
|
|
107
|
+
return `Yesterday ${time}`;
|
|
108
|
+
} else if (isWithinWeek(date, {timezone})) {
|
|
109
|
+
// E.g. Monday 9:00 AM
|
|
110
|
+
return `${clonedDate.toFormat("EEEE")} ${time}`;
|
|
111
|
+
} else if (isThisYear(date, {timezone})) {
|
|
112
|
+
// E.g. June 19
|
|
113
|
+
return `${clonedDate.toFormat("MMM d")} ${time}`;
|
|
114
|
+
} else {
|
|
115
|
+
// December 25, 2022
|
|
116
|
+
return `${clonedDate.toFormat("MMM d, iiii")} ${time}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Print date in the format of M/D/YY, taking timezones into account.
|
|
121
|
+
export const printDate = (
|
|
122
|
+
date?: string,
|
|
123
|
+
{
|
|
124
|
+
timezone,
|
|
125
|
+
showTimezone,
|
|
126
|
+
ignoreTime,
|
|
127
|
+
defaultValue,
|
|
128
|
+
}: {
|
|
129
|
+
timezone?: string;
|
|
130
|
+
showTimezone?: boolean;
|
|
131
|
+
// Ignore the time in the date, treat as a date in timezone.
|
|
132
|
+
// Will log a warning if the time is not set to midnight UTC.
|
|
133
|
+
ignoreTime?: boolean;
|
|
134
|
+
defaultValue?: string;
|
|
135
|
+
} = {}
|
|
136
|
+
): string => {
|
|
137
|
+
if (!date) {
|
|
138
|
+
return defaultValue ?? "Invalid Date";
|
|
139
|
+
}
|
|
140
|
+
if (showTimezone) {
|
|
141
|
+
console.warn("showTimezone is not supported for printDate");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let clonedDate;
|
|
145
|
+
try {
|
|
146
|
+
clonedDate = getDate(date!, {timezone});
|
|
147
|
+
} catch (error: any) {
|
|
148
|
+
throw new Error(`printDate: ${error.message}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (ignoreTime) {
|
|
152
|
+
if (!date) {
|
|
153
|
+
throw new Error("printDate: Passed undefined");
|
|
154
|
+
}
|
|
155
|
+
// Use only the date component, ignore the time.
|
|
156
|
+
const justDate = DateTime.fromISO(date);
|
|
157
|
+
// We force it into UTC so we can get the correct date.
|
|
158
|
+
return justDate.setZone("UTC").toFormat("M/d/yyyy");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return clonedDate.toLocaleString(DateTime.DATE_SHORT);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// For printing dates from date times, ignoring the time. These should end in T00:00:00.000Z.
|
|
165
|
+
// For example, the dates returned by Field type="date".
|
|
166
|
+
export const printOnlyDate = (
|
|
167
|
+
date?: string,
|
|
168
|
+
{
|
|
169
|
+
defaultValue,
|
|
170
|
+
}: {
|
|
171
|
+
defaultValue?: string;
|
|
172
|
+
} = {}
|
|
173
|
+
): string => {
|
|
174
|
+
if (!date) {
|
|
175
|
+
return defaultValue ?? "Invalid Date";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!date?.endsWith("T00:00:00.000Z")) {
|
|
179
|
+
console.warn(
|
|
180
|
+
"printOnlyDate, but the time is not set to midnight UTC. " +
|
|
181
|
+
"This may cause unexpected behavior."
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
// Use only the date component, ignore the time.
|
|
185
|
+
const justDate = DateTime.fromISO(date, {zone: "UTC"});
|
|
186
|
+
// We force it into UTC so we can get the correct date.
|
|
187
|
+
return justDate.toFormat("M/d/yyyy");
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Print time in the format of HH:mm A, taking timezones into account.
|
|
191
|
+
export function printTime(
|
|
192
|
+
date?: string,
|
|
193
|
+
{
|
|
194
|
+
timezone,
|
|
195
|
+
showTimezone,
|
|
196
|
+
defaultValue,
|
|
197
|
+
}: {
|
|
198
|
+
timezone: string;
|
|
199
|
+
showTimezone?: boolean;
|
|
200
|
+
defaultValue?: string;
|
|
201
|
+
} = {timezone: "America/New_York", defaultValue: "Invalid Date"}
|
|
202
|
+
): string {
|
|
203
|
+
if (!date) {
|
|
204
|
+
return defaultValue ?? "Invalid Date";
|
|
205
|
+
}
|
|
206
|
+
let clonedDate;
|
|
207
|
+
if (!timezone) {
|
|
208
|
+
throw new Error("printTime: timezone is required");
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
clonedDate = getDate(date, {timezone});
|
|
212
|
+
} catch (error: any) {
|
|
213
|
+
throw new Error(`printTime: ${error.message}`);
|
|
214
|
+
}
|
|
215
|
+
if (showTimezone) {
|
|
216
|
+
return clonedDate.toFormat("h:mm a ZZZZ");
|
|
217
|
+
} else {
|
|
218
|
+
return clonedDate.toLocaleString(DateTime.TIME_SIMPLE);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Print date in the format of M/D/YY HH:mm A, taking timezones into account.
|
|
223
|
+
export function printDateAndTime(
|
|
224
|
+
date?: string,
|
|
225
|
+
{
|
|
226
|
+
timezone,
|
|
227
|
+
showTimezone,
|
|
228
|
+
defaultValue,
|
|
229
|
+
}: {
|
|
230
|
+
timezone?: string;
|
|
231
|
+
showTimezone?: boolean;
|
|
232
|
+
defaultValue?: string;
|
|
233
|
+
} = {}
|
|
234
|
+
): string {
|
|
235
|
+
if (!date) {
|
|
236
|
+
return defaultValue ?? "Invalid Datetime";
|
|
237
|
+
}
|
|
238
|
+
let clonedDate;
|
|
239
|
+
try {
|
|
240
|
+
clonedDate = getDate(date, {timezone});
|
|
241
|
+
} catch (error: any) {
|
|
242
|
+
throw new Error(`printDateAndTime: ${error.message}`);
|
|
243
|
+
}
|
|
244
|
+
let dateString = clonedDate.toLocaleString(DateTime.DATETIME_SHORT);
|
|
245
|
+
if (showTimezone) {
|
|
246
|
+
dateString += ` ${clonedDate.offsetNameShort}`;
|
|
247
|
+
}
|
|
248
|
+
return dateString;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Prints a date range in the format of M/D/YY HH:mm A - M/D/YY HH:mm A EST, taking timezones into
|
|
252
|
+
// account. If the dates are the same, it will print the date only once, e.g. M/D/YY HH:mm A - HH:mm
|
|
253
|
+
// A EST.
|
|
254
|
+
export function printDateRange(
|
|
255
|
+
start: string,
|
|
256
|
+
end: string,
|
|
257
|
+
{timezone, showTimezone = true}: {timezone: string; showTimezone?: boolean}
|
|
258
|
+
): string {
|
|
259
|
+
const startDate = printDate(start, {timezone, showTimezone: false});
|
|
260
|
+
const endDate = printDate(end, {timezone, showTimezone: false});
|
|
261
|
+
|
|
262
|
+
const startTime = printTime(start, {timezone, showTimezone: false});
|
|
263
|
+
const endTime = printTime(end, {timezone, showTimezone});
|
|
264
|
+
if (startDate === endDate) {
|
|
265
|
+
return `${startDate} ${startTime} - ${endTime}`;
|
|
266
|
+
} else {
|
|
267
|
+
return `${startDate} ${startTime} - ${endDate} ${endTime}`;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Print since nicely. If less than 2 months, print days, otherwise print months. If over 1 year,
|
|
272
|
+
// print years.
|
|
273
|
+
export function printSince(
|
|
274
|
+
date: string,
|
|
275
|
+
{timezone, showAgo = true}: {timezone?: string; showAgo?: boolean} = {}
|
|
276
|
+
): string {
|
|
277
|
+
let clonedDate;
|
|
278
|
+
const ago = showAgo ? " ago" : "";
|
|
279
|
+
try {
|
|
280
|
+
clonedDate = getDate(date, {timezone});
|
|
281
|
+
} catch (error: any) {
|
|
282
|
+
throw new Error(`printSince: ${error.message}`);
|
|
283
|
+
}
|
|
284
|
+
const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
|
|
285
|
+
const diff = now.diff(clonedDate, "months");
|
|
286
|
+
if (diff.months < 2) {
|
|
287
|
+
const days = Math.floor(now.diff(clonedDate, "days").days);
|
|
288
|
+
return `${days} ${days === 1 ? "day" : "days"}${ago}`;
|
|
289
|
+
} else if (diff.months < 12) {
|
|
290
|
+
const months = Math.floor(diff.months);
|
|
291
|
+
return `${months} ${months === 1 ? "month" : "months"}${ago}`;
|
|
292
|
+
} else {
|
|
293
|
+
const years = Math.floor(now.diff(clonedDate, "years").years);
|
|
294
|
+
return `${years} ${years === 1 ? "year" : "years"}${ago}`;
|
|
295
|
+
}
|
|
296
|
+
}
|
package/src/Field.tsx
CHANGED
|
@@ -37,6 +37,7 @@ export const Field = ({
|
|
|
37
37
|
googleMapsApiKey,
|
|
38
38
|
googlePlacesMobileStyles,
|
|
39
39
|
testID,
|
|
40
|
+
transformValue,
|
|
40
41
|
}: FieldProps) => {
|
|
41
42
|
const handleAddressChange = (field: string, newValue: string) => {
|
|
42
43
|
onChange({...value, [field]: newValue});
|
|
@@ -152,6 +153,7 @@ export const Field = ({
|
|
|
152
153
|
id={name}
|
|
153
154
|
placeholder={placeholder}
|
|
154
155
|
testID={testID}
|
|
156
|
+
transformValue={transformValue}
|
|
155
157
|
type={type as "date" | "time" | "datetime"}
|
|
156
158
|
value={value}
|
|
157
159
|
onBlur={(result) => {
|
package/src/TextField.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getCalendars} from "expo-localization";
|
|
1
2
|
import {AsYouType} from "libphonenumber-js";
|
|
2
3
|
import React, {ReactElement, useCallback, useContext, useMemo, useState} from "react";
|
|
3
4
|
import {
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
import {Box} from "./Box";
|
|
13
14
|
import {TextFieldProps} from "./Common";
|
|
14
15
|
import {DateTimeActionSheet} from "./DateTimeActionSheet";
|
|
15
|
-
import
|
|
16
|
+
import {printDate, printDateAndTime, printTime} from "./DateUtilities";
|
|
16
17
|
import {DecimalRangeActionSheet} from "./DecimalRangeActionSheet";
|
|
17
18
|
import {HeightActionSheet} from "./HeightActionSheet";
|
|
18
19
|
import {Icon} from "./Icon";
|
|
@@ -86,6 +87,7 @@ export const TextField = ({
|
|
|
86
87
|
onEnter,
|
|
87
88
|
onSubmitEditing,
|
|
88
89
|
testID,
|
|
90
|
+
transformValue,
|
|
89
91
|
}: TextFieldProps): ReactElement => {
|
|
90
92
|
const {theme} = useContext(ThemeContext);
|
|
91
93
|
|
|
@@ -94,6 +96,12 @@ export const TextField = ({
|
|
|
94
96
|
const decimalRangeActionSheetRef: React.RefObject<any> = React.createRef();
|
|
95
97
|
const weightActionSheetRef: React.RefObject<any> = React.createRef();
|
|
96
98
|
|
|
99
|
+
const calendar = getCalendars()[0];
|
|
100
|
+
const localTimeZone = calendar?.timeZone;
|
|
101
|
+
if (!localTimeZone) {
|
|
102
|
+
console.warn("Could not automatically determine timezone.");
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
const [focused, setFocused] = useState(false);
|
|
98
106
|
const [height, setHeight] = useState(propsHeight || 40);
|
|
99
107
|
const [showDate, setShowDate] = useState(false);
|
|
@@ -194,24 +202,15 @@ export const TextField = ({
|
|
|
194
202
|
}, [decimalRangeActionSheetRef, disabled, numberRangeActionSheetRef, type, weightActionSheetRef]);
|
|
195
203
|
|
|
196
204
|
let displayValue = value;
|
|
197
|
-
if (
|
|
205
|
+
if (value) {
|
|
206
|
+
const timezone = transformValue?.options?.timezone || localTimeZone;
|
|
207
|
+
|
|
198
208
|
if (type === "date") {
|
|
199
|
-
|
|
200
|
-
// offset.
|
|
201
|
-
if (
|
|
202
|
-
dayjs.utc(value).hour() === 0 &&
|
|
203
|
-
dayjs.utc(value).minute() === 0 &&
|
|
204
|
-
dayjs.utc(value).second() === 0
|
|
205
|
-
) {
|
|
206
|
-
const timezoneOffset = new Date().getTimezoneOffset();
|
|
207
|
-
displayValue = dayjs.utc(value).add(timezoneOffset, "minutes").format("MM/DD/YYYY");
|
|
208
|
-
} else {
|
|
209
|
-
displayValue = dayjs(value).format("MM/DD/YYYY");
|
|
210
|
-
}
|
|
209
|
+
displayValue = printDate(value, {ignoreTime: true});
|
|
211
210
|
} else if (type === "time") {
|
|
212
|
-
displayValue =
|
|
211
|
+
displayValue = printTime(value, {timezone, showTimezone: true});
|
|
213
212
|
} else if (type === "datetime") {
|
|
214
|
-
displayValue =
|
|
213
|
+
displayValue = printDateAndTime(value, {timezone, showTimezone: true});
|
|
215
214
|
} else if (type === "height") {
|
|
216
215
|
displayValue = `${Math.floor(Number(value) / 12)} ft, ${Number(value) % 12} in`;
|
|
217
216
|
} else if (type === "phoneNumber") {
|
|
@@ -222,8 +221,8 @@ export const TextField = ({
|
|
|
222
221
|
// which would then be formatted back to `"(123)"`
|
|
223
222
|
// and so a user wouldn't be able to erase the phone number.
|
|
224
223
|
// This is the workaround for that.
|
|
225
|
-
const formattedPhoneNumber = new AsYouType("US").input(
|
|
226
|
-
if (displayValue !== formattedPhoneNumber &&
|
|
224
|
+
const formattedPhoneNumber = new AsYouType("US").input(value);
|
|
225
|
+
if (displayValue !== formattedPhoneNumber && value.length !== 4) {
|
|
227
226
|
displayValue = formattedPhoneNumber;
|
|
228
227
|
}
|
|
229
228
|
}
|
|
@@ -308,21 +307,24 @@ export const TextField = ({
|
|
|
308
307
|
// }
|
|
309
308
|
}}
|
|
310
309
|
onChangeText={(text) => {
|
|
311
|
-
if (onChange) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
onChange({value: formattedPhoneNumber});
|
|
319
|
-
}
|
|
320
|
-
} else if (type === "number") {
|
|
321
|
-
text = text.replace(/[^0-9]/g, "");
|
|
322
|
-
onChange({value: !isNaN(parseInt(text)) ? parseInt(text).toString() : ""});
|
|
323
|
-
} else {
|
|
310
|
+
if (!onChange) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (type === "phoneNumber") {
|
|
314
|
+
const formattedPhoneNumber = new AsYouType("US").input(text);
|
|
315
|
+
// another workaround for the same issue as above with backspacing phone numbers
|
|
316
|
+
if (formattedPhoneNumber === value) {
|
|
324
317
|
onChange({value: text});
|
|
318
|
+
} else {
|
|
319
|
+
onChange({value: formattedPhoneNumber});
|
|
325
320
|
}
|
|
321
|
+
} else if (type === "number") {
|
|
322
|
+
text = text.replace(/[^0-9]/g, "");
|
|
323
|
+
onChange({value: !isNaN(parseInt(text)) ? parseInt(text).toString() : ""});
|
|
324
|
+
} else if (type === "date" || type === "datetime" || type === "time") {
|
|
325
|
+
// Do nothing, this is handled by the date time action sheet
|
|
326
|
+
} else {
|
|
327
|
+
onChange({value: text});
|
|
326
328
|
}
|
|
327
329
|
}}
|
|
328
330
|
onContentSizeChange={(event) => {
|
|
@@ -352,6 +354,7 @@ export const TextField = ({
|
|
|
352
354
|
<DateTimeActionSheet
|
|
353
355
|
actionSheetRef={dateActionSheetRef}
|
|
354
356
|
mode={type}
|
|
357
|
+
transformValue={transformValue}
|
|
355
358
|
value={value}
|
|
356
359
|
visible={showDate}
|
|
357
360
|
onChange={(result) => {
|
|
@@ -5,7 +5,6 @@ import {ActionSheet} from "./ActionSheet";
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
6
|
import {Button} from "./Button";
|
|
7
7
|
import {NumberPickerActionSheetProps, TextFieldPickerActionSheetProps} from "./Common";
|
|
8
|
-
import dayjs from "./dayjsExtended";
|
|
9
8
|
|
|
10
9
|
interface NumberPickerActionSheetState {}
|
|
11
10
|
|
|
@@ -39,7 +38,7 @@ export class NumberPickerActionSheet extends React.Component<
|
|
|
39
38
|
is24Hour
|
|
40
39
|
mode={this.props.mode}
|
|
41
40
|
testID="dateTimePicker"
|
|
42
|
-
value={
|
|
41
|
+
value={this.props.value ? new Date(this.props.value) : new Date()}
|
|
43
42
|
onChange={(event: any, date?: Date) => {
|
|
44
43
|
if (!date) {
|
|
45
44
|
return;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import {Box} from "./Box";
|
|
4
|
+
import {TimezonePickerProps} from "./Common";
|
|
5
|
+
import {SelectList} from "./SelectList";
|
|
6
|
+
import {WithLabel} from "./WithLabel";
|
|
7
|
+
|
|
8
|
+
// TODO: Support world wide timezones
|
|
9
|
+
const options = [
|
|
10
|
+
{label: "Eastern", value: "America/New_York"},
|
|
11
|
+
{label: "Central", value: "America/Chicago"},
|
|
12
|
+
{label: "Mountain", value: "America/Denver"},
|
|
13
|
+
{label: "Pacific", value: "America/Los_Angeles"},
|
|
14
|
+
{label: "Alaska", value: "America/Anchorage"},
|
|
15
|
+
{label: "Hawaii", value: "Pacific/Honolulu"},
|
|
16
|
+
{label: "Arizona", value: "America/Phoenix"},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const TimezonePicker = ({
|
|
20
|
+
timezone,
|
|
21
|
+
onChange,
|
|
22
|
+
showLabel,
|
|
23
|
+
width = 100,
|
|
24
|
+
}: TimezonePickerProps): React.ReactElement => {
|
|
25
|
+
if (showLabel) {
|
|
26
|
+
return (
|
|
27
|
+
<Box maxWidth={width}>
|
|
28
|
+
<WithLabel label="Timezone">
|
|
29
|
+
<SelectList
|
|
30
|
+
allowClear
|
|
31
|
+
options={options}
|
|
32
|
+
style={{minHeight: 40}}
|
|
33
|
+
value={timezone}
|
|
34
|
+
onChange={onChange}
|
|
35
|
+
/>
|
|
36
|
+
</WithLabel>
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
} else {
|
|
40
|
+
return (
|
|
41
|
+
<Box maxWidth={width}>
|
|
42
|
+
<SelectList
|
|
43
|
+
allowClear
|
|
44
|
+
options={options}
|
|
45
|
+
style={{minHeight: 40}}
|
|
46
|
+
value={timezone}
|
|
47
|
+
onChange={onChange}
|
|
48
|
+
/>
|
|
49
|
+
</Box>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./Common";
|
|
|
12
12
|
export * from "./Constants";
|
|
13
13
|
export * from "./DateTimeActionSheet";
|
|
14
14
|
export * from "./DateTimeField";
|
|
15
|
+
export * from "./DateUtilities";
|
|
15
16
|
export * from "./DecimalRangeActionSheet";
|
|
16
17
|
export * from "./ErrorBoundary";
|
|
17
18
|
export * from "./ErrorPage";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
process.env.TZ = "America/New_York";
|
package/dist/dayjsExtended.d.ts
DELETED
package/dist/dayjsExtended.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import relativeTime from "dayjs/plugin/relativeTime";
|
|
3
|
-
import timezone from "dayjs/plugin/timezone";
|
|
4
|
-
import utc from "dayjs/plugin/utc";
|
|
5
|
-
dayjs.extend(utc);
|
|
6
|
-
dayjs.extend(timezone);
|
|
7
|
-
dayjs.extend(relativeTime);
|
|
8
|
-
// eslint-disable-next-line import/no-default-export
|
|
9
|
-
export default dayjs;
|
|
10
|
-
//# sourceMappingURL=dayjsExtended.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dayjsExtended.js","sourceRoot":"","sources":["../src/dayjsExtended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAEnC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvB,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAE3B,oDAAoD;AACpD,eAAe,KAAK,CAAC"}
|
package/src/dayjsExtended.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import relativeTime from "dayjs/plugin/relativeTime";
|
|
3
|
-
import timezone from "dayjs/plugin/timezone";
|
|
4
|
-
import utc from "dayjs/plugin/utc";
|
|
5
|
-
|
|
6
|
-
dayjs.extend(utc);
|
|
7
|
-
dayjs.extend(timezone);
|
|
8
|
-
dayjs.extend(relativeTime);
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line import/no-default-export
|
|
11
|
-
export default dayjs;
|