@blueprintjs/select
Version:
Components related to selecting items from a list
59 lines • 3.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Omnibar = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
/*
* Copyright 2017 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const react_1 = require("react");
const core_1 = require("@blueprintjs/core");
const icons_1 = require("@blueprintjs/icons");
const common_1 = require("../../common");
const queryList_1 = require("../query-list/queryList");
/**
* Omnibar component.
*
* @see https://blueprintjs.com/docs/#select/omnibar
*/
class Omnibar extends react_1.PureComponent {
static displayName = `${core_1.DISPLAYNAME_PREFIX}.Omnibar`;
static ofType() {
return Omnibar;
}
render() {
// omit props specific to this component, spread the rest.
const { isOpen, inputProps, overlayProps, ...restProps } = this.props;
const initialContent = "initialContent" in this.props ? this.props.initialContent : null;
return ((0, jsx_runtime_1.jsx)(queryList_1.QueryList, { ...restProps,
// Omnibar typically does not keep track of and/or show its selection state like other
// select components, so it's more of a menu than a listbox. This means that users should return
// MenuItems with roleStructure="menuitem" (the default value) in `props.itemRenderer`.
menuProps: { role: "menu" }, initialContent: initialContent, renderer: this.renderQueryList }));
}
renderQueryList = (listProps) => {
const { inputProps = {}, isOpen, overlayProps = {} } = this.props;
const { handleKeyDown, handleKeyUp } = listProps;
const handlers = isOpen ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {};
return ((0, jsx_runtime_1.jsx)(core_1.Overlay2, { hasBackdrop: true, ...overlayProps, isOpen: isOpen, className: (0, classnames_1.default)(common_1.Classes.OMNIBAR_OVERLAY, overlayProps.className), onClose: this.handleOverlayClose, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(common_1.Classes.OMNIBAR, listProps.className), ...handlers, children: [(0, jsx_runtime_1.jsx)(core_1.InputGroup, { autoFocus: true, leftIcon: (0, jsx_runtime_1.jsx)(icons_1.Search, {}), placeholder: "Search...", size: "large", ...inputProps, onChange: listProps.handleQueryChange, value: listProps.query }), listProps.itemList] }) }));
};
handleOverlayClose = (event) => {
this.props.overlayProps?.onClose?.(event);
this.props.onClose?.(event);
};
}
exports.Omnibar = Omnibar;
//# sourceMappingURL=omnibar.js.map