diff --git a/components/Dialogs/Confirm/HorizontalButtons.tsx b/components/Dialogs/Confirm/HorizontalButtons.tsx new file mode 100644 index 00000000..aa4765fd --- /dev/null +++ b/components/Dialogs/Confirm/HorizontalButtons.tsx @@ -0,0 +1,77 @@ +import React from 'react'; + +import { Colors, Text, TouchableOpacity, View } from 'react-native-ui-lib'; + +import { useUpdate } from './context'; + +export interface ConfirmDialogHorizontalButtonsProps { + /** + * The function to call when the confirm button is pressed + */ + onConfirm: () => void; + + /** + * 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 const HorizontalButtons = ({ + onConfirm, + cancelText = 'No', + confirmText = 'Yes', + cancelColor = '$textDanger', + confirmColor = '$textSuccess', +}: ConfirmDialogHorizontalButtonsProps) => { + const update = useUpdate(); + + const handleClose = () => update({ visible: false }); + + const handleConfirm = () => { + handleClose(); + onConfirm(); + }; + + return ( + + + + {cancelText} + + + + + {confirmText} + + + + ); +}; +HorizontalButtons.displayName = 'ConfirmDialog.HorizontalButtons'; diff --git a/components/Dialogs/Confirm/Root.tsx b/components/Dialogs/Confirm/Root.tsx new file mode 100644 index 00000000..c509daad --- /dev/null +++ b/components/Dialogs/Confirm/Root.tsx @@ -0,0 +1,72 @@ +import React from 'react'; + +import { Card, Dialog } from 'react-native-ui-lib'; + +import { useContext, useUpdate } from './context'; + +export interface ConfirmDialogProps { + /** + * The description text if title is not enough + */ + children?: React.ReactNode; +} + +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 ( + * <> + * + * Save Session + * Are you sure you want to save this session? + * + * + *