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 support for custom Component prop #28

Merged
merged 4 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Rating from 'material-ui-rating'
|Name |Type |Default|Description |
|-------------------|--------|-------|-------------------------------------------------------------------------------------|
|classes* |`object`| |Useful to extend the style applied to components. The accepted keys are listed below.|
|component |`elementType`|`div`|The component used for the root node. Either a string to use a DOM element or a component.|
|disabled |`bool` |`false`|Disables the rating and gray it out if set to true. |
|iconFilled |`node` | |This is the icon to be used as an icon in value range. |
|iconFilledRenderer |`func` | |Overrides filled icon renderer. |
Expand Down
7 changes: 5 additions & 2 deletions src/components/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Rating extends Component {
}

render () {
const { classes, max, disabled, readOnly, value, onChange } = this.props
const { component: Component, classes, max, disabled, readOnly, value, onChange } = this.props
const rating = []

for (let i = 1; i <= max; i++) {
Expand Down Expand Up @@ -131,11 +131,12 @@ class Rating extends Component {
)
}

return (<div className={classes.root}>{rating}</div>)
return (<Component className={classes.root}>{rating}</Component>)
}
}

Rating.defaultProps = {
component: 'div',
disabled: false,
max: 5,
readOnly: false,
Expand All @@ -148,6 +149,8 @@ Rating.defaultProps = {
Rating.propTypes = {
/** Useful to extend the style applied to components. See the repository README for the accepted keys. */
classes: PropTypes.object.isRequired,
/** The component used for the root node. Either a string to use a DOM element or a component. */
component: PropTypes.elementType,
/** Disables the rating and gray it out if set to true. */
disabled: PropTypes.bool,
/** This is the icon to be used as an icon in value range. */
Expand Down
1 change: 1 addition & 0 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ storiesOf('Rating', module)
</div>
)
})
.add('with custom component', () => <Rating Component='span' onChange={action('onChange')} />)