UNPKG

4.69 kBTypeScriptView Raw
1import * as React from 'react';
2import { Animated, ScrollViewProps, StyleProp, ViewStyle } from 'react-native';
3import type { MD3Elevation, ThemeProp } from '../../types';
4import { ElevationLevels } from '../../types';
5export type Props = {
6 /**
7 * Whether the Menu is currently visible.
8 */
9 visible: boolean;
10 /**
11 * The anchor to open the menu from. In most cases, it will be a button that opens the menu.
12 */
13 anchor: React.ReactNode | {
14 x: number;
15 y: number;
16 };
17 /**
18 * Whether the menu should open at the top of the anchor or at its bottom.
19 * Applied only when anchor is a node, not an x/y position.
20 */
21 anchorPosition?: 'top' | 'bottom';
22 /**
23 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
24 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
25 * Pass `0` or a custom value to and customize it.
26 * This is automatically handled on iOS.
27 */
28 statusBarHeight?: number;
29 /**
30 * Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
31 */
32 onDismiss?: () => void;
33 /**
34 * Accessibility label for the overlay. This is read by the screen reader when the user taps outside the menu.
35 */
36 overlayAccessibilityLabel?: string;
37 /**
38 * Content of the `Menu`.
39 */
40 children: React.ReactNode;
41 /**
42 * Style of menu's inner content.
43 */
44 contentStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
45 style?: StyleProp<ViewStyle>;
46 /**
47 * Elevation level of the menu's content. Shadow styles are calculated based on this value. Default `backgroundColor` is taken from the corresponding `theme.colors.elevation` property. By default equals `2`.
48 * @supported Available in v5.x with theme version 3
49 */
50 elevation?: MD3Elevation;
51 /**
52 * Mode of the menu's content.
53 * - `elevated` - Surface with a shadow and background color corresponding to set `elevation` value.
54 * - `flat` - Surface without a shadow, with the background color corresponding to set `elevation` value.
55 *
56 * @supported Available in v5.x with theme version 3
57 */
58 mode?: 'flat' | 'elevated';
59 /**
60 * @optional
61 */
62 theme?: ThemeProp;
63 /**
64 * Inner ScrollView prop
65 */
66 keyboardShouldPersistTaps?: ScrollViewProps['keyboardShouldPersistTaps'];
67 /**
68 * testID to be used on tests.
69 */
70 testID?: string;
71};
72export declare const ELEVATION_LEVELS_MAP: ElevationLevels[];
73/**
74 * Menus display a list of choices on temporary elevated surfaces. Their placement varies based on the element that opens them.
75 *
76 * ## Usage
77 * ```js
78 * import * as React from 'react';
79 * import { View } from 'react-native';
80 * import { Button, Menu, Divider, PaperProvider } from 'react-native-paper';
81 *
82 * const MyComponent = () => {
83 * const [visible, setVisible] = React.useState(false);
84 *
85 * const openMenu = () => setVisible(true);
86 *
87 * const closeMenu = () => setVisible(false);
88 *
89 * return (
90 * <PaperProvider>
91 * <View
92 * style={{
93 * paddingTop: 50,
94 * flexDirection: 'row',
95 * justifyContent: 'center',
96 * }}>
97 * <Menu
98 * visible={visible}
99 * onDismiss={closeMenu}
100 * anchor={<Button onPress={openMenu}>Show menu</Button>}>
101 * <Menu.Item onPress={() => {}} title="Item 1" />
102 * <Menu.Item onPress={() => {}} title="Item 2" />
103 * <Divider />
104 * <Menu.Item onPress={() => {}} title="Item 3" />
105 * </Menu>
106 * </View>
107 * </PaperProvider>
108 * );
109 * };
110 *
111 * export default MyComponent;
112 * ```
113 *
114 * ### Note
115 * When using `Menu` within a React Native's `Modal` component, you need to wrap all
116 * `Modal` contents within a `PaperProvider` in order for the menu to show. This
117 * wrapping is not necessary if you use Paper's `Modal` instead.
118 */
119declare const Menu: {
120 ({ visible, statusBarHeight, overlayAccessibilityLabel, testID, anchor, onDismiss, anchorPosition, contentStyle, style, elevation, mode, children, theme: themeOverrides, keyboardShouldPersistTaps, }: Props): React.JSX.Element;
121 Item: {
122 ({ leadingIcon, trailingIcon, dense, title, disabled, background, onPress, style, contentStyle, titleStyle, rippleColor: customRippleColor, testID, accessibilityLabel, accessibilityState, theme: themeOverrides, titleMaxFontSizeMultiplier, }: import("./MenuItem").Props): React.JSX.Element;
123 displayName: string;
124 };
125};
126export default Menu;
127//# sourceMappingURL=Menu.d.ts.map
\No newline at end of file