GithubHelp home page GithubHelp logo

smastrom / react-rating Goto Github PK

View Code? Open in Web Editor NEW
281.0 1.0 5.0 639 KB

:star: Zero-dependency, highly customizable rating component for React.

Home Page: https://reactrating.netlify.app

License: MIT License

HTML 0.56% TypeScript 88.15% CSS 11.10% Shell 0.19%
rating rating-stars react react-component stars react-rating reviews rating-star star

react-rating's People

Contributors

nickmackenzie avatar smastrom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-rating's Issues

MouseEvent Not Returning on onChange in Rating Component, Causing Unintended Navigation

I'm currently facing an issue with the rating component, specifically when used within cards containing navigation links. Upon attempting to change the rating, it triggers navigation to the card's link unintentionally.

This behavior poses a usability problem, especially when the rating component is embedded within cards that are meant to serve as navigation links. The expected functionality is to change the rating without triggering navigation.

Type declaration file not found in Next.js app with Typescript

The following static checking error pops up with import { Rating } from "@smastrom/react-rating".

Could not find a declaration file for module '@smastrom/react-rating'. '/path/to/node_modules/@smastrom/react-rating/dist/index.mjs' implicitly has an 'any' type.
There are types at '/path/to/node_modules/@smastrom/react-rating/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@smastrom/react-rating' library may need to update its package.json or typings.ts(7016)

Environment

  • "next": "13.4.12",
  • "react": "18.2.0",
  • "@types/node": "20.4.5",
  • "@types/react": "18.2.17",
  • "@types/react-dom": "18.2.7",
  • "typescript": "5.1.6"

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "typeRoots": ["./node_modules/@types", "./node_modules"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

My temporary solution

I added a new file react-rating.d.ts in the root directory with the following code:

declare module '@smastrom/react-rating';

The error is resolved.

Component error when using react testing library

I currently cannot use the Rating component with the react testing library. Here is a minimal example:

import { Rating } from "@smastrom/react-rating";
import { render } from '@testing-library/react';


describe('Rating', () => {
    test('Fails', async () => {
        render(
            <Rating data-testid={'X'} isDisabled={false} style={{ maxWidth: 100 }} items={5}
                value={0} />
        );
    }, 10000);
});

If I run it with yarn test Rating.test.tsx, I get following error:

TypeError: h.current.getBBox is not a function

       5 | describe('Rating', () => {
       6 |     test('Fails', async () => {
    >  7 |         render(
         |               ^
       8 |             <Rating data-testid={'X'} isDisabled={false} style={{ maxWidth: 100 }} items={5}
       9 |                 value={0} />
      10 |         );

      at node_modules/@smastrom/react-rating/dist/index.js:1:1735
      at commitHookEffectListMount (node_modules/react-dom/cjs/react-dom.development.js:23150:26)
      at commitLayoutEffectOnFiber (node_modules/react-dom/cjs/react-dom.development.js:23273:15)
      at commitLayoutMountEffects_complete (node_modules/react-dom/cjs/react-dom.development.js:24688:9)
      at commitLayoutEffects_begin (node_modules/react-dom/cjs/react-dom.development.js:24674:7)
      at commitLayoutEffects (node_modules/react-dom/cjs/react-dom.development.js:24612:3)
      at commitRootImpl (node_modules/react-dom/cjs/react-dom.development.js:26823:5)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:26682:5)
      at finishConcurrentRender (node_modules/react-dom/cjs/react-dom.development.js:25981:9)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25809:7)
      at flushActQueue (node_modules/react/cjs/react.development.js:2667:24)
      at act (node_modules/react/cjs/react.development.js:2582:11)
      at node_modules/@testing-library/react/dist/act-compat.js:63:25
      at renderRoot (node_modules/@testing-library/react/dist/pure.js:159:26)
      at render (node_modules/@testing-library/react/dist/pure.js:246:10)
      at Object.<anonymous> (src/test/org/mycollection/games/client/widgets/commonviews/Rating.test.tsx:7:15)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

What do I need to do to use it with react testing library?

No stars are visible if container was hidden on mount

Thanks for this components! Looks promising for my use case. However, I have a small issue

I'm integrating this component with Preline Tabs and whenever the stars component is mounted on a default hidden tab, the stars are invisible when the tab gets selected. I guess there must be some size calculations that get broken if the container is hidden. If I move the rating component to a default visible tab, everything works as expected.

Not sure how to work around this issue.

Rating Star not shown at Popup

When I try this package on my Website, It works on Normal pages. But not at the Modal Popup. The CSS is rendered correctly. But it is not shown. Also, the half-star rating is not working while selecting the stars. Please check the attachment.

image

Could someone please assist me with this?

This is my code.

import { Rating as ReactRating, RoundedStar } from '@smastrom/react-rating';
import '@smastrom/react-rating/style.css';
<ReactRating  
      value={1.5} 
      readOnly 
      style={{ maxWidth: 130 }}       
      itemStyles={{
      itemShapes: RoundedStar,
      activeFillColor: '#EB0444',
      inactiveFillColor: '#E2E2E2',
    }}
/>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.