Portal/rsconcept/frontend/src/components/select/SelectLocationHead.tsx

70 lines
2.2 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 { useCallback } from 'react';
2025-01-28 23:23:03 +03:00
import { LocationIcon } from '@/components/DomainIcons';
import { CProps } from '@/components/props';
2024-06-07 20:17:03 +03:00
import Dropdown from '@/components/ui/Dropdown';
2025-01-28 23:23:03 +03:00
import DropdownButton from '@/components/ui/DropdownButton';
2024-06-07 20:17:03 +03:00
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 {
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[];
}
function SelectLocationHead({ value, excluded = [], onChange, className, ...restProps }: SelectLocationHeadProps) {
2024-06-07 20:17:03 +03:00
const menu = useDropdown();
const handleChange = useCallback(
(newValue: LocationHead) => {
menu.hide();
onChange(newValue);
},
[menu, onChange]
);
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}
/>
<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;