UNPKG

@undp/design-system-react

Version:

React based design system for UNDP

2 lines 3.14 kB
const e=require("./rolldown-runtime-mLOUI7ql.cjs"),t=require("./utils-Dd9-5CFr.cjs"),n=require("./chevron-left-5647beWo.cjs"),r=require("./chevron-right-Be2hAWX1.cjs"),i=require("./ellipsis-BsCXlwHt.cjs");let a=require("react");a=e.r(a,1);let o=require("react/jsx-runtime");function s({className:e,...n}){return(0,o.jsx)(`nav`,{...n,"aria-label":`pagination`,className:t.t(`mx-auto flex w-full justify-center`,e)})}s.displayName=`PaginationUnit`;var c=a.default.forwardRef(({className:e,...n},r)=>(0,o.jsx)(`ul`,{...n,ref:r,className:t.t(`flex list-none flex-row items-center gap-1`,e)}));c.displayName=`PaginationContent`;var l=a.default.forwardRef(({className:e,...n},r)=>(0,o.jsx)(`li`,{...n,ref:r,className:t.t(`mr-2 last:mr-0`,e)}));l.displayName=`PaginationItem`;function u({className:e,children:n,...r}){return(0,o.jsx)(`button`,{...r,type:`button`,className:t.t(`p-4 text-base text-content-primary`,e),children:n})}u.displayName=`PaginationLink`;function d({className:e,...r}){return(0,o.jsx)(u,{...r,"aria-label":`Go to previous page`,className:t.t(`rounded-full bg-surface p-2 hover:bg-surface-hover rtl:scale-x-[-1]`,e),children:(0,o.jsx)(n.t,{className:`h-6 w-6 stroke-foreground`})})}d.displayName=`PaginationPrevious`;function f({className:e,...n}){return(0,o.jsx)(u,{...n,"aria-label":`Go to next page`,className:t.t(`rounded-full bg-surface p-2 hover:bg-surface-hover rtl:scale-x-[-1]`,e),children:(0,o.jsx)(r.t,{className:`h-6 w-6 stroke-foreground`})})}f.displayName=`PaginationNext`;function p({className:e,...n}){return(0,o.jsxs)(`span`,{...n,"aria-hidden":!0,className:t.t(`flex h-9 w-9 items-center justify-center`,e),children:[(0,o.jsx)(i.t,{className:`h-4 w-4 text-content-primary`}),(0,o.jsx)(`span`,{className:`sr-only`,children:`More pages`})]})}p.displayName=`PaginationEllipsis`;var m=(e,t)=>{let n=[];return t<=7?Array.from({length:t},(e,t)=>t+1):(n.push(1),e<=3?n.push(2,3,4,`ellipsis`):e>=t-2?n.push(`ellipsis`,t-3,t-2,t-1):n.push(`ellipsis`,e-1,e,e+1,`ellipsis`),n.push(t),n)};function h(e){let{defaultPage:n=1,total:r,pageSize:i,onChange:h,className:g,classNames:_}=e,v=Math.ceil(r/i),[y,b]=(0,a.useState)(n),[x,S]=(0,a.useState)(m(n,v));return(0,a.useEffect)(()=>{S(m(y,v))},[y,v]),(0,o.jsx)(s,{className:t.t(`select-none`,g,_?.control),children:(0,o.jsxs)(c,{children:[(0,o.jsx)(l,{children:(0,o.jsx)(d,{onClick:()=>{y>1&&(h(y-1),b(y-1))},className:t.t(`cursor-pointer`,_?.navigation,y<=1&&`pointer-events-none cursor-not-allowed opacity-35`)})}),x.map(e=>(0,o.jsx)(l,{children:e===`ellipsis`?(0,o.jsx)(p,{className:_?.ellipsis}):(0,o.jsx)(u,{onClick:()=>{b(e),h(e)},className:t.t(`flex h-[32px] w-[32px] cursor-pointer items-center justify-center rounded-full hover:bg-surface-hover`,_?.list,e===y&&[`bg-secondary text-content-reverse hover:bg-secondary-hover`,_?.active]),children:e})},e)),(0,o.jsx)(l,{children:(0,o.jsx)(f,{onClick:()=>{y<v&&(h(y+1),b(y+1))},className:t.t(`cursor-pointer`,_?.navigation,y>=v&&`pointer-events-none cursor-not-allowed opacity-35`)})})]})})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return h}}); //# sourceMappingURL=Pagination-C7dHfirZ.cjs.map