import React, { Component } from 'react'; import PropTypes from 'prop-types'; import AceEditor from 'react-ace'; import classnames from 'classnames'; import 'brace/mode/sql'; import 'brace/ext/linking'; import 'brace/ext/language_tools'; import './mode'; import './theme'; const baseClass = 'kolide-ace'; class KolideAce extends Component { static propTypes = { error: PropTypes.string, fontSize: PropTypes.number, handleSubmit: PropTypes.func.isRequired, label: PropTypes.string, name: PropTypes.string, onChange: PropTypes.func.isRequired, onLoad: PropTypes.func.isRequired, value: PropTypes.string, readOnly: PropTypes.bool, showGutter: PropTypes.bool, wrapEnabled: PropTypes.bool, wrapperClassName: PropTypes.string, hint: PropTypes.string, }; static defaultProps = { fontSize: 14, name: 'query-editor', showGutter: true, wrapEnabled: false, }; renderLabel = () => { const { error, label } = this.props; const labelClassName = classnames(`${baseClass}__label`, { [`${baseClass}__label--error`]: error, }); return (

{error || label}

); } renderHint = () => { const { hint } = this.props; if (hint) { return {hint}; } return false; } render () { const { error, fontSize, handleSubmit, name, onChange, onLoad, readOnly, showGutter, value, wrapEnabled, wrapperClassName, } = this.props; const { renderLabel, renderHint } = this; const wrapperClass = classnames(wrapperClassName, { [`${baseClass}__wrapper--error`]: error, }); return (
{renderLabel()} {renderHint()}
); } } export default KolideAce;