Skip to content

Commit c8051a1

Browse files
committed
completed the package
1 parent 7cf5536 commit c8051a1

File tree

5 files changed

+97
-76
lines changed

5 files changed

+97
-76
lines changed

README.md

Whitespace-only changes.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@irfanwani/rn-dialog",
2+
"name": "@irfanwani/react-native-dialog",
33
"version": "0.0.1",
44
"description": "This is a typescript package for react native apps to display a dialog box",
55
"main": "lib/index.js",
@@ -10,7 +10,7 @@
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/irfanwani/rn-dialog.git"
13+
"url": "git+https://github.com/irfanwani/react-native-dialog.git"
1414
},
1515
"keywords": [
1616
"react-native",
@@ -21,11 +21,11 @@
2121
"rn-dialog"
2222
],
2323
"author": "Irfanwani <irfanwani347@gmail.com>",
24-
"license": "ISC",
24+
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/irfanwani/rn-dialog/issues"
26+
"url": "https://github.com/irfanwani/react-native-dialog/issues"
2727
},
28-
"homepage": "https://github.com/irfanwani/rn-dialog#readme",
28+
"homepage": "https://github.com/irfanwani/react-native-dialog#readme",
2929
"devDependencies": {
3030
"@types/react": "^18.0.0",
3131
"@types/react-native": "^0.69",

src/index.tsx

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
1-
import { FC, useState, useEffect } from 'react';
1+
import { FC, useState, useEffect } from "react";
22
import {
33
View,
44
TouchableOpacity,
55
Text,
66
GestureResponderEvent,
7-
StyleSheet,
8-
Dimensions,
9-
Button,
10-
} from 'react-native';
7+
} from "react-native";
118

12-
import * as Animatable from 'react-native-animatable';
9+
import * as Animatable from "react-native-animatable";
1310

14-
import styles from './styles'
11+
import styles from "./styles";
12+
13+
// ADD OTHER PROPS LIKE CONFIRM STYLES, CANCEL STYLES,OTHER STYLES AS PROPS TO SUPPORT DYNAMIC STYLING, CHANGE TITLE, SUBTTILE FROM STRING TO REACT COMPONENTS FOR MORE CUSTOMIZATION OPTIONS, DARK AND LIGHT MODE, LINEARGRADIENT(OPTIONAL), BACKDROP (CLOSE WHEN CLICKED OUTSIDE DIALOG).
1514

1615
interface DialogProps {
1716
visible: boolean;
17+
title: string;
18+
subtitle: string;
1819
closeDialog: (event: GestureResponderEvent) => void;
1920
confirm: (event: GestureResponderEvent) => void;
21+
confirmText: string;
22+
titleStyle?: Object;
23+
cancelStyle?: Object;
24+
confirmStyle?: Object;
25+
subtitleStyle?: Object;
26+
cancelTextStyle?: Object;
27+
cancelText: string;
28+
confirmTextStyle?: Object;
2029
}
2130

22-
const Dialog: FC<DialogProps> = ({ visible, closeDialog, confirm }) => {
31+
const Dialog: FC<DialogProps> = ({
32+
visible,
33+
title,
34+
subtitle,
35+
closeDialog,
36+
confirm,
37+
confirmText,
38+
confirmTextStyle,
39+
titleStyle,
40+
cancelStyle,
41+
confirmStyle,
42+
subtitleStyle,
43+
cancelTextStyle,
44+
cancelText,
45+
}) => {
2346
const [visiblest, setvisible] = useState(visible);
2447

2548
useEffect(() => {
@@ -34,20 +57,27 @@ const Dialog: FC<DialogProps> = ({ visible, closeDialog, confirm }) => {
3457

3558
if (visiblest) {
3659
return (
37-
<View style={styles.dialog}>
60+
<View style={styles.dialog} onTouchEnd={closeDialog}>
3861
<Animatable.View
39-
animation={visible ? 'zoomIn' : 'zoomOut'}
62+
animation={visible ? "zoomIn" : "zoomOut"}
4063
style={styles.dialogbox}
41-
duration={250}>
42-
<Text style={styles.warning}>Are you Sure?</Text>
43-
<Text>This action cannot be reverted.</Text>
64+
duration={250}
65+
>
66+
<Text style={[styles.warning, titleStyle]}>{title}</Text>
67+
<Text style={subtitleStyle}>{subtitle}</Text>
4468

4569
<View style={styles.card}>
46-
<TouchableOpacity onPress={closeDialog} style={styles.cancel}>
47-
<Text>Cancel</Text>
70+
<TouchableOpacity
71+
onPress={closeDialog}
72+
style={[styles.cancel, cancelStyle]}
73+
>
74+
<Text style={cancelTextStyle}>{cancelText}</Text>
4875
</TouchableOpacity>
49-
<TouchableOpacity onPress={confirm} style={styles.confirm}>
50-
<Text>Delete</Text>
76+
<TouchableOpacity
77+
onPress={confirm}
78+
style={[styles.confirm, confirmStyle]}
79+
>
80+
<Text style={confirmTextStyle}>{confirmText}</Text>
5181
</TouchableOpacity>
5282
</View>
5383
</Animatable.View>
@@ -58,5 +88,4 @@ const Dialog: FC<DialogProps> = ({ visible, closeDialog, confirm }) => {
5888
return <></>;
5989
};
6090

61-
6291
export default Dialog;

src/styles.ts

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,47 @@
1-
import {StyleSheet, Dimensions} from 'react-native'
2-
1+
import { StyleSheet, Dimensions } from "react-native";
32

43
const styles = StyleSheet.create({
5-
card: {
6-
flexDirection: 'row',
7-
justifyContent: 'space-between',
8-
borderColor: 'grey',
9-
borderWidth: 0.5,
10-
padding: 15,
11-
marginHorizontal: 10,
12-
marginVertical: 5,
13-
borderRadius: 10,
14-
backgroundColor: 'rgba(50, 50, 50, 0.1)',
15-
},
16-
warning: {
17-
color: 'red',
18-
fontSize: 20,
19-
alignSelf: 'center',
20-
marginBottom: 20,
21-
},
22-
cancel: {
23-
borderWidth: 0.5,
24-
borderColor: 'grey',
25-
padding: 10,
26-
borderRadius: 10,
27-
backgroundColor: 'rgba(50, 50, 50, 0.3)',
28-
},
29-
confirm: {
30-
borderWidth: 0.5,
31-
borderColor: 'red',
32-
padding: 10,
33-
borderRadius: 10,
34-
backgroundColor: 'rgba(255, 0, 0, 0.4)',
35-
},
36-
dialog: {
37-
flex: 1,
38-
position: 'absolute',
39-
backgroundColor: 'rgba(50, 50, 50, 0.4)',
40-
width: Dimensions.get('window').width,
41-
height: Dimensions.get('window').height,
42-
marginTop: 30,
43-
justifyContent: 'center',
44-
alignItems: 'center',
45-
elevation: 5,
46-
},
47-
dialogbox: {
48-
backgroundColor: 'white',
49-
padding: 20,
50-
borderRadius: 20,
51-
justifyContent: 'space-between',
52-
},
53-
});
4+
card: {
5+
flexDirection: "row",
6+
justifyContent: "space-between",
7+
marginHorizontal: 10,
8+
marginVertical: 5,
9+
padding: 10
10+
},
11+
warning: {
12+
fontSize: 20,
13+
alignSelf: "center",
14+
marginBottom: 20,
15+
},
16+
cancel: {
17+
borderWidth: 0.5,
18+
borderColor: "grey",
19+
padding: 10,
20+
borderRadius: 10,
21+
backgroundColor: "rgba(50, 50, 50, 0.3)",
22+
},
23+
confirm: {
24+
borderWidth: 0.5,
25+
borderColor: "green",
26+
padding: 10,
27+
borderRadius: 10,
28+
backgroundColor: "rgba(100, 255, 100, 0.7)",
29+
},
30+
dialog: {
31+
position: "absolute",
32+
backgroundColor: "rgba(50, 50, 50, 0.4)",
33+
width: Dimensions.get("window").width,
34+
height: Dimensions.get("window").height,
35+
justifyContent: "center",
36+
alignItems: "center",
37+
zIndex: 999,
38+
},
39+
dialogbox: {
40+
backgroundColor: "white",
41+
padding: 20,
42+
borderRadius: 20,
43+
justifyContent: "space-between"
44+
},
45+
});
5446

55-
export default styles;
47+
export default styles;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/* Modules */
3131
"module": "ESNext" /* Specify what module code is generated. */,
3232
// "rootDir": "./", /* Specify the root folder within your source files. */
33-
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
33+
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
3434
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3535
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3636
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */

0 commit comments

Comments
 (0)