Portal/rsconcept/frontend/src/features/library/components/select-location-head.tsx

66 lines
1.8 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
2025-03-12 12:04:23 +03:00
import { SelectorButton } from '@/components/control';
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-03-12 11:54:32 +03:00
import { IconLocationHead } from './icon-location-head';
2025-02-26 00:16:22 +03:00
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 (
2025-03-09 21:57:21 +03:00
<div ref={menu.ref} className={clsx('text-right relative', className)} {...restProps}>
2024-06-07 20:17:03 +03:00
<SelectorButton
transparent
tabIndex={-1}
title={describeLocationHead(value)}
hideTitle={menu.isOpen}
className='h-full'
2025-02-26 00:16:22 +03:00
icon={<IconLocationHead value={value} size='1rem' />}
2024-06-07 20:17:03 +03:00
text={labelLocationHead(value)}
onClick={menu.toggle}
/>
2025-03-07 16:21:18 +03:00
<Dropdown isOpen={menu.isOpen} margin='mt-2'>
2024-06-07 20:17:03 +03:00
{Object.values(LocationHead)
.filter(head => !excluded.includes(head))
.map((head, index) => {
return (
<DropdownButton
key={`${prefixes.location_head_list}${index}`}
onClick={() => handleChange(head)}
title={describeLocationHead(head)}
2025-03-09 21:57:21 +03:00
icon={<IconLocationHead value={head} size='1rem' />}
text={labelLocationHead(head)}
/>
2024-06-07 20:17:03 +03:00
);
})}
</Dropdown>
</div>
);
}