UNPKG

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