react-timezone-select 1.5.5 → 2.0.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/README.md CHANGED
@@ -16,7 +16,7 @@ While looking around for a good option, I had trouble finding a timezone select
16
16
 
17
17
  #### Demo: [ndom91.github.io/react-timezone-select](https://ndom91.github.io/react-timezone-select/)
18
18
 
19
- > This demo is also available in the `./examples` directory. Simply run `npm run dev` in the root of the repository after installing everything in the examples subdirectory and snowpack dev will begin, where you can find the demo at [`localhost:8080`](http://localhost:8080).
19
+ > This demo is also available in the `./examples` directory. Simply run `pnpm dev` in the root of the repository and the vite dev server will start, where you can then find the example app at [`localhost:3001`](http://localhost:3001).
20
20
 
21
21
  We also have some **more examples** available on Codesandbox using this component with the datetime library `spacetime` ([example](https://codesandbox.io/s/react-timezone-select-usage-z37hf)) as well as with `moment` ([example](https://codesandbox.io/s/react-timezone-select-usage-moment-5n6vn)), as well as in Typescript using the new `Intl` browser API ([example](https://codesandbox.io/s/react-timezone-select-typescript-8lsv3?file=/src/App.tsx)) showing how one might use this component in a real application.
22
22
 
@@ -34,7 +34,9 @@ import ReactDOM from 'react-dom'
34
34
  import TimezoneSelect from 'react-timezone-select'
35
35
 
36
36
  const App = () => {
37
- const [selectedTimezone, setSelectedTimezone] = useState({})
37
+ const [selectedTimezone, setSelectedTimezone] =useState(
38
+ Intl.DateTimeFormat().resolvedOptions().timeZone
39
+ )
38
40
 
39
41
  return (
40
42
  <div className="App">
@@ -86,22 +88,7 @@ const [timezone, setTimezone] = useState(
86
88
  )
87
89
  ```
88
90
 
89
- Thanks [@ndrwksr](https://github.com/ndom91/react-timezone-select/issues/25)!
90
-
91
- ### ⚠ Next.js Users
92
-
93
- **Update**: Starting with `v1.3.0` you DO NOT need `next-transpile-modules` to use this library with Next.js anymore!
94
-
95
- For now, Next.js isn't great about handling ESM packages. Until this gets fixed, there is a workaround for using this and other ESM packages via [`next-transpile-modules`](https://www.npmjs.com/package/next-transpile-modules).
96
-
97
- ```js
98
- // next.config.js
99
- const withTM = require('next-transpile-modules')(['react-timezone-select'])
100
-
101
- module.exports = withTM({
102
- // ...further Next.js config
103
- })
104
- ```
91
+ Thanks [@ndrwksr](https://github.com/ndom91/react-timezone-select/issues/25)
105
92
 
106
93
  ### 🕒 Custom Timezones
107
94
 
@@ -111,7 +98,7 @@ The `timezones` prop takes a dictionary of timezones. Don't worry, we'll prepend
111
98
 
112
99
  ```jsx
113
100
  import TimezoneSelect, { allTimezones } from 'react-timezone-select'
114
- ;<TimezoneSelect
101
+ <TimezoneSelect
115
102
  value={selectedTimezone}
116
103
  onChange={setSelectedTimezone}
117
104
  timezones={{
@@ -126,26 +113,34 @@ The above example will generate two additional choices in the select options, on
126
113
 
127
114
  ## đŸ•šī¸ Props
128
115
 
129
- - `value` - Initial Timezone `string`, i.e. `'Europe/Amsterdam'` or the full object from the onChange function: `{ value: string, label: string, abbrev: string, altName: string }`
116
+ - `value` - `string | Object` - Initial/current Timezone.
117
+ ```
118
+ 'America/Juneau' | {
119
+ value: 'America/Juneau'
120
+ label: '(GMT-8:00) Alaska,
121
+ abbrev: 'AHST',
122
+ offset: -8,
123
+ altName: 'Alaskan Standard Time'
124
+ }
125
+ ```
130
126
  - `onBlur` - `() => void`
131
127
  - `onChange` - `(timezone) => void`
132
- - Example `timezone` parameter:
133
- ```
134
- {
135
- value: 'America/Juneau'
136
- label: '(GMT-8:00) Alaska,
137
- abbrev: 'AHST',
138
- offset: -8,
139
- altName: 'Alaskan Standard Time'
140
- }
141
- ```
142
128
  - `labelStyle` - `'original' | 'altName' | 'abbrev'`
143
- - `timezones` - Custom Timezone Object
129
+ - `timezones` - `Record<string,string>`
130
+ ```
131
+ timezones={{
132
+ ...allTimezones,
133
+ 'America/Lima': 'Pittsburgh',
134
+ 'Europe/Berlin': 'Frankfurt',
135
+ }}
136
+ ```
137
+
138
+ - `maxAbbrLength` - `number` - Truncate `abbrev` labelStyles string to length
144
139
  - Any other [`react-select`](https://github.com/jedwatson/react-select#props) props
145
140
 
146
141
  ## 🚧 Contributing
147
142
 
148
- Pull requests are always welcome! Please stick to the `prettier` settings, and if adding new features, please consider adding test(s) and documentation where appropriate!
143
+ Pull requests are always welcome! Please stick to repo settings (prettier, eslint, etc.), and if adding new features, please consider adding test(s) and documentation where appropriate!
149
144
 
150
145
  ## 🙏 Thanks
151
146
 
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,14 +128,12 @@ 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();
@@ -170,8 +168,9 @@ var TimezoneSelect = ({
170
168
  } catch {
171
169
  return selectOptions;
172
170
  }
173
- }, []).sort((a, b) => a.offset - b.offset);
174
- }, [labelStyle, timezones]);
171
+ }, []).sort((a, b) => a.offset - b.offset),
172
+ [labelStyle, timezones]
173
+ );
175
174
  const handleChange = (tz) => {
176
175
  onChange && onChange(tz);
177
176
  };
@@ -227,7 +226,6 @@ var TimezoneSelect = ({
227
226
  }
228
227
  );
229
228
  };
230
- var src_default = TimezoneSelect;
231
229
  // Annotate the CommonJS export names for ESM import in node:
232
230
  0 && (module.exports = {
233
231
  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,14 +94,12 @@ 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();
@@ -136,8 +134,9 @@ var TimezoneSelect = ({
136
134
  } catch {
137
135
  return selectOptions;
138
136
  }
139
- }, []).sort((a, b) => a.offset - b.offset);
140
- }, [labelStyle, timezones]);
137
+ }, []).sort((a, b) => a.offset - b.offset),
138
+ [labelStyle, timezones]
139
+ );
141
140
  const handleChange = (tz) => {
142
141
  onChange && onChange(tz);
143
142
  };
@@ -193,8 +192,7 @@ var TimezoneSelect = ({
193
192
  }
194
193
  );
195
194
  };
196
- var src_default = TimezoneSelect;
197
195
  export {
198
196
  timezone_list_default as allTimezones,
199
- src_default as default
197
+ TimezoneSelect as default
200
198
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "1.5.5",
3
+ "version": "2.0.0",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
5
  "scripts": {
6
- "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && npm run dev\"",
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
9
  "build": "tsup src/index.tsx --format cjs,esm --dts",
@@ -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
  },