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

[Chip] Add component property #9890

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 pages/api/chip.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Chips represent complex entities in small blocks, such as a contact.
|:-----|:-----|:--------|:------------|
| avatar | element | | Avatar element. |
| classes | object | | Useful to extend the style applied to components. |
| component | union:&nbsp;string&nbsp;&#124;<br>&nbsp;func<br> | 'div' | The component used for the root node. Either a string to use a DOM element or a component. |
| deleteIcon | element | | Custom delete icon element. Will be shown only if `onDelete` is set. |
| label | node | | The content of the label. |
| onDelete | func | | Callback function fired when the delete icon is clicked. If set, the delete icon will be shown. |
Expand Down
1 change: 1 addition & 0 deletions src/Chip/Chip.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StandardProps } from '..';
export interface ChipProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ChipClassKey> {
avatar?: React.ReactElement<any>;
component?: React.ReactType<ChipProps>;
deleteIcon?: React.ReactElement<any>;
label?: React.ReactNode;
onDelete?: React.EventHandler<any>;
Expand Down
14 changes: 12 additions & 2 deletions src/Chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Chip extends React.Component {
avatar: avatarProp,
classes,
className: classNameProp,
component: ComponentProp,
deleteIcon: deleteIconProp,
label,
onClick,
Expand Down Expand Up @@ -168,7 +169,7 @@ class Chip extends React.Component {
}

return (
<div
<ComponentProp
role="button"
className={className}
tabIndex={tabIndex}
Expand All @@ -182,7 +183,7 @@ class Chip extends React.Component {
{avatar}
<span className={classes.label}>{label}</span>
{deleteIcon}
</div>
</ComponentProp>
);
}
}
Expand All @@ -200,6 +201,11 @@ Chip.propTypes = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Custom delete icon element. Will be shown only if `onDelete` is set.
*/
Expand Down Expand Up @@ -227,4 +233,8 @@ Chip.propTypes = {
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

Chip.defaultProps = {
component: 'div',
};

export default withStyles(styles, { name: 'MuiChip' })(Chip);