From 3ec09d57ee731eab485442bbb91abf66ba677fc7 Mon Sep 17 00:00:00 2001 From: goztrk Date: Mon, 6 May 2024 21:15:27 +0300 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E2=9C=A8=20confirm=20dialog=20comp?= =?UTF-8?q?onent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Dialogs/Confirm.tsx | 150 +++++++++++++++++++++++++++++++++ components/Dialogs/index.ts | 1 + components/README.md | 118 ++++++++++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 components/Dialogs/Confirm.tsx create mode 100644 components/Dialogs/index.ts create mode 100644 components/README.md diff --git a/components/Dialogs/Confirm.tsx b/components/Dialogs/Confirm.tsx new file mode 100644 index 00000000..f946c172 --- /dev/null +++ b/components/Dialogs/Confirm.tsx @@ -0,0 +1,150 @@ +import React from 'react'; + +import { + Card, + Colors, + Dialog, + Text, + TouchableOpacity, + View, +} from 'react-native-ui-lib'; + +export interface ConfirmDialogProps { + /** + * The title of the dialog + */ + title: string; + + /** + * The function to call when the confirm button is pressed + */ + onConfirm: () => void; + + /** + * The description text if title is not enough + */ + children?: React.ReactNode; + + /** + * The text to display on the confirm button + * @default 'Yes' + */ + confirmText?: string; + + /** + * The text to display on the cancel button + * @default 'No' + */ + cancelText?: string; + + /** + * The color of the confirm button + * @default '$textSuccess' + */ + confirmColor?: keyof typeof Colors; + + /** + * The color of the cancel button + * @default '$textDefault' + */ + cancelColor?: keyof typeof Colors; +} + +export type ConfirmDialogRef = { + /** + * Open the dialog + */ + open: () => void; +}; + +/** + * A dialog that asks the user to confirm an action + * + * @example + * ```tsx + * const ref = React.useRef(null); + * + * const handlePress = () => { + * ref.current?.open(); + * }; + * + * const handleDialogConfirm = () => { + * ref.current?.close(); + * // do something + * }; + * + * return ( + * <> + * + * Are you sure you want to save this session? + * + *