navigationButtonGroup.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {LocationDescriptor} from 'history';
  2. import Button, {ButtonProps} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import {IconNext, IconPrevious} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. type Props = {
  7. /**
  8. * A set of LocationDescriptors that will be used in the buttons in the following order:
  9. * [Oldest, Older, Newer, Newest]
  10. */
  11. links: [LocationDescriptor, LocationDescriptor, LocationDescriptor, LocationDescriptor];
  12. className?: string;
  13. hasNext?: boolean;
  14. hasPrevious?: boolean;
  15. onNewerClick?: () => void;
  16. onNewestClick?: () => void;
  17. onOlderClick?: () => void;
  18. onOldestClick?: () => void;
  19. size?: ButtonProps['size'];
  20. };
  21. const NavigationButtonGroup = ({
  22. links,
  23. hasNext = false,
  24. hasPrevious = false,
  25. className,
  26. size,
  27. onOldestClick,
  28. onOlderClick,
  29. onNewerClick,
  30. onNewestClick,
  31. }: Props) => {
  32. return (
  33. <ButtonBar className={className} merged>
  34. <Button
  35. size={size}
  36. to={links[0]}
  37. disabled={!hasPrevious}
  38. aria-label={t('Oldest')}
  39. icon={<IconPrevious size="xs" />}
  40. onClick={onOldestClick}
  41. />
  42. <Button size={size} to={links[1]} disabled={!hasPrevious} onClick={onOlderClick}>
  43. {t('Older')}
  44. </Button>
  45. <Button size={size} to={links[2]} disabled={!hasNext} onClick={onNewerClick}>
  46. {t('Newer')}
  47. </Button>
  48. <Button
  49. size={size}
  50. to={links[3]}
  51. disabled={!hasNext}
  52. aria-label={t('Newest')}
  53. icon={<IconNext size="xs" />}
  54. onClick={onNewestClick}
  55. />
  56. </ButtonBar>
  57. );
  58. };
  59. export default NavigationButtonGroup;