2024-06-07 20:17:03 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
|
|
|
import { IconMenuFold, IconMenuUnfold } from '@/components/Icons';
|
|
|
|
import Button from '@/components/ui/Button';
|
|
|
|
import SelectTree from '@/components/ui/SelectTree';
|
2024-06-26 19:47:05 +03:00
|
|
|
import { useConceptOptions } from '@/context/ConceptOptionsContext';
|
2024-06-07 20:17:03 +03:00
|
|
|
import useDropdown from '@/hooks/useDropdown';
|
|
|
|
import { HelpTopic, topicParent } from '@/models/miscellaneous';
|
2024-12-11 23:37:23 +03:00
|
|
|
import { PARAMETER, prefixes } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
import { describeHelpTopic, labelHelpTopic } from '@/utils/labels';
|
|
|
|
|
|
|
|
interface TopicsDropdownProps {
|
|
|
|
activeTopic: HelpTopic;
|
|
|
|
onChangeTopic: (newTopic: HelpTopic) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
function TopicsDropdown({ activeTopic, onChangeTopic }: TopicsDropdownProps) {
|
|
|
|
const menu = useDropdown();
|
|
|
|
const { noNavigation, calculateHeight } = useConceptOptions();
|
|
|
|
|
|
|
|
const handleSelectTopic = useCallback(
|
|
|
|
(topic: HelpTopic) => {
|
|
|
|
menu.hide();
|
|
|
|
onChangeTopic(topic);
|
|
|
|
},
|
|
|
|
[onChangeTopic, menu]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={menu.ref}
|
|
|
|
className={clsx(
|
|
|
|
'absolute left-0 w-[13.5rem]', // prettier: split-lines
|
|
|
|
'flex flex-col',
|
|
|
|
'z-modalTooltip',
|
|
|
|
'text-xs sm:text-sm',
|
|
|
|
'select-none',
|
|
|
|
{
|
|
|
|
'top-0': noNavigation,
|
|
|
|
'top-[3rem]': !noNavigation
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
noOutline
|
|
|
|
tabIndex={-1}
|
|
|
|
title='Список тем'
|
|
|
|
hideTitle={menu.isOpen}
|
|
|
|
icon={!menu.isOpen ? <IconMenuUnfold size='1.25rem' /> : <IconMenuFold size='1.25rem' />}
|
2024-12-11 14:59:04 +03:00
|
|
|
className={clsx('w-[3rem] h-7 rounded-none border-l-0', menu.isOpen && 'border-b-0')}
|
2024-06-07 20:17:03 +03:00
|
|
|
onClick={menu.toggle}
|
|
|
|
/>
|
2024-12-11 23:37:23 +03:00
|
|
|
<SelectTree
|
|
|
|
items={Object.values(HelpTopic).map(item => item as HelpTopic)}
|
|
|
|
value={activeTopic}
|
|
|
|
onChangeValue={handleSelectTopic}
|
|
|
|
prefix={prefixes.topic_list}
|
|
|
|
getParent={item => topicParent.get(item) ?? item}
|
|
|
|
getLabel={labelHelpTopic}
|
|
|
|
getDescription={describeHelpTopic}
|
2024-06-07 20:17:03 +03:00
|
|
|
className={clsx(
|
2024-12-11 23:37:23 +03:00
|
|
|
'border-r border-t rounded-none', // prettier: split-lines
|
2024-06-07 20:17:03 +03:00
|
|
|
'cc-scroll-y',
|
2024-12-17 10:52:36 +03:00
|
|
|
'bg-prim-200'
|
2024-06-07 20:17:03 +03:00
|
|
|
)}
|
2024-12-11 23:37:23 +03:00
|
|
|
style={{
|
|
|
|
maxHeight: calculateHeight('4rem + 2px'),
|
|
|
|
transitionProperty: 'clip-path',
|
|
|
|
transitionDuration: `${PARAMETER.moveDuration}ms`,
|
|
|
|
clipPath: menu.isOpen ? 'inset(0% 0% 0% 0%)' : 'inset(0% 100% 0% 0%)'
|
|
|
|
}}
|
|
|
|
/>
|
2024-06-07 20:17:03 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopicsDropdown;
|