dhre-ui-kit 0.0.3 → 0.0.5
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/package.json +1 -1
- package/src/assets/images/arrowLeft.svg +3 -0
- package/src/assets/images/caretDown.svg +3 -0
- package/src/assets/images/caretLeft.svg +3 -0
- package/src/assets/images/caretUp.svg +3 -0
- package/src/assets/images/circleTick.svg +3 -0
- package/src/assets/images/crossIcon.svg +3 -0
- package/src/assets/images/dotsThreeVertical.svg +5 -0
- package/src/assets/images/searchIcon.svg +4 -0
- package/src/assets/index.ts +20 -1
- package/src/components/accordion/Accordion.interface.ts +7 -0
- package/src/components/accordion/Accordion.styles.ts +28 -0
- package/src/components/accordion/Accordion.test.tsx +21 -0
- package/src/components/accordion/Accordion.tsx +64 -0
- package/src/components/accordion/index.ts +1 -0
- package/src/components/bottomDrawer/BottomDrawer.interface.ts +5 -0
- package/src/components/bottomDrawer/BottomDrawer.styles.ts +18 -10
- package/src/components/bottomDrawer/BottomDrawer.tsx +29 -12
- package/src/components/customHeader/CustomHeader.interface.tsx +10 -0
- package/src/components/customHeader/CustomHeader.styles.ts +24 -0
- package/src/components/customHeader/CustomHeader.test.tsx +14 -0
- package/src/components/customHeader/CustomHeader.tsx +46 -0
- package/src/components/customHeader/index.ts +1 -0
- package/src/components/customSearchBar/CustomSearchBar.interface.ts +9 -0
- package/src/components/customSearchBar/CustomSearchBar.styles.ts +23 -0
- package/src/components/customSearchBar/CustomSearchBar.test.tsx +19 -0
- package/src/components/customSearchBar/CustomSearchBar.tsx +55 -0
- package/src/components/customSearchBar/index.ts +1 -0
- package/src/components/customTypography/CustomTypography.test.tsx +12 -0
- package/src/components/customTypography/CustomTypography.tsx +5 -3
- package/src/components/swipableList/SwipableList.interface.ts +37 -0
- package/src/components/swipableList/SwipableList.styles.ts +24 -0
- package/src/components/{notification/Notification.test.tsx → swipableList/SwipableList.test.tsx} +20 -21
- package/src/components/swipableList/SwipableList.tsx +106 -0
- package/src/components/swipableList/index.ts +1 -0
- package/src/components/toast/Toast.interface.ts +8 -0
- package/src/components/toast/Toast.styles.ts +40 -0
- package/src/components/toast/Toast.test.tsx +21 -0
- package/src/components/toast/Toast.tsx +89 -0
- package/src/components/toast/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/theme/fonts.ts +4 -4
- package/src/utils/stylehelper.ts +1 -1
- package/src/components/notification/Notification.interface.ts +0 -61
- package/src/components/notification/Notification.styles.ts +0 -33
- package/src/components/notification/Notification.tsx +0 -156
package/src/components/{notification/Notification.test.tsx → swipableList/SwipableList.test.tsx}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {fireEvent, render} from '@testing-library/react-native';
|
|
3
|
-
import
|
|
3
|
+
import SwipableList from './SwipableList';
|
|
4
4
|
import {CalenderDots} from '../../assets';
|
|
5
|
+
import {Text} from 'react-native';
|
|
5
6
|
|
|
6
7
|
jest.mock('react-native-gesture-handler', () => {
|
|
7
8
|
const mockGestureHandler = {
|
|
@@ -51,7 +52,6 @@ describe('Notification Component', () => {
|
|
|
51
52
|
const mockLeftPrimaryActionHandler = jest.fn();
|
|
52
53
|
const mockRightPrimaryActionHandler = jest.fn();
|
|
53
54
|
const mockLeftSecondaryActionHandler = jest.fn();
|
|
54
|
-
const mockRightSecondaryActionHandler = jest.fn();
|
|
55
55
|
|
|
56
56
|
const commonProps = {
|
|
57
57
|
leftPrimaryActionIcon: <CalenderDots />,
|
|
@@ -63,54 +63,53 @@ describe('Notification Component', () => {
|
|
|
63
63
|
rightPrimaryActionIcon: <CalenderDots />,
|
|
64
64
|
rightPrimaryActionHandler: mockRightPrimaryActionHandler,
|
|
65
65
|
rightPrimaryActionStyle: {backgroundColor: 'green'},
|
|
66
|
-
rightSecondaryActionIcon: <CalenderDots />,
|
|
67
|
-
rightSecondaryActionHandler: mockRightSecondaryActionHandler,
|
|
68
|
-
rightSecondaryActionStyle: {backgroundColor: 'yellow'},
|
|
69
66
|
itemStyle: customStyle,
|
|
70
67
|
titleStyle: customStyle,
|
|
71
68
|
};
|
|
72
69
|
|
|
73
70
|
const props = {
|
|
74
71
|
...commonProps,
|
|
75
|
-
notifications,
|
|
72
|
+
data: notifications,
|
|
76
73
|
leftPrimaryActionTitle: 'Pin',
|
|
77
74
|
leftSecondaryActionTitle: 'Read',
|
|
78
75
|
rightPrimaryActionTitle: 'Delete',
|
|
79
|
-
rightSecondaryActionTitle: 'Archive',
|
|
80
76
|
};
|
|
81
77
|
const propsUnPinned = {
|
|
82
78
|
...commonProps,
|
|
83
|
-
|
|
79
|
+
data: notificationsUnPinned,
|
|
84
80
|
leftPrimaryActionTitle: 'Pin',
|
|
85
81
|
leftSecondaryActionTitle: 'Read',
|
|
86
82
|
rightPrimaryActionTitle: 'Delete',
|
|
87
|
-
rightSecondaryActionTitle: 'Archive',
|
|
88
83
|
};
|
|
89
84
|
|
|
90
85
|
const propsPinned = {
|
|
91
86
|
...commonProps,
|
|
92
|
-
|
|
87
|
+
data: notificationsPinned,
|
|
93
88
|
leftPrimaryActionTitle: '',
|
|
94
89
|
leftSecondaryActionTitle: '',
|
|
95
90
|
rightPrimaryActionTitle: '',
|
|
96
|
-
rightSecondaryActionTitle: '',
|
|
97
91
|
};
|
|
98
92
|
|
|
99
93
|
it('renders Notification component correctly', () => {
|
|
100
|
-
const {getByTestId} = render(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
fireEvent.press(getByTestId('
|
|
105
|
-
fireEvent.press(getByTestId('
|
|
94
|
+
const {getByTestId} = render(
|
|
95
|
+
<SwipableList {...props} renderItem={() => <Text>Title</Text>} />,
|
|
96
|
+
);
|
|
97
|
+
expect(getByTestId('SWIPABLE-LIST')).toBeTruthy();
|
|
98
|
+
fireEvent.press(getByTestId('SWIPABLE-LIST-LEFT-PRIMARY-1'));
|
|
99
|
+
fireEvent.press(getByTestId('SWIPABLE-LIST-LEFT-SECONDARY-1'));
|
|
100
|
+
fireEvent.press(getByTestId('SWIPABLE-LIST-RIGHT-PRIMARY-1'));
|
|
106
101
|
});
|
|
107
102
|
|
|
108
103
|
it('renders Notification component when pinned', () => {
|
|
109
|
-
const {getByTestId} = render(
|
|
110
|
-
|
|
104
|
+
const {getByTestId} = render(
|
|
105
|
+
<SwipableList {...propsPinned} renderItem={() => <Text>Title</Text>} />,
|
|
106
|
+
);
|
|
107
|
+
expect(getByTestId('SWIPABLE-LIST')).toBeTruthy();
|
|
111
108
|
});
|
|
112
109
|
it('renders Notification component when pinned', () => {
|
|
113
|
-
const {getByTestId} = render(
|
|
114
|
-
|
|
110
|
+
const {getByTestId} = render(
|
|
111
|
+
<SwipableList {...propsUnPinned} renderItem={() => <Text>Title</Text>} />,
|
|
112
|
+
);
|
|
113
|
+
expect(getByTestId('SWIPABLE-LIST')).toBeTruthy();
|
|
115
114
|
});
|
|
116
115
|
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {FlatList, View, Pressable} from 'react-native';
|
|
3
|
+
import {GestureHandlerRootView, Swipeable} from 'react-native-gesture-handler';
|
|
4
|
+
import {
|
|
5
|
+
ActionButtonProps,
|
|
6
|
+
ListItem,
|
|
7
|
+
SwipableListProps,
|
|
8
|
+
} from './SwipableList.interface';
|
|
9
|
+
import {styles} from './SwipableList.styles';
|
|
10
|
+
import CustomTypography from '../customTypography/CustomTypography';
|
|
11
|
+
|
|
12
|
+
const SwipableList = (props: SwipableListProps) => {
|
|
13
|
+
const {
|
|
14
|
+
data,
|
|
15
|
+
testId = 'SWIPABLE-LIST',
|
|
16
|
+
leftPrimaryActionIcon,
|
|
17
|
+
leftPrimaryActionTitle,
|
|
18
|
+
leftPrimaryActionHandler,
|
|
19
|
+
leftPrimaryActionStyle,
|
|
20
|
+
leftSecondaryActionIcon,
|
|
21
|
+
leftSecondaryActionTitle,
|
|
22
|
+
leftSecondaryActionHandler,
|
|
23
|
+
leftSecondaryActionStyle,
|
|
24
|
+
rightPrimaryActionIcon,
|
|
25
|
+
rightPrimaryActionTitle,
|
|
26
|
+
rightPrimaryActionHandler,
|
|
27
|
+
rightPrimaryActionStyle,
|
|
28
|
+
titleStyle,
|
|
29
|
+
} = props;
|
|
30
|
+
|
|
31
|
+
const ActionButton = ({
|
|
32
|
+
icon,
|
|
33
|
+
title,
|
|
34
|
+
onPress,
|
|
35
|
+
style,
|
|
36
|
+
testID,
|
|
37
|
+
}: ActionButtonProps) => (
|
|
38
|
+
<Pressable
|
|
39
|
+
testID={testID}
|
|
40
|
+
onPress={onPress}
|
|
41
|
+
style={[styles.actionButton, style]}>
|
|
42
|
+
{icon}
|
|
43
|
+
<CustomTypography variant="L1_REGULAR" style={titleStyle} text={title} />
|
|
44
|
+
</Pressable>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const leftActionHandle = item => (
|
|
48
|
+
<View style={[styles.leftActions, leftPrimaryActionStyle]}>
|
|
49
|
+
{leftPrimaryActionIcon && (
|
|
50
|
+
<ActionButton
|
|
51
|
+
icon={leftPrimaryActionIcon}
|
|
52
|
+
title={leftPrimaryActionTitle || ''}
|
|
53
|
+
onPress={() => leftPrimaryActionHandler?.(item.id)}
|
|
54
|
+
style={leftPrimaryActionStyle}
|
|
55
|
+
testID={`${testId}-LEFT-PRIMARY-${item.id}`}
|
|
56
|
+
/>
|
|
57
|
+
)}
|
|
58
|
+
{leftSecondaryActionIcon && (
|
|
59
|
+
<ActionButton
|
|
60
|
+
icon={leftSecondaryActionIcon}
|
|
61
|
+
title={leftSecondaryActionTitle || ''}
|
|
62
|
+
onPress={() => leftSecondaryActionHandler?.(item.id)}
|
|
63
|
+
style={leftSecondaryActionStyle}
|
|
64
|
+
testID={`${testId}-LEFT-SECONDARY-${item.id}`}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
</View>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const rightActionHandle = item => (
|
|
71
|
+
<View style={[styles.rightActions, rightPrimaryActionStyle]}>
|
|
72
|
+
{rightPrimaryActionIcon && (
|
|
73
|
+
<ActionButton
|
|
74
|
+
icon={rightPrimaryActionIcon}
|
|
75
|
+
title={rightPrimaryActionTitle || ''}
|
|
76
|
+
onPress={() => rightPrimaryActionHandler?.(item.id)}
|
|
77
|
+
style={rightPrimaryActionStyle}
|
|
78
|
+
testID={`${testId}-RIGHT-PRIMARY-${item.id}`}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const renderItem = ({item}: {item: ListItem}) => (
|
|
85
|
+
<GestureHandlerRootView testID={`${testId}-LIST`} style={styles.container}>
|
|
86
|
+
<Swipeable
|
|
87
|
+
renderLeftActions={() => leftActionHandle(item)}
|
|
88
|
+
renderRightActions={() => rightActionHandle(item)}>
|
|
89
|
+
{props?.renderItem(item)}
|
|
90
|
+
</Swipeable>
|
|
91
|
+
</GestureHandlerRootView>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<View testID={testId}>
|
|
96
|
+
<FlatList
|
|
97
|
+
data={data}
|
|
98
|
+
renderItem={renderItem}
|
|
99
|
+
keyExtractor={item => item.id}
|
|
100
|
+
ItemSeparatorComponent={() => <View style={styles.seprator} />}
|
|
101
|
+
/>
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default SwipableList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default} from './SwipableList';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
horizontalScale,
|
|
4
|
+
moderateScale,
|
|
5
|
+
verticalScale,
|
|
6
|
+
width,
|
|
7
|
+
} from '../../utils/stylehelper';
|
|
8
|
+
|
|
9
|
+
const styles = StyleSheet.create({
|
|
10
|
+
container: {
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
height: verticalScale(72),
|
|
13
|
+
width: width - horizontalScale(48),
|
|
14
|
+
top: 56,
|
|
15
|
+
borderRadius: moderateScale(8),
|
|
16
|
+
overflow: 'hidden',
|
|
17
|
+
},
|
|
18
|
+
toastContainer: {flex: 1, justifyContent: 'center'},
|
|
19
|
+
innerContainer: {
|
|
20
|
+
flexDirection: 'row',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
paddingHorizontal: horizontalScale(12),
|
|
23
|
+
},
|
|
24
|
+
icon: {
|
|
25
|
+
marginRight: 9,
|
|
26
|
+
},
|
|
27
|
+
messageText: {
|
|
28
|
+
flex: 1,
|
|
29
|
+
color: '#fff',
|
|
30
|
+
},
|
|
31
|
+
button: {
|
|
32
|
+
marginLeft: 9,
|
|
33
|
+
},
|
|
34
|
+
buttonText: {
|
|
35
|
+
textDecorationLine: 'underline',
|
|
36
|
+
color: '#fff',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export default styles;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {render} from '@testing-library/react-native';
|
|
3
|
+
import Toast from './Toast';
|
|
4
|
+
|
|
5
|
+
jest.mock('react-native-progress', () => ({
|
|
6
|
+
Bar: props => <div {...props} />,
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe('Toast Component', () => {
|
|
10
|
+
it('Component renders correctly', () => {
|
|
11
|
+
const {getByTestId} = render(
|
|
12
|
+
<Toast
|
|
13
|
+
message="Test message"
|
|
14
|
+
setToast={jest.fn()}
|
|
15
|
+
btnText="Undo"
|
|
16
|
+
onBtnPress={jest.fn()}
|
|
17
|
+
/>,
|
|
18
|
+
);
|
|
19
|
+
expect(getByTestId('TOAST')).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, {useEffect, useState} from 'react';
|
|
2
|
+
import {View, Animated, Pressable} from 'react-native';
|
|
3
|
+
import * as Progress from 'react-native-progress';
|
|
4
|
+
import {CrossIcon, CircleTick} from '../../assets';
|
|
5
|
+
import CustomTypography from '../customTypography/CustomTypography';
|
|
6
|
+
import {horizontalScale, moderateScale, width} from '../../utils/stylehelper';
|
|
7
|
+
import {ToastProps} from './Toast.interface';
|
|
8
|
+
import styles from './Toast.styles';
|
|
9
|
+
|
|
10
|
+
const Toast = ({
|
|
11
|
+
message,
|
|
12
|
+
testId = 'TOAST',
|
|
13
|
+
isSuccess = true,
|
|
14
|
+
btnText,
|
|
15
|
+
onBtnPress,
|
|
16
|
+
setToast,
|
|
17
|
+
}: ToastProps) => {
|
|
18
|
+
const [progress, setProgress] = useState(0);
|
|
19
|
+
const bottom = React.useRef(new Animated.Value(-80)).current;
|
|
20
|
+
|
|
21
|
+
function animate() {
|
|
22
|
+
Animated.timing(bottom, {
|
|
23
|
+
toValue: 20,
|
|
24
|
+
duration: 2000,
|
|
25
|
+
useNativeDriver: false,
|
|
26
|
+
}).start(() => {
|
|
27
|
+
setToast(false);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
animate();
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
const simulateProgress = () => {
|
|
36
|
+
setProgress(prev => (prev + 0.1 > 1 ? 1 : prev + 0.1));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const interval = setInterval(simulateProgress, 180);
|
|
41
|
+
return () => clearInterval(interval);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Animated.View
|
|
46
|
+
style={[
|
|
47
|
+
styles.container,
|
|
48
|
+
{bottom},
|
|
49
|
+
{backgroundColor: isSuccess ? '#04743F' : '#DB3056'},
|
|
50
|
+
]}
|
|
51
|
+
testID={testId}>
|
|
52
|
+
<View style={styles.toastContainer}>
|
|
53
|
+
<View style={styles.innerContainer}>
|
|
54
|
+
{React.cloneElement(isSuccess ? <CircleTick /> : <CrossIcon />, {
|
|
55
|
+
width: moderateScale(20),
|
|
56
|
+
height: moderateScale(20),
|
|
57
|
+
style: styles.icon,
|
|
58
|
+
})}
|
|
59
|
+
<CustomTypography
|
|
60
|
+
variant={'L2_REGULAR'}
|
|
61
|
+
text={message}
|
|
62
|
+
style={styles.messageText}
|
|
63
|
+
/>
|
|
64
|
+
{btnText ? (
|
|
65
|
+
<Pressable
|
|
66
|
+
style={styles.button}
|
|
67
|
+
onPress={onBtnPress}
|
|
68
|
+
testID={`${testId}-BTN`}>
|
|
69
|
+
<CustomTypography
|
|
70
|
+
variant={'L2_BOLD'}
|
|
71
|
+
text={btnText}
|
|
72
|
+
style={styles.buttonText}
|
|
73
|
+
/>
|
|
74
|
+
</Pressable>
|
|
75
|
+
) : null}
|
|
76
|
+
</View>
|
|
77
|
+
</View>
|
|
78
|
+
<Progress.Bar
|
|
79
|
+
progress={progress}
|
|
80
|
+
width={width - horizontalScale(48)}
|
|
81
|
+
height={3}
|
|
82
|
+
color={isSuccess ? '#024324' : '#851D41'}
|
|
83
|
+
borderColor="transparent"
|
|
84
|
+
/>
|
|
85
|
+
</Animated.View>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default Toast;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default} from './Toast';
|
package/src/index.ts
CHANGED
|
@@ -17,3 +17,8 @@ export {default as StarRating} from './components/rating';
|
|
|
17
17
|
export {default as Tabs} from './components/tabs';
|
|
18
18
|
export {default as Tags} from './components/tags';
|
|
19
19
|
export {default as ToggleButton} from './components/toggleButton';
|
|
20
|
+
// export {default as Accordion} from './components/accordion';
|
|
21
|
+
// export {default as Toast} from './components/toast';
|
|
22
|
+
// export {default as CustomSearchBar} from './components/customSearchBar';
|
|
23
|
+
// export {default as CustomHeader} from './components/customHeader';
|
|
24
|
+
// export {default as SwipableList} from './components/swipableList';
|
package/src/theme/fonts.ts
CHANGED
|
@@ -16,12 +16,12 @@ const createFontStyle = (
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export const meraasActivFontfamily: TextStyle = {
|
|
19
|
-
fontFamily: 'MeraasAktiv_Rg'
|
|
20
|
-
}
|
|
19
|
+
fontFamily: 'MeraasAktiv_Rg',
|
|
20
|
+
};
|
|
21
21
|
|
|
22
22
|
export const serifActivFontfamily: TextStyle = {
|
|
23
|
-
fontFamily: 'PT Serif'
|
|
24
|
-
}
|
|
23
|
+
fontFamily: 'PT Serif',
|
|
24
|
+
};
|
|
25
25
|
|
|
26
26
|
export const FONT_STYLES: FontStyles = {
|
|
27
27
|
// Bold headding styles
|
package/src/utils/stylehelper.ts
CHANGED
|
@@ -10,4 +10,4 @@ const verticalScale = (size: number) => (height / guidelineBaseHeight) * size;
|
|
|
10
10
|
const moderateScale = (size: number, factor = 0.5) =>
|
|
11
11
|
size + (horizontalScale(size) - size) * factor;
|
|
12
12
|
|
|
13
|
-
export {horizontalScale, verticalScale, moderateScale};
|
|
13
|
+
export {horizontalScale, verticalScale, moderateScale, width, height};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import {ReactNode} from 'react';
|
|
2
|
-
import {ViewStyle} from 'react-native';
|
|
3
|
-
|
|
4
|
-
export interface NotificationItem {
|
|
5
|
-
id: string;
|
|
6
|
-
title: string;
|
|
7
|
-
isPinned: boolean;
|
|
8
|
-
isRead: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ActionButtonProps {
|
|
12
|
-
icon: ReactNode;
|
|
13
|
-
title: string;
|
|
14
|
-
onPress: () => void;
|
|
15
|
-
style?: object;
|
|
16
|
-
testID: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ListItemProps {
|
|
20
|
-
item: NotificationItem;
|
|
21
|
-
leftPrimaryActionIcon?: ReactNode;
|
|
22
|
-
leftPrimaryActionTitle?: string;
|
|
23
|
-
leftPrimaryActionHandler?: (id: string) => void;
|
|
24
|
-
leftPrimaryActionStyle?: ViewStyle;
|
|
25
|
-
leftSecondaryActionIcon?: ReactNode;
|
|
26
|
-
leftSecondaryActionTitle?: string;
|
|
27
|
-
leftSecondaryActionHandler?: (id: string) => void;
|
|
28
|
-
leftSecondaryActionStyle?: ViewStyle;
|
|
29
|
-
rightPrimaryActionIcon?: ReactNode;
|
|
30
|
-
rightPrimaryActionTitle?: string;
|
|
31
|
-
rightPrimaryActionHandler?: (id: string) => void;
|
|
32
|
-
rightPrimaryActionStyle?: ViewStyle;
|
|
33
|
-
rightSecondaryActionIcon?: ReactNode;
|
|
34
|
-
rightSecondaryActionTitle?: string;
|
|
35
|
-
rightSecondaryActionHandler?: (id: string) => void;
|
|
36
|
-
rightSecondaryActionStyle?: ViewStyle;
|
|
37
|
-
itemStyle?: ViewStyle;
|
|
38
|
-
titleStyle?: ViewStyle;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface NotificationProps {
|
|
42
|
-
notifications: NotificationItem[];
|
|
43
|
-
leftPrimaryActionIcon?: ReactNode;
|
|
44
|
-
leftPrimaryActionTitle?: string;
|
|
45
|
-
leftPrimaryActionHandler?: (id: string) => void;
|
|
46
|
-
leftPrimaryActionStyle?: ViewStyle;
|
|
47
|
-
leftSecondaryActionIcon?: ReactNode;
|
|
48
|
-
leftSecondaryActionTitle?: string;
|
|
49
|
-
leftSecondaryActionHandler?: (id: string) => void;
|
|
50
|
-
leftSecondaryActionStyle?: ViewStyle;
|
|
51
|
-
rightPrimaryActionIcon?: ReactNode;
|
|
52
|
-
rightPrimaryActionTitle?: string;
|
|
53
|
-
rightPrimaryActionHandler?: (id: string) => void;
|
|
54
|
-
rightPrimaryActionStyle?: ViewStyle;
|
|
55
|
-
rightSecondaryActionIcon?: ReactNode;
|
|
56
|
-
rightSecondaryActionTitle?: string;
|
|
57
|
-
rightSecondaryActionHandler?: (id: string) => void;
|
|
58
|
-
rightSecondaryActionStyle?: ViewStyle;
|
|
59
|
-
itemStyle?: ViewStyle;
|
|
60
|
-
titleStyle?: ViewStyle;
|
|
61
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {DHRE_COLORS_ALERT} from '../../theme/colors';
|
|
2
|
-
import {horizontalScale, verticalScale} from '../../utils/stylehelper';
|
|
3
|
-
import {StyleSheet} from 'react-native';
|
|
4
|
-
|
|
5
|
-
export const styles = StyleSheet.create({
|
|
6
|
-
container: {
|
|
7
|
-
flex: 1,
|
|
8
|
-
},
|
|
9
|
-
item: {
|
|
10
|
-
backgroundColor: DHRE_COLORS_ALERT.DH_ALERT_ORANGE_0,
|
|
11
|
-
padding: horizontalScale(20),
|
|
12
|
-
marginHorizontal: horizontalScale(8),
|
|
13
|
-
},
|
|
14
|
-
actionButton: {
|
|
15
|
-
justifyContent: 'center',
|
|
16
|
-
padding: horizontalScale(12),
|
|
17
|
-
marginVertical: verticalScale(8),
|
|
18
|
-
},
|
|
19
|
-
leftActions: {
|
|
20
|
-
flexDirection: 'row',
|
|
21
|
-
justifyContent: 'flex-start',
|
|
22
|
-
},
|
|
23
|
-
rightActions: {
|
|
24
|
-
flexDirection: 'row',
|
|
25
|
-
justifyContent: 'flex-end',
|
|
26
|
-
},
|
|
27
|
-
sepratorView: {
|
|
28
|
-
marginVertical: verticalScale(8),
|
|
29
|
-
},
|
|
30
|
-
itemIconAlign: {
|
|
31
|
-
alignItems: 'center',
|
|
32
|
-
},
|
|
33
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {FlatList, View, Pressable} from 'react-native';
|
|
3
|
-
import {GestureHandlerRootView, Swipeable} from 'react-native-gesture-handler';
|
|
4
|
-
import {
|
|
5
|
-
ActionButtonProps,
|
|
6
|
-
ListItemProps,
|
|
7
|
-
NotificationItem,
|
|
8
|
-
NotificationProps,
|
|
9
|
-
} from './Notification.interface';
|
|
10
|
-
import {styles} from './Notification.styles';
|
|
11
|
-
import CustomTypography from '../customTypography/CustomTypography';
|
|
12
|
-
|
|
13
|
-
const Notification = ({
|
|
14
|
-
notifications,
|
|
15
|
-
leftPrimaryActionIcon,
|
|
16
|
-
leftPrimaryActionTitle,
|
|
17
|
-
leftPrimaryActionHandler,
|
|
18
|
-
leftPrimaryActionStyle,
|
|
19
|
-
leftSecondaryActionIcon,
|
|
20
|
-
leftSecondaryActionTitle,
|
|
21
|
-
leftSecondaryActionHandler,
|
|
22
|
-
leftSecondaryActionStyle,
|
|
23
|
-
rightPrimaryActionIcon,
|
|
24
|
-
rightPrimaryActionTitle,
|
|
25
|
-
rightPrimaryActionHandler,
|
|
26
|
-
rightPrimaryActionStyle,
|
|
27
|
-
rightSecondaryActionIcon,
|
|
28
|
-
rightSecondaryActionTitle,
|
|
29
|
-
rightSecondaryActionHandler,
|
|
30
|
-
rightSecondaryActionStyle,
|
|
31
|
-
itemStyle,
|
|
32
|
-
titleStyle,
|
|
33
|
-
}: NotificationProps) => {
|
|
34
|
-
const ActionButton = ({
|
|
35
|
-
icon,
|
|
36
|
-
title,
|
|
37
|
-
onPress,
|
|
38
|
-
style,
|
|
39
|
-
testID,
|
|
40
|
-
}: ActionButtonProps) => (
|
|
41
|
-
<Pressable
|
|
42
|
-
testID={testID}
|
|
43
|
-
onPress={onPress}
|
|
44
|
-
style={[styles.actionButton, style, styles.itemIconAlign]}>
|
|
45
|
-
{icon}
|
|
46
|
-
<CustomTypography variant="H9medium" style={titleStyle} text={title} />
|
|
47
|
-
</Pressable>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const leftActionHandle = item => (
|
|
51
|
-
<View style={[styles.leftActions, leftPrimaryActionStyle]}>
|
|
52
|
-
{leftPrimaryActionIcon && leftPrimaryActionHandler && (
|
|
53
|
-
<ActionButton
|
|
54
|
-
icon={leftPrimaryActionIcon}
|
|
55
|
-
title={leftPrimaryActionTitle || ''}
|
|
56
|
-
onPress={() => leftPrimaryActionHandler(item.id)}
|
|
57
|
-
style={leftPrimaryActionStyle}
|
|
58
|
-
testID={`leftPrimary-${item.id}`}
|
|
59
|
-
/>
|
|
60
|
-
)}
|
|
61
|
-
{leftSecondaryActionIcon && leftSecondaryActionHandler && (
|
|
62
|
-
<ActionButton
|
|
63
|
-
icon={leftSecondaryActionIcon}
|
|
64
|
-
title={leftSecondaryActionTitle || ''}
|
|
65
|
-
onPress={() => leftSecondaryActionHandler(item.id)}
|
|
66
|
-
style={leftSecondaryActionStyle}
|
|
67
|
-
testID={`leftSecondary-${item.id}`}
|
|
68
|
-
/>
|
|
69
|
-
)}
|
|
70
|
-
</View>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const rightActionHandle = item => (
|
|
74
|
-
<View style={[styles.rightActions, rightPrimaryActionStyle]}>
|
|
75
|
-
{rightPrimaryActionIcon && rightPrimaryActionHandler && (
|
|
76
|
-
<ActionButton
|
|
77
|
-
icon={rightPrimaryActionIcon}
|
|
78
|
-
title={rightPrimaryActionTitle || ''}
|
|
79
|
-
onPress={() => rightPrimaryActionHandler(item.id)}
|
|
80
|
-
style={rightPrimaryActionStyle}
|
|
81
|
-
testID={`rightPrimary-${item.id}`}
|
|
82
|
-
/>
|
|
83
|
-
)}
|
|
84
|
-
{rightSecondaryActionIcon && rightSecondaryActionHandler && (
|
|
85
|
-
<ActionButton
|
|
86
|
-
icon={rightSecondaryActionIcon}
|
|
87
|
-
title={rightSecondaryActionTitle || ''}
|
|
88
|
-
onPress={() => rightSecondaryActionHandler(item.id)}
|
|
89
|
-
style={rightSecondaryActionStyle}
|
|
90
|
-
testID={`rightSecondary-${item.id}`}
|
|
91
|
-
/>
|
|
92
|
-
)}
|
|
93
|
-
</View>
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const ListItem = ({item, itemStyle, titleStyle}: ListItemProps) => (
|
|
97
|
-
<GestureHandlerRootView testID="LIST" style={styles.container}>
|
|
98
|
-
<Swipeable
|
|
99
|
-
renderLeftActions={() => leftActionHandle(item)}
|
|
100
|
-
renderRightActions={() => rightActionHandle(item)}>
|
|
101
|
-
<View style={[styles.item, itemStyle]}>
|
|
102
|
-
<CustomTypography
|
|
103
|
-
variant="H7medium"
|
|
104
|
-
style={titleStyle}
|
|
105
|
-
text={item?.title}
|
|
106
|
-
/>
|
|
107
|
-
</View>
|
|
108
|
-
</Swipeable>
|
|
109
|
-
</GestureHandlerRootView>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const sortData = (data: NotificationItem[]) => {
|
|
113
|
-
return data?.sort((a, b) => {
|
|
114
|
-
if (a.isPinned && !b.isPinned) return -1;
|
|
115
|
-
if (!a.isPinned && b.isPinned) return 1;
|
|
116
|
-
return 0;
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const renderItem = ({item}: {item: NotificationItem}) => (
|
|
121
|
-
<ListItem
|
|
122
|
-
item={item}
|
|
123
|
-
leftPrimaryActionIcon={leftPrimaryActionIcon}
|
|
124
|
-
leftPrimaryActionTitle={leftPrimaryActionTitle}
|
|
125
|
-
leftPrimaryActionHandler={leftPrimaryActionHandler}
|
|
126
|
-
leftPrimaryActionStyle={leftPrimaryActionStyle}
|
|
127
|
-
leftSecondaryActionIcon={leftSecondaryActionIcon}
|
|
128
|
-
leftSecondaryActionTitle={leftSecondaryActionTitle}
|
|
129
|
-
leftSecondaryActionHandler={leftSecondaryActionHandler}
|
|
130
|
-
leftSecondaryActionStyle={leftSecondaryActionStyle}
|
|
131
|
-
rightPrimaryActionIcon={rightPrimaryActionIcon}
|
|
132
|
-
rightPrimaryActionTitle={rightPrimaryActionTitle}
|
|
133
|
-
rightPrimaryActionHandler={rightPrimaryActionHandler}
|
|
134
|
-
rightPrimaryActionStyle={rightPrimaryActionStyle}
|
|
135
|
-
rightSecondaryActionIcon={rightSecondaryActionIcon}
|
|
136
|
-
rightSecondaryActionTitle={rightSecondaryActionTitle}
|
|
137
|
-
rightSecondaryActionHandler={rightSecondaryActionHandler}
|
|
138
|
-
rightSecondaryActionStyle={rightSecondaryActionStyle}
|
|
139
|
-
itemStyle={itemStyle}
|
|
140
|
-
titleStyle={titleStyle}
|
|
141
|
-
/>
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<View testID="NOTIFICATION">
|
|
146
|
-
<FlatList
|
|
147
|
-
data={sortData(notifications)}
|
|
148
|
-
renderItem={renderItem}
|
|
149
|
-
keyExtractor={item => item.id}
|
|
150
|
-
ItemSeparatorComponent={() => <View style={styles.sepratorView} />}
|
|
151
|
-
/>
|
|
152
|
-
</View>
|
|
153
|
-
);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export default Notification;
|