react-timezone-select 1.4.0 → 1.5.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/index.cjs +235 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +201 -0
- package/package.json +42 -18
- package/dist/cjs/dist/index.d.ts +0 -7
- package/dist/cjs/dist/timezone-list.d.ts +0 -3
- package/dist/cjs/dist/types/globals.d.ts +0 -1
- package/dist/cjs/dist/types/timezone.d.ts +0 -19
- package/dist/cjs/index.js +0 -10
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/dist/index.d.ts +0 -7
- package/dist/esm/dist/timezone-list.d.ts +0 -3
- package/dist/esm/dist/types/globals.d.ts +0 -1
- package/dist/esm/dist/types/timezone.d.ts +0 -19
- package/dist/esm/index.js +0 -10
- package/dist/esm/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.tsx
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
allTimezones: () => timezone_list_default,
|
|
33
|
+
default: () => src_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var React = __toESM(require("react"), 1);
|
|
37
|
+
var import_react_select = __toESM(require("react-select"), 1);
|
|
38
|
+
var import_spacetime = __toESM(require("spacetime"), 1);
|
|
39
|
+
var import_timezone_soft = __toESM(require("timezone-soft"), 1);
|
|
40
|
+
|
|
41
|
+
// src/timezone-list.ts
|
|
42
|
+
var allTimezones = {
|
|
43
|
+
"Pacific/Midway": "Midway Island, Samoa",
|
|
44
|
+
"Pacific/Honolulu": "Hawaii",
|
|
45
|
+
"America/Juneau": "Alaska",
|
|
46
|
+
"America/Boise": "Mountain Time",
|
|
47
|
+
"America/Dawson": "Dawson, Yukon",
|
|
48
|
+
"America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
|
|
49
|
+
"America/Phoenix": "Arizona",
|
|
50
|
+
"America/Chicago": "Central Time",
|
|
51
|
+
"America/Regina": "Saskatchewan",
|
|
52
|
+
"America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
|
|
53
|
+
"America/Belize": "Central America",
|
|
54
|
+
"America/Detroit": "Eastern Time",
|
|
55
|
+
"America/Bogota": "Bogota, Lima, Quito",
|
|
56
|
+
"America/Caracas": "Caracas, La Paz",
|
|
57
|
+
"America/Santiago": "Santiago",
|
|
58
|
+
"America/St_Johns": "Newfoundland and Labrador",
|
|
59
|
+
"America/Sao_Paulo": "Brasilia",
|
|
60
|
+
"America/Tijuana": "Tijuana",
|
|
61
|
+
"America/Montevideo": "Montevideo",
|
|
62
|
+
"America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
|
|
63
|
+
"America/Godthab": "Greenland",
|
|
64
|
+
"America/Los_Angeles": "Pacific Time",
|
|
65
|
+
"Atlantic/Azores": "Azores",
|
|
66
|
+
"Atlantic/Cape_Verde": "Cape Verde Islands",
|
|
67
|
+
GMT: "UTC",
|
|
68
|
+
"Europe/London": "Edinburgh, London",
|
|
69
|
+
"Europe/Dublin": "Dublin",
|
|
70
|
+
"Europe/Lisbon": "Lisbon",
|
|
71
|
+
"Africa/Casablanca": "Casablanca, Monrovia",
|
|
72
|
+
"Atlantic/Canary": "Canary Islands",
|
|
73
|
+
"Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
|
|
74
|
+
"Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
|
|
75
|
+
"Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
|
|
76
|
+
"Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
|
|
77
|
+
"Africa/Algiers": "West Central Africa",
|
|
78
|
+
"Europe/Bucharest": "Bucharest",
|
|
79
|
+
"Africa/Cairo": "Cairo",
|
|
80
|
+
"Europe/Helsinki": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
|
|
81
|
+
"Europe/Athens": "Athens, Minsk",
|
|
82
|
+
"Asia/Jerusalem": "Jerusalem",
|
|
83
|
+
"Africa/Harare": "Harare, Pretoria",
|
|
84
|
+
"Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
|
|
85
|
+
"Asia/Kuwait": "Kuwait, Riyadh",
|
|
86
|
+
"Africa/Nairobi": "Nairobi",
|
|
87
|
+
"Asia/Baghdad": "Baghdad",
|
|
88
|
+
"Asia/Tehran": "Tehran",
|
|
89
|
+
"Asia/Dubai": "Abu Dhabi, Muscat",
|
|
90
|
+
"Asia/Baku": "Baku, Tbilisi, Yerevan",
|
|
91
|
+
"Asia/Kabul": "Kabul",
|
|
92
|
+
"Asia/Yekaterinburg": "Ekaterinburg",
|
|
93
|
+
"Asia/Karachi": "Islamabad, Karachi, Tashkent",
|
|
94
|
+
"Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
|
|
95
|
+
"Asia/Kathmandu": "Kathmandu",
|
|
96
|
+
"Asia/Dhaka": "Astana, Dhaka",
|
|
97
|
+
"Asia/Colombo": "Sri Jayawardenepura",
|
|
98
|
+
"Asia/Almaty": "Almaty, Novosibirsk",
|
|
99
|
+
"Asia/Rangoon": "Yangon Rangoon",
|
|
100
|
+
"Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
|
|
101
|
+
"Asia/Krasnoyarsk": "Krasnoyarsk",
|
|
102
|
+
"Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
|
|
103
|
+
"Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
|
|
104
|
+
"Asia/Taipei": "Taipei",
|
|
105
|
+
"Australia/Perth": "Perth",
|
|
106
|
+
"Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
|
|
107
|
+
"Asia/Seoul": "Seoul",
|
|
108
|
+
"Asia/Tokyo": "Osaka, Sapporo, Tokyo",
|
|
109
|
+
"Asia/Yakutsk": "Yakutsk",
|
|
110
|
+
"Australia/Darwin": "Darwin",
|
|
111
|
+
"Australia/Adelaide": "Adelaide",
|
|
112
|
+
"Australia/Sydney": "Canberra, Melbourne, Sydney",
|
|
113
|
+
"Australia/Brisbane": "Brisbane",
|
|
114
|
+
"Australia/Hobart": "Hobart",
|
|
115
|
+
"Asia/Vladivostok": "Vladivostok",
|
|
116
|
+
"Pacific/Guam": "Guam, Port Moresby",
|
|
117
|
+
"Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
|
|
118
|
+
"Asia/Kamchatka": "Kamchatka, Marshall Islands",
|
|
119
|
+
"Pacific/Fiji": "Fiji Islands",
|
|
120
|
+
"Pacific/Auckland": "Auckland, Wellington",
|
|
121
|
+
"Pacific/Tongatapu": "Nuku'alofa"
|
|
122
|
+
};
|
|
123
|
+
var timezone_list_default = allTimezones;
|
|
124
|
+
|
|
125
|
+
// src/index.tsx
|
|
126
|
+
var TimezoneSelect = ({
|
|
127
|
+
value,
|
|
128
|
+
onBlur,
|
|
129
|
+
onChange,
|
|
130
|
+
labelStyle = "original",
|
|
131
|
+
timezones,
|
|
132
|
+
...props
|
|
133
|
+
}) => {
|
|
134
|
+
if (!timezones)
|
|
135
|
+
timezones = timezone_list_default;
|
|
136
|
+
const getOptions = React.useMemo(() => {
|
|
137
|
+
return Object.entries(timezones).reduce((selectOptions, zone) => {
|
|
138
|
+
const now = import_spacetime.default.now(zone[0]);
|
|
139
|
+
const tz = now.timezone();
|
|
140
|
+
const tzStrings = (0, import_timezone_soft.default)(zone[0]);
|
|
141
|
+
let label = "";
|
|
142
|
+
let abbr = now.isDST() ? (
|
|
143
|
+
// @ts-expect-error
|
|
144
|
+
tzStrings[0].daylight?.abbr
|
|
145
|
+
) : (
|
|
146
|
+
// @ts-expect-error
|
|
147
|
+
tzStrings[0].standard?.abbr
|
|
148
|
+
);
|
|
149
|
+
let altName = now.isDST() ? tzStrings[0].daylight?.name : tzStrings[0].standard?.name;
|
|
150
|
+
const min = tz.current.offset * 60;
|
|
151
|
+
const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
|
|
152
|
+
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
153
|
+
switch (labelStyle) {
|
|
154
|
+
case "original":
|
|
155
|
+
label = prefix;
|
|
156
|
+
break;
|
|
157
|
+
case "altName":
|
|
158
|
+
label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
|
|
159
|
+
break;
|
|
160
|
+
case "abbrev":
|
|
161
|
+
label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ""}`;
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
label = `${prefix}`;
|
|
165
|
+
}
|
|
166
|
+
selectOptions.push({
|
|
167
|
+
value: tz.name,
|
|
168
|
+
label,
|
|
169
|
+
offset: tz.current.offset,
|
|
170
|
+
abbrev: abbr,
|
|
171
|
+
altName
|
|
172
|
+
});
|
|
173
|
+
return selectOptions;
|
|
174
|
+
}, []).sort((a, b) => a.offset - b.offset);
|
|
175
|
+
}, [labelStyle, timezones]);
|
|
176
|
+
const handleChange = (tz) => {
|
|
177
|
+
onChange && onChange(tz);
|
|
178
|
+
};
|
|
179
|
+
const findFuzzyTz = (zone) => {
|
|
180
|
+
let currentTime = import_spacetime.default.now("GMT");
|
|
181
|
+
try {
|
|
182
|
+
currentTime = import_spacetime.default.now(zone);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
return getOptions.filter(
|
|
187
|
+
(tz) => tz.offset === currentTime.timezone().current.offset
|
|
188
|
+
).map((tz) => {
|
|
189
|
+
let score = 0;
|
|
190
|
+
if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
|
|
191
|
+
if (tz.value.toLowerCase().indexOf(
|
|
192
|
+
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
193
|
+
) !== -1) {
|
|
194
|
+
score += 8;
|
|
195
|
+
}
|
|
196
|
+
if (tz.label.toLowerCase().indexOf(
|
|
197
|
+
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
198
|
+
) !== -1) {
|
|
199
|
+
score += 4;
|
|
200
|
+
}
|
|
201
|
+
if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf("/")))) {
|
|
202
|
+
score += 2;
|
|
203
|
+
}
|
|
204
|
+
score += 1;
|
|
205
|
+
} else if (tz.value === "GMT") {
|
|
206
|
+
score += 1;
|
|
207
|
+
}
|
|
208
|
+
return { tz, score };
|
|
209
|
+
}).sort((a, b) => b.score - a.score).map(({ tz }) => tz)[0];
|
|
210
|
+
};
|
|
211
|
+
const parseTimezone = (zone) => {
|
|
212
|
+
if (typeof zone === "object" && zone.value && zone.label)
|
|
213
|
+
return zone;
|
|
214
|
+
if (typeof zone === "string") {
|
|
215
|
+
return getOptions.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
|
|
216
|
+
} else if (zone.value && !zone.label) {
|
|
217
|
+
return getOptions.find((tz) => tz.value === zone.value);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
return /* @__PURE__ */ React.createElement(
|
|
221
|
+
import_react_select.default,
|
|
222
|
+
{
|
|
223
|
+
value: parseTimezone(value),
|
|
224
|
+
onChange: handleChange,
|
|
225
|
+
options: getOptions,
|
|
226
|
+
onBlur,
|
|
227
|
+
...props
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
};
|
|
231
|
+
var src_default = TimezoneSelect;
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
allTimezones
|
|
235
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Props as Props$1 } from 'react-select';
|
|
2
|
+
|
|
3
|
+
declare type ICustomTimezone = {
|
|
4
|
+
[key: string]: string
|
|
5
|
+
}
|
|
6
|
+
declare type ILabelStyle = 'original' | 'altName' | 'abbrev'
|
|
7
|
+
interface ITimezoneOption {
|
|
8
|
+
value: string
|
|
9
|
+
label: string
|
|
10
|
+
offset: number
|
|
11
|
+
abbrev?: string
|
|
12
|
+
altName?: string
|
|
13
|
+
}
|
|
14
|
+
declare type ITimezone = ITimezoneOption | string
|
|
15
|
+
interface Props extends Omit<Props$1, 'onChange'> {
|
|
16
|
+
value: ITimezone
|
|
17
|
+
labelStyle?: ILabelStyle
|
|
18
|
+
onChange?: (timezone: ITimezoneOption) => void
|
|
19
|
+
timezones?: ICustomTimezone
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const allTimezones: ICustomTimezone;
|
|
23
|
+
|
|
24
|
+
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, timezones, ...props }: Props) => JSX.Element;
|
|
25
|
+
|
|
26
|
+
export { ILabelStyle, ITimezone, ITimezoneOption, Props, allTimezones, TimezoneSelect as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/index.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import Select from "react-select";
|
|
4
|
+
import spacetime from "spacetime";
|
|
5
|
+
import soft from "timezone-soft";
|
|
6
|
+
|
|
7
|
+
// src/timezone-list.ts
|
|
8
|
+
var allTimezones = {
|
|
9
|
+
"Pacific/Midway": "Midway Island, Samoa",
|
|
10
|
+
"Pacific/Honolulu": "Hawaii",
|
|
11
|
+
"America/Juneau": "Alaska",
|
|
12
|
+
"America/Boise": "Mountain Time",
|
|
13
|
+
"America/Dawson": "Dawson, Yukon",
|
|
14
|
+
"America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
|
|
15
|
+
"America/Phoenix": "Arizona",
|
|
16
|
+
"America/Chicago": "Central Time",
|
|
17
|
+
"America/Regina": "Saskatchewan",
|
|
18
|
+
"America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
|
|
19
|
+
"America/Belize": "Central America",
|
|
20
|
+
"America/Detroit": "Eastern Time",
|
|
21
|
+
"America/Bogota": "Bogota, Lima, Quito",
|
|
22
|
+
"America/Caracas": "Caracas, La Paz",
|
|
23
|
+
"America/Santiago": "Santiago",
|
|
24
|
+
"America/St_Johns": "Newfoundland and Labrador",
|
|
25
|
+
"America/Sao_Paulo": "Brasilia",
|
|
26
|
+
"America/Tijuana": "Tijuana",
|
|
27
|
+
"America/Montevideo": "Montevideo",
|
|
28
|
+
"America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
|
|
29
|
+
"America/Godthab": "Greenland",
|
|
30
|
+
"America/Los_Angeles": "Pacific Time",
|
|
31
|
+
"Atlantic/Azores": "Azores",
|
|
32
|
+
"Atlantic/Cape_Verde": "Cape Verde Islands",
|
|
33
|
+
GMT: "UTC",
|
|
34
|
+
"Europe/London": "Edinburgh, London",
|
|
35
|
+
"Europe/Dublin": "Dublin",
|
|
36
|
+
"Europe/Lisbon": "Lisbon",
|
|
37
|
+
"Africa/Casablanca": "Casablanca, Monrovia",
|
|
38
|
+
"Atlantic/Canary": "Canary Islands",
|
|
39
|
+
"Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
|
|
40
|
+
"Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
|
|
41
|
+
"Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
|
|
42
|
+
"Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
|
|
43
|
+
"Africa/Algiers": "West Central Africa",
|
|
44
|
+
"Europe/Bucharest": "Bucharest",
|
|
45
|
+
"Africa/Cairo": "Cairo",
|
|
46
|
+
"Europe/Helsinki": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
|
|
47
|
+
"Europe/Athens": "Athens, Minsk",
|
|
48
|
+
"Asia/Jerusalem": "Jerusalem",
|
|
49
|
+
"Africa/Harare": "Harare, Pretoria",
|
|
50
|
+
"Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
|
|
51
|
+
"Asia/Kuwait": "Kuwait, Riyadh",
|
|
52
|
+
"Africa/Nairobi": "Nairobi",
|
|
53
|
+
"Asia/Baghdad": "Baghdad",
|
|
54
|
+
"Asia/Tehran": "Tehran",
|
|
55
|
+
"Asia/Dubai": "Abu Dhabi, Muscat",
|
|
56
|
+
"Asia/Baku": "Baku, Tbilisi, Yerevan",
|
|
57
|
+
"Asia/Kabul": "Kabul",
|
|
58
|
+
"Asia/Yekaterinburg": "Ekaterinburg",
|
|
59
|
+
"Asia/Karachi": "Islamabad, Karachi, Tashkent",
|
|
60
|
+
"Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
|
|
61
|
+
"Asia/Kathmandu": "Kathmandu",
|
|
62
|
+
"Asia/Dhaka": "Astana, Dhaka",
|
|
63
|
+
"Asia/Colombo": "Sri Jayawardenepura",
|
|
64
|
+
"Asia/Almaty": "Almaty, Novosibirsk",
|
|
65
|
+
"Asia/Rangoon": "Yangon Rangoon",
|
|
66
|
+
"Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
|
|
67
|
+
"Asia/Krasnoyarsk": "Krasnoyarsk",
|
|
68
|
+
"Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
|
|
69
|
+
"Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
|
|
70
|
+
"Asia/Taipei": "Taipei",
|
|
71
|
+
"Australia/Perth": "Perth",
|
|
72
|
+
"Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
|
|
73
|
+
"Asia/Seoul": "Seoul",
|
|
74
|
+
"Asia/Tokyo": "Osaka, Sapporo, Tokyo",
|
|
75
|
+
"Asia/Yakutsk": "Yakutsk",
|
|
76
|
+
"Australia/Darwin": "Darwin",
|
|
77
|
+
"Australia/Adelaide": "Adelaide",
|
|
78
|
+
"Australia/Sydney": "Canberra, Melbourne, Sydney",
|
|
79
|
+
"Australia/Brisbane": "Brisbane",
|
|
80
|
+
"Australia/Hobart": "Hobart",
|
|
81
|
+
"Asia/Vladivostok": "Vladivostok",
|
|
82
|
+
"Pacific/Guam": "Guam, Port Moresby",
|
|
83
|
+
"Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
|
|
84
|
+
"Asia/Kamchatka": "Kamchatka, Marshall Islands",
|
|
85
|
+
"Pacific/Fiji": "Fiji Islands",
|
|
86
|
+
"Pacific/Auckland": "Auckland, Wellington",
|
|
87
|
+
"Pacific/Tongatapu": "Nuku'alofa"
|
|
88
|
+
};
|
|
89
|
+
var timezone_list_default = allTimezones;
|
|
90
|
+
|
|
91
|
+
// src/index.tsx
|
|
92
|
+
var TimezoneSelect = ({
|
|
93
|
+
value,
|
|
94
|
+
onBlur,
|
|
95
|
+
onChange,
|
|
96
|
+
labelStyle = "original",
|
|
97
|
+
timezones,
|
|
98
|
+
...props
|
|
99
|
+
}) => {
|
|
100
|
+
if (!timezones)
|
|
101
|
+
timezones = timezone_list_default;
|
|
102
|
+
const getOptions = React.useMemo(() => {
|
|
103
|
+
return Object.entries(timezones).reduce((selectOptions, zone) => {
|
|
104
|
+
const now = spacetime.now(zone[0]);
|
|
105
|
+
const tz = now.timezone();
|
|
106
|
+
const tzStrings = soft(zone[0]);
|
|
107
|
+
let label = "";
|
|
108
|
+
let abbr = now.isDST() ? (
|
|
109
|
+
// @ts-expect-error
|
|
110
|
+
tzStrings[0].daylight?.abbr
|
|
111
|
+
) : (
|
|
112
|
+
// @ts-expect-error
|
|
113
|
+
tzStrings[0].standard?.abbr
|
|
114
|
+
);
|
|
115
|
+
let altName = now.isDST() ? tzStrings[0].daylight?.name : tzStrings[0].standard?.name;
|
|
116
|
+
const min = tz.current.offset * 60;
|
|
117
|
+
const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
|
|
118
|
+
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
119
|
+
switch (labelStyle) {
|
|
120
|
+
case "original":
|
|
121
|
+
label = prefix;
|
|
122
|
+
break;
|
|
123
|
+
case "altName":
|
|
124
|
+
label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
|
|
125
|
+
break;
|
|
126
|
+
case "abbrev":
|
|
127
|
+
label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ""}`;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
label = `${prefix}`;
|
|
131
|
+
}
|
|
132
|
+
selectOptions.push({
|
|
133
|
+
value: tz.name,
|
|
134
|
+
label,
|
|
135
|
+
offset: tz.current.offset,
|
|
136
|
+
abbrev: abbr,
|
|
137
|
+
altName
|
|
138
|
+
});
|
|
139
|
+
return selectOptions;
|
|
140
|
+
}, []).sort((a, b) => a.offset - b.offset);
|
|
141
|
+
}, [labelStyle, timezones]);
|
|
142
|
+
const handleChange = (tz) => {
|
|
143
|
+
onChange && onChange(tz);
|
|
144
|
+
};
|
|
145
|
+
const findFuzzyTz = (zone) => {
|
|
146
|
+
let currentTime = spacetime.now("GMT");
|
|
147
|
+
try {
|
|
148
|
+
currentTime = spacetime.now(zone);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
return getOptions.filter(
|
|
153
|
+
(tz) => tz.offset === currentTime.timezone().current.offset
|
|
154
|
+
).map((tz) => {
|
|
155
|
+
let score = 0;
|
|
156
|
+
if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
|
|
157
|
+
if (tz.value.toLowerCase().indexOf(
|
|
158
|
+
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
159
|
+
) !== -1) {
|
|
160
|
+
score += 8;
|
|
161
|
+
}
|
|
162
|
+
if (tz.label.toLowerCase().indexOf(
|
|
163
|
+
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
164
|
+
) !== -1) {
|
|
165
|
+
score += 4;
|
|
166
|
+
}
|
|
167
|
+
if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf("/")))) {
|
|
168
|
+
score += 2;
|
|
169
|
+
}
|
|
170
|
+
score += 1;
|
|
171
|
+
} else if (tz.value === "GMT") {
|
|
172
|
+
score += 1;
|
|
173
|
+
}
|
|
174
|
+
return { tz, score };
|
|
175
|
+
}).sort((a, b) => b.score - a.score).map(({ tz }) => tz)[0];
|
|
176
|
+
};
|
|
177
|
+
const parseTimezone = (zone) => {
|
|
178
|
+
if (typeof zone === "object" && zone.value && zone.label)
|
|
179
|
+
return zone;
|
|
180
|
+
if (typeof zone === "string") {
|
|
181
|
+
return getOptions.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
|
|
182
|
+
} else if (zone.value && !zone.label) {
|
|
183
|
+
return getOptions.find((tz) => tz.value === zone.value);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return /* @__PURE__ */ React.createElement(
|
|
187
|
+
Select,
|
|
188
|
+
{
|
|
189
|
+
value: parseTimezone(value),
|
|
190
|
+
onChange: handleChange,
|
|
191
|
+
options: getOptions,
|
|
192
|
+
onBlur,
|
|
193
|
+
...props
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
var src_default = TimezoneSelect;
|
|
198
|
+
export {
|
|
199
|
+
timezone_list_default as allTimezones,
|
|
200
|
+
src_default as default
|
|
201
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-timezone-select",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Usable, dynamic React Timezone Select",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "concurrently \"rollup -cw\" \"cd example && npm run dev\"",
|
|
7
7
|
"prepublish": "npm run build",
|
|
8
8
|
"postpublish": "npm run build:example && npm run deploy",
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts",
|
|
10
10
|
"build:example": "cd example && npm run build",
|
|
11
11
|
"deploy": "gh-pages -d example/dist",
|
|
12
12
|
"test": "jest",
|
|
13
13
|
"test:watch": "jest --watch",
|
|
14
14
|
"test:ci": "jest --ci ",
|
|
15
|
-
"pretty-quick": "pretty-quick --staged",
|
|
16
15
|
"tsc": "tsc"
|
|
17
16
|
},
|
|
18
17
|
"author": "Nico Domino <yo@ndo.dev>",
|
|
@@ -36,13 +35,13 @@
|
|
|
36
35
|
"package.json"
|
|
37
36
|
],
|
|
38
37
|
"type": "module",
|
|
39
|
-
"main": "./dist/
|
|
40
|
-
"module": "./dist/
|
|
41
|
-
"types": "./dist/
|
|
38
|
+
"main": "./dist/index.cjs",
|
|
39
|
+
"module": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
42
41
|
"exports": {
|
|
43
42
|
".": {
|
|
44
|
-
"import": "./
|
|
45
|
-
"require": "./
|
|
43
|
+
"import": "./index.js",
|
|
44
|
+
"require": "./index.cjs"
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
@@ -55,9 +54,7 @@
|
|
|
55
54
|
"timezone-soft": "^1.3.1"
|
|
56
55
|
},
|
|
57
56
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
60
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
57
|
+
"@babel/core": "^7.20.7",
|
|
61
58
|
"@testing-library/jest-dom": "^5.16.1",
|
|
62
59
|
"@testing-library/react": "^12.1.2",
|
|
63
60
|
"@types/jest": "^27.4.0",
|
|
@@ -65,21 +62,40 @@
|
|
|
65
62
|
"@types/react-dom": "^17.0.11",
|
|
66
63
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
67
64
|
"concurrently": "^7.0.0",
|
|
68
|
-
"esbuild": "^0.
|
|
65
|
+
"esbuild": "^0.16.12",
|
|
66
|
+
"esbuild-jest": "^0.5.0",
|
|
67
|
+
"eslint": "^8.36.0",
|
|
68
|
+
"eslint-config-prettier": "^8.8.0",
|
|
69
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
69
70
|
"gh-pages": "^3.2.3",
|
|
70
71
|
"jest": "^27.4.7",
|
|
71
72
|
"prettier": "^2.5.1",
|
|
72
|
-
"pretty-quick": "^3.1.3",
|
|
73
73
|
"react": "^17",
|
|
74
74
|
"react-dom": "^17",
|
|
75
|
-
"rollup": "^2.67.0",
|
|
76
|
-
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
77
|
-
"rollup-plugin-postcss": "^4.0.2",
|
|
78
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
79
75
|
"simple-git-hooks": "^2.7.0",
|
|
80
76
|
"ts-jest": "^27.1.3",
|
|
77
|
+
"tsup": "^6.5.0",
|
|
81
78
|
"typescript": "^4.5.5"
|
|
82
79
|
},
|
|
80
|
+
"eslintConfig": {
|
|
81
|
+
"parserOptions": {
|
|
82
|
+
"sourceType": "module"
|
|
83
|
+
},
|
|
84
|
+
"extends": [
|
|
85
|
+
"eslint:recommended",
|
|
86
|
+
"prettier"
|
|
87
|
+
],
|
|
88
|
+
"env": {
|
|
89
|
+
"browser": true,
|
|
90
|
+
"es6": true
|
|
91
|
+
},
|
|
92
|
+
"plugins": [
|
|
93
|
+
"prettier"
|
|
94
|
+
],
|
|
95
|
+
"rules": {
|
|
96
|
+
"prettier/prettier": "error"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
83
99
|
"prettier": {
|
|
84
100
|
"trailingComma": "es5",
|
|
85
101
|
"semi": false,
|
|
@@ -87,6 +103,14 @@
|
|
|
87
103
|
"arrowParens": "avoid"
|
|
88
104
|
},
|
|
89
105
|
"simple-git-hooks": {
|
|
90
|
-
"pre-commit": "
|
|
106
|
+
"pre-commit": "npx lint-staged"
|
|
107
|
+
},
|
|
108
|
+
"lint-staged": {
|
|
109
|
+
"*.{js,jsx,ts,tsx,css,json}": [
|
|
110
|
+
"prettier --write"
|
|
111
|
+
],
|
|
112
|
+
"*.{js,jsx}": [
|
|
113
|
+
"eslint --fix"
|
|
114
|
+
]
|
|
91
115
|
}
|
|
92
116
|
}
|
package/dist/cjs/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import allTimezones from './timezone-list.js';
|
|
3
|
-
import type { Props, ITimezone, ITimezoneOption, ILabelStyle } from './types/timezone';
|
|
4
|
-
export { allTimezones };
|
|
5
|
-
export type { ITimezone, ITimezoneOption, Props, ILabelStyle };
|
|
6
|
-
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, timezones, ...props }: Props) => JSX.Element;
|
|
7
|
-
export default TimezoneSelect;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom/extend-expect";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Props as ReactSelectProps } from "react-select";
|
|
2
|
-
export declare type ICustomTimezone = {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
};
|
|
5
|
-
export declare type ILabelStyle = "original" | "altName" | "abbrev";
|
|
6
|
-
export interface ITimezoneOption {
|
|
7
|
-
value: string;
|
|
8
|
-
label: string;
|
|
9
|
-
abbrev?: string;
|
|
10
|
-
altName?: string;
|
|
11
|
-
offset?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare type ITimezone = ITimezoneOption | string;
|
|
14
|
-
export interface Props extends Omit<ReactSelectProps, "onChange"> {
|
|
15
|
-
value: ITimezone;
|
|
16
|
-
labelStyle?: ILabelStyle;
|
|
17
|
-
onChange?: (timezone: ITimezoneOption) => void;
|
|
18
|
-
timezones?: ICustomTimezone;
|
|
19
|
-
}
|