Skip to content

Commit

Permalink
feat(Badge): handle links
Browse files Browse the repository at this point in the history
Updated tests
Updated docs
  • Loading branch information
TheSharpieOne committed Sep 16, 2017
1 parent fd59d37 commit 9b32cee
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
13 changes: 13 additions & 0 deletions docs/lib/Components/BadgePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const BadgePillsExampleSource = require('!!raw!../examples/BadgePills');
import BadgeVariationsExample from '../examples/BadgeVariations';
const BadgeVariationsExampleSource = require('!!raw!../examples/BadgeVariations');

import BadgeLinksExample from '../examples/BadgeLinks';
const BadgeLinksExampleSource = require('!!raw!../examples/BadgeLinks');

export default class BadgesPage extends React.Component {
render() {
return (
Expand Down Expand Up @@ -58,6 +61,16 @@ export default class BadgesPage extends React.Component {
{BadgePillsExampleSource}
</PrismCode>
</pre>
<h3>Links</h3>
<p>Adding the <code>href</code> prop (without specifying a <code>tag</code> prop) will default the badge to a link.</p>
<div className="docs-example">
<BadgeLinksExample />
</div>
<pre>
<PrismCode className="language-jsx">
{BadgeLinksExampleSource}
</PrismCode>
</pre>
</div>
);
}
Expand Down
19 changes: 19 additions & 0 deletions docs/lib/examples/BadgeLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { Badge } from 'reactstrap';

export default class Example extends React.Component {
render() {
return (
<div>
<Badge href="#" color="primary">Primary</Badge>
<Badge href="#" color="secondary">Secondary</Badge>
<Badge href="#" color="success">Success</Badge>
<Badge href="#" color="danger">Danger</Badge>
<Badge href="#" color="warning">Warning</Badge>
<Badge href="#" color="info">Info</Badge>
<Badge href="#" color="light">Light</Badge>
<Badge href="#" color="dark">Dark</Badge>
</div>
);
}
}
8 changes: 6 additions & 2 deletions src/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const propTypes = {
};

const defaultProps = {
color: 'default',
color: 'secondary',
pill: false,
tag: 'span'
};

const Badge = (props) => {
const {
let {
className,
cssModule,
color,
Expand All @@ -35,6 +35,10 @@ const Badge = (props) => {
pill ? 'badge-pill' : false
), cssModule);

if (attributes.href && Tag === 'span') {
Tag = 'a';
}

return (
<Tag {...attributes} className={classes} />
);
Expand Down
22 changes: 20 additions & 2 deletions src/__tests__/Badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,34 @@ import { shallow } from 'enzyme';
import { Badge } from '../';

describe('Badge', () => {
it('should render a span by default', () => {
const wrapper = shallow(<Badge>Yo!</Badge>);

expect(wrapper.type()).toBe('span');
});

it('should render an anchor when when href is provided', () => {
const wrapper = shallow(<Badge href="#">Yo!</Badge>);

expect(wrapper.type()).toBe('a');
});

it('should render a custom tag when provided', () => {
const wrapper = shallow(<Badge tag="main">Yo!</Badge>);

expect(wrapper.type()).toBe('main');
});

it('should render children', () => {
const wrapper = shallow(<Badge>Yo!</Badge>);

expect(wrapper.text()).toBe('Yo!');
});

it('should render badges with default color', () => {
it('should render badges with secondary color', () => {
const wrapper = shallow(<Badge>Default Badge</Badge>);

expect(wrapper.hasClass('badge-default')).toBe(true);
expect(wrapper.hasClass('badge-secondary')).toBe(true);
});

it('should render Badges with other colors', () => {
Expand Down

0 comments on commit 9b32cee

Please sign in to comment.