UNPKG

5.67 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import memoTheme from "../utils/memoTheme.js";
9import { useDefaultProps } from "../DefaultPropsProvider/index.js";
10import ButtonBase from "../ButtonBase/index.js";
11import unsupportedProp from "../utils/unsupportedProp.js";
12import bottomNavigationActionClasses, { getBottomNavigationActionUtilityClass } from "./bottomNavigationActionClasses.js";
13import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14const useUtilityClasses = ownerState => {
15 const {
16 classes,
17 showLabel,
18 selected
19 } = ownerState;
20 const 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};
26const BottomNavigationActionRoot = styled(ButtonBase, {
27 name: 'MuiBottomNavigationAction',
28 slot: 'Root',
29 overridesResolver: (props, styles) => {
30 const {
31 ownerState
32 } = props;
33 return [styles.root, !ownerState.showLabel && !ownerState.selected && styles.iconOnly];
34 }
35})(memoTheme(({
36 theme
37}) => ({
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 [`&.${bottomNavigationActionClasses.selected}`]: {
48 color: (theme.vars || theme).palette.primary.main
49 },
50 variants: [{
51 props: ({
52 showLabel,
53 selected
54 }) => !showLabel && !selected,
55 style: {
56 paddingTop: 14
57 }
58 }, {
59 props: ({
60 showLabel,
61 selected,
62 label
63 }) => !showLabel && !selected && !label,
64 style: {
65 paddingTop: 0
66 }
67 }]
68})));
69const BottomNavigationActionLabel = styled('span', {
70 name: 'MuiBottomNavigationAction',
71 slot: 'Label',
72 overridesResolver: (props, styles) => styles.label
73})(memoTheme(({
74 theme
75}) => ({
76 fontFamily: theme.typography.fontFamily,
77 fontSize: theme.typography.pxToRem(12),
78 opacity: 1,
79 transition: 'font-size 0.2s, opacity 0.2s',
80 transitionDelay: '0.1s',
81 [`&.${bottomNavigationActionClasses.selected}`]: {
82 fontSize: theme.typography.pxToRem(14)
83 },
84 variants: [{
85 props: ({
86 showLabel,
87 selected
88 }) => !showLabel && !selected,
89 style: {
90 opacity: 0,
91 transitionDelay: '0s'
92 }
93 }]
94})));
95const BottomNavigationAction = /*#__PURE__*/React.forwardRef(function BottomNavigationAction(inProps, ref) {
96 const props = useDefaultProps({
97 props: inProps,
98 name: 'MuiBottomNavigationAction'
99 });
100 const {
101 className,
102 icon,
103 label,
104 onChange,
105 onClick,
106 // eslint-disable-next-line react/prop-types -- private, always overridden by BottomNavigation
107 selected,
108 showLabel,
109 value,
110 ...other
111 } = props;
112 const ownerState = props;
113 const classes = useUtilityClasses(ownerState);
114 const handleChange = event => {
115 if (onChange) {
116 onChange(event, value);
117 }
118 if (onClick) {
119 onClick(event);
120 }
121 };
122 return /*#__PURE__*/_jsxs(BottomNavigationActionRoot, {
123 ref: ref,
124 className: clsx(classes.root, className),
125 focusRipple: true,
126 onClick: handleChange,
127 ownerState: ownerState,
128 ...other,
129 children: [icon, /*#__PURE__*/_jsx(BottomNavigationActionLabel, {
130 className: classes.label,
131 ownerState: ownerState,
132 children: label
133 })]
134 });
135});
136process.env.NODE_ENV !== "production" ? BottomNavigationAction.propTypes /* remove-proptypes */ = {
137 // ┌────────────────────────────── Warning ──────────────────────────────┐
138 // │ These PropTypes are generated from the TypeScript type definitions. │
139 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
140 // └─────────────────────────────────────────────────────────────────────┘
141 /**
142 * This prop isn't supported.
143 * Use the `component` prop if you need to change the children structure.
144 */
145 children: unsupportedProp,
146 /**
147 * Override or extend the styles applied to the component.
148 */
149 classes: PropTypes.object,
150 /**
151 * @ignore
152 */
153 className: PropTypes.string,
154 /**
155 * The icon to display.
156 */
157 icon: PropTypes.node,
158 /**
159 * The label element.
160 */
161 label: PropTypes.node,
162 /**
163 * @ignore
164 */
165 onChange: PropTypes.func,
166 /**
167 * @ignore
168 */
169 onClick: PropTypes.func,
170 /**
171 * If `true`, the `BottomNavigationAction` will show its label.
172 * By default, only the selected `BottomNavigationAction`
173 * inside `BottomNavigation` will show its label.
174 *
175 * The prop defaults to the value (`false`) inherited from the parent BottomNavigation component.
176 */
177 showLabel: PropTypes.bool,
178 /**
179 * The system prop that allows defining system overrides as well as additional CSS styles.
180 */
181 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
182 /**
183 * You can provide your own value. Otherwise, we fallback to the child position index.
184 */
185 value: PropTypes.any
186} : void 0;
187export default BottomNavigationAction;
\No newline at end of file