carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 874 B
JavaScript
import{jsx as t}from"react/jsx-runtime";import{useRef as e,useCallback as n,useEffect as r}from"react";import{StyledPagerLink as i}from"../pager.style.js";import a from"../../../hooks/__internal__/useLocale/useLocale.js";const o=({type:o,currentPage:s,pageCount:l,hideDisabledElements:p,pageSize:u,onClick:d,onPagination:c})=>{const m=a(),g=e(null),x={first:{text:m.pager.first(),destination:1},last:{text:m.pager.last(),destination:l},next:{text:m.pager.next(),destination:s+1},previous:{text:m.pager.previous(),destination:s-1}},f=n((()=>1===s?"previous"===o||"first"===o:s===l&&("next"===o||"last"===o)),[l,s,o]);r((()=>{f()&&g.current&&g.current.blur()}),[f]);const{text:b}=x[o],h=p&&f();return t(i,{hideDisabledButtons:h,"data-element":`pager-link-${o}`,disabled:f(),onClick:t=>{null==d||d(t),null==c||c(x[o].destination,u,o)},ref:g,children:b})};export{o as default};