|
1 | 1 | import { ArrowUpIcon, BellIcon, CheckCircleIcon, CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid';
|
2 | 2 | import { ChatBubbleOvalLeftEllipsisIcon, ExclamationTriangleIcon } from '@heroicons/react/24/outline';
|
3 | 3 | import { useMemo, useState } from 'react';
|
4 |
| -import { Button, Cell, Collection, Column, ComboBox, DateInput, DatePicker, DateSegment, Dialog, DialogTrigger, Group, Header, Heading, Input, Label, ListBox, ListBoxItem, Menu, MenuItem, MenuTrigger, Modal, ModalOverlay, OverlayArrow, Popover, ProgressBar, Radio, RadioGroup, Row, Section, Select, SelectValue, Separator, Slider, SliderOutput, SliderThumb, SliderTrack, Switch, Tab, Table, TableBody, TableHeader, TabList, TabPanel, Tabs, Text } from 'react-aria-components'; |
| 4 | +import { UNSTABLE_Autocomplete as Autocomplete, Button, Cell, Collection, Column, ComboBox, DateInput, DatePicker, DateSegment, Dialog, DialogTrigger, Group, Header, Heading, Input, Label, ListBox, ListBoxItem, Menu, MenuItem, MenuTrigger, Modal, ModalOverlay, OverlayArrow, Popover, ProgressBar, Radio, RadioGroup, Row, SearchField, Section, Select, SelectValue, Separator, Slider, SliderOutput, SliderThumb, SliderTrack, Switch, Tab, Table, TableBody, TableHeader, TabList, TabPanel, Tabs, Text, useFilter} from 'react-aria-components'; |
5 | 5 | import { useAsyncList } from 'react-stately';
|
6 | 6 | import { people } from './people.js';
|
7 | 7 | import stocks from './stocks.json';
|
@@ -29,6 +29,7 @@ export function App() {
|
29 | 29 | <ImageGridExample />
|
30 | 30 | <ComboBoxExample />
|
31 | 31 | <ProgressBarExample />
|
| 32 | + <AutocompleteExample /> |
32 | 33 | </div>
|
33 | 34 | </>
|
34 | 35 | );
|
@@ -549,3 +550,31 @@ function StockRow(props) {
|
549 | 550 | function StockCell(props) {
|
550 | 551 | return <Cell {...props} className={`px-4 py-2 text-sm ${props.className} data-[focus-visible]:outline data-[focus-visible]:outline-2 data-[focus-visible]:outline-slate-600 data-[focus-visible]:-outline-offset-4 group-aria-selected:data-[focus-visible]:outline-white`} />;
|
551 | 552 | }
|
| 553 | + |
| 554 | +function AutocompleteExample() { |
| 555 | + let {contains} = useFilter({sensitivity: 'base'}); |
| 556 | + return ( |
| 557 | + <div className="bg-gradient-to-r from-sky-400 to-cyan-400 p-8 rounded-lg flex justify-center flex-col"> |
| 558 | + <Autocomplete filter={contains} className="flex flex-col gap-1 w-5/6"> |
| 559 | + <SearchField> |
| 560 | + <Label className="text-sm text-black">Contacts</Label> |
| 561 | + <div className="relative w-full cursor-default overflow-hidden rounded-lg bg-white bg-opacity-90 focus-within:bg-opacity-100 transition text-left shadow-md [&:has([data-focus-visible])]:ring-2 [&:has([data-focus-visible])]:ring-black sm:text-sm"> |
| 562 | + <Input className="w-full border-none py-2 pl-3 pr-2 sm:text-sm leading-5 text-gray-900 bg-transparent outline-none" /> |
| 563 | + </div> |
| 564 | + </SearchField> |
| 565 | + <div className="h-[300px] py-2 rounded-lg flex justify-center"> |
| 566 | + <ListBox aria-label="Contacts" selectionMode="multiple" selectionBehavior="replace" className="w-72 max-h-[290px] overflow-auto outline-none bg-white text-gray-700 p-2 flex flex-col gap-2 rounded-lg shadow scroll-pb-2 scroll-pt-7"> |
| 567 | + <ContactSection title="Favorites"> |
| 568 | + <Contact id="wade" name="Tony Baldwin" handle="@tony" avatar="https://images.unsplash.com/photo-1633332755192-727a05c4013d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" /> |
| 569 | + <Contact id="arelene" name="Julienne Langstrath" handle="@jlangstrath" avatar="https://images.unsplash.com/photo-1580489944761-15a19d654956?ixlib=rb-1.2.1&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" /> |
| 570 | + <Contact id="tom" name="Roberto Gonzalez" handle="@rgonzalez" avatar="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" /> |
| 571 | + </ContactSection> |
| 572 | + <ContactSection title="All Contacts" items={people}> |
| 573 | + {item => <Contact name={item.name} handle={item.username} avatar={item.avatar} />} |
| 574 | + </ContactSection> |
| 575 | + </ListBox> |
| 576 | + </div> |
| 577 | + </Autocomplete> |
| 578 | + </div> |
| 579 | + ); |
| 580 | +} |
0 commit comments