286 lines
9.7 KiB
JavaScript
286 lines
9.7 KiB
JavaScript
"use strict";
|
||
|
||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||
|
||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||
|
||
Object.defineProperty(exports, "__esModule", {
|
||
value: true
|
||
});
|
||
exports.default = exports.styles = void 0;
|
||
|
||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
||
|
||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
||
|
||
var React = _interopRequireWildcard(require("react"));
|
||
|
||
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||
|
||
var _styles = require("@material-ui/styles");
|
||
|
||
var _SelectInput = _interopRequireDefault(require("./SelectInput"));
|
||
|
||
var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
|
||
|
||
var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
|
||
|
||
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
||
|
||
var _ArrowDropDown = _interopRequireDefault(require("../internal/svg-icons/ArrowDropDown"));
|
||
|
||
var _Input = _interopRequireDefault(require("../Input"));
|
||
|
||
var _NativeSelect = require("../NativeSelect/NativeSelect");
|
||
|
||
var _NativeSelectInput = _interopRequireDefault(require("../NativeSelect/NativeSelectInput"));
|
||
|
||
var _FilledInput = _interopRequireDefault(require("../FilledInput"));
|
||
|
||
var _OutlinedInput = _interopRequireDefault(require("../OutlinedInput"));
|
||
|
||
var styles = _NativeSelect.styles;
|
||
exports.styles = styles;
|
||
|
||
var _ref = /*#__PURE__*/React.createElement(_Input.default, null);
|
||
|
||
var _ref2 = /*#__PURE__*/React.createElement(_FilledInput.default, null);
|
||
|
||
var Select = /*#__PURE__*/React.forwardRef(function Select(props, ref) {
|
||
var _props$autoWidth = props.autoWidth,
|
||
autoWidth = _props$autoWidth === void 0 ? false : _props$autoWidth,
|
||
children = props.children,
|
||
classes = props.classes,
|
||
_props$displayEmpty = props.displayEmpty,
|
||
displayEmpty = _props$displayEmpty === void 0 ? false : _props$displayEmpty,
|
||
_props$IconComponent = props.IconComponent,
|
||
IconComponent = _props$IconComponent === void 0 ? _ArrowDropDown.default : _props$IconComponent,
|
||
id = props.id,
|
||
input = props.input,
|
||
inputProps = props.inputProps,
|
||
label = props.label,
|
||
labelId = props.labelId,
|
||
_props$labelWidth = props.labelWidth,
|
||
labelWidth = _props$labelWidth === void 0 ? 0 : _props$labelWidth,
|
||
MenuProps = props.MenuProps,
|
||
_props$multiple = props.multiple,
|
||
multiple = _props$multiple === void 0 ? false : _props$multiple,
|
||
_props$native = props.native,
|
||
native = _props$native === void 0 ? false : _props$native,
|
||
onClose = props.onClose,
|
||
onOpen = props.onOpen,
|
||
open = props.open,
|
||
renderValue = props.renderValue,
|
||
SelectDisplayProps = props.SelectDisplayProps,
|
||
_props$variant = props.variant,
|
||
variantProps = _props$variant === void 0 ? 'standard' : _props$variant,
|
||
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"]);
|
||
var inputComponent = native ? _NativeSelectInput.default : _SelectInput.default;
|
||
var muiFormControl = (0, _useFormControl.default)();
|
||
var fcs = (0, _formControlState.default)({
|
||
props: props,
|
||
muiFormControl: muiFormControl,
|
||
states: ['variant']
|
||
});
|
||
var variant = fcs.variant || variantProps;
|
||
var InputComponent = input || {
|
||
standard: _ref,
|
||
outlined: /*#__PURE__*/React.createElement(_OutlinedInput.default, {
|
||
label: label,
|
||
labelWidth: labelWidth
|
||
}),
|
||
filled: _ref2
|
||
}[variant];
|
||
return /*#__PURE__*/React.cloneElement(InputComponent, (0, _extends2.default)({
|
||
// Most of the logic is implemented in `SelectInput`.
|
||
// The `Select` component is a simple API wrapper to expose something better to play with.
|
||
inputComponent: inputComponent,
|
||
inputProps: (0, _extends2.default)({
|
||
children: children,
|
||
IconComponent: IconComponent,
|
||
variant: variant,
|
||
type: undefined,
|
||
// We render a select. We can ignore the type provided by the `Input`.
|
||
multiple: multiple
|
||
}, native ? {
|
||
id: id
|
||
} : {
|
||
autoWidth: autoWidth,
|
||
displayEmpty: displayEmpty,
|
||
labelId: labelId,
|
||
MenuProps: MenuProps,
|
||
onClose: onClose,
|
||
onOpen: onOpen,
|
||
open: open,
|
||
renderValue: renderValue,
|
||
SelectDisplayProps: (0, _extends2.default)({
|
||
id: id
|
||
}, SelectDisplayProps)
|
||
}, inputProps, {
|
||
classes: inputProps ? (0, _styles.mergeClasses)({
|
||
baseClasses: classes,
|
||
newClasses: inputProps.classes,
|
||
Component: Select
|
||
}) : classes
|
||
}, input ? input.props.inputProps : {}),
|
||
ref: ref
|
||
}, other));
|
||
});
|
||
process.env.NODE_ENV !== "production" ? Select.propTypes = {
|
||
// ----------------------------- Warning --------------------------------
|
||
// | These PropTypes are generated from the TypeScript type definitions |
|
||
// | To update them edit the d.ts file and run "yarn proptypes" |
|
||
// ----------------------------------------------------------------------
|
||
|
||
/**
|
||
* If `true`, the width of the popover will automatically be set according to the items inside the
|
||
* menu, otherwise it will be at least the width of the select input.
|
||
*/
|
||
autoWidth: _propTypes.default.bool,
|
||
|
||
/**
|
||
* The option elements to populate the select with.
|
||
* Can be some `MenuItem` when `native` is false and `option` when `native` is true.
|
||
*
|
||
* ⚠️The `MenuItem` elements **must** be direct descendants when `native` is false.
|
||
*/
|
||
children: _propTypes.default.node,
|
||
|
||
/**
|
||
* Override or extend the styles applied to the component.
|
||
* See [CSS API](#css) below for more details.
|
||
*/
|
||
classes: _propTypes.default.object,
|
||
|
||
/**
|
||
* The default element value. Use when the component is not controlled.
|
||
*/
|
||
defaultValue: _propTypes.default.any,
|
||
|
||
/**
|
||
* If `true`, a value is displayed even if no items are selected.
|
||
*
|
||
* 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.
|
||
* You can only use it when the `native` prop is `false` (default).
|
||
*/
|
||
displayEmpty: _propTypes.default.bool,
|
||
|
||
/**
|
||
* The icon that displays the arrow.
|
||
*/
|
||
IconComponent: _propTypes.default.elementType,
|
||
|
||
/**
|
||
* The `id` of the wrapper element or the `select` element when `native`.
|
||
*/
|
||
id: _propTypes.default.string,
|
||
|
||
/**
|
||
* An `Input` element; does not have to be a material-ui specific `Input`.
|
||
*/
|
||
input: _propTypes.default.element,
|
||
|
||
/**
|
||
* [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
|
||
* When `native` is `true`, the attributes are applied on the `select` element.
|
||
*/
|
||
inputProps: _propTypes.default.object,
|
||
|
||
/**
|
||
* See [OutlinedInput#label](/api/outlined-input/#props)
|
||
*/
|
||
label: _propTypes.default.node,
|
||
|
||
/**
|
||
* The ID of an element that acts as an additional label. The Select will
|
||
* be labelled by the additional label and the selected value.
|
||
*/
|
||
labelId: _propTypes.default.string,
|
||
|
||
/**
|
||
* See [OutlinedInput#label](/api/outlined-input/#props)
|
||
*/
|
||
labelWidth: _propTypes.default.number,
|
||
|
||
/**
|
||
* Props applied to the [`Menu`](/api/menu/) element.
|
||
*/
|
||
MenuProps: _propTypes.default.object,
|
||
|
||
/**
|
||
* If `true`, `value` must be an array and the menu will support multiple selections.
|
||
*/
|
||
multiple: _propTypes.default.bool,
|
||
|
||
/**
|
||
* If `true`, the component will be using a native `select` element.
|
||
*/
|
||
native: _propTypes.default.bool,
|
||
|
||
/**
|
||
* Callback function fired when a menu item is selected.
|
||
*
|
||
* @param {object} event The event source of the callback.
|
||
* You can pull out the new value by accessing `event.target.value` (any).
|
||
* @param {object} [child] The react element that was selected when `native` is `false` (default).
|
||
*/
|
||
onChange: _propTypes.default.func,
|
||
|
||
/**
|
||
* Callback fired when the component requests to be closed.
|
||
* Use in controlled mode (see open).
|
||
*
|
||
* @param {object} event The event source of the callback.
|
||
*/
|
||
onClose: _propTypes.default.func,
|
||
|
||
/**
|
||
* Callback fired when the component requests to be opened.
|
||
* Use in controlled mode (see open).
|
||
*
|
||
* @param {object} event The event source of the callback.
|
||
*/
|
||
onOpen: _propTypes.default.func,
|
||
|
||
/**
|
||
* Control `select` open state.
|
||
* You can only use it when the `native` prop is `false` (default).
|
||
*/
|
||
open: _propTypes.default.bool,
|
||
|
||
/**
|
||
* Render the selected value.
|
||
* You can only use it when the `native` prop is `false` (default).
|
||
*
|
||
* @param {any} value The `value` provided to the component.
|
||
* @returns {ReactNode}
|
||
*/
|
||
renderValue: _propTypes.default.func,
|
||
|
||
/**
|
||
* Props applied to the clickable div element.
|
||
*/
|
||
SelectDisplayProps: _propTypes.default.object,
|
||
|
||
/**
|
||
* The input value. Providing an empty string will select no options.
|
||
* This prop is required when the `native` prop is `false` (default).
|
||
* Set to an empty string `''` if you don't want any of the available options to be selected.
|
||
*
|
||
* If the value is an object it must have reference equality with the option in order to be selected.
|
||
* If the value is not an object, the string representation must match with the string representation of the option in order to be selected.
|
||
*/
|
||
value: _propTypes.default.any,
|
||
|
||
/**
|
||
* The variant to use.
|
||
*/
|
||
variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
|
||
} : void 0;
|
||
Select.muiName = 'Select';
|
||
|
||
var _default = (0, _withStyles.default)(styles, {
|
||
name: 'MuiSelect'
|
||
})(Select);
|
||
|
||
exports.default = _default; |