ninjasort / react-star-rating

[Looking for Maintainers (email me)]: A simple star rating component built with React.
MIT License
173 stars 55 forks source link
react star-rating-component

react-star-rating

NPM

A simple star rating component built with React.

Install

$ npm install react-star-rating --save

Include the css:

<link rel="stylesheet" href="https://github.com/ninjasort/react-star-rating/blob/master/node_modules/react-star-rating/dist/css/react-star-rating.min.css">

Usage

ES6

import React from 'react';
import StarRating from 'react-star-rating';

class FormComponent extends React.Component {
  render() {
    return (
      <form action="/api" method="POST">
        <StarRating name="airbnb-rating" caption="Rate your stay!" totalStars={5} />
        <button type="submit" className="btn btn-submit">Submit Rating</button>
      </form>
    );
  }
}

React.render(<FormComponent />, document.getElementById('star-rating'));

ES5

var React = require('react');
var StarRating = require('react-star-rating');

var FormComponent = React.createClass({
    render: function () {
      return (
        <form action="/api" method="POST">
          <StarRating name="airbnb-rating" caption="Rate your stay!" totalStars={5} />
          <button type="submit" className="btn btn-submit">Submit Rating</button>
        </form>
      );
    }
});

React.render(<FormComponent />, document.getElementById('star-rating'));

Options

Todo

License

MIT