@hero-design/rn 8.22.0 → 8.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.turbo/turbo-build.log +9 -9
  2. package/es/index.js +235 -65
  3. package/lib/index.js +235 -64
  4. package/package.json +5 -5
  5. package/src/components/Alert/index.tsx +6 -0
  6. package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
  7. package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +5 -5
  8. package/src/components/List/ListItem.tsx +12 -8
  9. package/src/components/Success/StyledSuccess.tsx +87 -0
  10. package/src/components/Success/__tests__/__snapshots__/index.spec.tsx.snap +497 -0
  11. package/src/components/Success/__tests__/index.spec.tsx +78 -0
  12. package/src/components/Success/index.tsx +129 -0
  13. package/src/components/Tag/StyledTag.tsx +1 -1
  14. package/src/components/Tag/__tests__/Tag.spec.tsx +22 -71
  15. package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +106 -53
  16. package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +265 -0
  17. package/src/components/TextInput/__tests__/index.spec.tsx +29 -0
  18. package/src/components/TextInput/index.tsx +6 -1
  19. package/src/index.ts +2 -0
  20. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +33 -3
  21. package/src/theme/components/empty.ts +1 -1
  22. package/src/theme/components/error.ts +1 -1
  23. package/src/theme/components/success.ts +40 -0
  24. package/src/theme/components/tag.ts +1 -1
  25. package/src/theme/getTheme.ts +3 -0
  26. package/src/utils/hooks.ts +1 -1
  27. package/types/components/Success/StyledSuccess.d.ts +54 -0
  28. package/types/components/Success/index.d.ts +42 -0
  29. package/types/components/TextInput/index.d.ts +5 -1
  30. package/types/index.d.ts +2 -1
  31. package/types/theme/components/success.d.ts +32 -0
  32. package/types/theme/getTheme.d.ts +2 -0
@@ -0,0 +1,497 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Success renders full screen success page correctly 1`] = `
4
+ <Modal
5
+ animationType="slide"
6
+ hardwareAccelerated={false}
7
+ style={
8
+ Array [
9
+ Object {
10
+ "height": "100%",
11
+ "width": "100%",
12
+ },
13
+ undefined,
14
+ ]
15
+ }
16
+ visible={true}
17
+ >
18
+ <View
19
+ style={
20
+ Array [
21
+ Object {
22
+ "backgroundColor": "#ccd2d3",
23
+ "display": "flex",
24
+ "flex": 1,
25
+ "flexDirection": "column",
26
+ },
27
+ undefined,
28
+ ]
29
+ }
30
+ themeVariant="full-screen"
31
+ >
32
+ <View
33
+ style={
34
+ Array [
35
+ Object {
36
+ "alignItems": "center",
37
+ "display": "flex",
38
+ "flex": 1,
39
+ "flexDirection": "column",
40
+ "justifyContent": "center",
41
+ "padding": 24,
42
+ },
43
+ undefined,
44
+ ]
45
+ }
46
+ >
47
+ <View
48
+ style={
49
+ Array [
50
+ Object {
51
+ "height": 176,
52
+ "marginBottom": 32,
53
+ "width": 176,
54
+ },
55
+ undefined,
56
+ ]
57
+ }
58
+ >
59
+ <Image
60
+ source={
61
+ Object {
62
+ "uri": "path_to_image",
63
+ }
64
+ }
65
+ style={
66
+ Array [
67
+ Object {
68
+ "borderRadius": 0,
69
+ "height": 72,
70
+ "width": 72,
71
+ },
72
+ Array [
73
+ Object {
74
+ "height": 176,
75
+ "marginBottom": 32,
76
+ "resizeMode": "contain",
77
+ "width": 176,
78
+ },
79
+ undefined,
80
+ ],
81
+ ]
82
+ }
83
+ testID="success-image"
84
+ />
85
+ </View>
86
+ <Text
87
+ allowFontScaling={false}
88
+ style={
89
+ Array [
90
+ Object {
91
+ "color": "#001f23",
92
+ "fontFamily": "BeVietnamPro-Regular",
93
+ "fontSize": 14,
94
+ "letterSpacing": 0.42,
95
+ "lineHeight": 22,
96
+ },
97
+ Array [
98
+ Object {
99
+ "color": "#001f23",
100
+ "fontFamily": "RebondGrotesque-SemiBold",
101
+ "fontSize": 24,
102
+ "marginBottom": 8,
103
+ "textAlign": "center",
104
+ },
105
+ undefined,
106
+ ],
107
+ ]
108
+ }
109
+ themeFontSize="medium"
110
+ themeFontWeight="regular"
111
+ themeIntent="body"
112
+ themeTypeface="neutral"
113
+ >
114
+ We’re sorry, something went wrong
115
+ </Text>
116
+ <Text
117
+ allowFontScaling={false}
118
+ style={
119
+ Array [
120
+ Object {
121
+ "color": "#001f23",
122
+ "fontFamily": "BeVietnamPro-Regular",
123
+ "fontSize": 14,
124
+ "letterSpacing": 0.42,
125
+ "lineHeight": 22,
126
+ },
127
+ Array [
128
+ Object {
129
+ "color": "#4d6265",
130
+ "fontFamily": "RebondGrotesque",
131
+ "fontSize": 18,
132
+ "textAlign": "center",
133
+ },
134
+ undefined,
135
+ ],
136
+ ]
137
+ }
138
+ themeFontSize="medium"
139
+ themeFontWeight="regular"
140
+ themeIntent="body"
141
+ themeTypeface="neutral"
142
+ >
143
+ Please try again later
144
+ </Text>
145
+ </View>
146
+ </View>
147
+ </Modal>
148
+ `;
149
+
150
+ exports[`Success renders succe screen with custom image element correctly 1`] = `
151
+ <View
152
+ style={
153
+ Array [
154
+ Object {
155
+ "backgroundColor": "#f6f6f7",
156
+ "display": "flex",
157
+ "flex": 1,
158
+ "flexDirection": "column",
159
+ },
160
+ undefined,
161
+ ]
162
+ }
163
+ themeVariant="in-page"
164
+ >
165
+ <View
166
+ style={
167
+ Array [
168
+ Object {
169
+ "alignItems": "center",
170
+ "display": "flex",
171
+ "flex": 1,
172
+ "flexDirection": "column",
173
+ "justifyContent": "center",
174
+ "padding": 24,
175
+ },
176
+ undefined,
177
+ ]
178
+ }
179
+ >
180
+ <View
181
+ style={
182
+ Array [
183
+ Object {
184
+ "height": 176,
185
+ "marginBottom": 32,
186
+ "width": 176,
187
+ },
188
+ undefined,
189
+ ]
190
+ }
191
+ >
192
+ <Image
193
+ source={
194
+ Object {
195
+ "uri": "path_to_image",
196
+ }
197
+ }
198
+ style={
199
+ Array [
200
+ Object {
201
+ "borderRadius": 0,
202
+ "height": 72,
203
+ "width": 72,
204
+ },
205
+ undefined,
206
+ ]
207
+ }
208
+ testID="success-image"
209
+ />
210
+ </View>
211
+ <Text
212
+ allowFontScaling={false}
213
+ style={
214
+ Array [
215
+ Object {
216
+ "color": "#001f23",
217
+ "fontFamily": "BeVietnamPro-Regular",
218
+ "fontSize": 14,
219
+ "letterSpacing": 0.42,
220
+ "lineHeight": 22,
221
+ },
222
+ Array [
223
+ Object {
224
+ "color": "#001f23",
225
+ "fontFamily": "RebondGrotesque-SemiBold",
226
+ "fontSize": 24,
227
+ "marginBottom": 8,
228
+ "textAlign": "center",
229
+ },
230
+ undefined,
231
+ ],
232
+ ]
233
+ }
234
+ themeFontSize="medium"
235
+ themeFontWeight="regular"
236
+ themeIntent="body"
237
+ themeTypeface="neutral"
238
+ >
239
+ We’re sorry, something went wrong
240
+ </Text>
241
+ <Text
242
+ allowFontScaling={false}
243
+ style={
244
+ Array [
245
+ Object {
246
+ "color": "#001f23",
247
+ "fontFamily": "BeVietnamPro-Regular",
248
+ "fontSize": 14,
249
+ "letterSpacing": 0.42,
250
+ "lineHeight": 22,
251
+ },
252
+ Array [
253
+ Object {
254
+ "color": "#4d6265",
255
+ "fontFamily": "RebondGrotesque",
256
+ "fontSize": 18,
257
+ "textAlign": "center",
258
+ },
259
+ undefined,
260
+ ],
261
+ ]
262
+ }
263
+ themeFontSize="medium"
264
+ themeFontWeight="regular"
265
+ themeIntent="body"
266
+ themeTypeface="neutral"
267
+ >
268
+ Please try again later
269
+ </Text>
270
+ </View>
271
+ </View>
272
+ `;
273
+
274
+ exports[`Success renders success screen with image correctly 1`] = `
275
+ <View
276
+ style={
277
+ Array [
278
+ Object {
279
+ "backgroundColor": "#f6f6f7",
280
+ "display": "flex",
281
+ "flex": 1,
282
+ "flexDirection": "column",
283
+ },
284
+ undefined,
285
+ ]
286
+ }
287
+ themeVariant="in-page"
288
+ >
289
+ <View
290
+ style={
291
+ Array [
292
+ Object {
293
+ "alignItems": "center",
294
+ "display": "flex",
295
+ "flex": 1,
296
+ "flexDirection": "column",
297
+ "justifyContent": "center",
298
+ "padding": 24,
299
+ },
300
+ undefined,
301
+ ]
302
+ }
303
+ >
304
+ <View
305
+ style={
306
+ Array [
307
+ Object {
308
+ "height": 176,
309
+ "marginBottom": 32,
310
+ "width": 176,
311
+ },
312
+ undefined,
313
+ ]
314
+ }
315
+ >
316
+ <Image
317
+ source={
318
+ Object {
319
+ "uri": "path_to_image",
320
+ }
321
+ }
322
+ style={
323
+ Array [
324
+ Object {
325
+ "borderRadius": 0,
326
+ "height": 72,
327
+ "width": 72,
328
+ },
329
+ Array [
330
+ Object {
331
+ "height": 176,
332
+ "marginBottom": 32,
333
+ "resizeMode": "contain",
334
+ "width": 176,
335
+ },
336
+ undefined,
337
+ ],
338
+ ]
339
+ }
340
+ testID="success-image"
341
+ />
342
+ </View>
343
+ <Text
344
+ allowFontScaling={false}
345
+ style={
346
+ Array [
347
+ Object {
348
+ "color": "#001f23",
349
+ "fontFamily": "BeVietnamPro-Regular",
350
+ "fontSize": 14,
351
+ "letterSpacing": 0.42,
352
+ "lineHeight": 22,
353
+ },
354
+ Array [
355
+ Object {
356
+ "color": "#001f23",
357
+ "fontFamily": "RebondGrotesque-SemiBold",
358
+ "fontSize": 24,
359
+ "marginBottom": 8,
360
+ "textAlign": "center",
361
+ },
362
+ undefined,
363
+ ],
364
+ ]
365
+ }
366
+ themeFontSize="medium"
367
+ themeFontWeight="regular"
368
+ themeIntent="body"
369
+ themeTypeface="neutral"
370
+ >
371
+ We’re sorry, something went wrong
372
+ </Text>
373
+ <Text
374
+ allowFontScaling={false}
375
+ style={
376
+ Array [
377
+ Object {
378
+ "color": "#001f23",
379
+ "fontFamily": "BeVietnamPro-Regular",
380
+ "fontSize": 14,
381
+ "letterSpacing": 0.42,
382
+ "lineHeight": 22,
383
+ },
384
+ Array [
385
+ Object {
386
+ "color": "#4d6265",
387
+ "fontFamily": "RebondGrotesque",
388
+ "fontSize": 18,
389
+ "textAlign": "center",
390
+ },
391
+ undefined,
392
+ ],
393
+ ]
394
+ }
395
+ themeFontSize="medium"
396
+ themeFontWeight="regular"
397
+ themeIntent="body"
398
+ themeTypeface="neutral"
399
+ >
400
+ Please try again later
401
+ </Text>
402
+ </View>
403
+ </View>
404
+ `;
405
+
406
+ exports[`Success renders title only correctly 1`] = `
407
+ <View
408
+ style={
409
+ Array [
410
+ Object {
411
+ "backgroundColor": "#f6f6f7",
412
+ "display": "flex",
413
+ "flex": 1,
414
+ "flexDirection": "column",
415
+ },
416
+ undefined,
417
+ ]
418
+ }
419
+ themeVariant="in-page"
420
+ >
421
+ <View
422
+ style={
423
+ Array [
424
+ Object {
425
+ "alignItems": "center",
426
+ "display": "flex",
427
+ "flex": 1,
428
+ "flexDirection": "column",
429
+ "justifyContent": "center",
430
+ "padding": 24,
431
+ },
432
+ undefined,
433
+ ]
434
+ }
435
+ >
436
+ <Text
437
+ allowFontScaling={false}
438
+ style={
439
+ Array [
440
+ Object {
441
+ "color": "#001f23",
442
+ "fontFamily": "BeVietnamPro-Regular",
443
+ "fontSize": 14,
444
+ "letterSpacing": 0.42,
445
+ "lineHeight": 22,
446
+ },
447
+ Array [
448
+ Object {
449
+ "color": "#001f23",
450
+ "fontFamily": "RebondGrotesque-SemiBold",
451
+ "fontSize": 24,
452
+ "marginBottom": 8,
453
+ "textAlign": "center",
454
+ },
455
+ undefined,
456
+ ],
457
+ ]
458
+ }
459
+ themeFontSize="medium"
460
+ themeFontWeight="regular"
461
+ themeIntent="body"
462
+ themeTypeface="neutral"
463
+ >
464
+ We’re sorry, something went wrong
465
+ </Text>
466
+ <Text
467
+ allowFontScaling={false}
468
+ style={
469
+ Array [
470
+ Object {
471
+ "color": "#001f23",
472
+ "fontFamily": "BeVietnamPro-Regular",
473
+ "fontSize": 14,
474
+ "letterSpacing": 0.42,
475
+ "lineHeight": 22,
476
+ },
477
+ Array [
478
+ Object {
479
+ "color": "#4d6265",
480
+ "fontFamily": "RebondGrotesque",
481
+ "fontSize": 18,
482
+ "textAlign": "center",
483
+ },
484
+ undefined,
485
+ ],
486
+ ]
487
+ }
488
+ themeFontSize="medium"
489
+ themeFontWeight="regular"
490
+ themeIntent="body"
491
+ themeTypeface="neutral"
492
+ >
493
+ Please try again later
494
+ </Text>
495
+ </View>
496
+ </View>
497
+ `;
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import { fireEvent } from '@testing-library/react-native';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import Success from '..';
5
+ import Image from '../../Image';
6
+
7
+ const title = `We’re sorry, something went wrong`;
8
+ const description = 'Please try again later';
9
+
10
+ describe('Success', () => {
11
+ it('renders title only correctly', () => {
12
+ const { toJSON, getByText } = renderWithTheme(
13
+ <Success title={title} description={description} />
14
+ );
15
+
16
+ expect(getByText(title)).toBeTruthy();
17
+ expect(getByText(description)).toBeTruthy();
18
+ expect(toJSON()).toMatchSnapshot();
19
+ });
20
+ it('renders success screen with image correctly', () => {
21
+ const { toJSON, getByText, getByTestId } = renderWithTheme(
22
+ <Success title={title} description={description} image="path_to_image" />
23
+ );
24
+
25
+ expect(getByText(title)).toBeTruthy();
26
+ expect(getByText(description)).toBeTruthy();
27
+ expect(getByTestId('success-image')).toBeTruthy();
28
+ expect(toJSON()).toMatchSnapshot();
29
+ });
30
+ it('renders succe screen with custom image element correctly', () => {
31
+ const image = (
32
+ <Image
33
+ source={{
34
+ uri: 'path_to_image',
35
+ }}
36
+ />
37
+ );
38
+ const { toJSON, getByText, getByTestId } = renderWithTheme(
39
+ <Success title={title} description={description} image={image} />
40
+ );
41
+
42
+ expect(getByText(title)).toBeTruthy();
43
+ expect(getByText(description)).toBeTruthy();
44
+ expect(getByTestId('success-image')).toBeTruthy();
45
+ expect(toJSON()).toMatchSnapshot();
46
+ });
47
+ it('renders full screen success page correctly', () => {
48
+ const { toJSON, getByText, getByTestId } = renderWithTheme(
49
+ <Success
50
+ variant="full-screen"
51
+ title={title}
52
+ description={description}
53
+ image="path_to_image"
54
+ />
55
+ );
56
+
57
+ expect(getByText(title)).toBeTruthy();
58
+ expect(getByText(description)).toBeTruthy();
59
+ expect(getByTestId('success-image')).toBeTruthy();
60
+ expect(toJSON()).toMatchSnapshot();
61
+ });
62
+ it('handles CTA press correctly', () => {
63
+ const onCtaPress = jest.fn();
64
+ const { getByText } = renderWithTheme(
65
+ <Success
66
+ title={title}
67
+ description={description}
68
+ image="path_to_image"
69
+ ctaText="CTA Text"
70
+ onCtaPress={onCtaPress}
71
+ />
72
+ );
73
+
74
+ const CTA = getByText('CTA Text');
75
+ fireEvent.press(CTA);
76
+ expect(onCtaPress).toBeCalledTimes(1);
77
+ });
78
+ });
@@ -0,0 +1,129 @@
1
+ import React, { ReactElement, isValidElement } from 'react';
2
+ import type {
3
+ ViewProps,
4
+ ImageSourcePropType,
5
+ ImageProps as RNImageProps,
6
+ } from 'react-native';
7
+ import {
8
+ SuccessVariant,
9
+ StyledSuccessImage,
10
+ StyledSuccessContainer,
11
+ StyledSuccessContent,
12
+ StyledSuccessImageContainer,
13
+ StyledSuccessTitle,
14
+ StyledSuccessDescription,
15
+ StyledSuccessButtonContainer,
16
+ StyledSuccessButtonPrimary,
17
+ StyledSuccessModal,
18
+ } from './StyledSuccess';
19
+ import { ImageProps } from '../Image';
20
+ import { noop } from '../../utils/functions';
21
+
22
+ export interface SuccessProps extends ViewProps {
23
+ /**
24
+ * Image to be displayed.
25
+ */
26
+ image?:
27
+ | ReactElement<ImageProps | RNImageProps>
28
+ | ImageSourcePropType
29
+ | string;
30
+ /**
31
+ * Success's title.
32
+ */
33
+ title: string;
34
+ /**
35
+ * Success's description.
36
+ */
37
+ description?: string;
38
+ /**
39
+ * Success's variant.
40
+ */
41
+ variant?: SuccessVariant;
42
+ /**
43
+ * Action button text
44
+ */
45
+ ctaText?: string;
46
+ /**
47
+ * Callback when the action button is pressed.
48
+ */
49
+ onCtaPress?: () => void;
50
+ /**
51
+ * Testing id of the component.
52
+ */
53
+ testID?: string;
54
+ }
55
+
56
+ const renderImage = (
57
+ image: ReactElement<ImageProps | RNImageProps> | ImageSourcePropType | string
58
+ ) => {
59
+ if (isValidElement(image)) {
60
+ return React.cloneElement(image, {
61
+ testID: 'success-image',
62
+ });
63
+ }
64
+
65
+ return (
66
+ <StyledSuccessImage
67
+ source={typeof image === 'string' ? { uri: image } : image}
68
+ testID="success-image"
69
+ />
70
+ );
71
+ };
72
+
73
+ const SuccessPage = ({
74
+ variant = 'in-page',
75
+ title,
76
+ description,
77
+ image,
78
+ testID,
79
+ ctaText,
80
+ onCtaPress = noop,
81
+ ...nativeProps
82
+ }: SuccessProps): ReactElement => {
83
+ return (
84
+ <StyledSuccessContainer
85
+ testID={testID}
86
+ themeVariant={variant}
87
+ {...nativeProps}
88
+ >
89
+ <StyledSuccessContent>
90
+ {!!image && (
91
+ <StyledSuccessImageContainer>
92
+ {renderImage(image)}
93
+ </StyledSuccessImageContainer>
94
+ )}
95
+ <StyledSuccessTitle>{title}</StyledSuccessTitle>
96
+
97
+ {!!description && (
98
+ <StyledSuccessDescription>{description}</StyledSuccessDescription>
99
+ )}
100
+ </StyledSuccessContent>
101
+
102
+ {!!ctaText && (
103
+ <StyledSuccessButtonContainer>
104
+ <StyledSuccessButtonPrimary text={ctaText} onPress={onCtaPress} />
105
+ </StyledSuccessButtonContainer>
106
+ )}
107
+ </StyledSuccessContainer>
108
+ );
109
+ };
110
+
111
+ /**
112
+ * Renders success page
113
+ *
114
+ * @param {SuccessProps} props
115
+ * @return {*} {ReactElement}
116
+ */
117
+ const Success = (props: SuccessProps): ReactElement => {
118
+ const { variant } = props;
119
+ if (variant === 'full-screen') {
120
+ return (
121
+ <StyledSuccessModal animationType="slide">
122
+ <SuccessPage {...props} />
123
+ </StyledSuccessModal>
124
+ );
125
+ }
126
+
127
+ return <SuccessPage {...props} />;
128
+ };
129
+ export default Success;
@@ -14,7 +14,7 @@ type ThemeIntent =
14
14
  type ThemeVariant = 'filled' | 'outlined';
15
15
 
16
16
  const getFilledStyles = (themeIntent: ThemeIntent, theme: Theme) => ({
17
- textColor: theme.__hd__.tag.colors.text,
17
+ textColor: theme.__hd__.tag.colors[themeIntent],
18
18
  borderColor: theme.__hd__.tag.colors[`${themeIntent}Background`],
19
19
  backgroundColor: theme.__hd__.tag.colors[`${themeIntent}Background`],
20
20
  });