1.0.1 • Published 5 years ago

csdemo-weather-widgets v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Built With Stencil

Demo Weather Widgets

This is a sample custom element library that contains some simple weather related elements. This library contains the following custom elements:

  • Simple
    • csdemo-temperature - takes a temperature in Kelvin and displays the value in either Celcius or Fahrenheit
    • csdemo-uv-index - takes a UV Index value and displays the value with a description and color coding
    • csdemo-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
    • csdemo-daily-forecast - condition, date, low, high

Usage

This library is not currently published to NPM, so the easiest way to include it is to:

  1. npm run build
  2. npm link
  3. then in any consuming project - npm link csdemo-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 csdemo so the ignoredElements line is Vue.config.ignoredElements = [/csdemo-\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.

csdemo-temperature

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

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

csdemo-condition

Displays the current condition in both text and icon form.

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

csdemo-daily-forecast

Displays the forcast for a given day.

<csdemo-daily-forecast scale="F" [forecasts]="forecastData" [iconPaths]="iconMap"></csdemo-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.

csdemo-uv-index

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

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