UNPKG

7.65 kBTypeScriptView Raw
1import * as React from 'react';
2import { StyleProp, Animated, LayoutRectangle, ViewStyle } from 'react-native';
3import type { $Omit } from '../../types';
4declare type Props = {
5 /**
6 * Whether the Menu is currently visible.
7 */
8 visible: boolean;
9 /**
10 * The anchor to open the menu from. In most cases, it will be a button that opens the menu.
11 */
12 anchor: React.ReactNode | {
13 x: number;
14 y: number;
15 };
16 /**
17 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
18 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
19 * Pass `0` or a custom value to and customize it.
20 * This is automatically handled on iOS.
21 */
22 statusBarHeight?: number;
23 /**
24 * Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
25 */
26 onDismiss: () => void;
27 /**
28 * Accessibility label for the overlay. This is read by the screen reader when the user taps outside the menu.
29 */
30 overlayAccessibilityLabel?: string;
31 /**
32 * Content of the `Menu`.
33 */
34 children: React.ReactNode;
35 /**
36 * Style of menu's inner content.
37 */
38 contentStyle?: StyleProp<ViewStyle>;
39 style?: StyleProp<ViewStyle>;
40 /**
41 * @optional
42 */
43 theme: ReactNativePaper.Theme;
44};
45declare type Layout = $Omit<$Omit<LayoutRectangle, 'x'>, 'y'>;
46declare type State = {
47 rendered: boolean;
48 top: number;
49 left: number;
50 menuLayout: Layout;
51 anchorLayout: Layout;
52 opacityAnimation: Animated.Value;
53 scaleAnimation: Animated.ValueXY;
54};
55/**
56 * Menus display a list of choices on temporary elevated surfaces. Their placement varies based on the element that opens them.
57 *
58 * <div class="screenshots">
59 * <img class="medium" src="screenshots/menu-1.png" />
60 * <img class="medium" src="screenshots/menu-2.png" />
61 * </div>
62 *
63 * ## Usage
64 * ```js
65 * import * as React from 'react';
66 * import { View } from 'react-native';
67 * import { Button, Menu, Divider, Provider } from 'react-native-paper';
68 *
69 * const MyComponent = () => {
70 * const [visible, setVisible] = React.useState(false);
71 *
72 * const openMenu = () => setVisible(true);
73 *
74 * const closeMenu = () => setVisible(false);
75 *
76 * return (
77 * <Provider>
78 * <View
79 * style={{
80 * paddingTop: 50,
81 * flexDirection: 'row',
82 * justifyContent: 'center',
83 * }}>
84 * <Menu
85 * visible={visible}
86 * onDismiss={closeMenu}
87 * anchor={<Button onPress={openMenu}>Show menu</Button>}>
88 * <Menu.Item onPress={() => {}} title="Item 1" />
89 * <Menu.Item onPress={() => {}} title="Item 2" />
90 * <Divider />
91 * <Menu.Item onPress={() => {}} title="Item 3" />
92 * </Menu>
93 * </View>
94 * </Provider>
95 * );
96 * };
97 *
98 * export default MyComponent;
99 * ```
100 */
101declare class Menu extends React.Component<Props, State> {
102 static Item: React.ComponentType<Pick<{
103 title: React.ReactNode;
104 icon?: import("../Icon").IconSource | undefined;
105 disabled?: boolean | undefined;
106 onPress?: (() => void) | undefined;
107 style?: StyleProp<ViewStyle>;
108 contentStyle?: StyleProp<ViewStyle>; /**
109 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
110 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
111 * Pass `0` or a custom value to and customize it.
112 * This is automatically handled on iOS.
113 */
114 titleStyle?: StyleProp<import("react-native").TextStyle>;
115 theme: ReactNativePaper.Theme;
116 testID?: string | undefined;
117 accessibilityLabel?: string | undefined;
118 }, "style" | "title" | "onPress" | "testID" | "accessibilityLabel" | "icon" | "disabled" | "titleStyle" | "contentStyle"> & {
119 theme?: import("@callstack/react-theme-provider").$DeepPartial<ReactNativePaper.Theme> | undefined;
120 }> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<{
121 title: React.ReactNode;
122 icon?: import("../Icon").IconSource | undefined;
123 disabled?: boolean | undefined;
124 onPress?: (() => void) | undefined;
125 style?: StyleProp<ViewStyle>;
126 contentStyle?: StyleProp<ViewStyle>; /**
127 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
128 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
129 * Pass `0` or a custom value to and customize it.
130 * This is automatically handled on iOS.
131 */
132 titleStyle?: StyleProp<import("react-native").TextStyle>;
133 theme: ReactNativePaper.Theme;
134 testID?: string | undefined;
135 accessibilityLabel?: string | undefined;
136 }> & {
137 ({ icon, title, disabled, onPress, style, contentStyle, testID, titleStyle, accessibilityLabel, theme, }: {
138 title: React.ReactNode;
139 icon?: import("../Icon").IconSource | undefined;
140 disabled?: boolean | undefined;
141 onPress?: (() => void) | undefined;
142 style?: StyleProp<ViewStyle>;
143 contentStyle?: StyleProp<ViewStyle>; /**
144 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
145 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
146 * Pass `0` or a custom value to and customize it.
147 * This is automatically handled on iOS.
148 */
149 titleStyle?: StyleProp<import("react-native").TextStyle>;
150 theme: ReactNativePaper.Theme;
151 testID?: string | undefined;
152 accessibilityLabel?: string | undefined;
153 }): JSX.Element;
154 displayName: string;
155 }, {}>;
156 static defaultProps: {
157 statusBarHeight: any;
158 overlayAccessibilityLabel: string;
159 };
160 static getDerivedStateFromProps(nextProps: Props, prevState: State): {
161 rendered: boolean;
162 } | null;
163 state: {
164 rendered: boolean;
165 top: number;
166 left: number;
167 menuLayout: {
168 width: number;
169 height: number;
170 };
171 anchorLayout: {
172 width: number;
173 height: number;
174 };
175 opacityAnimation: Animated.Value;
176 scaleAnimation: Animated.ValueXY;
177 };
178 componentDidUpdate(prevProps: Props): void;
179 componentWillUnmount(): void;
180 private anchor?;
181 private menu?;
182 private backHandlerSubscription;
183 private dimensionsSubscription;
184 private isCoordinate;
185 private measureMenuLayout;
186 private measureAnchorLayout;
187 private updateVisibility;
188 private isBrowser;
189 private focusFirstDOMNode;
190 private handleDismiss;
191 private handleKeypress;
192 private attachListeners;
193 private removeListeners;
194 private show;
195 private hide;
196 render(): JSX.Element;
197}
198declare const _default: React.ComponentType<Pick<Props, "style" | "anchor" | "children" | "visible" | "contentStyle" | "statusBarHeight" | "onDismiss" | "overlayAccessibilityLabel"> & {
199 theme?: import("@callstack/react-theme-provider").$DeepPartial<ReactNativePaper.Theme> | undefined;
200}> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<Props> & typeof Menu, {}>;
201export default _default;
202
\No newline at end of file