-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathAppbarAction.tsx
More file actions
118 lines (109 loc) · 2.84 KB
/
AppbarAction.tsx
File metadata and controls
118 lines (109 loc) · 2.84 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as React from 'react';
import type { Animated, StyleProp, View, ViewStyle } from 'react-native';
import type { ThemeProp } from 'src/types';
import { useInternalTheme } from '../../core/theming';
import type { MD3Theme } from '../../types';
import { forwardRef } from '../../utils/forwardRef';
import type { IconSource } from '../Icon';
import IconButton from '../IconButton/IconButton';
export type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {
/**
* Custom color for action icon.
*/
color?: string;
/**
* Name of the icon to show.
*/
icon: IconSource;
/**
* Optional icon size.
*/
size?: number;
/**
* Whether the button is disabled. A disabled button is greyed out and `onPress` is not called on touch.
*/
disabled?: boolean;
/**
* Accessibility label for the button. This is read by the screen reader when the user taps the button.
*/
accessibilityLabel?: string;
/**
* Function to execute on press.
*/
onPress?: () => void;
/**
* @supported Available in v5.x with theme version 3
*
* Whether it's the leading button. Note: If `Appbar.BackAction` is present, it will be rendered before any `isLeading` icons.
*/
isLeading?: boolean;
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
ref?: React.RefObject<View>;
/**
* @optional
*/
theme?: ThemeProp;
};
/**
* A component used to display an action item in the appbar.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { Appbar } from 'react-native-paper';
* import { Platform } from 'react-native';
*
* const MORE_ICON = Platform.OS === 'ios' ? 'dots-horizontal' : 'dots-vertical';
*
* const MyComponent = () => (
* <Appbar.Header>
* <Appbar.Content title="Title" subtitle={'Subtitle'} />
* <Appbar.Action icon="magnify" onPress={() => {}} />
* <Appbar.Action icon={MORE_ICON} onPress={() => {}} />
* </Appbar.Header>
* );
*
* export default MyComponent;
* ```
*/
const AppbarAction = forwardRef<View, Props>(
(
{
size = 24,
color: iconColor,
icon,
disabled,
onPress,
accessibilityLabel,
isLeading,
theme: themeOverrides,
...rest
}: Props,
ref
) => {
const theme = useInternalTheme(themeOverrides);
const { colors } = theme as MD3Theme;
const actionIconColor = iconColor
? iconColor
: isLeading
? colors.onSurface
: colors.onSurfaceVariant;
return (
<IconButton
size={size}
onPress={onPress}
iconColor={actionIconColor}
icon={icon}
disabled={disabled}
accessibilityLabel={accessibilityLabel}
animated
ref={ref}
{...rest}
/>
);
}
);
AppbarAction.displayName = 'Appbar.Action';
export default AppbarAction;
// @component-docs ignore-next-line
export { AppbarAction };