@janiscommerce/ui-native 1.23.0 → 1.25.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.
@@ -1,5 +1,12 @@
1
1
  import React from 'react';
2
2
  import { ViewStyle } from 'react-native';
3
+ interface CollapsibleHeaderProps {
4
+ isOpen: boolean;
5
+ }
6
+ interface CollapsibleContentProps {
7
+ index: number;
8
+ isOpen?: boolean;
9
+ }
3
10
  interface CollapsibleProps<HeaderProps = {}, ContentProps = {}> {
4
11
  header: React.ComponentType<HeaderProps>;
5
12
  content: React.ComponentType<ContentProps & {
@@ -10,10 +17,8 @@ interface CollapsibleProps<HeaderProps = {}, ContentProps = {}> {
10
17
  duration?: number;
11
18
  onPressCallback?: null | (() => void);
12
19
  wrapperStyle?: ViewStyle;
20
+ isDefaultOpen?: boolean;
13
21
  }
14
- declare const Collapsible: React.FC<CollapsibleProps<{
15
- isOpen: boolean;
16
- }, {
17
- isOpen?: boolean;
18
- }>>;
22
+ declare const Collapsible: React.FC<CollapsibleProps<CollapsibleHeaderProps, CollapsibleContentProps>>;
19
23
  export default Collapsible;
24
+ export type { CollapsibleHeaderProps, CollapsibleContentProps };
@@ -2,8 +2,8 @@ import List from '../List';
2
2
  import React, { useState } from 'react';
3
3
  import { StyleSheet, View, Pressable } from 'react-native';
4
4
  import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
5
- const Collapsible = ({ header: Header, content: Content, data = [], onPressCallback = null, pressableComponent: PressableComponent = Pressable, duration = 500, wrapperStyle = {}, }) => {
6
- const [isOpen, setIsOpen] = useState(false);
5
+ const Collapsible = ({ header: Header, content: Content, data = [], onPressCallback = null, pressableComponent: PressableComponent = Pressable, duration = 500, wrapperStyle = {}, isDefaultOpen = false, }) => {
6
+ const [isOpen, setIsOpen] = useState(isDefaultOpen);
7
7
  const [measuredHeight, setMeasuredHeight] = useState(0);
8
8
  const contentHeight = useSharedValue(0);
9
9
  const hasHeightBeenMeasured = !!measuredHeight;
@@ -41,8 +41,7 @@ const Collapsible = ({ header: Header, content: Content, data = [], onPressCallb
41
41
  opacity: 0,
42
42
  },
43
43
  });
44
- const renderContent = (contentData) => {
45
- const { item, index } = contentData;
44
+ const renderContent = ({ item, index }) => {
46
45
  return <Content {...item} index={index} isOpen={isOpen}/>;
47
46
  };
48
47
  return (<View style={[wrapperStyle, styles.wrapperView]}>
@@ -50,10 +49,10 @@ const Collapsible = ({ header: Header, content: Content, data = [], onPressCallb
50
49
  <Header isOpen={isOpen}/>
51
50
  </PressableComponent>
52
51
  {!hasHeightBeenMeasured && (<View style={styles.contentWrapper} onLayout={handleContentLayout}>
53
- <List data={data} renderComponent={renderContent} keyExtractor={(_, index) => String(index)} showsVerticalScrollIndicator={false}/>
52
+ <List data={data} renderComponent={renderContent} keyExtractor={(_, index) => String(index)} showsVerticalScrollIndicator={false} nestedScrollEnabled={true}/>
54
53
  </View>)}
55
54
  <Animated.View style={[styles.animatedView, bodyStyle]}>
56
- <List data={data} renderComponent={renderContent} keyExtractor={(_, index) => String(index)} showsVerticalScrollIndicator={false}/>
55
+ <List data={data} renderComponent={renderContent} keyExtractor={(_, index) => String(index)} showsVerticalScrollIndicator={false} nestedScrollEnabled={true}/>
57
56
  </Animated.View>
58
57
  </View>);
59
58
  };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ErrorFallback: React.FC;
3
+ export default ErrorFallback;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import Typography from '../../../../atoms/Typography';
3
+ import { StyleSheet, View } from 'react-native';
4
+ import { palette } from '../../../../../theme/palette';
5
+ import Icon from '../../../../atoms/Icon';
6
+ const styles = StyleSheet.create({
7
+ container: {
8
+ flexDirection: 'row',
9
+ alignItems: 'center',
10
+ },
11
+ errorMessageText: {
12
+ marginLeft: 4,
13
+ color: palette.error.main,
14
+ },
15
+ });
16
+ const ErrorFallback = () => {
17
+ return (<View style={styles.container}>
18
+ <Icon name="exclamation_circle" color={palette.error.main} size={20}/>
19
+ <Typography type="body" size="medium" style={styles.errorMessageText}>
20
+ Something went wrong.
21
+ </Typography>
22
+ </View>);
23
+ };
24
+ export default ErrorFallback;
@@ -1,8 +1,6 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  interface ErrorBoundaryProps {
3
3
  children: ReactNode;
4
- isDebug?: boolean;
5
- errorMessage?: string;
6
4
  renderErrorComponent?: (errorMessage: string) => ReactNode;
7
5
  onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
8
6
  onMount?: () => void;
@@ -29,7 +29,7 @@ class ErrorBoundary extends React.Component {
29
29
  if (typeof renderErrorComponent === 'function') {
30
30
  return renderErrorComponent(this.state.error?.message || '');
31
31
  }
32
- return (<ErrorFallback isDebug={this.props.isDebug} errorMessage={this.props.errorMessage} error={this.state.error?.message} errorDetails={this.state.errorInfo?.componentStack}/>);
32
+ return <ErrorFallback />;
33
33
  }
34
34
  return this.props.children;
35
35
  }
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ import BaseDetail from './components/molecules/BaseDetail';
30
30
  import LoadingFullScreen from './components/organisms/LoadingFullScreen';
31
31
  import FullScreenMessage from './components/organisms/FullScreenMessage';
32
32
  import SwipeItemSelectionList from './components/organisms/SwipeItemSelectionList';
33
- import ErrorBoundary from './components/organisms/ErrorBoundary';
33
+ import ErrorBoundary from './components/molecules/ErrorBoundary';
34
34
  import ProductDetail from './components/organisms/ProductDetail';
35
35
  import { palette } from './theme/palette';
36
36
  import * as getScale from './scale';
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ import BaseDetail from './components/molecules/BaseDetail';
33
33
  import LoadingFullScreen from './components/organisms/LoadingFullScreen';
34
34
  import FullScreenMessage from './components/organisms/FullScreenMessage';
35
35
  import SwipeItemSelectionList from './components/organisms/SwipeItemSelectionList';
36
- import ErrorBoundary from './components/organisms/ErrorBoundary';
36
+ import ErrorBoundary from './components/molecules/ErrorBoundary';
37
37
  import ProductDetail from './components/organisms/ProductDetail';
38
38
  // Misc
39
39
  import { palette } from './theme/palette';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janiscommerce/ui-native",
3
- "version": "1.23.0",
3
+ "version": "1.25.0",
4
4
  "description": "components library for Janis app",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- interface ErrorFallbackProps {
3
- error?: string;
4
- errorDetails?: string;
5
- isDebug?: boolean;
6
- errorMessage?: string;
7
- }
8
- declare const ErrorFallback: React.FC<ErrorFallbackProps>;
9
- export default ErrorFallback;
@@ -1,81 +0,0 @@
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 && isDebug && <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;