UNPKG

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