@hero-design/rn 8.40.3 → 8.41.1

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 (39) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/assets/fonts/hero-icons-mobile.ttf +0 -0
  3. package/es/index.js +613 -709
  4. package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
  5. package/lib/index.js +615 -713
  6. package/package.json +7 -8
  7. package/rollup.config.js +0 -1
  8. package/src/components/Error/StyledError.tsx +2 -1
  9. package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +115 -97
  10. package/src/components/Error/__tests__/index.spec.tsx +9 -6
  11. package/src/components/Icon/HeroIcon/glyphMap.json +1 -1
  12. package/src/components/Icon/IconList.ts +1 -0
  13. package/src/components/Modal/__tests__/__snapshots__/index.spec.tsx.snap +117 -0
  14. package/src/components/Modal/__tests__/index.spec.tsx +99 -0
  15. package/src/components/Modal/index.tsx +178 -82
  16. package/src/components/Portal/__tests__/__snapshots__/index.spec.tsx.snap +29 -0
  17. package/src/components/Portal/__tests__/index.spec.tsx +19 -0
  18. package/src/components/Portal/index.tsx +18 -5
  19. package/src/components/Success/StyledSuccess.tsx +2 -1
  20. package/src/components/Success/__tests__/__snapshots__/index.spec.tsx.snap +115 -95
  21. package/src/components/Success/__tests__/index.spec.tsx +9 -6
  22. package/src/index.ts +0 -2
  23. package/testUtils/setup.tsx +0 -18
  24. package/types/components/Error/StyledError.d.ts +3 -5
  25. package/types/components/Icon/IconList.d.ts +1 -1
  26. package/types/components/Icon/index.d.ts +1 -1
  27. package/types/components/Icon/utils.d.ts +1 -1
  28. package/types/components/Modal/index.d.ts +12 -8
  29. package/types/components/Portal/index.d.ts +10 -5
  30. package/types/components/Success/StyledSuccess.d.ts +3 -5
  31. package/types/index.d.ts +1 -2
  32. package/src/components/Modal/ModalContentWrapper.tsx +0 -112
  33. package/src/components/Modal/ModalPresenter/ModalPresenter.tsx +0 -135
  34. package/src/components/Modal/ModalPresenter/index.tsx +0 -9
  35. package/src/components/Modal/ModalProvider.tsx +0 -8
  36. package/types/components/Modal/ModalContentWrapper.d.ts +0 -16
  37. package/types/components/Modal/ModalPresenter/ModalPresenter.d.ts +0 -34
  38. package/types/components/Modal/ModalPresenter/index.d.ts +0 -3
  39. package/types/components/Modal/ModalProvider.d.ts +0 -5
@@ -1,21 +1,41 @@
1
- import React from 'react';
2
- import { BackHandler, Dimensions, View, ViewStyle } from 'react-native';
3
- import ModalContentWrapper, {
4
- ModalContentWrapperHandler,
5
- } from './ModalContentWrapper';
6
- import ModalProvider from './ModalProvider';
7
- import { ModalHandler, showModal } from './ModalPresenter';
8
-
9
- const wrapperStyle: ViewStyle = {
10
- width: Dimensions.get('window').width,
11
- height: Dimensions.get('window').height,
1
+ import React, {
2
+ ReactNode,
3
+ forwardRef,
4
+ useEffect,
5
+ useImperativeHandle,
6
+ useRef,
7
+ useState,
8
+ useCallback,
9
+ } from 'react';
10
+ import {
11
+ Animated,
12
+ BackHandler,
13
+ Dimensions,
14
+ Easing,
15
+ Platform,
16
+ StyleSheet,
17
+ } from 'react-native';
18
+ import { useTheme } from '../../theme';
19
+ import Portal from '../Portal';
20
+
21
+ type ModalHandles = {
22
+ show: () => void;
23
+ hide: (callback: () => void) => void;
24
+ };
25
+
26
+ const DEFAULT_BACKDROP_OPACITY = 0.4;
27
+
28
+ const DEFAULT_ANIMATION_CONFIG = {
29
+ easing: Easing.inOut(Easing.cubic),
30
+ useNativeDriver: Platform.OS !== 'web',
31
+ duration: 400,
12
32
  };
13
33
 
14
34
  export interface ModalProps {
15
35
  /**
16
36
  * Content of the modal.
17
37
  */
18
- children: React.ReactElement;
38
+ children: ReactNode;
19
39
  /**
20
40
  * Visibility of the modal
21
41
  */
@@ -36,86 +56,162 @@ export interface ModalProps {
36
56
  * Animation type of the modal content.
37
57
  */
38
58
  animationType?: 'none' | 'slide' | 'fade';
59
+ /**
60
+ * Whether to show the modal backdrop
61
+ */
62
+ transparent?: boolean;
63
+ /**
64
+ * Callback when the modal is dismissed. iOS only.
65
+ */
66
+ onDismiss?: () => void;
39
67
  }
40
68
 
41
- const Modal = ({
42
- children,
43
- onShow,
44
- onRequestClose,
45
- testID,
46
- visible = true,
47
- animationType = 'none',
48
- }: ModalProps) => {
49
- const [modalHandler, setModalHandler] = React.useState<ModalHandler>();
50
- const modalContentWrapperRef = React.useRef<ModalContentWrapperHandler>(null);
51
-
52
- const getModalContent = React.useCallback(
53
- (isUpdate = false) => {
54
- return animationType === 'none' ? (
55
- <View style={wrapperStyle} testID={testID}>
56
- {children}
57
- </View>
58
- ) : (
59
- <ModalContentWrapper
60
- visible={visible}
61
- style={wrapperStyle}
62
- animationType={animationType}
69
+ const Modal = forwardRef<ModalHandles, Omit<ModalProps, 'visible'>>(
70
+ (
71
+ {
72
+ children,
73
+ onShow,
74
+ onRequestClose,
75
+ testID,
76
+ animationType = 'none',
77
+ transparent = false,
78
+ onDismiss,
79
+ },
80
+ ref
81
+ ) => {
82
+ const theme = useTheme();
83
+ const animatedBackdropValue = useRef(new Animated.Value(0)).current;
84
+ const animatedModalValue = useRef(new Animated.Value(0)).current;
85
+
86
+ // Show or hide the backdrop and modal content
87
+ const animateBackdropAndContent = useCallback(
88
+ ({ toValue, callback }: { toValue: number; callback?: () => void }) => {
89
+ if (animationType !== 'none') {
90
+ // Backdrop animation
91
+ if (!transparent) {
92
+ Animated.timing(animatedBackdropValue, {
93
+ toValue,
94
+ ...DEFAULT_ANIMATION_CONFIG,
95
+ }).start();
96
+ }
97
+
98
+ // Modal content animation
99
+ Animated.timing(animatedModalValue, {
100
+ toValue,
101
+ ...DEFAULT_ANIMATION_CONFIG,
102
+ }).start(callback);
103
+ } else {
104
+ callback?.();
105
+ }
106
+ },
107
+ [animationType, onShow, transparent]
108
+ );
109
+
110
+ const backdropOpacityAnimation = animatedBackdropValue.interpolate({
111
+ inputRange: [0, 1],
112
+ outputRange: [0, DEFAULT_BACKDROP_OPACITY],
113
+ });
114
+
115
+ const modalAnimation = animatedModalValue.interpolate({
116
+ inputRange: [0, 1],
117
+ outputRange:
118
+ animationType === 'slide'
119
+ ? [Dimensions.get('window').height, 0]
120
+ : [0, 1],
121
+ });
122
+
123
+ useImperativeHandle(
124
+ ref,
125
+ () => {
126
+ return {
127
+ show: () => {
128
+ animateBackdropAndContent({ toValue: 1, callback: onShow });
129
+ },
130
+
131
+ hide: (wrapperCallback) => {
132
+ animateBackdropAndContent({
133
+ toValue: 0,
134
+ callback: () => {
135
+ if (Platform.OS === 'ios') {
136
+ onDismiss?.();
137
+ }
138
+
139
+ wrapperCallback();
140
+ },
141
+ });
142
+ },
143
+ };
144
+ },
145
+ [onDismiss, onShow, animateBackdropAndContent]
146
+ );
147
+
148
+ // Back button handler
149
+ useEffect(() => {
150
+ const backHandler = BackHandler.addEventListener(
151
+ 'hardwareBackPress',
152
+ () => {
153
+ onRequestClose?.();
154
+ return true;
155
+ }
156
+ );
157
+
158
+ return () => backHandler.remove();
159
+ }, [onRequestClose]);
160
+
161
+ return (
162
+ <Portal>
163
+ <Animated.View
164
+ style={{
165
+ ...StyleSheet.absoluteFillObject,
166
+ backgroundColor: transparent
167
+ ? 'transparent'
168
+ : theme.colors.overlayGlobalSurface,
169
+ opacity:
170
+ animationType !== 'none'
171
+ ? backdropOpacityAnimation
172
+ : DEFAULT_BACKDROP_OPACITY,
173
+ }}
174
+ />
175
+
176
+ <Animated.View
63
177
  testID={testID}
64
- onShow={onShow}
65
- ref={modalContentWrapperRef}
66
- animated={!isUpdate}
178
+ style={{
179
+ ...StyleSheet.absoluteFillObject,
180
+ opacity: animationType === 'fade' ? modalAnimation : 1,
181
+ transform: [
182
+ {
183
+ translateY: animationType === 'slide' ? modalAnimation : 0,
184
+ },
185
+ ],
186
+ }}
67
187
  >
68
188
  {children}
69
- </ModalContentWrapper>
70
- );
71
- },
72
- [visible, children, onShow, testID, animationType]
73
- );
189
+ </Animated.View>
190
+ </Portal>
191
+ );
192
+ }
193
+ );
74
194
 
75
- React.useEffect(() => {
195
+ const ModalWrapper = ({ visible = true, ...props }: ModalProps) => {
196
+ const modalRef = useRef<ModalHandles>(null);
197
+ const [internalVisible, setInternalVisible] = useState(visible);
198
+
199
+ useEffect(() => {
76
200
  if (visible) {
77
- // Modal does not exist, create a new one
78
- if (!modalHandler) {
79
- const newModalHandler = showModal(getModalContent(false));
80
- setModalHandler(newModalHandler);
81
-
82
- // If animationType is slide for fade, onShow would be run after animation on ModalContentWrapper,
83
- // else run on this component.
84
- if (animationType === 'none') {
85
- onShow?.();
86
- }
87
- }
88
- // Modal already exists, update it
89
- else {
90
- modalHandler.update(getModalContent(true));
91
- }
92
- } else if (animationType === 'none') {
93
- modalHandler?.dismiss();
94
- setModalHandler(undefined);
201
+ setInternalVisible(true);
95
202
  } else {
96
- // Wait to finish animation before dismissing
97
- modalContentWrapperRef.current?.hide(() => {
98
- modalHandler?.dismiss();
99
- setModalHandler(undefined);
100
- });
203
+ // Wait for animation to finish before hiding the modal
204
+ modalRef.current?.hide(() => setInternalVisible(false));
101
205
  }
102
- }, [getModalContent]);
206
+ }, [visible]);
103
207
 
104
- React.useEffect(() => {
105
- const backHandler = BackHandler.addEventListener(
106
- 'hardwareBackPress',
107
- () => {
108
- onRequestClose?.();
109
- return true;
110
- }
111
- );
112
-
113
- return () => backHandler.remove();
114
- }, [onRequestClose]);
208
+ useEffect(() => {
209
+ if (internalVisible) {
210
+ modalRef.current?.show();
211
+ }
212
+ }, [internalVisible]);
115
213
 
116
- return null;
214
+ return internalVisible ? <Modal ref={modalRef} {...props} /> : null;
117
215
  };
118
216
 
119
- export default Object.assign(Modal, {
120
- Provider: ModalProvider,
121
- });
217
+ export default ModalWrapper;
@@ -0,0 +1,29 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Portal allows rendering children with custom theme 1`] = `
4
+ <View
5
+ testID="portal-wrapper"
6
+ >
7
+ <Text
8
+ allowFontScaling={false}
9
+ style={
10
+ [
11
+ {
12
+ "color": "#001f23",
13
+ "fontFamily": "BeVietnamPro-Regular",
14
+ "fontSize": 16,
15
+ "letterSpacing": 0.48,
16
+ "lineHeight": 24,
17
+ },
18
+ undefined,
19
+ ]
20
+ }
21
+ themeIntent="body"
22
+ themeTypeface="neutral"
23
+ themeVariant="regular"
24
+ >
25
+ portal
26
+ </Text>
27
+ ;
28
+ </View>
29
+ `;
@@ -6,6 +6,8 @@ import { PortalHost } from '../PortalHost';
6
6
  import { PortalProvider } from '../PortalProvider';
7
7
  import Typography from '../../Typography';
8
8
  import Portal from '..';
9
+ import { getTheme } from '../../../theme';
10
+ import { defaultScale, walletSystemPalette } from '../../../theme/global';
9
11
 
10
12
  describe('Portal', () => {
11
13
  it('should render Typography inside Portal.Host', async () => {
@@ -26,4 +28,21 @@ describe('Portal', () => {
26
28
  ).toBeDefined()
27
29
  );
28
30
  });
31
+
32
+ it('allows rendering children with custom theme', () => {
33
+ const customTheme = getTheme(defaultScale, walletSystemPalette);
34
+
35
+ const wrapper = renderWithTheme(
36
+ <PortalProvider>
37
+ <View testID="portal-wrapper">
38
+ <PortalHost name="host" />
39
+ </View>
40
+ <Portal theme={customTheme} hostName="host">
41
+ <Typography.Body>portal</Typography.Body>;
42
+ </Portal>
43
+ </PortalProvider>
44
+ );
45
+
46
+ expect(wrapper.toJSON()).toMatchSnapshot();
47
+ });
29
48
  });
@@ -1,10 +1,11 @@
1
- import { ReactNode, memo, useLayoutEffect, useMemo } from 'react';
1
+ import React, { ReactNode, memo, useLayoutEffect, useMemo } from 'react';
2
2
  // Fix issue no crypto in react-native
3
3
  // https://stackoverflow.com/a/66852908
4
4
  import { customAlphabet } from 'nanoid/non-secure';
5
5
  import { usePortal } from './usePortal';
6
6
  import { PortalProvider } from './PortalProvider';
7
7
  import { PortalHost } from './PortalHost';
8
+ import { Theme, ThemeProvider, useTheme } from '../../theme';
8
9
 
9
10
  const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
10
11
 
@@ -23,23 +24,35 @@ export interface PortalProps {
23
24
  * Content of the portal.
24
25
  */
25
26
  children?: ReactNode | ReactNode[];
27
+ /**
28
+ * Theme for portal children.
29
+ */
30
+ theme?: Theme;
26
31
  }
27
32
 
28
- const PortalComponent = ({ name, hostName, children }: PortalProps) => {
33
+ const PortalComponent = ({ name, hostName, children, theme }: PortalProps) => {
34
+ const defaultTheme = useTheme();
29
35
  const { addPortal: addUpdatePortal, removePortal } = usePortal(hostName);
30
36
 
31
37
  const nameOrRandom = useMemo(() => name || nanoid(), [name]);
32
38
 
39
+ const ChildrenComponent = useMemo(
40
+ () => (
41
+ <ThemeProvider theme={theme || defaultTheme}>{children}</ThemeProvider>
42
+ ),
43
+ [theme, children, defaultTheme]
44
+ );
45
+
33
46
  useLayoutEffect(() => {
34
- addUpdatePortal(nameOrRandom, children);
47
+ addUpdatePortal(nameOrRandom, ChildrenComponent);
35
48
  return () => {
36
49
  removePortal(nameOrRandom);
37
50
  };
38
51
  }, [addUpdatePortal]);
39
52
 
40
53
  useLayoutEffect(() => {
41
- addUpdatePortal(nameOrRandom, children);
42
- }, [children]);
54
+ addUpdatePortal(nameOrRandom, ChildrenComponent);
55
+ }, [ChildrenComponent]);
43
56
 
44
57
  return null;
45
58
  };
@@ -1,8 +1,9 @@
1
1
  import styled from '@emotion/native';
2
- import { Modal, View } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import Image from '../Image';
4
4
  import Typography from '../Typography';
5
5
  import Button from '../Button';
6
+ import Modal from '../Modal';
6
7
 
7
8
  type SuccessVariant = 'full-screen' | 'in-page';
8
9
 
@@ -1,144 +1,164 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`Success renders full screen success page correctly 1`] = `
4
- <Modal
5
- animationType="slide"
6
- hardwareAccelerated={false}
7
- style={
8
- [
4
+ [
5
+ <View
6
+ collapsable={false}
7
+ style={
9
8
  {
10
- "height": "100%",
11
- "width": "100%",
12
- },
13
- undefined,
14
- ]
15
- }
16
- visible={true}
17
- >
9
+ "backgroundColor": "#000000",
10
+ "bottom": 0,
11
+ "left": 0,
12
+ "opacity": 0,
13
+ "position": "absolute",
14
+ "right": 0,
15
+ "top": 0,
16
+ }
17
+ }
18
+ />,
18
19
  <View
20
+ collapsable={false}
19
21
  style={
20
- [
21
- {
22
- "backgroundColor": "#ccd2d3",
23
- "display": "flex",
24
- "flex": 1,
25
- "flexDirection": "column",
26
- },
27
- undefined,
28
- ]
22
+ {
23
+ "bottom": 0,
24
+ "left": 0,
25
+ "opacity": 1,
26
+ "position": "absolute",
27
+ "right": 0,
28
+ "top": 0,
29
+ "transform": [
30
+ {
31
+ "translateY": 1334,
32
+ },
33
+ ],
34
+ }
29
35
  }
30
- themeVariant="full-screen"
31
36
  >
32
37
  <View
33
38
  style={
34
39
  [
35
40
  {
36
- "alignItems": "center",
41
+ "backgroundColor": "#ccd2d3",
37
42
  "display": "flex",
38
43
  "flex": 1,
39
44
  "flexDirection": "column",
40
- "justifyContent": "center",
41
- "padding": 24,
42
45
  },
43
46
  undefined,
44
47
  ]
45
48
  }
49
+ themeVariant="full-screen"
46
50
  >
47
51
  <View
48
52
  style={
49
53
  [
50
54
  {
51
- "height": 176,
52
- "marginBottom": 32,
53
- "width": 176,
55
+ "alignItems": "center",
56
+ "display": "flex",
57
+ "flex": 1,
58
+ "flexDirection": "column",
59
+ "justifyContent": "center",
60
+ "padding": 24,
54
61
  },
55
62
  undefined,
56
63
  ]
57
64
  }
58
65
  >
59
- <Image
60
- source={
61
- {
62
- "uri": "path_to_image",
63
- }
66
+ <View
67
+ style={
68
+ [
69
+ {
70
+ "height": 176,
71
+ "marginBottom": 32,
72
+ "width": 176,
73
+ },
74
+ undefined,
75
+ ]
64
76
  }
77
+ >
78
+ <Image
79
+ source={
80
+ {
81
+ "uri": "path_to_image",
82
+ }
83
+ }
84
+ style={
85
+ [
86
+ {
87
+ "borderRadius": 0,
88
+ "height": 72,
89
+ "width": 72,
90
+ },
91
+ [
92
+ {
93
+ "height": 176,
94
+ "marginBottom": 32,
95
+ "resizeMode": "contain",
96
+ "width": 176,
97
+ },
98
+ undefined,
99
+ ],
100
+ ]
101
+ }
102
+ testID="success-image"
103
+ />
104
+ </View>
105
+ <Text
106
+ allowFontScaling={false}
65
107
  style={
66
108
  [
67
109
  {
68
- "borderRadius": 0,
69
- "height": 72,
70
- "width": 72,
110
+ "color": "#001f23",
111
+ "fontFamily": "RebondGrotesque-SemiBold",
112
+ "fontSize": 24,
113
+ "letterSpacing": 0.24,
114
+ "lineHeight": 32,
71
115
  },
72
116
  [
73
117
  {
74
- "height": 176,
75
- "marginBottom": 32,
76
- "resizeMode": "contain",
77
- "width": 176,
118
+ "color": "#001f23",
119
+ "marginBottom": 8,
120
+ "textAlign": "center",
78
121
  },
79
122
  undefined,
80
123
  ],
81
124
  ]
82
125
  }
83
- testID="success-image"
84
- />
85
- </View>
86
- <Text
87
- allowFontScaling={false}
88
- style={
89
- [
90
- {
91
- "color": "#001f23",
92
- "fontFamily": "RebondGrotesque-SemiBold",
93
- "fontSize": 24,
94
- "letterSpacing": 0.24,
95
- "lineHeight": 32,
96
- },
126
+ themeIntent="body"
127
+ themeLevel="h4"
128
+ themeTypeface="playful"
129
+ >
130
+ We’re sorry, something went wrong
131
+ </Text>
132
+ <Text
133
+ allowFontScaling={false}
134
+ style={
97
135
  [
98
136
  {
99
137
  "color": "#001f23",
100
- "marginBottom": 8,
101
- "textAlign": "center",
138
+ "fontFamily": "BeVietnamPro-Regular",
139
+ "fontSize": 16,
140
+ "letterSpacing": 0.48,
141
+ "lineHeight": 24,
102
142
  },
103
- undefined,
104
- ],
105
- ]
106
- }
107
- themeIntent="body"
108
- themeLevel="h4"
109
- themeTypeface="playful"
110
- >
111
- We’re sorry, something went wrong
112
- </Text>
113
- <Text
114
- allowFontScaling={false}
115
- style={
116
- [
117
- {
118
- "color": "#001f23",
119
- "fontFamily": "BeVietnamPro-Regular",
120
- "fontSize": 16,
121
- "letterSpacing": 0.48,
122
- "lineHeight": 24,
123
- },
124
- [
125
- {
126
- "color": "#4d6265",
127
- "textAlign": "center",
128
- },
129
- undefined,
130
- ],
131
- ]
132
- }
133
- themeIntent="body"
134
- themeTypeface="neutral"
135
- themeVariant="regular"
136
- >
137
- Please try again later
138
- </Text>
143
+ [
144
+ {
145
+ "color": "#4d6265",
146
+ "textAlign": "center",
147
+ },
148
+ undefined,
149
+ ],
150
+ ]
151
+ }
152
+ themeIntent="body"
153
+ themeTypeface="neutral"
154
+ themeVariant="regular"
155
+ >
156
+ Please try again later
157
+ </Text>
158
+ </View>
139
159
  </View>
140
- </View>
141
- </Modal>
160
+ </View>,
161
+ ]
142
162
  `;
143
163
 
144
164
  exports[`Success renders succe screen with custom image element correctly 1`] = `