Coder Social home page Coder Social logo

react-stars's People

Contributors

anvk avatar fedoryakubovich avatar gabmus avatar hermanya avatar jim-at-jibba avatar nolanleung avatar olegberman avatar peterpme avatar zdila 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  avatar  avatar  avatar  avatar  avatar

react-stars's Issues

Use our own images

It is posible?

Example: fullStar={require('../../../Resources/star.png')}

get Rating on Hover

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})
}
}

User cannot change stars when edit property is passed as true

How to setup test:

  1. Follow instructions provided in readme.
  2. Change one of the component configurations in /example/index.js to include edit: true
    E.g.
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}`)
  }
}
  1. Run npm run dev-example and observe how the apple rater does not work anymore

Warning when using with React v16.9

react-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

Discussion: two separate characters for the on/off states.

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?

Get the e.target or pass another param into onChange handler

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 ?

The component ReactStars won't let me use setState({})

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.

styling problem

Hey, thanks for this very handy component! I'm having a couple styling issues with it though.

  1. 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.

  2. 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?

Don't change star color when I selected

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}); }

Warning: componentWillReceiveProps has been renamed

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.

  • 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

half and edit props are always either the default value or false

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?

Rest state of stars when i change the parent state

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); }

Hello guys I'm having an issue to keep the format!

Hello and first of all thanks, it's a nice feature.

I'm having this issue:

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}`)
  }
}

This is my code:

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>
//                  ...

How to specify default stars

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.

Change styling to display: inline-block?

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?

Half stars doesnt seem to be working

With half set to true can't seem to get half values to work?
see below:

          <ReactStars
             onChange={this.handleRating}
             value={this.state.currentRating}
             count={5}
             half={true}
             size={25}
           />

screen shot 2017-08-17 at 14 56 05

className property ignored?

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.

Props.edit is always false, even when set to true.

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.

import ReactStars from 'react-stars';

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 ?

have propTypes

like

ReactStars.propTypes = {
    count: PropTypes.optionalNumber,
    onChange: PropTypes.optionalFunc,
    half: PropTypes.optionalBool
//  ...otherProps 
}

It doesn't work in iOS

How to replicate?

  • in an iPhone or Apple Tablet go to the demo: http://developers.n49.com/react-stars/
  • set a rating in the apple ratings control
  • set a rating in the stars rating control
  • you'll notice the apple ratings revert back to what it was

Workaround

Setting the option half={false} fixes the issue

After re-rendering, the star value is not changing to 0, its still set to the selected value.

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>
);

}

Problem with half star classes

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?

Why use edit prop but it does not work?

<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?

Licensing

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?

Hello guys, It is not keeping the format :(

Hello and first of all thanks, it's a nice feature.

I'm having this issue:

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}`)
  }
}

This is my code:

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>
//                  ...

Disable user interaction

I want to use this component to display rate.
So I want to disable user interaction. how can I do that?

Component doesn't re-render when sent new props

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.

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.