Skip to content

Commit

Permalink
Merge branch 'release/0.2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
igorprado committed Aug 29, 2016
2 parents c3af7fa + 4ff90c8 commit 82e8f45
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.2.10 - Aug 29, 2016

* Allows children content to override `action`. (thanks to @gor181)

## 0.2.9 - Aug 25, 2016

* Improved CSS styles for better performance
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The notification object has the following properties:
| autoDismiss | integer | 5 | Delay in seconds for the notification go away. Set this to **0** to not auto-dismiss the notification |
| dismissible | bool | true | Set if notification is dismissible by the user. [See more](#dismissible) |
| action | object | null | Add a button with label and callback function (callback is optional). [See more](#action) |
| children | element,string | null | Adds custom content, and overrides `action` (if defined) [See more](#customContent) |
| onAdd | function | null | A callback function that will be called when the notification is successfully added. The first argument is the original notification e.g. `function (notification) { console.log(notification.title + 'was added'); }` |
| onRemove | function | null | A callback function that will be called when the notification is about to be removed. The first argument is the original notification e.g. `function (notification) { console.log(notification.title + 'was removed'); }` |
| uid | integer/string | null | Overrides the internal `uid`. Useful if you are managing your notifications id. Notifications with same `uid` won't be displayed. |
Expand All @@ -125,6 +126,23 @@ notification = {

```

### Children

Add custom content / react elements

```js
notification = {
[...],
children: (
<div>
<h2>Hello World</h2>
<a>Anchor</a>
</div>
)
}

```

## Styles

This component was made to work as plug and play. For that, a handcrafted style was added to it and is used as inline CSS.
Expand Down
12 changes: 12 additions & 0 deletions example/src/scripts/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ NotificationSystemExample = React.createClass({
}
}
},
{
title: 'Hey, it\'s good to see you!',
message: 'I come with custom content!',
level: 'success',
position: 'tr',
children: (
<div>
<h2>Hello World</h2>
<a>Anchor</a>
</div>
)
},
{
title: 'I\'ll be here forever!',
message: 'Just kidding, you can click me.',
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function (config) {
// see: https://github.com/deepsweet/isparta-loader/issues/1
{
test: /\.js$|.jsx$/,
loader: 'babel',
loader: 'babel?presets=airbnb',
exclude: /node_modules/
},
{
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-notification-system",
"version": "0.2.9",
"version": "0.2.10",
"description": "A React Notification System fully customized",
"main": "dist/NotificationSystem.js",
"scripts": {
Expand Down Expand Up @@ -40,11 +40,12 @@
},
"devDependencies": {
"autoprefixer-loader": "^3.1.0",
"babel-core": "^5.8.25",
"babel-core": "^6.14.0",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"babel-loader": "^6.2.5",
"babel-plugin-react-class-display-name": "^0.1.0",
"babel-plugin-react-transform": "^1.1.1",
"babel-plugin-react-transform": "^2.0.2",
"babel-preset-airbnb": "^2.0.0",
"css-loader": "^0.19.0",
"eslint": "1.9.0",
"eslint-config-airbnb": "^0.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/NotificationContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var NotificationContainer = React.createClass({
onRemove={ self.props.onRemove }
noAnimation={ self.props.noAnimation }
allowHTML={ self.props.allowHTML }
children={ self.props.children }
/>
);
});
Expand Down
10 changes: 9 additions & 1 deletion src/NotificationItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ var NotificationItem = React.createClass({
getStyles: React.PropTypes.object,
onRemove: React.PropTypes.func,
allowHTML: React.PropTypes.bool,
noAnimation: React.PropTypes.bool
noAnimation: React.PropTypes.bool,
children: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element
])
},

getDefaultProps: function() {
Expand Down Expand Up @@ -304,6 +308,10 @@ var NotificationItem = React.createClass({
);
}

if (notification.children) {
actionButton = notification.children;
}

return (
<div className={ className } onClick={ this._dismiss } onMouseEnter={ this._handleMouseEnter } onMouseLeave={ this._handleMouseLeave } style={ notificationStyle }>
{ title }
Expand Down
19 changes: 15 additions & 4 deletions test/notification-system.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ describe('Notification Component', function() {
done();
});

it('should render a children if passed', done => {
defaultNotification.children = (
<div className="custom-container"></div>
);

component.addNotification(defaultNotification);
let customContainer = TestUtils.findRenderedDOMComponentWithClass(instance, 'custom-container');
expect(customContainer).toExist();
done();
});

it('should pause the timer if a notification has a mouse enter', done => {
notificationObj.autoDismiss = 2;
component.addNotification(notificationObj);
Expand Down Expand Up @@ -327,25 +338,25 @@ describe('Notification Component', function() {

it('should throw an error if no level is defined', done => {
delete notificationObj.level;
expect(component.addNotification).withArgs(notificationObj).toThrow(/notification level is required/);
expect(() => component.addNotification(notificationObj)).toThrow(/notification level is required/);
done();
});

it('should throw an error if a invalid level is defined', done => {
notificationObj.level = 'invalid';
expect(component.addNotification).withArgs(notificationObj).toThrow(/is not a valid level/);
expect(() => component.addNotification(notificationObj)).toThrow(/is not a valid level/);
done();
});

it('should throw an error if a invalid position is defined', done => {
notificationObj.position = 'invalid';
expect(component.addNotification).withArgs(notificationObj).toThrow(/is not a valid position/);
expect(() => component.addNotification(notificationObj)).toThrow(/is not a valid position/);
done();
});

it('should throw an error if autoDismiss is not a number', done => {
notificationObj.autoDismiss = 'string';
expect(component.addNotification).withArgs(notificationObj).toThrow(/\'autoDismiss\' must be a number./);
expect(() => component.addNotification(notificationObj)).toThrow(/\'autoDismiss\' must be a number./);
done();
});
});
16 changes: 1 addition & 15 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,7 @@ module.exports = {
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'example/src')
],
loader: 'babel',
query: {
stage: 0,
plugins: ['react-class-display-name', 'react-transform'],
extra: {
'react-transform': [{
'target': 'react-transform-hmr',
'imports': ['react'],
'locals': ['module']
}, {
'target': 'react-transform-catch-errors',
'imports': ['react', 'redbox-react']
}]
}
}
loader: 'babel?presets=airbnb'
},
{
test: /\.sass$/,
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'example/src')
],
loader: 'babel'
loader: 'babel?presets=airbnb'
},
{
test: /\.sass$/,
Expand Down

0 comments on commit 82e8f45

Please sign in to comment.