react-timezone-select 2.1.0 → 2.1.2

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/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -126,6 +126,7 @@ The above example will generate two additional choices in the select options, on
126
126
  - `onBlur` - `() => void`
127
127
  - `onChange` - `(timezone) => void`
128
128
  - `labelStyle` - `'original' | 'altName' | 'abbrev'`
129
+ - `displayValue` - `'GMT' | 'UTC'`
129
130
  - `timezones` - `Record<string,string>`
130
131
  ```
131
132
  timezones={{
package/dist/index.cjs CHANGED
@@ -2,8 +2,34 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
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
+ };
7
33
  var __export = (target, all) => {
8
34
  for (var name in all)
9
35
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -79,10 +105,10 @@ var allTimezones = {
79
105
  "Europe/Bucharest": "Bucharest",
80
106
  "Africa/Cairo": "Cairo",
81
107
  "Europe/Helsinki": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
82
- "Europe/Athens": "Athens, Minsk",
108
+ "Europe/Athens": "Athens",
83
109
  "Asia/Jerusalem": "Jerusalem",
84
110
  "Africa/Harare": "Harare, Pretoria",
85
- "Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
111
+ "Europe/Moscow": "Istanbul, Minsk, Moscow, St. Petersburg, Volgograd",
86
112
  "Asia/Kuwait": "Kuwait, Riyadh",
87
113
  "Africa/Nairobi": "Nairobi",
88
114
  "Asia/Baghdad": "Baghdad",
@@ -127,24 +153,26 @@ var timezone_list_default = allTimezones;
127
153
  function useTimezoneSelect({
128
154
  timezones = timezone_list_default,
129
155
  labelStyle = "original",
156
+ displayValue = "GMT",
130
157
  maxAbbrLength = 4
131
158
  }) {
132
159
  const options = React.useMemo(() => {
133
160
  return Object.entries(timezones).map((zone) => {
161
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
134
162
  try {
135
163
  const now = import_spacetime.default.now(zone[0]);
136
164
  const tz = now.timezone();
137
165
  const tzStrings = (0, import_timezone_soft.default)(zone[0]);
138
166
  let label = "";
139
- const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
140
- const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
167
+ const standardAbbr = (_c = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a.standard) == null ? void 0 : _b.abbr) != null ? _c : "";
168
+ const dstAbbr = (_f = (_e = (_d = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _d.daylight) == null ? void 0 : _e.abbr) != null ? _f : standardAbbr;
141
169
  let abbr = now.isDST() ? dstAbbr : standardAbbr;
142
- const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
143
- const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
170
+ const standardAltName = (_i = (_h = (_g = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _g.standard) == null ? void 0 : _h.name) != null ? _i : "";
171
+ const dstAltName = (_l = (_k = (_j = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _j.daylight) == null ? void 0 : _k.name) != null ? _l : standardAltName;
144
172
  let altName = now.isDST() ? dstAltName : standardAltName;
145
173
  const min = tz.current.offset * 60;
146
174
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
147
- const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
175
+ const prefix = `(${displayValue}${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
148
176
  switch (labelStyle) {
149
177
  case "original":
150
178
  label = prefix;
@@ -165,7 +193,7 @@ function useTimezoneSelect({
165
193
  abbrev: abbr,
166
194
  altName
167
195
  };
168
- } catch {
196
+ } catch (e) {
169
197
  return null;
170
198
  }
171
199
  }).filter(Boolean).sort((a, b) => a.offset - b.offset);
@@ -213,18 +241,28 @@ function useTimezoneSelect({
213
241
  };
214
242
  return { options, parseTimezone };
215
243
  }
216
- var TimezoneSelect = ({
217
- value,
218
- onBlur,
219
- onChange,
220
- labelStyle,
221
- maxAbbrLength,
222
- timezones,
223
- ...props
224
- }) => {
244
+ var TimezoneSelect = (_a) => {
245
+ var _b = _a, {
246
+ value,
247
+ onBlur,
248
+ onChange,
249
+ labelStyle,
250
+ displayValue,
251
+ maxAbbrLength,
252
+ timezones
253
+ } = _b, props = __objRest(_b, [
254
+ "value",
255
+ "onBlur",
256
+ "onChange",
257
+ "labelStyle",
258
+ "displayValue",
259
+ "maxAbbrLength",
260
+ "timezones"
261
+ ]);
225
262
  const { options, parseTimezone } = useTimezoneSelect({
226
263
  timezones,
227
264
  labelStyle,
265
+ displayValue,
228
266
  maxAbbrLength
229
267
  });
230
268
  const handleChange = (tz) => {
@@ -232,13 +270,12 @@ var TimezoneSelect = ({
232
270
  };
233
271
  return /* @__PURE__ */ React.createElement(
234
272
  import_react_select.default,
235
- {
273
+ __spreadValues({
236
274
  value: parseTimezone(value),
237
275
  onChange: handleChange,
238
276
  options,
239
- onBlur,
240
- ...props
241
- }
277
+ onBlur
278
+ }, props)
242
279
  );
243
280
  };
244
281
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ declare type ICustomTimezone = {
4
4
  [key: string]: string;
5
5
  };
6
6
  declare type ILabelStyle = 'original' | 'altName' | 'abbrev';
7
+ declare type IDisplayValue = 'GMT' | 'UTC';
7
8
  declare type ITimezoneOption = {
8
9
  value: string;
9
10
  label: string;
@@ -14,6 +15,7 @@ declare type ITimezoneOption = {
14
15
  declare type ITimezone = ITimezoneOption | string;
15
16
  declare type TimezoneSelectOptions = {
16
17
  labelStyle?: ILabelStyle;
18
+ displayValue?: IDisplayValue;
17
19
  timezones?: ICustomTimezone;
18
20
  maxAbbrLength?: number;
19
21
  };
@@ -24,10 +26,10 @@ declare type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelec
24
26
 
25
27
  declare const allTimezones: ICustomTimezone;
26
28
 
27
- declare function useTimezoneSelect({ timezones, labelStyle, maxAbbrLength, }: TimezoneSelectOptions): {
29
+ declare function useTimezoneSelect({ timezones, labelStyle, displayValue, maxAbbrLength, }: TimezoneSelectOptions): {
28
30
  parseTimezone: (zone: ITimezone) => ITimezoneOption;
29
31
  options: ITimezoneOption[];
30
32
  };
31
- declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, maxAbbrLength, timezones, ...props }: Props) => JSX.Element;
33
+ declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, maxAbbrLength, timezones, ...props }: Props) => JSX.Element;
32
34
 
33
35
  export { ILabelStyle, ITimezone, ITimezoneOption, Props, TimezoneSelectOptions, allTimezones, TimezoneSelect as default, useTimezoneSelect };
package/dist/index.js CHANGED
@@ -1,3 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+
1
30
  // src/index.tsx
2
31
  import * as React from "react";
3
32
  import Select from "react-select";
@@ -44,10 +73,10 @@ var allTimezones = {
44
73
  "Europe/Bucharest": "Bucharest",
45
74
  "Africa/Cairo": "Cairo",
46
75
  "Europe/Helsinki": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
47
- "Europe/Athens": "Athens, Minsk",
76
+ "Europe/Athens": "Athens",
48
77
  "Asia/Jerusalem": "Jerusalem",
49
78
  "Africa/Harare": "Harare, Pretoria",
50
- "Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
79
+ "Europe/Moscow": "Istanbul, Minsk, Moscow, St. Petersburg, Volgograd",
51
80
  "Asia/Kuwait": "Kuwait, Riyadh",
52
81
  "Africa/Nairobi": "Nairobi",
53
82
  "Asia/Baghdad": "Baghdad",
@@ -92,24 +121,26 @@ var timezone_list_default = allTimezones;
92
121
  function useTimezoneSelect({
93
122
  timezones = timezone_list_default,
94
123
  labelStyle = "original",
124
+ displayValue = "GMT",
95
125
  maxAbbrLength = 4
96
126
  }) {
97
127
  const options = React.useMemo(() => {
98
128
  return Object.entries(timezones).map((zone) => {
129
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
99
130
  try {
100
131
  const now = spacetime.now(zone[0]);
101
132
  const tz = now.timezone();
102
133
  const tzStrings = soft(zone[0]);
103
134
  let label = "";
104
- const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
105
- const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
135
+ const standardAbbr = (_c = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a.standard) == null ? void 0 : _b.abbr) != null ? _c : "";
136
+ const dstAbbr = (_f = (_e = (_d = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _d.daylight) == null ? void 0 : _e.abbr) != null ? _f : standardAbbr;
106
137
  let abbr = now.isDST() ? dstAbbr : standardAbbr;
107
- const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
108
- const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
138
+ const standardAltName = (_i = (_h = (_g = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _g.standard) == null ? void 0 : _h.name) != null ? _i : "";
139
+ const dstAltName = (_l = (_k = (_j = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _j.daylight) == null ? void 0 : _k.name) != null ? _l : standardAltName;
109
140
  let altName = now.isDST() ? dstAltName : standardAltName;
110
141
  const min = tz.current.offset * 60;
111
142
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
112
- const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
143
+ const prefix = `(${displayValue}${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
113
144
  switch (labelStyle) {
114
145
  case "original":
115
146
  label = prefix;
@@ -130,7 +161,7 @@ function useTimezoneSelect({
130
161
  abbrev: abbr,
131
162
  altName
132
163
  };
133
- } catch {
164
+ } catch (e) {
134
165
  return null;
135
166
  }
136
167
  }).filter(Boolean).sort((a, b) => a.offset - b.offset);
@@ -178,18 +209,28 @@ function useTimezoneSelect({
178
209
  };
179
210
  return { options, parseTimezone };
180
211
  }
181
- var TimezoneSelect = ({
182
- value,
183
- onBlur,
184
- onChange,
185
- labelStyle,
186
- maxAbbrLength,
187
- timezones,
188
- ...props
189
- }) => {
212
+ var TimezoneSelect = (_a) => {
213
+ var _b = _a, {
214
+ value,
215
+ onBlur,
216
+ onChange,
217
+ labelStyle,
218
+ displayValue,
219
+ maxAbbrLength,
220
+ timezones
221
+ } = _b, props = __objRest(_b, [
222
+ "value",
223
+ "onBlur",
224
+ "onChange",
225
+ "labelStyle",
226
+ "displayValue",
227
+ "maxAbbrLength",
228
+ "timezones"
229
+ ]);
190
230
  const { options, parseTimezone } = useTimezoneSelect({
191
231
  timezones,
192
232
  labelStyle,
233
+ displayValue,
193
234
  maxAbbrLength
194
235
  });
195
236
  const handleChange = (tz) => {
@@ -197,13 +238,12 @@ var TimezoneSelect = ({
197
238
  };
198
239
  return /* @__PURE__ */ React.createElement(
199
240
  Select,
200
- {
241
+ __spreadValues({
201
242
  value: parseTimezone(value),
202
243
  onChange: handleChange,
203
244
  options,
204
- onBlur,
205
- ...props
206
- }
245
+ onBlur
246
+ }, props)
207
247
  );
208
248
  };
209
249
  export {
package/package.json CHANGED
@@ -1,20 +1,7 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
- "scripts": {
6
- "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && pnpm dev\"",
7
- "prepublishOnly": "pnpm run build",
8
- "postpublish": "pnpm run build:example && npm run deploy",
9
- "build": "tsup src/index.tsx --format cjs,esm --dts",
10
- "build:example": "cd example && pnpm run build",
11
- "deploy": "gh-pages -d example/dist",
12
- "pretest": "pnpm run build",
13
- "test": "jest",
14
- "test:watch": "jest --watch",
15
- "test:ci": "pnpm run build && jest --ci ",
16
- "tsc": "tsc"
17
- },
18
5
  "author": "Nico Domino <yo@ndo.dev>",
19
6
  "homepage": "https://github.com/ndom91/react-timezone-select",
20
7
  "repository": {
@@ -114,5 +101,16 @@
114
101
  "*.{js,jsx}": [
115
102
  "eslint --fix"
116
103
  ]
104
+ },
105
+ "scripts": {
106
+ "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && pnpm dev\"",
107
+ "build": "tsup src/index.tsx --format cjs,esm --dts",
108
+ "build:example": "cd example && pnpm run build",
109
+ "deploy": "gh-pages -d example/dist",
110
+ "pretest": "pnpm run build",
111
+ "test": "jest",
112
+ "test:watch": "jest --watch",
113
+ "test:ci": "pnpm run build && jest --ci ",
114
+ "tsc": "tsc"
117
115
  }
118
- }
116
+ }