1 |
|
2 | import React from 'react';
|
3 | import { storiesOf } from '@storybook/react';
|
4 | import { action } from '@storybook/addon-actions';
|
5 | import { Provider } from 'react-redux';
|
6 | import { createStore, combineReducers, applyMiddleware } from 'redux';
|
7 | import thunk from 'redux-thunk';
|
8 | import notification from '../src/reducers/notificationReducer';
|
9 | import ConnectedNotificationContainer, {
|
10 | NotificationContainer,
|
11 | } from '../src/components/notificationContainer';
|
12 | import { showNotification } from '../src/actions/notificationActions';
|
13 |
|
14 | type Props = {
|
15 | notification: any,
|
16 | removeNotification: number => void,
|
17 | };
|
18 | const Notifications = (props: Props) => <NotificationContainer {...props} />;
|
19 |
|
20 | const baseProps = {
|
21 | notification: {},
|
22 | removeNotification: action('remove notification'),
|
23 | };
|
24 |
|
25 | const checkNotification = {
|
26 | dismissable: true,
|
27 | icon: 'CHECK',
|
28 | id: performance.now(),
|
29 | text: 'Check Notification',
|
30 | timeout: 0,
|
31 | };
|
32 |
|
33 | const cancelNotification = {
|
34 | dismissable: true,
|
35 | icon: 'CANCEL',
|
36 | id: performance.now() + 1,
|
37 | text: 'Cancel Notification',
|
38 | timeout: 0,
|
39 | };
|
40 |
|
41 | const exclamationNotification = {
|
42 | dismissable: true,
|
43 | icon: 'EXCLAMATION',
|
44 | id: performance.now() + 2,
|
45 | text: 'Exclamation Notification',
|
46 | timeout: 0,
|
47 | };
|
48 |
|
49 | storiesOf('Notifications', module)
|
50 | .add('All three notifications', () => (
|
51 | <Notifications
|
52 | {...{
|
53 | ...baseProps,
|
54 | notification: {
|
55 | '1': cancelNotification,
|
56 | '2': checkNotification,
|
57 | '3': exclamationNotification,
|
58 | },
|
59 | }}
|
60 | />
|
61 | ))
|
62 | .add('No dismiss', () => (
|
63 | <Notifications
|
64 | {...{
|
65 | ...baseProps,
|
66 | notification: { '1': { ...checkNotification, dismissable: false } },
|
67 | }}
|
68 | />
|
69 | ))
|
70 | .add('Call to action', () => (
|
71 | <Notifications
|
72 | {...{
|
73 | ...baseProps,
|
74 | notification: {
|
75 | '1': {
|
76 | ...checkNotification,
|
77 | dismissable: true,
|
78 | callToAction: 'Do a thing',
|
79 | onCallToAction: action('call to action'),
|
80 | },
|
81 | },
|
82 | }}
|
83 | />
|
84 | ))
|
85 | .add('Subtext', () => (
|
86 | <Notifications
|
87 | {...{
|
88 | ...baseProps,
|
89 | notification: {
|
90 | '1': {
|
91 | ...checkNotification,
|
92 | dismissable: true,
|
93 | subText: "I think there's a bear in my house.",
|
94 | },
|
95 | },
|
96 | }}
|
97 | />
|
98 | ))
|
99 | .add('Subtext and C2A', () => (
|
100 | <Notifications
|
101 | {...{
|
102 | ...baseProps,
|
103 | notification: {
|
104 | '1': {
|
105 | ...checkNotification,
|
106 | dismissable: true,
|
107 | subText: "I think there's a bear in my house.",
|
108 | callToAction: 'Poke the bear',
|
109 | onCallToAction: action('poke'),
|
110 | },
|
111 | },
|
112 | }}
|
113 | />
|
114 | ))
|
115 | .add('Connected notification', () => {
|
116 | const store = createStore(
|
117 | combineReducers({ notification }),
|
118 | { notification: {} },
|
119 | applyMiddleware(thunk)
|
120 | );
|
121 | function show() {
|
122 | store.dispatch(
|
123 | showNotification({
|
124 | dismissable: true,
|
125 | icon: 'CHECK',
|
126 | text: 'Check Notification',
|
127 | timeout: 0,
|
128 | })
|
129 | );
|
130 | }
|
131 | show();
|
132 | return (
|
133 | <Provider store={store}>
|
134 | <React.Fragment>
|
135 | <ConnectedNotificationContainer />
|
136 | <button onClick={show}>Show</button>
|
137 | </React.Fragment>
|
138 | </Provider>
|
139 | );
|
140 | });
|