Skip to content

Commit

Permalink
[Badge] Add error as a palette option (#10004)
Browse files Browse the repository at this point in the history
  • Loading branch information
t49tran authored and oliviertassinari committed Jan 23, 2018
1 parent 839fbdf commit a39d4a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pages/api/badge.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ filename: /src/Badge/Badge.js
| <span style="color: #31a148">badgeContent *</span> | node | | The content rendered within the badge. |
| <span style="color: #31a148">children *</span> | node | | The badge will be added relative to this node. |
| classes | object | | Useful to extend the style applied to components. |
| color | enum:&nbsp;'default'&nbsp;&#124;<br>&nbsp;'primary'&nbsp;&#124;<br>&nbsp;'secondary'<br> | 'default' | The color of the component. It's using the theme palette when that makes sense. |
| color | enum:&nbsp;'default'&nbsp;&#124;<br>&nbsp;'primary'&nbsp;&#124;<br>&nbsp;'secondary'&nbsp;&#124;<br>&nbsp;'error'<br> | 'default' | The color of the component. It's using the theme palette when that makes sense. |
| component | union:&nbsp;string&nbsp;&#124;<br>&nbsp;func<br> | 'span' | The component used for the root node. Either a string to use a DOM element or a component. |

Any other properties supplied will be [spread to the root element](/guides/api#spread).
Expand All @@ -28,6 +28,7 @@ This property accepts the following keys:
- `badge`
- `colorPrimary`
- `colorSecondary`
- `colorError`

Have a look at [overriding with classes](/customization/overrides#overriding-with-classes) section
and the [implementation of the component](https://github.com/mui-org/material-ui/tree/v1-beta/src/Badge/Badge.js)
Expand Down
2 changes: 1 addition & 1 deletion src/Badge/Badge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface BadgeProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, BadgeClassKey> {
badgeContent: React.ReactNode;
children: React.ReactNode;
color?: PropTypes.Color;
color?: PropTypes.Color | 'error';
component?: React.ReactType<BadgeProps>;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const styles = theme => ({
backgroundColor: theme.palette.secondary.main,
color: theme.palette.secondary.contrastText,
},
colorError: {
backgroundColor: theme.palette.error.main,
color: theme.palette.error.contrastText,
},
});

function Badge(props) {
Expand Down Expand Up @@ -86,7 +90,7 @@ Badge.propTypes = {
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color: PropTypes.oneOf(['default', 'primary', 'secondary']),
color: PropTypes.oneOf(['default', 'primary', 'secondary', 'error']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
Expand Down
16 changes: 16 additions & 0 deletions src/Badge/Badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ describe('<Badge />', () => {
);
});

it('have error class', () => {
const wrapper = shallow(
<Badge badgeContent={10} color="error">
<span />
</Badge>,
);

assert.strictEqual(
wrapper
.find('span')
.at(2)
.hasClass(classes.colorError),
true,
);
});

it('renders children and overwrite root styles', () => {
const style = { backgroundColor: 'red' };
const wrapper = shallow(
Expand Down

0 comments on commit a39d4a9

Please sign in to comment.