import { Search } from '@megafon/ui-core';
Код DemoSearchWrapperconst DemoSearchWrapper: React.FC<IDemoSearchWrapperProps> = ({ children }) => {const [value, setValue] = React.useState('');const [items, setItems] = React.useState([]);const handleChange = React.useCallback((query: string) => {if (!query) {return;}setItems((oldItems) => [...oldItems, query]);}, [items, setItems]);return (<div><p style={{ marginTop: 0, marginBottom: '15px' }}>Value: {value}</p>{children({ onChange: handleChange, onSubmit: setValue, items: items, chosenValue: value })}</div>);};
<Search label="Заголовок поля" searchId="2" />
<Search label="Заголовок поля" textarea />
<Search label="Заголовок поля" textarea showResizer />
иконка поиска расположена слева, добавлена возможность очистить поле по клику на крестик
<Search value="очистить поле по клику на крестик" placeholder="Введите что-нибудь" type="compact" />
<Search hideIcon searchId="1" />
<Search hideIcon textarea />
<Search label="Заголовок поля" searchId="2" />
<Search label="Заголовок поля" textarea />
<Search searchId="3" placeholder="Введите что-нибудь" />
<Search placeholder="Введите что-нибудь" textarea />
<Search label="Заголовок поля" placeholder="Введите что-нибудь" searchId="4" />
<Search label="Заголовок поля" placeholder="Введите что-нибудь" textarea />
<Search placeholder="This field is disabled" searchId="5" disabled />
<Search placeholder="This field is disabled" textarea disabled />
<Search placeholder="Type here for search" value="Previous request" searchId="6" />
<Search placeholder="Type here for search" value="Previous request" textarea />
<DemoSearchWrapper> {({ onSubmit }) => ( <Search placeholder="Type here for search" onSubmit={onSubmit} label="Обработчик onSubmit" searchId="7" /> )} </DemoSearchWrapper> <DemoSearchWrapper> {({ onSubmit }) => ( <Search placeholder="Type here for search" onChange={onSubmit} changeDelay={50} label="Обработчик onChange" searchId="8" /> )} </DemoSearchWrapper>
<DemoSearchWrapper> {({ onSubmit, chosenValue, items, onChange }) => ( <Search value={chosenValue} items={items} placeholder="Type and wait for results" searchId="7" onChange={onChange} onSubmit={onSubmit} /> )} </DemoSearchWrapper>
<Search label="Заголовок поля" searchId="8" required />
<Search noticeText="Текст под полем" searchId="9" />
<Search noticeText="Текст под полем" textarea />
<Search noticeText="Успешная валидация" verification="valid" searchId="10" /> <Search noticeText="Ошибка валидации" verification="error" searchId="11" /> <Search noticeText="Успешная валидация" verification="valid" textarea /> <Search noticeText="Ошибка валидации" verification="error" textarea />
Код DemoSearchCustomItemsWrapperconst DemoSearchCustomItemsWrapper: React.FC<IDemoSearchCustomItemsWrapper> = ({ children }) => {const [value, setValue] = React.useState<string>('');const getContent = React.useCallback((index: number) => (<div><div><b>ИП Баранник Александр Николаевич {index + 1}</b></div><div><b>ИНН: 503209463031</b></div><div>Московская обл, Одинцовский р-н, г Одинцово</div></div>), []);const items = React.useMemo(() => (new Array(5).fill('').map((_, i) => ({value: `ИП Баранник Александр Николаевич ${i + 1}`,searchView: getContent(i),}))), []);return <div>{children({ value, onSubmit: setValue, items })}</div>;};
<DemoSearchCustomItemsWrapper> {({ value, onSubmit, items }) => ( <Search value={value} onSubmit={onSubmit} items={items} placeholder="Type and wait for results" searchId="12" /> )} </DemoSearchCustomItemsWrapper>
<Search label="Заголовок поля" searchId="2" showLoader /> <Search label="Заголовок поля" textarea showLoader /> <Search label="Заголовок поля" type="compact" showLoader />
<DemoSearchItemsNotFoundWrapper> {({ value, searchItems, initialItems, isNotFound, onChange, onSubmit }) => ( <Search value={value} items={searchItems} label="Поиск" placeholder="Type and wait for results" showNotFound={isNotFound} onChange={onChange} onSubmit={onSubmit} /> )} </DemoSearchItemsNotFoundWrapper> <DemoSearchItemsNotFoundWrapper> {({ value, searchItems, initialItems, isNotFound, onChange, onSubmit }) => ( <Search value={value} items={searchItems} label="Поиск" placeholder="Type and wait for results" textNotFound="Not found" type="compact" showNotFound={isNotFound} onChange={onChange} onSubmit={onSubmit} /> )} </DemoSearchItemsNotFoundWrapper>
<DemoSearchItemsNotFoundWrapper> {({ value, searchItems, initialItems, isNotFound, popularItems, onChange, onSubmit, onPopularItemClick }) => ( <Search value={value} items={searchItems} label="Поиск" placeholder="Type and wait for results" showNotFound={isNotFound} popularItems={popularItems} onChange={onChange} onSubmit={onSubmit} onPopularItemClick={onPopularItemClick} /> )} </DemoSearchItemsNotFoundWrapper>