npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ionic-enterprise/cs-demo-weather-widgets-angular

v3.1.3

Published

Angular specific proxies for @ionic-enterprise/cs-demo-weather-widgets

Downloads

14

Readme

Weather Widgets - Angular

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

  • Simple
    • csdemo-temperature - takes a temperature in Kelvin and displays the value in either Celsius 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

This package is intended for use in an Angular application. It wraps the web components in Angular proxies that make using the web components more natural within an Angular application.

This project is intended to be a simple example of how these proxies work with Stencil based web component projects. It is not intended to be a full-featured component library.

Installation

npm @ionic-enterprise/cs-demo-weather-widgets-angular

Adjust accordingly if you are using yarn, pnpm, etc.

Usage

Module

Any module that is going to use a Weather Widget component needs to import the appropriate module or modules.

The most efficient strategy to use is to import the module(s) associated with the individual component(s) that will be used. For example:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CsdemoConditionModule, CsdemoTemperatureModule } from '@ionic-enterprise/cs-demo-weather-widgets-angular';
import { IonicModule } from '@ionic/angular';
import { CurrentWeatherPageRoutingModule } from './current-weather-routing.module';
import { CurrentWeatherPage } from './current-weather.page';

@NgModule({
  imports: [
    CommonModule,
    CsdemoConditionModule,
    CsdemoTemperatureModule,
    CurrentWeatherPageRoutingModule,
    FormsModule,
    IonicModule,
  ],
  declarations: [CurrentWeatherPage],
})
export class CurrentWeatherPageModule {}

The CsdemoWeatherWidgetsModule module can be imported instead of individual component modules. This is more convenient, but it will also lead to larger bundle sizes.

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CsdemoWeatherWidgetsModule } from '@ionic-enterprise/cs-demo-weather-widgets-angular';
import { IonicModule } from '@ionic/angular';
import { ForecastPageRoutingModule } from './forecast-routing.module';
import { ForecastPage } from './forecast.page';

@NgModule({
  imports: [IonicModule, CommonModule, CsdemoWeatherWidgetsModule, FormsModule, ForecastPageRoutingModule],
  declarations: [CurrentWeatherPage],
})
export class CurrentWeatherPageModule {}

Components

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

csdemo-temperature

Displays the temperature, supplied in Kelvin, in the specified 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"></csdemo-condition>

csdemo-daily-forecast

Displays the forecast for a given day.

<csdemo-daily-forecast scale="F" [forecast]="forecastData"></csdemo-daily-forecast>

The forecast property is a forecast data object in the following format:

export interface Forecast {
  date: Date;
  condition: number;
  low: number;
  high: number;
}

The low and high temperatures are 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>

Image Handling

This library includes a set of images under node_modules/@ionic-enterprise/cs-demo-weather-widgets/dist/images. If you copy all of these images to src/assets/images they will be automatically loaded by the components that need them.

You are also free to use your own images, copy them to a different location, and/or name some of the images differently.

If you use a different location or name, you will need to specify a mapping that the components can use. In Angular applications, it is often useful to attach this mapping object to the environment object as such:

export const environment = {
  production: false,
  icons: {
    sunny: 'alt/location/sunny.png',
    cloudy: 'alt/location/cloudy.png',
    lightRain: 'alt/location/light-rain.png',
    shower: 'alt/location/shower.png',
    sunnyThunderstorm: 'alt/location/sunny-tstorm.png',
    thunderstorm: 'alt/location/tstorm.png',
    fog: 'alt/location/fog.png',
    snow: 'alt/location/snow.png',
    unknown: 'alt/location/unknown.png',
  },
};

You can also specify a partial list if only only a couple of icons are different or have different names:

export const environment = {
  production: false,
  icons: {
    sunnyThunderstorm: 'assets/images/partial-tstorm.png',
    unknown: 'assets/images/this-is-wrong.png',
  },
};

If you have multiple environments, refactor as needed to keep your code DRY.

You can pass the icons to any component that has a iconPaths property:

<csdemo-condition [condition]="200" [iconPaths]="icons"></csdemo-condition>
<csdemo-daily-forecast scale="F" [forecast]="forecast" [iconPaths]="icons"></csdemo-daily-forecast>

Conclusion

That is it. We also have a demo application you can check out if you would like to.

Happy Coding!! 🤓