Skip to content

Commit db595b7

Browse files
authored
feat: add elevation property for Menu component (#4077)
1 parent f7d147c commit db595b7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/components/Menu/Menu.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
import MenuItem from './MenuItem';
2424
import { APPROX_STATUSBAR_HEIGHT } from '../../constants';
2525
import { withInternalTheme } from '../../core/theming';
26-
import type { $Omit, InternalTheme } from '../../types';
26+
import type { $Omit, InternalTheme, MD3Elevation } from '../../types';
27+
import { ElevationLevels } from '../../types';
2728
import { addEventListener } from '../../utils/addEventListener';
2829
import { BackHandler } from '../../utils/BackHandler/BackHandler';
2930
import Portal from '../Portal/Portal';
@@ -67,6 +68,11 @@ export type Props = {
6768
*/
6869
contentStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
6970
style?: StyleProp<ViewStyle>;
71+
/**
72+
* 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`.
73+
* @supported Available in v5.x with theme version 3
74+
*/
75+
elevation?: MD3Elevation;
7076
/**
7177
* @optional
7278
*/
@@ -103,6 +109,11 @@ const EASING = Easing.bezier(0.4, 0, 0.2, 1);
103109

104110
const WINDOW_LAYOUT = Dimensions.get('window');
105111

112+
const DEFAULT_ELEVATION: MD3Elevation = 2;
113+
const ELEVATION_LEVELS_MAP = Object.values(
114+
ElevationLevels
115+
) as ElevationLevels[];
116+
106117
/**
107118
* Menus display a list of choices on temporary elevated surfaces. Their placement varies based on the element that opens them.
108119
*
@@ -406,6 +417,7 @@ class Menu extends React.Component<Props, State> {
406417
anchorPosition,
407418
contentStyle,
408419
style,
420+
elevation = DEFAULT_ELEVATION,
409421
children,
410422
theme,
411423
statusBarHeight,
@@ -639,11 +651,12 @@ class Menu extends React.Component<Props, State> {
639651
styles.shadowMenuContainer,
640652
shadowMenuContainerStyle,
641653
theme.isV3 && {
642-
backgroundColor: theme.colors.elevation.level2,
654+
backgroundColor:
655+
theme.colors.elevation[ELEVATION_LEVELS_MAP[elevation]],
643656
},
644657
contentStyle,
645658
]}
646-
{...(theme.isV3 && { elevation: 2 })}
659+
{...(theme.isV3 && { elevation })}
647660
testID={`${testID}-surface`}
648661
theme={theme}
649662
>

0 commit comments

Comments
 (0)