# react-simple-star-rating

> A simple react component for adding a star rating to your project.

Latest version **5.1.7** (published 2022-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-simple-star-rating
pnpm add react-simple-star-rating
yarn add react-simple-star-rating
bun add react-simple-star-rating
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.7 |
| Published | 2022-11-22 |
| First published | 2020-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 43.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 147 |
| Author | awran5 |
| Maintainers | awran5 |
| Keywords | react, star rating, react component, react rating |

## Links

- npm: https://www.npmjs.com/package/react-simple-star-rating
- Repository: https://github.com/awran5/react-simple-star-rating
- Homepage: https://github.com/awran5/react-simple-star-rating#readme
- Issues: https://github.com/awran5/react-simple-star-rating/issues
- npm.io page: https://npm.io/package/react-simple-star-rating

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 5.1.7 (latest) — 2022-11-22
- 5.1.6 — 2022-10-28
- 5.1.5 — 2022-10-28
- 5.1.3 — 2022-10-11
- 5.1.2 — 2022-10-07
- 5.1.1 — 2022-10-07
- 5.1.0 — 2022-10-03
- 5.0.0 — 2022-10-03
- 4.1.1 — 2022-10-03
- 4.1.0 — 2022-10-03
- 4.0.5 — 2021-12-13
- 4.0.4 — 2021-12-13
- 4.0.3 — 2021-12-11
- 4.0.2 — 2021-12-10
- 0.0.0-development — 2021-12-10
- … 7 more at https://npm.io/package/react-simple-star-rating/versions

## README

# React Simple Rating

> A simple react component for adding a star rating to your project.

[![NPM](https://img.shields.io/npm/v/react-simple-star-rating.svg)](https://www.npmjs.com/package/react-simple-star-rating) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)![npm bundle size](https://img.shields.io/bundlephobia/min/react-simple-star-rating)![GitHub](https://img.shields.io/github/license/awran5/react-simple-star-rating)

<p align="center">
  <img src="./screenshot.gif" alt="screenshot" width="100%" />
</p>

## Install

#### npm

```sh
npm i react-simple-star-rating
```

#### Yarn

```sh
yarn add react-simple-star-rating
```

<br />

## Usage

```jsx
import React, { useState } from 'react'
import { Rating } from 'react-simple-star-rating'

export function MyComponent() {
  const [rating, setRating] = useState(0)

  // Catch Rating value
  const handleRating = (rate: number) => {
    setRating(rate)

    // other logic
  }
  // Optinal callback functions
  const onPointerEnter = () => console.log('Enter')
  const onPointerLeave = () => console.log('Leave')
  const onPointerMove = (value: number, index: number) => console.log(value, index)

  return (
    <div className='App'>
      <Rating
        onClick={handleRating}
        onPointerEnter={onPointerEnter}
        onPointerLeave={onPointerLeave}
        onPointerMove={onPointerMove}
        /* Available Props */
      />
    </div>
  )
}
```

## Reset Rating Value

```jsx
import React, { useState } from 'react'
import { Rating } from 'react-simple-star-rating'

export function MyComponent() {
  const [rating, setRating] = useState(0)

  // Catch Rating value
  const handleRating = (rate: number) => {
    setRating(rate)
  }

  const handleReset = () => {
    // Set the initial value
    setRating(0)
  }

  return (
    <div className='App'>
      {/* set initial value */}
      <Rating onClick={handleRating} initialValue={rating} />

      <button onClick={handleReset}>reset</button>
    </div>
  )
}
```

### Available Props

| Prop                 | Type             | Options  | Description                                               |          Default           |
| -------------------- | ---------------- | -------- | --------------------------------------------------------- | :------------------------: |
| `onClick`            | function         | Optional | callback with `hover`, `index` and `event` values passed  |            `-`             |
| `onPointerMove`      | function         | Optional | callback with `hover`, `index` and `event` values passed  |            `-`             |
| `onPointerEnter`     | function         | Optional | callback with `event` passed                              |            `-`             |
| `onPointerLeave`     | function         | Optional | callback with `event` passed                              |            `-`             |
| `initialValue`       | number           | Optional | Set initial value                                         |            `0`             |
| `iconsCount`         | number           | Optional | Number of the icons                                       |            `5`             |
| `readonly`           | boolean          | Optional | Readonly mode                                             |          `false`           |
| `rtl`                | boolean          | Optional | RTL mode                                                  |          `false`           |
| `transition`         | boolean          | Optional | Adds a smooth transition effect on mouse hover            |          `false`           |
| `allowFraction`      | boolean          | Optional | Enable a fractional icon (half icon)                      |          `false`           |
| `className`          | string           | Optional | Applied to the `main` span                                | `react-simple-star-rating` |
| `style`              | CSSProperties    | Optional | Inline style applied to the `main` span                   |       `basic style`        |
| `size`               | number           | Optional | SVG Icon width / height in `px`                           |            `25`            |
| `SVGstrokeColor`     | string           | Optional | SVG Icon stroke color                                     |       `currentColor`       |
| `SVGstorkeWidth`     | string \| number | Optional | SVG Icon storke width                                     |            `0`             |
| `SVGclassName`       | string           | Optional | SVG Icon css class                                        |         `star-svg`         |
| `SVGstyle`           | CSSProperties    | Optional | SVG inline style                                          |            `-`             |
| `fillIcon`           | ReactNode        | Optional | Custom fill icon SVG                                      |           `null`           |
| `fillColor`          | string           | Optional | Fill icons color                                          |         `#f1a545`          |
| `fillColorArray`     | array            | Optional | Array of string to add color range                        |            `[]`            |
| `fillStyle`          | CSSProperties    | Optional | Inline style applied to `filled` icon span                |       `basic style`        |
| `fillClassName`      | string           | Optional | Applied to the `filled` icon span                         |       `filled-icons`       |
| `emptyIcon`          | ReactNode        | Optional | Custom empty icon SVG                                     |           `null`           |
| `emptyColor`         | string           | Optional | Empty icons color                                         |         `#cccccc`          |
| `emptyStyle`         | CSSProperties    | Optional | Inline style applied to `empty` icon span                 |       `basic style`        |
| `emptyClassName`     | string           | Optional | Applied to the `empty` icon span                          |       `empty-icons`        |
| `customIcons`        | array of object  | Optional | Add a group of icons                                      |            `[]`            |
| `allowHover`         | boolean          | Optional | Enable / Disable hover effect                             |           `true`           |
| `disableFillHover`   | boolean          | Optional | Enable / Disable hover effect on filled stars             |          `false`           |
| `showTooltip`        | string           | Optional | Show a tooltip with live values                           |          `false`           |
| `tooltipDefaultText` | string           | Optional | Initial tooltip text if no rating value                   |        `Your Rate`         |
| `tooltipArray`       | array            | Optional | Array of strings to show inside tooltip                   |            `[]`            |
| `tooltipClassName`   | string           | Optional | Tooltip CSS class                                         |      `rating-tooltip`      |
| `tooltipStyle`       | CSSProperties    | Optional | Inline style applied to the `tooltip` span                |       `basic style`        |
| `titleSeparator`     | string           | Optional | Separator word in a title of a rating star `(1 out of 5)` |          `out of`          |

---

<br />

## BREAKING CHANGES: version [4.1.0](https://github.com/awran5/react-simple-star-rating/compare/v4.0.5...v4.1.0) (2022-10-03)

| old             | new             | changes   |
| --------------- | --------------- | --------- |
| `allowHalfIcon` | `allowFraction` | `Renamed` |
| `fullIcon`      | `fillIcon`      | `Renamed` |
| `fullStyle`     | `fillStyle`     | `Renamed` |
| `fullClassName` | `fillClassName` | `Renamed` |
| `ratingValue`   | `-`             | `Removed` |

## Demos

See all demos and usage examples [in action](https://react-simple-star-rating.vercel.app/).

<br />

[![Edit react-simple-rating-ts](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-simple-rating-ts-fzmpu?fontsize=14&hidenavigation=1&theme=dark)

### License

MIT © [awran5](https://github.com/awran5/)

---
_Source: https://npm.io/package/react-simple-star-rating · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
