1.1.0 • Published 4 years ago

react-open-weather-widget v1.1.0

Weekly downloads
44
License
MIT
Repository
-
Last release
4 years ago

React Open Weather


Build Status Coverage Status Code Climate

React open weather is a React Component loading forecast data from OpenWeather API.

Features Implemented:

  1. Showing Today Weather
  2. Showing 5 days Weather Forecast

The Component development is in progress and will contain more features in the future versions.

Demo & Docs

Dependencies

Installation


First you will need to register and account on OpenWeather website and obtain an API key

Next, in your project directory run:

    $ npm install react-open-weather

you will need to add link to weather icons css file in your html file or require it in your build process Weather Icons, or you can directly use the CDN.

<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css"
  type="text/css"
/>

Then in your code file you can import the component

Using ES2015 import

import ReactWeather from 'react-open-weather';
//Optional include of the default css styles
import 'react-open-weather/lib/css/ReactWeather.css';

Using CommonJS

var ReactWeather = require('react-open-weather').default;
//Optional include of the default css styles
require('react-open-weather/lib/css/ReactWeather.css');

UMD build is available with script tag

<script src="node_modules/react-open-weather/lib/js/ReactWeather.js"></script>

Usage


1-Loading today weather data by city name

<ReactWeather
  forecast="today"
  apikey="YOUR_API_KEY"
  type="city"
  city="Munich"
/>

2-Loading today data by longitude and latitude

<ReactWeather
  forecast="today"
  apikey="YOUR_API_KEY"
  type="geo"
  lat="48.1351"
  lon="11.5820"
/>

3-Loading today data based on the current IP address (default)

<ReactWeather forecast="today" apikey="YOUR_API_KEY" type="auto" />

3-Loading 5 days forecast

<ReactWeather
  forecast="5days"
  apikey="YOUR_API_KEY"
  type="city"
  city="Munich"
/>

4-Changing the the units to imperial system

<ReactWeather
  forecast="today"
  unit="imperial"
  apikey="YOUR_API_KEY"
  type="city"
  city="Munich"
/>

5-Changing the language

<ReactWeather
  forecast="today"
  unit="imperial"
  apikey="YOUR_API_KEY"
  type="city"
  city="Munich"
  lang="es"
/>

Props Options

PropsOptionsDefaultDescription
type'city', 'geo'cityDetermine the data should be loaded by city name or longitude and latitude
cityName of the city to show forecast for, must be provided if the type='city'
lonLongitude value, must be provided if the type='geo'
latlatitude value, must be provided if the type='geo'
forecast'today', '5days'todayDetermine what forecast to show, today or today plus 4 days ahead
apikeyYour API key for open weather map API
unit'imperial', 'meteric'metericThe unit system you want to use, for Meteric the temperature will be shown in Celsius and distances will be in kilometers, for Imperial the temperature will be shown in Fahrenheit and distances in miles.
langlang codesenReturns 'condition:text' field in API in the desired language, Please pass 'lang code' from below table. e.g.: lang=es

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',}
        }

Language and lang codes from OpenWeather

Languagelang code
Arabicar
Bengalibn
Bulgarianbg
Chinese Simplifiedzh
Chinese Traditionalzh_tw
Czechcs
Danishda
Dutchnl
Finnishfi
Frenchfr
Germande
Greekel
Hindihi
Hungarianhu
Italianit
Japaneseja
Javanesejv
Koreanko
Mandarinzh_cmn
Marathimr
Polishpl
Portuguesept
Punjabipa
Romanianro
Russianru
Serbiansr
Sinhalesesi
Slovaksk
Spanishes
Swedishsv
Tamilta
Telugute
Turkishtr
Ukrainianuk
Urduur
Vietnamesevi
Wu (Shanghainese)zh_wuu
Xiangzh_hsn
Yue (Cantonese)zh_yue
Zuluzu

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.