react-timezone-select
Advanced tools
Comparing version 2.1.5 to 3.0.0
@@ -0,9 +1,10 @@ | ||
import React from 'react'; | ||
import { Props as Props$1 } from 'react-select'; | ||
declare type ICustomTimezone = { | ||
type ICustomTimezone = { | ||
[key: string]: string; | ||
}; | ||
declare type ILabelStyle = 'original' | 'altName' | 'abbrev' | 'offsetHidden'; | ||
declare type IDisplayValue = 'GMT' | 'UTC'; | ||
declare type ITimezoneOption = { | ||
type ILabelStyle = 'original' | 'altName' | 'abbrev' | 'offsetHidden'; | ||
type IDisplayValue = 'GMT' | 'UTC'; | ||
type ITimezoneOption = { | ||
value: string; | ||
@@ -15,4 +16,4 @@ label: string; | ||
}; | ||
declare type ITimezone = ITimezoneOption | string; | ||
declare type TimezoneSelectOptions = { | ||
type ITimezone = ITimezoneOption | string; | ||
type TimezoneSelectOptions = { | ||
labelStyle?: ILabelStyle; | ||
@@ -23,3 +24,3 @@ displayValue?: IDisplayValue; | ||
}; | ||
declare type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & { | ||
type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & { | ||
value: ITimezone; | ||
@@ -31,8 +32,8 @@ onChange?: (timezone: ITimezone) => void; | ||
declare function useTimezoneSelect({ timezones, labelStyle, displayValue, maxAbbrLength, }: TimezoneSelectOptions): { | ||
declare function useTimezoneSelect({ timezones, labelStyle, displayValue, }: TimezoneSelectOptions): { | ||
parseTimezone: (zone: ITimezone) => ITimezoneOption; | ||
options: ITimezoneOption[]; | ||
}; | ||
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, maxAbbrLength, timezones, ...props }: Props) => JSX.Element; | ||
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, ...props }: Props) => React.JSX.Element; | ||
export { ILabelStyle, ITimezone, ITimezoneOption, Props, TimezoneSelectOptions, allTimezones, TimezoneSelect as default, useTimezoneSelect }; |
@@ -31,3 +31,3 @@ var __defProp = Object.defineProperty; | ||
// src/index.tsx | ||
import * as React from "react"; | ||
import React, { useMemo } from "react"; | ||
import Select from "react-select"; | ||
@@ -125,22 +125,18 @@ import spacetime from "spacetime"; | ||
labelStyle = "original", | ||
displayValue = "GMT", | ||
maxAbbrLength = 4 | ||
displayValue = "GMT" | ||
}) { | ||
const options = React.useMemo(() => { | ||
const options = useMemo(() => { | ||
return Object.entries(timezones).map((zone) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; | ||
var _a, _b, _c, _d; | ||
try { | ||
const now = spacetime.now(zone[0]); | ||
const isDstString = now.isDST() ? "daylight" : "standard"; | ||
const tz = now.timezone(); | ||
const tzStrings = soft(zone[0]); | ||
let label = ""; | ||
const standardAbbr = (_c = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a.standard) == null ? void 0 : _b.abbr) != null ? _c : ""; | ||
const dstAbbr = (_f = (_e = (_d = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _d.daylight) == null ? void 0 : _e.abbr) != null ? _f : standardAbbr; | ||
let abbr = now.isDST() ? dstAbbr : standardAbbr; | ||
const standardAltName = (_i = (_h = (_g = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _g.standard) == null ? void 0 : _h.name) != null ? _i : ""; | ||
const dstAltName = (_l = (_k = (_j = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _j.daylight) == null ? void 0 : _k.name) != null ? _l : standardAltName; | ||
let altName = now.isDST() ? dstAltName : standardAltName; | ||
const abbr = (_b = (_a = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _a[isDstString]) == null ? void 0 : _b.abbr; | ||
const altName = (_d = (_c = tzStrings == null ? void 0 : tzStrings[0]) == null ? void 0 : _c[isDstString]) == null ? void 0 : _d.name; | ||
const min = tz.current.offset * 60; | ||
const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60)); | ||
const hr = `${min / 60 ^ 0}:${min % 60 === 0 ? "00" : Math.abs(min % 60)}`; | ||
const prefix = `(${displayValue}${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`; | ||
let label = ""; | ||
switch (labelStyle) { | ||
@@ -154,3 +150,3 @@ case "original": | ||
case "abbrev": | ||
label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`; | ||
label = `${prefix} (${abbr})`; | ||
break; | ||
@@ -176,7 +172,7 @@ case "offsetHidden": | ||
const findFuzzyTz = (zone) => { | ||
let currentTime = spacetime.now("GMT"); | ||
let currentTime; | ||
try { | ||
currentTime = spacetime.now(zone); | ||
} catch (err) { | ||
return; | ||
currentTime = spacetime.now("GMT"); | ||
} | ||
@@ -206,3 +202,3 @@ return options.filter( | ||
return { tz, score }; | ||
}).sort((a, b) => b.score - a.score).map(({ tz }) => tz)[0]; | ||
}).sort((a, b) => b.score - a.score)[0].tz; | ||
}; | ||
@@ -227,3 +223,2 @@ const parseTimezone = (zone) => { | ||
displayValue, | ||
maxAbbrLength, | ||
timezones | ||
@@ -236,3 +231,2 @@ } = _b, props = __objRest(_b, [ | ||
"displayValue", | ||
"maxAbbrLength", | ||
"timezones" | ||
@@ -243,4 +237,3 @@ ]); | ||
labelStyle, | ||
displayValue, | ||
maxAbbrLength | ||
displayValue | ||
}); | ||
@@ -247,0 +240,0 @@ const handleChange = (tz) => { |
{ | ||
"name": "react-timezone-select", | ||
"version": "2.1.5", | ||
"version": "3.0.0", | ||
"description": "Usable, dynamic React Timezone Select", | ||
@@ -13,5 +13,5 @@ "scripts": { | ||
"pretest": "pnpm run build", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:ci": "pnpm run build && jest --ci ", | ||
"test": "vitest", | ||
"test:watch": "vitest --watch", | ||
"test:ci": "pnpm run build && pnpm test", | ||
"tsc": "tsc" | ||
@@ -56,31 +56,39 @@ }, | ||
"dependencies": { | ||
"spacetime": "^7.4.1", | ||
"timezone-soft": "^1.4.1" | ||
"spacetime": "^7.4.8", | ||
"timezone-soft": "^1.5.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.20.7", | ||
"@testing-library/jest-dom": "^5.16.1", | ||
"@testing-library/react": "^12.1.2", | ||
"@types/jest": "^27.4.0", | ||
"@types/react": "^17.0.38", | ||
"@types/react-dom": "^17.0.11", | ||
"@types/testing-library__jest-dom": "^5.14.5", | ||
"concurrently": "^7.0.0", | ||
"esbuild": "^0.16.12", | ||
"@babel/core": "^7.23.5", | ||
"@testing-library/jest-dom": "^5.17.0", | ||
"@testing-library/react": "^14.1.2", | ||
"@types/jest": "^27.5.2", | ||
"@types/react": "^18.2.43", | ||
"@types/react-dom": "^18.2.17", | ||
"@types/testing-library__jest-dom": "^5.14.9", | ||
"@typescript-eslint/eslint-plugin": "^6.13.2", | ||
"@typescript-eslint/parser": "^6.13.2", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"concurrently": "^7.6.0", | ||
"esbuild": "^0.16.17", | ||
"esbuild-jest": "^0.5.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint": "^8.55.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "5.0.1", | ||
"gh-pages": "^3.2.3", | ||
"jest": "^27.4.7", | ||
"prettier": "^2.5.1", | ||
"react": "^17", | ||
"react-dom": "^17", | ||
"simple-git-hooks": "^2.7.0", | ||
"ts-jest": "^27.1.3", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.5.5" | ||
"jest-environment-jsdom": "^29.7.0", | ||
"prettier": "^3.1.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"simple-git-hooks": "^2.9.0", | ||
"ts-jest": "^29.1.1", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.7", | ||
"vite-tsconfig-paths": "^4.2.2", | ||
"vitest": "^1.0.4" | ||
}, | ||
"eslintConfig": { | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
@@ -90,20 +98,14 @@ }, | ||
"eslint:recommended", | ||
"prettier" | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"plugins": [ | ||
"prettier" | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
"root": true | ||
}, | ||
"prettier": { | ||
"trailingComma": "es5", | ||
"semi": false, | ||
"singleQuote": true, | ||
"arrowParens": "avoid" | ||
"maxLineLength": 100 | ||
}, | ||
@@ -114,6 +116,3 @@ "simple-git-hooks": { | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx,css,json}": [ | ||
"prettier --write" | ||
], | ||
"*.{js,jsx}": [ | ||
"*.{js,jsx,ts,tsx}": [ | ||
"eslint --fix" | ||
@@ -120,0 +119,0 @@ ] |
@@ -128,3 +128,3 @@ # đâ react-timezone-select | ||
- `onChange` - `(timezone) => void` | ||
- `labelStyle` - `'original' | 'altName' | 'abbrev'` | ||
- `labelStyle` - `'original' | 'altName' | 'abbrev' | 'offsetHidden'` | ||
- `displayValue` - `'GMT' | 'UTC'` | ||
@@ -140,3 +140,2 @@ - `timezones` - `Record<string,string>` | ||
- `maxAbbrLength` - `number` - Truncate `abbrev` labelStyles string to length | ||
- Any other [`react-select`](https://github.com/jedwatson/react-select#props) props | ||
@@ -143,0 +142,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32864
28
578
177
Updatedspacetime@^7.4.8
Updatedtimezone-soft@^1.5.1