UNPKG

flipper-plugin

Version:

Flipper Desktop plugin SDK and components

46 lines 1.9 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.PowerSearchEnumSetTerm = void 0; const antd_1 = require("antd"); const react_1 = __importDefault(require("react")); const PowerSearchEnumSetTerm = ({ onCancel, onChange, enumLabels, defaultValue, allowFreeform, }) => { const options = react_1.default.useMemo(() => { return Object.entries(enumLabels).map(([key, label]) => ({ label, value: key, })); }, [enumLabels]); const selectValueRef = react_1.default.useRef(); if (defaultValue && !selectValueRef.current) { selectValueRef.current = defaultValue; } return (react_1.default.createElement(antd_1.Select, { mode: allowFreeform ? 'tags' : 'multiple', autoFocus: !defaultValue, style: { minWidth: 100 }, placeholder: "...", options: options, defaultOpen: !defaultValue, defaultValue: defaultValue, dropdownMatchSelectWidth: false, onBlur: () => { if (!selectValueRef.current?.length) { onCancel(); } }, onChange: (value) => { if (!value.length) { onCancel(); return; } selectValueRef.current = value; onChange(value); }, onClear: onCancel, onKeyDown: (event) => { if (event.key === 'Enter' || event.key === 'Escape') { event.currentTarget.blur(); } } })); }; exports.PowerSearchEnumSetTerm = PowerSearchEnumSetTerm; //# sourceMappingURL=PowerSearchEnumSetTerm.js.map