1.2.25 • Published 6 days ago

react-timezone-map-select v1.2.25

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 days ago

react-timezone-map-select

pipeline status coverage report semantic-release

Features

This is a react component which lets you select a timezone on world map in a modal dialog.

  • Modal dialog is implemented using MUI (a.k.a. material UI) ver 5.x.
  • You can select a timezone from the list of country / city.
  • You can also select a country / city on the world map.
  • It is fully customizable to make it fit to your application's look and feel.
    • All text labels
    • Button design (you can specify your own react component)
    • Order of buttons. (Mac style: OK comes last. Windows style: OK comes first.)

modal dialog screenshot

Installation

react-timezone-map-select is available as an npm package.

To install and save in your package.json dependencies, run:

// with npm
npm install react-timezone-map-select

// with yarn
yarn add react-timezone-map-select

Usage

You can use TimeZoneSelectDialog in the same manner as modal dialog in MUI.

import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import React, { ReactElement } from 'react';
import { TimeZoneSelectDialog } from 'react-timezone-map-select';


function App(): ReactElement {
  /** Timezone name */
  const [timezoneName, setTimezoneName] = React.useState('America/Los_Angeles');

  /** Set true when you open TimeZoneSelectDialog. */
  const [open, setOpen] = React.useState(false);

  /** Called when you press "Open Dialog" button. */
  const handleOpen = React.useCallback(() => {
    setOpen(true);
  }, []);

  /** Called when TimeZoneSelectDialog is closed. */
  const handleClose = React.useCallback((newTimeZoneName: string) => {
    setTimezoneName(newTimeZoneName);
    setOpen(false);
  }, []);

  return (
    <Container>
      <Box>
        <p>Timezone = {timezoneName}</p>
      </Box>
      <Box>
        <Button onClick={handleOpen} variant="contained" >
          Open Dialog
        </Button>
      </Box>
      <TimeZoneSelectDialog
        open={open}
        timeZoneName={timezoneName}
        onClose={handleClose}
      />
    </Container>
  );
}

Examples

Simple demo

Customize demo

Properties and Functions

TimeZoneSelectDialog

Property nameTypeDefault ValueDescription
openbooleanfalseIf true, the modal dialog is shown.
onClose(newTZ:string) => voidundefinedCallback fired when the modal dialog is to be closed.
timezoneNamestring"America/Los_Angeles"Initial timezone name.
titlestring"Time Zone"Title string.
descriptionstring"Select a time zone in the list or click an area on the map."Description string.
buttonLabelOkstring"OK"Label on "ok" button.
buttonLabelCancelstring"Cancel"Label on "cancel" button.
SubstituteButtonOk((props: ButtonProps) => ReactElement) | string;@mui/material/ButtonReact component to be used as "ok" button.
SubstituteButtonCancel((props: ButtonProps) => ReactElement) | string;@mui/material/ButtonReact component to be used as "cancel" button.
isOkFirstButtonbooleanfalseIf true, "ok" button comes first (Windows style). Otherwise, "cancel" button comes first (Mac style).

convertOffsetInMinutesToString

function convertOffsetInMinutesToString(offsetInMinutes: number): string

Convert time offset to user friendly string. e.g. -60 ==> "-01:00"

Parameters | Parameter | Type | Description | |------------|--------|----------------| | offsetInMinutes | number | offset from UTC in minutes. |

Return value

User friendly string e.g. "-01:00"

findTimeZone

function findTimeZone(timeZoneName: string): RawTimeZone | undefined

Find a time zone data in @vvo/tzdb.

Parameters

ParameterTypeDescription
timeZoneNamestringTime zone name. Note it could be grouped in "group".

Return value

Time zone data in @vvo/tzdb if found. undefined if not found.

License

react-timezone-map-select is available under the MIT License.

1.2.25

6 days ago

1.2.24

20 days ago

1.2.23

1 month ago

1.2.22

2 months ago

1.2.21

3 months ago

1.2.20

3 months ago

1.2.18

9 months ago

1.2.19

8 months ago

1.2.16

11 months ago

1.2.17

10 months ago

1.2.15

11 months ago

1.2.8

1 year ago

1.2.9

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.14

12 months ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago