react-timezone-select 1.0.8
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 +21 -0
- package/README.md +155 -0
- package/dist/index.css +3 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +194 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nico Domino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# 🌐⌚ react-timezone-select
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/react-timezone-select)
|
|
4
|
+
[](https://www.npmjs.com/package/react-timezone-select)
|
|
5
|
+
[](https://github.com/ndom91/react-timezone-select/issues)
|
|
6
|
+
[](https://skypack.dev/view/react-timezone-select)
|
|
7
|
+
[](https://github.com/ndom91/react-timezone-select/actions?query=workflow%3A%22Tests+CI%22)
|
|
8
|
+
[](https://github.com/ndom91/react-timezone-select/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
Another react timezone select component, I know.. However this one has a few key benefits!
|
|
11
|
+
|
|
12
|
+
While looking around for a good option, I had trouble finding a timezone select components which:
|
|
13
|
+
|
|
14
|
+
1) Adjusted the choices automatically with Daylight Savings Time (DST)
|
|
15
|
+
2) Didn't have a huge list of choices to scroll through when technically only 24 (ish) are necessary
|
|
16
|
+
|
|
17
|
+
#### Demo: [ndom91.github.io/react-timezone-select](https://ndom91.github.io/react-timezone-select/)
|
|
18
|
+
|
|
19
|
+
> This demo is also available in the `./examples` directory. Simply run `npm start` 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).
|
|
20
|
+
|
|
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)), showing how one might use this component in a real application.
|
|
22
|
+
|
|
23
|
+
## 🏗️ Installing
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install react-timezone-select
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 🔭 Usage
|
|
30
|
+
|
|
31
|
+
```jsx
|
|
32
|
+
import React, { useState } from "react"
|
|
33
|
+
import ReactDOM from "react-dom"
|
|
34
|
+
import TimezoneSelect from "react-timezone-select"
|
|
35
|
+
|
|
36
|
+
const App = () => {
|
|
37
|
+
const [selectedTimezone, setSelectedTimezone] = useState({})
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className="App">
|
|
41
|
+
<h2>react-timezone-select</h2>
|
|
42
|
+
<blockquote>Please make a selection</blockquote>
|
|
43
|
+
<div className="select-wrapper">
|
|
44
|
+
<TimezoneSelect
|
|
45
|
+
value={selectedTimezone}
|
|
46
|
+
onChange={setSelectedTimezone}
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
<h3>Output:</h3>
|
|
50
|
+
<div
|
|
51
|
+
style={{
|
|
52
|
+
backgroundColor: "#ccc",
|
|
53
|
+
padding: "20px",
|
|
54
|
+
margin: "20px auto",
|
|
55
|
+
borderRadius: "5px",
|
|
56
|
+
maxWidth: "600px",
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<pre
|
|
60
|
+
style={{
|
|
61
|
+
margin: "0 20px",
|
|
62
|
+
fontWeight: 500,
|
|
63
|
+
fontFamily: "monospace",
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
{JSON.stringify(selectedTimezone, null, 2)}
|
|
67
|
+
</pre>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const rootElement = document.getElementById("root")
|
|
74
|
+
ReactDOM.render(<App />, rootElement)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 🪙 Tips
|
|
78
|
+
|
|
79
|
+
### 👤 Default Users Timezone
|
|
80
|
+
|
|
81
|
+
If you'd like the user's own timezone to be set as the initially selected option on render, we can make use of the new `Intl` browser API by setting the default state value to `Intl.DateTimeFormat().resolvedOptions().timeZone`.
|
|
82
|
+
|
|
83
|
+
```jsx
|
|
84
|
+
const [timezone, setTimezone] = useState(
|
|
85
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Thanks [@ndrwksr](https://github.com/ndom91/react-timezone-select/issues/25)!
|
|
90
|
+
|
|
91
|
+
### ⚠ Next.js Users
|
|
92
|
+
|
|
93
|
+
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).
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// next.config.js
|
|
97
|
+
const withTM = require("next-transpile-modules")(["react-timezone-select"])
|
|
98
|
+
|
|
99
|
+
module.exports = withTM({
|
|
100
|
+
// ...further Next.js config
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Update**: Next.js 11.1.0 now supports ESM packages natively! Until 12.0.0 you need to include `esmExternals: true` in your `next.js.config` though.
|
|
105
|
+
|
|
106
|
+
### 🕒 Custom Timezones
|
|
107
|
+
|
|
108
|
+
You can append custom choices of your own, or fully replace the listed timezone options.
|
|
109
|
+
|
|
110
|
+
The `timezones` prop takes a dictionary of timezones. Don't worry, we'll prepend the `(GMT...)` part, you just have to pass the city(s) or region(s) you want in your label.
|
|
111
|
+
|
|
112
|
+
```jsx
|
|
113
|
+
import TimezoneSelect, { i18nTimezones } from "react-timezone-select"
|
|
114
|
+
;<TimezoneSelect
|
|
115
|
+
value={selectedTimezone}
|
|
116
|
+
onChange={setSelectedTimezone}
|
|
117
|
+
timezones={{
|
|
118
|
+
...i18nTimezones,
|
|
119
|
+
"America/Lima": "Pittsburgh",
|
|
120
|
+
"Europe/Berlin": "Frankfurt",
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The above example will generate two additional choices in the select options, one with the label `'(GMT-5:00) Pittsburgh'` and another with `'(GMT+1:00) Frankfurt'`. You can omit spreading in the `i18nTimezones` object and then only your custom timezone options get rendered in the select component.
|
|
126
|
+
|
|
127
|
+
## 🕹️ Props
|
|
128
|
+
|
|
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 }`
|
|
130
|
+
- `onBlur` - `() => void`
|
|
131
|
+
- `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
|
+
- `labelStyle` - `'original' | 'altName' | 'abbrev'`
|
|
143
|
+
- `timezones` - Custom Timezone Object
|
|
144
|
+
- Any other [`react-select`](https://github.com/jedwatson/react-select#props) props
|
|
145
|
+
|
|
146
|
+
## 🚧 Contributing
|
|
147
|
+
|
|
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!
|
|
149
|
+
|
|
150
|
+
## 🙏 Thanks
|
|
151
|
+
|
|
152
|
+
- [All Contributors](https://github.com/ndom91/react-timezone-select/graphs/contributors)
|
|
153
|
+
- [Carlos Matallin](https://github.com/matallo/)
|
|
154
|
+
- [spacetime](https://github.com/spencermountain/spacetime)
|
|
155
|
+
- [react-select](https://react-select.com)
|
package/dist/index.css
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Props as ReactSelectProps } from "react-select";
|
|
3
|
+
import "./index.css";
|
|
4
|
+
declare type ExcludeValue<T> = Pick<T, Exclude<keyof T, "value">>;
|
|
5
|
+
export declare type ICustomTimezone = {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const i18nTimezones: ICustomTimezone;
|
|
9
|
+
export declare type ILabelStyle = "original" | "altName" | "abbrev";
|
|
10
|
+
export declare enum LabelType {
|
|
11
|
+
ORIGINAL = "original",
|
|
12
|
+
ALTNAME = "altName",
|
|
13
|
+
ABBREV = "abbrev"
|
|
14
|
+
}
|
|
15
|
+
export declare type ITimezoneOption = {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
abbrev?: string;
|
|
19
|
+
altName?: string;
|
|
20
|
+
offset?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare type ITimezone = ITimezoneOption | string;
|
|
23
|
+
interface Props extends ExcludeValue<ReactSelectProps> {
|
|
24
|
+
value: ITimezone;
|
|
25
|
+
labelStyle?: ILabelStyle;
|
|
26
|
+
timezones?: ICustomTimezone;
|
|
27
|
+
}
|
|
28
|
+
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, timezones, ...props }: Props) => JSX.Element;
|
|
29
|
+
export default TimezoneSelect;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Select from "react-select";
|
|
3
|
+
import spacetime from "spacetime";
|
|
4
|
+
import informal from "spacetime-informal";
|
|
5
|
+
import "./index.css";
|
|
6
|
+
export const i18nTimezones = {
|
|
7
|
+
"Pacific/Midway": "Midway Island, Samoa",
|
|
8
|
+
"Pacific/Honolulu": "Hawaii",
|
|
9
|
+
"America/Juneau": "Alaska",
|
|
10
|
+
"America/Boise": "Mountain Time",
|
|
11
|
+
"America/Dawson": "Dawson, Yukon",
|
|
12
|
+
"America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
|
|
13
|
+
"America/Phoenix": "Arizona",
|
|
14
|
+
"America/Chicago": "Central Time",
|
|
15
|
+
"America/Regina": "Saskatchewan",
|
|
16
|
+
"America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
|
|
17
|
+
"America/Belize": "Central America",
|
|
18
|
+
"America/Detroit": "Eastern Time",
|
|
19
|
+
"America/Bogota": "Bogota, Lima, Quito",
|
|
20
|
+
"America/Caracas": "Caracas, La Paz",
|
|
21
|
+
"America/Santiago": "Santiago",
|
|
22
|
+
"America/St_Johns": "Newfoundland and Labrador",
|
|
23
|
+
"America/Sao_Paulo": "Brasilia",
|
|
24
|
+
"America/Tijuana": "Tijuana",
|
|
25
|
+
"America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
|
|
26
|
+
"America/Godthab": "Greenland",
|
|
27
|
+
"America/Los_Angeles": "Pacific Time",
|
|
28
|
+
"Atlantic/Azores": "Azores",
|
|
29
|
+
"Atlantic/Cape_Verde": "Cape Verde Islands",
|
|
30
|
+
GMT: "UTC",
|
|
31
|
+
"Europe/London": "Edinburgh, London",
|
|
32
|
+
"Europe/Dublin": "Dublin",
|
|
33
|
+
"Europe/Lisbon": "Lisbon",
|
|
34
|
+
"Africa/Casablanca": "Casablanca, Monrovia",
|
|
35
|
+
"Atlantic/Canary": "Canary Islands",
|
|
36
|
+
"Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
|
|
37
|
+
"Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
|
|
38
|
+
"Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
|
|
39
|
+
"Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
|
|
40
|
+
"Africa/Algiers": "West Central Africa",
|
|
41
|
+
"Europe/Bucharest": "Bucharest",
|
|
42
|
+
"Africa/Cairo": "Cairo",
|
|
43
|
+
"Europe/Helsinki": "Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius",
|
|
44
|
+
"Europe/Athens": "Athens, Istanbul, Minsk",
|
|
45
|
+
"Asia/Jerusalem": "Jerusalem",
|
|
46
|
+
"Africa/Harare": "Harare, Pretoria",
|
|
47
|
+
"Europe/Moscow": "Moscow, St. Petersburg, Volgograd",
|
|
48
|
+
"Asia/Kuwait": "Kuwait, Riyadh",
|
|
49
|
+
"Africa/Nairobi": "Nairobi",
|
|
50
|
+
"Asia/Baghdad": "Baghdad",
|
|
51
|
+
"Asia/Tehran": "Tehran",
|
|
52
|
+
"Asia/Dubai": "Abu Dhabi, Muscat",
|
|
53
|
+
"Asia/Baku": "Baku, Tbilisi, Yerevan",
|
|
54
|
+
"Asia/Kabul": "Kabul",
|
|
55
|
+
"Asia/Yekaterinburg": "Ekaterinburg",
|
|
56
|
+
"Asia/Karachi": "Islamabad, Karachi, Tashkent",
|
|
57
|
+
"Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
|
|
58
|
+
"Asia/Kathmandu": "Kathmandu",
|
|
59
|
+
"Asia/Dhaka": "Astana, Dhaka",
|
|
60
|
+
"Asia/Colombo": "Sri Jayawardenepura",
|
|
61
|
+
"Asia/Almaty": "Almaty, Novosibirsk",
|
|
62
|
+
"Asia/Rangoon": "Yangon Rangoon",
|
|
63
|
+
"Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
|
|
64
|
+
"Asia/Krasnoyarsk": "Krasnoyarsk",
|
|
65
|
+
"Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
|
|
66
|
+
"Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
|
|
67
|
+
"Asia/Taipei": "Taipei",
|
|
68
|
+
"Australia/Perth": "Perth",
|
|
69
|
+
"Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
|
|
70
|
+
"Asia/Seoul": "Seoul",
|
|
71
|
+
"Asia/Tokyo": "Osaka, Sapporo, Tokyo",
|
|
72
|
+
"Asia/Yakutsk": "Yakutsk",
|
|
73
|
+
"Australia/Darwin": "Darwin",
|
|
74
|
+
"Australia/Adelaide": "Adelaide",
|
|
75
|
+
"Australia/Sydney": "Canberra, Melbourne, Sydney",
|
|
76
|
+
"Australia/Brisbane": "Brisbane",
|
|
77
|
+
"Australia/Hobart": "Hobart",
|
|
78
|
+
"Asia/Vladivostok": "Vladivostok",
|
|
79
|
+
"Pacific/Guam": "Guam, Port Moresby",
|
|
80
|
+
"Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
|
|
81
|
+
"Asia/Kamchatka": "Kamchatka, Marshall Islands",
|
|
82
|
+
"Pacific/Fiji": "Fiji Islands",
|
|
83
|
+
"Pacific/Auckland": "Auckland, Wellington",
|
|
84
|
+
"Pacific/Tongatapu": "Nuku'alofa",
|
|
85
|
+
};
|
|
86
|
+
export var LabelType;
|
|
87
|
+
(function (LabelType) {
|
|
88
|
+
LabelType["ORIGINAL"] = "original";
|
|
89
|
+
LabelType["ALTNAME"] = "altName";
|
|
90
|
+
LabelType["ABBREV"] = "abbrev";
|
|
91
|
+
})(LabelType || (LabelType = {}));
|
|
92
|
+
const TimezoneSelect = ({ value, onBlur, onChange, labelStyle = "original", timezones = i18nTimezones, ...props }) => {
|
|
93
|
+
const getOptions = React.useMemo(() => {
|
|
94
|
+
return Object.entries(timezones)
|
|
95
|
+
.reduce((selectOptions, zone) => {
|
|
96
|
+
const now = spacetime.now().goto(zone[0]);
|
|
97
|
+
const tz = now.timezone();
|
|
98
|
+
const tzStrings = informal.display(zone[0]);
|
|
99
|
+
let label = "";
|
|
100
|
+
let abbrev = zone[0];
|
|
101
|
+
let altName = zone[0];
|
|
102
|
+
if (tzStrings && tzStrings.daylight && tzStrings.standard) {
|
|
103
|
+
abbrev = now.isDST()
|
|
104
|
+
? tzStrings.daylight.abbrev
|
|
105
|
+
: tzStrings.standard.abbrev;
|
|
106
|
+
altName = now.isDST()
|
|
107
|
+
? tzStrings.daylight.name
|
|
108
|
+
: tzStrings.standard.name;
|
|
109
|
+
}
|
|
110
|
+
const min = tz.current.offset * 60;
|
|
111
|
+
const hr = `${(min / 60) ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
|
|
112
|
+
const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
|
|
113
|
+
switch (labelStyle) {
|
|
114
|
+
case "original":
|
|
115
|
+
label = prefix;
|
|
116
|
+
break;
|
|
117
|
+
case "altName":
|
|
118
|
+
label = `${prefix} ${!altName.includes("/") ? `(${altName})` : ""}`;
|
|
119
|
+
break;
|
|
120
|
+
case "abbrev":
|
|
121
|
+
label = `${prefix} ${abbrev.length < 5 ? `(${abbrev})` : ""}`;
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
label = `${prefix}`;
|
|
125
|
+
}
|
|
126
|
+
selectOptions.push({
|
|
127
|
+
value: zone[0],
|
|
128
|
+
label: label,
|
|
129
|
+
offset: tz.current.offset,
|
|
130
|
+
abbrev: abbrev,
|
|
131
|
+
altName: altName,
|
|
132
|
+
});
|
|
133
|
+
return selectOptions;
|
|
134
|
+
}, [])
|
|
135
|
+
.sort((a, b) => a.offset - b.offset);
|
|
136
|
+
}, [labelStyle, timezones]);
|
|
137
|
+
const handleChange = (tz) => {
|
|
138
|
+
onChange && onChange(tz);
|
|
139
|
+
};
|
|
140
|
+
const findFuzzyTz = (zone) => {
|
|
141
|
+
let currentTime;
|
|
142
|
+
try {
|
|
143
|
+
currentTime = spacetime.now(zone);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return getOptions
|
|
149
|
+
.filter((tz) => tz.offset === currentTime.timezone().current.offset)
|
|
150
|
+
.map((tz) => {
|
|
151
|
+
let score = 0;
|
|
152
|
+
if (currentTime.timezones[tz.value.toLowerCase()] &&
|
|
153
|
+
!!currentTime.timezones[tz.value.toLowerCase()].dst ===
|
|
154
|
+
currentTime.timezone().hasDst) {
|
|
155
|
+
if (tz.value
|
|
156
|
+
.toLowerCase()
|
|
157
|
+
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf("/") + 1)) !== -1) {
|
|
158
|
+
score += 8;
|
|
159
|
+
}
|
|
160
|
+
if (tz.label
|
|
161
|
+
.toLowerCase()
|
|
162
|
+
.indexOf(currentTime.tz.substr(currentTime.tz.indexOf("/") + 1)) !== -1) {
|
|
163
|
+
score += 4;
|
|
164
|
+
}
|
|
165
|
+
if (tz.value
|
|
166
|
+
.toLowerCase()
|
|
167
|
+
.indexOf(currentTime.tz.substr(0, currentTime.tz.indexOf("/")))) {
|
|
168
|
+
score += 2;
|
|
169
|
+
}
|
|
170
|
+
score += 1;
|
|
171
|
+
}
|
|
172
|
+
else if (tz.value === "GMT") {
|
|
173
|
+
score += 1;
|
|
174
|
+
}
|
|
175
|
+
return { tz, score };
|
|
176
|
+
})
|
|
177
|
+
.sort((a, b) => b.score - a.score)
|
|
178
|
+
.map(({ tz, score }) => tz)[0];
|
|
179
|
+
};
|
|
180
|
+
const parseTimezone = (zone) => {
|
|
181
|
+
if (typeof zone === "object" && zone.value && zone.label)
|
|
182
|
+
return zone;
|
|
183
|
+
if (typeof zone === "string") {
|
|
184
|
+
return (getOptions.find(tz => tz.value === zone) ||
|
|
185
|
+
(zone.indexOf("/") !== -1 && findFuzzyTz(zone)));
|
|
186
|
+
}
|
|
187
|
+
else if (zone.value && !zone.label) {
|
|
188
|
+
return getOptions.find(tz => tz.value === zone.value);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return (React.createElement(Select, { value: parseTimezone(value), onChange: handleChange, options: getOptions, onBlur: onBlur, ...props }));
|
|
192
|
+
};
|
|
193
|
+
export default TimezoneSelect;
|
|
194
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AAEzC,OAAO,aAAa,CAAA;AAQpB,MAAM,CAAC,MAAM,aAAa,GAAoB;IAC5C,gBAAgB,EAAE,sBAAsB;IACxC,kBAAkB,EAAE,QAAQ;IAC5B,gBAAgB,EAAE,QAAQ;IAC1B,eAAe,EAAE,eAAe;IAChC,gBAAgB,EAAE,eAAe;IACjC,mBAAmB,EAAE,6BAA6B;IAClD,iBAAiB,EAAE,SAAS;IAC5B,iBAAiB,EAAE,cAAc;IACjC,gBAAgB,EAAE,cAAc;IAChC,qBAAqB,EAAE,qCAAqC;IAC5D,gBAAgB,EAAE,iB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AAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;aACjC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAClC,CAAC,CAAA;IAED,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAE;QACxC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QACrE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,CACL,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;gBACxC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAChD,CAAA;SACF;aAAM,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACpC,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,CAAA;SACtD;IACH,CAAC,CAAA;IAED,OAAO,CACL,oBAAC,MAAM,IACL,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,EAC3B,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,KACV,KAAK,GACT,CACH,CAAA;AACH,CAAC,CAAA;AAED,eAAe,cAAc,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-timezone-select",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Usable, dynamic React Timezone Select",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "cd example && npm start",
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"postpublish": "npm run build:example && npm run deploy",
|
|
10
|
+
"build": "tsc --project ./tsconfig.json && npm run copy-files",
|
|
11
|
+
"build:example": "cd example && npm run build",
|
|
12
|
+
"copy-files": "cp ./src/index.css ./dist",
|
|
13
|
+
"deploy": "gh-pages -d example/build",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"test:watch": "jest --watch",
|
|
16
|
+
"test:ci": "jest --ci "
|
|
17
|
+
},
|
|
18
|
+
"author": "Nico Domino <yo@ndo.dev>",
|
|
19
|
+
"homepage": "https://github.com/ndom91/react-timezone-select",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ndom91/react-timezone-select.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/ndom91/react-timezone-select/issues"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react",
|
|
30
|
+
"timezone",
|
|
31
|
+
"select",
|
|
32
|
+
"react-select"
|
|
33
|
+
],
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/*"
|
|
36
|
+
],
|
|
37
|
+
"type": "module",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"module": "./dist/index.js",
|
|
40
|
+
"exports": "./dist/index.js",
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^17.0.1",
|
|
43
|
+
"react-dom": "^17.0.1"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"react-select": "^4.3.1",
|
|
47
|
+
"spacetime": "^6.16.2",
|
|
48
|
+
"spacetime-informal": "^0.6.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@testing-library/jest-dom": "^5.14.1",
|
|
52
|
+
"@testing-library/react": "^11.2.7",
|
|
53
|
+
"@types/jest": "^26.0.23",
|
|
54
|
+
"@types/react": "^17.0.11",
|
|
55
|
+
"@types/react-dom": "^17.0.7",
|
|
56
|
+
"@types/react-select": "^4.0.15",
|
|
57
|
+
"gh-pages": "^3.2.1",
|
|
58
|
+
"jest": "^27.0.3",
|
|
59
|
+
"prettier": "^2.3.1",
|
|
60
|
+
"react": "^17.0.2",
|
|
61
|
+
"react-dom": "^17.0.2",
|
|
62
|
+
"ts-jest": "^27.0.3",
|
|
63
|
+
"typescript": "^4.3.2"
|
|
64
|
+
},
|
|
65
|
+
"prettier": {
|
|
66
|
+
"trailingComma": "es5",
|
|
67
|
+
"semi": false,
|
|
68
|
+
"arrowParens": "avoid"
|
|
69
|
+
}
|
|
70
|
+
}
|