UNPKG

4.04 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = exports.styles = void 0;
9
10var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
14var _react = _interopRequireDefault(require("react"));
15
16var _reactIs = require("react-is");
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var styles = function styles(theme) {
25 return {
26 /* Styles applied to the root element. */
27 root: {
28 display: 'flex',
29 justifyContent: 'center',
30 height: 56,
31 backgroundColor: theme.palette.background.paper
32 }
33 };
34};
35
36exports.styles = styles;
37
38var BottomNavigation = _react.default.forwardRef(function BottomNavigation(props, ref) {
39 var children = props.children,
40 classes = props.classes,
41 className = props.className,
42 _props$component = props.component,
43 Component = _props$component === void 0 ? 'div' : _props$component,
44 onChange = props.onChange,
45 _props$showLabels = props.showLabels,
46 showLabels = _props$showLabels === void 0 ? false : _props$showLabels,
47 value = props.value,
48 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "component", "onChange", "showLabels", "value"]);
49 return _react.default.createElement(Component, (0, _extends2.default)({
50 className: (0, _clsx.default)(classes.root, className),
51 ref: ref
52 }, other), _react.default.Children.map(children, function (child, childIndex) {
53 if (!_react.default.isValidElement(child)) {
54 return null;
55 }
56
57 if (process.env.NODE_ENV !== 'production') {
58 if ((0, _reactIs.isFragment)(child)) {
59 console.error(["Material-UI: the BottomNavigation component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
60 }
61 }
62
63 var childValue = child.props.value === undefined ? childIndex : child.props.value;
64 return _react.default.cloneElement(child, {
65 selected: childValue === value,
66 showLabel: child.props.showLabel !== undefined ? child.props.showLabel : showLabels,
67 value: childValue,
68 onChange: onChange
69 });
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 DOM element or a component.
98 */
99 component: _propTypes.default.elementType,
100
101 /**
102 * Callback fired when the value changes.
103 *
104 * @param {object} event The event source of the callback
105 * @param {any} value We default to the index of the child
106 */
107 onChange: _propTypes.default.func,
108
109 /**
110 * If `true`, all `BottomNavigationAction`s will show their labels.
111 * By default, only the selected `BottomNavigationAction` will show its label.
112 */
113 showLabels: _propTypes.default.bool,
114
115 /**
116 * The value of the currently selected `BottomNavigationAction`.
117 */
118 value: _propTypes.default.any
119} : void 0;
120
121var _default = (0, _withStyles.default)(styles, {
122 name: 'MuiBottomNavigation'
123})(BottomNavigation);
124
125exports.default = _default;
\No newline at end of file