/* eslint-disable react/no-danger */ /* eslint-disable react/no-multi-comp */ /* @flow */ import React, { useState } from 'react' import { components, OptionProps } from 'react-select' import { Avatar, Body, Flex, FlexItem, Title, Typeahead, } from '../..' const USERS = [ { name: "Wade Winningham", title: "Nitro Principal Developer", territory: "PHL", }, { name: "Jason Cypret", title: "Vice President of User Experience", territory: "PHL", }, { name: "Stephen Marshall", title: "Senior User Experience Engineer", territory: "PHL", }, { name: "Jasper Furniss", title: "Senior User Experience Engineer", territory: "PHL", }, ]; const TypeaheadWithHighlight = (props) => { const [selectedUser, setSelectedUser] = useState() const formatOptionLabel = ({name, territory, title}, {inputValue}) => { const highlighted = (text: string) => { if (!inputValue.length) return text return text.replace( new RegExp(inputValue, 'gi'), highlighted => `${highlighted}` ) } return ( <span dangerouslySetInnerHTML={{ __html: highlighted(name) }} /> {" • "} {territory} ) } const customComponents = { Option: (props: OptionProps) => ( ), SingleValue: ({ data }: any) => ( {data.name} ) } return ( option.name} getOptionValue={({name, title}) => `${name} ${title}`} label="Users" onChange={(user) => setSelectedUser(user)} options={USERS.filter((option) => option.name != selectedUser?.name)} placeholder="type the name of a user" {...props} /> ) } export default TypeaheadWithHighlight