UNPKG

5.9 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _extends from "@babel/runtime/helpers/esm/extends";
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import styled from '../styles/styled';
9import useThemeProps from '../styles/useThemeProps';
10import ButtonBase from '../ButtonBase';
11import unsupportedProp from '../utils/unsupportedProp';
12import bottomNavigationActionClasses, { getBottomNavigationActionUtilityClass } from './bottomNavigationActionClasses';
13import { jsx as _jsx } from "react/jsx-runtime";
14import { jsxs as _jsxs } from "react/jsx-runtime";
15
16var useUtilityClasses = function useUtilityClasses(ownerState) {
17 var classes = ownerState.classes,
18 showLabel = ownerState.showLabel,
19 selected = ownerState.selected;
20 var slots = {
21 root: ['root', !showLabel && !selected && 'iconOnly', selected && 'selected'],
22 label: ['label', !showLabel && !selected && 'iconOnly', selected && 'selected']
23 };
24 return composeClasses(slots, getBottomNavigationActionUtilityClass, classes);
25};
26
27var BottomNavigationActionRoot = styled(ButtonBase, {
28 name: 'MuiBottomNavigationAction',
29 slot: 'Root',
30 overridesResolver: function overridesResolver(props, styles) {
31 var ownerState = props.ownerState;
32 return [styles.root, !ownerState.showLabel && !ownerState.selected && styles.iconOnly];
33 }
34})(function (_ref) {
35 var theme = _ref.theme,
36 ownerState = _ref.ownerState;
37 return _extends({
38 transition: theme.transitions.create(['color', 'padding-top'], {
39 duration: theme.transitions.duration.short
40 }),
41 padding: '0px 12px',
42 minWidth: 80,
43 maxWidth: 168,
44 color: (theme.vars || theme).palette.text.secondary,
45 flexDirection: 'column',
46 flex: '1'
47 }, !ownerState.showLabel && !ownerState.selected && {
48 paddingTop: 14
49 }, !ownerState.showLabel && !ownerState.selected && !ownerState.label && {
50 paddingTop: 0
51 }, _defineProperty({}, "&.".concat(bottomNavigationActionClasses.selected), {
52 color: (theme.vars || theme).palette.primary.main
53 }));
54});
55var BottomNavigationActionLabel = styled('span', {
56 name: 'MuiBottomNavigationAction',
57 slot: 'Label',
58 overridesResolver: function overridesResolver(props, styles) {
59 return styles.label;
60 }
61})(function (_ref2) {
62 var theme = _ref2.theme,
63 ownerState = _ref2.ownerState;
64 return _extends({
65 fontFamily: theme.typography.fontFamily,
66 fontSize: theme.typography.pxToRem(12),
67 opacity: 1,
68 transition: 'font-size 0.2s, opacity 0.2s',
69 transitionDelay: '0.1s'
70 }, !ownerState.showLabel && !ownerState.selected && {
71 opacity: 0,
72 transitionDelay: '0s'
73 }, _defineProperty({}, "&.".concat(bottomNavigationActionClasses.selected), {
74 fontSize: theme.typography.pxToRem(14)
75 }));
76});
77var BottomNavigationAction = /*#__PURE__*/React.forwardRef(function BottomNavigationAction(inProps, ref) {
78 var props = useThemeProps({
79 props: inProps,
80 name: 'MuiBottomNavigationAction'
81 });
82
83 var className = props.className,
84 icon = props.icon,
85 label = props.label,
86 onChange = props.onChange,
87 onClick = props.onClick,
88 selected = props.selected,
89 showLabel = props.showLabel,
90 value = props.value,
91 other = _objectWithoutProperties(props, ["className", "icon", "label", "onChange", "onClick", "selected", "showLabel", "value"]);
92
93 var ownerState = props;
94 var classes = useUtilityClasses(ownerState);
95
96 var handleChange = function handleChange(event) {
97 if (onChange) {
98 onChange(event, value);
99 }
100
101 if (onClick) {
102 onClick(event);
103 }
104 };
105
106 return /*#__PURE__*/_jsxs(BottomNavigationActionRoot, _extends({
107 ref: ref,
108 className: clsx(classes.root, className),
109 focusRipple: true,
110 onClick: handleChange,
111 ownerState: ownerState
112 }, other, {
113 children: [icon, /*#__PURE__*/_jsx(BottomNavigationActionLabel, {
114 className: classes.label,
115 ownerState: ownerState,
116 children: label
117 })]
118 }));
119});
120process.env.NODE_ENV !== "production" ? BottomNavigationAction.propTypes
121/* remove-proptypes */
122= {
123 // ----------------------------- Warning --------------------------------
124 // | These PropTypes are generated from the TypeScript type definitions |
125 // | To update them edit the d.ts file and run "yarn proptypes" |
126 // ----------------------------------------------------------------------
127
128 /**
129 * This prop isn't supported.
130 * Use the `component` prop if you need to change the children structure.
131 */
132 children: unsupportedProp,
133
134 /**
135 * Override or extend the styles applied to the component.
136 */
137 classes: PropTypes.object,
138
139 /**
140 * @ignore
141 */
142 className: PropTypes.string,
143
144 /**
145 * The icon to display.
146 */
147 icon: PropTypes.node,
148
149 /**
150 * The label element.
151 */
152 label: PropTypes.node,
153
154 /**
155 * @ignore
156 */
157 onChange: PropTypes.func,
158
159 /**
160 * @ignore
161 */
162 onClick: PropTypes.func,
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 * The prop defaults to the value (`false`) inherited from the parent BottomNavigation component.
170 */
171 showLabel: PropTypes.bool,
172
173 /**
174 * The system prop that allows defining system overrides as well as additional CSS styles.
175 */
176 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
177
178 /**
179 * You can provide your own value. Otherwise, we fallback to the child position index.
180 */
181 value: PropTypes.any
182} : void 0;
183export default BottomNavigationAction;
\No newline at end of file