dateNavigator.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {type BaseButtonProps, Button} from 'sentry/components/button';
  2. import {IconChevron} from 'sentry/icons';
  3. import {t} from 'sentry/locale';
  4. import type {DateNavigation} from './hooks/useDateNavigation';
  5. interface Props extends BaseButtonProps {
  6. dateNavigation: DateNavigation;
  7. /**
  8. * Direction to navigate
  9. */
  10. direction: 'back' | 'forward';
  11. }
  12. export function DateNavigator({direction, dateNavigation, ...props}: Props) {
  13. const isForward = direction === 'forward';
  14. const title = isForward
  15. ? t('Next %s', dateNavigation.label)
  16. : t('Previous %s', dateNavigation.label);
  17. const action = isForward
  18. ? dateNavigation.navigateToNextPeriod
  19. : dateNavigation.navigateToPreviousPeriod;
  20. const disabled = isForward && dateNavigation.endIsNow;
  21. const iconDirection = isForward ? 'right' : 'left';
  22. return (
  23. <Button
  24. icon={<IconChevron direction={iconDirection} />}
  25. title={!disabled && title}
  26. aria-label={title}
  27. onClick={action}
  28. disabled={disabled}
  29. {...props}
  30. />
  31. );
  32. }