UNPKG

@atlaskit/editor-plugin-find-replace

Version:

find replace plugin for @atlaskit/editor-core

116 lines (115 loc) 3.93 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */ /* eslint-disable @atlaskit/design-system/prefer-primitives */ /** * @jsxRuntime classic * @jsx jsx */ import React from 'react'; // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports import { jsx } from '@emotion/react'; import { findReplaceMessages as messages } from '@atlaskit/editor-common/messages'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import Find from './Find'; import Replace from './Replace'; import { ruleStyles, wrapperPaddingStyles, wrapperStyles } from './ui-styles'; // eslint-disable-next-line @repo/internal/react/no-class-components class FindReplace extends React.PureComponent { constructor(props) { super(props); _defineProperty(this, "findTextfield", null); _defineProperty(this, "replaceTextfield", null); _defineProperty(this, "state", { findTyped: false }); _defineProperty(this, "setFindTyped", value => { this.setState({ findTyped: value }); }); _defineProperty(this, "setFindTextfieldRef", findTextfieldRef => { this.findTextfield = findTextfieldRef.current; }); _defineProperty(this, "setReplaceTextfieldRef", replaceTextfieldRef => { this.replaceTextfield = replaceTextfieldRef.current; }); _defineProperty(this, "setFocusToFind", () => { if (this.findTextfield) { this.findTextfield.focus(); } }); _defineProperty(this, "setFocusToReplace", () => { if (this.replaceTextfield) { this.replaceTextfield.focus(); } }); this.modalRef = /*#__PURE__*/React.createRef(); } render() { const { findText, count, isReplaceable, shouldFocus, onFind, onFindBlur, onFindNext, onFindPrev, onCancel, replaceText, onReplace, onReplaceAll, dispatchAnalyticsEvent, allowMatchCase, shouldMatchCase, onToggleMatchCase, intl } = this.props; const focusToolbarButton = this.props.focusToolbarButton || (() => {}); return jsx("div", { role: 'dialog', "aria-label": intl === null || intl === void 0 ? void 0 : intl.formatMessage(messages.findReplaceDialogAriaLabel), "aria-modal": false, ref: this.modalRef // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766 , css: [wrapperStyles, wrapperPaddingStyles] }, jsx(Find, { allowMatchCase: allowMatchCase, shouldMatchCase: shouldMatchCase, onToggleMatchCase: onToggleMatchCase, findText: findText, count: count, shouldFocus: shouldFocus, onFind: onFind, onFindBlur: onFindBlur, onFindPrev: onFindPrev, onFindNext: onFindNext, onFindTextfieldRefSet: this.setFindTextfieldRef, onCancel: onCancel, onArrowDown: this.setFocusToReplace, findTyped: this.state.findTyped, setFindTyped: this.setFindTyped }), jsx("hr", { role: "presentation", css: ruleStyles, id: "replace-hr-element" }), jsx(Replace, { canReplace: expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? !!isReplaceable : count.total > 0, replaceText: replaceText, onReplace: onReplace, onReplaceAll: onReplaceAll, onReplaceTextfieldRefSet: this.setReplaceTextfieldRef, onArrowUp: this.setFocusToFind, onCancel: onCancel, count: count, onFindPrev: onFindPrev, onFindNext: onFindNext, dispatchAnalyticsEvent: dispatchAnalyticsEvent, findTyped: this.state.findTyped, setFindTyped: this.setFindTyped, focusToolbarButton: focusToolbarButton })); } } export default FindReplace;