UNPKG

4.64 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3import * as React from 'react';
4import { isFragment } from 'react-is';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import styled from '../styles/styled';
9import useThemeProps from '../styles/useThemeProps';
10import { getBottomNavigationUtilityClass } from './bottomNavigationClasses';
11import { jsx as _jsx } from "react/jsx-runtime";
12
13var useUtilityClasses = function useUtilityClasses(ownerState) {
14 var classes = ownerState.classes;
15 var slots = {
16 root: ['root']
17 };
18 return composeClasses(slots, getBottomNavigationUtilityClass, classes);
19};
20
21var BottomNavigationRoot = styled('div', {
22 name: 'MuiBottomNavigation',
23 slot: 'Root',
24 overridesResolver: function overridesResolver(props, styles) {
25 return styles.root;
26 }
27})(function (_ref) {
28 var theme = _ref.theme;
29 return {
30 display: 'flex',
31 justifyContent: 'center',
32 height: 56,
33 backgroundColor: (theme.vars || theme).palette.background.paper
34 };
35});
36var BottomNavigation = /*#__PURE__*/React.forwardRef(function BottomNavigation(inProps, ref) {
37 var props = useThemeProps({
38 props: inProps,
39 name: 'MuiBottomNavigation'
40 });
41
42 var children = props.children,
43 className = props.className,
44 _props$component = props.component,
45 component = _props$component === void 0 ? 'div' : _props$component,
46 onChange = props.onChange,
47 _props$showLabels = props.showLabels,
48 showLabels = _props$showLabels === void 0 ? false : _props$showLabels,
49 value = props.value,
50 other = _objectWithoutProperties(props, ["children", "className", "component", "onChange", "showLabels", "value"]);
51
52 var ownerState = _extends({}, props, {
53 component: component,
54 showLabels: showLabels
55 });
56
57 var classes = useUtilityClasses(ownerState);
58 return /*#__PURE__*/_jsx(BottomNavigationRoot, _extends({
59 as: component,
60 className: clsx(classes.root, className),
61 ref: ref,
62 ownerState: ownerState
63 }, other, {
64 children: React.Children.map(children, function (child, childIndex) {
65 if (! /*#__PURE__*/React.isValidElement(child)) {
66 return null;
67 }
68
69 if (process.env.NODE_ENV !== 'production') {
70 if (isFragment(child)) {
71 console.error(["MUI: The BottomNavigation component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
72 }
73 }
74
75 var childValue = child.props.value === undefined ? childIndex : child.props.value;
76 return /*#__PURE__*/React.cloneElement(child, {
77 selected: childValue === value,
78 showLabel: child.props.showLabel !== undefined ? child.props.showLabel : showLabels,
79 value: childValue,
80 onChange: onChange
81 });
82 })
83 }));
84});
85process.env.NODE_ENV !== "production" ? BottomNavigation.propTypes
86/* remove-proptypes */
87= {
88 // ----------------------------- Warning --------------------------------
89 // | These PropTypes are generated from the TypeScript type definitions |
90 // | To update them edit the d.ts file and run "yarn proptypes" |
91 // ----------------------------------------------------------------------
92
93 /**
94 * The content of the component.
95 */
96 children: PropTypes.node,
97
98 /**
99 * Override or extend the styles applied to the component.
100 */
101 classes: PropTypes.object,
102
103 /**
104 * @ignore
105 */
106 className: PropTypes.string,
107
108 /**
109 * The component used for the root node.
110 * Either a string to use a HTML element or a component.
111 */
112 component: PropTypes.elementType,
113
114 /**
115 * Callback fired when the value changes.
116 *
117 * @param {React.SyntheticEvent} event The event source of the callback. **Warning**: This is a generic event not a change event.
118 * @param {any} value We default to the index of the child.
119 */
120 onChange: PropTypes.func,
121
122 /**
123 * If `true`, all `BottomNavigationAction`s will show their labels.
124 * By default, only the selected `BottomNavigationAction` will show its label.
125 * @default false
126 */
127 showLabels: PropTypes.bool,
128
129 /**
130 * The system prop that allows defining system overrides as well as additional CSS styles.
131 */
132 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
133
134 /**
135 * The value of the currently selected `BottomNavigationAction`.
136 */
137 value: PropTypes.any
138} : void 0;
139export default BottomNavigation;
\No newline at end of file