import React, { useCallback } from "react"; import AceEditor from "react-ace"; import classnames from "classnames"; import "ace-builds/src-noconflict/mode-sql"; import "ace-builds/src-noconflict/ext-linking"; import "ace-builds/src-noconflict/ext-language_tools"; import { noop } from "lodash"; import { IAceEditor } from "react-ace/lib/types"; import "./mode"; import "./theme"; interface IFleetAceProps { error?: string; fontSize?: number; label?: string; name?: string; value?: string; readOnly?: boolean; showGutter?: boolean; wrapEnabled?: boolean; wrapperClassName?: string; hint?: string; labelActionComponent?: React.ReactNode; onLoad?: (editor: IAceEditor) => void; onChange?: () => void; handleSubmit?: () => void; } const baseClass = "fleet-ace"; const FleetAce = ({ error, fontSize = 14, label, labelActionComponent, name = "query-editor", value, readOnly, showGutter = true, wrapEnabled = false, wrapperClassName, hint, onLoad, onChange, handleSubmit = noop, }: IFleetAceProps) => { const renderLabel = useCallback(() => { const labelText = error || label; const labelClassName = classnames(`${baseClass}__label`, { [`${baseClass}__label--error`]: !!error, [`${baseClass}__label--with-action`]: !!labelActionComponent, }); return (

{labelText}

{labelActionComponent}
); }, [error, label, labelActionComponent]); const renderHint = () => { if (hint) { return {hint}; } return false; }; const wrapperClass = classnames(wrapperClassName, { [`${baseClass}__wrapper--error`]: !!error, }); const fixHotkeys = (editor: IAceEditor) => { editor.commands.removeCommand("gotoline"); editor.commands.removeCommand("find"); onLoad && onLoad(editor); }; return (
{renderLabel()} {renderHint()}
); }; export default FleetAce;