ConceptPortal-public/rsconcept/frontend/src/features/library/components/SelectLocationContext.tsx

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-06-26 19:00:29 +03:00
'use client';
import clsx from 'clsx';
import { MiniButton } from '@/components/Control';
import { Dropdown, useDropdown } from '@/components/Dropdown';
2025-01-28 23:23:42 +03:00
import { IconFolderTree } from '@/components/Icons';
import { type EventMouse, type Styling } from '@/components/props';
2024-06-26 19:00:29 +03:00
import { prefixes } from '@/utils/constants';
2025-02-19 23:30:35 +03:00
import { SelectLocation } from './SelectLocation';
2024-06-26 19:00:29 +03:00
interface SelectLocationContextProps extends Styling {
2024-06-26 19:00:29 +03:00
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;
}
2025-02-12 15:13:37 +03:00
export function SelectLocationContext({
2024-09-12 13:27:20 +03:00
value,
title = 'Проводник...',
onChange,
className,
style
}: SelectLocationContextProps) {
2024-06-26 19:00:29 +03:00
const menu = useDropdown();
function handleClick(event: EventMouse, newValue: string) {
2025-02-05 01:27:52 +03:00
event.preventDefault();
event.stopPropagation();
menu.hide();
onChange(newValue);
}
2024-06-26 19:00:29 +03:00
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>
);
}