n49 / react-stars Goto Github PK
View Code? Open in Web Editor NEWA simple star rating component for your React projects :star:
Home Page: http://developers.n49.com/react-stars/
A simple star rating component for your React projects :star:
Home Page: http://developers.n49.com/react-stars/
event.target will give every time the same data-index. It should be event.currentTarget
I am waiting on many of the resolved issues.
It is posible?
Example: fullStar={require('../../../Resources/star.png')}
they're just staying gray and yellow.
how can i get the rating valu on hover?
I have tried mouseover but its not workin...
const thirdExample = {
size: 20,
count:5,
half: false,
color1:'grey',
color2:'#e5c145',
value: metaData.rate || 0,
edit:true,
mouseOver:newValue=>{
console.log(Example 3: new value is ${newValue}
)
},
onChange: newValue => {
this.saveRate(newValue);
console.log(Example 3: new value is ${newValue}
)
}
}
I have to manually style and adjust average ratting. It would be great if I could set average ratings on the component just like value
prop
How to setup test:
/example/index.js
to include edit: true
const secondExample = {
size: 50,
count: 10,
char: '',
edit: true, // Added this property
color1: '#ff9900',
color2: '#6599ff',
onChange: newValue => {
console.log(`Example 2: new value is ${newValue}`)
}
}
npm run dev-example
and observe how the apple rater does not work anymorereact-dom.development.js:11494 Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.
Please update the following components: ReactStars
These events get called on page load no matter what.
Hey there,
I have a use case where I want to be able to have one character as the 'off' state, and a separate character as the 'on' state. I'm using my own font and the off star is a completely separate character than the on star.
I'm happy to work on a PR for it, just wondering if that's something you'd consider merging?
I've render a list of voting of item like this
<ReactStars id={index} className="star-vote" onChange={this.feedBack} size={35} half={false} count={5} value={item.VoteAvg} color1={'gray'} color2={'#009CDE'} edit={true}/>
Now I need to set and get the id for ReactStars component, or is there any other way that I can pass another param to onChange handler ?
We found an issue on the ReactStars component when trying to set a state.
Here is the code to reproduce the problem:
import React from 'react';
import Relay from 'react-relay';
import autobind from 'autobind-decorator';
import ReactStars from 'react-stars';
export default class BookPagePostReview extends React.Component {
constructor(props) {
super(props);
this.state = {
rating: 0,
};
}
@autobind
onStarClick(value) {
this.setState({rating: value});
}
render() {
return (
<div>
<ReactStars
count={5}
size={24}
onChange={this.onStarClick}
/>
</div>
);
}
}
Problem:
When clicking the stars the new state is set, but the stars won't show the rating I picked (i.e. if I click 3 stars, it will show nothing). That in terms of User Experience is not the optimal result.
The solution we found for this problem is using:
@autobind
onStarClick(value) {
this.state.rating = value;
}
But that one is not ideal for React.
Hey, thanks for this very handy component! I'm having a couple styling issues with it though.
The stars become half cut off once I set the size to be relatively large, e.g. 42. I tried adding margins, paddings and changing the height. None of them helped.
Also I wonder how to make the component inline, so that I could add texts before and after the stars on the same line. I tried changing the display option of the component to inline. It doesn't help.
Would really appreciate if you could shed some light on this. Thanks! @olegberman, any ideas?
I'm integrate this library into my proyect but when I select one star don't change of color.
my code
<ReactStars count={5} onChange={ratingChangedServicio} size={34} color1={'#eee'} color2={'#ffe900'} />
method ratingChangedServicio
const ratingChangedServicio = (newRating) => { this.setState({servicio : newRating}); }
this messes with snapshot testing. please make the DOM tree deterministic :)
react_devtools_backend.js:2273 Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.
npx react-codemod rename-unsafe-lifecycles
in your project source folder.Please update the following components: ReactStars
https://github.com/n49/react-stars/blob/master/src/react-stars.js#L40-L50
if(typeof props.half === 'undefined') {
props.half = true
} else {
props.half = false
}
You are checking whether the prop is not passed and then set it to true
, I guess that's the default value and it makes sense. But in the other case where the code enters the else
clause (a value is passed to the prop and that overrides it's default value) you explicitly set it to false
❓
The else clauses seem redundant and are the culprits causing the issue, don't you think?
Hello,
When i try to update the state of parent component, the state change correctly but the stars don't stay selected
onChange: newValue => { console.log(
Example 3: new value is ${newValue}) thiz.props.parentAction(newValue); }
When I select and number of stars the format do not change at the first click (generally), I need to press several times.
And the principal issue is that after rate when I begin typing at next input the format disappear.
It doesn't behave like the secondExample
:
Thanks in advance!
const secondExample = {
size: 50,
count: 10,
char: '',
color1: '#ff9900',
color2: '#6599ff',
onChange: newValue => {
console.log(`Example 2: new value is ${newValue}`)
}
}
function EditReview({editReview, user, product}) {
const[show, setShow] = useState(false);
const [stars, setStars] = useState(0);
const [description, setDescription] = useState('');
const handleOnclick = (e) => {
e.preventDefault();
setShow(true);
}
const handleOnChange = (e) => {
e.preventDefault();
setDescription(e.target.value)
console.log(e.target.value)
}
const handleOnSubmit = (e) => {
e.preventDefault();
const review = {
description: description,
qualification: Math.round(stars),
userdId: user.id
};
const id = product.id
editReview(id, review);
setShow(false);
}
const star = {
count:5,
onChange: stars=>setStars(stars),
size: 74,
color2: '#8a2be2',
half: false,
}
return (
<React.Fragment>
<Button
onClick={(e)=>handleOnclick(e)}
className=""
>Edit review
</Button>
<Modal
show={show}
onHide={()=>setShow(false)}
keyboard={true}
animation={true}
centered={true}
>
<Modal.Header
closeButton={true}
closeLabel={'Close'}
>
<Modal.Title>Change your review</Modal.Title>
</Modal.Header>
<Modal.Body>
<h4>Rate the product.</h4>
<Form>
<ReactStars {...star}/>
<hr/>
<h4>The new product review?</h4>
<InputGroup>
<InputGroup.Prepend>
<InputGroup.Text>Your review</InputGroup.Text>
</InputGroup.Prepend>
<FormControl
as="textarea"
aria-label="Description"
placeholder="I hope it's for better"
onChange={e=>handleOnChange(e)}
/>
</InputGroup>
</Form>
</Modal.Body>
// ...
I am not sure how to insert padding between star. Please help
Hi, wonderful library here thanks. I would like to specify a certain number of stars for display purpose, i dont know if this functionality is available. Also half stars doesn't seem to work.
Currently the project has reached to version 2.2.1 but npm is still using version 2.1.0.
If the star value
remains unchanged even after clicking the stars (due to a failure in the onChange
method or otherwise), the stars retain their changed state, instead of reverting to the original.
I think
react-stars/src/react-stars.js
Line 91 in b3455bd
this.props.value
and not this.state.value
. Let me know and I can push a PR.Hi! Thanks for the nice component.
I have one issue with it though, I can't get the half stars to show.
Half stars not appearing, even with value={4.5} and half={true}
Any ideas why ?
I am trying to display some texts on the right side of the stars however the component is set to be displayed as block.
How would I change it so that my texts (in
tags) are displayed beside it rather than below it?
I use className={styles.stars}
And have these styles:
.stars
display inline-block
This component is still positioning as a block. So I wrapped your component with my own inline-block positioned div
.
If the value was chosen It can't be unset to 0 stars, In any way minimum value will be 1 star
Weird bug; the only way I can set the 'edit' prop to true is by not including it in my settings object. If I include it, even when it's set to true, it appears as false. I think it's due to this line which overrides the value to 'false' when props.edit == true
, since the typeof it is not undefined.
I use React Stars in my tsx code.
I found this error “Customer/node_modules/react-stars/dist/react-stars.js' implicitly has an 'any' type.”
Could you tell me how to fix it ?
like
ReactStars.propTypes = {
count: PropTypes.optionalNumber,
onChange: PropTypes.optionalFunc,
half: PropTypes.optionalBool
// ...otherProps
}
Setting the option half={false} fixes the issue
export const FeedbackPage = () => {
const [ratedstars, setRatedstars] = useState(0);
const [ratings, setRatings] = useState('');
const [suggestions, setSuggestions] = useState('');
const ratingChanged = (value) => setRatedstars(value);
const onRatingschange = event => setRatings(event.target.value);
const onSuggestionschange = event => setSuggestions(event.target.value);
const clearForm = () => {
setRatedstars(0);
setRatings('');
setSuggestions('');
console.log(ratedstars,'ratedstars---------------------------------------')
}
const updateFeedback = () => {
const web = Web("");
web.lists.getByTitle('Feedback')
.items.add({
Pleaseexplainyourrating : {ratedstars},
Doyouhaveanysuggestionsforimprov : {ratings},
How_x0020_useful_x0020_is_x0020_ : {suggestions}
}).then(() => {
alert('success');
}).catch(() => {
clearForm()
alert('failure')
});
}
return (
<div className="main-divstyle">
<div className="hdr-style">Feedback</div>
<div className="ques-style required"> How useful is the company financials Dashboard? </div>
<div className="rating-style">
<ReactStars
count={5}
value={ratedstars}
onChange={ratingChanged}
size={50}
isHalf={true}
emptyIcon={<i className="far fa-star"></i>}
halfIcon={<i className="fa fa-star-half-alt"></i>}
fullIcon={<i className="fa fa-star"></i>}
activeColor="#ffe600"
a11y={true}
/>
</div>
<div className="ques-style required"> Please explain your rating.</div>
<textarea className='textarea-style' value={ratings} onChange={onRatingschange}></textarea>
<div className="ques-style">Do you have any suggestions for improvement? Please be specific.</div>
<textarea className='textarea-style' value={suggestions} onChange={onSuggestionschange}></textarea>
<div><button className="btn-style" onClick={updateFeedback}>Submit</button></div>
</div>
);
}
Hi, I'm using a select component with react-stars and when I choose a rating with a half star, just the half star render overlapping the options of the select, but it only happens with the half stars because it has z-index 1, but I don't know how to change it to 0, does somebody have the same problem?
componentWillReceiveProps has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.
<ReactStars
className={cx('rating')}
count={5}
half={false}
value={formData.score}
onChange={ratingChanged}
size={30}
color1='#F2F2F2'
color2='#FADB15'
edit={!hasSubmitted}
/>
When I've submitted form, the rating star actually can interactive with users, so how to solve this problem?
Hey!
I love the work that has been put in into this project. I cannot seem to find a licence for this - would you point me to it, or if its not available would you be able to license the project?
When I select and number of stars the format do not change at the first click (generally), I need to press several times.
And the principal issue is that after rate when I begin typing at next input the format disappear.
It doesn't behave like the secondExample
:
Thanks in advance!
const secondExample = {
size: 50,
count: 10,
char: '',
color1: '#ff9900',
color2: '#6599ff',
onChange: newValue => {
console.log(`Example 2: new value is ${newValue}`)
}
}
function EditReview({editReview, user, product}) {
const[show, setShow] = useState(false);
const [stars, setStars] = useState(0);
const [description, setDescription] = useState('');
const handleOnclick = (e) => {
e.preventDefault();
setShow(true);
}
const handleOnChange = (e) => {
e.preventDefault();
setDescription(e.target.value)
console.log(e.target.value)
}
const handleOnSubmit = (e) => {
e.preventDefault();
const review = {
description: description,
qualification: Math.round(stars),
userdId: user.id
};
const id = product.id
editReview(id, review);
setShow(false);
}
const star = {
count:5,
onChange: stars=>setStars(stars),
size: 74,
color2: '#8a2be2',
half: false,
}
return (
<React.Fragment>
<Button
onClick={(e)=>handleOnclick(e)}
className=""
>Edit review
</Button>
<Modal
show={show}
onHide={()=>setShow(false)}
keyboard={true}
animation={true}
centered={true}
>
<Modal.Header
closeButton={true}
closeLabel={'Close'}
>
<Modal.Title>Change your review</Modal.Title>
</Modal.Header>
<Modal.Body>
<h4>Rate the product.</h4>
<Form>
<ReactStars {...star}/>
<hr/>
<h4>The new product review?</h4>
<InputGroup>
<InputGroup.Prepend>
<InputGroup.Text>Your review</InputGroup.Text>
</InputGroup.Prepend>
<FormControl
as="textarea"
aria-label="Description"
placeholder="I hope it's for better"
onChange={e=>handleOnChange(e)}
/>
</InputGroup>
</Form>
</Modal.Body>
// ...
I want to use this component to display rate.
So I want to disable user interaction. how can I do that?
I'm using the {...starSettings}
method of passing props, one of which is the edit
prop. After manually fixing the edit override issue (#12), I expected it to re-render if I passed it a changed prop. In this case, it doesn't re-render, leaving it stuck in an edit true/false state until I refresh my page. From my understanding of react, if a prop changes, it should force a re-render? In the React tab of chrome dev tools, I can confirm that my state value changes from true
to false
and vice versa (the state value that's assigned to the edit
prop), but this doesn't seem to affect the ReactStars component, since its edit
prop stays at the initially rendered value.
edit: After poking the code a bit more, changing all the occurrences of config.edit
to this.props.edit
fixes the issue. Not sure why, but there's something wrong with the way the state (and therefore config
) is assigned values.
Now stars have cursor: pointer
when read-only. That's silly!
Gotta use this adhoc hack :(
.stars
*
cursor default !important
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.