UNPKG

@6thquake/react-material

Version:

React components that implement Google's Material Design.

186 lines (166 loc) 5.37 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; // @inheritedComponent Input /** * @ignore - internal component. */ import React from 'react'; import PropTypes from 'prop-types'; import SelectInput from './SelectInput'; import { withStyles, mergeClasses } from '../styles'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import Input from '../Input'; function AsyncSelectRoot(props) { const { autoWidth, children, classes, displayEmpty, IconComponent, input, inputProps, MenuProps, multiple, onClose, onOpen, open, comparison, readOnly, renderValue, SelectDisplayProps } = props, other = _objectWithoutPropertiesLoose(props, ["autoWidth", "children", "classes", "displayEmpty", "IconComponent", "input", "inputProps", "MenuProps", "multiple", "onClose", "onOpen", "open", "comparison", "readOnly", "renderValue", "SelectDisplayProps"]); const inputComponent = SelectInput; return React.cloneElement(input, _extends({ // Most of the logic is implemented in `SelectInput`. // The `Select` component is a simple API wrapper to expose something better to play with. inputComponent, inputProps: _extends({ children, IconComponent, type: undefined }, { autoWidth, displayEmpty, MenuProps, multiple, onClose, onOpen, open, comparison, readOnly, renderValue, SelectDisplayProps }, inputProps, { classes: inputProps ? mergeClasses({ baseClasses: classes, newClasses: inputProps.classes, Component: AsyncSelectRoot }) : classes }, input ? input.props.inputProps : {}) }, other)); } process.env.NODE_ENV !== "production" ? AsyncSelectRoot.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.bool, /** * The option elements to populate the select with. * Can be some `MenuItem` when `native` is false and `option` when `native` is true. */ children: PropTypes.node, /** * Override or extend the styles applied to the component. * See [CSS API](#css-api) below for more details. */ classes: PropTypes.object.isRequired, /** * If `true`, the selected item is displayed even if its value is empty. * You can only use it when the `native` property is `false` (default). */ displayEmpty: PropTypes.bool, /** * The icon that displays the arrow. */ IconComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]), /** * An `Input` element; does not have to be a material-ui specific `Input`. */ input: PropTypes.element, /** * Attributes applied to the `input` element. * When `native` is `true`, the attributes are applied on the `select` element. */ inputProps: PropTypes.object, /** * Properties applied to the `Menu` element. */ MenuProps: PropTypes.object, /** * If true, `value` must be an array and the menu will support multiple selections. * You can only use it when the `native` property is `false` (default). */ multiple: PropTypes.bool, /** * If `true`, the component will be using a native `select` element. */ native: PropTypes.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`. * @param {object} [child] The react element that was selected when `native` is `false` (default). */ onChange: PropTypes.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.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.func, /** * Control `select` open state. * You can only use it when the `native` property is `false` (default). */ open: PropTypes.bool, /** * Render the selected value. * You can only use it when the `native` property is `false` (default). * * @param {*} value The `value` provided to the component. * @returns {ReactElement} */ renderValue: PropTypes.func, /** * Properties applied to the clickable div element. */ SelectDisplayProps: PropTypes.object, /** * The input value. * This property is required when the `native` property is `false` (default). */ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number]))]) } : void 0; AsyncSelectRoot.defaultProps = { autoWidth: false, displayEmpty: false, IconComponent: ArrowDropDownIcon, input: React.createElement(Input, null), multiple: false, native: false }; AsyncSelectRoot.muiName = 'AsyncSelectRoot'; export default withStyles({ name: 'MuiAsyncSelectRoot' })(AsyncSelectRoot);