UNPKG

4.18 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _reactIs = require("react-is");
19
20var _propTypes = _interopRequireDefault(require("prop-types"));
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var styles = function styles(theme) {
27 return {
28 /* Styles applied to the root element. */
29 root: {
30 display: 'flex',
31 justifyContent: 'center',
32 height: 56,
33 backgroundColor: theme.palette.background.paper
34 }
35 };
36};
37
38exports.styles = styles;
39var BottomNavigation = /*#__PURE__*/React.forwardRef(function BottomNavigation(props, ref) {
40 var children = props.children,
41 classes = props.classes,
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 = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "component", "onChange", "showLabels", "value"]);
50 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
51 className: (0, _clsx.default)(classes.root, className),
52 ref: ref
53 }, other), React.Children.map(children, function (child, childIndex) {
54 if (! /*#__PURE__*/React.isValidElement(child)) {
55 return null;
56 }
57
58 if (process.env.NODE_ENV !== 'production') {
59 if ((0, _reactIs.isFragment)(child)) {
60 console.error(["Material-UI: The BottomNavigation component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
61 }
62 }
63
64 var childValue = child.props.value === undefined ? childIndex : child.props.value;
65 return /*#__PURE__*/React.cloneElement(child, {
66 selected: childValue === value,
67 showLabel: child.props.showLabel !== undefined ? child.props.showLabel : showLabels,
68 value: childValue,
69 onChange: onChange
70 });
71 }));
72});
73process.env.NODE_ENV !== "production" ? BottomNavigation.propTypes = {
74 // ----------------------------- Warning --------------------------------
75 // | These PropTypes are generated from the TypeScript type definitions |
76 // | To update them edit the d.ts file and run "yarn proptypes" |
77 // ----------------------------------------------------------------------
78
79 /**
80 * The content of the component.
81 */
82 children: _propTypes.default.node,
83
84 /**
85 * Override or extend the styles applied to the component.
86 * See [CSS API](#css) below for more details.
87 */
88 classes: _propTypes.default.object,
89
90 /**
91 * @ignore
92 */
93 className: _propTypes.default.string,
94
95 /**
96 * The component used for the root node.
97 * Either a string to use a HTML element or a component.
98 */
99 component: _propTypes.default
100 /* @typescript-to-proptypes-ignore */
101 .elementType,
102
103 /**
104 * Callback fired when the value changes.
105 *
106 * @param {object} event The event source of the callback.
107 * @param {any} value We default to the index of the child.
108 */
109 onChange: _propTypes.default.func,
110
111 /**
112 * If `true`, all `BottomNavigationAction`s will show their labels.
113 * By default, only the selected `BottomNavigationAction` will show its label.
114 */
115 showLabels: _propTypes.default.bool,
116
117 /**
118 * The value of the currently selected `BottomNavigationAction`.
119 */
120 value: _propTypes.default.any
121} : void 0;
122
123var _default = (0, _withStyles.default)(styles, {
124 name: 'MuiBottomNavigation'
125})(BottomNavigation);
126
127exports.default = _default;
\No newline at end of file