UNPKG

6.14 kBJavaScriptView Raw
1'use client';
2
3var _span;
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import composeClasses from '@mui/utils/composeClasses';
8import capitalize from "../utils/capitalize.js";
9import Typography from "../Typography/index.js";
10import FormControlContext from "../FormControl/FormControlContext.js";
11import useFormControl from "../FormControl/useFormControl.js";
12import { styled } from "../zero-styled/index.js";
13import memoTheme from "../utils/memoTheme.js";
14import { useDefaultProps } from "../DefaultPropsProvider/index.js";
15import inputAdornmentClasses, { getInputAdornmentUtilityClass } from "./inputAdornmentClasses.js";
16import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17const overridesResolver = (props, styles) => {
18 const {
19 ownerState
20 } = props;
21 return [styles.root, styles[`position${capitalize(ownerState.position)}`], ownerState.disablePointerEvents === true && styles.disablePointerEvents, styles[ownerState.variant]];
22};
23const useUtilityClasses = ownerState => {
24 const {
25 classes,
26 disablePointerEvents,
27 hiddenLabel,
28 position,
29 size,
30 variant
31 } = ownerState;
32 const slots = {
33 root: ['root', disablePointerEvents && 'disablePointerEvents', position && `position${capitalize(position)}`, variant, hiddenLabel && 'hiddenLabel', size && `size${capitalize(size)}`]
34 };
35 return composeClasses(slots, getInputAdornmentUtilityClass, classes);
36};
37const InputAdornmentRoot = styled('div', {
38 name: 'MuiInputAdornment',
39 slot: 'Root',
40 overridesResolver
41})(memoTheme(({
42 theme
43}) => ({
44 display: 'flex',
45 maxHeight: '2em',
46 alignItems: 'center',
47 whiteSpace: 'nowrap',
48 color: (theme.vars || theme).palette.action.active,
49 variants: [{
50 props: {
51 variant: 'filled'
52 },
53 style: {
54 [`&.${inputAdornmentClasses.positionStart}&:not(.${inputAdornmentClasses.hiddenLabel})`]: {
55 marginTop: 16
56 }
57 }
58 }, {
59 props: {
60 position: 'start'
61 },
62 style: {
63 marginRight: 8
64 }
65 }, {
66 props: {
67 position: 'end'
68 },
69 style: {
70 marginLeft: 8
71 }
72 }, {
73 props: {
74 disablePointerEvents: true
75 },
76 style: {
77 pointerEvents: 'none'
78 }
79 }]
80})));
81const InputAdornment = /*#__PURE__*/React.forwardRef(function InputAdornment(inProps, ref) {
82 const props = useDefaultProps({
83 props: inProps,
84 name: 'MuiInputAdornment'
85 });
86 const {
87 children,
88 className,
89 component = 'div',
90 disablePointerEvents = false,
91 disableTypography = false,
92 position,
93 variant: variantProp,
94 ...other
95 } = props;
96 const muiFormControl = useFormControl() || {};
97 let variant = variantProp;
98 if (variantProp && muiFormControl.variant) {
99 if (process.env.NODE_ENV !== 'production') {
100 if (variantProp === muiFormControl.variant) {
101 console.error('MUI: The `InputAdornment` variant infers the variant prop ' + 'you do not have to provide one.');
102 }
103 }
104 }
105 if (muiFormControl && !variant) {
106 variant = muiFormControl.variant;
107 }
108 const ownerState = {
109 ...props,
110 hiddenLabel: muiFormControl.hiddenLabel,
111 size: muiFormControl.size,
112 disablePointerEvents,
113 position,
114 variant
115 };
116 const classes = useUtilityClasses(ownerState);
117 return /*#__PURE__*/_jsx(FormControlContext.Provider, {
118 value: null,
119 children: /*#__PURE__*/_jsx(InputAdornmentRoot, {
120 as: component,
121 ownerState: ownerState,
122 className: clsx(classes.root, className),
123 ref: ref,
124 ...other,
125 children: typeof children === 'string' && !disableTypography ? /*#__PURE__*/_jsx(Typography, {
126 color: "textSecondary",
127 children: children
128 }) : /*#__PURE__*/_jsxs(React.Fragment, {
129 children: [position === 'start' ? (/* notranslate needed while Google Translate will not fix zero-width space issue */_span || (_span = /*#__PURE__*/_jsx("span", {
130 className: "notranslate",
131 children: "\u200B"
132 }))) : null, children]
133 })
134 })
135 });
136});
137process.env.NODE_ENV !== "production" ? InputAdornment.propTypes /* remove-proptypes */ = {
138 // ┌────────────────────────────── Warning ──────────────────────────────┐
139 // │ These PropTypes are generated from the TypeScript type definitions. │
140 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
141 // └─────────────────────────────────────────────────────────────────────┘
142 /**
143 * The content of the component, normally an `IconButton` or string.
144 */
145 children: PropTypes.node,
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 component used for the root node.
156 * Either a string to use a HTML element or a component.
157 */
158 component: PropTypes.elementType,
159 /**
160 * Disable pointer events on the root.
161 * This allows for the content of the adornment to focus the `input` on click.
162 * @default false
163 */
164 disablePointerEvents: PropTypes.bool,
165 /**
166 * If children is a string then disable wrapping in a Typography component.
167 * @default false
168 */
169 disableTypography: PropTypes.bool,
170 /**
171 * The position this adornment should appear relative to the `Input`.
172 */
173 position: PropTypes.oneOf(['end', 'start']).isRequired,
174 /**
175 * The system prop that allows defining system overrides as well as additional CSS styles.
176 */
177 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
178 /**
179 * The variant to use.
180 * Note: If you are using the `TextField` component or the `FormControl` component
181 * you do not have to set this manually.
182 */
183 variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
184} : void 0;
185export default InputAdornment;
\No newline at end of file