@hero-design/rn 8.42.0-alpha.0 → 8.42.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 (36) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/es/index.js +614 -696
  3. package/lib/index.js +616 -700
  4. package/package.json +7 -8
  5. package/rollup.config.js +0 -1
  6. package/src/components/Carousel/__tests__/__snapshots__/CardCarousel.spec.tsx.snap +20 -0
  7. package/src/components/Carousel/__tests__/__snapshots__/StyledCardCarousel.spec.tsx.snap +15 -0
  8. package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +96 -3
  9. package/src/components/Carousel/__tests__/index.spec.tsx +47 -1
  10. package/src/components/Carousel/index.tsx +16 -22
  11. package/src/components/Error/StyledError.tsx +2 -1
  12. package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +115 -97
  13. package/src/components/Error/__tests__/index.spec.tsx +9 -6
  14. package/src/components/Modal/__tests__/__snapshots__/index.spec.tsx.snap +117 -0
  15. package/src/components/Modal/__tests__/index.spec.tsx +99 -0
  16. package/src/components/Modal/index.tsx +178 -82
  17. package/src/components/PageControl/__tests__/__snapshots__/index.spec.tsx.snap +15 -0
  18. package/src/components/PageControl/index.tsx +1 -0
  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/Carousel/index.d.ts +1 -1
  25. package/types/components/Error/StyledError.d.ts +3 -5
  26. package/types/components/Modal/index.d.ts +12 -8
  27. package/types/components/Success/StyledSuccess.d.ts +3 -5
  28. package/types/index.d.ts +1 -2
  29. package/src/components/Modal/ModalContentWrapper.tsx +0 -112
  30. package/src/components/Modal/ModalPresenter/ModalPresenter.tsx +0 -135
  31. package/src/components/Modal/ModalPresenter/index.tsx +0 -9
  32. package/src/components/Modal/ModalProvider.tsx +0 -8
  33. package/types/components/Modal/ModalContentWrapper.d.ts +0 -16
  34. package/types/components/Modal/ModalPresenter/ModalPresenter.d.ts +0 -34
  35. package/types/components/Modal/ModalPresenter/index.d.ts +0 -3
  36. package/types/components/Modal/ModalProvider.d.ts +0 -5
@@ -1,12 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { Modal, View } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  type ErrorVariant = 'full-screen' | 'in-page';
4
- declare const StyledErrorModal: import("@emotion/native").StyledComponent<import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & {
4
+ declare const StyledErrorModal: import("@emotion/native").StyledComponent<import("../Modal").ModalProps & {
5
5
  theme?: import("@emotion/react").Theme | undefined;
6
6
  as?: import("react").ElementType<any> | undefined;
7
- }, {}, {
8
- ref?: import("react").Ref<Modal> | undefined;
9
- }>;
7
+ }, {}, {}>;
10
8
  declare const StyledErrorContainer: import("@emotion/native").StyledComponent<import("react-native").ViewProps & {
11
9
  theme?: import("@emotion/react").Theme | undefined;
12
10
  as?: import("react").ElementType<any> | undefined;
@@ -1,9 +1,9 @@
1
- import React from 'react';
1
+ import { ReactNode } from 'react';
2
2
  export interface ModalProps {
3
3
  /**
4
4
  * Content of the modal.
5
5
  */
6
- children: React.ReactElement;
6
+ children: ReactNode;
7
7
  /**
8
8
  * Visibility of the modal
9
9
  */
@@ -24,10 +24,14 @@ export interface ModalProps {
24
24
  * Animation type of the modal content.
25
25
  */
26
26
  animationType?: 'none' | 'slide' | 'fade';
27
+ /**
28
+ * Whether to show the modal backdrop
29
+ */
30
+ transparent?: boolean;
31
+ /**
32
+ * Callback when the modal is dismissed. iOS only.
33
+ */
34
+ onDismiss?: () => void;
27
35
  }
28
- declare const _default: (({ children, onShow, onRequestClose, testID, visible, animationType, }: ModalProps) => null) & {
29
- Provider: ({ children }: {
30
- children: React.ReactNode;
31
- }) => JSX.Element;
32
- };
33
- export default _default;
36
+ declare const ModalWrapper: ({ visible, ...props }: ModalProps) => JSX.Element | null;
37
+ export default ModalWrapper;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Modal, View } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  type SuccessVariant = 'full-screen' | 'in-page';
4
4
  declare const StyledSuccessContainer: import("@emotion/native").StyledComponent<import("react-native").ViewProps & {
5
5
  theme?: import("@emotion/react").Theme | undefined;
@@ -45,10 +45,8 @@ declare const StyledSuccessButtonPrimary: import("@emotion/native").StyledCompon
45
45
  theme?: import("@emotion/react").Theme | undefined;
46
46
  as?: import("react").ElementType<any> | undefined;
47
47
  }, {}, {}>;
48
- declare const StyledSuccessModal: import("@emotion/native").StyledComponent<import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & {
48
+ declare const StyledSuccessModal: import("@emotion/native").StyledComponent<import("../Modal").ModalProps & {
49
49
  theme?: import("@emotion/react").Theme | undefined;
50
50
  as?: import("react").ElementType<any> | undefined;
51
- }, {}, {
52
- ref?: import("react").Ref<Modal> | undefined;
53
- }>;
51
+ }, {}, {}>;
54
52
  export { SuccessVariant, StyledSuccessImage, StyledSuccessContainer, StyledSuccessContent, StyledSuccessImageContainer, StyledSuccessTitle, StyledSuccessDescription, StyledSuccessButtonContainer, StyledSuccessButtonPrimary, StyledSuccessModal, };
package/types/index.d.ts CHANGED
@@ -25,7 +25,6 @@ import HeroDesignProvider from './components/HeroDesignProvider';
25
25
  import Icon from './components/Icon';
26
26
  import Image from './components/Image';
27
27
  import List from './components/List';
28
- import Modal from './components/Modal';
29
28
  import PinInput from './components/PinInput';
30
29
  import Progress from './components/Progress';
31
30
  import Slider from './components/Slider';
@@ -49,5 +48,5 @@ import RefreshControl from './components/RefreshControl';
49
48
  import RichTextEditor from './components/RichTextEditor';
50
49
  import PageControl from './components/PageControl';
51
50
  import Portal from './components/Portal';
52
- export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, withTheme, swagSystemPalette, swagDarkSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, Error, FAB, Icon, Image, HeroDesignProvider, List, Modal, PinInput, Progress, Portal, PageControl, Skeleton, Slider, Spinner, Swipeable, Radio, SectionHeading, Select, Success, Switch, Tabs, Tag, TextInput, TimePicker, Toast, Toolbar, Typography, Rate, RefreshControl, RichTextEditor, };
51
+ export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, withTheme, swagSystemPalette, swagDarkSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, Error, FAB, Icon, Image, HeroDesignProvider, List, PinInput, Progress, Portal, PageControl, Skeleton, Slider, Spinner, Swipeable, Radio, SectionHeading, Select, Success, Switch, Tabs, Tag, TextInput, TimePicker, Toast, Toolbar, Typography, Rate, RefreshControl, RichTextEditor, };
53
52
  export * from './types';
@@ -1,112 +0,0 @@
1
- import React, { forwardRef } from 'react';
2
- import {
3
- Animated,
4
- Dimensions,
5
- Easing,
6
- Platform,
7
- StyleProp,
8
- ViewStyle,
9
- } from 'react-native';
10
-
11
- type ModalContentWrapperProps = {
12
- children: React.ReactElement;
13
- visible?: boolean;
14
- onShow?: () => void;
15
- testID?: string;
16
- animationType?: 'none' | 'slide' | 'fade';
17
- style?: StyleProp<ViewStyle>;
18
- animated?: boolean;
19
- };
20
-
21
- export type ModalContentWrapperHandler = {
22
- hide: (callback?: () => void) => void;
23
- };
24
-
25
- const windowHeight = Dimensions.get('window').height;
26
- const defaultAnimationConfig = {
27
- easing: Easing.inOut(Easing.cubic),
28
- duration: 400,
29
- useNativeDriver: Platform.OS !== 'web',
30
- };
31
-
32
- const ModalContentWrapper = forwardRef<
33
- ModalContentWrapperHandler,
34
- ModalContentWrapperProps
35
- >(
36
- (
37
- {
38
- animationType,
39
- children,
40
- testID,
41
- onShow,
42
- style,
43
- visible,
44
- animated = true,
45
- },
46
- ref
47
- ) => {
48
- const animatedValue = React.useRef(new Animated.Value(0)).current;
49
-
50
- const modalAnimation = animatedValue.interpolate(
51
- animationType === 'fade'
52
- ? {
53
- inputRange: [0, 1],
54
- outputRange: [0, 1],
55
- }
56
- : {
57
- inputRange: [0, 1],
58
- outputRange: [windowHeight, 0],
59
- }
60
- );
61
-
62
- React.useImperativeHandle(
63
- ref,
64
- () => ({
65
- hide: (callback) => {
66
- Animated.timing(animatedValue, {
67
- toValue: 0,
68
- ...defaultAnimationConfig,
69
- }).start(callback);
70
- },
71
- }),
72
- [animatedValue]
73
- );
74
-
75
- React.useEffect(() => {
76
- // Hiding animation will be called from the modal component
77
- if (visible) {
78
- Animated.timing(animatedValue, {
79
- toValue: 1,
80
- ...defaultAnimationConfig,
81
- // Prevent animation when updating the modal content
82
- duration: animated ? defaultAnimationConfig.duration : 0,
83
- }).start(() => {
84
- onShow?.();
85
- });
86
- }
87
- }, [visible, animatedValue, onShow, animated]);
88
-
89
- return (
90
- <Animated.View
91
- testID={testID}
92
- style={[
93
- style,
94
- {
95
- ...(animationType === 'fade' ? { opacity: modalAnimation } : {}),
96
- ...(animationType === 'slide'
97
- ? {
98
- transform: [{ translateY: modalAnimation }],
99
- }
100
- : {}),
101
- },
102
- ]}
103
- >
104
- {children}
105
- </Animated.View>
106
- );
107
- }
108
- );
109
-
110
- ModalContentWrapper.displayName = 'ModalContentWrapper';
111
-
112
- export default ModalContentWrapper;
@@ -1,135 +0,0 @@
1
- import React, { forwardRef, useRef } from 'react';
2
- import { Animated, StyleSheet, ViewProps } from 'react-native';
3
- import RootSiblings from 'react-native-root-siblings';
4
- import { useTheme } from '../../../theme';
5
- import Box from '../../Box';
6
-
7
- export type ModalPresenterHandles = {
8
- animatedOut: (completion?: () => void) => void;
9
- };
10
- export type ModalDismissFunc = (onDismiss?: () => void) => void;
11
- export type ModalUpdateFunc = (content: React.ReactNode) => void;
12
-
13
- /**
14
- * Modal handler is returned by `showModal` function.
15
- */
16
- export type ModalHandler = {
17
- /**
18
- * Same `dismiss` function as in `ModalContentProps`.
19
- */
20
- dismiss: ModalDismissFunc;
21
- /**
22
- * Same `update` function as in `ModalContentProps`.
23
- */
24
- update: ModalUpdateFunc;
25
- };
26
-
27
- const ModalPresenter = forwardRef<ModalPresenterHandles, ViewProps>(
28
- ({ style, children, ...props }, ref) => {
29
- const animatedOpacity = useRef(new Animated.Value(0));
30
- const theme = useTheme();
31
-
32
- React.useEffect(() => {
33
- Animated.spring(animatedOpacity.current, {
34
- toValue: 1,
35
- useNativeDriver: true,
36
- }).start();
37
- }, []);
38
-
39
- React.useImperativeHandle(ref, () => ({
40
- animatedOut: (completion?: () => void) => {
41
- Animated.spring(animatedOpacity.current, {
42
- toValue: 0,
43
- useNativeDriver: true,
44
- }).start(() => {
45
- completion?.();
46
- });
47
- },
48
- }));
49
-
50
- return (
51
- <Box style={StyleSheet.absoluteFill}>
52
- <Animated.View
53
- style={[
54
- {
55
- width: '100%',
56
- height: '100%',
57
- backgroundColor: `${theme.colors.overlayGlobalSurface}66`, // 66 = 40% opacity as suggested by the mobile color guidelines
58
- justifyContent: 'center',
59
- alignItems: 'center',
60
- opacity: animatedOpacity.current,
61
- },
62
- style,
63
- ]}
64
- {...props}
65
- >
66
- {children}
67
- </Animated.View>
68
- </Box>
69
- );
70
- }
71
- );
72
-
73
- /**
74
- * Present a modal on screen immediately.
75
- *
76
- * The new presented modal will be on top of existing modals if there are any.
77
- *
78
- * @param Content A component to be presented as a modal on screen.
79
- * This component will be centered horizontally and vertically on screen with
80
- * a semitransparent black overlay underneath.
81
- * @param contentProps Props for this modal component.
82
- * @returns A `ModalHandler` you can use to dismiss the modal.
83
- */
84
-
85
- export const showModal = (content: React.ReactNode): ModalHandler => {
86
- let ref: ModalPresenterHandles | null = null;
87
- let rootSiblings: RootSiblings | null = null;
88
-
89
- const dismiss: ModalDismissFunc = (onDismiss) => {
90
- if (rootSiblings) {
91
- const cleanup = () => {
92
- rootSiblings?.destroy();
93
- rootSiblings = null;
94
- ref = null;
95
- onDismiss?.();
96
- };
97
-
98
- if (ref) {
99
- ref.animatedOut(cleanup);
100
- } else {
101
- cleanup();
102
- }
103
- }
104
- };
105
-
106
- const update: ModalUpdateFunc = (newContent) => {
107
- rootSiblings?.update(
108
- <ModalPresenter
109
- ref={(_ref) => {
110
- ref = _ref;
111
- }}
112
- >
113
- {newContent}
114
- </ModalPresenter>
115
- );
116
- };
117
-
118
- rootSiblings = new RootSiblings(
119
- (
120
- <ModalPresenter
121
- ref={(_ref) => {
122
- ref = _ref;
123
- }}
124
- >
125
- {content}
126
- </ModalPresenter>
127
- )
128
- );
129
-
130
- return { dismiss, update };
131
- };
132
-
133
- ModalPresenter.displayName = 'ModalPresenter';
134
-
135
- export default ModalPresenter;
@@ -1,9 +0,0 @@
1
- import {
2
- ModalDismissFunc,
3
- ModalHandler,
4
- showModal,
5
- ModalPresenterHandles,
6
- } from './ModalPresenter';
7
-
8
- export type { ModalDismissFunc, ModalHandler, ModalPresenterHandles };
9
- export { showModal };
@@ -1,8 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { RootSiblingParent } from 'react-native-root-siblings';
3
-
4
- const ModalProvider = ({ children }: { children: ReactNode }) => {
5
- return <RootSiblingParent>{children}</RootSiblingParent>;
6
- };
7
-
8
- export default ModalProvider;
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { StyleProp, ViewStyle } from 'react-native';
3
- type ModalContentWrapperProps = {
4
- children: React.ReactElement;
5
- visible?: boolean;
6
- onShow?: () => void;
7
- testID?: string;
8
- animationType?: 'none' | 'slide' | 'fade';
9
- style?: StyleProp<ViewStyle>;
10
- animated?: boolean;
11
- };
12
- export type ModalContentWrapperHandler = {
13
- hide: (callback?: () => void) => void;
14
- };
15
- declare const ModalContentWrapper: React.ForwardRefExoticComponent<ModalContentWrapperProps & React.RefAttributes<ModalContentWrapperHandler>>;
16
- export default ModalContentWrapper;
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import { ViewProps } from 'react-native';
3
- export type ModalPresenterHandles = {
4
- animatedOut: (completion?: () => void) => void;
5
- };
6
- export type ModalDismissFunc = (onDismiss?: () => void) => void;
7
- export type ModalUpdateFunc = (content: React.ReactNode) => void;
8
- /**
9
- * Modal handler is returned by `showModal` function.
10
- */
11
- export type ModalHandler = {
12
- /**
13
- * Same `dismiss` function as in `ModalContentProps`.
14
- */
15
- dismiss: ModalDismissFunc;
16
- /**
17
- * Same `update` function as in `ModalContentProps`.
18
- */
19
- update: ModalUpdateFunc;
20
- };
21
- declare const ModalPresenter: React.ForwardRefExoticComponent<ViewProps & React.RefAttributes<ModalPresenterHandles>>;
22
- /**
23
- * Present a modal on screen immediately.
24
- *
25
- * The new presented modal will be on top of existing modals if there are any.
26
- *
27
- * @param Content A component to be presented as a modal on screen.
28
- * This component will be centered horizontally and vertically on screen with
29
- * a semitransparent black overlay underneath.
30
- * @param contentProps Props for this modal component.
31
- * @returns A `ModalHandler` you can use to dismiss the modal.
32
- */
33
- export declare const showModal: (content: React.ReactNode) => ModalHandler;
34
- export default ModalPresenter;
@@ -1,3 +0,0 @@
1
- import { ModalDismissFunc, ModalHandler, showModal, ModalPresenterHandles } from './ModalPresenter';
2
- export type { ModalDismissFunc, ModalHandler, ModalPresenterHandles };
3
- export { showModal };
@@ -1,5 +0,0 @@
1
- import { ReactNode } from 'react';
2
- declare const ModalProvider: ({ children }: {
3
- children: ReactNode;
4
- }) => JSX.Element;
5
- export default ModalProvider;