kws-weather-widgets
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

Built With Stencil

My Weather Widgets

This is a sample web component library that contains some simple weather related widgets. This library contains the following components:

  • Simple
    • kws-temperature - takes a temperature in Kelvin and displays the value in either Celcius or Fahrenheit
    • kws-uv-index - takes a UV Index value and displays the value with a description and color coding
    • kws-condition - given a mapping of condition types to image URLs and a condition code, determines which code to use and displays the image with a label
  • Compound
    • kws-daily-forecast - condition, date, low, high

Usage

Include the library in your project: npm i kws-weather-widgets

The Stencil documentation site has an excellent Framework Integration Guide. Following that to guide to integrate the library with your project.

Note: if you are using Vue, the prefix used is kws so the ignoredElements line is Vue.config.ignoredElements = [/kws-\w*/];.

Images

This library does not include its own images. In order to inform the library how to get the images to use, you need to set up a map that specifies the image file to use for each of the weather conditions.

Here is an example:

export class IconMap {
  sunny = 'assets/images/sunny.png';
  cloudy = 'assets/images/cloudy.png';
  lightRain = 'assets/images/rain.png';
  shower = 'assets/images/shower.png';
  sunnyThunderStorm = 'assets/images/partial-tstorm.png';
  thunderStorm = 'assets/images/tstorm.png';
  fog = 'assets/images/fog.png';
  snow = 'assets/images/snow.png';
  unknown = 'assets/images/unknown.png';
}

Components

Any component that take a condition assumes that the condition is one of the condition codes used by OpenWeatherMap.org.

Examples shown below are using Angular property bindings. Use whatever is appropriate for the architecture of your application.

kws-temperature

Displays the temperature, given in Kelvin, in the given scale (C or F).

<kws-temperature scale="F" temperature="297"></kws-temperature>

kws-condition

Displays the current condition in both text and icon form.

<kws-condition [condition]="200" [iconPaths]="iconMap"></kws-condition>

kws-daily-forecast

Displays the forcast for a given day.

<kws-daily-forecast scale="F" [forecasts]="forecastData" [iconPaths]="iconMap"></kws-daily-forecast>

The forecast property is an array of forecast data for a single day in the following format:

export interface Forecast {
  date: Date;
  condition: number;
  temperature: number;
}

This data will be the weather conditions every X hours throughout the day. The component figures out a general condition to use for that day from the given data.

The temperature is specified in Kelvin.

kws-uv-index

Displays the UV index along with a risk level, in a color appropriate for the level of risk.

<kws-uv-index [uvIndex]="value"></kws-uv-index>

Readme

Keywords

none

Package Sidebar

Install

npm i kws-weather-widgets

Weekly Downloads

4

Version

2.0.3

License

MIT

Unpacked Size

2.68 MB

Total Files

112

Last publish

Collaborators

  • kensodemann