Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datascientest-developer/react-simple-star-rating

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datascientest-developer/react-simple-star-rating

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

  • 5.1.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
68
increased by126.67%
Maintainers
1
Weekly downloads
 
Created
Source

React Simple Rating

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

NPM JavaScript Style Guidenpm bundle sizeGitHub

screenshot

Install

npm
npm i @datascientest-developer/react-simple-star-rating
Yarn
yarn add @datascientest-developer/react-simple-star-rating

Usage

import React, { useState } from 'react'
import { Rating } from '@datascientest-developer/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

import React, { useState } from 'react'
import { Rating } from '@datascientest-developer/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

PropTypeOptionsDescriptionDefault
onClickfunctionOptionalcallback with hover, index and event values passed-
onPointerMovefunctionOptionalcallback with hover, index and event values passed-
onPointerEnterfunctionOptionalcallback with event passed-
onPointerLeavefunctionOptionalcallback with event passed-
initialValuenumberOptionalSet initial value0
iconsCountnumberOptionalNumber of the icons5
readonlybooleanOptionalReadonly modefalse
rtlbooleanOptionalRTL modefalse
transitionbooleanOptionalAdds a smooth transition effect on mouse hoverfalse
allowFractionbooleanOptionalEnable a fractional icon (half icon)false
resetOnClickbooleanOptionalResets value on clickfalse
classNamestringOptionalApplied to the main spanreact-simple-star-rating
styleCSSPropertiesOptionalInline style applied to the main spanbasic style
sizenumberOptionalSVG Icon width / height in px25
SVGstrokeColorstringOptionalSVG Icon stroke colorcurrentColor
SVGstrokeWidthstring | numberOptionalSVG Icon storke width0
SVGclassNamestringOptionalSVG Icon css classstar-svg
SVGstyleCSSPropertiesOptionalSVG inline style-
fillIconReactNodeOptionalCustom fill icon SVGnull
fillColorstringOptionalFill icons color#f1a545
fillColorArrayarrayOptionalArray of string to add color range[]
fillStyleCSSPropertiesOptionalInline style applied to filled icon spanbasic style
fillClassNamestringOptionalApplied to the filled icon spanfilled-icons
emptyIconReactNodeOptionalCustom empty icon SVGnull
emptyColorstringOptionalEmpty icons color#cccccc
emptyStyleCSSPropertiesOptionalInline style applied to empty icon spanbasic style
emptyClassNamestringOptionalApplied to the empty icon spanempty-icons
customIconsarray of objectOptionalAdd a group of icons[]
allowHoverbooleanOptionalEnable / Disable hover effecttrue
disableFillHoverbooleanOptionalEnable / Disable hover effect on filled starsfalse
allowTitleTagbooleanOptionalEnable / Disable HTMLtitle Tagtrue
showTooltipbooleanOptionalShow a tooltip with live valuesfalse
tooltipDefaultTextstringOptionalInitial tooltip text if no rating valueYour Rate
tooltipArrayarrayOptionalArray of strings to show inside tooltip[]
tooltipClassNamestringOptionalTooltip CSS classrating-tooltip
tooltipStyleCSSPropertiesOptionalInline style applied to the tooltip spanbasic style
titleSeparatorstringOptionalSeparator word in a title of a rating star (1 out of 5)out of


BREAKING CHANGES: version 4.1.0 (2022-10-03)

oldnewchanges
allowHalfIconallowFractionRenamed
fullIconfillIconRenamed
fullStylefillStyleRenamed
fullClassNamefillClassNameRenamed
ratingValue-Removed

Demos

See all demos and usage examples in action.


Edit react-simple-rating-ts

License

MIT © awran5

Keywords

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc