Skip to content

Commit 28d3edf

Browse files
committed
feat(Label): add component
1 parent f2b0e4d commit 28d3edf

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

lib/Label.jsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { PropTypes } from 'react';
2+
import classNames from 'classnames';
3+
4+
const propTypes = {
5+
color: PropTypes.string,
6+
pill: PropTypes.bool
7+
};
8+
9+
const defaultProps = {
10+
color: 'default',
11+
pill: false
12+
};
13+
14+
class Label extends React.Component {
15+
constructor(props) {
16+
super(props);
17+
}
18+
19+
render() {
20+
const {
21+
children,
22+
className,
23+
color,
24+
pill,
25+
...attributes
26+
} = this.props;
27+
28+
const classes = classNames(
29+
className,
30+
'label',
31+
'label-' + color,
32+
pill ? 'label-pill' : false
33+
);
34+
35+
return (
36+
<span {...attributes}
37+
className={classes}>
38+
{children}
39+
</span>
40+
);
41+
}
42+
}
43+
44+
Label.propTypes = propTypes;
45+
Label.defaultProps = defaultProps;
46+
47+
export default Label;

test/Label.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+
import React from 'react';
3+
import { shallow } from 'enzyme';
4+
import { Label } from '../lib';
5+
6+
describe('Label', () => {
7+
it('should render children', () => {
8+
const wrapper = shallow(<Label>Yo!</Label>);
9+
10+
expect(wrapper.text()).toBe('Yo!');
11+
});
12+
13+
it('should render labels with default color', () => {
14+
const wrapper = shallow(<Label>Default Label</Label>);
15+
16+
expect(wrapper.hasClass('label-default')).toBe(true);
17+
});
18+
19+
it('should render Labels with other colors', () => {
20+
const wrapper = shallow(<Label color="danger">Danger Label</Label>);
21+
22+
expect(wrapper.hasClass('label-danger')).toBe(true);
23+
});
24+
});

0 commit comments

Comments
 (0)