Portal/rsconcept/frontend/src/features/library/components/SelectLocationHead.tsx

69 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
import clsx from 'clsx';
2024-06-07 20:17:03 +03:00
import { SelectorButton } from '@/components/Control';
2025-01-28 23:23:03 +03:00
import { LocationIcon } from '@/components/DomainIcons';
import { Dropdown, DropdownButton, useDropdown } from '@/components/Dropdown';
2025-02-20 20:22:05 +03:00
import { type Styling } from '@/components/props';
2024-06-07 20:17:03 +03:00
import { prefixes } from '@/utils/constants';
2025-02-11 20:56:11 +03:00
import { describeLocationHead, labelLocationHead } from '../labels';
import { LocationHead } from '../models/library';
2025-02-20 20:22:05 +03:00
interface SelectLocationHeadProps extends Styling {
2024-06-07 20:17:03 +03:00
value: LocationHead;
2024-06-21 19:16:41 +03:00
onChange: (newValue: LocationHead) => void;
2024-06-07 20:17:03 +03:00
excluded?: LocationHead[];
}
2025-02-12 15:12:59 +03:00
export function SelectLocationHead({
value,
excluded = [],
onChange,
className,
...restProps
}: SelectLocationHeadProps) {
2024-06-07 20:17:03 +03:00
const menu = useDropdown();
2025-02-05 01:27:32 +03:00
function handleChange(newValue: LocationHead) {
menu.hide();
onChange(newValue);
}
2024-06-07 20:17:03 +03:00
return (
<div ref={menu.ref} className={clsx('h-full text-right', className)} {...restProps}>
2024-06-07 20:17:03 +03:00
<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}
/>
2025-02-25 13:24:06 +03:00
<Dropdown isOpen={menu.isOpen} className='z-modal-tooltip'>
2024-06-07 20:17:03 +03:00
{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>
);
}