react-timezone-select 3.0.3 → 3.1.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/index.d.ts +9 -8
- package/package.json +3 -5
- package/dist/index.cjs +0 -282
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
|
|
1
2
|
import { Props as Props$1 } from 'react-select';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type ICustomTimezone = {
|
|
4
5
|
[key: string]: string;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type ILabelStyle = 'original' | 'altName' | 'abbrev' | 'offsetHidden';
|
|
8
|
+
type IDisplayValue = 'GMT' | 'UTC';
|
|
9
|
+
type ITimezoneOption = {
|
|
9
10
|
value: string;
|
|
10
11
|
label: string;
|
|
11
12
|
abbrev?: string;
|
|
12
13
|
altName?: string;
|
|
13
14
|
offset?: number;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
type ITimezone = ITimezoneOption | string;
|
|
17
|
+
type TimezoneSelectOptions = {
|
|
17
18
|
labelStyle?: ILabelStyle;
|
|
18
19
|
displayValue?: IDisplayValue;
|
|
19
20
|
timezones?: ICustomTimezone;
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
|
|
22
23
|
value: ITimezone;
|
|
23
24
|
onChange?: (timezone: ITimezone) => void;
|
|
24
25
|
};
|
|
@@ -29,6 +30,6 @@ declare function useTimezoneSelect({ timezones, labelStyle, displayValue, }: Tim
|
|
|
29
30
|
parseTimezone: (zone: ITimezone) => ITimezoneOption;
|
|
30
31
|
options: ITimezoneOption[];
|
|
31
32
|
};
|
|
32
|
-
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, ...props }: Props) => JSX.Element;
|
|
33
|
+
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, ...props }: Props) => react_jsx_runtime_js.JSX.Element;
|
|
33
34
|
|
|
34
35
|
export { ILabelStyle, ITimezone, ITimezoneOption, Props, TimezoneSelectOptions, allTimezones, TimezoneSelect as default, useTimezoneSelect };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-timezone-select",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Usable, dynamic React Timezone Select",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && pnpm dev\"",
|
|
7
7
|
"prepublishOnly": "pnpm run build",
|
|
8
8
|
"postpublish": "pnpm run build:example && npm run deploy",
|
|
9
|
-
"build": "tsup src/index.tsx --format
|
|
9
|
+
"build": "tsup src/index.tsx --format esm --clean --dts",
|
|
10
10
|
"build:example": "cd example && pnpm run build",
|
|
11
11
|
"deploy": "gh-pages -d example/dist",
|
|
12
12
|
"pretest": "pnpm run build",
|
|
@@ -36,14 +36,12 @@
|
|
|
36
36
|
"package.json"
|
|
37
37
|
],
|
|
38
38
|
"type": "module",
|
|
39
|
-
"main": "./dist/index.cjs",
|
|
40
39
|
"module": "./dist/index.js",
|
|
41
40
|
"types": "./dist/index.d.ts",
|
|
42
41
|
"exports": {
|
|
43
42
|
".": {
|
|
44
43
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"import": "./dist/index.js"
|
|
46
|
-
"require": "./dist/index.cjs"
|
|
44
|
+
"import": "./dist/index.js"
|
|
47
45
|
}
|
|
48
46
|
},
|
|
49
47
|
"peerDependencies": {
|
package/dist/index.cjs
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
|
-
var __export = (target, all) => {
|
|
34
|
-
for (var name in all)
|
|
35
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
|
-
};
|
|
37
|
-
var __copyProps = (to, from, except, desc) => {
|
|
38
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
-
for (let key of __getOwnPropNames(from))
|
|
40
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
41
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
42
|
-
}
|
|
43
|
-
return to;
|
|
44
|
-
};
|
|
45
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
46
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
47
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
48
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
49
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
50
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
51
|
-
mod
|
|
52
|
-
));
|
|
53
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
54
|
-
|
|
55
|
-
// src/index.tsx
|
|
56
|
-
var src_exports = {};
|
|
57
|
-
__export(src_exports, {
|
|
58
|
-
allTimezones: () => timezone_list_default,
|
|
59
|
-
default: () => TimezoneSelect,
|
|
60
|
-
useTimezoneSelect: () => useTimezoneSelect
|
|
61
|
-
});
|
|
62
|
-
module.exports = __toCommonJS(src_exports);
|
|
63
|
-
var import_react = require("react");
|
|
64
|
-
var import_react_select = __toESM(require("react-select"), 1);
|
|
65
|
-
var import_spacetime = __toESM(require("spacetime"), 1);
|
|
66
|
-
var import_timezone_soft = __toESM(require("timezone-soft"), 1);
|
|
67
|
-
|
|
68
|
-
// src/timezone-list.ts
|
|
69
|
-
var allTimezones = {
|
|
70
|
-
"Pacific/Midway": "Midway Island, Samoa",
|
|
71
|
-
"Pacific/Honolulu": "Hawaii",
|
|
72
|
-
"America/Juneau": "Alaska",
|
|
73
|
-
"America/Boise": "Mountain Time",
|
|
74
|
-
"America/Dawson": "Dawson, Yukon",
|
|
75
|
-
"America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
|
|
76
|
-
"America/Phoenix": "Arizona",
|
|
77
|
-
"America/Chicago": "Central Time",
|
|
78
|
-
"America/Regina": "Saskatchewan",
|
|
79
|
-
"America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
|
|
80
|
-
"America/Belize": "Central America",
|
|
81
|
-
"America/Detroit": "Eastern Time",
|
|
82
|
-
"America/Bogota": "Bogota, Lima, Quito",
|
|
83
|
-
"America/Caracas": "Caracas, La Paz",
|
|
84
|
-
"America/Santiago": "Santiago",
|
|
85
|
-
"America/St_Johns": "Newfoundland and Labrador",
|
|
86
|
-
"America/Sao_Paulo": "Brasilia",
|
|
87
|
-
"America/Tijuana": "Tijuana",
|
|
88
|
-
"America/Montevideo": "Montevideo",
|
|
89
|
-
"America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
|
|
90
|
-
"America/Godthab": "Greenland",
|
|
91
|
-
"America/Los_Angeles": "Pacific Time",
|
|
92
|
-
"Atlantic/Azores": "Azores",
|
|
93
|
-
"Atlantic/Cape_Verde": "Cape Verde Islands",
|
|
94
|
-
GMT: "UTC",
|
|
95
|
-
"Europe/London": "Edinburgh, London",
|
|
96
|
-
"Europe/Dublin": "Dublin",
|
|
97
|
-
"Europe/Lisbon": "Lisbon",
|
|
98
|
-
"Africa/Casablanca": "Casablanca, Monrovia",
|
|
99
|
-
"Atlantic/Canary": "Canary Islands",
|
|
100
|
-
"Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
|
|
101
|
-
"Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
|
|
102
|
-
"Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
|
|
103
|
-
"Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
|
|
104
|
-
"Africa/Algiers": "West Central Africa",
|
|
105
|
-
"Europe/Bucharest": "Bucharest",
|
|
106
|
-
"Africa/Cairo": "Cairo",
|
|
107
|
-
"Europe/Helsinki": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
|
|
108
|
-
"Europe/Athens": "Athens",
|
|
109
|
-
"Asia/Jerusalem": "Jerusalem",
|
|
110
|
-
"Africa/Harare": "Harare, Pretoria",
|
|
111
|
-
"Europe/Moscow": "Istanbul, Minsk, Moscow, St. Petersburg, Volgograd",
|
|
112
|
-
"Asia/Kuwait": "Kuwait, Riyadh",
|
|
113
|
-
"Africa/Nairobi": "Nairobi",
|
|
114
|
-
"Asia/Baghdad": "Baghdad",
|
|
115
|
-
"Asia/Tehran": "Tehran",
|
|
116
|
-
"Asia/Dubai": "Abu Dhabi, Muscat",
|
|
117
|
-
"Asia/Baku": "Baku, Tbilisi, Yerevan",
|
|
118
|
-
"Asia/Kabul": "Kabul",
|
|
119
|
-
"Asia/Yekaterinburg": "Ekaterinburg",
|
|
120
|
-
"Asia/Karachi": "Islamabad, Karachi, Tashkent",
|
|
121
|
-
"Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
|
|
122
|
-
"Asia/Kathmandu": "Kathmandu",
|
|
123
|
-
"Asia/Dhaka": "Astana, Dhaka",
|
|
124
|
-
"Asia/Colombo": "Sri Jayawardenepura",
|
|
125
|
-
"Asia/Almaty": "Almaty, Novosibirsk",
|
|
126
|
-
"Asia/Rangoon": "Yangon Rangoon",
|
|
127
|
-
"Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
|
|
128
|
-
"Asia/Krasnoyarsk": "Krasnoyarsk",
|
|
129
|
-
"Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
|
|
130
|
-
"Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
|
|
131
|
-
"Asia/Taipei": "Taipei",
|
|
132
|
-
"Australia/Perth": "Perth",
|
|
133
|
-
"Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
|
|
134
|
-
"Asia/Seoul": "Seoul",
|
|
135
|
-
"Asia/Tokyo": "Osaka, Sapporo, Tokyo",
|
|
136
|
-
"Asia/Yakutsk": "Yakutsk",
|
|
137
|
-
"Australia/Darwin": "Darwin",
|
|
138
|
-
"Australia/Adelaide": "Adelaide",
|
|
139
|
-
"Australia/Sydney": "Canberra, Melbourne, Sydney",
|
|
140
|
-
"Australia/Brisbane": "Brisbane",
|
|
141
|
-
"Australia/Hobart": "Hobart",
|
|
142
|
-
"Asia/Vladivostok": "Vladivostok",
|
|
143
|
-
"Pacific/Guam": "Guam, Port Moresby",
|
|
144
|
-
"Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
|
|
145
|
-
"Asia/Kamchatka": "Kamchatka, Marshall Islands",
|
|
146
|
-
"Pacific/Fiji": "Fiji Islands",
|
|
147
|
-
"Pacific/Auckland": "Auckland, Wellington",
|
|
148
|
-
"Pacific/Tongatapu": "Nuku'alofa"
|
|
149
|
-
};
|
|
150
|
-
var timezone_list_default = allTimezones;
|
|
151
|
-
|
|
152
|
-
// src/index.tsx
|
|
153
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
154
|
-
function useTimezoneSelect({
|
|
155
|
-
timezones = timezone_list_default,
|
|
156
|
-
labelStyle = "original",
|
|
157
|
-
displayValue = "GMT"
|
|
158
|
-
}) {
|
|
159
|
-
const options = (0, import_react.useMemo)(() => {
|
|
160
|
-
return Object.entries(timezones).map((zone) => {
|
|
161
|
-
var _a, _b, _c, _d;
|
|
162
|
-
try {
|
|
163
|
-
const now = import_spacetime.default.now(zone[0]);
|
|
164
|
-
const isDstString = now.isDST() ? "daylight" : "standard";
|
|
165
|
-
const tz = now.timezone();
|
|
166
|
-
const tzStrings = (0, import_timezone_soft.default)(zone[0]);
|
|
167
|
-
const abbr = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a[isDstString]) == null ? void 0 : _b.abbr;
|
|
168
|
-
const altName = (_d = (_c = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _c[isDstString]) == null ? void 0 : _d.name;
|
|
169
|
-
const min = tz.current.offset * 60;
|
|
170
|
-
const hr = `${min / 60 ^ 0}:${min % 60 === 0 ? "00" : Math.abs(min % 60)}`;
|
|
171
|
-
const prefix = `(${displayValue}${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
172
|
-
let label = "";
|
|
173
|
-
switch (labelStyle) {
|
|
174
|
-
case "original":
|
|
175
|
-
label = prefix;
|
|
176
|
-
break;
|
|
177
|
-
case "altName":
|
|
178
|
-
label = `${prefix} ${altName ? `(${altName})` : ""}`;
|
|
179
|
-
break;
|
|
180
|
-
case "abbrev":
|
|
181
|
-
label = `${prefix} (${abbr})`;
|
|
182
|
-
break;
|
|
183
|
-
case "offsetHidden":
|
|
184
|
-
label = `${prefix.replace(/^\(.*?\)\s*/, "")}`;
|
|
185
|
-
break;
|
|
186
|
-
default:
|
|
187
|
-
label = `${prefix}`;
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
value: tz.name,
|
|
191
|
-
label,
|
|
192
|
-
offset: tz.current.offset,
|
|
193
|
-
abbrev: abbr,
|
|
194
|
-
altName
|
|
195
|
-
};
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}).filter(Boolean).sort((a, b) => a.offset - b.offset);
|
|
200
|
-
}, [labelStyle, timezones]);
|
|
201
|
-
const findFuzzyTz = (zone) => {
|
|
202
|
-
let currentTime;
|
|
203
|
-
try {
|
|
204
|
-
currentTime = import_spacetime.default.now(zone);
|
|
205
|
-
} catch (err) {
|
|
206
|
-
currentTime = import_spacetime.default.now("GMT");
|
|
207
|
-
}
|
|
208
|
-
return options.filter(
|
|
209
|
-
(tz) => tz.offset === currentTime.timezone().current.offset
|
|
210
|
-
).map((tz) => {
|
|
211
|
-
let score = 0;
|
|
212
|
-
if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
|
|
213
|
-
if (tz.value.toLowerCase().indexOf(
|
|
214
|
-
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
215
|
-
) !== -1) {
|
|
216
|
-
score += 8;
|
|
217
|
-
}
|
|
218
|
-
if (tz.label.toLowerCase().indexOf(
|
|
219
|
-
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
220
|
-
) !== -1) {
|
|
221
|
-
score += 4;
|
|
222
|
-
}
|
|
223
|
-
if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf("/")))) {
|
|
224
|
-
score += 2;
|
|
225
|
-
}
|
|
226
|
-
score += 1;
|
|
227
|
-
} else if (tz.value === "GMT") {
|
|
228
|
-
score += 1;
|
|
229
|
-
}
|
|
230
|
-
return { tz, score };
|
|
231
|
-
}).sort((a, b) => b.score - a.score)[0].tz;
|
|
232
|
-
};
|
|
233
|
-
const parseTimezone = (zone) => {
|
|
234
|
-
if (typeof zone === "object" && zone.value && zone.label)
|
|
235
|
-
return zone;
|
|
236
|
-
if (typeof zone === "string") {
|
|
237
|
-
return options.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
|
|
238
|
-
} else if (zone.value && !zone.label) {
|
|
239
|
-
return options.find((tz) => tz.value === zone.value);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
return { options, parseTimezone };
|
|
243
|
-
}
|
|
244
|
-
var TimezoneSelect = (_a) => {
|
|
245
|
-
var _b = _a, {
|
|
246
|
-
value,
|
|
247
|
-
onBlur,
|
|
248
|
-
onChange,
|
|
249
|
-
labelStyle,
|
|
250
|
-
displayValue,
|
|
251
|
-
timezones
|
|
252
|
-
} = _b, props = __objRest(_b, [
|
|
253
|
-
"value",
|
|
254
|
-
"onBlur",
|
|
255
|
-
"onChange",
|
|
256
|
-
"labelStyle",
|
|
257
|
-
"displayValue",
|
|
258
|
-
"timezones"
|
|
259
|
-
]);
|
|
260
|
-
const { options, parseTimezone } = useTimezoneSelect({
|
|
261
|
-
timezones,
|
|
262
|
-
labelStyle,
|
|
263
|
-
displayValue
|
|
264
|
-
});
|
|
265
|
-
const handleChange = (tz) => {
|
|
266
|
-
onChange && onChange(tz);
|
|
267
|
-
};
|
|
268
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
269
|
-
import_react_select.default,
|
|
270
|
-
__spreadValues({
|
|
271
|
-
value: parseTimezone(value),
|
|
272
|
-
onChange: handleChange,
|
|
273
|
-
options,
|
|
274
|
-
onBlur
|
|
275
|
-
}, props)
|
|
276
|
-
);
|
|
277
|
-
};
|
|
278
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
279
|
-
0 && (module.exports = {
|
|
280
|
-
allTimezones,
|
|
281
|
-
useTimezoneSelect
|
|
282
|
-
});
|