2024-02-22 15:07:05 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Button } from '@/components/Control';
|
|
|
|
import { useDropdown } from '@/components/Dropdown';
|
2024-05-02 17:04:18 +03:00
|
|
|
import { IconMenuFold, IconMenuUnfold } from '@/components/Icons';
|
2025-02-10 01:32:55 +03:00
|
|
|
import { SelectTree } from '@/components/Input';
|
2025-01-14 21:58:16 +03:00
|
|
|
import { useAppLayoutStore, useFitHeight } from '@/stores/appLayout';
|
2024-12-12 13:19:12 +03:00
|
|
|
import { PARAMETER, prefixes } from '@/utils/constants';
|
2024-05-20 17:45:37 +03:00
|
|
|
import { describeHelpTopic, labelHelpTopic } from '@/utils/labels';
|
2024-05-14 19:16:04 +03:00
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { topicParent } from '../../models/helpTopic';
|
|
|
|
import { HelpTopic } from '../../models/helpTopic';
|
|
|
|
|
2024-05-14 19:16:04 +03:00
|
|
|
interface TopicsDropdownProps {
|
2024-02-22 15:07:05 +03:00
|
|
|
activeTopic: HelpTopic;
|
|
|
|
onChangeTopic: (newTopic: HelpTopic) => void;
|
|
|
|
}
|
|
|
|
|
2024-05-16 16:05:39 +03:00
|
|
|
function TopicsDropdown({ activeTopic, onChangeTopic }: TopicsDropdownProps) {
|
2024-02-22 15:07:05 +03:00
|
|
|
const menu = useDropdown();
|
2025-01-14 21:58:16 +03:00
|
|
|
const noNavigation = useAppLayoutStore(state => state.noNavigation);
|
|
|
|
const treeHeight = useFitHeight('4rem + 2px');
|
2024-02-22 15:07:05 +03:00
|
|
|
|
2025-02-05 01:27:52 +03:00
|
|
|
function handleSelectTopic(topic: HelpTopic) {
|
|
|
|
menu.hide();
|
|
|
|
onChangeTopic(topic);
|
|
|
|
}
|
2024-02-22 15:07:05 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={menu.ref}
|
|
|
|
className={clsx(
|
2024-05-15 02:51:50 +03:00
|
|
|
'absolute left-0 w-[13.5rem]', // prettier: split-lines
|
2024-02-22 15:07:05 +03:00
|
|
|
'flex flex-col',
|
2024-06-02 23:41:46 +03:00
|
|
|
'z-modalTooltip',
|
2024-02-22 15:07:05 +03:00
|
|
|
'text-xs sm:text-sm',
|
|
|
|
'select-none',
|
|
|
|
{
|
|
|
|
'top-0': noNavigation,
|
|
|
|
'top-[3rem]': !noNavigation
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
noOutline
|
|
|
|
tabIndex={-1}
|
|
|
|
title='Список тем'
|
|
|
|
hideTitle={menu.isOpen}
|
2024-05-02 17:04:18 +03:00
|
|
|
icon={!menu.isOpen ? <IconMenuUnfold size='1.25rem' /> : <IconMenuFold size='1.25rem' />}
|
2024-12-12 13:19:12 +03:00
|
|
|
className={clsx('w-[3rem] h-7 rounded-none border-l-0', menu.isOpen && 'border-b-0')}
|
2024-02-22 15:07:05 +03:00
|
|
|
onClick={menu.toggle}
|
|
|
|
/>
|
2024-12-12 13:19:12 +03:00
|
|
|
<SelectTree
|
|
|
|
items={Object.values(HelpTopic).map(item => item as HelpTopic)}
|
|
|
|
value={activeTopic}
|
2025-02-04 20:35:55 +03:00
|
|
|
onChange={handleSelectTopic}
|
2024-12-12 13:19:12 +03:00
|
|
|
prefix={prefixes.topic_list}
|
|
|
|
getParent={item => topicParent.get(item) ?? item}
|
|
|
|
getLabel={labelHelpTopic}
|
|
|
|
getDescription={describeHelpTopic}
|
2024-05-15 02:51:50 +03:00
|
|
|
className={clsx(
|
2024-12-12 13:19:12 +03:00
|
|
|
'border-r border-t rounded-none', // prettier: split-lines
|
2024-05-15 02:51:50 +03:00
|
|
|
'cc-scroll-y',
|
2024-12-17 10:53:01 +03:00
|
|
|
'bg-prim-200'
|
2024-05-15 02:51:50 +03:00
|
|
|
)}
|
2024-12-12 13:19:12 +03:00
|
|
|
style={{
|
2025-01-14 21:58:16 +03:00
|
|
|
maxHeight: treeHeight,
|
2024-12-12 13:19:12 +03:00
|
|
|
transitionProperty: 'clip-path',
|
|
|
|
transitionDuration: `${PARAMETER.moveDuration}ms`,
|
|
|
|
clipPath: menu.isOpen ? 'inset(0% 0% 0% 0%)' : 'inset(0% 100% 0% 0%)'
|
|
|
|
}}
|
|
|
|
/>
|
2024-02-22 15:07:05 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-14 19:16:04 +03:00
|
|
|
export default TopicsDropdown;
|