react-timezone-select 1.5.4 â 1.5.6
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 +27 -32
- package/dist/index.cjs +34 -35
- package/dist/index.d.ts +10 -1
- package/dist/index.js +34 -35
- package/package.json +9 -8
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 `
|
|
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] =
|
|
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
|
-
|
|
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` -
|
|
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` -
|
|
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
|
|
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
|
@@ -129,48 +129,47 @@ var TimezoneSelect = ({
|
|
|
129
129
|
onChange,
|
|
130
130
|
labelStyle = "original",
|
|
131
131
|
timezones,
|
|
132
|
+
maxAbbrLength = 4,
|
|
132
133
|
...props
|
|
133
134
|
}) => {
|
|
134
135
|
if (!timezones)
|
|
135
136
|
timezones = timezone_list_default;
|
|
136
137
|
const getOptions = React.useMemo(() => {
|
|
137
138
|
return Object.entries(timezones).reduce((selectOptions, zone) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
tzStrings[0].daylight
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
139
|
+
try {
|
|
140
|
+
const now = import_spacetime.default.now(zone[0]);
|
|
141
|
+
const tz = now.timezone();
|
|
142
|
+
const tzStrings = (0, import_timezone_soft.default)(zone[0]);
|
|
143
|
+
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;
|
|
146
|
+
const min = tz.current.offset * 60;
|
|
147
|
+
const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
|
|
148
|
+
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
149
|
+
switch (labelStyle) {
|
|
150
|
+
case "original":
|
|
151
|
+
label = prefix;
|
|
152
|
+
break;
|
|
153
|
+
case "altName":
|
|
154
|
+
label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
|
|
155
|
+
break;
|
|
156
|
+
case "abbrev":
|
|
157
|
+
label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
label = `${prefix}`;
|
|
161
|
+
}
|
|
162
|
+
selectOptions.push({
|
|
163
|
+
value: tz.name,
|
|
164
|
+
label,
|
|
165
|
+
offset: tz.current.offset,
|
|
166
|
+
abbrev: abbr,
|
|
167
|
+
altName
|
|
168
|
+
});
|
|
169
|
+
return selectOptions;
|
|
170
|
+
} catch {
|
|
171
|
+
return selectOptions;
|
|
165
172
|
}
|
|
166
|
-
selectOptions.push({
|
|
167
|
-
value: tz.name,
|
|
168
|
-
label,
|
|
169
|
-
offset: tz.current.offset,
|
|
170
|
-
abbrev: abbr,
|
|
171
|
-
altName
|
|
172
|
-
});
|
|
173
|
-
return selectOptions;
|
|
174
173
|
}, []).sort((a, b) => a.offset - b.offset);
|
|
175
174
|
}, [labelStyle, timezones]);
|
|
176
175
|
const handleChange = (tz) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -18,10 +18,19 @@ interface Props
|
|
|
18
18
|
labelStyle?: ILabelStyle
|
|
19
19
|
onChange?: (timezone: ITimezoneOption) => void
|
|
20
20
|
timezones?: ICustomTimezone
|
|
21
|
+
maxAbbrLength?: number
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
declare const allTimezones: ICustomTimezone;
|
|
24
25
|
|
|
25
|
-
declare const TimezoneSelect: ({
|
|
26
|
+
declare const TimezoneSelect: ({
|
|
27
|
+
value,
|
|
28
|
+
onBlur,
|
|
29
|
+
onChange,
|
|
30
|
+
labelStyle,
|
|
31
|
+
timezones,
|
|
32
|
+
maxAbbrLength,
|
|
33
|
+
...props
|
|
34
|
+
}: Props) => JSX.Element
|
|
26
35
|
|
|
27
36
|
export { ILabelStyle, ITimezone, ITimezoneOption, Props, allTimezones, TimezoneSelect as default };
|
package/dist/index.js
CHANGED
|
@@ -95,48 +95,47 @@ var TimezoneSelect = ({
|
|
|
95
95
|
onChange,
|
|
96
96
|
labelStyle = "original",
|
|
97
97
|
timezones,
|
|
98
|
+
maxAbbrLength = 4,
|
|
98
99
|
...props
|
|
99
100
|
}) => {
|
|
100
101
|
if (!timezones)
|
|
101
102
|
timezones = timezone_list_default;
|
|
102
103
|
const getOptions = React.useMemo(() => {
|
|
103
104
|
return Object.entries(timezones).reduce((selectOptions, zone) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
tzStrings[0].daylight
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
105
|
+
try {
|
|
106
|
+
const now = spacetime.now(zone[0]);
|
|
107
|
+
const tz = now.timezone();
|
|
108
|
+
const tzStrings = soft(zone[0]);
|
|
109
|
+
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;
|
|
112
|
+
const min = tz.current.offset * 60;
|
|
113
|
+
const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
|
|
114
|
+
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
115
|
+
switch (labelStyle) {
|
|
116
|
+
case "original":
|
|
117
|
+
label = prefix;
|
|
118
|
+
break;
|
|
119
|
+
case "altName":
|
|
120
|
+
label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
|
|
121
|
+
break;
|
|
122
|
+
case "abbrev":
|
|
123
|
+
label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
label = `${prefix}`;
|
|
127
|
+
}
|
|
128
|
+
selectOptions.push({
|
|
129
|
+
value: tz.name,
|
|
130
|
+
label,
|
|
131
|
+
offset: tz.current.offset,
|
|
132
|
+
abbrev: abbr,
|
|
133
|
+
altName
|
|
134
|
+
});
|
|
135
|
+
return selectOptions;
|
|
136
|
+
} catch {
|
|
137
|
+
return selectOptions;
|
|
131
138
|
}
|
|
132
|
-
selectOptions.push({
|
|
133
|
-
value: tz.name,
|
|
134
|
-
label,
|
|
135
|
-
offset: tz.current.offset,
|
|
136
|
-
abbrev: abbr,
|
|
137
|
-
altName
|
|
138
|
-
});
|
|
139
|
-
return selectOptions;
|
|
140
139
|
}, []).sort((a, b) => a.offset - b.offset);
|
|
141
140
|
}, [labelStyle, timezones]);
|
|
142
141
|
const handleChange = (tz) => {
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-timezone-select",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "Usable, dynamic React Timezone Select",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "concurrently \"
|
|
7
|
-
"
|
|
8
|
-
"postpublish": "
|
|
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
9
|
"build": "tsup src/index.tsx --format cjs,esm --dts",
|
|
10
|
-
"build:example": "cd example &&
|
|
10
|
+
"build:example": "cd example && pnpm run build",
|
|
11
11
|
"deploy": "gh-pages -d example/dist",
|
|
12
|
+
"pretest": "pnpm run build",
|
|
12
13
|
"test": "jest",
|
|
13
14
|
"test:watch": "jest --watch",
|
|
14
|
-
"test:ci": "jest --ci ",
|
|
15
|
+
"test:ci": "pnpm run build && jest --ci ",
|
|
15
16
|
"tsc": "tsc"
|
|
16
17
|
},
|
|
17
18
|
"author": "Nico Domino <yo@ndo.dev>",
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"react-select": "^5.7.0",
|
|
54
|
-
"spacetime": "^7.1
|
|
55
|
-
"timezone-soft": "^1.
|
|
55
|
+
"spacetime": "^7.4.1",
|
|
56
|
+
"timezone-soft": "^1.4.1"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@babel/core": "^7.20.7",
|