Skip to content

Commit

Permalink
feat(labels): react labels now accept classname, id, style
Browse files Browse the repository at this point in the history
[#87784030]
  • Loading branch information
matt-royal authored and pivotal ui committed Jul 15, 2015
1 parent 1f41c6d commit 48e9a39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
27 changes: 26 additions & 1 deletion spec/pivotal-ui-react/labels/labels_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require('../spec_helper');
describe('Label', function() {
var Label;
beforeEach(function() {
var Label = require('../../../src/pivotal-ui-react/labels/labels').Label;
Label = require('../../../src/pivotal-ui-react/labels/labels').Label;
React.render(<Label>bananas</Label>, root);
});

Expand All @@ -14,4 +15,28 @@ describe('Label', function() {
expect('#root span').toHaveClass('label-primary');
expect('#root span').toHaveText('bananas');
});

function renderLabel(props) {
React.render(<Label {...props}>bananas</Label>, root);
}

describe('when custom options are added', function() {
beforeEach(function() {
renderLabel({
title: 'stuff',
id: 'things',
className: 'foo',
style: {
color: 'red'
}
});
});

it('renders a label with custom options', function() {
expect('#root span').toHaveAttr('title', 'stuff');
expect('#root span').toHaveAttr('id', 'things');
expect('#root span').toHaveClass('foo');
expect('#root span').toHaveCss({color: 'rgb(255, 0, 0)'});
});
});
});
8 changes: 7 additions & 1 deletion src/pivotal-ui-react/labels/labels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var React = require('react');
import {mergeProps} from 'pui-react-helpers';

/**
* @component Label
Expand All @@ -18,7 +19,12 @@ var React = require('react');
*/
var Label = React.createClass({
render() {
return <span className="label label-primary">{this.props.children}</span>;
let defaultProps = {
className: ['label', 'label-primary']
};
let {children, ...others} = this.props;
let props = mergeProps(others, defaultProps);
return <span {...props}>{children}</span>;
}
});

Expand Down

0 comments on commit 48e9a39

Please sign in to comment.