forked from Skyscanner/backpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstories.js
More file actions
380 lines (355 loc) · 11.5 KB
/
stories.js
File metadata and controls
380 lines (355 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/*
* Backpack - Skyscanner's Design System
*
* Copyright 2018 Skyscanner Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* @flow */
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { storiesOf } from '@storybook/react-native';
import BpkText from 'react-native-bpk-component-text';
import BpkButton from 'react-native-bpk-component-button';
import { spacingBase } from 'bpk-tokens/tokens/base.react.native';
import CenterDecorator from '../../storybook/CenterDecorator';
import BpkBannerAlert, {
ALERT_TYPES,
type BpkBannerAlertProps,
propTypes as bannerAlertPropTypes,
defaultProps as bannerAlertDefaultProps,
} from './index';
const styles = StyleSheet.create({
bannerAlert: {
marginBottom: spacingBase,
},
button: {
marginBottom: spacingBase,
},
});
class ExpandableBannerAlert extends Component<
BpkBannerAlertProps,
{ expanded: boolean },
> {
static propTypes = {
...bannerAlertPropTypes,
toggleExpandedButtonLabel: PropTypes.string,
};
static defaultProps = {
...bannerAlertDefaultProps,
toggleExpandedButtonLabel: null,
};
constructor() {
super();
this.state = {
expanded: false,
};
}
onToggleExpanded = () => {
this.setState(prevState => ({ expanded: !prevState.expanded }));
};
render() {
return (
<BpkBannerAlert
{...this.props}
onToggleExpanded={this.onToggleExpanded}
expanded={this.state.expanded}
toggleExpandedButtonLabel={this.state.expanded ? 'Collapse' : 'Expand'}
/>
);
}
}
// eslint-disable-next-line react/no-multi-comp
class DismissableBannerAlert extends Component<
BpkBannerAlertProps,
{ show: boolean },
> {
static propTypes = { ...bannerAlertPropTypes };
static defaultProps = { ...bannerAlertDefaultProps };
constructor() {
super();
this.state = {
show: true,
};
}
onDismiss = () => {
this.setState({ show: false });
};
render() {
return (
<BpkBannerAlert
{...this.props}
show={this.state.show}
onDismiss={this.onDismiss}
dismissable
/>
);
}
}
// eslint-disable-next-line react/no-multi-comp
class BpkBannerAlertFadeDemo extends Component<
BpkBannerAlertProps,
{ bannerAlertCount: number },
> {
static propTypes = { ...bannerAlertPropTypes };
static defaultProps = { ...bannerAlertDefaultProps };
constructor() {
super();
this.state = {
bannerAlertCount: 0,
};
}
addBannerAlert = () => {
this.setState(prevState => ({
bannerAlertCount: prevState.bannerAlertCount + 1,
}));
};
render() {
return (
<View>
<BpkButton
title="Add banner alert!"
onPress={this.addBannerAlert}
style={styles.button}
/>
<View>
{[...Array(this.state.bannerAlertCount)].map((e, i) => (
<DismissableBannerAlert
key={i.toString()}
bannerStyle={this.props.bannerStyle}
message={this.props.message}
type={this.props.type}
animateOnEnter
dismissable
dismissButtonLabel={this.props.dismissButtonLabel}
/>
))}
</View>
</View>
);
}
}
storiesOf('react-native-bpk-component-banner-alert', module)
.addDecorator(CenterDecorator)
.add('docs:default', () => (
<View>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert."
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.success}
message="Successful alert."
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.warn}
message="Warn alert."
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.error}
message="Error alert."
/>
</View>
))
.add('docs:dismissable', () => (
<View>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert with dismiss option."
dismissButtonLabel="Dismiss"
/>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert with dismiss option and long description with emoji 😀."
dismissButtonLabel="Dismiss"
/>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.success}
message="Successful alert with dismiss option."
dismissButtonLabel="Dismiss"
/>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.warn}
message="Warn alert with dismiss option."
dismissButtonLabel="Dismiss"
/>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.error}
message="Error alert with dismiss option."
dismissButtonLabel="Dismiss"
/>
</View>
))
.add('docs:expandable', () => (
<View>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert with more information."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert with more information and long message with emoji 😀."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.success}
message="Successful alert with more information."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.warn}
message="Warn alert with more information."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.error}
message="Error alert with more information."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
</View>
))
.add('Banner alerts', () => (
<View>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message="Neutral alert."
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.success}
message="Successful alert."
/>
<DismissableBannerAlert
bannerStyle={styles.bannerAlert}
type={ALERT_TYPES.warn}
message="Warn alert with dismiss option."
dismissButtonLabel="Dismiss"
/>
<ExpandableBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.error}
message="Error alert with more information."
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</ExpandableBannerAlert>
</View>
))
.add('Fade-in', () => (
<BpkBannerAlertFadeDemo
bannerStyle={styles.bannerAlert}
message="Banner alert with dismiss option"
dismissButtonLabel="Dismiss"
type={ALERT_TYPES.success}
/>
))
.add('Edge-cases', () => {
// eslint-disable-next-line max-len
const message =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sagittis sagittis purus, id blandit ipsum.';
return (
<View>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.neutral}
message={message}
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.success}
message={message}
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.warn}
message={message}
dismissButtonLabel="Dismiss"
dismissable
onDismiss={() => null}
/>
<BpkBannerAlert
style={styles.bannerAlert}
type={ALERT_TYPES.error}
message={message}
toggleExpandedButtonLabel="Collapse"
expanded
onToggleExpanded={() => null}
>
<BpkText textStyle="sm" style={styles.child}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
sagittis sagittis purus, id blandit ipsum. Pellentesque nec diam nec
erat condimentum dapibus. Nunc diam augue, egestas id egestas ut,
facilisis nec mi. Donec et congue odio, nec laoreet est. Integer
rhoncus varius arcu, a fringilla libero laoreet at.
</BpkText>
</BpkBannerAlert>
</View>
);
});