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

react-open-weather

v1.3.2

Published

React Weather component

Downloads

3,136

Readme

React Open Weather


Build Status

Coverage Status

React open weather is a React Component loading forecast data from OpenWeather API, WeatherBit and Visual Crossing API.

Without Forecast

With Forecast

Version 1

The component has been fully refactored and now the UI presentation is completely decoupled from the weather provider to allow using any data sources for weather, the component currently comes with 2 weather providers (WeatherBit and OpenWeather), you can create your own provider easily and provide data to the component, the two providers are built as custom react hooks

  • WeatherBit provider (useWeatherBit)
  • OpenWeather provider (useOpenWeather)
  • Visual Crossing provider (useVisualCrossing)
  • Removed the dependency on the weather icon library in favor of SVG icons
  • Removed the dependency on momentjs
  • Allow custom theming to style the component with your colors
  • Fixed some major issues from version 0.6

More providers to be added in the future, feel free to open a pull request with any weather providers that allow a free plan.

For verion 0.6 please find the old read me here v0.6 readme

Dependencies

  • React 16+

Installation


First you will need to register an account on OpenWeather, WeatherBit or Visual Crossing to obtain an API key

Next, in your project directory run:

$ npm install react-open-weather

Usage with OpenWeather

import ReactWeather, { useOpenWeather } from 'react-open-weather';

const App = () => {
  const { data, isLoading, errorMessage } = useOpenWeather({
    key: 'YOUR-API-KEY',
    lat: '48.137154',
    lon: '11.576124',
    lang: 'en',
    unit: 'metric', // values are (metric, standard, imperial)
  });
  return (
    <ReactWeather
      isLoading={isLoading}
      errorMessage={errorMessage}
      data={data}
      lang="en"
      locationLabel="Munich"
      unitsLabels={{ temperature: 'C', windSpeed: 'Km/h' }}
      showForecast
    />
  );
};

Usage with WeatherBit

import ReactWeather, { useWeatherBit } from 'react-open-weather';

const { data, isLoading, errorMessage } = useWeatherBit({
  key: 'YOUR-API-KEY',
  lat: '48.137154',
  lon: '11.576124',
  lang: 'en',
  unit: 'M', // values are (M,S,I)
});

Usage with Visual Crossing

import ReactWeather, { useVisualCrossing } from 'react-open-weather';

const { data, isLoading, errorMessage } = useVisualCrossing({
  key: 'YOUR-API-KEY',
  lat: '48.137154',
  lon: '11.576124',
  lang: 'en',
  unit: 'metric', // values are (metric,us,uk)
});

Custom styling

const customStyles = {
	fontFamily:  'Helvetica, sans-serif',
	gradientStart:  '#0181C2',
	gradientMid:  '#04A7F9',
	gradientEnd:  '#4BC4F7',
	locationFontColor:  '#FFF',
	todayTempFontColor:  '#FFF',
	todayDateFontColor:  '#B5DEF4',
	todayRangeFontColor:  '#B5DEF4',
	todayDescFontColor:  '#B5DEF4',
	todayInfoFontColor:  '#B5DEF4',
	todayIconColor:  '#FFF',
	forecastBackgroundColor:  '#FFF',
	forecastSeparatorColor:  '#DDD',
	forecastDateColor:  '#777',
	forecastDescColor:  '#777',
	forecastRangeColor:  '#777',
	forecastIconColor:  '#4BC4F7',
};

		<ReactWeather
			theme={customStyles}
			...
		/>

useOpenWeather, useWeatherBit and useVisualCrossing options

| Option | Description | | ------ | ----------------------------------------------------------------------------------------------------------------------------------------- | | key | your api key from the openweather, weatherbit or visual crossing websites | | lon | longitude of the location | | lat | latitude of the location | | unit | the unit will be passed to the openweather, weatherbit or visualcrossing "units" property, please check their documentation for more info |

UI Component Props

| Props | Options | Default | Description | | ------------- | ---------------- | --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | data | - | - | the data object provided from the provider hooks or your custom data provider (check the customization section below to provide your own data) | | isLoading | true, false | false | boolean to determine if the component shows a loader until data is ready | | errorMessage | - | - | error message string | | lang | "en", "de", "es" | "en" | the language to show "humidity" and "wind speed", feel free to open a PR to lang.js to add more languages | | locationLabel | - | - | The name of the location or city to show in the component | | unitsLabels | - | { temperature: 'C', windSpeed: 'Km/h' } | the labels to be used for temperature and windspeed | | showForecast | true, false | true | whether or not to show the forecast bottom part of the component |

Customizations

You can always create your own data provider, it can be a react hook or any other implementation as long as it follows the schema the component is expecting like below

    const data = {
      forecast: [
          {
            date: 'Fri 27 November',
            description: 'Clear',
            icon:'SVG PATH',
            temperature: { min: '-0', max: '6' },
            wind: '2',
            humidity: 60,
          },
          {
            date: 'Sat 28 November',
            description: 'Clouds',
            icon:'SVG PATH',
            temperature: { min: '-1', max: '6' },
            wind: '3',
            humidity: 67,
          },
          .....
      ],
      current: {
          date: 'Fri 27 November',
          description: 'Clear',
          icon:'SVG PATH',
          temperature: { current: '-2', min: -3, max: 1 },
          wind: '2',
          humidity: 90,
        },
    };

Translate Wind and Humidity

In lang.js you can implement the necessary translation, to correctly translate Wind and Humidity into other languages, if you want to implement another language, this is where you can do it. Remember to make a Pull request to share it with everyone


langText: {

en: { Wind: 'Wind', Humidity: 'Humidity',},

es: { Wind: 'Viento', Humidity: 'Humedad',}

}

now in order to format the dates according to your locale you will need to import the locale from dayjs and in your code before rendering the component you will need to set the locale as follows

import 'dayjs/locale/de';
import dayjs from 'dayjs';

// then before using the hooks you will need to set the local
dayjs.locale('de');

Contribution

If you want to contribute to the project and make it better, your help is very welcome, create a pull request with your suggested feature/bug fix/ enhancements.