UNPKG

@lanaco/lnc-react-ui

Version:

React component library

13 lines (12 loc) 2.32 kB
"use strict";const n=require("react/jsx-runtime"),_=require("react"),h=require("./Button.cjs"),g=require("./IconButton.cjs"),A=require("./ButtonGroup.cjs"),q=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),L=require("./emotion-element-f0de968e.browser.esm-B7k6i6lC.cjs"),C=require("./useUpdateEffect-BtMgpgIV.cjs"),U=q.styled.div` display: inline-flex; flex-wrap: wrap; width: 100%; gap: 0.375rem; justify-content: ${u=>u.horizontalAlignment}; `,G=q.styled.div` & > .button-group-pagination-lnc { width: 100%; justify-content: ${u=>u.horizontalAlignment}; } `,O=u=>{const{icons:d={},borderRadius:c="regular",currentPage:b=1,buttonType:w="outline",currentPageButtonType:k="tinted",withFirstLast:x=!0,withButtonGroup:B=!0,disabledNext:T=!1,disabledPrevious:v=!1,disabledFirst:N=!1,disabledLast:S=!1,disabled:o=!1,totalNumberOfPages:f=1,pagesOffset:p=0,horizontalAlignment:m="left",onPageChange:z=()=>{},className:j="",style:y={},color:E="primary",size:F="small"}=u,r={theme:L.useTheme(),size:F,color:E,btnType:w},[t,l]=_.useState(b);C.useUpdateEffect(()=>{l(b)},[b]),C.useUpdateEffect(()=>{z(t)},[t]);const a=(i,e)=>{e=="next"&&t<f?l(t+1):e=="previous"&&t>1?l(t-1):e=="last"&&t!=f?l(f):e=="first"&&t!=1?l(1):isNaN(+e)||l(e)},R=()=>{let i=[];for(let e=t-p>0?t-p:1;e<t&&e>0;e++)i.push(n.jsx(h,{...r,borderRadius:c,onClick:s=>a(s,e),btnType:"basic",text:e.toString(),disabled:o},e));i.push(n.jsx(h,{...r,borderRadius:c,btnType:k,text:t.toString(),disabled:o},t));for(let e=t+1;e<=t+p&&e<=f;e++)i.push(n.jsx(h,{...r,borderRadius:c,onClick:s=>a(s,e),btnType:"basic",text:e.toString(),disabled:o},e));return i},P=(i=null)=>{var e={};return i&&(e.borderRadius=i),n.jsxs(n.Fragment,{children:[x&&n.jsx(g,{...r,icon:d.doubleLeft||"angle-double-left",disabled:N||o,onClick:s=>a(s,"first"),...e}),n.jsx(g,{...r,icon:d.left||"angle-left",disabled:v||o,onClick:s=>a(s,"previous"),...e}),R(),n.jsx(g,{...r,icon:d.right||"angle-right",disabled:T||o,onClick:s=>a(s,"next"),...e}),x&&n.jsx(g,{...r,icon:d.doubleRight||"angle-double-right",disabled:S||o,onClick:s=>a(s,"last"),...e})]})};return B?n.jsx(G,{horizontalAlignment:m,children:n.jsx(A,{className:"button-group-pagination-lnc "+j,style:y,borderRadius:c,children:P()})}):n.jsx(U,{horizontalAlignment:m,className:j,style:y,children:P(c)})};module.exports=O;