diff --git a/packages/bruno-app/src/components/BodyModeSelector/index.js b/packages/bruno-app/src/components/BodyModeSelector/index.js new file mode 100644 index 0000000000..842c3f9ce6 --- /dev/null +++ b/packages/bruno-app/src/components/BodyModeSelector/index.js @@ -0,0 +1,83 @@ +import React, { useRef, forwardRef } from 'react'; +import { IconCaretDown } from '@tabler/icons'; +import Dropdown from 'components/Dropdown'; +import { humanizeRequestBodyMode } from 'utils/collections'; + +const DEFAULT_MODES = [ + { key: 'multipartForm', label: 'Multipart Form', category: 'Form' }, + { key: 'formUrlEncoded', label: 'Form URL Encoded', category: 'Form' }, + { key: 'json', label: 'JSON', category: 'Raw' }, + { key: 'xml', label: 'XML', category: 'Raw' }, + { key: 'text', label: 'TEXT', category: 'Raw' }, + { key: 'sparql', label: 'SPARQL', category: 'Raw' }, + { key: 'file', label: 'File / Binary', category: 'Other' }, + { key: 'none', label: 'None', category: 'Other' } +]; + +const BodyModeSelector = ({ + currentMode, + onModeChange, + modes = DEFAULT_MODES, + disabled = false, + className = '', + wrapperClassName = '', + showCategories = true, + placement = 'bottom-end' +}) => { + const dropdownTippyRef = useRef(); + const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref); + + const Icon = forwardRef((props, ref) => { + return ( +