UNPKG

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