The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/components/dashboards/PeriodSelector.tsx

32 lines
926 B

import { Select } from '@rocket.chat/fuselage';
import type { ReactElement } from 'react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { Period } from './periods';
import { getPeriod } from './periods';
type PeriodSelectorProps<TPeriod extends Period['key']> = {
periods: TPeriod[];
value: TPeriod;
name?: string;
onChange: (value: TPeriod) => void;
};
const PeriodSelector = <TPeriod extends Period['key']>({ periods, value, name, onChange }: PeriodSelectorProps<TPeriod>): ReactElement => {
const { t } = useTranslation();
const options = useMemo<[string, string][]>(() => periods.map((period) => [period, t(...getPeriod(period).label)]), [periods, t]);
return (
<Select
name={name}
options={options}
value={value}
onChange={(value): void => onChange(value as TPeriod)}
aria-label={t('Select_period')}
/>
);
};
export default PeriodSelector;