avine-react-components
Advanced tools
Comparing version 0.1.18 to 0.1.19
@@ -201,5 +201,5 @@ 'use strict'; | ||
}; | ||
React.useEffect(() => { | ||
setTableData(data.slice(startIndex, endIndex)); | ||
}, [startIndex, endIndex]); | ||
React.useEffect(() => setTableColumns(columns), [columns]); | ||
React.useEffect(() => setTableData(data.slice(startIndex, endIndex)), [data]); | ||
React.useEffect(() => setTableData(data.slice(startIndex, endIndex)), [startIndex, endIndex]); | ||
return /*#__PURE__*/React__default.createElement("div", { | ||
@@ -206,0 +206,0 @@ className: "w-full" |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,a=require("react-icons/lu"),n=require("@headlessui/react");const l=(e,r)=>{const[a,n]=t.useState(1),l=t.useMemo(()=>{const t=Math.ceil(e/r);return t<a&&n(t),t},[e,r]),s=t.useMemo(()=>{if(e>0){if(l<=1)return[];if(l<=5)return Array.from({length:l}).map((e,t)=>t+1);if(a<5)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return 2;case 2:return 3;case 3:return 4;case 4:return 5;case 5:return"...";default:return l}});if(a>l-4)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return"...";case 2:return l-4;case 3:return l-3;case 4:return l-2;case 5:return l-1;default:return l}});if(a>=5&&a<=l-4)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return"...";case 2:return a-1;case 3:return a;case 4:return a+1;case 5:return"...";default:return l}})}return[]},[e,a,r]),{startIndex:o,endIndex:c}=t.useMemo(()=>{if(e>0){const e=(a-1)*r;return{startIndex:e,endIndex:e+r}}return[]},[e,a,r]);return{maxPages:l,currentPage:a,pages:s,startIndex:o,endIndex:c,handlePreviousPage:()=>{a>1&&n(e=>e-1)},handleNextPage:()=>{a<l&&n(e=>e+1)},handlePageChange:e=>{e>=1&&e<=l&&n(e)}}},s=(e,t,r)=>{const a=t.find(t=>t.key.toString()===e.toString());if(a){const n=a.sortableOrder===exports.ETableColumnOrder.Asc?exports.ETableColumnOrder.Desc:exports.ETableColumnOrder.Asc;let l=[];return n===exports.ETableColumnOrder.Asc&&(l=((e,t)=>{const r=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});return e.sort((e,a)=>r.compare(e[t.toString()],a[t.toString()]))})(r,e)),n===exports.ETableColumnOrder.Desc&&(l=(e=>e.reverse())(r)),{columns:t.map(t=>(t.key.toString()===e.toString()&&(t.sortableOrder=n),t.key.toString()!==e.toString()&&(t.sortableOrder=void 0),t)),data:l}}return{columns:t,data:r}},o=(e,t)=>e.reduce((e,t)=>e&&e[t]?e[t]:null,t);var c;(c=exports.ETableColumnOrder||(exports.ETableColumnOrder={})).Asc="asc",c.Desc="desc";const u=(e,t)=>e.formatter?e.formatter(t):o(e.key,t);exports.Table=e=>{let{isLoading:o,columns:c,data:i,emptyDataText:m,rowsPerPage:d=10,searchable:g=!1,fixed:p=!1,viewOnly:x=!1}=e;const[b,f]=t.useState(d),{pages:y,currentPage:h,handlePreviousPage:E,handleNextPage:v,handlePageChange:w,startIndex:N,endIndex:C}=l(i.length,b),[k,P]=t.useState(i.slice(N,C)),[O,S]=t.useState(c),I=m||"NĆ£o existem dados para exibiĆ§Ć£o";return t.useEffect(()=>{P(i.slice(N,C))},[N,C]),r.createElement("div",{className:"w-full"},!x&&r.createElement("div",{className:"w-full flex space-x-4 justify-end mb-4"},r.createElement("div",{className:"w-full flex space-x-4 justify-end"},g&&r.createElement("div",{className:"relative flex-1"},r.createElement(a.LuSearch,{className:"absolute top-2.5 left-2 text-gray-300",size:20}),r.createElement("input",{type:"text",id:"search-input",placeholder:"Pesquisar",className:"border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full py-2.5 pl-8 pr-4 outline-none"})),r.createElement("div",{className:"flex flex-nowrap items-center space-x-2 text-sm text-gray-400"},r.createElement("span",null,"Exibindo"),r.createElement("select",{value:b,onChange:e=>f(Number(e.target.value)),className:"bg-green-50 border border-green-300 text-green-700 font-medium text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block p-2"},r.createElement("option",{value:10,title:"10 itens por pĆ”gina"},"10"),r.createElement("option",{value:50,title:"50 itens por pĆ”gina"},"50"),r.createElement("option",{value:75,title:"75 itens por pĆ”gina"},"75"),r.createElement("option",{value:100,title:"100 itens por pĆ”gina"},"100")),r.createElement("span",null,"de ",i.length," resultados")),r.createElement(n.Menu,null,r.createElement(n.Menu.Button,{className:"px-2 -py-1 text-sm font-medium text-center flex items-center rounded-lg border border-transparent hover:border-gray-200"},r.createElement(a.LuMoreVertical,null)),r.createElement(n.Menu.Items,{className:"flex flex-col absolute right-0 top-12 bg-white shadow-md border rounded-xl p-4"},r.createElement(n.Menu.Item,null,r.createElement("button",{onClick:()=>{},type:"button",className:"px-3 py-2 text-sm font-medium text-center flex items-center"},r.createElement(a.LuDownload,{className:"mr-2"})," Download")))))),r.createElement("div",{className:"w-full overflow-x-auto"},r.createElement("table",{className:"w-full text-sm text-left text-gray-500 "+(p??"table-fixed")},r.createElement("thead",{className:"text-green-700 capitalize bg-green-50 whitespace-nowrap"},r.createElement("tr",null,O.map((e,t)=>!1!==e.visible?r.createElement("th",{key:t,scope:"col",className:"py-3 px-6 whitespace-nowrap",onClick:()=>(e=>{if(e.sortable){const{columns:t,data:r}=s(e.key,O,i);S(t),P(r.slice(N,C))}})(e)},r.createElement("div",{className:"flex items-center justify-between space-x-4"},r.createElement("span",null,e.name),e.sortable&&r.createElement("div",{className:"flex flex-col items-center justify-around"},r.createElement(a.LuChevronUp,{size:16,className:"asc"===e.sortableOrder?"text-green-700":"text-gray-300"}),r.createElement(a.LuChevronDown,{size:16,className:"desc"===e.sortableOrder?"-mt-1.5 text-green-700":"-mt-1.5 text-gray-300"})))):null))),r.createElement("tbody",{className:"overflow-y-auto"},!o&&k.map((e,t)=>r.createElement("tr",{key:t,className:"hover:bg-green-50 [&:not(:last-child)]:border-b"},O.map((t,a)=>!1!==t.visible?r.createElement("td",0===a?{scope:"row",key:a,className:u(t,e)?"py-4 px-6 whitespace-nowrap hover:bg-green-100":'py-4 px-6 whitespace-nowrap hover:bg-green-100 before:content-["(vazio)"] text-gray-300'}:{key:a,className:u(t,e)?"py-4 px-6 whitespace-nowrap hover:bg-green-100":'py-4 px-6 whitespace-nowrap hover:bg-green-100 before:content-["(vazio)"] text-gray-300'},r.createElement("span",null,u(t,e))):null))))),o&&r.createElement("div",{className:"w-full flex justify-center mt-4 text-sm"},r.createElement("p",{className:"text-gray-500"},"Carregando...")),!o&&i.length<=0&&r.createElement("div",{className:"w-full flex justify-center mt-4 text-sm"},r.createElement("p",{className:"text-gray-500"},I))),!o&&i.length>b&&r.createElement("nav",{className:"w-full flex justify-end mt-6"},r.createElement("ul",{className:"inline-flex -space-x-px"},r.createElement("li",null,r.createElement("a",{onClick:E,className:"select-none px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 cursor-pointer"},"Anterior")),y.map((e,t)=>r.createElement("li",{key:t},r.createElement("a",{onClick:"number"==typeof e?()=>w(e):void 0,className:e===h?"px-3 py-2 text-green-600 border border-gray-300 bg-green-50 hover:bg-green-100 hover:text-green-700 cursor-pointer select-none":"px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 cursor-pointer select-none"},e))),r.createElement("li",null,r.createElement("a",{onClick:v,className:"select-none px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 cursor-pointer"},"PrĆ³ximo")))))},exports.getNestedValues=o,exports.sortData=s,exports.usePagination=l; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,a=require("react-icons/lu"),n=require("@headlessui/react");const l=(e,r)=>{const[a,n]=t.useState(1),l=t.useMemo(()=>{const t=Math.ceil(e/r);return t<a&&n(t),t},[e,r]),s=t.useMemo(()=>{if(e>0){if(l<=1)return[];if(l<=5)return Array.from({length:l}).map((e,t)=>t+1);if(a<5)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return 2;case 2:return 3;case 3:return 4;case 4:return 5;case 5:return"...";default:return l}});if(a>l-4)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return"...";case 2:return l-4;case 3:return l-3;case 4:return l-2;case 5:return l-1;default:return l}});if(a>=5&&a<=l-4)return Array.from({length:7}).map((e,t)=>{switch(t){case 0:return 1;case 1:return"...";case 2:return a-1;case 3:return a;case 4:return a+1;case 5:return"...";default:return l}})}return[]},[e,a,r]),{startIndex:o,endIndex:c}=t.useMemo(()=>{if(e>0){const e=(a-1)*r;return{startIndex:e,endIndex:e+r}}return[]},[e,a,r]);return{maxPages:l,currentPage:a,pages:s,startIndex:o,endIndex:c,handlePreviousPage:()=>{a>1&&n(e=>e-1)},handleNextPage:()=>{a<l&&n(e=>e+1)},handlePageChange:e=>{e>=1&&e<=l&&n(e)}}},s=(e,t,r)=>{const a=t.find(t=>t.key.toString()===e.toString());if(a){const n=a.sortableOrder===exports.ETableColumnOrder.Asc?exports.ETableColumnOrder.Desc:exports.ETableColumnOrder.Asc;let l=[];return n===exports.ETableColumnOrder.Asc&&(l=((e,t)=>{const r=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});return e.sort((e,a)=>r.compare(e[t.toString()],a[t.toString()]))})(r,e)),n===exports.ETableColumnOrder.Desc&&(l=(e=>e.reverse())(r)),{columns:t.map(t=>(t.key.toString()===e.toString()&&(t.sortableOrder=n),t.key.toString()!==e.toString()&&(t.sortableOrder=void 0),t)),data:l}}return{columns:t,data:r}},o=(e,t)=>e.reduce((e,t)=>e&&e[t]?e[t]:null,t);var c;(c=exports.ETableColumnOrder||(exports.ETableColumnOrder={})).Asc="asc",c.Desc="desc";const u=(e,t)=>e.formatter?e.formatter(t):o(e.key,t);exports.Table=e=>{let{isLoading:o,columns:c,data:i,emptyDataText:m,rowsPerPage:d=10,searchable:g=!1,fixed:p=!1,viewOnly:x=!1}=e;const[f,b]=t.useState(d),{pages:y,currentPage:h,handlePreviousPage:E,handleNextPage:v,handlePageChange:w,startIndex:N,endIndex:C}=l(i.length,f),[k,P]=t.useState(i.slice(N,C)),[O,S]=t.useState(c),I=m||"NĆ£o existem dados para exibiĆ§Ć£o";return t.useEffect(()=>S(c),[c]),t.useEffect(()=>P(i.slice(N,C)),[i]),t.useEffect(()=>P(i.slice(N,C)),[N,C]),r.createElement("div",{className:"w-full"},!x&&r.createElement("div",{className:"w-full flex space-x-4 justify-end mb-4"},r.createElement("div",{className:"w-full flex space-x-4 justify-end"},g&&r.createElement("div",{className:"relative flex-1"},r.createElement(a.LuSearch,{className:"absolute top-2.5 left-2 text-gray-300",size:20}),r.createElement("input",{type:"text",id:"search-input",placeholder:"Pesquisar",className:"border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full py-2.5 pl-8 pr-4 outline-none"})),r.createElement("div",{className:"flex flex-nowrap items-center space-x-2 text-sm text-gray-400"},r.createElement("span",null,"Exibindo"),r.createElement("select",{value:f,onChange:e=>b(Number(e.target.value)),className:"bg-green-50 border border-green-300 text-green-700 font-medium text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block p-2"},r.createElement("option",{value:10,title:"10 itens por pĆ”gina"},"10"),r.createElement("option",{value:50,title:"50 itens por pĆ”gina"},"50"),r.createElement("option",{value:75,title:"75 itens por pĆ”gina"},"75"),r.createElement("option",{value:100,title:"100 itens por pĆ”gina"},"100")),r.createElement("span",null,"de ",i.length," resultados")),r.createElement(n.Menu,null,r.createElement(n.Menu.Button,{className:"px-2 -py-1 text-sm font-medium text-center flex items-center rounded-lg border border-transparent hover:border-gray-200"},r.createElement(a.LuMoreVertical,null)),r.createElement(n.Menu.Items,{className:"flex flex-col absolute right-0 top-12 bg-white shadow-md border rounded-xl p-4"},r.createElement(n.Menu.Item,null,r.createElement("button",{onClick:()=>{},type:"button",className:"px-3 py-2 text-sm font-medium text-center flex items-center"},r.createElement(a.LuDownload,{className:"mr-2"})," Download")))))),r.createElement("div",{className:"w-full overflow-x-auto"},r.createElement("table",{className:"w-full text-sm text-left text-gray-500 "+(p??"table-fixed")},r.createElement("thead",{className:"text-green-700 capitalize bg-green-50 whitespace-nowrap"},r.createElement("tr",null,O.map((e,t)=>!1!==e.visible?r.createElement("th",{key:t,scope:"col",className:"py-3 px-6 whitespace-nowrap",onClick:()=>(e=>{if(e.sortable){const{columns:t,data:r}=s(e.key,O,i);S(t),P(r.slice(N,C))}})(e)},r.createElement("div",{className:"flex items-center justify-between space-x-4"},r.createElement("span",null,e.name),e.sortable&&r.createElement("div",{className:"flex flex-col items-center justify-around"},r.createElement(a.LuChevronUp,{size:16,className:"asc"===e.sortableOrder?"text-green-700":"text-gray-300"}),r.createElement(a.LuChevronDown,{size:16,className:"desc"===e.sortableOrder?"-mt-1.5 text-green-700":"-mt-1.5 text-gray-300"})))):null))),r.createElement("tbody",{className:"overflow-y-auto"},!o&&k.map((e,t)=>r.createElement("tr",{key:t,className:"hover:bg-green-50 [&:not(:last-child)]:border-b"},O.map((t,a)=>!1!==t.visible?r.createElement("td",0===a?{scope:"row",key:a,className:u(t,e)?"py-4 px-6 whitespace-nowrap hover:bg-green-100":'py-4 px-6 whitespace-nowrap hover:bg-green-100 before:content-["(vazio)"] text-gray-300'}:{key:a,className:u(t,e)?"py-4 px-6 whitespace-nowrap hover:bg-green-100":'py-4 px-6 whitespace-nowrap hover:bg-green-100 before:content-["(vazio)"] text-gray-300'},r.createElement("span",null,u(t,e))):null))))),o&&r.createElement("div",{className:"w-full flex justify-center mt-4 text-sm"},r.createElement("p",{className:"text-gray-500"},"Carregando...")),!o&&i.length<=0&&r.createElement("div",{className:"w-full flex justify-center mt-4 text-sm"},r.createElement("p",{className:"text-gray-500"},I))),!o&&i.length>f&&r.createElement("nav",{className:"w-full flex justify-end mt-6"},r.createElement("ul",{className:"inline-flex -space-x-px"},r.createElement("li",null,r.createElement("a",{onClick:E,className:"select-none px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 cursor-pointer"},"Anterior")),y.map((e,t)=>r.createElement("li",{key:t},r.createElement("a",{onClick:"number"==typeof e?()=>w(e):void 0,className:e===h?"px-3 py-2 text-green-600 border border-gray-300 bg-green-50 hover:bg-green-100 hover:text-green-700 cursor-pointer select-none":"px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 cursor-pointer select-none"},e))),r.createElement("li",null,r.createElement("a",{onClick:v,className:"select-none px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 cursor-pointer"},"PrĆ³ximo")))))},exports.getNestedValues=o,exports.sortData=s,exports.usePagination=l; | ||
//# sourceMappingURL=avine-react-components.cjs.production.min.js.map |
@@ -195,5 +195,5 @@ import React, { useState, useMemo, useEffect } from 'react'; | ||
}; | ||
useEffect(() => { | ||
setTableData(data.slice(startIndex, endIndex)); | ||
}, [startIndex, endIndex]); | ||
useEffect(() => setTableColumns(columns), [columns]); | ||
useEffect(() => setTableData(data.slice(startIndex, endIndex)), [data]); | ||
useEffect(() => setTableData(data.slice(startIndex, endIndex)), [startIndex, endIndex]); | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -200,0 +200,0 @@ className: "w-full" |
{ | ||
"version": "0.1.18", | ||
"version": "0.1.19", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
216157