|
1 | 1 | import React, {forwardRef, type ReactNode} from 'react'; |
2 | | -import {Text, View, TouchableOpacity, type StyleProp, type TextStyle, type ViewProps} from 'react-native'; |
| 2 | +import {Text, View, type StyleProp, type TextStyle, type ViewProps} from 'react-native'; |
3 | 3 |
|
4 | 4 | import {styles} from './basic-dialog.styles'; |
5 | 5 | import {useTheme} from '../../theme/useTheme.hook'; |
6 | 6 | import {Dialog, type DialogRef} from '../dialog/Dialog.component'; |
7 | 7 | import {useTypography} from '../../typography/useTypography.component'; |
| 8 | +import {TextButton} from '../../buttons/common-buttons/text-button/TextButton.component'; |
8 | 9 |
|
9 | 10 | export interface BasicDialogProps extends ViewProps { |
10 | 11 | append?: ReactNode; |
@@ -43,26 +44,23 @@ export const BasicDialog = forwardRef<DialogRef, BasicDialogProps>( |
43 | 44 | }, |
44 | 45 | ref |
45 | 46 | ) => { |
46 | | - const {bodyMedium, headlineSmall, labelLarge} = useTypography(); |
47 | | - const {surfaceContainer, primaryContainer} = useTheme(); |
| 47 | + const {surfaceContainer} = useTheme(); |
| 48 | + const {bodyMedium, headlineSmall} = useTypography(); |
| 49 | + |
| 50 | + const renderActionButtons = () => ( |
| 51 | + <View style={styles.actions}> |
| 52 | + {secondActionTitle ? <TextButton style={styles.actionButton} onPress={onSecondActionPress} title={secondActionTitle} /> : null} |
| 53 | + {firstActionTitle ? <TextButton style={styles.actionButton} onPress={onFirstActionPress} title={firstActionTitle} /> : null} |
| 54 | + </View> |
| 55 | + ); |
48 | 56 |
|
49 | 57 | return ( |
50 | 58 | <Dialog ref={ref} style={[style]} {...props}> |
51 | 59 | {prepend} |
52 | 60 | {title ? <Text style={[headlineSmall, styles.title, {color: surfaceContainer.text}, titleStyle]}>{title}</Text> : null} |
53 | 61 | {subtitle ? <Text style={[bodyMedium, {color: surfaceContainer.textVariant}, subtitleStyle]}>{subtitle}</Text> : null} |
54 | 62 | {append} |
55 | | - {firstActionTitle && ( |
56 | | - <View style={styles.actions}> |
57 | | - {/* Todo: replace with libriry's text buttons */} |
58 | | - <TouchableOpacity onPress={onSecondActionPress}> |
59 | | - <Text style={[labelLarge, {color: primaryContainer.text}]}>{secondActionTitle}</Text> |
60 | | - </TouchableOpacity> |
61 | | - <TouchableOpacity onPress={onFirstActionPress}> |
62 | | - <Text style={[labelLarge, {color: primaryContainer.text}]}>{firstActionTitle}</Text> |
63 | | - </TouchableOpacity> |
64 | | - </View> |
65 | | - )} |
| 63 | + {firstActionTitle ? renderActionButtons() : null} |
66 | 64 | </Dialog> |
67 | 65 | ); |
68 | 66 | } |
|
0 commit comments