1.0.0 • Published 1 year ago

afrorating v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

AfroRating

CircleCI NPM Vesion NPM Downloads

AfroRating is an Angular frontend star rating library.

Installing

npm install afrorating

Usage

Component

import { Component } from '@angular/core';
import { AfroRatingComponent } from 'afrorating';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [AfroRatingComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  rate = 5;

  onHoverChange(event: MouseEvent) {
    console.log("hoverchanged", event);
  }

  onRateChange(value: number) {
    console.log("ratechanged", value);
  }
}

Template

<div style="width:100%">
    <afrorating [total]="10" [(rate)]="rate" [color]="'#ce0101'" [scaleDown]="10" (rateChange)="onRateChange($event)" (hoverChange)="onHoverChange($event)" [readonly]="false"></afrorating>
</div>

<div style="display:flex;flex-direction:row;width:50%;align-items:stretch;">
        <afrorating [total]="10" [(rate)]="rate" [color]="'green'" [showTooltip]="false" [readonly]="true"></afrorating>
        <div style="text-align:center;width:6vw;font-size:4vw;padding-left:1vw;padding-right:1vw" [style]="rate ? '' : 'visibility:hidden'">
            {{rate}}
        </div>
        <button (click)="rate=0" style="width:10vw;color:white;background-color:green;">Clear</button>
</div>

Input Attributes

NameTypeDefaultDescription
colorstring"green"CSS color value of icons
ratenumber0Current rating value
readonlybooleanfalseWhether or not to make icons interactive
scaleDownnumber0Value to shrink icon size
showTooltipbooleantrueWhether or not to display value on hover
totalnumber5Max value of rating scale

Events

NameTypePayloadDescription
hoverChangefunctionMouseEventFunction to call when hover event changes
rateChangefunctionnumberFunction to call when rating value changes