1.0.0 ā€¢ Published 4 years ago

@ayltai/react-weather v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-weather

Gorgeous React components to display weather information based on Material UI.

CategoryMeasurement
PipelineCircleCI
QualityCode Quality Sonar Quality Gate Sonar Violations (short format)
CoverageCode Coverage Sonar Coverage
RatingMaintainability Rating Reliability Rating Sonar Tech Debt
SecuritySecurity Rating Vulnerabilities
MiscellaneousMaintenance Release License

Buy me a coffee

Demo

WeatherBear Screenshot

Installation

npm install @ayltai/react-weather

Usage

// index.jsx
import React from 'react';
import { getWeather, Weather, } from 'react-weather';

const Example = () => {
    const [ weather, setWeather, ] = React.useState({});

    const source = 2; // Weatherbit API
    const unit   = 'si';

    React.useEffect(() => {
        getWeather(22.3080, 113.9185, source, apiKey, 8, 4, 'en-US')
            .then(setWeather)
            .catch(console.error);
    }, []);

    if (weather.currently && weather.hourly && weather.daily) return (
        <>
            <Weather.Currently
                width={320}
                height={160}
                backgroundImageUrl='https://images.unsplash.com/photo-1523643454511-d7e4e5697016?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjI0NDM4fQ'
                location='Hong Kong International Airport, Sky Plaza Road, Chek Lap Kok'
                summaryCurrently={weather.currently ? weather.currently.summary : undefined}
                summaryToday={weather.daily ? weather.daily[0].summary : undefined}
                iconId={weather.currently ? weather.currently.icon : undefined}
                iconType={source}
                temperature={weather.currently ? weather.currently.temperature : undefined}
                temperatureHigh={weather.daily ? weather.daily[0].temperatureHigh : undefined}
                temperatureLow={weather.daily ? weather.daily[0].temperatureLow : undefined}
                humidity={weather.currently ? weather.currently.humidity : undefined}
                windSpeed={weather.currently ? weather.currently.windSpeed : undefined}
                uvIndex={weather.currently ? weather.currently.uvIndex : undefined}
                unit={unit} />
            <Weather.Hourly
                width={320}
                height={160}
                hourly={weather.hourly}
                iconType={source}
                additionalForecast='humidity'
                unit='si' />
            <Weather.Daily
                orientation='vertical'
                date={weather.daily ? new Date(weather.daily[0].time) : undefined}
                summary={weather.daily ? weather.daily[0].summary : undefined}
                iconId={weather.daily ? weather.daily[0].icon : undefined}
                iconType={source}
                temperatureHigh={weather.daily ? weather.daily[0].temperatureHigh : undefined}
                temperatureLow={weather.daily ? weather.daily[0].temperatureLow : undefined}
                humidity={weather.daily ? weather.daily[0].humidity : undefined}
                precipProbability={weather.daily ? weather.daily[0].precipProbability : undefined}
                precipIntensity={weather.daily ? weather.daily[0].precipIntensity : undefined}
                windSpeed={weather.daily ? weather.daily[0].windSpeed : undefined}
                windSpeedSuffix='km/h'
                uvIndex={weather.daily ? weather.daily[0].uvIndex : undefined}
                unit={unit} />
        </>
    );

    return <div />;
};

getWeather parameters

NameTypeDefault valueDescription
sourceNumberWeather API source
apiKeyStringAPI key for specific weather source
latitudeNumberLatitude of weather location
longitudeNumberLongitude of weather location
hoursNumber8Number of future hours to forecast. Must be between 1 (inclusive) and 12 (inclusive).
daysNumber4Number of future days to forecast. Must be between 1 (inclusive) and 4 (inclusive).
localeStringen-USLocale of weather summaries

Weather API source

SourceValue
Dark Sky0
AccuWeather1
Weatherbit2

API key

SourceDefault value
Dark Skyprocess.env.REACT_APP_DARK_SKY_API_KEY
AccuWeatherprocess.env.REACT_APP_ACCU_WEATHER_API_KEY
Weatherbitprocess.env.REACT_APP_WEATHER_BIT_API_KEY

āš  Note that you are not allowed to make Dark Sky API calls from client-facing code. However, it is possible to use it native applications such as Electron.

<Weather.Currently /> props

NameTypeRequiredDefault valueDescription
widthNumberYesWidth of this component in pixels
heightNumberYesHeight of this component in pixels
locationStringNoA string representing the weather location
summaryCurrentlyStringNoA string that summaries the current weather condition
summaryTodayStringNoA string that summaries the weather today
iconIdString or NumberNoA weather source specific string or number representing the weather icon
iconTypeNumberNo0 (Dark Sky)The weather source type
temperatureNumberNoThe current temperature
temperatureHighNumberNoThe expected maximum temperature of today
temperatureLowNumberNoThe expected minimum temperature of today
humidityNumberNoThe current humidity
windSpeedNumberNoThe current average wind speed
uvIndexNumberNoThe current UV index
unitStringNosiThe unit of the values supplied to this component

<Weather.Hourly /> props

NameTypeRequiredDefault valueDescription
classNameStringNoA string representing the name of CSS style to apply to this component
widthNumberYesWidth of this component in pixels
heightNumberYesHeight of this component in pixels
hourlyObject arrayNoThe hourly object array returned by calling getWeather()
chartLabelStringNoHourly forecastA string representing the hourly weather chart title
iconTypeNumberNo0 (Dark Sky)The weather source type
temperatureLabelStringNošŸŒ”The prefix prepended to temperatureHigh and temperatureLow in tooltip
humidityLabelStringNošŸŒ¢The prefix prepended to humidity
precipitationLabelStringNošŸŒ§The prefix prepended to precipProbability and precipIntensity
windSpeedLabelStringNošŸ’ØThe prefix prepended to windSpeed in tooltip
windSpeedSuffixStringNokm/hThe suffix appended to windSpeed; typically you could use km/h
uvIndexLabelStringNoā˜€The prefix prepended to uvIndex in tooltip
additionalForecastStringNohumidityShow additional weather information as the 3rd line in the weather chart
unitStringNosiThe unit of the values supplied to this component
timeFormatStringNohaA string representing the hour format

<Weather.Daily /> props

NameTypeRequiredDefault valueDescription
orientationStringNohorizontalThe layout of this component, either horizontal or vertical
dateNumberNoThe weather date used to display the weekday
summaryStringNoA string representing the expected weather condition of this day
iconIdString or NumberNoA weather source specific string or number representing the weather icon
iconTypeNumberNo0 (Dark Sky)The weather source type
temperatureHighNumberNoThe expected maximum temperature of this day
temperatureHighLabelStringNošŸ”„The prefix prepended to temperatureHigh
temperatureLowNumberNoThe expected minimum temperature of this day
temperatureLowLabelStringNoā„The prefix prepended to temperatureLow
temperatureLabelStringNošŸŒ”The prefix prepended to temperatureHigh and temperatureLow in tooltip
humidityNumberNoThe expected humidity of this day
humidityLabelStringNošŸŒ¢The prefix prepended to humidity
precipProbabilityNumberNoThe probability of having any precipitation on this day
precipIntensityNumberNoThe expected precipitation intensity of this day
precipLabelStringNošŸŒ§The prefix prepended to precipProbability and precipIntensity
windSpeedNumberNoThe expected wind speed of this day
windSpeedLabelStringNošŸ’ØThe prefix prepended to windSpeed in tooltip
windSpeedSuffixStringNoThe suffix appended to windSpeed; typically you could use km/h
uvIndexNumberNoThe expected UV index of this day
uvIndexLabelStringNoā˜€The prefix prepended to uvIndex in tooltip
unitStringNosiThe unit of the values supplied to this component

iconType

SourceValue
Dark Sky0
AccuWeather1
Weatherbit2

unit

ValueDescription
siSI units
imperialImperial units

timeFormat

ValueDescription
HH24-hour format, e.g. 18
ha12-hour format, e.g. 6pm

additionalForecast

ValueDescription
humidityShow humidity information as the 3rd line in the weather chart
windSpeedShow wind speed information as the 3rd line in the weather chart
uvIndexShow UV index information as the 3rd line in the weather char

Acknowledgements

This software is made with the support of open source projects:

... and closed source services:

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago