1.0.1 • Published 5 years ago

coffeekraken-s-rating-component v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Coffeekraken s-rating-component

View demo

Table of content

  1. Demo
  2. Install
  3. Get Started
  4. Javascript API
  5. The for property
  6. The basedOn property
  7. Moods
  8. Sugar Web Components Documentation
  9. Browsers support
  10. Code linting
  11. Contribute
  12. Who are Coffeekraken?
  13. Licence

Install

npm install coffeekraken-s-rating-component --save

Get Started

First, import the component into your javascript file like so:

import SRatingComponent from 'coffeekraken-s-rating-component'
import SIconComponent from 'coffeekraken-s-icon-component' // optional but used in the demo

Then simply use it inside your html like so:

<s-rating for="my-cool-input">
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
</s-rating>
<input type="text" name="my-cool-input" id="my-cool-input" />

Here we use an s-icon component as "star" but you can use whatever you prefer. It can be emoji, text, image, etc...

The for property

If you use this rating component in a form, you'll need a proper form input to take care of sending the value or your rating system. This is where comes the for attribute. It's exactly like the for attribute of a label. You specify the id (or name) of your input field using a for and your good to go.

<s-rating for="my-cool-input">
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
</s-rating>
<input type="text" name="my-cool-input" id="my-cool-input" />

The basedOn property

By default, the component will take the number of items (stars) as the base for the value calculation. You can override that by passing a basedOn attribute like so:

View demo

<s-rating based-on="100">
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
</s-rating>

This will mean that the calculation will be based on 100 and not on 5. 1 "Star" will mean 100 / 5 * 1 = 20

Moods

In order to customize your rating system as you want, a system of moods has been implemented. The default moods are xlow, low, medium, high and xhigh. These values are going to be set on the component itself depending on the value of the rating system. Example:

<s-rating based-on="100">
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
  <s-icon driver="fontawesome" icon="fas fa-star"></s-icon>
</s-rating>
  • 1 star : xlow
  • 2 star : low
  • 3 star : medium
  • 4 star : high
  • 5 star : xhigh

You can customize these moods by passing the moods property like so:

<s-rating moods="['hello','world','universe']">
  <!-- etc... -->
</s-rating>

Browsers support

IE / EdgeFirefoxChromeSafari
IE11+last 2 versionslast 2 versionslast 2 versions

As browsers are automatically updated, we will keep as reference the last two versions of each but this component can work on older ones as well.

The webcomponent API (custom elements, shadowDOM, etc...) is not supported in some older browsers like IE10, etc... In order to make them work, you will need to integrate the corresponding polyfill.

Code linting

This package uses some code linting rules. Here's the list:

  1. StandardJS for javascript files
  2. Stylelint with stylelint-config-standard for scss files

Your commits will not been accepted if the code style is not respected!

Contribute

This is an open source project and will ever be! You are more that welcomed to contribute to his development and make it more awesome every day. To do so, you have several possibilities:

  1. Share the love ❤️
  2. Declare issues
  3. Fix issues
  4. Add features
  5. Build web component

Who are Coffeekraken

We try to be some cool guys that build some cool tools to make our (and yours hopefully) every day life better.

More on who we are

License

The code is available under the MIT license. This mean that you can use, modify, or do whatever you want with it. This mean also that it is shipped to you for free, so don't be a hater and if you find some issues, etc... feel free to contribute instead of sharing your frustrations on social networks like an asshole...