react-star-rating

[Looking for Maintainers (email me)]: A simple star rating component built with React.

Github星跟蹤圖

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="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

  • name={string} - name for form input (required)
  • caption={string} - caption for rating (optional)
  • totalStars={number} - rating amount (required, default: 5)
  • rating={number} - a set rating between the rating amount (optional)
  • disabled={boolean} - whether to disable the rating from being selected (optional)
  • editing={boolean} - whether the rating is explicitly in editing mode (optional)
  • size={number} - size of stars (optional)
  • onRatingClick={function} - a handler function that gets called onClick of the rating (optional) - gets passed (event, {position, rating, caption, name})

Todo

  • Fix ES6 bug with bundling
  • Add svg stars
  • Double-check touch support works
  • Re-implement star hovering (kinda janky right now)

License

MIT

主要指標

概覽
名稱與所有者ninjasort/react-star-rating
主編程語言JavaScript
編程語言CSS (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2015-02-27 03:05:46
推送於2022-11-08 14:28:46
最后一次提交2022-11-08 16:28:41
發布數9
最新版本名稱v1.4.2 (發布於 2015-11-08 10:38:26)
第一版名稱v1.1.3 (發布於 )
用户参与
星數173
關注者數4
派生數55
提交數165
已啟用問題?
問題數32
打開的問題數16
拉請求數4
打開的拉請求數5
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?