react-timezone-select 2.1.0 → 2.1.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 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 });
@@ -131,16 +157,17 @@ function useTimezoneSelect({
131
157
  }) {
132
158
  const options = React.useMemo(() => {
133
159
  return Object.entries(timezones).map((zone) => {
160
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
134
161
  try {
135
162
  const now = import_spacetime.default.now(zone[0]);
136
163
  const tz = now.timezone();
137
164
  const tzStrings = (0, import_timezone_soft.default)(zone[0]);
138
165
  let label = "";
139
- const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
140
- const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
166
+ const standardAbbr = (_c = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a.standard) == null ? void 0 : _b.abbr) != null ? _c : "";
167
+ 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
168
  let abbr = now.isDST() ? dstAbbr : standardAbbr;
142
- const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
143
- const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
169
+ const standardAltName = (_i = (_h = (_g = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _g.standard) == null ? void 0 : _h.name) != null ? _i : "";
170
+ 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
171
  let altName = now.isDST() ? dstAltName : standardAltName;
145
172
  const min = tz.current.offset * 60;
146
173
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
@@ -165,7 +192,7 @@ function useTimezoneSelect({
165
192
  abbrev: abbr,
166
193
  altName
167
194
  };
168
- } catch {
195
+ } catch (e) {
169
196
  return null;
170
197
  }
171
198
  }).filter(Boolean).sort((a, b) => a.offset - b.offset);
@@ -213,15 +240,22 @@ function useTimezoneSelect({
213
240
  };
214
241
  return { options, parseTimezone };
215
242
  }
216
- var TimezoneSelect = ({
217
- value,
218
- onBlur,
219
- onChange,
220
- labelStyle,
221
- maxAbbrLength,
222
- timezones,
223
- ...props
224
- }) => {
243
+ var TimezoneSelect = (_a) => {
244
+ var _b = _a, {
245
+ value,
246
+ onBlur,
247
+ onChange,
248
+ labelStyle,
249
+ maxAbbrLength,
250
+ timezones
251
+ } = _b, props = __objRest(_b, [
252
+ "value",
253
+ "onBlur",
254
+ "onChange",
255
+ "labelStyle",
256
+ "maxAbbrLength",
257
+ "timezones"
258
+ ]);
225
259
  const { options, parseTimezone } = useTimezoneSelect({
226
260
  timezones,
227
261
  labelStyle,
@@ -232,13 +266,12 @@ var TimezoneSelect = ({
232
266
  };
233
267
  return /* @__PURE__ */ React.createElement(
234
268
  import_react_select.default,
235
- {
269
+ __spreadValues({
236
270
  value: parseTimezone(value),
237
271
  onChange: handleChange,
238
272
  options,
239
- onBlur,
240
- ...props
241
- }
273
+ onBlur
274
+ }, props)
242
275
  );
243
276
  };
244
277
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
1
  import { Props as Props$1 } from 'react-select';
2
2
 
3
- declare type ICustomTimezone = {
3
+ type ICustomTimezone = {
4
4
  [key: string]: string;
5
5
  };
6
- declare type ILabelStyle = 'original' | 'altName' | 'abbrev';
7
- declare type ITimezoneOption = {
6
+ type ILabelStyle = 'original' | 'altName' | 'abbrev';
7
+ type ITimezoneOption = {
8
8
  value: string;
9
9
  label: string;
10
10
  abbrev?: string;
11
11
  altName?: string;
12
12
  offset?: number;
13
13
  };
14
- declare type ITimezone = ITimezoneOption | string;
15
- declare type TimezoneSelectOptions = {
14
+ type ITimezone = ITimezoneOption | string;
15
+ type TimezoneSelectOptions = {
16
16
  labelStyle?: ILabelStyle;
17
17
  timezones?: ICustomTimezone;
18
18
  maxAbbrLength?: number;
19
19
  };
20
- declare type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
20
+ type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
21
21
  value: ITimezone;
22
22
  onChange?: (timezone: ITimezoneOption) => void;
23
23
  };
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7
+ <meta name="theme-color" content="#000000">
8
+ <!--
9
+ manifest.json provides metadata used when your web app is added to the
10
+ homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
11
+ -->
12
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
13
+ <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
14
+ <!--
15
+ Notice the use of %PUBLIC_URL% in the tags above.
16
+ It will be replaced with the URL of the `public` folder during the build.
17
+ Only files inside the `public` folder can be referenced from the HTML.
18
+
19
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
20
+ work correctly both with client-side routing and a non-root public URL.
21
+ Learn how to configure a non-root public URL by running `npm run build`.
22
+ -->
23
+ <title>React App</title>
24
+ </head>
25
+
26
+ <body>
27
+ <noscript>
28
+ You need to enable JavaScript to run this app.
29
+ </noscript>
30
+ <div id="root"></div>
31
+ <!--
32
+ This HTML file is a template.
33
+ If you open it directly in the browser, you will see an empty page.
34
+
35
+ You can add webfonts, meta tags, or analytics to this file.
36
+ The build step will place the bundled scripts into the <body> tag.
37
+
38
+ To begin the development, run `npm start` or `yarn start`.
39
+ To create a production bundle, use `npm run build` or `yarn build`.
40
+ -->
41
+ </body>
42
+
43
+ </html>
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";
@@ -96,16 +125,17 @@ function useTimezoneSelect({
96
125
  }) {
97
126
  const options = React.useMemo(() => {
98
127
  return Object.entries(timezones).map((zone) => {
128
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
99
129
  try {
100
130
  const now = spacetime.now(zone[0]);
101
131
  const tz = now.timezone();
102
132
  const tzStrings = soft(zone[0]);
103
133
  let label = "";
104
- const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
105
- const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
134
+ const standardAbbr = (_c = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a.standard) == null ? void 0 : _b.abbr) != null ? _c : "";
135
+ 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
136
  let abbr = now.isDST() ? dstAbbr : standardAbbr;
107
- const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
108
- const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
137
+ const standardAltName = (_i = (_h = (_g = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _g.standard) == null ? void 0 : _h.name) != null ? _i : "";
138
+ 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
139
  let altName = now.isDST() ? dstAltName : standardAltName;
110
140
  const min = tz.current.offset * 60;
111
141
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
@@ -130,7 +160,7 @@ function useTimezoneSelect({
130
160
  abbrev: abbr,
131
161
  altName
132
162
  };
133
- } catch {
163
+ } catch (e) {
134
164
  return null;
135
165
  }
136
166
  }).filter(Boolean).sort((a, b) => a.offset - b.offset);
@@ -178,15 +208,22 @@ function useTimezoneSelect({
178
208
  };
179
209
  return { options, parseTimezone };
180
210
  }
181
- var TimezoneSelect = ({
182
- value,
183
- onBlur,
184
- onChange,
185
- labelStyle,
186
- maxAbbrLength,
187
- timezones,
188
- ...props
189
- }) => {
211
+ var TimezoneSelect = (_a) => {
212
+ var _b = _a, {
213
+ value,
214
+ onBlur,
215
+ onChange,
216
+ labelStyle,
217
+ maxAbbrLength,
218
+ timezones
219
+ } = _b, props = __objRest(_b, [
220
+ "value",
221
+ "onBlur",
222
+ "onChange",
223
+ "labelStyle",
224
+ "maxAbbrLength",
225
+ "timezones"
226
+ ]);
190
227
  const { options, parseTimezone } = useTimezoneSelect({
191
228
  timezones,
192
229
  labelStyle,
@@ -197,13 +234,12 @@ var TimezoneSelect = ({
197
234
  };
198
235
  return /* @__PURE__ */ React.createElement(
199
236
  Select,
200
- {
237
+ __spreadValues({
201
238
  value: parseTimezone(value),
202
239
  onChange: handleChange,
203
240
  options,
204
- onBlur,
205
- ...props
206
- }
241
+ onBlur
242
+ }, props)
207
243
  );
208
244
  };
209
245
  export {
@@ -0,0 +1,26 @@
1
+ * {
2
+ font-family: Helvetica;
3
+ }
4
+
5
+ .App {
6
+ display: flex;
7
+ align-items: center;
8
+ flex-direction: column;
9
+ }
10
+
11
+ .select-wrapper {
12
+ margin-top: 50px;
13
+ width: 500px;
14
+ }
15
+
16
+ .code,
17
+ .code span {
18
+ background-color: #efefef;
19
+ font-family: monospace;
20
+ }
21
+
22
+ .code {
23
+ padding: 10px;
24
+ line-height: 2;
25
+ font-size: 1.4rem;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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\"",