Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a renderOption prop on SegmentedControls #8

Merged
merged 1 commit into from
Dec 21, 2015

Conversation

laserpants
Copy link
Contributor

I wanted to add icons to my SegmentedControls buttons. I am not sure if there is a reason why only Text buttons are allowed but this pull requests introduces a renderOption prop which will allow an implementation to do something like:

  <SegmentedControls
    options         = {modes}
    onSelection     = {this.setMode.bind(this)}
    selectedOption  = {this.state.mode}
    renderOption    = {(option, selected) => {
      return (
        // ...render stuff
      )
    }}
  />

I made it so that if renderOption is not present, the default implementation is used:

  {'function' === typeof this.props.renderOption ? this.props.renderOption.bind(this)(option, selected) : (
    <Text style={style}>{label}</Text>
  )}

ArnaudRinquin added a commit that referenced this pull request Dec 21, 2015
Add a renderOption prop on SegmentedControls
@ArnaudRinquin ArnaudRinquin merged commit f830a00 into ArnaudRinquin:master Dec 21, 2015
@ArnaudRinquin
Copy link
Owner

That's a good option. Thanks 👍

@ArnaudRinquin
Copy link
Owner

FYI I adjusted your code to use call instead of bind (see)

@laserpants
Copy link
Contributor Author

Great! Thanks for the merge.

@ArnaudRinquin
Copy link
Owner

Feature published on npm with version 0.7.0 (also adds props documentation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants