/* * 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. */ import classNames from 'classnames'; import * as React from 'react'; import { Classes, DISPLAYNAME_PREFIX, Popover, Position, Utils, InputGroup, Button, refHandler, } from '@blueprintjs/core'; import { QueryList } from '@blueprintjs/select'; // export interface IMultiSelectProps extends IListItemsProps { // /** // * Whether the component should take up the full width of its container. // * This overrides `popoverProps.fill` and `tagInputProps.fill`. // */ // fill?: boolean; // /** // * Whether the popover opens on key down or when `TagInput` is focused. // * @default false // */ // openOnKeyDown?: boolean; // /** // * Input placeholder text. Shorthand for `tagInputProps.placeholder`. // * @default "Search..." // */ // placeholder?: string; // /** Props to spread to `Popover`. Note that `content` cannot be changed. */ // popoverProps?: Partial & object; // /** Controlled selected values. */ // selectedItems?: T[]; // /** Props to spread to `TagInput`. Use `query` and `onQueryChange` to control the input. */ // tagInputProps?: Partial & object; // /** Custom renderer to transform an item into tag content. */ // tagRenderer: (item: T) => React.ReactNode; // } // export interface IMultiSelectState { // isOpen: boolean; // } export default class MultiSelect extends React.Component { inputElement = null; handleInputRef = refHandler( this, 'inputElement', this.props.inputProps?.inputRef, ); static get displayName() { return `${DISPLAYNAME_PREFIX}.MultiSelect`; } static get defaultProps() { return { fill: false, placeholder: 'Search...', }; } constructor(props) { super(props); this.state = { isOpen: (this.props.popoverProps && this.props.popoverProps.isOpen) || false, }; this.input = null; this.queryList = null; this.listRef = React.createRef(); this.refHandlers = { queryList: (ref) => { this.queryList = ref; }, }; } render() { // omit props specific to this component, spread the rest. const { openOnKeyDown, popoverProps, ...restProps } = this.props; return ( ); } maybeRenderClearButton(query) { return query.length > 0 ? (