UNPKG

@mui/x-data-grid

Version:

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

98 lines 3.59 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import PropTypes from 'prop-types'; import { unstable_useId as useId } from '@mui/utils'; import { useGridRootProps } from "../../../hooks/utils/useGridRootProps.js"; import { jsx as _jsx } from "react/jsx-runtime"; function GridFilterInputMultipleValue(props) { const { item, applyValue, type, apiRef, focusElementRef, slotProps } = props; const id = useId(); const [options, setOptions] = React.useState([]); const [filterValueState, setFilterValueState] = React.useState(item.value || []); 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.map(filterItemValue => type === 'number' ? Number(filterItemValue) : filterItemValue)] })); }, [applyValue, item, type]); const handleInputChange = React.useCallback((event, value) => { if (value === '') { setOptions([]); } else { setOptions([value]); } }, [setOptions]); const BaseAutocomplete = rootProps.slots.baseAutocomplete; return /*#__PURE__*/_jsx(BaseAutocomplete, _extends({ multiple: true, freeSolo: true, options: options, id: id, value: filterValueState, onChange: handleChange, onInputChange: handleInputChange, label: apiRef.current.getLocaleText('filterPanelInputLabel'), placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'), slotProps: { textField: { type: type || 'text', inputRef: focusElementRef } } }, slotProps?.root)); } 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 "pnpm proptypes" | // ---------------------------------------------------------------------- apiRef: PropTypes.shape({ current: PropTypes.object.isRequired }).isRequired, applyValue: PropTypes.func.isRequired, className: PropTypes.string, clearButton: PropTypes.node, disabled: PropTypes.bool, focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]), headerFilterMenu: PropTypes.node, inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: (props, propName) => { if (props[propName] == null) { return null; } if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { return new Error(`Expected prop '${propName}' to be of type Element`); } return null; } })]), /** * It is `true` if the filter either has a value or an operator with no value * required is selected (for example `isEmpty`) */ isFilterActive: PropTypes.bool, item: PropTypes.shape({ field: PropTypes.string.isRequired, id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), operator: PropTypes.string.isRequired, value: PropTypes.any }).isRequired, onBlur: PropTypes.func, onFocus: PropTypes.func, slotProps: PropTypes.object, tabIndex: PropTypes.number, type: PropTypes.oneOf(['date', 'datetime-local', 'number', 'text']) } : void 0; export { GridFilterInputMultipleValue };