import { Combobox, Listbox, RadioGroup, Switch } from '@headlessui/react' import { useState } from 'react' import { Button } from '../../components/button' import { classNames } from '../../utils/class-names' function Section({ title, children }) { return (
{title}
{children}
) } let sizes = ['xs', 'sm', 'md', 'lg', 'xl'] let people = [ { id: 1, name: { first: 'Alice' } }, { id: 2, name: { first: 'Bob' } }, { id: 3, name: { first: 'Charlie' } }, ] let locations = ['New York', 'London', 'Paris', 'Berlin'] export default function App() { let [result, setResult] = useState(() => typeof window === 'undefined' || typeof document === 'undefined' ? [] : new FormData() ) let [query, setQuery] = useState('') return (
{ event.preventDefault() setResult(new FormData(event.currentTarget)) }} >
Enable notifications classNames( 'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2', checked ? 'bg-blue-600' : 'bg-gray-200' ) } > {({ checked }) => ( )}
Apple classNames( 'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2', checked ? 'bg-blue-600' : 'bg-gray-200' ) } > {({ checked }) => ( )} Banana classNames( 'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2', checked ? 'bg-blue-600' : 'bg-gray-200' ) } > {({ checked }) => ( )}
{sizes.map((size) => { return ( classNames( 'relative flex w-20 border px-2 py-4 first:rounded-l-md last:rounded-r-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2', active ? 'z-10 border-blue-200 bg-blue-50' : 'border-gray-200' ) } > {({ active, checked }) => (
{size}
{checked && ( )}
)}
) })}
{({ value }) => ( <>
{value?.name?.first}
{people.map((person) => ( { return classNames( 'relative cursor-default select-none py-2 pl-3 pr-9 ', active ? 'bg-blue-600 text-white' : 'text-gray-900' ) }} > {({ active, selected }) => ( <> {person.name.first} {selected && ( )} )} ))}
)}
{ setQuery('') }} > {({ open, value }) => { return (
setQuery(e.target.value)} className="w-full rounded rounded-md border-gray-300 bg-clip-padding px-3 py-1 shadow-sm focus:border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2" placeholder="Search users..." />
{locations .filter((location) => location.toLowerCase().includes(query.toLowerCase()) ) .map((location) => ( { return classNames( 'relative flex cursor-default select-none space-x-4 py-2 pl-3 pr-9 ', active ? 'bg-blue-600 text-white' : 'text-gray-900' ) }} > {({ active, selected }) => ( <> {location} {active && ( )} )} ))}
) }}
Form data (entries):
{JSON.stringify([...result.entries()], null, 2)}
) }