Full Code of cameronroe/react-star-rating for AI

master f602aa883d93 cached
17 files
26.4 KB
8.0k tokens
30 symbols
1 requests
Download .txt
Repository: cameronroe/react-star-rating
Branch: master
Commit: f602aa883d93
Files: 17
Total size: 26.4 KB

Directory structure:
gitextract_jpsz708p/

├── .eslintrc
├── .gitignore
├── .jshintrc
├── .npmignore
├── LICENSE
├── README.md
├── changelog.md
├── index.html
├── package.json
├── postcss.config.js
└── src/
    ├── StarRating.js
    ├── assets/
    │   └── react-star-rating.sketch
    ├── docs.html
    ├── docs.js
    ├── sass/
    │   ├── demo.scss
    │   └── react-star-rating.scss
    └── utils.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .eslintrc
================================================
{
  "parser": "babel-eslint",
  "ecmaFeatures": {
    "arrowFunctions": true,
    "templateStrings": true,
    "classes": true,
    "modules": true,
    "restParams": true,
    "jsx": true
  },

  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },

  "globals": {
    "BROWSER": true
  },

  "rules": {
    "quotes": 0,
    "no-trailing-spaces": 0,
    "no-unused-vars": 0,
    "no-alert": 0,
    "strict": 0
  }
}

================================================
FILE: .gitignore
================================================
node_modules
bootstrap-star-rating
./src/components/Review.jsx
other
.travis.yml
coverage
dist
test
karma.conf.js
webpack.config.js

================================================
FILE: .jshintrc
================================================
{
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "latedef": true,
  "newcap": false,
  "noarg": true,
  "sub": true,
  "undef": true,
  "unused": true,
  "boss": true,
  "eqnull": true,
  "expr": true,
  "node": true,
  "browser": true,
  "devel": true,
  "esnext": true
}

================================================
FILE: .npmignore
================================================
node_modules
bootstrap-star-rating
other
test
karma.conf.js
webpack.config.js

================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015 Cameron J Roe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

================================================
FILE: README.md
================================================
# react-star-rating ![](https://david-dm.org/cameronjroe/react-star-rating.svg)

[![NPM](https://nodei.co/npm/react-star-rating.png?compact=true)](https://nodei.co/npm/react-star-rating/)

<!-- [![Build Status](https://travis-ci.org/)](https://travis-ci.org/) -->
![](src/assets/star-rating.png)

> A simple star rating component built with React.

## Install

```sh
$ npm install react-star-rating --save
```

Include the css:

```html
<link rel="stylesheet" href="node_modules/react-star-rating/dist/css/react-star-rating.min.css">
```

## Usage

### ES6
```js
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
```js
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

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


## License

[MIT](https://github.com/cameronjroe/react-star-rating/blob/master/LICENSE)


================================================
FILE: changelog.md
================================================

## v1.4.0 - 10.10.15
  - Changed ratingAmount to totalStars
  - Added SVG stars
  - Updated to React 0.14.x
  - Temporarily removed step support while react updates mask attribute

================================================
FILE: index.html
================================================
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name=viewport content="width=device-width, initial-scale=1">
  <title>React Star Rating</title>
  <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="./dist/css/demo.css">
  <link rel="stylesheet" href="./dist/css/react-star-rating.css">
</head>
<body>
  <a href="https://github.com/cameronjroe/react-star-rating"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
  
  <div class="inject"></div>
  
  <script src="./dist/docs.js"></script>
</body>
</html>

================================================
FILE: package.json
================================================
{
  "name": "react-star-rating",
  "version": "1.4.2",
  "description": "A simple star rating component built with React.",
  "main": "./dist/react-star-rating.min.js",
  "scripts": {
    "start": "npm run dev",
    "dev": "webpack serve",
    "build": "webpack",
    "test": "karma start ./test/karma.conf.js",
    "prepublish": ""
  },
  "repository": "cameronroe/react-star-rating",
  "license": "MIT",
  "dependencies": {
    "classnames": "^2.3.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.19.6",
    "@babel/preset-env": "^7.19.4",
    "@babel/preset-react": "^7.18.6",
    "autoprefixer": "^10.4.13",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^9.0.0",
    "chai": "^4.3.6",
    "cross-env": "^7.0.3",
    "css-loader": "^6.7.1",
    "eslint": "^8.26.0",
    "eslint-webpack-plugin": "^3.2.0",
    "html-webpack-plugin": "^5.5.0",
    "isparta": "^3.0.4",
    "istanbul-instrumenter-loader": "^2.0.0",
    "jshint-stylish": "^2.2.1",
    "karma": "^6.4.1",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^3.1.1",
    "karma-coverage": "^2.2.0",
    "karma-mocha": "^2.0.1",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-sinon": "^1.0.5",
    "karma-sourcemap-loader": "^0.3.8",
    "karma-webpack": "^5.0.0",
    "mocha": "^10.1.0",
    "node-bourbon": "^4.2.8",
    "node-sass": "^7.0.3",
    "postcss": "^8.4.18",
    "postcss-loader": "^7.0.1",
    "react-addons-test-utils": "^15.6.2",
    "sass": "^1.55.0",
    "sass-loader": "^13.1.0",
    "sinon": "^14.0.1",
    "style-loader": "^3.3.1",
    "through2": "^4.0.2",
    "vinyl-source-stream": "^2.0.0",
    "webpack": "^5.74.0",
    "webpack-cli": "^4.10.0",
    "webpack-dev-server": "^4.11.1",
    "webpack-shell-plugin-next": "^2.2.2"
  }
}


================================================
FILE: postcss.config.js
================================================
module.exports = {
  plugins: [
    require('autoprefixer')
  ]
}


================================================
FILE: src/StarRating.js
================================================
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import { utils } from './utils';
import './sass/react-star-rating.scss';

function isFloat(n) {
  return n === Number(n) && n % 1 !== 0;
}

// TODO
// - Add support for svg symbol
// - Add svg masking when react supports it
// - Update onClick to onSelect which supports mobile, desktop
// - Add onChange to trigger function when rating changes

/**
 * @fileoverview react-star-rating
 * <StarRating
 *   name={string} - name for form input (required)
 *   caption={string} - caption for rating (optional)
 *   totalStars={number} - the total amount of stars (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)
 *   />
 */
class StarRating extends Component {

  // static propTypes = {
  //   name: React.PropTypes.string.isRequired,
  //   caption: React.PropTypes.string,
  //   totalStars: React.PropTypes.number.isRequired,
  //   rating: React.PropTypes.number,
  //   onRatingClick: React.PropTypes.func,
  //   disabled: React.PropTypes.bool,
  //   editing: React.PropTypes.bool,
  //   size: React.PropTypes.number
  // }

  static defaultProps = {
    step: 1,
    totalStars: 5,
    onRatingClick() {},
    disabled: false,
    size: 50,
    rating: 0
  }

  constructor(props) {
    super(props);

    this.state = {
      currentRatingVal: props.rating,
      currentRatingPos: this.getStarRatingPosition(props.rating),
      editing: props.editing || true,
      rating: props.rating,
      pos: this.getStarRatingPosition(props.rating),
      glyph: this.getStars(),
      size: props.size
    };
  }

  componentWillMount() {
    this.min = 0;
    this.max = this.props.totalStars || 5;

    if (this.props.rating) {
      this.state.editing = this.props.editing || false;
    }
  }

  componentDidMount() {
    this.root = ReactDOM.findDOMNode(this.refs.root);
    this.ratingContainer = ReactDOM.findDOMNode(this.refs.ratingContainer);
  }

  componentWillUnmount() {
    delete this.root;
    delete this.ratingContainer;
  }

  /**
   * Gets the stars based on totalStars
   * @return {string} stars
   */
  getStars() {
    var stars = '';
    var numRating = this.props.totalStars;
    for(var i = 0; i < numRating; i++) {
      stars += '\u2605';
    }
    return stars;
  }

  getWidthFromValue(val) {
    var min = this.min,
        max = this.max;
    if (val <= min || min === max) {
      return 0;
    }
    if (val >= max) {
      return 100;
    }
    return (val - min) * 100 / (max - min);
  }

  calculate(pos) {
    var val = utils.getValueFromPosition(pos, this.props.step, this.ratingContainer, this.min, this.max),
        width = this.getWidthFromValue(val);

    width += '%';
    return {width, val};
  }

  getStarRatingPosition(val) {
    return this.getWidthFromValue(val) + '%';
  }

  getRatingEvent(e) {
    let root = this.root;
    let pos = utils.getPosition(e, root);
    return this.calculate(pos);
  }

  /**
   * Get Star SVG
   */
  getSvg(rating) {
    let stars = [];
    for (let i = 0; i < this.props.totalStars; i++) {
      let attrs = {};
      attrs['transform'] = `translate(${i*50}, 0)`;
      attrs['fill'] = (i+this.props.step <= rating) ? '#FFA91B' : '#C6C6C6';
      stars.push(
        <path {...attrs}
          key={`star-${i}`}
          mask="url(#half-star-mask)"
          d="m0,18.1l19.1,0l5.9,-18.1l5.9,18.1l19.1,0l-15.4,11.2l5.9,18.1l-15.4,-11.2l-15.4,11.2l5.9,-18.1l-15.4,-11.2l0,0z" />
      );
    }

    let styles = {
      width: `${stars.length * this.props.size}px`,
      height: `${this.props.size}px`
    };

    return (
      <svg className="rsr__star"
        style={styles}
        viewBox={`0 0 ${stars.length} 50`}
        preserveAspectRatio="xMinYMin meet"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg">
        {/*
          React Doesn't support `mask` attributes yet
        <defs>
          <mask id="half-star-mask">
            <rect x="0" y="0" width="26" height="50" fill="blue"></rect>
          </mask>
        </defs>*/}
        <g>
          {stars.map((item) => {
            return item;
          })}
        </g>
      </svg>
    );
  }

  /**
   * Update the active rating selection
   * @param  {number} width width based on mouse position
   * @param  {number} val   current rating amount
   */
  updateRating(width, val) {
    this.setState({
      pos: width,
      rating: val
    });
  }

  /**
   * Update rating state if props have changed
   */
  shouldComponentUpdate(nextProps, nextState) {
    if (nextProps !== this.props) {
      this.updateRating(
        this.getStarRatingPosition(nextProps.rating),
        nextProps.rating
      );
      return true;
    } else {
      return nextState.currentRatingVal !== this.state.currentRatingVal || nextState.rating !== this.state.rating;
    }
  }

  /**
   * Set position to original state
   */
  handleMouseLeave() {
    this.setState({
      pos: this.state.currentRatingPos,
      rating: this.state.currentRatingVal
    });
  }

  /**
   * Update position to current event state
   * @param  {object} event
   */
  handleMouseMove(e) {
    // get hover position
    let ratingEvent = this.getRatingEvent(e);
    this.updateRating(
      ratingEvent.width,
      ratingEvent.val
    );
  }

  /**
   * Update rating state, Trigger function handler
   * @param  {object} event
   */
  handleClick(e) {
    if (this.props.disabled) {
      e.stopPropagation();
      e.preventDefault();
      return false;
    }

    var payload = {
      currentRatingPos: this.state.pos,
      currentRatingVal: this.state.rating,
      caption: this.props.caption,
      name: this.props.name
    };

    this.setState(payload);

    this.props.onRatingClick(e, {
      rating: this.state.rating,
      position: this.state.pos,
      caption: this.props.caption,
      name: this.props.name
    });
  }

  getClasses() {
    return cx({
      'rsr-root': true,
      'rsr--disabled': this.props.disabled,
      'rsr--editing': this.state.editing
    });
  }

  getCaption() {
    if (this.props.caption) {
      return (<span className="rsr__caption">{this.props.caption}</span>);
    } else {
      return null;
    }
  }

  setAttrs(isState) {
    let attrs = {};
    if (isState) {
      attrs['onMouseMove'] = this.handleMouseMove.bind(this);
      attrs['onMouseLeave'] = this.handleMouseLeave.bind(this);
      attrs['onClick'] = this.handleClick.bind(this);
    }
    return attrs;
  }

  render() {

    let classes = this.getClasses();
    let caption = this.getCaption();
    let attrs = this.setAttrs(this.state.editing);

    return (
      <span className="rsr-container">
        {caption}
        <div ref="root" className={classes}>
          <div ref="ratingContainer"
            className="rsr rating-gly-star"
            data-content={this.state.glyph} {...attrs}>
            {this.getSvg(this.state.rating)}
            <input type="hidden"
              name={this.props.name}
              value={this.state.currentRatingVal}
              style={{display: 'none !important'}}
              min={this.min}
              max={this.max}
              readOnly />
          </div>
        </div>
      </span>
    );
  }
}

export default StarRating;


================================================
FILE: src/docs.html
================================================
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name=viewport content="width=device-width, initial-scale=1">
  <title><%= htmlWebpackPlugin.options.title %></title>
  <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
</head>
<body>
  <a href="https://github.com/cameronjroe/react-star-rating"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>

  <div class="inject"></div>

</body>
</html>


================================================
FILE: src/docs.js
================================================
import React, { Component } from 'react';
import { createRoot } from 'react-dom/client';
import StarRating from './StarRating';
import pkg from '../package';
import './sass/demo.scss';

const inject = document.querySelector('.inject');
const root = createRoot(inject);

class Docs extends Component {

  handleRatingClick(e, data) {
    console.log(data);
    alert('You left a ' + data.rating + ' star rating for ' + data.name);
  }

  render() {
    var currentVersion = pkg.version;

    return (
      <section>
        <div className="intro">
          <h1 className="main-title">
            {'react-star-rating'}
            <small> easy star ratings with Test</small>
          </h1>
          <StarRating name="hotels" size={50} rating={5} editing={false} totalStars={5} step={1} />
          <p style={{marginBottom: '10px'}}>v{currentVersion}</p>
          <a href="https://github.com/cameronjroe/react-star-rating" className="btn btn-primary">View on Github</a>
        </div>
        <div className="ratings-wrap">
          <h2>Installation</h2>
          <hr/>
          <code>
            {'$ npm install react-star-rating --save'}
          </code>
          <p>Include the css:</p>
          <code>
            {'<link rel="stylesheet" href="node_modules/react-star-rating/dist/css/react-star-rating.min.css">'}
          </code>
          <h2>Usage</h2>
          <hr/>
          <form target="_self" method="GET" className="demo-form">
            <StarRating name="react-star-rating" caption="Rate this component!" totalStars={5} />
            <button type="submit" className="btn btn-primary">Submit Rating</button>
          </form>
          <h3>ES6</h3>
          <code>
            <p>{'import React from \'react\''}</p>
            <p>{'import StarRating from \'react-star-rating\''}</p>
            <p>{' '}</p>
            <p>{'class FormComponent extends React.Component {'}</p>
            <p>{'  render() { '}</p>
            <p>{'    return ('}</p>
            <p>{'      <form target="_self" method="GET">'}</p>
            <p>{'        <StarRating name="react-star-rating" caption="Rate this component!" totalStars={5} />'}</p>
            <p>{'        <button type="submit" className="btn btn-primary">Submit Rating</button>'}</p>
            <p>{'      </form>'}</p>
            <p>{'    );'}</p>
            <p>{'  }'}</p>
            <p>{'}'}</p>
            <p>{' '}</p>
            <p>{'React.render(<FormComponent />, document.getElementById(\'star-rating\'));'}</p>
          </code>
          <h3>ES5</h3>
          <code>
            <p>{'var React = require(\'react\');'}</p>
            <p>{'var StarRating = require(\'react-star-rating\');'}</p>
            <p>{' '}</p>
            <p>{'var FormComponent = React.createClass({'}</p>
            <p>{'  render: function () { '}</p>
            <p>{'    return ('}</p>
            <p>{'      <form target="_self" method="GET">'}</p>
            <p>{'        <StarRating name="react-star-rating" caption="Rate this component!" totalStars={5} />'}</p>
            <p>{'        <button type="submit" className="btn btn-primary">Submit Rating</button>'}</p>
            <p>{'      </form>'}</p>
            <p>{'    );'}</p>
            <p>{'  }'}</p>
            <p>{'});'}</p>
            <p>{' '}</p>
            <p>{'React.render(<FormComponent />, document.getElementById(\'star-rating\'));'}</p>
          </code>
          <h2>Options</h2>
          <hr/>
          <ul>
            <li><strong>name</strong>{'={string} - name for form input (required)'}</li>
            <li><strong>caption</strong>{'={string} - caption for rating (optional)'}</li>
            <li><strong>totalStars</strong>{'={number} - rating amount (required, default: 5)'}</li>
            <li><strong>rating</strong>{'={number} - a set rating between the rating amount (optional)'}</li>
            <li><strong>disabled</strong>{'={boolean} - whether to disable the rating from being selected (optional)'}</li>
            <li><strong>editing</strong>{'={boolean} - whether the rating is explicitly in editing mode (optional)'}</li>
            <li><strong>size</strong>{'={number} - size of stars (optional)'}</li>
            <li><strong>onRatingClick</strong>{'={function} - a handler function that gets called onClick of the rating (optional) - gets passed (event, {position, rating, caption, name})'}</li>
          </ul>
          <h2>Examples</h2>
          <hr/>
          <StarRating name="handler" caption="Use onClick Handlers!" totalStars={5} onRatingClick={this.handleRatingClick.bind(this)} />
          <p></p>
          <code>
            <p>{'// handler in react class'}</p>
            <p>{'handleRatingClick: function (e, data) {'}</p>
            <p>{'    alert(\'You left a \' + data.rating + \' star rating for \' + data.caption);'}</p>
            <p>{'}'}</p>
            <p>{' '}</p>
            <p>{'<StarRating name="handler" caption="Use onClick Handlers!" totalStars={5} onRatingClick={handleRatingClick} />'}</p>
          </code>
          <p></p>
          <blockquote><strong>{'If you\'re using ES6, make sure to bind the handler: '}</strong><code>{'this.handleRatingClick.bind(this, pass, args, here)'}</code></blockquote>
          <StarRating name="ten-stars" caption="Configure number of stars!" totalStars={10} step={1} onRatingClick={this.handleRatingClick.bind(this)} />
          <code>
            {'<StarRating name="ten-stars" caption="Configure number of stars!" totalStars={10} step={1} onRatingClick={this.handleRatingClick} />'}
          </code>
          {/*<StarRating name="half-stars" caption="Use half-star steps!" totalStars={5} />
          <code>
            {'<StarRating name="half-stars" caption="Use half-star steps!" totalStars={5} />'}
          </code>*/}
          <StarRating name="small-rating" caption="Small!" size={30} totalStars={5} rating={3} />
          <code>
            {'<StarRating name="small-rating" caption="Small!" size={30} totalStars={5} rating={3} />'}
          </code>
          <StarRating name="medium-rating" caption="Medium!" size={50} totalStars={5} rating={4} />
          <code>
            {'<StarRating name="medium-rating" caption="Medium!" size={50} totalStars={5} rating={4} />'}
          </code>
          <StarRating name="large-rating" caption="Large!" size={70} totalStars={5} rating={5} />
          <code>
            {'<StarRating name="large-rating" caption="Large!" size={70} totalStars={5} rating={5} />'}
          </code>
          <StarRating name="jumbo-rating" caption="Jumbo!" size={100} totalStars={5} rating={5} />
          <code>
            {'<StarRating name="jumbo-rating" caption="Jumbo!" size={100} totalStars={5} rating={5} />'}
          </code>
          <StarRating name="disabled" caption="Disabled." totalStars={5} rating={3} disabled={true} />
          <code>
            {'<StarRating name="disabled" caption="Disabled." totalStars={5} rating={3} disabled={true} />'}
          </code>
        </div>
        <footer>
          <div className="footer-creds">
            <p>Code licensed under <a href="https://github.com/cameronjroe/react-star-rating/blob/master/LICENSE">MIT</a> - Currently v{currentVersion} - <a href="https://github.com/cameronjroe/react-star-rating">Github Repo</a></p>
            <p>Created by <a href="http://twitter.com/cameronjroe">@cameronjroe</a> - <iframe src="https://ghbtns.com/github-btn.html?user=cameronjroe&type=follow&count=true" frameBorder="0" scrolling="0" width="170px" height="20px"></iframe></p>
          </div>
        </footer>
      </section>
    );
  }

}

root.render(<Docs />);


================================================
FILE: src/sass/demo.scss
================================================
@import "bourbon";

html, body {
  font-size: 16px;
  margin: 0;
  padding-bottom: 2em;
  font-family: 'Times';
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Philosopher', sans-serif;
}

code {
  color: #444;
  padding: 2em;
  line-height: 1.5;
  margin-top: 2em;
  margin-bottom: 2.5em;
  min-width: 100%;
  display: inline-block;
  box-shadow: inset 0px 0px 7px rgba(210, 210, 210, 0.54);
  background-color: rgba(210, 210, 210, 0.24);
  white-space: pre-wrap;
}

iframe {
  border: 0;
  display: inline-block;
  vertical-align: middle;
}

ul li {
  margin: 0.5em 0;
  font-size: 1.2em;
}

footer {
  text-align: center;
}

.btn {
  border-radius: 2px;
}

.btn-primary {
  background-color: #F5A71B;
  color: #fff;
  border: 0;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: bold;
  margin: 0 1.5em;
  letter-spacing: 1px;
  &:active, &:hover, &:focus {
    outline: 0;
    color: #fff;
    background-color: darken(#F5A71B, 10%);
  }
}

.demo-form {
  fieldset {
    display: inline-block;
  }
}

.footer-creds {
  display: inline-block;
  letter-spacing: 1px;
  opacity: 0.8;
}

.intro {
  color: #fff;
  background: linear-gradient(#444, #333) left repeat;
  padding: 8em 0;
  box-shadow: inset 0px 0px 7px #000;
  text-align: center;
  .react-star-rating {
    text-align: center;
  }
}

.main-title {
  font-size: 4em;
  letter-spacing: 1px;
  text-align: center;
  > small {
    display: block;
    font-size: 0.5em;
  }
}

.ratings-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 4em;
  border-radius: 5px;
}


================================================
FILE: src/sass/react-star-rating.scss
================================================
@import "bourbon";

.rsr-root {
  vertical-align: middle;
  display: inline-block;
}

.rsr--editing {
  &:hover {
    cursor: pointer;
  }
}

.rsr {
  position: relative;
  vertical-align: middle;
  display: inline-block;
  color: #e3e3e3;
  overflow: hidden;
}

.rsr__stars {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  overflow: hidden;
  color: #F5A71B;
  transition: all 0.01s;
}

.rsr__caption {
  font-size: 1.25em;
  vertical-align: middle;
  margin-right: 0.5em;
}

.rsr--disabled {
  .rsr-container:hover {
    cursor: not-allowed;
  }
}


================================================
FILE: src/utils.js
================================================

function getDecimalPlaces(num) {
  var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  return !match ? 0 : Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
}

function applyPrecision(val, precision) {
  return parseFloat(val.toFixed(precision));
}

export const utils = {
  /**
   * Gets the mouse position
   * @param  {event} e
   * @return {number} delta
   */
  getPosition(e, root) {
    return e.clientX - root.getBoundingClientRect().left;
  },

  treatName(title) {
    if (typeof title === 'string') {
      return title.toLowerCase().split(' ').join('_');
    }
  },

  getValueFromPosition(pos, step, container, min, max) {
    var precision = getDecimalPlaces(step);
    var maxWidth = container.offsetWidth;
    var diff = max - min;
    var factor = (diff * pos) / (maxWidth * step);
    factor = Math.ceil(factor);
    var val = applyPrecision(parseFloat(min + factor * step), precision);
    val = Math.max(Math.min(val, max), min);
    return val;
  }

}
Download .txt
gitextract_jpsz708p/

├── .eslintrc
├── .gitignore
├── .jshintrc
├── .npmignore
├── LICENSE
├── README.md
├── changelog.md
├── index.html
├── package.json
├── postcss.config.js
└── src/
    ├── StarRating.js
    ├── assets/
    │   └── react-star-rating.sketch
    ├── docs.html
    ├── docs.js
    ├── sass/
    │   ├── demo.scss
    │   └── react-star-rating.scss
    └── utils.js
Download .txt
SYMBOL INDEX (30 symbols across 3 files)

FILE: src/StarRating.js
  function isFloat (line 7) | function isFloat(n) {
  class StarRating (line 30) | class StarRating extends Component {
    method onRatingClick (line 46) | onRatingClick() {}
    method constructor (line 52) | constructor(props) {
    method componentWillMount (line 66) | componentWillMount() {
    method componentDidMount (line 75) | componentDidMount() {
    method componentWillUnmount (line 80) | componentWillUnmount() {
    method getStars (line 89) | getStars() {
    method getWidthFromValue (line 98) | getWidthFromValue(val) {
    method calculate (line 110) | calculate(pos) {
    method getStarRatingPosition (line 118) | getStarRatingPosition(val) {
    method getRatingEvent (line 122) | getRatingEvent(e) {
    method getSvg (line 131) | getSvg(rating) {
    method updateRating (line 178) | updateRating(width, val) {
    method shouldComponentUpdate (line 188) | shouldComponentUpdate(nextProps, nextState) {
    method handleMouseLeave (line 203) | handleMouseLeave() {
    method handleMouseMove (line 214) | handleMouseMove(e) {
    method handleClick (line 227) | handleClick(e) {
    method getClasses (line 251) | getClasses() {
    method getCaption (line 259) | getCaption() {
    method setAttrs (line 267) | setAttrs(isState) {
    method render (line 277) | render() {

FILE: src/docs.js
  class Docs (line 10) | class Docs extends Component {
    method handleRatingClick (line 12) | handleRatingClick(e, data) {
    method render (line 17) | render() {

FILE: src/utils.js
  function getDecimalPlaces (line 2) | function getDecimalPlaces(num) {
  function applyPrecision (line 7) | function applyPrecision(val, precision) {
  method getPosition (line 17) | getPosition(e, root) {
  method treatName (line 21) | treatName(title) {
  method getValueFromPosition (line 27) | getValueFromPosition(pos, step, container, min, max) {
Condensed preview — 17 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (29K chars).
[
  {
    "path": ".eslintrc",
    "chars": 432,
    "preview": "{\n  \"parser\": \"babel-eslint\",\n  \"ecmaFeatures\": {\n    \"arrowFunctions\": true,\n    \"templateStrings\": true,\n    \"classes\""
  },
  {
    "path": ".gitignore",
    "chars": 131,
    "preview": "node_modules\nbootstrap-star-rating\n./src/components/Review.jsx\nother\n.travis.yml\ncoverage\ndist\ntest\nkarma.conf.js\nwebpac"
  },
  {
    "path": ".jshintrc",
    "chars": 279,
    "preview": "{\n  \"curly\": true,\n  \"eqeqeq\": true,\n  \"immed\": true,\n  \"latedef\": true,\n  \"newcap\": false,\n  \"noarg\": true,\n  \"sub\": tr"
  },
  {
    "path": ".npmignore",
    "chars": 77,
    "preview": "node_modules\nbootstrap-star-rating\nother\ntest\nkarma.conf.js\nwebpack.config.js"
  },
  {
    "path": "LICENSE",
    "chars": 1079,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Cameron J Roe\n\nPermission is hereby granted, free of charge, to any person obt"
  },
  {
    "path": "README.md",
    "chars": 2420,
    "preview": "# react-star-rating ![](https://david-dm.org/cameronjroe/react-star-rating.svg)\n\n[![NPM](https://nodei.co/npm/react-star"
  },
  {
    "path": "changelog.md",
    "chars": 180,
    "preview": "\n## v1.4.0 - 10.10.15\n  - Changed ratingAmount to totalStars\n  - Added SVG stars\n  - Updated to React 0.14.x\n  - Tempora"
  },
  {
    "path": "index.html",
    "chars": 1186,
    "preview": "<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=viewport content=\"width=device-width, initial-scale="
  },
  {
    "path": "package.json",
    "chars": 1796,
    "preview": "{\n  \"name\": \"react-star-rating\",\n  \"version\": \"1.4.2\",\n  \"description\": \"A simple star rating component built with React"
  },
  {
    "path": "postcss.config.js",
    "chars": 66,
    "preview": "module.exports = {\n  plugins: [\n    require('autoprefixer')\n  ]\n}\n"
  },
  {
    "path": "src/StarRating.js",
    "chars": 7627,
    "preview": "import React, { Component } from 'react';\nimport ReactDOM from 'react-dom';\nimport cx from 'classnames';\nimport { utils "
  },
  {
    "path": "src/docs.html",
    "chars": 1044,
    "preview": "<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=viewport content=\"width=device-width, initial-scale="
  },
  {
    "path": "src/docs.js",
    "chars": 7640,
    "preview": "import React, { Component } from 'react';\nimport { createRoot } from 'react-dom/client';\nimport StarRating from './StarR"
  },
  {
    "path": "src/sass/demo.scss",
    "chars": 1540,
    "preview": "@import \"bourbon\";\n\nhtml, body {\n  font-size: 16px;\n  margin: 0;\n  padding-bottom: 2em;\n  font-family: 'Times';\n}\n\nh1, h"
  },
  {
    "path": "src/sass/react-star-rating.scss",
    "chars": 571,
    "preview": "@import \"bourbon\";\n\n.rsr-root {\n  vertical-align: middle;\n  display: inline-block;\n}\n\n.rsr--editing {\n  &:hover {\n    cu"
  },
  {
    "path": "src/utils.js",
    "chars": 1016,
    "preview": "\nfunction getDecimalPlaces(num) {\n  var match = ('' + num).match(/(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/);\n  return !match ? "
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the cameronroe/react-star-rating GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 17 files (26.4 KB), approximately 8.0k tokens, and a symbol index with 30 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!