-
Robert Dyer authoredRobert Dyer authored
ReportList.tsx 1.43 KiB
import React, { Fragment, type ComponentProps } from 'react';
import { useTranslation } from 'react-i18next';
import { theme } from '../../style/theme';
import { View } from '../common/View';
import { ItemHeader } from './ItemHeader';
export function ReportList<T extends { id: string; name: string }>({
items,
getItemProps,
highlightedIndex,
embedded,
}: {
items: T[];
getItemProps: (arg: { item: T }) => ComponentProps<typeof View>;
highlightedIndex: number;
embedded?: boolean;
}) {
const { t } = useTranslation();
return (
<View>
<View
style={{
overflow: 'auto',
padding: '5px 0',
...(!embedded && { maxHeight: 175 }),
}}
>
<Fragment>{ItemHeader({ title: t('Saved Reports') })}</Fragment>
{items.map((item, idx) => {
return [
<div
{...(getItemProps ? getItemProps({ item }) : null)}
key={item.id}
style={{
backgroundColor:
highlightedIndex === idx
? theme.menuAutoCompleteBackgroundHover
: 'transparent',
padding: 4,
paddingLeft: 20,
borderRadius: embedded ? 4 : 0,
}}
data-highlighted={highlightedIndex === idx || undefined}
>
{item.name}
</div>,
];
})}
</View>
</View>
);
}