From bfc54018ceb2cad5560418fcd1c3f1230decc908 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 24 Nov 2019 17:37:08 +0200 Subject: [PATCH] Widgets: add TimezonePicker widget. --- package.json | 3 ++- src/helpers.tsx | 4 ++++ src/widgets/TimezonePicker.tsx | 28 ++++++++++++++++++++++++++++ yarn.lock | 18 ++++++++++++++---- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/widgets/TimezonePicker.tsx diff --git a/package.json b/package.json index ad0b1df..01ca77b 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "version": "0.4.0", "private": true, "dependencies": { - "@material-ui/core": "^4.6.1", + "@material-ui/core": "^4.7.0", "@material-ui/icons": "^3.0.2", + "@material-ui/lab": "^4.0.0-alpha.33", "@material-ui/styles": "^4.6.0", "etesync": "^0.1.2", "ical.js": "^1.2.2", diff --git a/src/helpers.tsx b/src/helpers.tsx index 28de623..2783adc 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -100,3 +100,7 @@ export function formatOurTimezoneOffset() { return `GMT${prefix}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; } + +export function getCurrentTimezone() { + return Intl.DateTimeFormat().resolvedOptions().timeZone; +} diff --git a/src/widgets/TimezonePicker.tsx b/src/widgets/TimezonePicker.tsx new file mode 100644 index 0000000..85b4c5b --- /dev/null +++ b/src/widgets/TimezonePicker.tsx @@ -0,0 +1,28 @@ +import * as React from 'react'; + +import Autocomplete from '@material-ui/lab/Autocomplete'; +import TextField from '@material-ui/core/TextField'; + +import * as zones from '../data/zones.json'; +const zonelist = Object.keys(zones.zones).sort(); + +interface PropsType { + value: string | null; + onChange: (value: string) => void; + style?: React.CSSProperties; +} + +export default React.memo(function TimezonePicker(props: PropsType) { + return ( + props.onChange(value)} + getOptionLabel={(option) => option.replace('_', ' ')} + style={props.style} + renderInput={(params) => ( + + )} + /> + ); +}); diff --git a/yarn.lock b/yarn.lock index 26864c4..cd01ef5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1486,10 +1486,10 @@ "@types/istanbul-reports" "^1.1.1" "@types/yargs" "^13.0.0" -"@material-ui/core@^4.6.1": - version "4.6.1" - resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-4.6.1.tgz#039f97443547a88c41d290deabfb4a044c6031ec" - integrity sha512-TljDMCJmi1zh7JhAFTp8qjIlbkVACiNftrcitzJJ+hAqpuP9PTO4euEkkAuYjISfUFZl3Z4kaOrBwN1HDrhIOQ== +"@material-ui/core@^4.7.0": + version "4.7.0" + resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-4.7.0.tgz#84c02a6d1c99c7900e184538c5f9d87e30cf4c23" + integrity sha512-mwLehUo0Q9ZxjuWo7J1uy1/Grh3nRxlOAaWJ3EtKeJP2HwqlSy8bWrcvRQYlapaYIPXa5jN8zWbTwi8Pk30VQg== dependencies: "@babel/runtime" "^7.4.4" "@material-ui/styles" "^4.6.0" @@ -1513,6 +1513,16 @@ "@babel/runtime" "^7.2.0" recompose "0.28.0 - 0.30.0" +"@material-ui/lab@^4.0.0-alpha.33": + version "4.0.0-alpha.33" + resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.33.tgz#3de96da1e813afcea5a07d56e54ec41cfa636e2c" + integrity sha512-+xttHUZLwH4+yfkB7B5A3pNDtQO27tGftuUxMRDMevNXwQtAB7mgYco34JwMr9kmvESYmacoZReOacJ6rxym/Q== + dependencies: + "@babel/runtime" "^7.4.4" + "@material-ui/utils" "^4.5.2" + clsx "^1.0.4" + prop-types "^15.7.2" + "@material-ui/styles@^4.6.0": version "4.6.0" resolved "https://registry.yarnpkg.com/@material-ui/styles/-/styles-4.6.0.tgz#15679fab6dcbe0cc2416f01a22966f3ea26607c5"