import clsx from 'clsx'; import { Dialog, DialogPanel, DialogTitle, Button, Input, Label, Field } from '@headlessui/react'; import { useOptions } from '/src/utils/optionsContext'; import { useState } from 'react'; const FieldOption = ({ name, type, state }) => { const { options } = useOptions(); const [form, setForm] = state; return ( {name} setForm({ ...form, [type]: e.target.value })} /> ); }; const NewQuickLink = ({ state, set, update }) => { const { options } = useOptions(); const [form, setForm] = useState({ name: '', icon: '', link: '', }); const regex = (link) => (/^(https?:)?\/\//.test(link) ? link : `https://${link}`); const clear = () => setForm({ name: '', icon: '', link: '', }); const action = () => { set(false); update({ ...form, link: regex(form.link.trim()), icon: regex(form.icon.trim()), }); clear(); }; const filled = () => { if (form.name && form.link) return true; else return false; }; return ( <> set(false)} className="fixed inset-0 bg-black/40 z-50"> Add shortcut { set(false); clear(); }} className="cursor-pointer duration-150 hover:opacity-80" > Cancel action())} className={clsx( filled() ? 'cursor-pointer hover:opacity-80' : 'cursor-not-allowed opacity-70', 'duration-150', )} > Confirm > ); }; export default NewQuickLink;