react-timezone-select 3.2.7 → 3.3.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/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { Props as Props$1 } from 'react-select';
3
3
 
4
4
  type ICustomTimezone = {
@@ -12,6 +12,7 @@ type ITimezoneOption = {
12
12
  abbrev?: string;
13
13
  altName?: string;
14
14
  offset?: number;
15
+ searchTerms?: string;
15
16
  };
16
17
  type ITimezone = ITimezoneOption | string;
17
18
  type TimezoneSelectOptions = {
@@ -20,7 +21,7 @@ type TimezoneSelectOptions = {
20
21
  timezones?: ICustomTimezone;
21
22
  currentDatetime?: Date | string;
22
23
  };
23
- type Props = Omit<Props$1<ITimezone, false>, "onChange"> & TimezoneSelectOptions & {
24
+ type Props = Omit<Props$1<ITimezone>, "onChange"> & TimezoneSelectOptions & {
24
25
  value: ITimezone;
25
26
  onChange?: (timezone: ITimezoneOption) => void;
26
27
  };
@@ -30,7 +31,12 @@ declare const allTimezones: ICustomTimezone;
30
31
  declare function useTimezoneSelect({ timezones, labelStyle, displayValue, currentDatetime, }: TimezoneSelectOptions): {
31
32
  parseTimezone: (zone: ITimezone) => ITimezoneOption;
32
33
  options: ITimezoneOption[];
34
+ filterOption: (option: {
35
+ label: string;
36
+ value: string;
37
+ data: ITimezone;
38
+ }, inputValue: string) => boolean;
33
39
  };
34
- declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, currentDatetime, ...props }: Props) => react_jsx_runtime_js.JSX.Element;
40
+ declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, currentDatetime, ...props }: Props) => react_jsx_runtime.JSX.Element;
35
41
 
36
42
  export { type ILabelStyle, type ITimezone, type ITimezoneOption, type Props, type TimezoneSelectOptions, allTimezones, TimezoneSelect as default, useTimezoneSelect };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use client"
2
-
3
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -16,6 +17,7 @@ var __spreadValues = (a, b) => {
16
17
  }
17
18
  return a;
18
19
  };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
19
21
  var __objRest = (source, exclude) => {
20
22
  var target = {};
21
23
  for (var prop in source)
@@ -127,7 +129,7 @@ function useTimezoneSelect({
127
129
  displayValue = "GMT",
128
130
  currentDatetime
129
131
  }) {
130
- const options = useMemo(() => {
132
+ const allOptions = useMemo(() => {
131
133
  return Object.entries(timezones).map((zone) => {
132
134
  var _a, _b, _c, _d;
133
135
  try {
@@ -169,6 +171,19 @@ function useTimezoneSelect({
169
171
  }
170
172
  }).filter(Boolean).sort((a, b) => a.offset - b.offset);
171
173
  }, [labelStyle, timezones, currentDatetime]);
174
+ const options = useMemo(() => {
175
+ return allOptions.filter(
176
+ (item, idx, arr) => arr.findIndex((t) => t.offset === item.offset) === idx
177
+ ).map((item) => __spreadProps(__spreadValues({}, item), {
178
+ searchTerms: allOptions.filter((t) => t.offset === item.offset).map((t) => t.label).join(" ")
179
+ }));
180
+ }, [allOptions]);
181
+ const filterOption = (option, inputValue) => {
182
+ var _a, _b, _c;
183
+ const data = option.data;
184
+ const term = inputValue.toLowerCase();
185
+ return ((_a = data.label) == null ? void 0 : _a.toLowerCase().includes(term)) || ((_c = (_b = data.searchTerms) == null ? void 0 : _b.toLowerCase().includes(term)) != null ? _c : false);
186
+ };
172
187
  const findFuzzyTz = (zone) => {
173
188
  var _a, _b;
174
189
  let currentTime;
@@ -177,7 +192,7 @@ function useTimezoneSelect({
177
192
  } catch (err) {
178
193
  currentTime = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto("GMT");
179
194
  }
180
- return (_b = (_a = options.filter((tz) => tz.offset === currentTime.timezone().current.offset).map((tz) => {
195
+ return (_b = (_a = allOptions.filter((tz) => tz.offset === currentTime.timezone().current.offset).map((tz) => {
181
196
  let score = 0;
182
197
  if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
183
198
  if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)) !== -1) {
@@ -201,14 +216,14 @@ function useTimezoneSelect({
201
216
  }
202
217
  const parseTimezone = (zone) => {
203
218
  if (typeof zone === "string") {
204
- return options.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
219
+ return allOptions.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
205
220
  } else if (isObject(zone) && !zone.label) {
206
- return options.find((tz) => tz.value === zone.value);
221
+ return allOptions.find((tz) => tz.value === zone.value);
207
222
  } else {
208
223
  return zone;
209
224
  }
210
225
  };
211
- return { options, parseTimezone };
226
+ return { options, parseTimezone, filterOption };
212
227
  }
213
228
  var TimezoneSelect = (_a) => {
214
229
  var _b = _a, {
@@ -228,14 +243,16 @@ var TimezoneSelect = (_a) => {
228
243
  "timezones",
229
244
  "currentDatetime"
230
245
  ]);
231
- const { options, parseTimezone } = useTimezoneSelect({
246
+ const { options, parseTimezone, filterOption } = useTimezoneSelect({
232
247
  timezones,
233
248
  labelStyle,
234
249
  displayValue,
235
250
  currentDatetime
236
251
  });
237
252
  const handleChange = (tz) => {
238
- onChange && onChange(tz);
253
+ if (!onChange) return;
254
+ const _a2 = tz, { searchTerms: _ } = _a2, rest = __objRest(_a2, ["searchTerms"]);
255
+ onChange(rest);
239
256
  };
240
257
  return /* @__PURE__ */ jsx(
241
258
  Select,
@@ -243,6 +260,7 @@ var TimezoneSelect = (_a) => {
243
260
  value: parseTimezone(value),
244
261
  onChange: handleChange,
245
262
  options,
263
+ filterOption,
246
264
  onBlur
247
265
  }, props)
248
266
  );
package/package.json CHANGED
@@ -1,7 +1,24 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "3.2.7",
3
+ "version": "3.3.1",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
+ "scripts": {
6
+ "dev": "concurrently \"tsup --watch\" \"cd example && pnpm dev\"",
7
+ "prepublishOnly": "pnpm run build",
8
+ "postpublish": "pnpm run build:example && npm run deploy",
9
+ "build": "tsup",
10
+ "build:example": "cd example && pnpm run build",
11
+ "deploy": "gh-pages -d example/dist",
12
+ "pretest": "pnpm run build",
13
+ "test": "vitest",
14
+ "test:watch": "vitest --watch",
15
+ "test:ci": "pnpm run build && pnpm test",
16
+ "tsc": "tsc",
17
+ "lint": "biome lint",
18
+ "lint:fix": "biome lint --fix",
19
+ "format": "biome check",
20
+ "format:fix": "biome check --write"
21
+ },
5
22
  "author": "Nico Domino <yo@ndo.dev>",
6
23
  "homepage": "https://github.com/ndom91/react-timezone-select",
7
24
  "repository": {
@@ -12,16 +29,8 @@
12
29
  "url": "https://github.com/ndom91/react-timezone-select/issues"
13
30
  },
14
31
  "license": "MIT",
15
- "keywords": [
16
- "react",
17
- "timezone",
18
- "select",
19
- "react-select"
20
- ],
21
- "files": [
22
- "dist/**/*",
23
- "package.json"
24
- ],
32
+ "keywords": ["react", "timezone", "select", "react-select"],
33
+ "files": ["dist/**/*", "package.json"],
25
34
  "type": "module",
26
35
  "module": "./dist/index.js",
27
36
  "types": "./dist/index.d.ts",
@@ -32,81 +41,33 @@
32
41
  }
33
42
  },
34
43
  "peerDependencies": {
35
- "react": "^16 || ^17.0.1 || ^18 || ^19.0.0-0",
36
- "react-dom": "^16 || ^17.0.1 || ^18 || ^19.0.0-0",
44
+ "react": "^16 || ^17.0.1 || ^18 || ^19",
45
+ "react-dom": "^16 || ^17.0.1 || ^18 || ^19",
37
46
  "react-select": "^5.8.0"
38
47
  },
39
48
  "dependencies": {
40
- "spacetime": "^7.6.0",
49
+ "spacetime": "^7.12.0",
41
50
  "timezone-soft": "^1.5.2"
42
51
  },
43
52
  "devDependencies": {
44
- "@babel/core": "^7.24.9",
45
- "@testing-library/jest-dom": "^6.4.8",
46
- "@testing-library/react": "^16.0.0",
47
- "@types/jest": "^29.5.12",
48
- "@types/react": "^18.3.3",
49
- "@types/react-dom": "^18.3.0",
50
- "@types/testing-library__jest-dom": "^5.14.9",
51
- "@typescript-eslint/eslint-plugin": "^7.17.0",
52
- "@typescript-eslint/parser": "^7.17.0",
53
- "@vitejs/plugin-react": "^4.3.1",
54
- "concurrently": "^8.2.2",
55
- "esbuild": "^0.23.0",
56
- "esbuild-jest": "^0.5.0",
57
- "eslint": "^8.57.0",
58
- "eslint-config-prettier": "^9.1.0",
59
- "eslint-plugin-prettier": "5.2.1",
60
- "gh-pages": "^6.1.1",
61
- "jest-environment-jsdom": "^29.7.0",
62
- "prettier": "^3.3.3",
63
- "react": "^18.2.0",
64
- "react-dom": "^18.2.0",
65
- "simple-git-hooks": "^2.11.1",
66
- "ts-jest": "^29.2.3",
67
- "tsup": "^8.2.2",
68
- "typescript": "^5.5.4",
69
- "vite": "^5.3.4",
70
- "vite-tsconfig-paths": "^4.3.2",
71
- "vitest": "^2.0.4"
72
- },
73
- "eslintConfig": {
74
- "parser": "@typescript-eslint/parser",
75
- "parserOptions": {
76
- "ecmaVersion": "latest",
77
- "sourceType": "module"
78
- },
79
- "extends": [
80
- "eslint:recommended",
81
- "plugin:@typescript-eslint/recommended",
82
- "plugin:prettier/recommended"
83
- ],
84
- "plugins": [
85
- "@typescript-eslint"
86
- ],
87
- "root": true
88
- },
89
- "prettier": {
90
- "semi": false,
91
- "printWidth": 100
53
+ "@biomejs/biome": "^1.9.4",
54
+ "@testing-library/jest-dom": "^6.9.1",
55
+ "@testing-library/react": "^16.3.2",
56
+ "@types/node": "^20.19.0",
57
+ "@types/react": "^19.2.14",
58
+ "@types/react-dom": "^19.2.3",
59
+ "@vitejs/plugin-react": "^5.1.4",
60
+ "concurrently": "^9.2.1",
61
+ "esbuild": "^0.27.3",
62
+ "gh-pages": "^6.3.0",
63
+ "jsdom": "^26.1.0",
64
+ "react": "^19.2.4",
65
+ "react-dom": "^19.2.4",
66
+ "tsup": "^8.5.1",
67
+ "typescript": "^5.9.3",
68
+ "vite": "^7.3.1",
69
+ "vite-tsconfig-paths": "^6.1.1",
70
+ "vitest": "^4.0.18"
92
71
  },
93
- "simple-git-hooks": {
94
- "pre-commit": "npx lint-staged"
95
- },
96
- "lint-staged": {
97
- "*.{js,jsx,ts,tsx}": [
98
- "eslint --fix"
99
- ]
100
- },
101
- "scripts": {
102
- "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && pnpm dev\"",
103
- "build": "tsup src/index.tsx --format esm --clean --dts && sed -i '1i \"use client\"\\n' dist/index.js",
104
- "build:example": "cd example && pnpm run build",
105
- "deploy": "gh-pages -d example/dist",
106
- "pretest": "pnpm run build",
107
- "test": "vitest",
108
- "test:watch": "vitest --watch",
109
- "test:ci": "pnpm run build && pnpm test",
110
- "tsc": "tsc"
111
- }
112
- }
72
+ "packageManager": "pnpm@9.0.6+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3"
73
+ }