Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-timezone-select

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timezone-select

Usable, dynamic React Timezone Select

  • 0.10.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
increased by2.24%
Maintainers
1
Weekly downloads
 
Created
Source

🌐⌚ react-timezone-select

Bundlephobia NPM Downloads npm GitHub issues MIT

Another react timezone select component, I know.. However this one has a few key benefits!

While looking around for a good option, I had trouble finding a timezone select components which:

1) Adjusted the choices automatically with Daylight Savings Time (DST)
2) Didn't have a huge list of choices to scroll through when technically only 24 (ish) are necessary

Update: v0.7+ now built with spacetime instead of moment.js, reducing bundle size by ~66%!

Demo: ndom91.github.io/react-timezone-select

This demo is also available in the ./examples directory. Simply run npm start after installing everything and webpack dev server should begin, where you will be able to find the demo locally at localhost:3001.

There is another Demo available on Codesandbox showing how to adjust the timezone of a selected spacetime object, like how one might use this in a real app.

🏗️ Installing

npm install react-timezone-select

🔭 Usage

import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import TimezoneSelect from 'react-timezone-select'

const App = () => {
  const [selectedTimezone, setSelectedTimezone] = useState({})

  return (
    <div className='App'>
      <h2>react-timezone-select</h2>
      <blockquote>Please make a selection</blockquote>
      <div className='select-wrapper'>
        <TimezoneSelect
          value={selectedTimezone}
          onChange={setSelectedTimezone}
        />
      </div>
      <h3>Output:</h3>
      <div className='code'>
        <span style={{ fontWeight: '500' }}>selectedTimezone: {'{'}</span>{' '}
        <br />
        <span style={{ marginLeft: '20px', fontWeight: '500' }}>
          value: '{selectedTimezone.value}'
        </span>
        <br />
        <span style={{ marginLeft: '20px', fontWeight: '500' }}>
          label: '{selectedTimezone.label}'
        </span>
        <br />
        {'}'}
      </div>
    </div>
  )
}

const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)

🕹️ Props

Update v0.10.1+ we're now built with Typescript!

  • value - { value: string, label: string }
  • onBlur - () => void
  • onChange - (timezone) => void
    • Where timezone is, for example:
     {
       value: 'America/Juneau'
       label: '(GMT-8:00) Alaska (AHDT)'
     }
    
  • labelStyle - 'original' | 'altName' | 'abbrev'
  • timezone - Custom Timezone Object
  • Any other react-select props

🕒 Custom Timezones

Available in v0.9.11+ - we've shipped a new prop to allow users to fully replace the timezone choices, or simply append custom choices of their own.

The prop timezones takes an object where the key/value format is: 'Official Timezone Name' : 'Your Label for it'.

For example:

import TimezoneSelect, { i18nTimezones } from 'react-timezone-select'
...

<TimezoneSelect
  value={selectedTimezone}
  onChange={setSelectedTimezone}
  timezones={{
     ...i18nTimezones,
    'America/Lima': 'Pittsburgh',
    'Europe/Berlin': 'Frankfurt',
  }}
/>

Here you can see how to append two new choices to the existing ones (i18nTimezones). You can also omit the i18nTimezones object in the prop and pass your own completely custom list of timezone choices.

🚧 Contributing

Pull requests are always welcome!

🙏 Thanks

Keywords

FAQs

Package last updated on 06 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc