@janiscommerce/ui-native 1.16.2 → 1.17.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/dist/components/organisms/ErrorBoundary/components/ErrorFallback/index.d.ts +9 -0
- package/dist/components/organisms/ErrorBoundary/components/ErrorFallback/index.js +81 -0
- package/dist/components/organisms/ErrorBoundary/index.d.ts +22 -0
- package/dist/components/organisms/ErrorBoundary/index.js +37 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Collapsible from '../../../../atoms/Collapsible';
|
|
3
|
+
import Typography from '../../../../atoms/Typography';
|
|
4
|
+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
5
|
+
import { palette } from '../../../../../theme/palette';
|
|
6
|
+
const styles = StyleSheet.create({
|
|
7
|
+
container: {
|
|
8
|
+
flex: 1,
|
|
9
|
+
justifyContent: 'center',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
backgroundColor: palette.white.light,
|
|
12
|
+
padding: 30,
|
|
13
|
+
borderRadius: 12,
|
|
14
|
+
margin: 16,
|
|
15
|
+
shadowColor: palette.base.black,
|
|
16
|
+
shadowOffset: { width: 0, height: 2 },
|
|
17
|
+
shadowOpacity: 0.2,
|
|
18
|
+
shadowRadius: 4,
|
|
19
|
+
elevation: 5,
|
|
20
|
+
},
|
|
21
|
+
errorMessageText: {
|
|
22
|
+
textAlign: 'center',
|
|
23
|
+
color: palette.error.main,
|
|
24
|
+
},
|
|
25
|
+
showErrorButton: {
|
|
26
|
+
paddingVertical: 10,
|
|
27
|
+
paddingHorizontal: 20,
|
|
28
|
+
justifyContent: 'center',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
backgroundColor: palette.error.main,
|
|
31
|
+
borderRadius: 6,
|
|
32
|
+
marginVertical: 12,
|
|
33
|
+
},
|
|
34
|
+
collapsibleWrapper: {
|
|
35
|
+
marginBottom: 35,
|
|
36
|
+
},
|
|
37
|
+
errorDetails: {
|
|
38
|
+
padding: 10,
|
|
39
|
+
backgroundColor: palette.black.main,
|
|
40
|
+
borderRadius: 8,
|
|
41
|
+
marginVertical: 10,
|
|
42
|
+
},
|
|
43
|
+
heading: {
|
|
44
|
+
marginBottom: 12,
|
|
45
|
+
},
|
|
46
|
+
goBackButtonWrapper: {
|
|
47
|
+
marginTop: 20,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const ShowErrorDetailsButton = () => {
|
|
51
|
+
return (<View style={styles.showErrorButton}>
|
|
52
|
+
<Typography color={palette.base.white}>Show error details</Typography>
|
|
53
|
+
</View>);
|
|
54
|
+
};
|
|
55
|
+
const ErrorDetails = ({ errorDetails }) => {
|
|
56
|
+
return (<View style={styles.errorDetails}>
|
|
57
|
+
<Typography color={palette.error.main}>{errorDetails}</Typography>
|
|
58
|
+
</View>);
|
|
59
|
+
};
|
|
60
|
+
const ErrorFallback = ({ error, errorDetails, isDebug, errorMessage, }) => {
|
|
61
|
+
const data = [
|
|
62
|
+
{
|
|
63
|
+
errorDetails,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
if (errorMessage) {
|
|
67
|
+
return (<View style={styles.container}>
|
|
68
|
+
<Typography type="heading" size="large" style={styles.errorMessageText}>
|
|
69
|
+
{errorMessage}
|
|
70
|
+
</Typography>
|
|
71
|
+
</View>);
|
|
72
|
+
}
|
|
73
|
+
return (<View style={styles.container}>
|
|
74
|
+
<Typography type="heading" size="large" style={styles.heading}>
|
|
75
|
+
Oops! Something went wrong.
|
|
76
|
+
</Typography>
|
|
77
|
+
{error && <Typography color={palette.error.main}>{error}</Typography>}
|
|
78
|
+
{isDebug && (<Collapsible wrapperStyle={styles.collapsibleWrapper} header={ShowErrorDetailsButton} content={ErrorDetails} data={data} pressableComponent={TouchableOpacity}/>)}
|
|
79
|
+
</View>);
|
|
80
|
+
};
|
|
81
|
+
export default ErrorFallback;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
interface ErrorBoundaryProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
isDebug?: boolean;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
renderErrorComponent?: (errorMessage: string) => ReactNode;
|
|
7
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
8
|
+
onMount?: () => void;
|
|
9
|
+
}
|
|
10
|
+
interface ErrorBoundaryState {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
errorInfo: React.ErrorInfo | null;
|
|
14
|
+
}
|
|
15
|
+
declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
16
|
+
constructor(props: ErrorBoundaryProps);
|
|
17
|
+
static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
|
|
18
|
+
componentDidMount(): void;
|
|
19
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
20
|
+
render(): React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export default ErrorBoundary;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ErrorFallback from '../ErrorBoundary/components/ErrorFallback';
|
|
3
|
+
class ErrorBoundary extends React.Component {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
super(props);
|
|
6
|
+
this.state = {
|
|
7
|
+
hasError: false,
|
|
8
|
+
error: null,
|
|
9
|
+
errorInfo: null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
static getDerivedStateFromError(error) {
|
|
13
|
+
return { hasError: true, error };
|
|
14
|
+
}
|
|
15
|
+
componentDidMount() {
|
|
16
|
+
if (this.props.onMount) {
|
|
17
|
+
this.props.onMount();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
componentDidCatch(error, errorInfo) {
|
|
21
|
+
this.setState({ errorInfo });
|
|
22
|
+
if (this.props.onError) {
|
|
23
|
+
this.props.onError(error, errorInfo);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
if (this.state.hasError) {
|
|
28
|
+
const { renderErrorComponent } = this.props;
|
|
29
|
+
if (typeof renderErrorComponent === 'function') {
|
|
30
|
+
return renderErrorComponent(this.state.error?.message || '');
|
|
31
|
+
}
|
|
32
|
+
return (<ErrorFallback isDebug={this.props.isDebug} errorMessage={this.props.errorMessage} error={this.state.error?.message} errorDetails={this.state.errorInfo?.componentStack}/>);
|
|
33
|
+
}
|
|
34
|
+
return this.props.children;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default ErrorBoundary;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ import Input from './components/molecules/Input';
|
|
|
28
28
|
import LoadingFullScreen from './components/organisms/LoadingFullScreen';
|
|
29
29
|
import FullScreenMessage from './components/organisms/FullScreenMessage';
|
|
30
30
|
import SwipeItemSelectionList from './components/organisms/SwipeItemSelectionList';
|
|
31
|
+
import ErrorBoundary from './components/organisms/ErrorBoundary';
|
|
31
32
|
import { palette } from './theme/palette';
|
|
32
33
|
import * as getScale from './scale';
|
|
33
|
-
export { Text, Avatar, CheckBox, Icon, Image, Input, Loading, Svg, StatusChip, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, Button, getScale, LayoutWithBottomButtons, FullScreenMessage, Toast, configToast, SwipeList, ItemSelectionButton, SwipeItemSelectionList, MainCardList, BaseInput, Typography, Collapsible, };
|
|
34
|
+
export { Text, Avatar, CheckBox, Icon, Image, Input, Loading, Svg, StatusChip, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, Button, getScale, LayoutWithBottomButtons, FullScreenMessage, Toast, configToast, SwipeList, ItemSelectionButton, SwipeItemSelectionList, MainCardList, BaseInput, Typography, Collapsible, ErrorBoundary, };
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,8 @@ import Input from './components/molecules/Input';
|
|
|
31
31
|
import LoadingFullScreen from './components/organisms/LoadingFullScreen';
|
|
32
32
|
import FullScreenMessage from './components/organisms/FullScreenMessage';
|
|
33
33
|
import SwipeItemSelectionList from './components/organisms/SwipeItemSelectionList';
|
|
34
|
+
import ErrorBoundary from './components/organisms/ErrorBoundary';
|
|
34
35
|
// Misc
|
|
35
36
|
import { palette } from './theme/palette';
|
|
36
37
|
import * as getScale from './scale';
|
|
37
|
-
export { Text, Avatar, CheckBox, Icon, Image, Input, Loading, Svg, StatusChip, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, Button, getScale, LayoutWithBottomButtons, FullScreenMessage, Toast, configToast, SwipeList, ItemSelectionButton, SwipeItemSelectionList, MainCardList, BaseInput, Typography, Collapsible, };
|
|
38
|
+
export { Text, Avatar, CheckBox, Icon, Image, Input, Loading, Svg, StatusChip, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, Button, getScale, LayoutWithBottomButtons, FullScreenMessage, Toast, configToast, SwipeList, ItemSelectionButton, SwipeItemSelectionList, MainCardList, BaseInput, Typography, Collapsible, ErrorBoundary, };
|