@mui/material
Version:
React components that implement Google's Material Design.
222 lines (221 loc) • 9.61 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _base = require("@mui/base");
var _clsx = _interopRequireDefault(require("clsx"));
var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
var _FormLabel = _interopRequireWildcard(require("../FormLabel"));
var _useThemeProps = _interopRequireDefault(require("../styles/useThemeProps"));
var _styled = _interopRequireWildcard(require("../styles/styled"));
var _inputLabelClasses = require("./inputLabelClasses");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["disableAnimation", "margin", "shrink", "variant", "className"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const useUtilityClasses = ownerState => {
const {
classes,
formControl,
size,
shrink,
disableAnimation,
variant,
required
} = ownerState;
const slots = {
root: ['root', formControl && 'formControl', !disableAnimation && 'animated', shrink && 'shrink', size === 'small' && 'sizeSmall', variant],
asterisk: [required && 'asterisk']
};
const composedClasses = (0, _base.unstable_composeClasses)(slots, _inputLabelClasses.getInputLabelUtilityClasses, classes);
return (0, _extends2.default)({}, classes, composedClasses);
};
const InputLabelRoot = (0, _styled.default)(_FormLabel.default, {
shouldForwardProp: prop => (0, _styled.rootShouldForwardProp)(prop) || prop === 'classes',
name: 'MuiInputLabel',
slot: 'Root',
overridesResolver: (props, styles) => {
const {
ownerState
} = props;
return [{
[`& .${_FormLabel.formLabelClasses.asterisk}`]: styles.asterisk
}, styles.root, ownerState.formControl && styles.formControl, ownerState.size === 'small' && styles.sizeSmall, ownerState.shrink && styles.shrink, !ownerState.disableAnimation && styles.animated, styles[ownerState.variant]];
}
})(({
theme,
ownerState
}) => (0, _extends2.default)({
display: 'block',
transformOrigin: 'top left',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
maxWidth: '100%'
}, ownerState.formControl && {
position: 'absolute',
left: 0,
top: 0,
// slight alteration to spec spacing to match visual spec result
transform: 'translate(0, 20px) scale(1)'
}, ownerState.size === 'small' && {
// Compensation for the `Input.inputSizeSmall` style.
transform: 'translate(0, 17px) scale(1)'
}, ownerState.shrink && {
transform: 'translate(0, -1.5px) scale(0.75)',
transformOrigin: 'top left',
maxWidth: '133%'
}, !ownerState.disableAnimation && {
transition: theme.transitions.create(['color', 'transform', 'max-width'], {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
})
}, ownerState.variant === 'filled' && (0, _extends2.default)({
// Chrome's autofill feature gives the input field a yellow background.
// Since the input field is behind the label in the HTML tree,
// the input field is drawn last and hides the label with an opaque background color.
// zIndex: 1 will raise the label above opaque background-colors of input.
zIndex: 1,
pointerEvents: 'none',
transform: 'translate(12px, 16px) scale(1)',
maxWidth: 'calc(100% - 24px)'
}, ownerState.size === 'small' && {
transform: 'translate(12px, 13px) scale(1)'
}, ownerState.shrink && (0, _extends2.default)({
userSelect: 'none',
pointerEvents: 'auto',
transform: 'translate(12px, 7px) scale(0.75)',
maxWidth: 'calc(133% - 24px)'
}, ownerState.size === 'small' && {
transform: 'translate(12px, 4px) scale(0.75)'
})), ownerState.variant === 'outlined' && (0, _extends2.default)({
// see comment above on filled.zIndex
zIndex: 1,
pointerEvents: 'none',
transform: 'translate(14px, 16px) scale(1)',
maxWidth: 'calc(100% - 24px)'
}, ownerState.size === 'small' && {
transform: 'translate(14px, 9px) scale(1)'
}, ownerState.shrink && {
userSelect: 'none',
pointerEvents: 'auto',
// Theoretically, we should have (8+5)*2/0.75 = 34px
// but it feels a better when it bleeds a bit on the left, so 32px.
maxWidth: 'calc(133% - 32px)',
transform: 'translate(14px, -9px) scale(0.75)'
})));
const InputLabel = /*#__PURE__*/React.forwardRef(function InputLabel(inProps, ref) {
const props = (0, _useThemeProps.default)({
name: 'MuiInputLabel',
props: inProps
});
const {
disableAnimation = false,
shrink: shrinkProp,
className
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const muiFormControl = (0, _useFormControl.default)();
let shrink = shrinkProp;
if (typeof shrink === 'undefined' && muiFormControl) {
shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
}
const fcs = (0, _formControlState.default)({
props,
muiFormControl,
states: ['size', 'variant', 'required']
});
const ownerState = (0, _extends2.default)({}, props, {
disableAnimation,
formControl: muiFormControl,
shrink,
size: fcs.size,
variant: fcs.variant,
required: fcs.required
});
const classes = useUtilityClasses(ownerState);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(InputLabelRoot, (0, _extends2.default)({
"data-shrink": shrink,
ownerState: ownerState,
ref: ref,
className: (0, _clsx.default)(classes.root, className)
}, other, {
classes: classes
}));
});
process.env.NODE_ENV !== "production" ? InputLabel.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The content of the component.
*/
children: _propTypes.default.node,
/**
* Override or extend the styles applied to the component.
*/
classes: _propTypes.default.object,
/**
* @ignore
*/
className: _propTypes.default.string,
/**
* The color of the component.
* It supports both default and custom theme colors, which can be added as shown in the
* [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
*/
color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), _propTypes.default.string]),
/**
* If `true`, the transition animation is disabled.
* @default false
*/
disableAnimation: _propTypes.default.bool,
/**
* If `true`, the component is disabled.
*/
disabled: _propTypes.default.bool,
/**
* If `true`, the label is displayed in an error state.
*/
error: _propTypes.default.bool,
/**
* If `true`, the `input` of this label is focused.
*/
focused: _propTypes.default.bool,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: _propTypes.default.oneOf(['dense']),
/**
* if `true`, the label will indicate that the `input` is required.
*/
required: _propTypes.default.bool,
/**
* If `true`, the label is shrunk.
*/
shrink: _propTypes.default.bool,
/**
* The size of the component.
* @default 'normal'
*/
size: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['normal', 'small']), _propTypes.default.string]),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
/**
* The variant to use.
*/
variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
} : void 0;
var _default = InputLabel;
exports.default = _default;