2024-08-01 20:10:58 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2024-10-29 12:44:51 +03:00
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
2024-08-01 20:10:58 +03:00
|
|
|
|
import { IconOSS } from '@/components/Icons';
|
|
|
|
|
import { CProps } from '@/components/props';
|
2025-02-07 10:53:49 +03:00
|
|
|
|
import { MiniButton } from '@/components/ui/Control';
|
|
|
|
|
import { Dropdown, DropdownButton, useDropdown } from '@/components/ui/Dropdown';
|
|
|
|
|
import { Label } from '@/components/ui/Input';
|
2024-08-01 20:10:58 +03:00
|
|
|
|
import { ILibraryItemReference } from '@/models/library';
|
|
|
|
|
import { prefixes } from '@/utils/constants';
|
|
|
|
|
|
2024-10-29 12:44:51 +03:00
|
|
|
|
interface MiniSelectorOSSProps extends CProps.Styling {
|
2024-08-01 20:10:58 +03:00
|
|
|
|
items: ILibraryItemReference[];
|
|
|
|
|
onSelect: (event: CProps.EventMouse, newValue: ILibraryItemReference) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 12:44:51 +03:00
|
|
|
|
function MiniSelectorOSS({ items, onSelect, className, ...restProps }: MiniSelectorOSSProps) {
|
2024-08-01 20:10:58 +03:00
|
|
|
|
const ossMenu = useDropdown();
|
2024-08-05 23:53:07 +03:00
|
|
|
|
|
|
|
|
|
function onToggle(event: CProps.EventMouse) {
|
|
|
|
|
if (items.length > 1) {
|
|
|
|
|
ossMenu.toggle();
|
|
|
|
|
} else {
|
|
|
|
|
onSelect(event, items[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 20:10:58 +03:00
|
|
|
|
return (
|
2024-10-29 12:44:51 +03:00
|
|
|
|
<div ref={ossMenu.ref} className={clsx('flex items-center', className)} {...restProps}>
|
2024-08-01 20:10:58 +03:00
|
|
|
|
<MiniButton
|
|
|
|
|
icon={<IconOSS size='1.25rem' className='icon-primary' />}
|
2024-08-05 23:53:07 +03:00
|
|
|
|
title='Операционные схемы'
|
2024-08-01 20:10:58 +03:00
|
|
|
|
hideTitle={ossMenu.isOpen}
|
2024-08-05 23:53:07 +03:00
|
|
|
|
onClick={onToggle}
|
2024-08-01 20:10:58 +03:00
|
|
|
|
/>
|
2024-08-05 23:53:07 +03:00
|
|
|
|
{items.length > 1 ? (
|
|
|
|
|
<Dropdown isOpen={ossMenu.isOpen}>
|
|
|
|
|
<Label text='Список ОСС' className='border-b px-3 py-1' />
|
|
|
|
|
{items.map((reference, index) => (
|
|
|
|
|
<DropdownButton
|
|
|
|
|
className='min-w-[5rem]'
|
|
|
|
|
key={`${prefixes.oss_list}${index}`}
|
|
|
|
|
text={reference.alias}
|
|
|
|
|
onClick={event => onSelect(event, reference)}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
) : null}
|
2024-08-01 20:10:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MiniSelectorOSS;
|