import { Fragment,useState } from 'react'; import { faShuffle } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Menu, Transition } from '@headlessui/react'; /** * This is the menu that is used to (re)generate secrets (currently we only have ranom hex, in future we will have more options) * @returns the popup-menu for randomly generating secrets */ const GenerateSecretMenu = ({ modifyValue, position }: { modifyValue: (value: string, position: number) => void; position: number; }) => { const [randomStringLength, setRandomStringLength] = useState(32); return
{ if (randomStringLength > 32) { setRandomStringLength(32); } else if (randomStringLength < 2) { setRandomStringLength(2); } else { modifyValue( [...Array(randomStringLength)] .map(() => Math.floor(Math.random() * 16).toString(16)) .join(''), position ); } }} className="relative flex flex-row justify-start items-center cursor-pointer select-none py-2 px-2 rounded-md text-gray-400 hover:bg-white/10 duration-200 hover:text-gray-200 w-full" >

Generate Random Hex

digits

{ if (randomStringLength > 1) { setRandomStringLength(randomStringLength - 1); } }} > -
setRandomStringLength(parseInt(e.target.value)) } value={randomStringLength} className="text-center z-20 peer text-sm bg-transparent w-full outline-none" spellCheck="false" />
{ if (randomStringLength < 32) { setRandomStringLength(randomStringLength + 1); } }} > +
} export default GenerateSecretMenu;