Skip to content

Commit

Permalink
feat(notification): Notifications pass through className, style, and id
Browse files Browse the repository at this point in the history
Notification follows dropdown semantics for passing through these
attributes.

[Finishes #98913374]
  • Loading branch information
Kenny Wang and Matt Royal authored and matt-royal committed Jul 28, 2015
1 parent 49b2fdd commit 859e679
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
6 changes: 3 additions & 3 deletions spec/pivotal-ui-react/dropdown/dropdown_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ describe('Dropdowns', function() {
});

it('passes through className to the btn-group ', function() {
expect('#root .btn-group').toHaveClass('test-class');
expect('#root .btn-group').toHaveClass(props.className);
});

it('passes through style to the button', function() {
expect('#root .btn').toHaveCss({opacity: '0.5'});
expect('#root .btn').toHaveCss(props.style);
});

it('passes through id to the button', function() {
expect('#root #test-id').toExist();
expect('#root .btn#test-id').toExist();
});

it('creates a dropdown-toggle', () => {
Expand Down
33 changes: 31 additions & 2 deletions spec/pivotal-ui-react/notification/notification_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
require('../spec_helper');
import {itPropagatesAttributes} from '../support/shared_examples';

describe('Notification', function() {
var Notifications, NotificationItem;
var props = {
className: 'test-class',
id: 'test-id',
style: {
opacity: '0.5'
}
};
var itemProps = {
className: 'test-item-class',
id: 'test-item-id',
style: {
opacity: '0.75'
}
};
beforeEach(function() {
Notifications = require('../../../src/pivotal-ui-react/notifications/notifications').Notifications;
NotificationItem = require('../../../src/pivotal-ui-react/notifications/notifications').NotificationItem;
Expand All @@ -14,18 +29,32 @@ describe('Notification', function() {
describe('when there are children', function() {
beforeEach(function() {
React.render((
<Notifications>
<NotificationItem href="my-fee-link">fee</NotificationItem>
<Notifications {...props}>
<NotificationItem {...itemProps} href="my-fee-link">fee</NotificationItem>
<NotificationItem href="my-fi-link">fi</NotificationItem>
<NotificationItem href="my-fo-link">fo</NotificationItem>
<NotificationItem href="my-fum-link">fum</NotificationItem>
</Notifications>), root);
});

it('passes through the className to the btn-group', function() {
expect('#root .btn-group').toHaveClass(props.className);
});

it('passes through style to the button', function() {
expect('#root .btn').toHaveCss(props.style);
});

it('passes through id to the button', function() {
expect('#root .btn#test-id').toExist();
});

it('renders a notification count badge', function() {
expect('.dropdown-notifications-title .dropdown-notifications-badge').toContainText('4');
});

itPropagatesAttributes('#root li:first', itemProps);

it('renders the children in a dropdown menu', function() {
expect('.dropdown-menu a:eq(0)').toContainText('fee');
expect('.dropdown-menu a:eq(0)').toHaveAttr('href', 'my-fee-link');
Expand Down
11 changes: 7 additions & 4 deletions src/pivotal-ui-react/notifications/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var types = React.PropTypes;
var {Icon} = require('pui-react-iconography');
var {LinkDropdown, DropdownItem} = require('pui-react-dropdowns');
var classnames = require('classnames');
var {mergeProps} = require('pui-react-helpers');


/**
* @component Notifications
Expand Down Expand Up @@ -38,7 +40,8 @@ var Notifications = React.createClass({
size: React.PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])
},
render() {
var {size, children} = this.props;
var {size, children, ...others} = this.props;
var props = mergeProps(others, {className: 'dropdown-notifications'});
var numChildren = React.Children.count(children);
var badge = children ? <span className="dropdown-notifications-badge">{numChildren}</span> : null;
var dropdownTitleClasses = classnames('dropdown-notifications-title', size);
Expand All @@ -56,7 +59,7 @@ var Notifications = React.createClass({
</div>
</li>
);
return <LinkDropdown title={dropdownTitle} className="dropdown-notifications">{children}</LinkDropdown>;
return <LinkDropdown title={dropdownTitle} {...props}>{children}</LinkDropdown>;
}
});

Expand Down Expand Up @@ -129,8 +132,8 @@ var NotificationItem = React.createClass({
},

render() {
var {href, children} = this.props;
return <DropdownItem href={href}>{children}</DropdownItem>;
var {href, children, ...props} = this.props;
return <DropdownItem href={href} {...props}>{children}</DropdownItem>;
}
});

Expand Down

0 comments on commit 859e679

Please sign in to comment.