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

@zulkarnainshah/ng-rating-bar

v0.0.26

Published

Fully customizable rating bar component for Angular based apps

Downloads

20

Readme

NgRatingBar

ng-rating-bar is a fully customizable rating bar component for Angular based applications. It supports displaying read-only ratings, editable ratings, average ratings, customizable icons/images to use in place of the default stars and much more.

This library was generated with Angular CLI version 13.2.0.

Installation

  1. Run npm i @zulkarnainshah/ng-rating-bar to install the library

  2. Create a new folder named ng-rating-bar inside your assets folder

  3. Modify your angular.json file to add the following object to the assets array after the src/assets line :

    "assets":[ "src/favicon.ico", "src/assets",

    {
      "glob": "**/*",
      "input": "./node_modules/@zulkarnainshah/ng-rating-bar/assets",
      "output": "./assets/ng-rating-bar"
    }

    ]

Import

  1. In your app.module.ts file add the following import:

import NgRatingBarModule from @zulkarnainshah/ng-rating-bar
  1. Then add NgRatingBarModule in the imports array of app.module.ts:

imports: [...., NgRatingBarModule]

Using custom images for stars (optional):

By default 3 image resources are included with the library for showing filled, half and empty stars. You can modify the images for each of those states by supplying your own images. Just place your png images (at least 256 x 256) inside the assets folder (not necessarily inside the ng-rating-bar folder) and pass their path as input parameters to the component for the following attributes:

  • filledImgSrc
  • halfFilledImgSrc
  • emptyImgSrc

Basic usage

You can use the component in any of your templates like below:

Example 1 : Using default 5 as totalStars and setting the rating to 4.

<ng-rating-bar
[rating]="4">
</ng-rating-bar>

Example 2 : 6 totalStars with fractional rating

<ng-rating-bar
  [rating]="1.5"
  [totalStars]="6">
</ng-rating-bar>

Example 3: Changing the default size of the star images

<ng-rating-bar
  [rating]="1.5"
  [totalStars]="10"
  size="40px">
</ng-rating-bar>

Example 4: Using custom images for filled, half-filled and empty stars

<ng-rating-bar
  [rating]="3.5"
  [totalStars]="5"
  size="25px"
  filledImgSrc="../../assets/tomato.png"
  halfFilledImgSrc="../../assets/tomato_half.png"
  emptyImgSrc="../../assets/tomato_empty.png">
</ng-rating-bar>

Example 5: Disabling mouse events by passing true to the disabled property

<ng-rating-bar
  [rating]="3"
  [totalStars]="5"
  [disabled]="true"
  >
</ng-rating-bar>

Example 6: Handling ratingChanged event

<ng-rating-bar
  [rating]="3.5"
  [totalStars]="5"
  (ratingChanged)="onRatingChanged($event)">
</ng-rating-bar>

onRatingChanged method you will implement in your component and the $event parameter will contain the new rating (number type)

Properties table

| Name | Type | Required | Default | | :--------------- | ------- | -------- | :----------------------------------- | | rating | number | optional | 0 | | totalStars | number | optional | 5 | | size | string | optional | 20px | | filledImgSrc | string | optional | assets/ng-rating-bar/star_filled.png | | halfFilledImgSrc | string | optional | assets/ng-rating-bar/star_half.png | | emptyImgSrc | string | optional | assets/ng-rating-bar/star_empty.png | | disabled | boolean | optional | false | | animateOnHover | boolean | optional | true | | gap | string | optional | 3px |

Events table

| Name | Return Type | Required | Fires when | | :------------ | ----------- | -------- | :-------------------- | | ratingChanged | number | optional | User clicks on a star |

Demo