import React, { Children, Component } from 'react'; import DatalistItem from '../datalist-item'; import SelectorDropdown from './SelectorDropdown'; import TextInput, { TextInputProps } from '../text-input'; interface InputContainerProps extends Omit { inputProps?: Partial; onInput: (event: React.ChangeEvent) => void; } const InputContainer: React.FC = ({ inputProps = {}, ...rest }) => ( ); interface SelectorDropdownContainerProps { initialItems: string[]; placeholder: string; title: string; } interface SelectorDropdownContainerState { filterText: string; items: string[]; showTitle: boolean; remainOpen: boolean; } class SelectorDropdownContainer extends Component { constructor(props: SelectorDropdownContainerProps) { super(props); this.state = { filterText: '', items: props.initialItems, showTitle: false, remainOpen: false, }; } handleShowTitle = () => { this.setState({ showTitle: !this.state.showTitle }); }; handleRemainOpen = () => { this.setState({ remainOpen: !this.state.remainOpen }); }; handleUserInput = (event: React.ChangeEvent) => { this.filterByItem(event.target.value); }; handleItemSelection = (i: number) => { this.setState({ filterText: this.state.items[i] }); }; filterByItem(item: string) { this.setState({ filterText: item }); this.filterItems(item); } filterItems(filterText: string) { const { initialItems } = this.props; const filterTextLowerCase = filterText.toLowerCase(); const items = initialItems.filter(item => item.toLowerCase().includes(filterTextLowerCase)); this.setState({ items }); } render() { const { placeholder, title } = this.props; const { filterText, items, showTitle, remainOpen } = this.state; const dropdownTitle =
This is a Title
; return (


} title={showTitle ? dropdownTitle : undefined} > {Children.map(items, item => ( {item} ))}
); } } const SelectorDropdownExample: React.FC = () => ( ); export default SelectorDropdownExample;