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