ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - MurhafSousli/ngx-bar-rating: Angular Bar Rating
Angular Bar Rating. Contribute to MurhafSousli/ngx-bar-rating development by creating an account on GitHub.
Visit Site

GitHub - MurhafSousli/ngx-bar-rating: Angular Bar Rating

GitHub - MurhafSousli/ngx-bar-rating: Angular Bar Rating

npm npm npm npm


If you like this plugin, please give it a star ⭐.

Table of Contents

Installation

Install it with npm

npm i ngx-bar-rating

Basic usage:

Import BarRating or BarRatingModule in your component imports.

@Component({
  standalone: true,
  selector: 'bars',
  template: `
    <bar-rating [(rate)]="rate"/>
  `,
  styleUrl: './example.component.scss',
  imports: [BarRating]
})
export class BarsComponent {
  rate: number = 4;
}

Import the theme in your global styles (unless you want to use custom template)

@import 'ngx-bar-rating/themes/br-default-theme';

Rating inputs and outputs:

Name Description Default
[rate] Current rating. Can be a decimal value like 3.14 null
[max] Maximal rating that can be given using this widget 5
[theme] Theme class, see available themes default
[readonly] A flag that indicates if rating can be changed false
[showText] Display rating title if available, otherwise display rating value false
[required] A flag that indicates if rating is disabled. works only with forms false
[disabled] A flag that indicates if rating is disabled. works only with forms false
[titles] Titles array. array should represent all possible values including 0 []
(rateChange) A stream that emits when the rating value is changed

Custom rating template

BarRatingModule provides a couple of directives to set custom rating template of your choice.

  • *ratingActive: Set template, when a bar/star is active or hovered.
  • *ratingInactive: Set template, when a bar/star is inactive.
  • *ratingFraction: Set template, when a bar/star is a fraction.

Here are some example:

Bootstrap rating example

<bar-rating [(rate)]="rate" max="5">
  <i *ratingActive class="bi bi-star-fill" style="margin: 2px; color: #edb867"></i>
  <i *ratingInactive class="bi bi-star-fill" style="margin: 2px; color: #d2d2d2"></i>
</bar-rating>

FontAwesome rating example

<bar-rating [(rate)]="rate" max="10">
  <fa-icon *ratingInactive [icon]="['far', 'star']" [fixedWidth]="true" size="lg" style="color: #d2d2d2"/>
  <fa-icon *ratingActive [icon]="['fas', 'star']" [fixedWidth]="true" size="lg" style="color: #50e3c2"/>
  <fa-icon *ratingFraction [icon]="['fas', 'star-half-alt']" [fixedWidth]="true" size="lg" style="color: #50e3c2"/>
</bar-rating>

Movie rating example

<bar-rating [(rate)]="rate" max="4" theme="movie" showText
            [titles]="['Bad', 'Mediocre' , 'Good', 'Awesome']"/>

It can be used with Angular forms:

<form #form="ngForm">
  <bar-rating name="rating" [(ngModel)]="formRating" [max]="4" required disabled></bar-rating>
</form>
<p>form is valid: {{ form.valid ? 'true' : 'false' }}</p>
<pre>{{ formRating }}</pre>

And reactive forms:

<form [formGroup]="ratingForm">
  <bar-rating formControlName="rate" [max]="4" required disabled></bar-rating>
</form>
<p>form is valid: {{ form.valid ? 'true' : 'false' }}</p>
<pre>{{ formRating }}</pre>

CSS variables

  • --br-font-size Sets the size of the step for the following themes: [default, square, stars].
  • --br-width Sets the width of the step for the following themes: [stars, square, movie, vertical, horizontal].
  • --br-height Sets the height of the step for the following themes: [stars, square, movie, vertical, horizontal].
  • --br-gap Sets the gap between the stars.
  • --br-active-color Sets active color.
  • --br-inactive-color Sets inactive color.

Predefined themes

If you want to use a custom rating template, you don't need to import any CSS theme.

If you want to use one of the predefined themes, you will need to import it in the global style style.scss

  • Pure CSS stars (default) theme="default"
@import 'ngx-bar-rating/themes/br-default-theme';
  • Horizontal bars theme="horizontal"
@import 'ngx-bar-rating/themes/br-horizontal-theme';
  • Vertical bars theme="vertical"
@import 'ngx-bar-rating/themes/br-vertical-theme';
  • Custom stars theme="stars"
@import 'ngx-bar-rating/themes/br-stars-theme';
  • Movie rating theme="movie"
@import 'ngx-bar-rating/themes/br-movie-theme';
  • Square rating theme="square"
@import 'ngx-bar-rating/themes/br-square-theme';

Rating style can be easily customized, check the classes used in any theme and add your own css.

You can also do the same for forms classes such as untouched, touched, dirty, invalid, valid ...etc

Issues

If you identify any errors in this component, or have an idea for an improvement, please open an issue. I am excited to see what the community thinks of this project, and I would love your input!

Author

Murhaf Sousli

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory