UNPKG

6.14 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5import _extends from "@babel/runtime/helpers/esm/extends";
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import clsx from 'clsx';
9import composeClasses from '@mui/utils/composeClasses';
10import styled from '../styles/styled';
11import { useDefaultProps } from '../DefaultPropsProvider';
12import ButtonBase from '../ButtonBase';
13import unsupportedProp from '../utils/unsupportedProp';
14import bottomNavigationActionClasses, { getBottomNavigationActionUtilityClass } from './bottomNavigationActionClasses';
15import { jsx as _jsx } from "react/jsx-runtime";
16import { jsxs as _jsxs } from "react/jsx-runtime";
17var useUtilityClasses = function useUtilityClasses(ownerState) {
18 var classes = ownerState.classes,
19 showLabel = ownerState.showLabel,
20 selected = ownerState.selected;
21 var slots = {
22 root: ['root', !showLabel && !selected && 'iconOnly', selected && 'selected'],
23 label: ['label', !showLabel && !selected && 'iconOnly', selected && 'selected']
24 };
25 return composeClasses(slots, getBottomNavigationActionUtilityClass, classes);
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 = useDefaultProps({
79 props: inProps,
80 name: 'MuiBottomNavigationAction'
81 });
82 var className = props.className,
83 icon = props.icon,
84 label = props.label,
85 onChange = props.onChange,
86 onClick = props.onClick,
87 selected = props.selected,
88 showLabel = props.showLabel,
89 value = props.value,
90 other = _objectWithoutProperties(props, ["className", "icon", "label", "onChange", "onClick", "selected", "showLabel", "value"]);
91 var ownerState = props;
92 var classes = useUtilityClasses(ownerState);
93 var handleChange = function handleChange(event) {
94 if (onChange) {
95 onChange(event, value);
96 }
97 if (onClick) {
98 onClick(event);
99 }
100 };
101 return /*#__PURE__*/_jsxs(BottomNavigationActionRoot, _extends({
102 ref: ref,
103 className: clsx(classes.root, className),
104 focusRipple: true,
105 onClick: handleChange,
106 ownerState: ownerState
107 }, other, {
108 children: [icon, /*#__PURE__*/_jsx(BottomNavigationActionLabel, {
109 className: classes.label,
110 ownerState: ownerState,
111 children: label
112 })]
113 }));
114});
115process.env.NODE_ENV !== "production" ? BottomNavigationAction.propTypes /* remove-proptypes */ = {
116 // ┌────────────────────────────── Warning ──────────────────────────────┐
117 // │ These PropTypes are generated from the TypeScript type definitions. │
118 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
119 // └─────────────────────────────────────────────────────────────────────┘
120 /**
121 * This prop isn't supported.
122 * Use the `component` prop if you need to change the children structure.
123 */
124 children: unsupportedProp,
125 /**
126 * Override or extend the styles applied to the component.
127 */
128 classes: PropTypes.object,
129 /**
130 * @ignore
131 */
132 className: PropTypes.string,
133 /**
134 * The icon to display.
135 */
136 icon: PropTypes.node,
137 /**
138 * The label element.
139 */
140 label: PropTypes.node,
141 /**
142 * @ignore
143 */
144 onChange: PropTypes.func,
145 /**
146 * @ignore
147 */
148 onClick: PropTypes.func,
149 /**
150 * If `true`, the `BottomNavigationAction` will show its label.
151 * By default, only the selected `BottomNavigationAction`
152 * inside `BottomNavigation` will show its label.
153 *
154 * The prop defaults to the value (`false`) inherited from the parent BottomNavigation component.
155 */
156 showLabel: PropTypes.bool,
157 /**
158 * The system prop that allows defining system overrides as well as additional CSS styles.
159 */
160 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
161 /**
162 * You can provide your own value. Otherwise, we fallback to the child position index.
163 */
164 value: PropTypes.any
165} : void 0;
166export default BottomNavigationAction;
\No newline at end of file