1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import { styled } from "../zero-styled/index.js";
|
8 | import memoTheme from "../utils/memoTheme.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import ButtonBase from "../ButtonBase/index.js";
|
11 | import unsupportedProp from "../utils/unsupportedProp.js";
|
12 | import bottomNavigationActionClasses, { getBottomNavigationActionUtilityClass } from "./bottomNavigationActionClasses.js";
|
13 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
14 | const 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 | };
|
26 | const 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 | })));
|
69 | const 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 | })));
|
95 | const BottomNavigationAction = 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 |
|
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 _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, _jsx(BottomNavigationActionLabel, {
|
130 | className: classes.label,
|
131 | ownerState: ownerState,
|
132 | children: label
|
133 | })]
|
134 | });
|
135 | });
|
136 | process.env.NODE_ENV !== "production" ? BottomNavigationAction.propTypes = {
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 | children: unsupportedProp,
|
146 | |
147 |
|
148 |
|
149 | classes: PropTypes.object,
|
150 | |
151 |
|
152 |
|
153 | className: PropTypes.string,
|
154 | |
155 |
|
156 |
|
157 | icon: PropTypes.node,
|
158 | |
159 |
|
160 |
|
161 | label: PropTypes.node,
|
162 | |
163 |
|
164 |
|
165 | onChange: PropTypes.func,
|
166 | |
167 |
|
168 |
|
169 | onClick: PropTypes.func,
|
170 | |
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | showLabel: PropTypes.bool,
|
178 | |
179 |
|
180 |
|
181 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
182 | |
183 |
|
184 |
|
185 | value: PropTypes.any
|
186 | } : void 0;
|
187 | export default BottomNavigationAction; |
\ | No newline at end of file |