UNPKG

@mui/x-data-grid

Version:

The Community plan edition of the Data Grid components (MUI X).

93 lines 3.45 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant"]; import * as React from 'react'; import PropTypes from 'prop-types'; import Autocomplete from '@mui/material/Autocomplete'; import { unstable_useId as useId } from '@mui/utils'; import { useGridRootProps } from '../../../hooks/utils/useGridRootProps'; import { jsx as _jsx } from "react/jsx-runtime"; function GridFilterInputMultipleValue(props) { const { item, applyValue, type, apiRef, focusElementRef, color, error, helperText, size, variant } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const TextFieldProps = { color, error, helperText, size, variant }; const [filterValueState, setFilterValueState] = React.useState(item.value || []); const id = useId(); const rootProps = useGridRootProps(); React.useEffect(() => { const itemValue = item.value ?? []; setFilterValueState(itemValue.map(String)); }, [item.value]); const handleChange = React.useCallback((event, value) => { setFilterValueState(value.map(String)); applyValue(_extends({}, item, { value: [...value] })); }, [applyValue, item]); return /*#__PURE__*/_jsx(Autocomplete, _extends({ multiple: true, freeSolo: true, options: [], filterOptions: (options, params) => { const { inputValue } = params; return inputValue == null || inputValue === '' ? [] : [inputValue]; }, id: id, value: filterValueState, onChange: handleChange, renderTags: (value, getTagProps) => value.map((option, index) => /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({ variant: "outlined", size: "small", label: option }, getTagProps({ index })))), renderInput: params => /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({}, params, { label: apiRef.current.getLocaleText('filterPanelInputLabel'), placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'), InputLabelProps: _extends({}, params.InputLabelProps, { shrink: true }), inputRef: focusElementRef, type: type || 'text' }, TextFieldProps, rootProps.slotProps?.baseTextField)) }, other)); } process.env.NODE_ENV !== "production" ? GridFilterInputMultipleValue.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- apiRef: PropTypes.shape({ current: PropTypes.object.isRequired }).isRequired, applyValue: PropTypes.func.isRequired, focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]), item: PropTypes.shape({ field: PropTypes.string.isRequired, id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), operator: PropTypes.string.isRequired, value: PropTypes.any }).isRequired, type: PropTypes.oneOf(['number', 'text']) } : void 0; export { GridFilterInputMultipleValue };