2022-09-20 11:14:09 +02:00
|
|
|
import { Fragment } from 'react'
|
2021-12-11 14:04:05 +01:00
|
|
|
import themes from 'shared/themes/index.js'
|
2021-12-30 14:23:02 +01:00
|
|
|
import ThemeIcon from 'shared/components/icons/theme.js'
|
2022-02-10 21:40:19 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-09-20 11:14:09 +02:00
|
|
|
import { Popover, Transition } from '@headlessui/react'
|
2022-10-05 23:04:12 +02:00
|
|
|
import DownIcon from 'shared/components/icons/down'
|
2021-12-11 14:04:05 +01:00
|
|
|
|
2022-10-04 01:20:49 +02:00
|
|
|
const ThemePicker = ({ app, className, iconOnly = false }) => {
|
2022-09-20 11:14:09 +02:00
|
|
|
const { t } = useTranslation(['themes', 'common'])
|
2022-02-10 21:40:19 +01:00
|
|
|
|
2022-09-20 11:14:09 +02:00
|
|
|
return (
|
|
|
|
<Popover className="relative">
|
|
|
|
{() => (
|
|
|
|
<>
|
|
|
|
<Popover.Button
|
2022-10-04 01:20:49 +02:00
|
|
|
className={`group inline-flex items-center px-3 py-2 text-base font-medium text-neural-content rounded-lg px-4 hover:text-secondary-focus`}
|
2022-09-20 11:14:09 +02:00
|
|
|
>
|
|
|
|
<ThemeIcon />
|
2022-10-04 01:20:49 +02:00
|
|
|
{!iconOnly && <span className="ml-4 font-medium capitalize">{t(`common:theme`)}</span>}
|
2022-10-05 23:01:04 +02:00
|
|
|
<DownIcon className={`ml-2 h-5 w-5`} aria-hidden="true" />
|
2022-09-20 11:14:09 +02:00
|
|
|
</Popover.Button>
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 translate-y-1"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="transition ease-in duration-150"
|
|
|
|
leaveFrom="opacity-100 translate-y-0"
|
|
|
|
leaveTo="opacity-0 translate-y-1"
|
|
|
|
>
|
|
|
|
<Popover.Panel className="absolute z-10 mt-3 w-screen max-w-sm transform px-4 sm:px-0 lg:max-w-xl right-0">
|
|
|
|
<div className="overflow-hidden rounded-lg shadow-lg">
|
|
|
|
<div className="relative grid gap-8 bg-base-100 p-7 lg:grid-cols-1">
|
2022-10-04 01:20:49 +02:00
|
|
|
{Object.keys(themes).map((theme) => (
|
2022-09-20 11:14:09 +02:00
|
|
|
<button
|
|
|
|
key={theme}
|
|
|
|
onClick={() => app.setTheme(theme)}
|
|
|
|
data-theme={theme}
|
|
|
|
className="-m-3 flex rounded-lg p-2 transition duration-150 ease-in-out-50 hover:translate-x-2 hover:cursor-pointer"
|
|
|
|
>
|
2022-10-17 09:03:15 +02:00
|
|
|
<div className="w-full">
|
|
|
|
<div className="px-2">
|
|
|
|
<p className="text-xl font-medium text-base text-left mb-0 pb-0">
|
|
|
|
{t(`${theme}Theme`)}
|
|
|
|
</p>
|
|
|
|
<div className="theme-gradient h-1 w-full mb-2"></div>
|
|
|
|
<p className="text-base text-left -mt-4 shadow">
|
|
|
|
{t('common:sloganCome')}
|
|
|
|
<span className="px-2">|</span>
|
|
|
|
{t('common:sloganStay')}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-09-20 11:14:09 +02:00
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
)
|
2021-12-11 14:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ThemePicker
|