2023-06-29 17:29:13 +00:00
|
|
|
import { useContext, useMemo } from 'react'
|
2023-06-21 21:17:07 -05:00
|
|
|
import { PanZoomContext } from 'shared/components/workbench/pattern/pan-zoom-context.mjs'
|
2023-06-29 15:44:23 +00:00
|
|
|
import { useMobileAction } from 'shared/context/mobile-menubar-context.mjs'
|
2023-06-21 21:17:07 -05:00
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import {
|
|
|
|
PaperlessIcon,
|
|
|
|
SaIcon,
|
|
|
|
RocketIcon,
|
|
|
|
BulletIcon,
|
|
|
|
UnitsIcon,
|
|
|
|
DetailIcon,
|
|
|
|
IconWrapper,
|
|
|
|
ClearIcon,
|
|
|
|
} from 'shared/components/icons.mjs'
|
2023-06-24 15:00:46 -05:00
|
|
|
import { ClearAllButton } from 'shared/components/workbench/menus/core-settings/index.mjs'
|
2023-06-23 14:29:09 -05:00
|
|
|
import { shownHeaderSelector } from 'shared/components/wrappers/header.mjs'
|
2023-06-21 21:17:07 -05:00
|
|
|
|
2023-06-21 23:11:14 -05:00
|
|
|
export const ns = ['common', 'core-settings', 'ui-settings']
|
2023-06-21 21:17:07 -05:00
|
|
|
|
|
|
|
const ZoomInIcon = (props) => (
|
|
|
|
<IconWrapper {...props}>
|
|
|
|
<path d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607zM10.5 7.5v6m3-3h-6" />
|
|
|
|
</IconWrapper>
|
|
|
|
)
|
|
|
|
|
|
|
|
const ZoomOutIcon = (props) => (
|
|
|
|
<IconWrapper {...props}>
|
|
|
|
<path d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607zM13.5 10.5h-6" />
|
|
|
|
</IconWrapper>
|
|
|
|
)
|
|
|
|
|
2023-06-29 15:44:23 +00:00
|
|
|
const IconButton = ({ Icon, onClick, dflt = true, title, hide = false, extraClasses = '' }) => (
|
2023-06-21 23:11:14 -05:00
|
|
|
<div className="tooltip tooltip-bottom tooltip-primary flex items-center" data-tip={title}>
|
|
|
|
<button
|
|
|
|
onClick={onClick}
|
|
|
|
className={`text-${dflt ? 'neutral-content' : 'accent'} hover:text-secondary-focus ${
|
|
|
|
hide ? 'invisible' : ''
|
2023-06-29 15:44:23 +00:00
|
|
|
} ${extraClasses}`}
|
2023-06-21 23:11:14 -05:00
|
|
|
title={title}
|
|
|
|
>
|
|
|
|
<Icon />
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-06-21 21:17:07 -05:00
|
|
|
)
|
|
|
|
|
2023-06-29 15:44:23 +00:00
|
|
|
const smZoomClasses =
|
2023-06-29 16:41:11 +00:00
|
|
|
'[.mobile-menubar_&]:btn [.mobile-menubar_&]:btn-secondary [.mobile-menubar_&]:btn-circle [.mobile-menubar_&]:my-2'
|
2023-06-29 15:44:23 +00:00
|
|
|
const ZoomButtons = ({ t, zoomFunctions, zoomed }) => {
|
2023-06-21 21:17:07 -05:00
|
|
|
if (!zoomFunctions) return null
|
|
|
|
return (
|
2023-06-29 16:41:11 +00:00
|
|
|
<div className="flex flex-col lg:flex-row items-center lg:content-center lg:gap-4">
|
2023-06-21 21:17:07 -05:00
|
|
|
<IconButton
|
|
|
|
Icon={ClearIcon}
|
|
|
|
onClick={zoomFunctions.reset}
|
|
|
|
title={t('resetZoom')}
|
|
|
|
hide={!zoomed}
|
2023-06-29 15:44:23 +00:00
|
|
|
extraClasses={smZoomClasses}
|
2023-06-21 21:17:07 -05:00
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
Icon={ZoomOutIcon}
|
|
|
|
onClick={() => zoomFunctions.zoomOut()}
|
|
|
|
title={t('zoomOut')}
|
|
|
|
dflt
|
2023-06-29 15:44:23 +00:00
|
|
|
extraClasses={smZoomClasses}
|
2023-06-21 21:17:07 -05:00
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
Icon={ZoomInIcon}
|
|
|
|
onClick={() => zoomFunctions.zoomIn()}
|
|
|
|
title={t('zoomIn')}
|
|
|
|
dflt
|
2023-06-29 15:44:23 +00:00
|
|
|
extraClasses={smZoomClasses}
|
2023-06-21 21:17:07 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const Spacer = () => <span className="opacity-50">|</span>
|
|
|
|
|
2023-06-21 22:14:57 -05:00
|
|
|
export const ViewHeader = ({ update, settings, ui, control, setSettings }) => {
|
2023-06-21 21:17:07 -05:00
|
|
|
const { t } = useTranslation(ns)
|
2023-06-29 15:44:23 +00:00
|
|
|
const { zoomFunctions, zoomed } = useContext(PanZoomContext)
|
|
|
|
|
2023-06-29 17:29:13 +00:00
|
|
|
// make the zoom buttons so we can pass them to the mobile menubar
|
2023-06-29 15:44:23 +00:00
|
|
|
const headerZoomButtons = useMemo(
|
|
|
|
() => <ZoomButtons {...{ t, zoomFunctions, zoomed }} />,
|
|
|
|
[zoomed, t, zoomFunctions]
|
|
|
|
)
|
2023-06-29 17:29:13 +00:00
|
|
|
// add the zoom buttons as an action on the mobile menubar
|
2023-06-29 15:44:23 +00:00
|
|
|
useMobileAction('zoom', { order: 0, actionContent: headerZoomButtons })
|
|
|
|
|
2023-06-21 21:17:07 -05:00
|
|
|
return (
|
2023-06-23 14:29:09 -05:00
|
|
|
<div
|
2023-06-29 15:44:23 +00:00
|
|
|
className={`hidden lg:flex sticky top-0 z-20 ${shownHeaderSelector(
|
|
|
|
'lg:top-24'
|
|
|
|
)} transition-[top] duration-300 ease-in-out`}
|
2023-06-23 14:29:09 -05:00
|
|
|
>
|
|
|
|
<div className="hidden lg:flex flex-row flex-wrap gap-4 py-4 pt-4 w-full bg-neutral text-neutral-content items-center justify-center">
|
2023-06-29 15:44:23 +00:00
|
|
|
{headerZoomButtons}
|
2023-06-23 14:29:09 -05:00
|
|
|
<Spacer />
|
|
|
|
<div className="flex flex-row items-center gap-4">
|
|
|
|
<IconButton
|
|
|
|
Icon={SaIcon}
|
|
|
|
dflt={settings.sabool ? false : true}
|
|
|
|
onClick={() => update.toggleSa()}
|
|
|
|
title={t('core-settings:sabool.t')}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
Icon={PaperlessIcon}
|
|
|
|
dflt={settings.paperless ? false : true}
|
|
|
|
onClick={() => update.settings(['paperless'], !settings.paperless)}
|
|
|
|
title={t('core-settings:paperless.t')}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
Icon={DetailIcon}
|
|
|
|
dflt={settings.complete}
|
|
|
|
onClick={() =>
|
|
|
|
update.settings(
|
|
|
|
['complete'],
|
|
|
|
typeof settings.complete === 'undefined' ? 0 : settings.complete ? 0 : 1
|
|
|
|
)
|
|
|
|
}
|
|
|
|
title={t('core-settings:complete.t')}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
Icon={
|
|
|
|
settings.units !== 'imperial'
|
|
|
|
? UnitsIcon
|
|
|
|
: ({ className }) => <UnitsIcon className={`${className} rotate-180 w-6 h-6`} />
|
|
|
|
}
|
|
|
|
dflt={settings.units !== 'imperial'}
|
|
|
|
onClick={() =>
|
|
|
|
update.settings(['units'], settings.units === 'imperial' ? 'metric' : 'imperial')
|
|
|
|
}
|
|
|
|
title={t('core-settings:units.t')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Spacer />
|
|
|
|
<div
|
|
|
|
className="tooltip tooltip-primary tooltip-bottom flex flex-row items-center"
|
|
|
|
data-tip={t('ui-settings:control.t')}
|
2023-06-21 22:14:57 -05:00
|
|
|
>
|
2023-06-23 14:29:09 -05:00
|
|
|
{[1, 2, 3, 4, 5].map((score) => (
|
|
|
|
<button onClick={() => update.setControl(score)} className="text-primary" key={score}>
|
|
|
|
<BulletIcon fill={control >= score ? true : false} />
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<Spacer />
|
|
|
|
<div className="flex flex-row items-center gap-4">
|
|
|
|
<IconButton
|
|
|
|
Icon={RocketIcon}
|
|
|
|
dflt={ui.renderer !== 'svg'}
|
|
|
|
onClick={() => update.ui(['renderer'], ui.renderer === 'react' ? 'svg' : 'react')}
|
|
|
|
title={t('ui-settings:renderer.t')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Spacer />
|
|
|
|
<div className="flex flex-row items-center gap-4">
|
2023-06-24 15:00:46 -05:00
|
|
|
<ClearAllButton setSettings={setSettings} compact />
|
2023-06-23 14:29:09 -05:00
|
|
|
</div>
|
2023-06-21 22:14:57 -05:00
|
|
|
</div>
|
2023-06-21 21:17:07 -05:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|