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

69 lines
2.0 KiB
TypeScript
Raw Normal View History

'use client';
import clsx from 'clsx';
import { SelectorButton } from '@/components/Control';
2025-01-28 23:23:42 +03:00
import { LocationIcon } from '@/components/DomainIcons';
import { Dropdown, DropdownButton, useDropdown } from '@/components/Dropdown';
import { type Styling } from '@/components/props';
import { prefixes } from '@/utils/constants';
2025-02-11 20:56:24 +03:00
import { describeLocationHead, labelLocationHead } from '../labels';
import { LocationHead } from '../models/library';
interface SelectLocationHeadProps extends Styling {
value: LocationHead;
2024-06-21 19:27:36 +03:00
onChange: (newValue: LocationHead) => void;
excluded?: LocationHead[];
}
2025-02-12 15:13:37 +03:00
export function SelectLocationHead({
value,
excluded = [],
onChange,
className,
...restProps
}: SelectLocationHeadProps) {
const menu = useDropdown();
2025-02-05 01:27:52 +03:00
function handleChange(newValue: LocationHead) {
menu.hide();
onChange(newValue);
}
return (
<div ref={menu.ref} className={clsx('h-full text-right', className)} {...restProps}>
<SelectorButton
transparent
tabIndex={-1}
title={describeLocationHead(value)}
hideTitle={menu.isOpen}
className='h-full'
2024-06-04 11:19:21 +03:00
icon={<LocationIcon value={value} size='1rem' />}
text={labelLocationHead(value)}
onClick={menu.toggle}
/>
2025-02-25 13:24:19 +03:00
<Dropdown isOpen={menu.isOpen} className='z-modal-tooltip'>
{Object.values(LocationHead)
.filter(head => !excluded.includes(head))
.map((head, index) => {
return (
<DropdownButton
className='w-[10rem]'
key={`${prefixes.location_head_list}${index}`}
onClick={() => handleChange(head)}
title={describeLocationHead(head)}
>
<div className='inline-flex items-center gap-3'>
2024-06-04 11:19:21 +03:00
<LocationIcon value={head} size='1rem' />
{labelLocationHead(head)}
</div>
</DropdownButton>
);
})}
</Dropdown>
</div>
);
}