-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathDialogIcon.tsx
100 lines (89 loc) · 2.02 KB
/
DialogIcon.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import type { ThemeProp } from 'src/types';
import { useInternalTheme } from '../../core/theming';
import Icon, { IconSource } from '../Icon';
export type Props = {
/**
* Custom color for action icon.
*/
color?: string;
/**
* Name of the icon to show.
*/
icon: IconSource;
/**
* Optional icon size.
*/
size?: number;
/**
* @optional
*/
theme?: ThemeProp;
};
/**
* @supported Available in v5.x with theme version 3
* A component to show an icon in a Dialog.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { StyleSheet } from 'react-native';
* import { Dialog, Portal, Text } from 'react-native-paper';
*
* const MyComponent = () => {
* const [visible, setVisible] = React.useState(false);
*
* const hideDialog = () => setVisible(false);
*
* return (
* <Portal>
* <Dialog visible={visible} onDismiss={hideDialog}>
* <Dialog.Icon icon="alert" />
* <Dialog.Title style={styles.title}>This is a title</Dialog.Title>
* <Dialog.Content>
* <Text variant="bodyMedium">This is simple dialog</Text>
* </Dialog.Content>
* </Dialog>
* </Portal>
* );
* };
*
* const styles = StyleSheet.create({
* title: {
* textAlign: 'center',
* },
* })
*
* export default MyComponent;
* ```
*/
const DialogIcon = ({
size = 24,
color,
icon,
theme: themeOverrides,
}: Props) => {
const theme = useInternalTheme(themeOverrides);
if (!theme.isV3) {
return null;
}
//@ts-ignore
const iconColor = color || theme.colors.secondary;
return (
<View style={styles.wrapper}>
<Icon source={icon} color={iconColor} size={size} />
</View>
);
};
DialogIcon.displayName = 'Dialog.Icon';
const styles = StyleSheet.create({
wrapper: {
alignItems: 'center',
justifyContent: 'center',
paddingTop: 24,
},
});
export default DialogIcon;
// @component-docs ignore-next-line
export { DialogIcon };