Skip to content

Commit

Permalink
Add icon to badge component
Browse files Browse the repository at this point in the history
  • Loading branch information
jamero102 committed Jul 31, 2020
1 parent a994e3b commit 74e6abf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/src/components/Badge/Badge.css
Expand Up @@ -39,3 +39,7 @@
color: var(--color-black);
border-color: currentColor;
}

.icon {
padding-right: var(--size-micro);
}
5 changes: 4 additions & 1 deletion packages/core/src/components/Badge/Badge.js
@@ -1,6 +1,7 @@
// @flow
import React from 'react';
import classNames from 'classnames/bind';
import Icon from '../Icon/Icon';

import css from './Badge.css';

Expand All @@ -11,10 +12,12 @@ type Props = {
children: any,
context: 'primary' | 'special',
hollow?: boolean,
icon?: string,
}

const Badge = ({ className, children, context, hollow, ...rest }: Props) => (
const Badge = ({ className, children, context, hollow, icon, ...rest }: Props) => (
<span {...rest} className={cx(css.root, css[context], hollow ? css.hollow : null, className)}>
{icon && <Icon className={css.icon} name={icon}/>}
{children}
</span>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/playground/stories/Badge.story.js
Expand Up @@ -16,4 +16,9 @@ storiesOf('Badge', module)
<Badge context="special" hollow>
Collection
</Badge>
))
.add('With icon', () => (
<Badge icon="price-tag">
50% Discount
</Badge>
));

0 comments on commit 74e6abf

Please sign in to comment.