rating-control
Version:
Simple rating control
89 lines (50 loc) • 1.79 kB
Markdown
A simple rating control
Basic demo [here](http://requirebin.com/?gist=0275fc20dc656815d94d)
Complex demo [here](http://requirebin.com/?gist=ec110b224eb87dc1a47c)
npm i rating-control
var Rating = require('rating-control');
rating = new Rating();
window.document.body.appendChild(rating.element);
The constructor can take an options object that can have the following properties
{
element, // top level element to insert itemsElement into
itemsElement, // element to insert the actual items into
itemTemplate, // template element to be cloned for each item
items, // array of item values to be represented
value, // starting value
enabled, // enabled state
removeDefaultStyle // do not include the default styling of the control
}
The current value of the control
rating.value(); // gets the value
rating.value(123); // sets the value to 123
rating.on('value', function(value){
// triggered when the value changes
// parameter `value` is the updated value
});
The array of item values to be represented
rating.items(); // gets the items array
rating.items([1, 2, 3]); // sets the items array to [1, 2, 3]
rating.on('items', function(items){
// triggered when the items array changes
// parameter `items` is the updated items
});
Can the value be changed by a click event (programmatic access still works)
#### get
rating.enabled(); // gets the enabled state
rating.enabled(false); // sets the enabled state to false