Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 7653d93

Browse files
author
Patrick Burtchaell
authored
Merge pull request #119 from BamaBoy/barFactoriesUpdate
Bar styles factories enhancement
2 parents c98663c + 2988b5f commit 7653d93

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

docs/guides/styles.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ I would highly suggest using this method since the styles included in the compon
2727
These two function have the following signature:
2828

2929
```js
30-
(index: Number, style: Object|Void) => Object
30+
(index: Number, style: Object|Void, notification: Object) => Object
3131
```
3232

33-
Where `index` is the index of the notification in the notifications array and
34-
`style` is the style property of the individual notification.
33+
Where `index` is the index of the notification in the notifications array,
34+
`style` is the style property of the individual notification and `notification` is the notification itself.
3535

3636
This function is used to dynamically set the style of each notification in the
3737
stack. The default function adds the `bottom` style property to correctly
3838
position of the notification in a stack.
3939

4040
```js
41-
function defaultStyleFactory(index, style) {
41+
function defaultStyleFactory(index, style, notification) {
4242
return Object.assign(
4343
{},
4444
style,

src/notificationStack.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ const NotificationStack = props => (
2323
const dismissNow = isLast || !props.dismissInOrder;
2424

2525
// Handle styles
26-
const barStyle = props.barStyleFactory(index, notification.barStyle);
27-
const activeBarStyle = props.activeBarStyleFactory(index, notification.activeBarStyle);
26+
const barStyle = props.barStyleFactory(index, notification.barStyle, notification);
27+
const activeBarStyle = props.activeBarStyleFactory(
28+
index,
29+
notification.activeBarStyle,
30+
notification
31+
);
2832

2933
// Allow onClick from notification stack or individual notifications
3034
const onClick = notification.onClick || props.onClick;

test/notificationStack.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ describe('<NotificationStack />', () => {
179179
expect(notification.prop('barStyle').background).to.equal('rgb(2, 2, 2)');
180180
});
181181

182+
it('batStyleFactory should have access to notification', () => {
183+
const styleFactory = (index, style, notification) => Object.assign(
184+
{},
185+
style,
186+
{ bottom: `${index}px`, color: notification.key === 1111111 ? 'green' : 'red' }
187+
);
188+
189+
const stack = mount(
190+
<NotificationStack
191+
notifications={[mockNotification]}
192+
barStyleFactory={styleFactory}
193+
onDismiss={() => {}}
194+
/>
195+
);
196+
197+
const notification = stack.find(Notification);
198+
199+
expect(notification.prop('barStyle').color).to.equal('green');
200+
});
201+
182202
it('activeBarStyleFactory should set correct style on notification', () => {
183203
const styleFactory = (index, style) => Object.assign(
184204
{},
@@ -219,6 +239,26 @@ describe('<NotificationStack />', () => {
219239
expect(notification.prop('activeBarStyle').left).to.equal('4rem');
220240
});
221241

242+
it('activeBarStyleFactory should have access to notification', () => {
243+
const styleFactory = (index, style, notification) => Object.assign(
244+
{},
245+
style,
246+
{ bottom: `${index}px`, color: notification.key === 1111111 ? 'green' : 'red' }
247+
);
248+
249+
const stack = mount(
250+
<NotificationStack
251+
notifications={[mockNotification]}
252+
activeBarStyleFactory={styleFactory}
253+
onDismiss={() => {}}
254+
/>
255+
);
256+
257+
const notification = stack.find(Notification);
258+
259+
expect(notification.prop('activeBarStyle').color).to.equal('green');
260+
});
261+
222262
/**
223263
* Test: Global handling of onClick:
224264
*

0 commit comments

Comments
 (0)