UNPKG

5.21 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 _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
25
26var _unsupportedProp = _interopRequireDefault(require("../utils/unsupportedProp"));
27
28var styles = function styles(theme) {
29 return {
30 /* Styles applied to the root element. */
31 root: {
32 transition: theme.transitions.create(['color', 'padding-top'], {
33 duration: theme.transitions.duration.short
34 }),
35 padding: '6px 12px 8px',
36 minWidth: 80,
37 maxWidth: 168,
38 color: theme.palette.text.secondary,
39 flex: '1',
40 '&$iconOnly': {
41 paddingTop: 16
42 },
43 '&$selected': {
44 paddingTop: 6,
45 color: theme.palette.primary.main
46 }
47 },
48
49 /* Pseudo-class applied to the root element if selected. */
50 selected: {},
51
52 /* Pseudo-class applied to the root element if `showLabel={false}` and not selected. */
53 iconOnly: {},
54
55 /* Styles applied to the span element that wraps the icon and label. */
56 wrapper: {
57 display: 'inline-flex',
58 alignItems: 'center',
59 justifyContent: 'center',
60 width: '100%',
61 flexDirection: 'column'
62 },
63
64 /* Styles applied to the label's span element. */
65 label: {
66 fontFamily: theme.typography.fontFamily,
67 fontSize: theme.typography.pxToRem(12),
68 opacity: 1,
69 transition: 'font-size 0.2s, opacity 0.2s',
70 transitionDelay: '0.1s',
71 '&$iconOnly': {
72 opacity: 0,
73 transitionDelay: '0s'
74 },
75 '&$selected': {
76 fontSize: theme.typography.pxToRem(14)
77 }
78 }
79 };
80};
81
82exports.styles = styles;
83var BottomNavigationAction = /*#__PURE__*/React.forwardRef(function BottomNavigationAction(props, ref) {
84 var classes = props.classes,
85 className = props.className,
86 icon = props.icon,
87 label = props.label,
88 onChange = props.onChange,
89 onClick = props.onClick,
90 selected = props.selected,
91 showLabel = props.showLabel,
92 value = props.value,
93 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "icon", "label", "onChange", "onClick", "selected", "showLabel", "value"]);
94
95 var handleChange = function handleChange(event) {
96 if (onChange) {
97 onChange(event, value);
98 }
99
100 if (onClick) {
101 onClick(event);
102 }
103 };
104
105 return /*#__PURE__*/React.createElement(_ButtonBase.default, (0, _extends2.default)({
106 ref: ref,
107 className: (0, _clsx.default)(classes.root, className, selected ? classes.selected : !showLabel && classes.iconOnly),
108 focusRipple: true,
109 onClick: handleChange
110 }, other), /*#__PURE__*/React.createElement("span", {
111 className: classes.wrapper
112 }, icon, /*#__PURE__*/React.createElement("span", {
113 className: (0, _clsx.default)(classes.label, selected ? classes.selected : !showLabel && classes.iconOnly)
114 }, label)));
115});
116process.env.NODE_ENV !== "production" ? BottomNavigationAction.propTypes = {
117 // ----------------------------- Warning --------------------------------
118 // | These PropTypes are generated from the TypeScript type definitions |
119 // | To update them edit the d.ts file and run "yarn proptypes" |
120 // ----------------------------------------------------------------------
121
122 /**
123 * This prop isn't supported.
124 * Use the `component` prop if you need to change the children structure.
125 */
126 children: _unsupportedProp.default,
127
128 /**
129 * Override or extend the styles applied to the component.
130 * See [CSS API](#css) below for more details.
131 */
132 classes: _propTypes.default.object,
133
134 /**
135 * @ignore
136 */
137 className: _propTypes.default.string,
138
139 /**
140 * The icon element.
141 */
142 icon: _propTypes.default.node,
143
144 /**
145 * The label element.
146 */
147 label: _propTypes.default.node,
148
149 /**
150 * @ignore
151 */
152 onChange: _propTypes.default.func,
153
154 /**
155 * @ignore
156 */
157 onClick: _propTypes.default.func,
158
159 /**
160 * @ignore
161 */
162 selected: _propTypes.default.bool,
163
164 /**
165 * If `true`, the `BottomNavigationAction` will show its label.
166 * By default, only the selected `BottomNavigationAction`
167 * inside `BottomNavigation` will show its label.
168 */
169 showLabel: _propTypes.default.bool,
170
171 /**
172 * You can provide your own value. Otherwise, we fallback to the child position index.
173 */
174 value: _propTypes.default.any
175} : void 0;
176
177var _default = (0, _withStyles.default)(styles, {
178 name: 'MuiBottomNavigationAction'
179})(BottomNavigationAction);
180
181exports.default = _default;
\No newline at end of file