Skip to content

Commit

Permalink
NEW Add versioning state modifier for Badge component
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Feb 10, 2019
1 parent 9bd11fe commit a5b33f1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions client/src/components/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ export const statuses = [

class Badge extends PureComponent {
render() {
const { status, inverted, className, message } = this.props;
const { status, inverted, stateBadge, className, message } = this.props;
if (!status) {
return null;
}

const invertedClass = inverted ? `badge-${status}--inverted` : '';

const compiledClassNames = classnames(
className,
'badge',
`badge-${status}`,
invertedClass,
{
[`badge-${status}--inverted`]: inverted,
'badge--state': stateBadge,
}
);
return (
<span className={compiledClassNames}>
Expand All @@ -44,12 +45,14 @@ Badge.propTypes = {
status: PropTypes.oneOf(statuses),
className: PropTypes.string,
inverted: PropTypes.bool,
stateBadge: PropTypes.bool,
};

Badge.defaultProps = {
status: 'default',
className: 'badge-pill',
inverted: false,
stateBadge: false,
};

export default Badge;
7 changes: 7 additions & 0 deletions client/src/components/Badge/Badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@
@include badge-variant-inverted($value);
}
}

// Versioning state badges
.badge--state {
background-color: transparent;
padding-left: 0;
padding-right: 0;
}
3 changes: 3 additions & 0 deletions client/src/components/Badge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const props = {
status: 'success',
message: 'The save was successful.',
className: 'action__result',
inverted: false,
stateBadge: false,
};
<Badge {...props} />
```
Expand All @@ -18,3 +20,4 @@ const props = {
* `message` (string): The string to display in the badge.
* `className` (string): Any extra classes to apply for the badge.
* `inverted` (boolean): If the colours should be inverted.
* `stateBadge` (boolean): For use in the context of versioning states (use with inverted).
2 changes: 1 addition & 1 deletion client/src/components/Badge/tests/Badge-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import JSXAddon from 'storybook-addon-jsx';

import Badge, { statuses } from 'components/Badge/Badge';


setAddon(JSXAddon);

storiesOf('Admin/Badges', module)
Expand All @@ -18,5 +17,6 @@ storiesOf('Admin/Badges', module)
status={select('status', statuses, 'default')}
className={boolean('pill', true) ? 'badge-pill' : ''}
inverted={boolean('inverted')}
stateBadge={boolean('stateBadge')}
/>
));

0 comments on commit a5b33f1

Please sign in to comment.