1.0.0 • Published 2 years ago

awesome-react-stars v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

react-stars :star:

A simple star rating component for your React projects (now with half stars and custom characters)

react-stars

Get started quickly

Install react-stars package with NPM:

npm install react-stars --save

Then in your project include the component:

import ReactStars from 'react-stars'
import React from 'react'
import { render } from 'react-dom'

const ratingChanged = (newRating) => {
  console.log(newRating)
}

render(<ReactStars
  count={5}
  onChange={ratingChanged}
  size={24}
  color2={'#ffd700'} />,

  document.getElementById('where-to-render')
);

API

This a list of props that you can pass down to the component:

PropertyDescriptionDefault valuetype
classNameName of parent classnullstring
countHow many total stars you want5number
valueSet rating value0number
charWhich character you want to use as a starstring
color1Color of inactive star (this supports any CSS valid value)graystring
color2Color of selected or active star#ffd700string
sizeSize of stars (in px)15pxstring
editShould you be able to select rating or just see rating (for reusability)trueboolean
halfShould component use half stars, if not the decimal part will be dropped otherwise normal algebra rools will apply to round to half starstrueboolean
onChange(new_rating)Will be invoked any time the rating is changednullfunction

Help improve the component

Build on your machine:
# Clone the repo
git clone git@github.com:n49/react-stars.git
# Go into project folder
cd react-stars
# Install dependancies
npm install

Build the component:

npm build

Run the examples (dev):

npm run dev-example

Build the examples (production):

npm run build-example

Then in your browser go to: http://127.0.0.1:8080/example

Requirements

You will need to have React in your project in order to use the component, I didn't bundle React in the build, because it seemed like a crazy idea.

Todo

  • Make better docs
  • Better state management
  • Write tests
acceptsacornacorn-es7-pluginalign-textamdefineansi-regexansi-stylesanymatcharr-diffarr-excludearr-flattenarr-unionarray-differarray-find-indexarray-flattenarray-unionarray-uniqarray-uniquearrifyasapassertassign-symbolsasyncasync-eachatobava-initbabel-code-framebabel-corebabel-generatorbabel-helper-bindify-decoratorsbabel-helper-builder-binary-assignment-operator-visitorbabel-helper-builder-react-jsxbabel-helper-call-delegatebabel-helper-define-mapbabel-helper-explode-assignable-expressionbabel-helper-explode-classbabel-helper-function-namebabel-helper-get-function-aritybabel-helper-hoist-variablesbabel-helper-optimise-call-expressionbabel-helper-regexbabel-helper-remap-async-to-generatorbabel-helper-replace-supersbabel-helpersbabel-messagesbabel-plugin-check-es2015-constantsbabel-plugin-detectivebabel-plugin-espowerbabel-plugin-syntax-async-functionsbabel-plugin-syntax-async-generatorsbabel-plugin-syntax-class-propertiesbabel-plugin-syntax-decoratorsbabel-plugin-syntax-dynamic-importbabel-plugin-syntax-exponentiation-operatorbabel-plugin-syntax-flowbabel-plugin-syntax-jsxbabel-plugin-syntax-object-rest-spreadbabel-plugin-syntax-trailing-function-commasbabel-plugin-transform-async-generator-functionsbabel-plugin-transform-async-to-generatorbabel-plugin-transform-class-propertiesbabel-plugin-transform-decoratorsbabel-plugin-transform-es2015-arrow-functionsbabel-plugin-transform-es2015-block-scoped-functionsbabel-plugin-transform-es2015-block-scopingbabel-plugin-transform-es2015-classesbabel-plugin-transform-es2015-computed-propertiesbabel-plugin-transform-es2015-destructuringbabel-plugin-transform-es2015-duplicate-keysbabel-plugin-transform-es2015-for-ofbabel-plugin-transform-es2015-function-namebabel-plugin-transform-es2015-literalsbabel-plugin-transform-es2015-modules-amdbabel-plugin-transform-es2015-modules-commonjsbabel-plugin-transform-es2015-modules-systemjsbabel-plugin-transform-es2015-modules-umdbabel-plugin-transform-es2015-object-superbabel-plugin-transform-es2015-parametersbabel-plugin-transform-es2015-shorthand-propertiesbabel-plugin-transform-es2015-spreadbabel-plugin-transform-es2015-sticky-regexbabel-plugin-transform-es2015-template-literalsbabel-plugin-transform-es2015-typeof-symbolbabel-plugin-transform-es2015-unicode-regexbabel-plugin-transform-exponentiation-operatorbabel-plugin-transform-flow-strip-typesbabel-plugin-transform-object-rest-spreadbabel-plugin-transform-react-display-namebabel-plugin-transform-react-jsxbabel-plugin-transform-react-jsx-selfbabel-plugin-transform-react-jsx-sourcebabel-plugin-transform-regeneratorbabel-plugin-transform-runtimebabel-plugin-transform-strict-modebabel-polyfillbabel-preset-flowbabel-preset-stage-2babel-preset-stage-3babel-registerbabel-runtimebabel-templatebabel-traversebabel-typesbabylonbalanced-matchbasebase64-jsbatchbig.jsbinary-extensionsbluebirdbody-parserboxenbrace-expansionbracesbrowserify-aesbrowserify-zlibbuf-comparebufferbuiltin-status-codesbytescache-basecaching-transformcall-bindcall-matchercall-signaturecamelcasecamelcase-keyscapture-stack-tracecenter-alignchalkchokidarci-infoclass-utilsclean-yaml-objectcli-cursorcli-spinnerscli-truncatecliuicloneco-with-promisecode-point-atcollection-visitcommandercommon-path-prefixcommondircomponent-emittercompressiblecompressionconcat-mapconfigstoreconnect-history-api-fallbackconsole-browserifyconstants-browserifycontent-dispositioncontent-typeconvert-source-mapcookiecookie-signaturecopy-descriptorcore-assertcore-jscore-util-iscreate-error-classcreate-react-classcross-spawncrypto-browserifycurrently-unhandleddate-timedebugdecamelizedecode-uri-componentdeep-equaldeep-extenddefine-propertiesdefine-propertydepddestroydetect-indentdiff-match-patchdomain-browserdot-propduplexer2eastasianwidthee-firstemojis-listempower-coreencodeurlencodingenhanced-resolveerrnoerror-exescape-htmlescape-string-regexpespower-location-detectorespurifyestraverseesutilsetageventemitter3eventseventsourceexit-hookexpand-bracketsexpand-rangeexpressextend-shallowextglobfaye-websocketfbjsfiguresfilename-regexfill-rangefilled-arrayfinalhandlerfind-cache-dirfind-upfn-namefollow-redirectsfor-infor-ownforwardedfragment-cachefreshfs-readdir-recursivefs.realpathfunction-bindfunctions-have-namesget-intrinsicget-stdinget-valueglobglob-baseglob-parentglobalsglobbygotgraceful-fshashas-ansihas-colorhas-flaghas-property-descriptorshas-symbolshas-tostringtaghas-valuehas-valueshome-or-tmphosted-git-infohttp-errorshttp-parser-jshttp-proxyhttp-proxy-middlewarehttps-browserifyiconv-liteieee754ignore-by-defaultimurmurhashindent-stringindexofinflightinheritsiniinterpretinvariantipaddr.jsirregular-pluralsis-accessor-descriptoris-argumentsis-arrayishis-binary-pathis-bufferis-ciis-core-moduleis-data-descriptoris-date-objectis-descriptoris-dotfileis-equal-shallowis-extendableis-extglobis-finiteis-fullwidth-code-pointis-generator-fnis-globis-npmis-numberis-objis-observableis-plain-objis-plain-objectis-posix-bracketis-primitiveis-promiseis-redirectis-regexis-retry-allowedis-streamis-urlis-utf8is-windowsisarrayisexeisobjectisomorphic-fetchjs-tokensjsescjson5kind-oflast-line-streamlatest-versionlazy-cacheload-json-fileloader-utilslodashlodash.debouncelongestloose-envifyloud-rejectionlowercase-keyslru-cachemap-cachemap-objmap-visitmatchermath-randommax-timeoutmd5-hexmd5-o-maticmedia-typermemory-fsmeowmerge-descriptorsmethodsmicromatchmimemime-dbmime-typesminimatchminimistmixin-deepmkdirpmsmultimatchnanomatchnegotiatornode-fetchnode-libs-browsernode-status-codesnormalize-package-datanormalize-pathnumber-is-nanobject-assignobject-copyobject-inspectobject-isobject-keysobject-visitobject.omitobject.pickobservable-to-promiseon-finishedon-headersonceonetimeonly-shallowopenoptimistoption-chainos-browserifyos-homediros-tmpdirosenvoutput-file-syncpackage-jsonpakoparse-globparse-jsonparse-msparseurlpascalcasepath-browserifypath-existspath-is-absolutepath-parsepath-to-regexppath-typepbkdf2-compatpifypinkiepinkie-promisepkg-confpkg-dirplurposix-character-classespower-assert-context-formatterpower-assert-context-reducer-astpower-assert-context-traversalpower-assert-formatterpower-assert-renderer-assertionpower-assert-renderer-basepower-assert-renderer-comparisonpower-assert-renderer-diagrampower-assert-renderer-filepower-assert-renderer-succinctpower-assert-rendererspower-assert-util-string-widthprepend-httppreservepretty-msprivateprocessprocess-nextick-argspromiseproxy-addrprrpseudomappunycodeqsquerystringquerystring-es3querystringifyrandomaticrange-parserraw-bodyrcreact-isread-all-streamread-pkgread-pkg-upreadable-streamreaddirpredentregenerateregenerator-runtimeregenerator-transformregex-cacheregex-notregexp.prototype.flagsregexpu-coreregistry-auth-tokenregistry-urlregjsgenregjsparserremove-trailing-separatorrepeat-elementrepeat-stringrepeatingrequire-precompiledrequires-portresolveresolve-cwdresolve-fromresolve-urlrestore-cursorretright-alignripemd160safe-buffersafe-regexsafer-buffersemversemver-diffsendserve-indexserve-staticset-immediate-shimset-valuesetimmediatesetprototypeofsha.jsside-channelsignal-exitslashslice-ansislidesnapdragonsnapdragon-nodesnapdragon-utilsockjssockjs-clientsort-keyssource-list-mapsource-mapsource-map-resolvesource-map-supportsource-map-urlspdx-correctspdx-exceptionsspdx-expression-parsespdx-license-idssplit-stringstack-utilsstatic-extendstatusesstream-browserifystream-cachestream-httpstring_decoderstring-widthstringifierstrip-ansistrip-bomstrip-indentstrip-json-commentssupports-colorsupports-preserve-symlinks-flagsymbolsymbol-observabletapabletext-tablethe-argvthrough2time-requiretime-stamptimed-outtimers-browserifyto-arraybufferto-fast-propertiesto-object-pathto-regexto-regex-rangetoidentifiertraversetrim-newlinestrim-righttty-browserifytype-istype-nameua-parser-jsuglify-jsuglify-to-browserifyuid2union-valueunique-temp-dirunpipeunset-valueunzip-responseupdate-notifierurixurlurl-parseurl-parse-laxuseuser-homeutilutil-deprecateutils-mergeuuidv8flagsvalidate-npm-package-licensevaryvm-browserifywatchpackwebpack-corewebpack-dev-middlewarewebsocket-driverwebsocket-extensionswhatwg-fetchwhichwidest-linewindow-sizewordwrapwrappywrite-file-atomicwrite-json-filewrite-pkgxdg-basedirxtendyallistyargs
1.0.0

2 years ago