1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import composeClasses from '@mui/utils/composeClasses';
|
6 | import clsx from 'clsx';
|
7 | import formControlState from "../FormControl/formControlState.js";
|
8 | import useFormControl from "../FormControl/useFormControl.js";
|
9 | import FormLabel, { formLabelClasses } from "../FormLabel/index.js";
|
10 | import capitalize from "../utils/capitalize.js";
|
11 | import rootShouldForwardProp from "../styles/rootShouldForwardProp.js";
|
12 | import { styled } from "../zero-styled/index.js";
|
13 | import memoTheme from "../utils/memoTheme.js";
|
14 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
15 | import { getInputLabelUtilityClasses } from "./inputLabelClasses.js";
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | classes,
|
20 | formControl,
|
21 | size,
|
22 | shrink,
|
23 | disableAnimation,
|
24 | variant,
|
25 | required
|
26 | } = ownerState;
|
27 | const slots = {
|
28 | root: ['root', formControl && 'formControl', !disableAnimation && 'animated', shrink && 'shrink', size && size !== 'normal' && `size${capitalize(size)}`, variant],
|
29 | asterisk: [required && 'asterisk']
|
30 | };
|
31 | const composedClasses = composeClasses(slots, getInputLabelUtilityClasses, classes);
|
32 | return {
|
33 | ...classes,
|
34 |
|
35 | ...composedClasses
|
36 | };
|
37 | };
|
38 | const InputLabelRoot = styled(FormLabel, {
|
39 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
40 | name: 'MuiInputLabel',
|
41 | slot: 'Root',
|
42 | overridesResolver: (props, styles) => {
|
43 | const {
|
44 | ownerState
|
45 | } = props;
|
46 | return [{
|
47 | [`& .${formLabelClasses.asterisk}`]: styles.asterisk
|
48 | }, styles.root, ownerState.formControl && styles.formControl, ownerState.size === 'small' && styles.sizeSmall, ownerState.shrink && styles.shrink, !ownerState.disableAnimation && styles.animated, ownerState.focused && styles.focused, styles[ownerState.variant]];
|
49 | }
|
50 | })(memoTheme(({
|
51 | theme
|
52 | }) => ({
|
53 | display: 'block',
|
54 | transformOrigin: 'top left',
|
55 | whiteSpace: 'nowrap',
|
56 | overflow: 'hidden',
|
57 | textOverflow: 'ellipsis',
|
58 | maxWidth: '100%',
|
59 | variants: [{
|
60 | props: ({
|
61 | ownerState
|
62 | }) => ownerState.formControl,
|
63 | style: {
|
64 | position: 'absolute',
|
65 | left: 0,
|
66 | top: 0,
|
67 |
|
68 | transform: 'translate(0, 20px) scale(1)'
|
69 | }
|
70 | }, {
|
71 | props: {
|
72 | size: 'small'
|
73 | },
|
74 | style: {
|
75 |
|
76 | transform: 'translate(0, 17px) scale(1)'
|
77 | }
|
78 | }, {
|
79 | props: ({
|
80 | ownerState
|
81 | }) => ownerState.shrink,
|
82 | style: {
|
83 | transform: 'translate(0, -1.5px) scale(0.75)',
|
84 | transformOrigin: 'top left',
|
85 | maxWidth: '133%'
|
86 | }
|
87 | }, {
|
88 | props: ({
|
89 | ownerState
|
90 | }) => !ownerState.disableAnimation,
|
91 | style: {
|
92 | transition: theme.transitions.create(['color', 'transform', 'max-width'], {
|
93 | duration: theme.transitions.duration.shorter,
|
94 | easing: theme.transitions.easing.easeOut
|
95 | })
|
96 | }
|
97 | }, {
|
98 | props: {
|
99 | variant: 'filled'
|
100 | },
|
101 | style: {
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | zIndex: 1,
|
107 | pointerEvents: 'none',
|
108 | transform: 'translate(12px, 16px) scale(1)',
|
109 | maxWidth: 'calc(100% - 24px)'
|
110 | }
|
111 | }, {
|
112 | props: {
|
113 | variant: 'filled',
|
114 | size: 'small'
|
115 | },
|
116 | style: {
|
117 | transform: 'translate(12px, 13px) scale(1)'
|
118 | }
|
119 | }, {
|
120 | props: ({
|
121 | variant,
|
122 | ownerState
|
123 | }) => variant === 'filled' && ownerState.shrink,
|
124 | style: {
|
125 | userSelect: 'none',
|
126 | pointerEvents: 'auto',
|
127 | transform: 'translate(12px, 7px) scale(0.75)',
|
128 | maxWidth: 'calc(133% - 24px)'
|
129 | }
|
130 | }, {
|
131 | props: ({
|
132 | variant,
|
133 | ownerState,
|
134 | size
|
135 | }) => variant === 'filled' && ownerState.shrink && size === 'small',
|
136 | style: {
|
137 | transform: 'translate(12px, 4px) scale(0.75)'
|
138 | }
|
139 | }, {
|
140 | props: {
|
141 | variant: 'outlined'
|
142 | },
|
143 | style: {
|
144 |
|
145 | zIndex: 1,
|
146 | pointerEvents: 'none',
|
147 | transform: 'translate(14px, 16px) scale(1)',
|
148 | maxWidth: 'calc(100% - 24px)'
|
149 | }
|
150 | }, {
|
151 | props: {
|
152 | variant: 'outlined',
|
153 | size: 'small'
|
154 | },
|
155 | style: {
|
156 | transform: 'translate(14px, 9px) scale(1)'
|
157 | }
|
158 | }, {
|
159 | props: ({
|
160 | variant,
|
161 | ownerState
|
162 | }) => variant === 'outlined' && ownerState.shrink,
|
163 | style: {
|
164 | userSelect: 'none',
|
165 | pointerEvents: 'auto',
|
166 |
|
167 |
|
168 | maxWidth: 'calc(133% - 32px)',
|
169 | transform: 'translate(14px, -9px) scale(0.75)'
|
170 | }
|
171 | }]
|
172 | })));
|
173 | const InputLabel = React.forwardRef(function InputLabel(inProps, ref) {
|
174 | const props = useDefaultProps({
|
175 | name: 'MuiInputLabel',
|
176 | props: inProps
|
177 | });
|
178 | const {
|
179 | disableAnimation = false,
|
180 | margin,
|
181 | shrink: shrinkProp,
|
182 | variant,
|
183 | className,
|
184 | ...other
|
185 | } = props;
|
186 | const muiFormControl = useFormControl();
|
187 | let shrink = shrinkProp;
|
188 | if (typeof shrink === 'undefined' && muiFormControl) {
|
189 | shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
|
190 | }
|
191 | const fcs = formControlState({
|
192 | props,
|
193 | muiFormControl,
|
194 | states: ['size', 'variant', 'required', 'focused']
|
195 | });
|
196 | const ownerState = {
|
197 | ...props,
|
198 | disableAnimation,
|
199 | formControl: muiFormControl,
|
200 | shrink,
|
201 | size: fcs.size,
|
202 | variant: fcs.variant,
|
203 | required: fcs.required,
|
204 | focused: fcs.focused
|
205 | };
|
206 | const classes = useUtilityClasses(ownerState);
|
207 | return _jsx(InputLabelRoot, {
|
208 | "data-shrink": shrink,
|
209 | ref: ref,
|
210 | className: clsx(classes.root, className),
|
211 | ...other,
|
212 | ownerState: ownerState,
|
213 | classes: classes
|
214 | });
|
215 | });
|
216 | process.env.NODE_ENV !== "production" ? InputLabel.propTypes = {
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | |
222 |
|
223 |
|
224 | children: PropTypes.node,
|
225 | |
226 |
|
227 |
|
228 | classes: PropTypes.object,
|
229 | |
230 |
|
231 |
|
232 | className: PropTypes.string,
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 | color: PropTypes .oneOfType([PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
|
239 | |
240 |
|
241 |
|
242 |
|
243 | disableAnimation: PropTypes.bool,
|
244 | |
245 |
|
246 |
|
247 | disabled: PropTypes.bool,
|
248 | |
249 |
|
250 |
|
251 | error: PropTypes.bool,
|
252 | |
253 |
|
254 |
|
255 | focused: PropTypes.bool,
|
256 | |
257 |
|
258 |
|
259 |
|
260 | margin: PropTypes.oneOf(['dense']),
|
261 | |
262 |
|
263 |
|
264 | required: PropTypes.bool,
|
265 | |
266 |
|
267 |
|
268 | shrink: PropTypes.bool,
|
269 | |
270 |
|
271 |
|
272 |
|
273 | size: PropTypes .oneOfType([PropTypes.oneOf(['normal', 'small']), PropTypes.string]),
|
274 | |
275 |
|
276 |
|
277 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
278 | |
279 |
|
280 |
|
281 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
282 | } : void 0;
|
283 | export default InputLabel; |
\ | No newline at end of file |