UNPKG

8.67 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 composeClasses from '@mui/utils/composeClasses';
9import clsx from 'clsx';
10import formControlState from '../FormControl/formControlState';
11import useFormControl from '../FormControl/useFormControl';
12import FormLabel, { formLabelClasses } from '../FormLabel';
13import { useDefaultProps } from '../DefaultPropsProvider';
14import capitalize from '../utils/capitalize';
15import styled, { rootShouldForwardProp } from '../styles/styled';
16import { getInputLabelUtilityClasses } from './inputLabelClasses';
17import { jsx as _jsx } from "react/jsx-runtime";
18var useUtilityClasses = function useUtilityClasses(ownerState) {
19 var classes = ownerState.classes,
20 formControl = ownerState.formControl,
21 size = ownerState.size,
22 shrink = ownerState.shrink,
23 disableAnimation = ownerState.disableAnimation,
24 variant = ownerState.variant,
25 required = ownerState.required;
26 var slots = {
27 root: ['root', formControl && 'formControl', !disableAnimation && 'animated', shrink && 'shrink', size && size !== 'normal' && "size".concat(capitalize(size)), variant],
28 asterisk: [required && 'asterisk']
29 };
30 var composedClasses = composeClasses(slots, getInputLabelUtilityClasses, classes);
31 return _extends({}, classes, composedClasses);
32};
33var InputLabelRoot = styled(FormLabel, {
34 shouldForwardProp: function shouldForwardProp(prop) {
35 return rootShouldForwardProp(prop) || prop === 'classes';
36 },
37 name: 'MuiInputLabel',
38 slot: 'Root',
39 overridesResolver: function overridesResolver(props, styles) {
40 var ownerState = props.ownerState;
41 return [_defineProperty({}, "& .".concat(formLabelClasses.asterisk), styles.asterisk), 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]];
42 }
43})(function (_ref2) {
44 var theme = _ref2.theme,
45 ownerState = _ref2.ownerState;
46 return _extends({
47 display: 'block',
48 transformOrigin: 'top left',
49 whiteSpace: 'nowrap',
50 overflow: 'hidden',
51 textOverflow: 'ellipsis',
52 maxWidth: '100%'
53 }, ownerState.formControl && {
54 position: 'absolute',
55 left: 0,
56 top: 0,
57 // slight alteration to spec spacing to match visual spec result
58 transform: 'translate(0, 20px) scale(1)'
59 }, ownerState.size === 'small' && {
60 // Compensation for the `Input.inputSizeSmall` style.
61 transform: 'translate(0, 17px) scale(1)'
62 }, ownerState.shrink && {
63 transform: 'translate(0, -1.5px) scale(0.75)',
64 transformOrigin: 'top left',
65 maxWidth: '133%'
66 }, !ownerState.disableAnimation && {
67 transition: theme.transitions.create(['color', 'transform', 'max-width'], {
68 duration: theme.transitions.duration.shorter,
69 easing: theme.transitions.easing.easeOut
70 })
71 }, ownerState.variant === 'filled' && _extends({
72 // Chrome's autofill feature gives the input field a yellow background.
73 // Since the input field is behind the label in the HTML tree,
74 // the input field is drawn last and hides the label with an opaque background color.
75 // zIndex: 1 will raise the label above opaque background-colors of input.
76 zIndex: 1,
77 pointerEvents: 'none',
78 transform: 'translate(12px, 16px) scale(1)',
79 maxWidth: 'calc(100% - 24px)'
80 }, ownerState.size === 'small' && {
81 transform: 'translate(12px, 13px) scale(1)'
82 }, ownerState.shrink && _extends({
83 userSelect: 'none',
84 pointerEvents: 'auto',
85 transform: 'translate(12px, 7px) scale(0.75)',
86 maxWidth: 'calc(133% - 24px)'
87 }, ownerState.size === 'small' && {
88 transform: 'translate(12px, 4px) scale(0.75)'
89 })), ownerState.variant === 'outlined' && _extends({
90 // see comment above on filled.zIndex
91 zIndex: 1,
92 pointerEvents: 'none',
93 transform: 'translate(14px, 16px) scale(1)',
94 maxWidth: 'calc(100% - 24px)'
95 }, ownerState.size === 'small' && {
96 transform: 'translate(14px, 9px) scale(1)'
97 }, ownerState.shrink && {
98 userSelect: 'none',
99 pointerEvents: 'auto',
100 // Theoretically, we should have (8+5)*2/0.75 = 34px
101 // but it feels a better when it bleeds a bit on the left, so 32px.
102 maxWidth: 'calc(133% - 32px)',
103 transform: 'translate(14px, -9px) scale(0.75)'
104 }));
105});
106var InputLabel = /*#__PURE__*/React.forwardRef(function InputLabel(inProps, ref) {
107 var props = useDefaultProps({
108 name: 'MuiInputLabel',
109 props: inProps
110 });
111 var _props$disableAnimati = props.disableAnimation,
112 disableAnimation = _props$disableAnimati === void 0 ? false : _props$disableAnimati,
113 margin = props.margin,
114 shrinkProp = props.shrink,
115 variant = props.variant,
116 className = props.className,
117 other = _objectWithoutProperties(props, ["disableAnimation", "margin", "shrink", "variant", "className"]);
118 var muiFormControl = useFormControl();
119 var shrink = shrinkProp;
120 if (typeof shrink === 'undefined' && muiFormControl) {
121 shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
122 }
123 var fcs = formControlState({
124 props: props,
125 muiFormControl: muiFormControl,
126 states: ['size', 'variant', 'required', 'focused']
127 });
128 var ownerState = _extends({}, props, {
129 disableAnimation: disableAnimation,
130 formControl: muiFormControl,
131 shrink: shrink,
132 size: fcs.size,
133 variant: fcs.variant,
134 required: fcs.required,
135 focused: fcs.focused
136 });
137 var classes = useUtilityClasses(ownerState);
138 return /*#__PURE__*/_jsx(InputLabelRoot, _extends({
139 "data-shrink": shrink,
140 ownerState: ownerState,
141 ref: ref,
142 className: clsx(classes.root, className)
143 }, other, {
144 classes: classes
145 }));
146});
147process.env.NODE_ENV !== "production" ? InputLabel.propTypes /* remove-proptypes */ = {
148 // ┌────────────────────────────── Warning ──────────────────────────────┐
149 // │ These PropTypes are generated from the TypeScript type definitions. │
150 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
151 // └─────────────────────────────────────────────────────────────────────┘
152 /**
153 * The content of the component.
154 */
155 children: PropTypes.node,
156 /**
157 * Override or extend the styles applied to the component.
158 */
159 classes: PropTypes.object,
160 /**
161 * @ignore
162 */
163 className: PropTypes.string,
164 /**
165 * The color of the component.
166 * It supports both default and custom theme colors, which can be added as shown in the
167 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
168 */
169 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
170 /**
171 * If `true`, the transition animation is disabled.
172 * @default false
173 */
174 disableAnimation: PropTypes.bool,
175 /**
176 * If `true`, the component is disabled.
177 */
178 disabled: PropTypes.bool,
179 /**
180 * If `true`, the label is displayed in an error state.
181 */
182 error: PropTypes.bool,
183 /**
184 * If `true`, the `input` of this label is focused.
185 */
186 focused: PropTypes.bool,
187 /**
188 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
189 * FormControl.
190 */
191 margin: PropTypes.oneOf(['dense']),
192 /**
193 * if `true`, the label will indicate that the `input` is required.
194 */
195 required: PropTypes.bool,
196 /**
197 * If `true`, the label is shrunk.
198 */
199 shrink: PropTypes.bool,
200 /**
201 * The size of the component.
202 * @default 'normal'
203 */
204 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['normal', 'small']), PropTypes.string]),
205 /**
206 * The system prop that allows defining system overrides as well as additional CSS styles.
207 */
208 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
209 /**
210 * The variant to use.
211 */
212 variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
213} : void 0;
214export default InputLabel;
\No newline at end of file