ConceptPortal-public/rsconcept/frontend/src/components/select/SelectLocationContext.tsx

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-06-26 19:00:29 +03:00
'use client';
import clsx from 'clsx';
import { useCallback } from 'react';
2025-01-28 23:23:42 +03:00
import { IconFolderTree } from '@/components/Icons';
import { CProps } from '@/components/props';
import Dropdown from '@/components/ui/Dropdown';
import MiniButton from '@/components/ui/MiniButton';
2024-06-26 19:00:29 +03:00
import useDropdown from '@/hooks/useDropdown';
import { prefixes } from '@/utils/constants';
import SelectLocation from './SelectLocation';
interface SelectLocationContextProps extends CProps.Styling {
value: string;
onChange: (newValue: string) => void;
2024-09-12 13:27:20 +03:00
title?: string;
2024-06-26 19:00:29 +03:00
stretchTop?: boolean;
}
2024-09-12 13:27:20 +03:00
function SelectLocationContext({
value,
title = 'Проводник...',
onChange,
className,
style
}: SelectLocationContextProps) {
2024-06-26 19:00:29 +03:00
const menu = useDropdown();
const handleClick = useCallback(
(event: CProps.EventMouse, newValue: string) => {
event.preventDefault();
event.stopPropagation();
menu.hide();
onChange(newValue);
},
[menu, onChange]
);
return (
<div ref={menu.ref} className='h-full text-right self-start mt-[-0.25rem] ml-[-1.5rem]'>
<MiniButton
2024-09-12 13:27:20 +03:00
title={title}
2024-06-26 19:00:29 +03:00
hideTitle={menu.isOpen}
icon={<IconFolderTree size='1.25rem' className='icon-green' />}
onClick={() => menu.toggle()}
/>
<Dropdown
isOpen={menu.isOpen}
2024-09-19 20:52:37 +03:00
className={clsx('w-[20rem] h-[12.5rem] z-modalTooltip mt-[-0.25rem]', className)}
2024-06-26 19:00:29 +03:00
style={style}
>
<SelectLocation
value={value}
prefix={prefixes.folders_list}
dense
onClick={(event, target) => handleClick(event, target.getPath())}
/>
</Dropdown>
</div>
);
}
export default SelectLocationContext;