smastrom / react-rating Goto Github PK
View Code? Open in Web Editor NEW:star: Zero-dependency, highly customizable rating component for React.
Home Page: https://reactrating.netlify.app
License: MIT License
:star: Zero-dependency, highly customizable rating component for React.
Home Page: https://reactrating.netlify.app
License: MIT License
The component is amazing! But itβs a pity that such an opportunity is missing, it is very necessary
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.
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 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?
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
value={1.5}
readonly
style={{ maxWidth: 100 }}
/>
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',
}}
/>
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.