import React, { useState } from 'react' import { Container } from '@toptal/picasso' import { SPACING_4, isSubstring } from '@toptal/picasso-utils' import type { AutocompleteItem as Item } from '@toptal/picasso' import { FormNonCompound, Input, NumberInput, RadioGroup, Radio, DatePicker, TimePicker, TagSelector, CheckboxGroup, Checkbox, Select, Autocomplete, Rating, FileInput, Switch, SubmitButton, } from '@toptal/picasso-forms' const countries = [ { value: 'Afghanistan', text: 'Afghanistan' }, { value: 'Albania', text: 'Albania' }, { value: 'Algeria', text: 'Algeria' }, { value: 'Belarus', text: 'Belarus' }, { value: 'Croatia', text: 'Croatia' }, { value: 'Lithuania', text: 'Lithuania' }, { value: 'Slovakia', text: 'Slovakia' }, { value: 'Spain', text: 'Spain' }, { value: 'Ukraine', text: 'Ukraine' }, ] const skills = [ { value: 0, text: 'HTML' }, { value: 1, text: 'CSS' }, { value: 2, text: 'Javascript' }, ] const EMPTY_INPUT_VALUE = '' const getAutocompleteDisplayValue = (item: Item | null) => item?.text || EMPTY_INPUT_VALUE const filterOptions = (str = '', options: Item[] = []): Item[] | null => { if (!str) { return options } const result = options.filter(option => option?.text ? isSubstring(str, option.text) : false ) return result.length > 0 ? result : null } const Example = () => { const [skillInputValue, setSkillInputValue] = useState(EMPTY_INPUT_VALUE) const skillOptions = filterOptions(skillInputValue, skills) const [autocompleteValue, setAutocompleteValue] = useState(EMPTY_INPUT_VALUE) const [autocompleteOptions, setAutocompleteOptions] = useState( countries ) return ( window.alert(JSON.stringify(values, undefined, 2))} initialValues={{ 'titleCase-gender': 'female' }} > void) => { set('') }} required name='titleCase-firstName' label='First name' placeholder='e.g. Bruce' />