0.0.5 • Published 4 years ago

@eggtronic/react-weather-widget v0.0.5

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

☁️ react-weather-widget ☁️

☁️ A nice weather widget for react based on openweather - Demo

npm.io npm.io npm.io



Install

NPM


✨ Feature

  • Light Weight - the only peer dependency is styled-components
  • Typescript Support
  • Customizable Theme
  • Geo Detection - detect you geo location by default

🖥 Peer Dependency

  • react: "^16.8.0"
  • react-dom: "^16.8.0"
  • styled-components: "^4.0.0"

🌈 Usage

  • Basic

    import React from 'react';
    import WeatherWidget from '@eggtronic/react-weather-widget';
    
    function Basic() {
      const key = 'xxx'; // your openweathermap api key
    
      return (
        <WeatherWidget apiKey={key} />
      );
    }
  • Theme

    import React from 'react';
    import WeatherWidget, {
      darkTheme,
      lightTheme,
      defaultTheme
    } from '@eggtronic/react-weather-widget';
    function Theme() {
      const key = 'xxx'; // your openweathermap api key
    
      return (
        <WeatherWidget 
          apiKey={key} 
          theme={darkTheme}
        />
      );
    }
  • Customize Theme

    import React from 'react';
    import WeatherWidget from '@eggtronic/react-weather-widget';
    function CustomTheme() {
      const key = 'xxx'; // your openweathermap api key
      const theme = {
        color: ['#b92b27', '#1565C0'], // graient color of background
        width: '500px', // widget width
        height: '650px', // widget height
        mainFontSize: '24px', // main text size
        subFontSize: '14px', // sub text size
        mainFontColor: '#fff', // main text color
        subFontColor: '#fff', // sub text color
        hrColor: '#fff', // hr line color
    
        // line chart styles
        lineChartPadding: [45, 30],
        lineChartLabelPadding: [-10, -10],
        lineChartColor: '#fff',
        lineChartLabelColor: '#fff',
        lineChartLabelSize: 1,
        lineChartHeight: '120px'
      }
    
      return (
        <WeatherWidget 
          apiKey={key} 
          theme={theme}
        />
      );
    }
  • Others

    import {
      WeatherHeader, 
      WeatherHourly, 
      WeatherDaily,
      LineChart
    } from '@eggtronic/react-weather-widget';
    
    // you can use those child components independently

📝 Props

NameTypeDefaultDescription
classNamestringAdditional CSS class for the root DOM node
apiKeystringYour api key from OpenWeatherMap
geo{lat: string, lon: string} or undefinedundefinedWidget detects your geo by default, you can also specify your own geo location
themeWeatherWidgetThemedefaultThemeCustomize theme
excludeOpenWeatherMapExcludeundefinedOpenWeatherMap api config, exclude daily/hourly/current wealther data
dayRangenumber, number1, 6Specify how many days' weather to display (start from next day)
hourRangenumber, number1, 6Specify how many hours' weather to display (start from next hour)
childrenReactElement[]undefinedReact children

🔨 Development

npm run install
npm run storybook

🧪 Test

npm run test

🔧 Build

npm run build

License

MIT © EggTronic