summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/components/SearchModifiers.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /devtools/client/shared/components/SearchModifiers.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/shared/components/SearchModifiers.js')
-rw-r--r--devtools/client/shared/components/SearchModifiers.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/devtools/client/shared/components/SearchModifiers.js b/devtools/client/shared/components/SearchModifiers.js
new file mode 100644
index 0000000000..fb66076b83
--- /dev/null
+++ b/devtools/client/shared/components/SearchModifiers.js
@@ -0,0 +1,84 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {
+ Component,
+} = require("resource://devtools/client/shared/vendor/react.js");
+const {
+ div,
+ span,
+ button,
+} = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
+const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js");
+
+loader.lazyGetter(this, "l10n", function () {
+ const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
+ return new LocalizationHelper(
+ "devtools/client/locales/components.properties"
+ );
+});
+
+const modifierOptions = [
+ {
+ value: "regexMatch",
+ className: "regex-match-btn",
+ svgName: "regex-match",
+ tooltip: l10n.getStr("searchModifier.regExpModifier"),
+ },
+ {
+ value: "caseSensitive",
+ className: "case-sensitive-btn",
+ svgName: "case-match",
+ tooltip: l10n.getStr("searchModifier.caseSensitiveModifier"),
+ },
+ {
+ value: "wholeWord",
+ className: "whole-word-btn",
+ svgName: "whole-word-match",
+ tooltip: l10n.getStr("searchModifier.wholeWordModifier"),
+ },
+];
+
+class SearchModifiers extends Component {
+ static get propTypes() {
+ return {
+ modifiers: PropTypes.object.isRequired,
+ onToggleSearchModifier: PropTypes.func.isRequired,
+ };
+ }
+
+ #renderSearchModifier({ value, className, svgName, tooltip }) {
+ const { modifiers, onToggleSearchModifier } = this.props;
+
+ return button(
+ {
+ className: `${className} ${modifiers?.[value] ? "active" : ""}`,
+ onMouseDown: () => {
+ modifiers[value] = !modifiers[value];
+ onToggleSearchModifier(modifiers);
+ },
+ onKeyDown: e => {
+ if (e.key === "Enter") {
+ modifiers[value] = !modifiers[value];
+ onToggleSearchModifier(modifiers);
+ }
+ },
+ title: tooltip,
+ },
+ span({ className: svgName })
+ );
+ }
+
+ render() {
+ return div(
+ { className: "search-modifiers" },
+ span({ className: "pipe-divider" }),
+ modifierOptions.map(options => this.#renderSearchModifier(options))
+ );
+ }
+}
+
+module.exports = SearchModifiers;