1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import { isFragment } from 'react-is';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import withStyles from '../styles/withStyles';
|
8 | export const styles = theme => ({
|
9 |
|
10 | root: {
|
11 | display: 'flex',
|
12 | justifyContent: 'center',
|
13 | height: 56,
|
14 | backgroundColor: theme.palette.background.paper
|
15 | }
|
16 | });
|
17 | const BottomNavigation = React.forwardRef(function BottomNavigation(props, ref) {
|
18 | const {
|
19 | children,
|
20 | classes,
|
21 | className,
|
22 | component: Component = 'div',
|
23 | onChange,
|
24 | showLabels = false,
|
25 | value
|
26 | } = props,
|
27 | other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "component", "onChange", "showLabels", "value"]);
|
28 |
|
29 | return React.createElement(Component, _extends({
|
30 | className: clsx(classes.root, className),
|
31 | ref: ref
|
32 | }, other), React.Children.map(children, (child, childIndex) => {
|
33 | if (! React.isValidElement(child)) {
|
34 | return null;
|
35 | }
|
36 |
|
37 | if (process.env.NODE_ENV !== 'production') {
|
38 | if (isFragment(child)) {
|
39 | console.error(["Material-UI: The BottomNavigation component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
|
40 | }
|
41 | }
|
42 |
|
43 | const childValue = child.props.value === undefined ? childIndex : child.props.value;
|
44 | return React.cloneElement(child, {
|
45 | selected: childValue === value,
|
46 | showLabel: child.props.showLabel !== undefined ? child.props.showLabel : showLabels,
|
47 | value: childValue,
|
48 | onChange
|
49 | });
|
50 | }));
|
51 | });
|
52 | process.env.NODE_ENV !== "production" ? BottomNavigation.propTypes = {
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | |
59 |
|
60 |
|
61 | children: PropTypes.node,
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 | classes: PropTypes.object,
|
68 |
|
69 | |
70 |
|
71 |
|
72 | className: PropTypes.string,
|
73 |
|
74 | |
75 |
|
76 |
|
77 |
|
78 | component: PropTypes
|
79 |
|
80 | .elementType,
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | onChange: PropTypes.func,
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 | showLabels: PropTypes.bool,
|
95 |
|
96 | |
97 |
|
98 |
|
99 | value: PropTypes.any
|
100 | } : void 0;
|
101 | export default withStyles(styles, {
|
102 | name: 'MuiBottomNavigation'
|
103 | })(BottomNavigation); |
\ | No newline at end of file |