UNPKG

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