This is an Aurelia plugin in order for developers to create star-rate elements in their apps.
-
run the following command :
npm install aurelia-multi-select --save
or if you are using yarn
yarn add aurelia-multi-select
then update the
aurelia.json
with the following :{ "name": "aurelia-multi-select", "path": "../node_modules/aurelia-multi-select/dist/amd", "main": "aurelia-multi-select", "resources": [ "elements/multi-select.html" ] }
no need to mention that you should have added jquery and bootstrap in
aurelia.json
file"jquery", { "name": "bootstrap", "path": "../node_modules/bootstrap/dist", "main": "js/bootstrap.min", "deps": ["jquery"], "exports": "$", "resources": [ "css/bootstrap.css" ] }
then add the plugin in your
main.ts
ormain.js
file..plugin("aurelia-multi-select")
-
Run the jspm install command :
jspm install aurelia-multiple-select=github:bondib/aurelia-multiple-select
then update your
main.ts
ormain.js
file..plugin("aurelia-multi-select")
Using the control in your .html files is so simple ;-)
<star-rate color="darkgoldenrod" read-only.bind="false" rate.bind="viewmodel.rate & validate" max-rate.bind="5"></star-rate>
keep in mind that once again you need the following line somwhere in your htmls :
<require from="bootstrap/css/bootstrap.css"></require>
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
StarRateClicked
message will be published which hasnewRate
andoldRate
as its data
import { EventAggregator } from 'aurelia-event-aggregator';
import { StarRateClicked } from 'aurelia-multi-select';
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
.html
file useclicked.call
as follows
<star-rate clicked.call="star_clicked(newRate,oldRate)" max-rate.bind="8" rate.one-way="6" read-only.bind="false" color="darkgoldenrod"></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}`);
}
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
dist
folder, 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.js
for other tasks related to generating the docs and linting.