aurelia-star-rate
v2.0.0
Published
A rating element for Aurelia framework, inspired by [CSS Tricks](https://css-tricks.com/star-ratings/)
Maintainers
Readme
aurelia-star-rate
A rating plugin for Aurelia developers, inspired by Css Tricks.
Versions:
2.0.0: no dependency1.1.0: bootstrap
Breaking changes
- The custom element name has changed from
star-ratetoau-star-rate:weary:
- The custom element name has changed from
1. Installation
Run the following command :
npm install aurelia-star-rate --saveor if you are using yarn
yarn add aurelia-star-rateWebpack
Add
aurelia-star-ratein yourwebpack.configfile in which you haveAureliaPluginentry: { 'app': ['aurelia-bootstrapper', 'aurelia-star-rate'] }then add the plugin in your
main.tsorboot.tsfile (can be alsojsfiles)..plugin(PLATFORM.moduleName("aurelia-star-rate"))Aurelia CLI
Update the
aurelia.jsonwith the following :{ "name": "aurelia-star-rate", "path": "../node_modules/aurelia-star-rate/dist/amd", "main": "aurelia-star-rate", "resources": [ "elements/star-rate.html" ] }then add the plugin in your
main.tsorboot.tsfile (can be alsojsfiles)..plugin("aurelia-star-rate")JSPM
Run the jspm install command :
jspm instal npm:aurelia-star-rate@^1.0.0then update your
main.tsormain.jsfile..plugin("aurelia-star-rate")
2. Usage
HTML
Simple
Using the control in your .html files is as simple as the following simple :wink:
<au-star-rate color="darkgoldenrod" read-only.bind="false" rate.bind="viewmodel.rate" max-rate.bind="5"></au-star-rate>Integrating with other frameworks
This plugin can be used side by side with other frameworks such as font-awesome and bootstrap, the plugin provides three properties which can be assigned by your own css classes.
full-star empty-star half-starto use with font-awesome for instance:
<au-star-rate full-star="fa fa-star" empty-star="fa fa-star-o" half-star="fa fa-star-half-o" rate.bind="viewmodel.rate" max-rate.bind="5"></au-star-rate>bear in mind that this plugin accepts floting point values if and only if you provide a value for
half-starcss class property, otherwise it uses fixed point values. Similarly you can use bootstrap glyphicons.Right to Left support
You can bind the
rtlproperty to a boolean value:<au-star-rate rtl.bind="true" rate.bind="viewmodel.rate" max-rate.bind="5"></au-star-rate>
Events
You can handle the callback for star rate clicked or changed in two forms :
- Globally :
When any of the star-rate elemnts in your dom which are not read only change the rate a
StarRateClickedmessage will be published which hasnewRateandoldRateas its data
import { EventAggregator } from 'aurelia-event-aggregator';
import { StarRateClicked } from 'aurelia-star-rate';
and then subscribe fo the message :
@autoinject
export class Welcome {
constructor(ea: EventAggregator) {
ea.subscribe(StarRateClicked, x => console.info(`E.Aggregator : Rate changed from ${x.oldRate} to ${x.newRate}`));
}
}
- Element based : You can handle seperate event callbacks for individual star-rate elements
in your
.htmlfile useclicked.callas follows
<au-star-rate clicked.call="star_clicked(newRate,oldRate)" max-rate.bind="8" rate.one-way="6" read-only.bind="false" color="darkgoldenrod"></au-star-rate>and then in your .js or .ts file add your event handler :
private star_clicked(newRate, oldRate) {
console.info(`clicked: Rate changed from ${oldRate} to ${newRate}`);
}3. Building The Code
To build the code, follow these steps.
- Ensure that NodeJS is installed. This provides the platform on which the build tooling runs.
- Ensure that Gulp is installed. If you need to install it, use the following command:
npm install -g gulp- From the project folder (root), execute the following command:
npm install && jspm install- Install the typings from the root
typings install- To build the plugin, you can now run:
gulp build- You will find the compiled code in the
distfolder, available in three module formats: AMD, CommonJS and ES2015.
- to run the sample do the followings :
- run ```npm install && jsmp install`` in the sample older
- run
gulp watch
- See
gulpfile.jsfor other tasks related to generating the docs and linting.
