react-timezone-select 1.5.3 → 1.5.5
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 +34 -35
- package/dist/index.d.ts +12 -2
- package/dist/index.js +34 -35
- package/package.json +9 -8
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
|
@@ -12,15 +12,25 @@ interface ITimezoneOption {
|
|
|
12
12
|
altName?: string
|
|
13
13
|
}
|
|
14
14
|
declare type ITimezone = ITimezoneOption | string
|
|
15
|
-
interface Props
|
|
15
|
+
interface Props
|
|
16
|
+
extends Omit<Props$1<ITimezone, false>, 'onChange'> {
|
|
16
17
|
value: ITimezone
|
|
17
18
|
labelStyle?: ILabelStyle
|
|
18
19
|
onChange?: (timezone: ITimezoneOption) => void
|
|
19
20
|
timezones?: ICustomTimezone
|
|
21
|
+
maxAbbrLength?: number
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare const allTimezones: ICustomTimezone;
|
|
23
25
|
|
|
24
|
-
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
|
|
25
35
|
|
|
26
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.5",
|
|
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 && npm run 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",
|