npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mahhoura/react-timezone-select-mui

v1.6.0

Published

Usable, dynamic React Timezone Select

Downloads

18

Readme

🌐⌚ react-timezone-select

NPM Downloads npm GitHub issues Skypack Test CI 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

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

This demo is also available in the ./examples directory. Simply run npm run dev in the root of the repository after installing everything in the examples subdirectory and snowpack dev will begin, where you can find the demo at localhost:8080.

We also have some more examples available on Codesandbox using this component with the datetime library spacetime (example) as well as with moment (example), as well as in Typescript using the new Intl browser API (example) showing how one might use this component in a real application.

🏗️ 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
        style={{
          backgroundColor: '#ccc',
          padding: '20px',
          margin: '20px auto',
          borderRadius: '5px',
          maxWidth: '600px',
        }}
      >
        <pre
          style={{
            margin: '0 20px',
            fontWeight: 500,
            fontFamily: 'monospace',
          }}
        >
          {JSON.stringify(selectedTimezone, null, 2)}
        </pre>
      </div>
    </div>
  )
}

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

🪙 Tips

👤 Default Users Timezone

If you'd like the user's own timezone to be set as the initially selected option on render, we can make use of the new Intl browser API by setting the default state value to Intl.DateTimeFormat().resolvedOptions().timeZone.

const [timezone, setTimezone] = useState(
  Intl.DateTimeFormat().resolvedOptions().timeZone
)

Thanks @ndrwksr!

⚠ Next.js Users

Update: Starting with v1.3.0 you DO NOT need next-transpile-modules to use this library with Next.js anymore!

For now, Next.js isn't great about handling ESM packages. Until this gets fixed, there is a workaround for using this and other ESM packages via next-transpile-modules.

// next.config.js
const withTM = require('next-transpile-modules')(['react-timezone-select'])

module.exports = withTM({
  // ...further Next.js config
})

🕒 Custom Timezones

You can append custom choices of your own, or fully replace the listed timezone options.

The timezones prop takes a dictionary of timezones. Don't worry, we'll prepend the (GMT...) part, you just have to pass the city(s) or region(s) you want in your label.

import TimezoneSelect, { allTimezones } from 'react-timezone-select'
;<TimezoneSelect
  value={selectedTimezone}
  onChange={setSelectedTimezone}
  timezones={{
    ...allTimezones,
    'America/Lima': 'Pittsburgh',
    'Europe/Berlin': 'Frankfurt',
  }}
/>

The above example will generate two additional choices in the select options, one with the label '(GMT-5:00) Pittsburgh' and another with '(GMT+1:00) Frankfurt'. You can omit spreading in the allTimezones object and then only your custom timezone options get rendered in the select component.

🕹️ Props

  • value - Initial Timezone string, i.e. 'Europe/Amsterdam' or the full object from the onChange function: { value: string, label: string, abbrev: string, altName: string }
  • onBlur - () => void
  • onChange - (timezone) => void
    • Example timezone parameter:
     {
       value: 'America/Juneau'
       label: '(GMT-8:00) Alaska,
       abbrev: 'AHST',
       offset: -8,
       altName: 'Alaskan Standard Time'
     }
  • labelStyle - 'original' | 'altName' | 'abbrev'
  • timezones - Custom Timezone Object
  • Any other react-select props

🚧 Contributing

Pull requests are always welcome! Please stick to the prettier settings, and if adding new features, please consider adding test(s) and documentation where appropriate!

🙏 Thanks