smastrom / react-rating Goto Github PK
View Code? Open in Web Editor NEW⭐ Zero-dependency, highly customizable rating component for React.
Home Page: https://reactrating.netlify.app
License: MIT License
⭐ Zero-dependency, highly customizable rating component for React.
Home Page: https://reactrating.netlify.app
License: MIT License
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.
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',
}}
/>
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.
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)
<Rating
value={1.5}
readonly
style={{ maxWidth: 100 }}
/>
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)
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"]
}
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.
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.
The component is amazing! But it’s a pity that such an opportunity is missing, it is very necessary
Hey, the example from docs, but with default value of rating being non 0, causes first value of onChange handler be 0 ignoring the user input. Following updates of rating are correctly handled and corresponding user inputs are received in onChange handler.
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?
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.