-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adjust Dialog components, introduce DialogIcon (#3079)
- Loading branch information
1 parent
2f7ef4b
commit e5dbcb6
Showing
15 changed files
with
418 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof NativeText> & { | ||
isSubheading?: boolean; | ||
children: React.ReactNode; | ||
style?: StyleProp<TextStyle>; | ||
variant?: keyof typeof MD3TypescaleKey; | ||
}; | ||
|
||
export const TextComponent = ({ isSubheading = false, ...props }: Props) => { | ||
const theme = useTheme(); | ||
|
||
if (theme.isV3) { | ||
return ( | ||
<Text | ||
variant={isSubheading ? 'bodyLarge' : 'bodyMedium'} | ||
style={{ color: theme.colors.onSurfaceVariant }} | ||
{...props} | ||
/> | ||
); | ||
} else if (isSubheading) { | ||
return <Subheading {...props} />; | ||
} | ||
return <Paragraph {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}) => ( | ||
<Portal> | ||
<Dialog | ||
onDismiss={close} | ||
style={{ backgroundColor: MD2Colors.purple900 }} | ||
visible={visible} | ||
> | ||
<Dialog.Title style={{ color: MD2Colors.white }}>Alert</Dialog.Title> | ||
<Dialog.Content> | ||
<Paragraph style={{ color: MD2Colors.white }}> | ||
This is a dialog with custom colors | ||
</Paragraph> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<Button color={MD2Colors.white} onPress={close}> | ||
OK | ||
</Button> | ||
</Dialog.Actions> | ||
</Dialog> | ||
</Portal> | ||
); | ||
}) => { | ||
const { isV3 } = useTheme(); | ||
|
||
return ( | ||
<Portal> | ||
<Dialog | ||
onDismiss={close} | ||
style={{ | ||
backgroundColor: isV3 ? MD3Colors.primary10 : MD2Colors.purple900, | ||
}} | ||
visible={visible} | ||
> | ||
<Dialog.Title | ||
style={{ color: isV3 ? MD3Colors.primary95 : MD2Colors.white }} | ||
> | ||
Alert | ||
</Dialog.Title> | ||
<Dialog.Content> | ||
<TextComponent | ||
style={{ color: isV3 ? MD3Colors.primary95 : MD2Colors.white }} | ||
> | ||
This is a dialog with custom colors | ||
</TextComponent> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<Button | ||
color={isV3 ? MD3Colors.primary95 : MD2Colors.white} | ||
onPress={close} | ||
> | ||
Ok | ||
</Button> | ||
</Dialog.Actions> | ||
</Dialog> | ||
</Portal> | ||
); | ||
}; | ||
|
||
export default DialogWithCustomColors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Portal> | ||
<Dialog onDismiss={close} visible={visible}> | ||
<Dialog.Icon icon="alert" /> | ||
<Dialog.Title style={styles.title}>Dialog with Icon</Dialog.Title> | ||
<Dialog.Content> | ||
<TextComponent> | ||
This is a dialog with new component called DialogIcon. When icon is | ||
displayed you should center the header. | ||
</TextComponent> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<Button onPress={close} color={MD3Colors.error50}> | ||
Disagree | ||
</Button> | ||
<Button onPress={close}>Agree</Button> | ||
</Dialog.Actions> | ||
</Dialog> | ||
</Portal> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
title: { | ||
textAlign: 'center', | ||
}, | ||
}); | ||
export default DialogWithIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.