2021-04-13 09:51:42 -07:00
|
|
|
import { LockClosedIcon, LockOpenIcon } from '@heroicons/react/outline'
|
2021-04-22 05:33:35 -07:00
|
|
|
import { Transition } from '@headlessui/react'
|
2021-04-13 09:51:42 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-04-22 05:33:35 -07:00
|
|
|
import ResetLayout from './ResetLayout'
|
2021-04-24 15:02:13 -07:00
|
|
|
import Tooltip from './Tooltip'
|
2021-07-29 06:19:32 -07:00
|
|
|
import { IconButton } from './Button'
|
2021-10-20 05:42:40 -07:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-04-13 09:51:42 -07:00
|
|
|
|
|
|
|
const UiLock = ({ className = '' }) => {
|
2021-10-20 05:42:40 -07:00
|
|
|
const { t } = useTranslation('common')
|
2021-04-13 09:51:42 -07:00
|
|
|
const set = useMangoStore((s) => s.set)
|
|
|
|
const uiLocked = useMangoStore((s) => s.settings.uiLocked)
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
set((state) => {
|
|
|
|
state.settings.uiLocked = !uiLocked
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-05-07 12:41:26 -07:00
|
|
|
<div className="flex">
|
2021-04-22 05:33:35 -07:00
|
|
|
{!uiLocked ? (
|
|
|
|
<Transition
|
|
|
|
appear={true}
|
|
|
|
show={!uiLocked}
|
|
|
|
enter="transition-opacity duration-500"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="transition-opacity duration-500"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
2021-05-17 22:33:04 -07:00
|
|
|
className="pr-2"
|
2021-04-22 05:33:35 -07:00
|
|
|
>
|
|
|
|
<ResetLayout />
|
|
|
|
</Transition>
|
|
|
|
) : null}
|
2021-05-07 12:41:26 -07:00
|
|
|
<div className={`${className} flex relative cursor-pointer`}>
|
2021-04-24 15:02:13 -07:00
|
|
|
<Tooltip
|
2021-10-20 05:42:40 -07:00
|
|
|
content={
|
|
|
|
uiLocked ? t('tooltip-unlock-layout') : t('tooltip-lock-layout')
|
|
|
|
}
|
2021-04-24 15:02:13 -07:00
|
|
|
className="text-xs py-1"
|
2021-04-22 05:33:35 -07:00
|
|
|
>
|
2021-07-29 06:19:32 -07:00
|
|
|
<IconButton onClick={handleClick}>
|
2021-04-24 15:02:13 -07:00
|
|
|
{uiLocked ? (
|
2021-05-07 12:41:26 -07:00
|
|
|
<LockClosedIcon className="w-4 h-4" />
|
2021-04-24 15:02:13 -07:00
|
|
|
) : (
|
2021-05-07 12:41:26 -07:00
|
|
|
<LockOpenIcon className="w-4 h-4 animate-bounce" />
|
2021-04-24 15:02:13 -07:00
|
|
|
)}
|
2021-07-29 06:19:32 -07:00
|
|
|
</IconButton>
|
2021-04-24 15:02:13 -07:00
|
|
|
</Tooltip>
|
2021-04-22 05:33:35 -07:00
|
|
|
</div>
|
2021-05-07 12:41:26 -07:00
|
|
|
</div>
|
2021-04-13 09:51:42 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UiLock
|