From e5dbcb670b9658db43b56b9d24c922034787c8a4 Mon Sep 17 00:00:00 2001 From: Luke Walczak Date: Mon, 23 May 2022 22:40:43 +0200 Subject: [PATCH] feat: adjust Dialog components, introduce DialogIcon (#3079) --- example/src/Examples/DialogExample.tsx | 19 +++- .../Examples/Dialogs/DialogTextComponent.tsx | 34 +++++++ .../Dialogs/DialogWithCustomColors.tsx | 62 +++++++----- .../src/Examples/Dialogs/DialogWithIcon.tsx | 40 ++++++++ .../Dialogs/DialogWithLoadingIndicator.tsx | 46 +++++---- .../Examples/Dialogs/DialogWithLongText.tsx | 9 +- .../Examples/Dialogs/DialogWithRadioBtns.tsx | 18 +++- .../Examples/Dialogs/UndismissableDialog.tsx | 15 +-- example/src/Examples/Dialogs/index.tsx | 1 + src/components/Dialog/Dialog.tsx | 97 ++++++++++++------- src/components/Dialog/DialogActions.tsx | 43 +++++--- src/components/Dialog/DialogIcon.tsx | 88 +++++++++++++++++ src/components/Dialog/DialogScrollArea.tsx | 35 +++++-- src/components/Dialog/DialogTitle.tsx | 39 +++++--- src/components/Modal.tsx | 4 +- 15 files changed, 418 insertions(+), 132 deletions(-) create mode 100644 example/src/Examples/Dialogs/DialogTextComponent.tsx create mode 100644 example/src/Examples/Dialogs/DialogWithIcon.tsx create mode 100644 src/components/Dialog/DialogIcon.tsx diff --git a/example/src/Examples/DialogExample.tsx b/example/src/Examples/DialogExample.tsx index 0d043ba470..add3a59427 100644 --- a/example/src/Examples/DialogExample.tsx +++ b/example/src/Examples/DialogExample.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; -import { Button } from 'react-native-paper'; +import { Button, useTheme } from 'react-native-paper'; import ScreenWrapper from '../ScreenWrapper'; import { DialogWithCustomColors, @@ -8,6 +8,7 @@ import { DialogWithLongText, DialogWithRadioBtns, UndismissableDialog, + DialogWithIcon, } from './Dialogs'; type ButtonVisibility = { @@ -16,6 +17,7 @@ type ButtonVisibility = { const DialogExample = () => { const [visible, setVisible] = React.useState({}); + const { isV3 } = useTheme(); const _toggleDialog = (name: string) => () => setVisible({ ...visible, [name]: !visible[name] }); @@ -59,6 +61,15 @@ const DialogExample = () => { > Custom colors + {isV3 && ( + + )} { visible={_getVisible('dialog5')} close={_toggleDialog('dialog5')} /> + {isV3 && ( + + )} ); }; diff --git a/example/src/Examples/Dialogs/DialogTextComponent.tsx b/example/src/Examples/Dialogs/DialogTextComponent.tsx new file mode 100644 index 0000000000..0104c0041a --- /dev/null +++ b/example/src/Examples/Dialogs/DialogTextComponent.tsx @@ -0,0 +1,34 @@ +import * as React from 'react'; +import type { StyleProp, TextStyle } from 'react-native'; +import { + Paragraph, + Text, + Text as NativeText, + useTheme, + Subheading, +} from 'react-native-paper'; +import type { MD3TypescaleKey } from '../../../../src/types'; + +type Props = React.ComponentProps & { + isSubheading?: boolean; + children: React.ReactNode; + style?: StyleProp; + variant?: keyof typeof MD3TypescaleKey; +}; + +export const TextComponent = ({ isSubheading = false, ...props }: Props) => { + const theme = useTheme(); + + if (theme.isV3) { + return ( + + ); + } else if (isSubheading) { + return ; + } + return ; +}; diff --git a/example/src/Examples/Dialogs/DialogWithCustomColors.tsx b/example/src/Examples/Dialogs/DialogWithCustomColors.tsx index a433586196..ed4ef3a453 100644 --- a/example/src/Examples/Dialogs/DialogWithCustomColors.tsx +++ b/example/src/Examples/Dialogs/DialogWithCustomColors.tsx @@ -1,38 +1,54 @@ import * as React from 'react'; import { - Paragraph, Button, Portal, Dialog, MD2Colors, + useTheme, + MD3Colors, } from 'react-native-paper'; - +import { TextComponent } from './DialogTextComponent'; const DialogWithCustomColors = ({ visible, close, }: { visible: boolean; close: () => void; -}) => ( - - - Alert - - - This is a dialog with custom colors - - - - - - - -); +}) => { + const { isV3 } = useTheme(); + + return ( + + + + Alert + + + + This is a dialog with custom colors + + + + + + + + ); +}; export default DialogWithCustomColors; diff --git a/example/src/Examples/Dialogs/DialogWithIcon.tsx b/example/src/Examples/Dialogs/DialogWithIcon.tsx new file mode 100644 index 0000000000..18a35b8d13 --- /dev/null +++ b/example/src/Examples/Dialogs/DialogWithIcon.tsx @@ -0,0 +1,40 @@ +import * as React from 'react'; +import { StyleSheet } from 'react-native'; +import { Button, Portal, Dialog, MD3Colors } from 'react-native-paper'; +import { TextComponent } from './DialogTextComponent'; + +const DialogWithIcon = ({ + visible, + close, +}: { + visible: boolean; + close: () => void; +}) => { + return ( + + + + Dialog with Icon + + + This is a dialog with new component called DialogIcon. When icon is + displayed you should center the header. + + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + title: { + textAlign: 'center', + }, +}); +export default DialogWithIcon; diff --git a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx index e70b4153de..5f6bad323c 100644 --- a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx +++ b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx @@ -1,6 +1,13 @@ import * as React from 'react'; import { ActivityIndicator, Platform, View, StyleSheet } from 'react-native'; -import { Paragraph, MD2Colors, Portal, Dialog } from 'react-native-paper'; +import { + MD2Colors, + Portal, + Dialog, + useTheme, + MD3Colors, +} from 'react-native-paper'; +import { TextComponent } from './DialogTextComponent'; const isIOS = Platform.OS === 'ios'; @@ -10,23 +17,26 @@ const DialogWithLoadingIndicator = ({ }: { visible: boolean; close: () => void; -}) => ( - - - Progress Dialog - - - - Loading..... - - - - -); +}) => { + const { isV3 } = useTheme(); + return ( + + + Progress Dialog + + + + Loading..... + + + + + ); +}; const styles = StyleSheet.create({ flexing: { diff --git a/example/src/Examples/Dialogs/DialogWithLongText.tsx b/example/src/Examples/Dialogs/DialogWithLongText.tsx index c6d9de0076..90313aee5c 100644 --- a/example/src/Examples/Dialogs/DialogWithLongText.tsx +++ b/example/src/Examples/Dialogs/DialogWithLongText.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { Dimensions, ScrollView, StyleSheet } from 'react-native'; -import { Paragraph, Button, Portal, Dialog } from 'react-native-paper'; +import { Button, Portal, Dialog } from 'react-native-paper'; +import { TextComponent } from './DialogTextComponent'; const DialogWithLongText = ({ visible, @@ -18,7 +19,7 @@ const DialogWithLongText = ({ Alert - + Material is the metaphor {'\n'} {'\n'}A material metaphor is the unifying theory of a rationalized @@ -56,11 +57,11 @@ const DialogWithLongText = ({ conveying how objects move, interact, and exist in space and in relation to each other. Realistic lighting shows seams, divides space, and indicates moving parts. - + - + diff --git a/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx b/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx index 4d982a3a1a..ecc2cd626f 100644 --- a/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx +++ b/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx @@ -1,13 +1,13 @@ import * as React from 'react'; import { ScrollView, View, StyleSheet } from 'react-native'; import { - Subheading, Button, Portal, Dialog, RadioButton, TouchableRipple, } from 'react-native-paper'; +import { TextComponent } from './DialogTextComponent'; type Props = { visible: boolean; @@ -34,7 +34,9 @@ const DialogWithRadioBtns = ({ visible, close }: Props) => { status={checked === 'normal' ? 'checked' : 'unchecked'} /> - Option 1 + + Option 1 + setChecked('second')}> @@ -45,7 +47,9 @@ const DialogWithRadioBtns = ({ visible, close }: Props) => { status={checked === 'second' ? 'checked' : 'unchecked'} /> - Option 2 + + Option 2 + setChecked('third')}> @@ -56,7 +60,9 @@ const DialogWithRadioBtns = ({ visible, close }: Props) => { status={checked === 'third' ? 'checked' : 'unchecked'} /> - Option 3 + + Option 3 + setChecked('fourth')}> @@ -67,7 +73,9 @@ const DialogWithRadioBtns = ({ visible, close }: Props) => { status={checked === 'fourth' ? 'checked' : 'unchecked'} /> - Option 4 + + Option 4 + diff --git a/example/src/Examples/Dialogs/UndismissableDialog.tsx b/example/src/Examples/Dialogs/UndismissableDialog.tsx index 41b3e6ea34..30724c5485 100644 --- a/example/src/Examples/Dialogs/UndismissableDialog.tsx +++ b/example/src/Examples/Dialogs/UndismissableDialog.tsx @@ -1,13 +1,8 @@ import * as React from 'react'; -import { - Paragraph, - Button, - Portal, - Dialog, - MD2Colors, -} from 'react-native-paper'; +import { Button, Portal, Dialog, MD2Colors } from 'react-native-paper'; +import { TextComponent } from './DialogTextComponent'; -const DialogWithLongText = ({ +const UndismissableDialog = ({ visible, close, }: { @@ -18,7 +13,7 @@ const DialogWithLongText = ({ Alert - This is an undismissable dialog!! + This is an undismissable dialog!!