UNPKG

@mui/x-data-grid-premium

Version:

The Premium plan edition of the MUI X Data Grid Components.

84 lines (83 loc) 4.26 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.GridPromptField = GridPromptField; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var _PromptField = require("./PromptField"); var _PromptFieldControl = require("./PromptFieldControl"); var _PromptFieldRecord = require("./PromptFieldRecord"); var _PromptFieldSend = require("./PromptFieldSend"); var _useGridRootProps = require("../../hooks/utils/useGridRootProps"); var _useGridApiContext = require("../../hooks/utils/useGridApiContext"); var _speechRecognition = require("../../utils/speechRecognition"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["ref"]; function GridPromptField(props) { const rootProps = (0, _useGridRootProps.useGridRootProps)(); const apiRef = (0, _useGridApiContext.useGridApiContext)(); let placeholder = apiRef.current.getLocaleText('promptFieldPlaceholder'); if (_speechRecognition.IS_SPEECH_RECOGNITION_SUPPORTED) { placeholder = apiRef.current.getLocaleText('promptFieldPlaceholderWithRecording'); } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PromptField.PromptField, (0, _extends2.default)({}, props, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PromptFieldControl.PromptFieldControl, { onKeyDown: event => { if (event.key === 'Enter') { // Prevents the `multiline` TextField from adding a new line event.preventDefault(); } }, render: (_ref, state) => { let { ref } = _ref, controlProps = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded); return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTextField, (0, _extends2.default)({}, controlProps, { fullWidth: true, inputRef: ref, "aria-label": apiRef.current.getLocaleText('promptFieldLabel'), placeholder: state.recording ? apiRef.current.getLocaleText('promptFieldPlaceholderListening') : placeholder, size: "small", multiline: true, autoFocus: true, slotProps: (0, _extends2.default)({ input: (0, _extends2.default)({ startAdornment: _speechRecognition.IS_SPEECH_RECOGNITION_SUPPORTED ? /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, { title: state.recording ? apiRef.current.getLocaleText('promptFieldStopRecording') : apiRef.current.getLocaleText('promptFieldRecord'), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PromptFieldRecord.PromptFieldRecord, { size: "small", edge: "start", color: state.recording ? 'primary' : 'default', children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.promptSpeechRecognitionIcon, { fontSize: "small" }) }) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, { title: apiRef.current.getLocaleText('promptFieldSpeechRecognitionNotSupported'), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.promptSpeechRecognitionOffIcon, { fontSize: "small" }) }), endAdornment: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, { title: apiRef.current.getLocaleText('promptFieldSend'), children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PromptFieldSend.PromptFieldSend, { size: "small", edge: "end", color: "primary", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.promptSendIcon, { fontSize: "small" }) }) }) }) }, controlProps.slotProps?.input) }, controlProps.slotProps) })); } }) })); }