|
1 | 1 | import React, { Fragment, useState, useRef } from 'react'; |
2 | 2 | import { PropTypes } from 'prop-types'; |
| 3 | +import { Listbox, Transition } from '@headlessui/react'; |
| 4 | +import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid'; |
3 | 5 | import { EllipsisVerticalIcon, PlusIcon } from '@heroicons/react/24/solid'; |
4 | 6 | import { |
5 | 7 | DocumentArrowUpIcon, |
6 | 8 | ClipboardDocumentCheckIcon, |
7 | 9 | ClipboardDocumentIcon, |
8 | 10 | TrashIcon, |
9 | 11 | } from '@heroicons/react/24/outline'; |
10 | | -import { Menu, Transition } from '@headlessui/react'; |
| 12 | +//import { Menu, Transition } from '@headlessui/react'; |
11 | 13 | import useCanvasStore from 'stores/CanvasStore'; |
12 | 14 | import { toast } from 'react-toastify'; |
13 | 15 | import { Editor } from 'components/atoms/Editor'; |
@@ -216,36 +218,50 @@ const RequestBody = ({ nodeId, nodeData }) => { |
216 | 218 | <> |
217 | 219 | <div className='flex items-center justify-between bg-background p-4'> |
218 | 220 | <h3>Body</h3> |
219 | | - <Menu as='div' className='relative inline-block text-left'> |
220 | | - <Menu.Button data-click-from='body-type-menu'> |
221 | | - <EllipsisVerticalIcon className='h-4 w-4' aria-hidden='true' data-click-from='body-type-menu' /> |
222 | | - </Menu.Button> |
223 | | - <Transition |
224 | | - as={Fragment} |
225 | | - enter='transition ease-out duration-100' |
226 | | - enterFrom='transform opacity-0 scale-95' |
227 | | - enterTo='transform opacity-100 scale-100' |
228 | | - leave='transition ease-in duration-75' |
229 | | - leaveFrom='transform opacity-100 scale-100' |
230 | | - leaveTo='transform opacity-0 scale-95' |
231 | | - > |
232 | | - <Menu.Items |
233 | | - className='absolute right-0 z-10 mt-2 w-56 origin-top-right divide-y divide-gray-100 rounded-md bg-white px-1 py-1 shadow-lg ring-1 ring-black/5 focus:outline-none' |
234 | | - data-click-from='body-type-menu' |
| 221 | + <Listbox |
| 222 | + value={nodeData.requestBody?.type ? nodeData.requestBody.type : 'None'} |
| 223 | + onChange={(selectedValue) => { |
| 224 | + handleClose(selectedValue); |
| 225 | + }} |
| 226 | + className='text-xl' |
| 227 | + > |
| 228 | + <div> |
| 229 | + <Listbox.Button className='relative flex cursor-default border-cyan-950 text-left'> |
| 230 | + <EllipsisVerticalIcon className='h-4 w-4' aria-hidden='true' data-click-from='body-type-menu' /> |
| 231 | + </Listbox.Button> |
| 232 | + <Transition |
| 233 | + as={Fragment} |
| 234 | + leave='transition ease-in duration-100' |
| 235 | + leaveFrom='opacity-100' |
| 236 | + leaveTo='opacity-0' |
235 | 237 | > |
236 | | - {requestBodyTypeOptions.map((bodyTypeOption, index) => ( |
237 | | - <Menu.Item key={index} data-click-from='body-type-menu' onClick={() => handleClose(bodyTypeOption)}> |
238 | | - <button |
239 | | - className='group flex w-full items-center rounded-md px-2 py-2 text-sm text-gray-900 hover:bg-background-light' |
240 | | - data-click-from='body-type-menu' |
| 238 | + <Listbox.Options className='absolute z-50 mt-1 max-h-60 w-36 overflow-auto bg-white py-1 text-base focus:outline-none'> |
| 239 | + {requestBodyTypeOptions.map((bodyTypeOption) => ( |
| 240 | + <Listbox.Option |
| 241 | + key={bodyTypeOption} |
| 242 | + className={({ active }) => |
| 243 | + `relative cursor-default select-none py-2 pl-7 pr-4 hover:font-semibold ${ |
| 244 | + active ? 'bg-background-light text-slate-900' : '' |
| 245 | + }` |
| 246 | + } |
| 247 | + value={bodyTypeOption} |
241 | 248 | > |
242 | | - {bodyTypeOption} |
243 | | - </button> |
244 | | - </Menu.Item> |
245 | | - ))} |
246 | | - </Menu.Items> |
247 | | - </Transition> |
248 | | - </Menu> |
| 249 | + {({ selected }) => ( |
| 250 | + <> |
| 251 | + <span className={`block`}>{bodyTypeOption}</span> |
| 252 | + {selected ? ( |
| 253 | + <span className='absolute inset-y-0 left-0 flex items-center pl-1 font-semibold'> |
| 254 | + <CheckIcon className='h-5 w-5' aria-hidden='true' /> |
| 255 | + </span> |
| 256 | + ) : null} |
| 257 | + </> |
| 258 | + )} |
| 259 | + </Listbox.Option> |
| 260 | + ))} |
| 261 | + </Listbox.Options> |
| 262 | + </Transition> |
| 263 | + </div> |
| 264 | + </Listbox> |
249 | 265 | </div> |
250 | 266 | {nodeData.requestBody && nodeData.requestBody.type === 'raw-json' && ( |
251 | 267 | <> |
|
0 commit comments