UNPKG

@mui/x-data-grid

Version:

The community edition of the data grid component (MUI X).

61 lines (59 loc) 2.57 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["item", "applyValue", "apiRef", "focusElementRef"]; import * as React from 'react'; import MenuItem from '@mui/material/MenuItem'; import { useGridRootProps } from '../../../hooks/utils/useGridRootProps'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; export function GridFilterInputBoolean(props) { var _rootProps$components, _baseSelectProps$nati, _rootProps$components2, _rootProps$components3; const { item, applyValue, apiRef, focusElementRef } = props, others = _objectWithoutPropertiesLoose(props, _excluded); const [filterValueState, setFilterValueState] = React.useState(item.value || ''); const rootProps = useGridRootProps(); const baseSelectProps = ((_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.baseSelect) || {}; const isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true; const OptionComponent = isSelectNative ? 'option' : MenuItem; const onFilterChange = React.useCallback(event => { const value = event.target.value; setFilterValueState(value); applyValue(_extends({}, item, { value })); }, [applyValue, item]); React.useEffect(() => { setFilterValueState(item.value || ''); }, [item.value]); return /*#__PURE__*/_jsxs(rootProps.components.BaseTextField, _extends({ label: apiRef.current.getLocaleText('filterPanelInputLabel'), value: filterValueState, onChange: onFilterChange, select: true, variant: "standard", SelectProps: _extends({ native: isSelectNative, displayEmpty: true }, (_rootProps$components2 = rootProps.componentsProps) == null ? void 0 : _rootProps$components2.baseSelect), InputLabelProps: { shrink: true }, inputRef: focusElementRef }, others, (_rootProps$components3 = rootProps.componentsProps) == null ? void 0 : _rootProps$components3.baseTextField, { children: [/*#__PURE__*/_jsx(OptionComponent, { value: "", children: apiRef.current.getLocaleText('filterValueAny') }), /*#__PURE__*/_jsx(OptionComponent, { value: "true", children: apiRef.current.getLocaleText('filterValueTrue') }), /*#__PURE__*/_jsx(OptionComponent, { value: "false", children: apiRef.current.getLocaleText('filterValueFalse') })] })); }