UNPKG

flipper-plugin

Version:

Flipper Desktop plugin SDK and components

44 lines 1.94 kB
"use strict"; /** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PowerSearchIntegerTerm = void 0; const antd_1 = require("antd"); const react_1 = __importDefault(require("react")); const PowerSearchIntegerTerm = ({ onCancel, onChange, defaultValue, }) => { const [editing, setEditing] = react_1.default.useState(!defaultValue); if (editing) { return (react_1.default.createElement(antd_1.Input, { autoFocus: true, style: { width: 100 }, placeholder: "...", onChange: (event) => { const newValue = event.target.value; const normalizedValue = parseInt(newValue, 10); if (normalizedValue.toString() !== newValue) { event.target.value = normalizedValue.toString(); } }, onBlur: (event) => { const newValue = event.target.value; setEditing(false); if (!newValue) { onCancel(); return; } const normalizedValue = parseInt(newValue, 10); onChange(normalizedValue); }, onKeyDown: (event) => { if (event.key === 'Enter' || event.key === 'Escape') { event.currentTarget.blur(); } }, type: "number", step: 1, defaultValue: defaultValue })); } return react_1.default.createElement(antd_1.Button, { onClick: () => setEditing(true) }, defaultValue); }; exports.PowerSearchIntegerTerm = PowerSearchIntegerTerm; //# sourceMappingURL=PowerSearchIntegerTerm.js.map