import classNames from "classnames"; import * as React from "react"; import { DISPLAYNAME_PREFIX, HTMLInputProps, IInputGroupProps, InputGroup, IOverlayProps, Overlay, Utils, } from "reui-core"; import { Classes, IListItemsProps } from "../../common"; import { IQueryListRendererProps, QueryList } from "../query-list/queryList"; export interface IOmnibarProps extends IListItemsProps { /** * Props to spread to the query `InputGroup`. Use `query` and * `onQueryChange` instead of `inputProps.value` and `inputProps.onChange` * to control this input. Use `inputRef` instead of `ref`. */ inputProps?: IInputGroupProps & HTMLInputProps; /** * Toggles the visibility of the omnibar. * This prop is required because the component is controlled. */ isOpen: boolean; /** * A callback that is invoked when user interaction causes the omnibar to * close, such as clicking on the overlay or pressing the `esc` key (if * enabled). Receives the event from the user's interaction, if there was an * event (generally either a mouse or key event). * * Note that due to controlled usage, this component will not actually close * itself until the `isOpen` prop becomes `false`. * . */ onClose?: (event?: React.SyntheticEvent) => void; /** Props to spread to `Overlay`. */ overlayProps?: Partial; } export class Omnibar extends React.PureComponent> { public static displayName = `${DISPLAYNAME_PREFIX}.Omnibar`; public static ofType() { return Omnibar as new (props: IOmnibarProps) => Omnibar; } private TypedQueryList = QueryList.ofType(); private queryList?: QueryList | null; private refHandlers = { queryList: (ref: QueryList | null) => (this.queryList = ref), }; public render() { // omit props specific to this component, spread the rest. const { initialContent = null, isOpen, inputProps, overlayProps, ...restProps } = this.props; return ( ); } private renderQueryList = (listProps: IQueryListRendererProps) => { const { inputProps = {}, isOpen, overlayProps = {} } = this.props; const { handleKeyDown, handleKeyUp } = listProps; const handlers = isOpen && listProps.query.length > 0 ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; return (
{listProps.itemList}
); }; private handleOverlayClose = (event?: React.SyntheticEvent) => { const { overlayProps = {} } = this.props; Utils.safeInvoke(overlayProps.onClose, event); Utils.safeInvoke(this.props.onClose, event); }; }