getPagerLinks()

in src/pager/pager.tsx [167:220]


  getPagerLinks() {
    const {translate} = this.context;

    const prevLinkAvailable = this.props.currentPage !== 1;

    const nextLinkAvailable = this.props.openTotal || this.props.currentPage !== this.getTotalPages();

    const nextIcon = <Icon glyph={chevronRightIcon} key='icon' />;

    const prevIcon = <Icon glyph={chevronLeftIcon} key='icon' />;

    const prevText = this.props.translations?.previousPage ?? translate('previousPage');

    const nextText = this.props.translations?.nextPage ?? translate('nextPage');

    const nextLinkContent = [<span key='text'>{nextText}</span>, nextIcon];

    const prevLinkContent = [prevIcon, <span key='text'>{prevText}</span>];

    const prevLinkHref = this.generateHref(this.props.currentPage - 1);

    const nextLinkHref = this.generateHref(this.props.currentPage + 1);

    const disabledLinkClasses = classNames({
      [style.link]: true,
      [style.linkDisabled]: true,
    });

    return (
      <div className={style.links}>
        {prevLinkAvailable && (!this.props.loader || this.props.loaderNavigation) ? (
          <Link href={prevLinkHref} className={style.link} {...this.getClickProps(this.handlePrevClick)}>
            {prevLinkContent}
          </Link>
        ) : (
          <span className={disabledLinkClasses}>
            {prevIcon}
            <span key='text'>{prevText}</span>
          </span>
        )}

        {nextLinkAvailable && (!this.props.loader || this.props.loaderNavigation) ? (
          <Link href={nextLinkHref} className={style.link} {...this.getClickProps(this.handleNextClick)}>
            {nextLinkContent}
          </Link>
        ) : (
          <span className={disabledLinkClasses}>
            <span key='text'>{nextText}</span>
            {nextIcon}
          </span>
        )}
      </div>
    );
  }