UNPKG

@mui/x-data-grid

Version:

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

101 lines 3.81 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"], _excluded2 = ["key"]; 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.js"; import { jsx as _jsx } from "react/jsx-runtime"; function GridFilterInputMultipleValue(props) { const { item, applyValue, type, apiRef, focusElementRef, color, error, helperText, size, variant = 'standard' } = 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.map(filterItemValue => type === 'number' ? Number(filterItemValue) : filterItemValue)] })); }, [applyValue, item, type]); 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) => { const _getTagProps = getTagProps({ index }), { key } = _getTagProps, tagProps = _objectWithoutPropertiesLoose(_getTagProps, _excluded2); return /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({ variant: "outlined", size: "small", label: option }, tagProps), key); }), 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 "pnpm 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(['date', 'datetime-local', 'number', 'text']) } : void 0; export { GridFilterInputMultipleValue };