@hero-design/rn 8.41.1 → 8.41.3-rc.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.
- package/.turbo/turbo-build.log +1 -1
- package/es/index.js +681 -577
- package/lib/index.js +685 -579
- package/package.json +8 -7
- package/rollup.config.js +1 -0
- package/src/components/Error/StyledError.tsx +1 -2
- package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +97 -115
- package/src/components/Error/__tests__/index.spec.tsx +6 -9
- package/src/components/Modal/ModalContentWrapper.tsx +112 -0
- package/src/components/Modal/ModalPresenter/ModalPresenter.tsx +135 -0
- package/src/components/Modal/ModalPresenter/index.tsx +9 -0
- package/src/components/Modal/ModalProvider.tsx +8 -0
- package/src/components/Modal/index.tsx +82 -178
- package/src/components/Success/StyledSuccess.tsx +1 -2
- package/src/components/Success/__tests__/__snapshots__/index.spec.tsx.snap +95 -115
- package/src/components/Success/__tests__/index.spec.tsx +6 -9
- package/src/index.ts +2 -0
- package/testUtils/setup.tsx +18 -0
- package/types/components/Error/StyledError.d.ts +5 -3
- package/types/components/Modal/ModalContentWrapper.d.ts +16 -0
- package/types/components/Modal/ModalPresenter/ModalPresenter.d.ts +34 -0
- package/types/components/Modal/ModalPresenter/index.d.ts +3 -0
- package/types/components/Modal/ModalProvider.d.ts +5 -0
- package/types/components/Modal/index.d.ts +8 -12
- package/types/components/Success/StyledSuccess.d.ts +5 -3
- package/types/index.d.ts +2 -1
- package/src/components/Modal/__tests__/__snapshots__/index.spec.tsx.snap +0 -117
- package/src/components/Modal/__tests__/index.spec.tsx +0 -99
|
@@ -0,0 +1,34 @@
|
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface ModalProps {
|
|
3
3
|
/**
|
|
4
4
|
* Content of the modal.
|
|
5
5
|
*/
|
|
6
|
-
children:
|
|
6
|
+
children: React.ReactElement;
|
|
7
7
|
/**
|
|
8
8
|
* Visibility of the modal
|
|
9
9
|
*/
|
|
@@ -24,14 +24,10 @@ 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;
|
|
35
27
|
}
|
|
36
|
-
declare const
|
|
37
|
-
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { View } from 'react-native';
|
|
2
|
+
import { Modal, 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,8 +45,10 @@ 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("
|
|
48
|
+
declare const StyledSuccessModal: import("@emotion/native").StyledComponent<import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & {
|
|
49
49
|
theme?: import("@emotion/react").Theme | undefined;
|
|
50
50
|
as?: import("react").ElementType<any> | undefined;
|
|
51
|
-
}, {}, {
|
|
51
|
+
}, {}, {
|
|
52
|
+
ref?: import("react").Ref<Modal> | undefined;
|
|
53
|
+
}>;
|
|
52
54
|
export { SuccessVariant, StyledSuccessImage, StyledSuccessContainer, StyledSuccessContent, StyledSuccessImageContainer, StyledSuccessTitle, StyledSuccessDescription, StyledSuccessButtonContainer, StyledSuccessButtonPrimary, StyledSuccessModal, };
|
package/types/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ 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';
|
|
28
29
|
import PinInput from './components/PinInput';
|
|
29
30
|
import Progress from './components/Progress';
|
|
30
31
|
import Slider from './components/Slider';
|
|
@@ -48,5 +49,5 @@ import RefreshControl from './components/RefreshControl';
|
|
|
48
49
|
import RichTextEditor from './components/RichTextEditor';
|
|
49
50
|
import PageControl from './components/PageControl';
|
|
50
51
|
import Portal from './components/Portal';
|
|
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, };
|
|
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, };
|
|
52
53
|
export * from './types';
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Modal renders correctly 1`] = `
|
|
4
|
-
[
|
|
5
|
-
<View
|
|
6
|
-
collapsable={false}
|
|
7
|
-
style={
|
|
8
|
-
{
|
|
9
|
-
"backgroundColor": "#000000",
|
|
10
|
-
"bottom": 0,
|
|
11
|
-
"left": 0,
|
|
12
|
-
"opacity": 0.4,
|
|
13
|
-
"position": "absolute",
|
|
14
|
-
"right": 0,
|
|
15
|
-
"top": 0,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/>,
|
|
19
|
-
<View
|
|
20
|
-
collapsable={false}
|
|
21
|
-
style={
|
|
22
|
-
{
|
|
23
|
-
"bottom": 0,
|
|
24
|
-
"left": 0,
|
|
25
|
-
"opacity": 1,
|
|
26
|
-
"position": "absolute",
|
|
27
|
-
"right": 0,
|
|
28
|
-
"top": 0,
|
|
29
|
-
"transform": [
|
|
30
|
-
{
|
|
31
|
-
"translateY": 0,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
>
|
|
37
|
-
<Text
|
|
38
|
-
allowFontScaling={false}
|
|
39
|
-
style={
|
|
40
|
-
[
|
|
41
|
-
{
|
|
42
|
-
"color": "#001f23",
|
|
43
|
-
"fontFamily": "BeVietnamPro-Regular",
|
|
44
|
-
"fontSize": 16,
|
|
45
|
-
"letterSpacing": 0.48,
|
|
46
|
-
"lineHeight": 24,
|
|
47
|
-
},
|
|
48
|
-
undefined,
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
themeIntent="body"
|
|
52
|
-
themeTypeface="neutral"
|
|
53
|
-
themeVariant="regular"
|
|
54
|
-
>
|
|
55
|
-
Modal content
|
|
56
|
-
</Text>
|
|
57
|
-
</View>,
|
|
58
|
-
]
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
exports[`Modal renders correctly with transparent 1`] = `
|
|
62
|
-
[
|
|
63
|
-
<View
|
|
64
|
-
collapsable={false}
|
|
65
|
-
style={
|
|
66
|
-
{
|
|
67
|
-
"backgroundColor": "transparent",
|
|
68
|
-
"bottom": 0,
|
|
69
|
-
"left": 0,
|
|
70
|
-
"opacity": 0.4,
|
|
71
|
-
"position": "absolute",
|
|
72
|
-
"right": 0,
|
|
73
|
-
"top": 0,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/>,
|
|
77
|
-
<View
|
|
78
|
-
collapsable={false}
|
|
79
|
-
style={
|
|
80
|
-
{
|
|
81
|
-
"bottom": 0,
|
|
82
|
-
"left": 0,
|
|
83
|
-
"opacity": 1,
|
|
84
|
-
"position": "absolute",
|
|
85
|
-
"right": 0,
|
|
86
|
-
"top": 0,
|
|
87
|
-
"transform": [
|
|
88
|
-
{
|
|
89
|
-
"translateY": 0,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
>
|
|
95
|
-
<Text
|
|
96
|
-
allowFontScaling={false}
|
|
97
|
-
style={
|
|
98
|
-
[
|
|
99
|
-
{
|
|
100
|
-
"color": "#001f23",
|
|
101
|
-
"fontFamily": "BeVietnamPro-Regular",
|
|
102
|
-
"fontSize": 16,
|
|
103
|
-
"letterSpacing": 0.48,
|
|
104
|
-
"lineHeight": 24,
|
|
105
|
-
},
|
|
106
|
-
undefined,
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
themeIntent="body"
|
|
110
|
-
themeTypeface="neutral"
|
|
111
|
-
themeVariant="regular"
|
|
112
|
-
>
|
|
113
|
-
Modal content
|
|
114
|
-
</Text>
|
|
115
|
-
</View>,
|
|
116
|
-
]
|
|
117
|
-
`;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { fireEvent } from '@testing-library/react-native';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { BackHandler } from 'react-native';
|
|
4
|
-
import Modal from '..';
|
|
5
|
-
import { Button } from '../../..';
|
|
6
|
-
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
7
|
-
import Portal from '../../Portal';
|
|
8
|
-
import Typography from '../../Typography';
|
|
9
|
-
|
|
10
|
-
describe('Modal', () => {
|
|
11
|
-
it('renders correctly', () => {
|
|
12
|
-
const wrapper = renderWithTheme(
|
|
13
|
-
<Portal.Provider>
|
|
14
|
-
<Modal visible>
|
|
15
|
-
<Typography.Body>Modal content</Typography.Body>
|
|
16
|
-
</Modal>
|
|
17
|
-
</Portal.Provider>
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('renders correctly with transparent', () => {
|
|
24
|
-
const wrapper = renderWithTheme(
|
|
25
|
-
<Portal.Provider>
|
|
26
|
-
<Modal visible transparent>
|
|
27
|
-
<Typography.Body>Modal content</Typography.Body>
|
|
28
|
-
</Modal>
|
|
29
|
-
</Portal.Provider>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('trigger onShow callback correctly', () => {
|
|
36
|
-
const onShow = jest.fn();
|
|
37
|
-
renderWithTheme(
|
|
38
|
-
<Portal.Provider>
|
|
39
|
-
<Modal visible onShow={onShow}>
|
|
40
|
-
<Typography.Body>Modal content</Typography.Body>
|
|
41
|
-
</Modal>
|
|
42
|
-
</Portal.Provider>
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
expect(onShow).toBeCalledTimes(1);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('trigger onRequestClose callback correctly', () => {
|
|
49
|
-
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
|
|
50
|
-
OS: 'android',
|
|
51
|
-
select: () => null,
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
const onRequestClose = jest.fn();
|
|
55
|
-
renderWithTheme(
|
|
56
|
-
<Portal.Provider>
|
|
57
|
-
<Modal visible onRequestClose={onRequestClose}>
|
|
58
|
-
<Typography.Body>Modal content</Typography.Body>
|
|
59
|
-
</Modal>
|
|
60
|
-
</Portal.Provider>
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
// @ts-expect-error: BackHandler mock
|
|
64
|
-
BackHandler.mockPressBack();
|
|
65
|
-
expect(onRequestClose).toBeCalled();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('trigger onDismiss callback correctly', async () => {
|
|
69
|
-
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
|
|
70
|
-
OS: 'ios',
|
|
71
|
-
select: () => null,
|
|
72
|
-
}));
|
|
73
|
-
|
|
74
|
-
const onDismiss = jest.fn();
|
|
75
|
-
|
|
76
|
-
const ModalExample = () => {
|
|
77
|
-
const [modalVisible, setModalVisible] = React.useState(true);
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<Portal.Provider>
|
|
81
|
-
<Modal
|
|
82
|
-
animationType="none"
|
|
83
|
-
visible={modalVisible}
|
|
84
|
-
onDismiss={onDismiss}
|
|
85
|
-
transparent
|
|
86
|
-
>
|
|
87
|
-
<Typography.Body>Modal content</Typography.Body>
|
|
88
|
-
<Button text="Close modal" onPress={() => setModalVisible(false)} />
|
|
89
|
-
</Modal>
|
|
90
|
-
</Portal.Provider>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const { getByText } = renderWithTheme(<ModalExample />);
|
|
95
|
-
|
|
96
|
-
fireEvent.press(getByText('Close modal'));
|
|
97
|
-
expect(onDismiss).toBeCalled();
|
|
98
|
-
});
|
|
99
|
-
});
|