Giter VIP home page Giter VIP logo

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

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',
    }}
/>

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.

Not working with react v17.0.1

I'm facing with this error on my project using react v17.0.1:

ERROR in ./node_modules/@smastrom/react-rating/dist/index.mjs 308:13-14 Can't import the named export 'Fragment' from non EcmaScript module (only default export is available)

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.

Styles are not imported

I did

import { Rating } from '@smastrom/react-rating';

   <Rating
        value={4}
        items={6}
        style={{ maxWidth: 100 }}
        // className='flex w-[200px]'
      />

but when looking at devtools, the styles are not imported. Here is the output:

image

What am I doing wrong?

Stars not rendering in production

I have Vite + React + Typescript application and I am using this react-rating library for displaying ratings in a modal.

Versions:
"react": "^18.2.0",
"@smastrom/react-rating": "^1.5.0",

It is working as expected in in dev but as soon as I build it, the stars disappears.

Here's what I found:

Svgs in development:

<svg aria-hidden="true" class="rr--svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 58" preserveAspectRatio="xMidYMid meet"><g shape-rendering="geometricPrecision" transform="translate(-2 -3)"><path d="M62 25.154H39.082L32 3l-7.082 22.154H2l18.541 13.693L13.459 61L32 47.309L50.541 61l-7.082-22.152L62 25.154z"></path></g></svg>

The same svg in production:
<svg aria-hidden="true" class="rr--svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" preserveAspectRatio="xMidYMid meet"><g shape-rendering="geometricPrecision"><path d="M62 25.154H39.082L32 3l-7.082 22.154H2l18.541 13.693L13.459 61L32 47.309L50.541 61l-7.082-22.152L62 25.154z"></path></g></svg>

I noticed that viewBox is set to "0 0 0 0", if I manually edit the html, I can see my svg icons.

Oh! and I should also mention that the Rating is rendered inside a headlessui modal.

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?

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.

More granular star fill (average)

Is there a chance to add a possibility to fill star in 2/3 instead of filing it either entirely or in half? I need for "average" rating displaying

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.