react-timezone-select 1.5.6 → 2.0.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/README.md CHANGED
@@ -23,7 +23,7 @@ We also have some **more examples** available on Codesandbox using this componen
23
23
  ## 🏗️ Installing
24
24
 
25
25
  ```bash
26
- npm install react-timezone-select
26
+ npm install react-select react-timezone-select
27
27
  ```
28
28
 
29
29
  ## 🔭 Usage
package/dist/index.cjs CHANGED
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
32
  allTimezones: () => timezone_list_default,
33
- default: () => src_default
33
+ default: () => TimezoneSelect
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
36
  var React = __toESM(require("react"), 1);
@@ -128,21 +128,23 @@ var TimezoneSelect = ({
128
128
  onBlur,
129
129
  onChange,
130
130
  labelStyle = "original",
131
- timezones,
131
+ timezones = timezone_list_default,
132
132
  maxAbbrLength = 4,
133
133
  ...props
134
134
  }) => {
135
- if (!timezones)
136
- timezones = timezone_list_default;
137
- const getOptions = React.useMemo(() => {
138
- return Object.entries(timezones).reduce((selectOptions, zone) => {
135
+ const getOptions = React.useMemo(
136
+ () => Object.entries(timezones).reduce((selectOptions, zone) => {
139
137
  try {
140
138
  const now = import_spacetime.default.now(zone[0]);
141
139
  const tz = now.timezone();
142
140
  const tzStrings = (0, import_timezone_soft.default)(zone[0]);
143
141
  let label = "";
144
- let abbr = now.isDST() ? tzStrings[0].daylight.abbr : tzStrings[0].standard.abbr;
145
- let altName = now.isDST() ? tzStrings[0].daylight.name : tzStrings[0].standard.name;
142
+ const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
143
+ const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
144
+ let abbr = now.isDST() ? dstAbbr : standardAbbr;
145
+ const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
146
+ const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
147
+ let altName = now.isDST() ? dstAltName : standardAltName;
146
148
  const min = tz.current.offset * 60;
147
149
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
148
150
  const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
@@ -151,7 +153,7 @@ var TimezoneSelect = ({
151
153
  label = prefix;
152
154
  break;
153
155
  case "altName":
154
- label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
156
+ label = `${prefix} ${altName ? `(${altName})` : ""}`;
155
157
  break;
156
158
  case "abbrev":
157
159
  label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
@@ -170,8 +172,9 @@ var TimezoneSelect = ({
170
172
  } catch {
171
173
  return selectOptions;
172
174
  }
173
- }, []).sort((a, b) => a.offset - b.offset);
174
- }, [labelStyle, timezones]);
175
+ }, []).sort((a, b) => a.offset - b.offset),
176
+ [labelStyle, timezones]
177
+ );
175
178
  const handleChange = (tz) => {
176
179
  onChange && onChange(tz);
177
180
  };
@@ -227,7 +230,6 @@ var TimezoneSelect = ({
227
230
  }
228
231
  );
229
232
  };
230
- var src_default = TimezoneSelect;
231
233
  // Annotate the CommonJS export names for ESM import in node:
232
234
  0 && (module.exports = {
233
235
  allTimezones
package/dist/index.d.ts CHANGED
@@ -1,36 +1,27 @@
1
1
  import { Props as Props$1 } from 'react-select';
2
2
 
3
3
  declare type ICustomTimezone = {
4
- [key: string]: string
5
- }
6
- declare type ILabelStyle = 'original' | 'altName' | 'abbrev'
4
+ [key: string]: string;
5
+ };
6
+ declare type ILabelStyle = 'original' | 'altName' | 'abbrev';
7
7
  interface ITimezoneOption {
8
- value: string
9
- label: string
10
- offset: number
11
- abbrev?: string
12
- altName?: string
8
+ value: string;
9
+ label: string;
10
+ abbrev?: string;
11
+ altName?: string;
12
+ offset?: number;
13
13
  }
14
- declare type ITimezone = ITimezoneOption | string
15
- interface Props
16
- extends Omit<Props$1<ITimezone, false>, 'onChange'> {
17
- value: ITimezone
18
- labelStyle?: ILabelStyle
19
- onChange?: (timezone: ITimezoneOption) => void
20
- timezones?: ICustomTimezone
21
- maxAbbrLength?: number
14
+ declare type ITimezone = ITimezoneOption | string;
15
+ interface Props extends Omit<Props$1<ITimezone, false>, 'onChange'> {
16
+ value: ITimezone;
17
+ labelStyle?: ILabelStyle;
18
+ onChange?: (timezone: ITimezoneOption) => void;
19
+ timezones?: ICustomTimezone;
20
+ maxAbbrLength?: number;
22
21
  }
23
22
 
24
23
  declare const allTimezones: ICustomTimezone;
25
24
 
26
- declare const TimezoneSelect: ({
27
- value,
28
- onBlur,
29
- onChange,
30
- labelStyle,
31
- timezones,
32
- maxAbbrLength,
33
- ...props
34
- }: Props) => JSX.Element
25
+ declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, timezones, maxAbbrLength, ...props }: Props) => JSX.Element;
35
26
 
36
27
  export { ILabelStyle, ITimezone, ITimezoneOption, Props, allTimezones, TimezoneSelect as default };
package/dist/index.js CHANGED
@@ -94,21 +94,23 @@ var TimezoneSelect = ({
94
94
  onBlur,
95
95
  onChange,
96
96
  labelStyle = "original",
97
- timezones,
97
+ timezones = timezone_list_default,
98
98
  maxAbbrLength = 4,
99
99
  ...props
100
100
  }) => {
101
- if (!timezones)
102
- timezones = timezone_list_default;
103
- const getOptions = React.useMemo(() => {
104
- return Object.entries(timezones).reduce((selectOptions, zone) => {
101
+ const getOptions = React.useMemo(
102
+ () => Object.entries(timezones).reduce((selectOptions, zone) => {
105
103
  try {
106
104
  const now = spacetime.now(zone[0]);
107
105
  const tz = now.timezone();
108
106
  const tzStrings = soft(zone[0]);
109
107
  let label = "";
110
- let abbr = now.isDST() ? tzStrings[0].daylight.abbr : tzStrings[0].standard.abbr;
111
- let altName = now.isDST() ? tzStrings[0].daylight.name : tzStrings[0].standard.name;
108
+ const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? "";
109
+ const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr;
110
+ let abbr = now.isDST() ? dstAbbr : standardAbbr;
111
+ const standardAltName = tzStrings?.[0]?.standard?.name ?? "";
112
+ const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName;
113
+ let altName = now.isDST() ? dstAltName : standardAltName;
112
114
  const min = tz.current.offset * 60;
113
115
  const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
114
116
  const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
@@ -117,7 +119,7 @@ var TimezoneSelect = ({
117
119
  label = prefix;
118
120
  break;
119
121
  case "altName":
120
- label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
122
+ label = `${prefix} ${altName ? `(${altName})` : ""}`;
121
123
  break;
122
124
  case "abbrev":
123
125
  label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
@@ -136,8 +138,9 @@ var TimezoneSelect = ({
136
138
  } catch {
137
139
  return selectOptions;
138
140
  }
139
- }, []).sort((a, b) => a.offset - b.offset);
140
- }, [labelStyle, timezones]);
141
+ }, []).sort((a, b) => a.offset - b.offset),
142
+ [labelStyle, timezones]
143
+ );
141
144
  const handleChange = (tz) => {
142
145
  onChange && onChange(tz);
143
146
  };
@@ -193,8 +196,7 @@ var TimezoneSelect = ({
193
196
  }
194
197
  );
195
198
  };
196
- var src_default = TimezoneSelect;
197
199
  export {
198
200
  timezone_list_default as allTimezones,
199
- src_default as default
201
+ TimezoneSelect as default
200
202
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "1.5.6",
3
+ "version": "2.0.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\"",
@@ -48,10 +48,10 @@
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "^18 || ^17.0.1 || ^16",
51
- "react-dom": "^18 || ^17.0.1 || ^16"
51
+ "react-dom": "^18 || ^17.0.1 || ^16",
52
+ "react-select": "^5.7.0"
52
53
  },
53
54
  "dependencies": {
54
- "react-select": "^5.7.0",
55
55
  "spacetime": "^7.4.1",
56
56
  "timezone-soft": "^1.4.1"
57
57
  },