This repository was archived by the owner on Jul 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 230
chore(fab): Pass icon as a prop, not a child element #159
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf2c84a
chore(fab): Pass icon as a prop, not a child element
lynnmercier 6d1f1d2
Merge branch 'master' into feat/extended-fab
lynnmercier c33bf07
fix: convert screenshot elements to elements with no children
cc863b3
fix unit tests, address comments
lynnmercier 07d1f60
addressed comments
lynnmercier d473fa2
update README
lynnmercier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,34 +6,33 @@ import withRipple from '@material/react-ripple'; | |
|
||
export class Fab extends React.Component { | ||
|
||
state = { | ||
classList: new Set(), | ||
}; | ||
|
||
get classes() { | ||
const {classList} = this.state; | ||
const { | ||
mini, | ||
className, | ||
} = this.props; | ||
|
||
return classnames('mdc-fab', Array.from(classList), className, { | ||
return classnames('mdc-fab', className, { | ||
'mdc-fab--mini': mini, | ||
}); | ||
} | ||
|
||
addIconClassToAllChildren = () => { | ||
return React.Children.map(this.props.children, (item) => { | ||
const className = `${item.props.className} mdc-fab__icon`; | ||
const props = Object.assign({}, item.props, {className}); | ||
return React.cloneElement(item, props); | ||
}); | ||
}; | ||
renderIcon() { | ||
const {icon} = this.props; | ||
|
||
if (!icon) { | ||
return; | ||
} | ||
|
||
const updatedProps = { | ||
className: classnames('mdc-fab__icon', icon.props.className), | ||
}; | ||
return React.cloneElement(icon, updatedProps); | ||
} | ||
|
||
render() { | ||
const { | ||
/* eslint-disable */ | ||
children, | ||
className, | ||
unbounded, | ||
mini, | ||
|
@@ -47,24 +46,22 @@ export class Fab extends React.Component { | |
className={this.classes} | ||
ref={initRipple} | ||
{...otherProps}> | ||
{this.addIconClassToAllChildren()} | ||
{this.renderIcon()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment for line above ^ remove children from list, since you don't use it |
||
</button> | ||
); | ||
} | ||
} | ||
|
||
Fab.propTypes = { | ||
mini: PropTypes.bool, | ||
icon: PropTypes.element, | ||
className: PropTypes.string, | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.element), | ||
PropTypes.element, | ||
]).isRequired, | ||
initRipple: PropTypes.func, | ||
}; | ||
|
||
Fab.defaultProps = { | ||
mini: false, | ||
icon: null, | ||
className: '', | ||
initRipple: () => {}, | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment for lines above^
You are not using this.state.classList. Please remove that from state.