ConceptPortal-public/rsconcept/frontend/src/pages/ManualsPage/TopicsDropdown.tsx

75 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-02-22 15:07:05 +03:00
'use client';
import clsx from 'clsx';
import { motion } from 'framer-motion';
import { useCallback } from 'react';
2024-05-02 17:04:18 +03:00
import { IconMenuFold, IconMenuUnfold } from '@/components/Icons';
2024-02-22 15:07:05 +03:00
import Button from '@/components/ui/Button';
2024-04-01 19:07:20 +03:00
import { useConceptOptions } from '@/context/OptionsContext';
2024-02-22 15:07:05 +03:00
import useDropdown from '@/hooks/useDropdown';
import { HelpTopic } from '@/models/miscellaneous';
import { animateSlideLeft } from '@/styling/animations';
2024-05-14 19:16:04 +03:00
import TopicsTree from './TopicsTree';
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();
2024-05-14 19:16:04 +03:00
const { noNavigation, calculateHeight } = useConceptOptions();
2024-02-22 15:07:05 +03:00
const selectTheme = useCallback(
(topic: HelpTopic) => {
menu.hide();
onChangeTopic(topic);
},
[onChangeTopic, menu]
);
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',
'z-modal-tooltip',
'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-05-14 19:16:04 +03:00
className='w-[3rem] h-7 rounded-none'
2024-02-22 15:07:05 +03:00
onClick={menu.toggle}
/>
<motion.div
2024-05-15 02:51:50 +03:00
className={clsx(
'border divide-y rounded-none', // prettier: split-lines
'cc-scroll-y',
'clr-controls'
)}
2024-05-14 19:16:04 +03:00
style={{ maxHeight: calculateHeight('4rem + 2px') }}
2024-02-22 15:07:05 +03:00
initial={false}
animate={menu.isOpen ? 'open' : 'closed'}
variants={animateSlideLeft}
>
2024-05-16 16:05:39 +03:00
<TopicsTree activeTopic={activeTopic} onChangeTopic={selectTheme} />
2024-02-22 15:07:05 +03:00
</motion.div>
</div>
);
}
2024-05-14 19:16:04 +03:00
export default TopicsDropdown;