2023-04-01 16:47:00 +11:00
|
|
|
import { Dialog, Transition } from '@headlessui/react'
|
2023-08-18 17:14:35 -05:00
|
|
|
import { Fragment } from 'react'
|
2023-04-01 16:47:00 +11:00
|
|
|
import { useCalc, CreateNewVariable } from './AvailableVarsHelpers'
|
2023-09-09 01:38:36 -04:00
|
|
|
import { ActionButton } from './ActionButton'
|
|
|
|
import { faPlus } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { toast } from 'react-hot-toast'
|
2023-04-01 16:47:00 +11:00
|
|
|
|
|
|
|
export const SetVarNameModal = ({
|
|
|
|
isOpen,
|
|
|
|
onResolve,
|
|
|
|
onReject,
|
|
|
|
valueName,
|
2023-10-10 06:43:25 +11:00
|
|
|
}: {
|
|
|
|
isOpen: boolean
|
|
|
|
onResolve: (a: { variableName?: string }) => void
|
|
|
|
onReject: (a: any) => void
|
|
|
|
value: number
|
|
|
|
valueName: string
|
|
|
|
}) => {
|
2023-04-01 16:47:00 +11:00
|
|
|
const { isNewVariableNameUnique, newVariableName, setNewVariableName } =
|
|
|
|
useCalc({ value: '', initialVariableName: valueName })
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Transition appear show={isOpen} as={Fragment}>
|
2023-09-09 01:38:36 -04:00
|
|
|
<Dialog
|
|
|
|
as="div"
|
|
|
|
className="fixed inset-0 z-40 overflow-y-auto p-4 pt-[25vh]"
|
|
|
|
onClose={onReject}
|
|
|
|
>
|
2023-04-01 16:47:00 +11:00
|
|
|
<Transition.Child
|
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-300"
|
2023-09-09 01:38:36 -04:00
|
|
|
enterFrom="opacity-0 translate-y-4"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="ease-in duration-75"
|
2023-04-01 16:47:00 +11:00
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2023-09-09 01:38:36 -04:00
|
|
|
<Dialog.Overlay className="fixed inset-0 bg-chalkboard-10/70 dark:bg-chalkboard-110/50" />
|
2023-04-01 16:47:00 +11:00
|
|
|
</Transition.Child>
|
|
|
|
|
2023-09-09 01:38:36 -04:00
|
|
|
<Transition.Child
|
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0 scale-95"
|
|
|
|
enterTo="opacity-100 scale-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100 scale-100"
|
|
|
|
leaveTo="opacity-0 scale-95"
|
|
|
|
>
|
|
|
|
<Dialog.Panel className="rounded relative mx-auto px-4 py-8 bg-chalkboard-10 dark:bg-chalkboard-100 border dark:border-chalkboard-70 max-w-xl w-full shadow-lg">
|
|
|
|
<form
|
|
|
|
onSubmit={(e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
onResolve({
|
|
|
|
variableName: newVariableName,
|
|
|
|
})
|
|
|
|
toast.success(`Added variable ${newVariableName}`)
|
|
|
|
}}
|
2023-04-01 16:47:00 +11:00
|
|
|
>
|
2023-09-09 01:38:36 -04:00
|
|
|
<CreateNewVariable
|
|
|
|
setNewVariableName={setNewVariableName}
|
|
|
|
newVariableName={newVariableName}
|
|
|
|
isNewVariableNameUnique={isNewVariableNameUnique}
|
|
|
|
shouldCreateVariable={true}
|
|
|
|
showCheckbox={false}
|
|
|
|
/>
|
|
|
|
<div className="mt-8 flex justify-between">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
type="submit"
|
|
|
|
disabled={!isNewVariableNameUnique}
|
|
|
|
icon={{ icon: faPlus }}
|
2023-04-01 16:47:00 +11:00
|
|
|
>
|
2023-09-09 01:38:36 -04:00
|
|
|
Add variable
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton Element="button" onClick={() => onReject(false)}>
|
|
|
|
Cancel
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</Dialog.Panel>
|
|
|
|
</Transition.Child>
|
2023-04-01 16:47:00 +11:00
|
|
|
</Dialog>
|
|
|
|
</Transition>
|
|
|
|
)
|
|
|
|
}
|