ConceptPortal-public/rsconcept/frontend/src/components/select/SelectLocationHead.tsx
Ivan 507faf4689
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
R: Remove redundant useCallback
2025-02-05 01:27:52 +03:00

66 lines
2.1 KiB
TypeScript

'use client';
import clsx from 'clsx';
import { LocationIcon } from '@/components/DomainIcons';
import { CProps } from '@/components/props';
import Dropdown from '@/components/ui/Dropdown';
import DropdownButton from '@/components/ui/DropdownButton';
import SelectorButton from '@/components/ui/SelectorButton';
import useDropdown from '@/hooks/useDropdown';
import { LocationHead } from '@/models/library';
import { prefixes } from '@/utils/constants';
import { describeLocationHead, labelLocationHead } from '@/utils/labels';
interface SelectLocationHeadProps extends CProps.Styling {
value: LocationHead;
onChange: (newValue: LocationHead) => void;
excluded?: LocationHead[];
}
function SelectLocationHead({ value, excluded = [], onChange, className, ...restProps }: SelectLocationHeadProps) {
const menu = useDropdown();
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'
icon={<LocationIcon value={value} size='1rem' />}
text={labelLocationHead(value)}
onClick={menu.toggle}
/>
<Dropdown isOpen={menu.isOpen} className='z-modalTooltip'>
{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'>
<LocationIcon value={head} size='1rem' />
{labelLocationHead(head)}
</div>
</DropdownButton>
);
})}
</Dropdown>
</div>
);
}
export default SelectLocationHead;