UNPKG

11.7 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _deepmerge = _interopRequireDefault(require("@mui/utils/deepmerge"));
14var _getReactElementRef = _interopRequireDefault(require("@mui/utils/getReactElementRef"));
15var _SelectInput = _interopRequireDefault(require("./SelectInput"));
16var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
17var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
18var _ArrowDropDown = _interopRequireDefault(require("../internal/svg-icons/ArrowDropDown"));
19var _Input = _interopRequireDefault(require("../Input"));
20var _NativeSelectInput = _interopRequireDefault(require("../NativeSelect/NativeSelectInput"));
21var _FilledInput = _interopRequireDefault(require("../FilledInput"));
22var _OutlinedInput = _interopRequireDefault(require("../OutlinedInput"));
23var _DefaultPropsProvider = require("../DefaultPropsProvider");
24var _useForkRef = _interopRequireDefault(require("../utils/useForkRef"));
25var _zeroStyled = require("../zero-styled");
26var _rootShouldForwardProp = _interopRequireDefault(require("../styles/rootShouldForwardProp"));
27var _jsxRuntime = require("react/jsx-runtime");
28const useUtilityClasses = ownerState => {
29 const {
30 classes
31 } = ownerState;
32 return classes;
33};
34const styledRootConfig = {
35 name: 'MuiSelect',
36 overridesResolver: (props, styles) => styles.root,
37 shouldForwardProp: prop => (0, _rootShouldForwardProp.default)(prop) && prop !== 'variant',
38 slot: 'Root'
39};
40const StyledInput = (0, _zeroStyled.styled)(_Input.default, styledRootConfig)('');
41const StyledOutlinedInput = (0, _zeroStyled.styled)(_OutlinedInput.default, styledRootConfig)('');
42const StyledFilledInput = (0, _zeroStyled.styled)(_FilledInput.default, styledRootConfig)('');
43const Select = /*#__PURE__*/React.forwardRef(function Select(inProps, ref) {
44 const props = (0, _DefaultPropsProvider.useDefaultProps)({
45 name: 'MuiSelect',
46 props: inProps
47 });
48 const {
49 autoWidth = false,
50 children,
51 classes: classesProp = {},
52 className,
53 defaultOpen = false,
54 displayEmpty = false,
55 IconComponent = _ArrowDropDown.default,
56 id,
57 input,
58 inputProps,
59 label,
60 labelId,
61 MenuProps,
62 multiple = false,
63 native = false,
64 onClose,
65 onOpen,
66 open,
67 renderValue,
68 SelectDisplayProps,
69 variant: variantProp = 'outlined',
70 ...other
71 } = props;
72 const inputComponent = native ? _NativeSelectInput.default : _SelectInput.default;
73 const muiFormControl = (0, _useFormControl.default)();
74 const fcs = (0, _formControlState.default)({
75 props,
76 muiFormControl,
77 states: ['variant', 'error']
78 });
79 const variant = fcs.variant || variantProp;
80 const ownerState = {
81 ...props,
82 variant,
83 classes: classesProp
84 };
85 const classes = useUtilityClasses(ownerState);
86 const {
87 root,
88 ...restOfClasses
89 } = classes;
90 const InputComponent = input || {
91 standard: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledInput, {
92 ownerState: ownerState
93 }),
94 outlined: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledOutlinedInput, {
95 label: label,
96 ownerState: ownerState
97 }),
98 filled: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledFilledInput, {
99 ownerState: ownerState
100 })
101 }[variant];
102 const inputComponentRef = (0, _useForkRef.default)(ref, (0, _getReactElementRef.default)(InputComponent));
103 return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
104 children: /*#__PURE__*/React.cloneElement(InputComponent, {
105 // Most of the logic is implemented in `SelectInput`.
106 // The `Select` component is a simple API wrapper to expose something better to play with.
107 inputComponent,
108 inputProps: {
109 children,
110 error: fcs.error,
111 IconComponent,
112 variant,
113 type: undefined,
114 // We render a select. We can ignore the type provided by the `Input`.
115 multiple,
116 ...(native ? {
117 id
118 } : {
119 autoWidth,
120 defaultOpen,
121 displayEmpty,
122 labelId,
123 MenuProps,
124 onClose,
125 onOpen,
126 open,
127 renderValue,
128 SelectDisplayProps: {
129 id,
130 ...SelectDisplayProps
131 }
132 }),
133 ...inputProps,
134 classes: inputProps ? (0, _deepmerge.default)(restOfClasses, inputProps.classes) : restOfClasses,
135 ...(input ? input.props.inputProps : {})
136 },
137 ...((multiple && native || displayEmpty) && variant === 'outlined' ? {
138 notched: true
139 } : {}),
140 ref: inputComponentRef,
141 className: (0, _clsx.default)(InputComponent.props.className, className, classes.root),
142 // If a custom input is provided via 'input' prop, do not allow 'variant' to be propagated to it's root element. See https://github.com/mui/material-ui/issues/33894.
143 ...(!input && {
144 variant
145 }),
146 ...other
147 })
148 });
149});
150process.env.NODE_ENV !== "production" ? Select.propTypes /* remove-proptypes */ = {
151 // β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ Warning ──────────────────────────────┐
152 // β”‚ These PropTypes are generated from the TypeScript type definitions. β”‚
153 // β”‚ To update them, edit the d.ts file and run `pnpm proptypes`. β”‚
154 // β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
155 /**
156 * If `true`, the width of the popover will automatically be set according to the items inside the
157 * menu, otherwise it will be at least the width of the select input.
158 * @default false
159 */
160 autoWidth: _propTypes.default.bool,
161 /**
162 * The option elements to populate the select with.
163 * Can be some `MenuItem` when `native` is false and `option` when `native` is true.
164 *
165 * ⚠️The `MenuItem` elements **must** be direct descendants when `native` is false.
166 */
167 children: _propTypes.default.node,
168 /**
169 * Override or extend the styles applied to the component.
170 * @default {}
171 */
172 classes: _propTypes.default.object,
173 /**
174 * @ignore
175 */
176 className: _propTypes.default.string,
177 /**
178 * If `true`, the component is initially open. Use when the component open state is not controlled (i.e. the `open` prop is not defined).
179 * You can only use it when the `native` prop is `false` (default).
180 * @default false
181 */
182 defaultOpen: _propTypes.default.bool,
183 /**
184 * The default value. Use when the component is not controlled.
185 */
186 defaultValue: _propTypes.default.any,
187 /**
188 * If `true`, a value is displayed even if no items are selected.
189 *
190 * In order to display a meaningful value, a function can be passed to the `renderValue` prop which
191 * returns the value to be displayed when no items are selected.
192 *
193 * ⚠️ When using this prop, make sure the label doesn't overlap with the empty displayed value.
194 * The label should either be hidden or forced to a shrunk state.
195 * @default false
196 */
197 displayEmpty: _propTypes.default.bool,
198 /**
199 * The icon that displays the arrow.
200 * @default ArrowDropDownIcon
201 */
202 IconComponent: _propTypes.default.elementType,
203 /**
204 * The `id` of the wrapper element or the `select` element when `native`.
205 */
206 id: _propTypes.default.string,
207 /**
208 * An `Input` element; does not have to be a material-ui specific `Input`.
209 */
210 input: _propTypes.default.element,
211 /**
212 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
213 * When `native` is `true`, the attributes are applied on the `select` element.
214 */
215 inputProps: _propTypes.default.object,
216 /**
217 * See [OutlinedInput#label](https://mui.com/material-ui/api/outlined-input/#props)
218 */
219 label: _propTypes.default.node,
220 /**
221 * The ID of an element that acts as an additional label. The Select will
222 * be labelled by the additional label and the selected value.
223 */
224 labelId: _propTypes.default.string,
225 /**
226 * Props applied to the [`Menu`](https://mui.com/material-ui/api/menu/) element.
227 */
228 MenuProps: _propTypes.default.object,
229 /**
230 * If `true`, `value` must be an array and the menu will support multiple selections.
231 * @default false
232 */
233 multiple: _propTypes.default.bool,
234 /**
235 * If `true`, the component uses a native `select` element.
236 * @default false
237 */
238 native: _propTypes.default.bool,
239 /**
240 * Callback fired when a menu item is selected.
241 *
242 * @param {SelectChangeEvent<Value>} event The event source of the callback.
243 * You can pull out the new value by accessing `event.target.value` (any).
244 * **Warning**: This is a generic event, not a change event, unless the change event is caused by browser autofill.
245 * @param {object} [child] The react element that was selected when `native` is `false` (default).
246 */
247 onChange: _propTypes.default.func,
248 /**
249 * Callback fired when the component requests to be closed.
250 * Use it in either controlled (see the `open` prop), or uncontrolled mode (to detect when the Select collapses).
251 *
252 * @param {object} event The event source of the callback.
253 */
254 onClose: _propTypes.default.func,
255 /**
256 * Callback fired when the component requests to be opened.
257 * Use it in either controlled (see the `open` prop), or uncontrolled mode (to detect when the Select expands).
258 *
259 * @param {object} event The event source of the callback.
260 */
261 onOpen: _propTypes.default.func,
262 /**
263 * If `true`, the component is shown.
264 * You can only use it when the `native` prop is `false` (default).
265 */
266 open: _propTypes.default.bool,
267 /**
268 * Render the selected value.
269 * You can only use it when the `native` prop is `false` (default).
270 *
271 * @param {any} value The `value` provided to the component.
272 * @returns {ReactNode}
273 */
274 renderValue: _propTypes.default.func,
275 /**
276 * Props applied to the clickable div element.
277 */
278 SelectDisplayProps: _propTypes.default.object,
279 /**
280 * The system prop that allows defining system overrides as well as additional CSS styles.
281 */
282 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]),
283 /**
284 * The `input` value. Providing an empty string will select no options.
285 * Set to an empty string `''` if you don't want any of the available options to be selected.
286 *
287 * If the value is an object it must have reference equality with the option in order to be selected.
288 * If the value is not an object, the string representation must match with the string representation of the option in order to be selected.
289 */
290 value: _propTypes.default.oneOfType([_propTypes.default.oneOf(['']), _propTypes.default.any]),
291 /**
292 * The variant to use.
293 * @default 'outlined'
294 */
295 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
296} : void 0;
297Select.muiName = 'Select';
298var _default = exports.default = Select;
\No newline at end of file