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

d-ng-rating

v3.0.0

Published

Rating is Angular component that helps visualising and interacting with a star rating bar.

Downloads

11

Readme

Overview

Rating is Angular component that helps visualising and interacting with a star rating bar.


Usage

Basic rating

In order to create a rating component, we simply have to define it in our component's template:

<d-ng-rating [size]="6"></d-ng-rating>

We need to define size of our rating items and we can do it by defining size mandatory property.

Result label

We can define rating result label that shows clicked rate item.

<d-ng-rating showCancelIcon (rateChange)="this.ratingLabel = $event" (rateCancel)="this.ratingLabel = null" [size]="6">
  <d-ng-rating-label>{{ this.ratingLabel }}</d-ng-rating-label>
</d-ng-rating>

Using form

We can use single form for the rating component. Rating items are set to type='button' in order to prevent sumibssion of the form before rating is completed.

<form [formGroup]="form">
  <d-ng-rating formControlName="ratingControl" [size]="6"></d-ng-rating>
</form>

Cancelable rating

By setting showCancelIcon property to true, we are activating new functionality for canceling current rating. For example, we can cancel our rating if we rate wrong. We can change rating cancel icon by using FontAwesome icons and input property cancelIcon.

<d-ng-rating showCancelIcon [size]="6"></d-ng-rating>

OR

<d-ng-rating [showCancelIcon]="true" [size]="6"></d-ng-rating>

Custom template

In order to use your own rating template, you can define it by using ng-template and hovered template variable. Inside the template virtual element you need to define your rating item element and styling (item color, hovered item color).

<d-ng-rating (rateChange)="this.ratingLabel = $event" [size]="6">
  <ng-template let-hovered="hovered">
    <span class="star" [class.filled]="hovered">&#9733;</span>
  </ng-template>
</d-ng-rating>

Keyboard interaction

  • ArrowUp, ArrowRight: Moves to next rating item
  • ArrowDown, ArrowLeft: Moves to previous rating item
  • Home: Moves to the first step header
  • End: Moves to the last step header

API

Please find the related API below.

Reference

import { NgRatingModule } from 'd-ng-rating';

NgRatingComponent

Selector: d-ng-rating

| Property | Type | Description | Default value | | ------------------------- | --------------------------- | ---------------------------------------------------------------- | ----------------- | | @Input() id | string | Unique id of the element. | Auto-generated | | @Input('aria-label') | string | Used to set the aria-label attribute on the rating. | star | | @Input('aria-labelledby') | string | Used to set the aria-labelledby attribute on the rating. | Star rating | | @Input() rating | number | Used to set a number of initially selected items. | 0 | | @Input() size | number | Used to set maximal rating that can be given. | 5 | | @Input() readonly | boolean | If true, the rating can't be changed. | false | | @Input() disabled | boolean | Used to set disabled property for rating. | false | | @Input() showCancelIcon | boolean | Whether a cancel icon will be shown for canceling rating. | false | | @Input() icon | IconDefinition | Used to set icon for rating item. FontAwesome used for icons. | faStar | | @Input() cancelIcon | IconDefinition | Used to set icon for cancel button. FontAwesome used for icons. | faBan | | @Output() rateChange | EventEmitter | Event emitted when the rate is changed (rating item is clicked). | No default value. | | @Output() rateCancel | EventEmitter | Event emitted when rating is canceled. | No default value | | @Input() ratingTemplate | TemplateRef | Define custom template and pass as reference. | No default value |

Dependency

In order to use our rating star and cancel icons you will need to install @fortawesome/angular-fontawesome package as peer dependency. You can find this npm package HERE. If you want to use your own custom rating template, then you don't need to install the peer dependency.

List of dependencies:

  • @fortawesome/angular-fontawesome
  • @fortawesome/fontawesome-svg-core
  • @fortawesome/free-solid-svg-icons
  • @angular/cdk

Interfaces

IRatingContext

export interface IRatingContext {
  hovered: boolean;
}

Accessibility

The rating component has role attribute set to slider.
The component exposes aria inputs in order to provide accessible experience. The components should be given a meaningful label via aria-label or aria-labelledby. By default aria-label is set to star and aria-labelledby to Star rating.