ConceptPortal-public/rsconcept/frontend/src/features/library/components/pick-location/select-location-context.tsx
Ivan 25663322e3
Some checks failed
Backend CI / build (3.12) (push) Has been cancelled
Frontend CI / build (22.x) (push) Has been cancelled
Backend CI / notify-failure (push) Has been cancelled
Frontend CI / notify-failure (push) Has been cancelled
F: Replace clickOutside with onBlur trigger for dropdowns
2025-03-20 19:47:08 +03:00

61 lines
1.6 KiB
TypeScript

'use client';
import clsx from 'clsx';
import { MiniButton } from '@/components/control';
import { Dropdown, useDropdown } from '@/components/dropdown';
import { IconFolderTree } from '@/components/icons';
import { type Styling } from '@/components/props';
import { prefixes } from '@/utils/constants';
import { SelectLocation } from '../select-location';
interface SelectLocationContextProps extends Styling {
value: string;
onChange: (newValue: string) => void;
title?: string;
dropdownHeight?: string;
}
export function SelectLocationContext({
value,
title = 'Проводник...',
onChange,
className,
dropdownHeight = 'h-50',
...restProps
}: SelectLocationContextProps) {
const menu = useDropdown();
function handleClick(event: React.MouseEvent<Element>, newValue: string) {
event.preventDefault();
event.stopPropagation();
menu.hide();
onChange(newValue);
}
return (
<div
ref={menu.ref} //
onBlur={menu.handleBlur}
className={clsx('relative text-right self-start', className)}
{...restProps}
>
<MiniButton
title={title}
hideTitle={menu.isOpen}
icon={<IconFolderTree size='1.25rem' className='icon-green' />}
onClick={() => menu.toggle()}
/>
<Dropdown isOpen={menu.isOpen} className={clsx('w-80 z-tooltip', dropdownHeight)}>
<SelectLocation
value={value}
prefix={prefixes.folders_list}
dense
onClick={(event, target) => handleClick(event, target.getPath())}
/>
</Dropdown>
</div>
);
}