|
| 1 | +import React, { Fragment, useState } from 'react'; |
| 2 | +import { Listbox, Transition } from '@headlessui/react'; |
| 3 | +import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid'; |
| 4 | +import { Square3Stack3DIcon } from '@heroicons/react/24/outline'; |
| 5 | + |
| 6 | +const environments = [ |
| 7 | + { |
| 8 | + id: 'feebd601-63c5-4a4f-8def-1dde4f317567', |
| 9 | + createdAt: 1710096201431, |
| 10 | + modifiedAt: 1710096201431, |
| 11 | + name: 'test.env', |
| 12 | + pathname: |
| 13 | + '/Users/sirachit/Desktop/Personal Devo/FlowTest/test/folder-test/Simple API overview/environments/test.env', |
| 14 | + variables: { k1: 'v1', k2: 'v2', k3: 'v3' }, |
| 15 | + }, |
| 16 | + { |
| 17 | + id: 'feebd601-63c5-4a4f-8def-1dde4f317567', |
| 18 | + createdAt: 1710096202431, |
| 19 | + modifiedAt: 1710096202431, |
| 20 | + name: 'test2.env', |
| 21 | + pathname: |
| 22 | + '/Users/sirachit/Desktop/Personal Devo/FlowTest/test/folder-test/Simple API overview/environments/test2.env', |
| 23 | + variables: { k1: 'v1', k2: 'v2', k3: 'v3' }, |
| 24 | + }, |
| 25 | +]; |
| 26 | + |
| 27 | +const SelectEnvironment = () => { |
| 28 | + const [selected, setSelected] = useState(null); |
| 29 | + return ( |
| 30 | + <Listbox value={selected} onChange={setSelected}> |
| 31 | + <div className='relative flex h-full pl-4 border-l border-neutral-300'> |
| 32 | + <Listbox.Button className='flex items-center justify-between gap-4 cursor-default sm:text-sm'> |
| 33 | + <Square3Stack3DIcon className='w-4 h-4' /> |
| 34 | + <div className='min-w-32'>{selected ? selected : 'Select environment'}</div> |
| 35 | + <ChevronUpDownIcon className='w-5 h-5' aria-hidden='true' /> |
| 36 | + </Listbox.Button> |
| 37 | + <Transition as={Fragment} leave='transition ease-in duration-100' leaveFrom='opacity-100' leaveTo='opacity-0'> |
| 38 | + <Listbox.Options className='absolute right-0 z-10 w-full py-1 mt-1 overflow-auto text-base bg-white rounded shadow-lg top-12 max-h-60 ring-1 ring-black/5 sm:text-sm'> |
| 39 | + {environments.map((environment, environmentIndex) => ( |
| 40 | + <Listbox.Option |
| 41 | + key={environmentIndex} |
| 42 | + className={({ active }) => |
| 43 | + `relative cursor-default select-none py-2 pl-10 pr-4 ${ |
| 44 | + active ? 'bg-amber-100 text-amber-900' : 'text-gray-900' |
| 45 | + }` |
| 46 | + } |
| 47 | + value={environment.name} |
| 48 | + > |
| 49 | + {({ selected }) => ( |
| 50 | + <> |
| 51 | + <span className={`block truncate ${selected ? 'font-medium' : 'font-normal'}`}> |
| 52 | + {environment.name} |
| 53 | + </span> |
| 54 | + {selected ? ( |
| 55 | + <span className='absolute inset-y-0 left-0 flex items-center pl-3 text-amber-600'> |
| 56 | + <CheckIcon className='w-5 h-5' aria-hidden='true' /> |
| 57 | + </span> |
| 58 | + ) : null} |
| 59 | + </> |
| 60 | + )} |
| 61 | + </Listbox.Option> |
| 62 | + ))} |
| 63 | + </Listbox.Options> |
| 64 | + </Transition> |
| 65 | + </div> |
| 66 | + </Listbox> |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +export default SelectEnvironment; |
0 commit comments