2022-01-22 17:55:03 +01:00
|
|
|
import { useState } from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import orderBy from 'lodash.orderby'
|
|
|
|
import OptionsIcon from 'shared/components/icons/options.js'
|
|
|
|
import SettingsIcon from 'shared/components/icons/settings.js'
|
2022-01-25 08:31:06 +01:00
|
|
|
import MenuIcon from 'shared/components/icons/menu.js'
|
2022-01-22 17:55:03 +01:00
|
|
|
import { linkClasses, Chevron } from 'shared/components/navigation/primary.js'
|
|
|
|
|
2022-01-25 08:31:06 +01:00
|
|
|
// Component that renders a sublevel of navigation
|
|
|
|
const ModeButtons = props => props.children.length === 0
|
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<ul className="pl-5 list-inside">
|
|
|
|
{props.children.map(mode => (
|
|
|
|
<li key={mode.title} className="flex flex-row">
|
|
|
|
<button title={mode.title} className={`
|
|
|
|
grow pl-2 border-l-2
|
|
|
|
${linkClasses}
|
|
|
|
hover:border-secondary
|
|
|
|
sm:hover:border-secondary-focus
|
|
|
|
text-left
|
2022-01-25 10:29:47 +01:00
|
|
|
capitalize
|
2022-01-25 08:31:06 +01:00
|
|
|
${mode.name === props.mode
|
|
|
|
? 'text-secondary border-secondary sm:text-secondary-focus sm:border-secondary-focus'
|
|
|
|
: 'text-base-content sm:text-neutral-content'
|
|
|
|
}
|
2022-01-25 10:03:10 +01:00
|
|
|
`} onClick={mode.onClick}>
|
2022-01-25 08:31:06 +01:00
|
|
|
<span className={`
|
|
|
|
text-3xl mr-2 inline-block p-0 leading-3
|
|
|
|
${mode.name === props.mode
|
|
|
|
? 'text-secondary sm:text-secondary-focus translate-y-1'
|
|
|
|
: 'translate-y-3'
|
|
|
|
}
|
|
|
|
`}>
|
|
|
|
{mode.name === props.mode ? <>•</> : <>°</>}
|
|
|
|
</span>
|
|
|
|
<span className={mode.name === props.mode ? 'font-bold' : ''}>
|
|
|
|
{ mode.title }
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
)
|
2022-01-22 17:55:03 +01:00
|
|
|
|
2022-01-25 08:31:06 +01:00
|
|
|
const groupMaker = (t, setMode, pattern) => ({
|
|
|
|
modes: {
|
|
|
|
icon: <MenuIcon />,
|
|
|
|
title: t('app.modes'),
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
name: 'measurements',
|
|
|
|
title: t('app.measurements'),
|
|
|
|
onClick: () => setMode('measurements')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'draft',
|
2022-01-25 10:29:47 +01:00
|
|
|
title: t('app.draftPattern', { pattern: pattern.config.name }),
|
2022-01-25 08:31:06 +01:00
|
|
|
onClick: () => setMode('draft')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test',
|
2022-01-25 10:29:47 +01:00
|
|
|
title: t('app.testPattern', { pattern: pattern.config.name }),
|
2022-01-25 08:31:06 +01:00
|
|
|
onClick: () => setMode('test')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'export',
|
|
|
|
title: t('app.export'),
|
|
|
|
onClick: () => setMode('export')
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
toggles: {
|
|
|
|
icon: <OptionsIcon />,
|
|
|
|
title: `${t('cfp.turnOn')} / ${t('cfp.turnOff')}`,
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
icon: <OptionsIcon />,
|
|
|
|
title: t('app.designOptions'),
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
icon: <SettingsIcon />,
|
|
|
|
title: t('app.settings')
|
|
|
|
},
|
|
|
|
})
|
2022-01-22 17:55:03 +01:00
|
|
|
|
2022-01-25 08:31:06 +01:00
|
|
|
const WorkbenchMenu = props => {
|
|
|
|
const groups = groupMaker(props.app.t, props.setMode, props.pattern)
|
|
|
|
return (
|
|
|
|
<nav className="smmax-w-96 grow mb-12">
|
|
|
|
{Object.keys(groups).map(group => (
|
2022-01-25 10:03:10 +01:00
|
|
|
<details className='py-1' key={group}>
|
2022-01-25 08:31:06 +01:00
|
|
|
<summary className={`
|
|
|
|
flex flex-row uppercase gap-4 font-bold text-lg
|
|
|
|
hover:cursor-row-resize
|
|
|
|
p-2
|
|
|
|
text-base-content
|
|
|
|
sm:text-neutral-content
|
|
|
|
items-center
|
|
|
|
`} open={'modes' === group}>
|
|
|
|
<span className="text-secondary-focus mr-4">{groups[group].icon}</span>
|
|
|
|
<span className={`grow ${linkClasses}`}>
|
|
|
|
{groups[group].title}
|
|
|
|
</span>
|
|
|
|
<Chevron />
|
|
|
|
</summary>
|
|
|
|
{group === 'modes' && <ModeButtons {...props} {...groups[group]} />}
|
|
|
|
</details>
|
|
|
|
))}
|
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|
2022-01-22 17:55:03 +01:00
|
|
|
|
|
|
|
export default WorkbenchMenu
|