bitys-react-components 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,54 @@
1
- # react-components
2
- Componentes e dependências para ReactJS
1
+ # Bitys React Components
2
+
3
+ Biblioteca de componentes reutilizáveis para React, com suporte a Bootstrap 5 e styled-components.
4
+
5
+ ---
6
+
7
+ ## Instalação
8
+
9
+ ```bash
10
+ npm install bitys-react-components
11
+ ```
12
+
13
+ **Peer dependencies:** `react`, `react-dom`, `bootstrap`, `reactstrap`, `react-icons`, `styled-components`
14
+
15
+ ---
16
+
17
+ ## Componentes
18
+
19
+ ### CardFilter
20
+
21
+ Card colapsável para agrupar filtros de busca. Inclui botão "Buscar" e toggle para expandir/recolher o conteúdo. Ideal para telas de listagem com critérios de filtro.
22
+
23
+ ### InputCheck
24
+
25
+ Checkbox estilizado com label opcional. Aceita `value`, `onChange` e demais props nativas de input, com suporte a customização via estilos no container e no label.
26
+
27
+ ### DataGridView
28
+
29
+ Tabela de dados completa com ordenação por coluna, paginação (básica ou avançada), busca em tempo real e exportação (Excel, CSV, PDF). Configurável por `config` (idioma, botões, tamanho de página, etc.) e colunas definidas via `columns` + `data`.
30
+
31
+ ---
32
+
33
+ ## Uso básico
34
+
35
+ ```js
36
+ import { CardFilter, InputCheck, DataGridView } from 'bitys-react-components';
37
+
38
+ // CardFilter: envolva seus campos de filtro
39
+ <CardFilter onChange={handleSearch}>
40
+ <input type="text" placeholder="Nome" />
41
+ </CardFilter>
42
+
43
+ // InputCheck: checkbox com label
44
+ <InputCheck label="Aceito os termos" value={checked} onChange={handleChange} />
45
+
46
+ // DataGridView: tabela com columns e data
47
+ <DataGridView columns={columns} data={rows} config={config} onChange={handleChange} />
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Licença
53
+
54
+ MIT
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = ADPagination;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ function ADPagination(props) {
11
+ var size = props.pages;
12
+ var page = props.page_number;
13
+ var step = 2;
14
+ var tags = [];
15
+ var pagination = props.language.pagination;
16
+ var Item = function Item(props) {
17
+ var className = props.className || "";
18
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
19
+ className: "page-item " + className,
20
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
21
+ href: "#",
22
+ className: "page-link",
23
+ tabIndex: "-1",
24
+ onClick: function onClick(e) {
25
+ e.preventDefault();
26
+ props.onClick(e);
27
+ },
28
+ children: props.children
29
+ })
30
+ });
31
+ };
32
+ var Add = function Add(s, f) {
33
+ var _loop = function _loop(i) {
34
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
35
+ className: page == i ? "active" : "",
36
+ onClick: function onClick(e) {
37
+ return props.goToPage(e, i);
38
+ },
39
+ children: i
40
+ }, i));
41
+ };
42
+ for (var i = s; i < f; i++) {
43
+ _loop(i);
44
+ }
45
+ };
46
+ var Last = function Last() {
47
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
48
+ children: "..."
49
+ }, "l..."));
50
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
51
+ className: page == size ? "active" : "",
52
+ onClick: function onClick(e) {
53
+ return props.goToPage(e, size);
54
+ },
55
+ children: size
56
+ }, size));
57
+ };
58
+ var First = function First() {
59
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
60
+ className: page == 1 ? "active" : "",
61
+ onClick: function onClick(e) {
62
+ return props.goToPage(e, 1);
63
+ },
64
+ children: "1"
65
+ }, "1"));
66
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
67
+ children: "..."
68
+ }, "f..."));
69
+ };
70
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
71
+ className: props.isFirst ? "disabled " : "",
72
+ onClick: props.previousPage,
73
+ children: pagination.previous ? pagination.previous : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
74
+ children: "\u25C4"
75
+ })
76
+ }, "p0"));
77
+ if (size < step * 2 + 6) {
78
+ Add(1, size + 1);
79
+ } else if (page < step * 2 + 1) {
80
+ Add(1, step * 2 + 4);
81
+ Last();
82
+ } else if (page > size - step * 2) {
83
+ First();
84
+ Add(size - step * 2 - 2, size + 1);
85
+ } else {
86
+ First();
87
+ Add(page - step, page + step + 1);
88
+ Last();
89
+ }
90
+ tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
91
+ className: props.isLast ? "disabled " : "",
92
+ onClick: props.nextPage,
93
+ children: pagination.next ? pagination.next : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
94
+ children: "\u25BA"
95
+ })
96
+ }, "n0"));
97
+ return tags;
98
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = InitialPagination;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
12
+ function InitialPagination(props) {
13
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
14
+ children: [props.config.show_first ? /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
15
+ className: (props.isFirst ? "disabled " : "") + "page-item",
16
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
17
+ href: "#",
18
+ className: "page-link",
19
+ tabIndex: "-1",
20
+ onClick: props.firstPage,
21
+ children: props.config.language.pagination.first
22
+ })
23
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
24
+ className: (props.isFirst ? "disabled " : "") + "page-item",
25
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
26
+ href: "#",
27
+ className: "page-link",
28
+ tabIndex: "-1",
29
+ onClick: props.previousPage,
30
+ children: props.config.language.pagination.previous
31
+ })
32
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
33
+ className: "page-item",
34
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
35
+ className: "page-link",
36
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
37
+ style: {
38
+ border: 'none',
39
+ padding: '0',
40
+ maxWidth: '30px',
41
+ textAlign: 'center',
42
+ display: 'inline-block'
43
+ },
44
+ type: "text",
45
+ value: props.is_temp_page ? props.temp_page_number : props.page_number,
46
+ onChange: function onChange(e) {
47
+ return props.onPageChange(e, true);
48
+ },
49
+ onBlur: props.onPageBlur,
50
+ onKeyDown: props.onPageChange
51
+ })
52
+ })
53
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
54
+ className: (props.isLast ? "disabled " : "") + "page-item",
55
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
56
+ href: "#",
57
+ className: "page-link",
58
+ onClick: props.nextPage,
59
+ children: props.config.language.pagination.next
60
+ })
61
+ }), props.config.show_last ? /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
62
+ className: (props.isLast ? "disabled " : "") + "page-item",
63
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
64
+ href: "#",
65
+ className: "page-link",
66
+ tabIndex: "-1",
67
+ onClick: props.lastPage,
68
+ children: props.config.language.pagination.last
69
+ })
70
+ }) : null]
71
+ });
72
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = TableFooter;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _Pagination = _interopRequireDefault(require("./Pagination"));
9
+ var _ADPagination = _interopRequireDefault(require("./ADPagination"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ function TableFooter(props) {
13
+ if (props.config.show_info == true || props.config.show_pagination == true) {
14
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
15
+ className: "row table-foot asrt-table-foot",
16
+ id: props.id ? props.id + "-table-foot" : "",
17
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
18
+ className: "col-md-6",
19
+ children: props.config.show_info ? props.paginationInfo : null
20
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
21
+ className: "col-md-6 pull-right text-right",
22
+ children: props.config.show_pagination ? /*#__PURE__*/(0, _jsxRuntime.jsx)("nav", {
23
+ "aria-label": "Page navigation",
24
+ className: "pull-right",
25
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
26
+ className: "pagination justify-content-end asrt-pagination",
27
+ children: props.config.pagination == "basic" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Pagination["default"], {
28
+ config: props.config,
29
+ isFirst: props.isFirst,
30
+ isLast: props.isLast,
31
+ pages: props.pages,
32
+ page_number: props.page_number,
33
+ is_temp_page: props.is_temp_page,
34
+ temp_page_number: props.temp_page_number,
35
+ previousPage: props.previousPage,
36
+ firstPage: props.firstPage,
37
+ nextPage: props.nextPage,
38
+ lastPage: props.lastPage,
39
+ goToPage: props.goToPage,
40
+ onPageChange: props.onPageChange,
41
+ onPageBlur: props.onPageBlur
42
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ADPagination["default"], {
43
+ language: props.config.language,
44
+ isFirst: props.isFirst,
45
+ isLast: props.isLast,
46
+ pages: props.pages,
47
+ page_number: props.page_number,
48
+ previousPage: props.previousPage,
49
+ nextPage: props.nextPage,
50
+ goToPage: props.goToPage
51
+ })
52
+ })
53
+ }) : null
54
+ })]
55
+ });
56
+ } else {
57
+ return null;
58
+ }
59
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = TableHeader;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _includes = _interopRequireDefault(require("lodash/includes"));
9
+ var _style = _interopRequireDefault(require("../style"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ function TableHeader(props) {
13
+ if (props.config.show_length_menu == true || props.config.show_filter == true || props.config.button.excel == true || props.config.button.csv == true || props.config.button.print == true) {
14
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
15
+ className: "row table-head asrt-table-head",
16
+ id: props.id ? props.id + "-table-head" : "",
17
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
18
+ className: "col-md-6",
19
+ children: props.config.show_length_menu ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
20
+ className: "input-group asrt-page-length",
21
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
22
+ className: "input-group-addon input-group-prepend",
23
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
24
+ className: "input-group-text",
25
+ style: _style["default"].table_size,
26
+ children: props.lengthMenuText[0] ? props.lengthMenuText[0] : ''
27
+ })
28
+ }), (0, _includes["default"])(props.config.language.length_menu, '_MENU_') ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
29
+ type: "text",
30
+ className: "form-control",
31
+ style: _style["default"].table_size_dropdown,
32
+ onChange: props.changePageSize,
33
+ children: [props.config.length_menu.map(function (value, key) {
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
35
+ children: value
36
+ }, value);
37
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
38
+ value: props.recordLength,
39
+ children: "All"
40
+ })]
41
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
42
+ className: "input-group-addon input-group-prepend",
43
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
44
+ className: "input-group-text",
45
+ style: _style["default"].table_size,
46
+ children: props.lengthMenuText[1] ? props.lengthMenuText[1] : ''
47
+ })
48
+ })]
49
+ }) : null
50
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
51
+ className: "col-md-6 float-right text-right",
52
+ children: [props.config.show_filter ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
53
+ className: "table_filter",
54
+ style: _style["default"].table_filter,
55
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
56
+ type: "search",
57
+ className: "form-control",
58
+ placeholder: props.config.language.filter,
59
+ onChange: props.filterRecords
60
+ })
61
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
62
+ className: "table_tools",
63
+ style: _style["default"].table_tool,
64
+ children: [props.config.button.excel ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
65
+ className: "btn btn-primary buttons-excel",
66
+ tabIndex: "0",
67
+ "aria-controls": "configuration_tbl",
68
+ title: "Export to Excel",
69
+ style: _style["default"].table_tool_btn,
70
+ onClick: props.exportToExcel,
71
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
72
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
73
+ className: "fa fa-file-excel-o",
74
+ "aria-hidden": "true"
75
+ })
76
+ })
77
+ }) : null, props.config.button.csv ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
78
+ className: "btn btn-primary buttons-csv",
79
+ tabIndex: "0",
80
+ "aria-controls": "configuration_tbl",
81
+ title: "Export to CSV",
82
+ style: _style["default"].table_tool_btn,
83
+ onClick: props.exportToCSV,
84
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
85
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
86
+ className: "fa fa-file-text-o",
87
+ "aria-hidden": "true"
88
+ })
89
+ })
90
+ }) : null, props.config.button.print ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
91
+ className: "btn btn-primary buttons-pdf",
92
+ tabIndex: "0",
93
+ "aria-controls": "configuration_tbl",
94
+ title: "Export to PDF",
95
+ style: _style["default"].table_tool_btn,
96
+ onClick: props.exportToPDF,
97
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
98
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
99
+ className: "glyphicon glyphicon-print fa fa-print",
100
+ "aria-hidden": "true"
101
+ })
102
+ })
103
+ }) : null, props.config.button.extra == true ? props.extraButtons.map(function (elem, index) {
104
+ elem.clickCount = 0;
105
+ elem.singleClickTimer = '';
106
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
107
+ className: elem.className ? elem.className : "btn btn-primary buttons-pdf",
108
+ tabIndex: "0",
109
+ "aria-controls": "configuration_tbl",
110
+ title: elem.title ? elem.title : "Export to PDF",
111
+ style: _style["default"].table_tool_btn,
112
+ onClick: function onClick(event) {
113
+ elem.onClick(event);
114
+ },
115
+ children: elem.children
116
+ }, index);
117
+ }) : null]
118
+ })]
119
+ })]
120
+ });
121
+ } else {
122
+ return null;
123
+ }
124
+ }
@@ -0,0 +1,772 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _server = _interopRequireDefault(require("react-dom/server"));
9
+ var _lodash = _interopRequireDefault(require("lodash"));
10
+ require("./assets/css/style.css");
11
+ var _TableHeader = _interopRequireDefault(require("./components/TableHeader"));
12
+ var _TableFooter = _interopRequireDefault(require("./components/TableFooter"));
13
+ var _InputCheck = _interopRequireDefault(require("../InputCheck"));
14
+ var _style2 = _interopRequireDefault(require("./style"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
18
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
19
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
20
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
21
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
22
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
23
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
24
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
25
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
27
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
29
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
30
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
31
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
32
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
33
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
34
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
35
+ function isCheckBoxColumn(column) {
36
+ return column.key === 'checkBox' || column.type === 'checkBox';
37
+ }
38
+ var ReactDatatable = /*#__PURE__*/function (_Component) {
39
+ function ReactDatatable(props) {
40
+ var _this;
41
+ _classCallCheck(this, ReactDatatable);
42
+ _this = _callSuper(this, ReactDatatable, [props]);
43
+ _this.exportExcelRef = /*#__PURE__*/_react["default"].createRef();
44
+ _this.sortColumn = _this.sortColumn.bind(_this);
45
+ _this.numPages = _this.numPages.bind(_this);
46
+ _this.exportToExcel = _this.exportToExcel.bind(_this);
47
+ _this.exportToPDF = _this.exportToPDF.bind(_this);
48
+ _this.exportToCSV = _this.exportToCSV.bind(_this);
49
+ _this.onChange = _this.onChange.bind(_this);
50
+ _this.filterRecords = _this.filterRecords.bind(_this);
51
+ _this.filterData = _this.filterData.bind(_this);
52
+ _this.sortRecords = _this.sortRecords.bind(_this);
53
+ _this.config = {
54
+ button: {
55
+ excel: props.config && props.config.button && props.config.button.excel ? props.config.button.excel : false,
56
+ print: props.config && props.config.button && props.config.button.print ? props.config.button.print : false,
57
+ csv: props.config && props.config.button && props.config.button.csv ? props.config.button.csv : false,
58
+ extra: props.config && props.config.button && props.config.button.extra ? props.config.button.extra : false
59
+ },
60
+ filename: props.config && props.config.filename ? props.config.filename : 'table',
61
+ key_column: props.config && props.config.key_column ? props.config.key_column : 'id',
62
+ language: {
63
+ length_menu: props.config && props.config.language && props.config.language.length_menu ? props.config.language.length_menu : 'Show _MENU_ records per page',
64
+ filter: props.config && props.config.language && props.config.language.filter ? props.config.language.filter : 'Search in records...',
65
+ info: props.config && props.config.language && props.config.language.info ? props.config.language.info : 'Showing _START_ to _END_ of _TOTAL_ entries',
66
+ pagination: {
67
+ first: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.first ? props.config.language.pagination.first : 'First',
68
+ previous: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.previous ? props.config.language.pagination.previous : 'Previous',
69
+ next: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.next ? props.config.language.pagination.next : 'Next',
70
+ last: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.last ? props.config.language.pagination.last : 'Last'
71
+ },
72
+ no_data_text: props.config && props.config.language && props.config.language.no_data_text ? props.config.language.no_data_text : 'No rows found',
73
+ loading_text: props.config && props.config.language && props.config.language.loading_text ? props.config.language.loading_text : 'Loading...'
74
+ },
75
+ length_menu: props.config && props.config.length_menu ? props.config.length_menu : [10, 25, 50, 75, 100],
76
+ show_length_menu: props.config.show_length_menu != undefined ? props.config.show_length_menu : true,
77
+ show_filter: props.config.show_filter != undefined ? props.config.show_filter : true,
78
+ show_pagination: props.config.show_pagination != undefined ? props.config.show_pagination : true,
79
+ show_info: props.config.show_info != undefined ? props.config.show_info : true,
80
+ show_first: props.config.show_first != undefined ? props.config.show_first : true,
81
+ show_last: props.config.show_last != undefined ? props.config.show_last : true,
82
+ pagination: props.config.pagination ? props.config.pagination : 'basic'
83
+ };
84
+ _this.state = {
85
+ is_temp_page: false,
86
+ filter_value: '',
87
+ page_size: props.config.page_size ? props.config.page_size : 10,
88
+ page_number: 1,
89
+ sort: props.config && props.config.sort ? props.config.sort : false,
90
+ lastCheckBoxRowIndex: null
91
+ };
92
+ return _this;
93
+ }
94
+ _inherits(ReactDatatable, _Component);
95
+ return _createClass(ReactDatatable, [{
96
+ key: "handleCheckBoxRowChange",
97
+ value: function handleCheckBoxRowChange(record, checked, payload, rowIndex) {
98
+ var _this2 = this;
99
+ var ev = payload && (payload.event || payload.nativeEvent);
100
+ var shiftPressed = ev && ev.shiftKey;
101
+ var lastCheckBoxRowIndex = this.state.lastCheckBoxRowIndex;
102
+ var records = this.props.records;
103
+ if (shiftPressed && lastCheckBoxRowIndex !== null && records.length > 0) {
104
+ var start = Math.min(rowIndex, lastCheckBoxRowIndex);
105
+ var end = Math.max(rowIndex, lastCheckBoxRowIndex);
106
+ var recordsInRange = records.slice(start, end + 1);
107
+ recordsInRange.forEach(function (r) {
108
+ return _this2.props.onCheckRowChange(r[_this2.config.key_column], checked);
109
+ });
110
+ } else {
111
+ this.props.onCheckRowChange(record[this.config.key_column], checked);
112
+ this.setState({
113
+ lastCheckBoxRowIndex: rowIndex
114
+ });
115
+ }
116
+ }
117
+ }, {
118
+ key: "filterRecords",
119
+ value: function filterRecords(e) {
120
+ var _this3 = this;
121
+ var value = e.target.value;
122
+ this.setState({
123
+ page_number: 1,
124
+ filter_value: value
125
+ }, function () {
126
+ _this3.onChange();
127
+ });
128
+ }
129
+ }, {
130
+ key: "changePageSize",
131
+ value: function changePageSize(e) {
132
+ var _this4 = this;
133
+ var value = e.target.value;
134
+ this.setState({
135
+ page_size: value
136
+ }, function () {
137
+ _this4.onChange();
138
+ });
139
+ }
140
+ }, {
141
+ key: "sortColumn",
142
+ value: function sortColumn(event, column, sortOrder) {
143
+ var _this5 = this;
144
+ if (!column.sortable) return false;
145
+ var newSortOrder = sortOrder == 'asc' ? 'desc' : 'asc';
146
+ this.setState({
147
+ sort: {
148
+ column: column.key,
149
+ order: newSortOrder
150
+ }
151
+ }, function () {
152
+ _this5.onChange();
153
+ });
154
+ }
155
+ }, {
156
+ key: "paginate",
157
+ value: function paginate(records) {
158
+ var page_size = this.state.page_size;
159
+ var page_number = this.state.page_number;
160
+ --page_number; // because pages logically start with 1, but technically with 0
161
+ return records.slice(page_number * page_size, (page_number + 1) * page_size);
162
+ }
163
+ }, {
164
+ key: "numPages",
165
+ value: function numPages(totalRecord) {
166
+ return Math.ceil(totalRecord / this.state.page_size);
167
+ }
168
+ }, {
169
+ key: "isLast",
170
+ value: function isLast() {
171
+ // because for empty records page_number will still be 1
172
+ if (this.pages == 0) {
173
+ return true;
174
+ }
175
+ if (this.state.page_number == this.pages) {
176
+ return true;
177
+ } else {
178
+ return false;
179
+ }
180
+ }
181
+ }, {
182
+ key: "isFirst",
183
+ value: function isFirst() {
184
+ if (this.state.page_number == 1) {
185
+ return true;
186
+ } else {
187
+ return false;
188
+ }
189
+ }
190
+ }, {
191
+ key: "goToPage",
192
+ value: function goToPage(e, pageNumber) {
193
+ var _this6 = this;
194
+ e.preventDefault();
195
+ if (this.state.page_number == pageNumber) {
196
+ return;
197
+ }
198
+ var pageState = {
199
+ previous_page: this.state.page_number,
200
+ current_page: pageNumber
201
+ };
202
+ this.setState({
203
+ is_temp_page: false,
204
+ page_number: pageNumber
205
+ }, function () {
206
+ _this6.props.onPageChange(pageState);
207
+ _this6.onChange();
208
+ });
209
+ }
210
+ }, {
211
+ key: "firstPage",
212
+ value: function firstPage(e) {
213
+ e.preventDefault();
214
+ if (this.isFirst()) return;
215
+ this.goToPage(e, 1);
216
+ }
217
+ }, {
218
+ key: "lastPage",
219
+ value: function lastPage(e) {
220
+ e.preventDefault();
221
+ if (this.isLast()) return;
222
+ this.goToPage(e, this.pages);
223
+ }
224
+ }, {
225
+ key: "previousPage",
226
+ value: function previousPage(e) {
227
+ e.preventDefault();
228
+ if (this.isFirst()) return false;
229
+ this.goToPage(e, this.state.page_number - 1);
230
+ }
231
+ }, {
232
+ key: "nextPage",
233
+ value: function nextPage(e) {
234
+ e.preventDefault();
235
+ if (this.isLast()) return;
236
+ this.goToPage(e, parseInt(this.state.page_number) + 1);
237
+ }
238
+ }, {
239
+ key: "onPageChange",
240
+ value: function onPageChange(e) {
241
+ var isInputChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
242
+ if (isInputChange) {
243
+ this.setState({
244
+ is_temp_page: true,
245
+ temp_page_number: e.target.value
246
+ });
247
+ } else {
248
+ if (e.key === 'Enter') {
249
+ var pageNumber = e.target.value;
250
+ this.goToPage(e, pageNumber);
251
+ }
252
+ }
253
+ }
254
+ }, {
255
+ key: "onPageBlur",
256
+ value: function onPageBlur(e) {
257
+ var pageNumber = e.target.value;
258
+ this.goToPage(e, pageNumber);
259
+ }
260
+ }, {
261
+ key: "strip",
262
+ value: function strip(html) {
263
+ var doc = new DOMParser().parseFromString(html, 'text/html');
264
+ return doc.body.textContent || '';
265
+ }
266
+ }, {
267
+ key: "getExportHtml",
268
+ value: function getExportHtml() {
269
+ var tableHtml = '<table>';
270
+ tableHtml += '<thead>';
271
+ tableHtml += '<tr>';
272
+ var _iterator = _createForOfIteratorHelper(this.props.columns),
273
+ _step;
274
+ try {
275
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
276
+ var _column = _step.value;
277
+ if (isCheckBoxColumn(_column)) continue;
278
+ var headerText = typeof _column.text === 'string' ? _column.text : _column.key || '';
279
+ tableHtml += '<th>' + headerText + '</th>';
280
+ }
281
+ } catch (err) {
282
+ _iterator.e(err);
283
+ } finally {
284
+ _iterator.f();
285
+ }
286
+ tableHtml += '</tr>';
287
+ tableHtml += '</thead>';
288
+ tableHtml += '<tbody>';
289
+
290
+ // Filter records before export
291
+ var filterRecords = this.props.records;
292
+ if (this.props.dynamic === false) {
293
+ var records = this.sortRecords(),
294
+ filterValue = this.state.filter_value;
295
+ filterRecords = records;
296
+ if (filterValue) {
297
+ filterRecords = this.filterData(records);
298
+ }
299
+ }
300
+ for (var i in filterRecords) {
301
+ var record = filterRecords[i];
302
+ tableHtml += '<tr>';
303
+ var _iterator2 = _createForOfIteratorHelper(this.props.columns),
304
+ _step2;
305
+ try {
306
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
307
+ var column = _step2.value;
308
+ if (isCheckBoxColumn(column)) continue;
309
+ if (column.cell && typeof column.cell === 'function') {
310
+ var cellData = _server["default"].renderToStaticMarkup(column.cell(record, i));
311
+ cellData = this.strip(cellData);
312
+ tableHtml += '<td>' + cellData + '</td>';
313
+ } else if (record[column.key]) {
314
+ tableHtml += '<td>' + record[column.key] + '</td>';
315
+ } else {
316
+ tableHtml += '<td></td>';
317
+ }
318
+ }
319
+ } catch (err) {
320
+ _iterator2.e(err);
321
+ } finally {
322
+ _iterator2.f();
323
+ }
324
+ tableHtml += '</tr>';
325
+ }
326
+ tableHtml += '</tbody>';
327
+ tableHtml += '</table>';
328
+ return tableHtml;
329
+ }
330
+ }, {
331
+ key: "exportToExcel",
332
+ value: function exportToExcel() {
333
+ var downloadLink,
334
+ dataType = 'application/vnd.ms-excel';
335
+ var tableHtml = this.getExportHtml();
336
+
337
+ // Specify file name
338
+ var filename = this.config.filename ? this.config.filename + '.xls' : 'table.xls';
339
+ // Create download link element
340
+ downloadLink = document.createElement('a');
341
+ if (navigator.msSaveOrOpenBlob) {
342
+ var blob = new Blob(["\uFEFF", tableHtml], {
343
+ type: dataType
344
+ });
345
+ navigator.msSaveOrOpenBlob(blob, filename);
346
+ } else {
347
+ // Create a link to the file
348
+ downloadLink.href = 'data:' + dataType + ', ' + tableHtml;
349
+ // Setting the file name
350
+ downloadLink.download = filename;
351
+ //triggering the function
352
+ downloadLink.click();
353
+ }
354
+ }
355
+ }, {
356
+ key: "exportToPDF",
357
+ value: function exportToPDF() {
358
+ var tableHtml = this.getExportHtml();
359
+ var style = '<style>';
360
+ style = style + 'table {width: 100%;font: 17px Calibri;}';
361
+ style = style + 'table, th, td {border: solid 1px #DDD; border-collapse: collapse;';
362
+ style = style + 'padding: 2px 3px;text-align:left;}';
363
+ style = style + '</style>';
364
+ var win = window.open('', '_blank');
365
+ win.document.write('<html><head>');
366
+ win.document.write('<title>' + this.config.filename + '</title>');
367
+ win.document.write(style);
368
+ win.document.write('</head>');
369
+ win.document.write('<body>');
370
+ win.document.write('<h1>' + this.config.filename + '</h1>');
371
+ win.document.write(tableHtml);
372
+ win.document.write('</body></html>');
373
+ win.print();
374
+ win.close();
375
+ }
376
+ }, {
377
+ key: "convertToCSV",
378
+ value: function convertToCSV(objArray) {
379
+ var array = _typeof(objArray) != 'object' ? JSON.parse(objArray) : objArray;
380
+ var str = '';
381
+ for (var i = 0; i < array.length; i++) {
382
+ var line = '';
383
+ for (var index in array[i]) {
384
+ if (line != '') line += ',';
385
+ line += array[i][index];
386
+ }
387
+ str += line + '\r\n';
388
+ }
389
+ return str;
390
+ }
391
+ }, {
392
+ key: "exportToCSV",
393
+ value: function exportToCSV() {
394
+ var headers = {};
395
+ // add columns in sheet array
396
+ var _iterator3 = _createForOfIteratorHelper(this.props.columns),
397
+ _step3;
398
+ try {
399
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
400
+ var _column2 = _step3.value;
401
+ if (isCheckBoxColumn(_column2)) continue;
402
+ var headerText = typeof _column2.text === 'string' ? _column2.text : _column2.key || '';
403
+ headers[_column2.key] = '"' + headerText + '"';
404
+ }
405
+
406
+ // Filter records before export
407
+ } catch (err) {
408
+ _iterator3.e(err);
409
+ } finally {
410
+ _iterator3.f();
411
+ }
412
+ var filterRecords = this.props.records;
413
+ if (this.props.dynamic === false) {
414
+ var _records = this.sortRecords(),
415
+ filterValue = this.state.filter_value;
416
+ filterRecords = _records;
417
+ if (filterValue) {
418
+ filterRecords = this.filterData(_records);
419
+ }
420
+ }
421
+ var records = [];
422
+ // add data rows in sheet array
423
+ for (var i in filterRecords) {
424
+ var record = filterRecords[i],
425
+ newRecord = {};
426
+ var _iterator4 = _createForOfIteratorHelper(this.props.columns),
427
+ _step4;
428
+ try {
429
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
430
+ var column = _step4.value;
431
+ if (isCheckBoxColumn(column)) continue;
432
+ if (column.cell && typeof column.cell === 'function') {
433
+ var cellData = _server["default"].renderToStaticMarkup(column.cell(record, i));
434
+ cellData = this.strip(cellData);
435
+ newRecord[column.key] = cellData;
436
+ } else if (record[column.key]) {
437
+ var colValue = record[column.key];
438
+ colValue = typeof colValue === 'string' ? colValue.replace(/"/g, '""') : colValue;
439
+ newRecord[column.key] = '"' + colValue + '"';
440
+ } else {
441
+ newRecord[column.key] = '';
442
+ }
443
+ }
444
+ } catch (err) {
445
+ _iterator4.e(err);
446
+ } finally {
447
+ _iterator4.f();
448
+ }
449
+ records.push(newRecord);
450
+ }
451
+ if (headers) {
452
+ records.unshift(headers);
453
+ }
454
+ // Convert Object to JSON
455
+ var jsonObject = JSON.stringify(records);
456
+ var csv = this.convertToCSV(jsonObject);
457
+ var exportedFilename = this.config.filename + '.csv' || 'export.csv';
458
+ var blob = new Blob([csv], {
459
+ type: 'text/csv;charset=utf-8;'
460
+ });
461
+ if (navigator.msSaveBlob) {
462
+ // IE 10+
463
+ navigator.msSaveBlob(blob, exportedFilename);
464
+ } else {
465
+ var link = document.createElement('a');
466
+ if (link.download !== undefined) {
467
+ // feature detection
468
+ // Browsers that support HTML5 download attribute
469
+ var url = URL.createObjectURL(blob);
470
+ link.setAttribute('href', url);
471
+ link.setAttribute('download', exportedFilename);
472
+ link.style.visibility = 'hidden';
473
+ document.body.appendChild(link);
474
+ link.click();
475
+ link.remove();
476
+ }
477
+ }
478
+ }
479
+ }, {
480
+ key: "onChange",
481
+ value: function onChange() {
482
+ var tableData = {
483
+ filter_value: this.state.filter_value,
484
+ page_number: this.state.page_number,
485
+ page_size: this.state.page_size,
486
+ sort_order: this.state.sort
487
+ };
488
+ this.props.onChange(tableData);
489
+ }
490
+ }, {
491
+ key: "filterData",
492
+ value: function filterData(records) {
493
+ var _this7 = this;
494
+ var filterValue = this.state.filter_value;
495
+ return records.filter(function (record) {
496
+ var allow = false;
497
+ _lodash["default"].each(_this7.props.columns, function (column, key) {
498
+ if (record[column.key]) {
499
+ allow = _lodash["default"].includes(record[column.key].toString().toLowerCase(), filterValue.toString().toLowerCase()) ? true : allow;
500
+ }
501
+ });
502
+ return allow;
503
+ });
504
+ }
505
+ }, {
506
+ key: "sortRecords",
507
+ value: function sortRecords() {
508
+ var _this8 = this;
509
+ if (this.state.sort) {
510
+ return _lodash["default"].orderBy(this.props.records, function (o) {
511
+ var colVal = o[_this8.state.sort.column];
512
+ var typeofColVal = _typeof(colVal);
513
+ if (typeofColVal == 'string') {
514
+ if (isNaN(colVal)) {
515
+ return new String(colVal.toLowerCase());
516
+ } else {
517
+ return new Number(colVal);
518
+ }
519
+ } else if (typeofColVal == 'number') {
520
+ return new Number(colVal);
521
+ }
522
+ }, [this.state.sort.order]);
523
+ } else {
524
+ return this.props.records;
525
+ }
526
+ }
527
+ }, {
528
+ key: "render",
529
+ value: function render() {
530
+ var _this9 = this;
531
+ var filterRecords, totalRecords, pages, isFirst, isLast;
532
+ if (this.props.dynamic === false) {
533
+ var records = this.props.onSort ? this.props.onSort(this.state.sort.column, this.props.records, this.state.sort.order) : this.sortRecords(),
534
+ filterValue = this.state.filter_value;
535
+ filterRecords = records;
536
+ if (filterValue) {
537
+ filterRecords = this.filterData(records);
538
+ }
539
+ totalRecords = Array.isArray(filterRecords) ? filterRecords.length : 0;
540
+ pages = this.pages = this.numPages(totalRecords);
541
+ isFirst = this.isFirst();
542
+ isLast = this.isLast();
543
+ filterRecords = Array.isArray(filterRecords) ? this.paginate(filterRecords) : [];
544
+ } else {
545
+ filterRecords = this.props.records;
546
+ totalRecords = this.props.total_record;
547
+ pages = this.pages = this.numPages(totalRecords);
548
+ isFirst = this.isFirst();
549
+ isLast = this.isLast();
550
+ }
551
+ var startRecords = this.state.page_number * this.state.page_size - (this.state.page_size - 1);
552
+ var endRecords = this.state.page_size * this.state.page_number;
553
+ endRecords = endRecords > totalRecords ? totalRecords : endRecords;
554
+ var lengthMenuText = this.config.language.length_menu;
555
+ lengthMenuText = lengthMenuText.split('_MENU_');
556
+ var paginationInfo = this.config.language.info;
557
+ paginationInfo = paginationInfo.replace('_START_', this.state.page_number == 1 ? 1 : startRecords);
558
+ paginationInfo = paginationInfo.replace('_END_', endRecords);
559
+ paginationInfo = paginationInfo.replace('_TOTAL_', totalRecords);
560
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
561
+ className: "as-react-table",
562
+ id: this.props.id ? this.props.id + '-container' : '',
563
+ children: [this.config.show_filter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableHeader["default"], {
564
+ config: this.config,
565
+ id: this.props.id,
566
+ lengthMenuText: lengthMenuText,
567
+ recordLength: this.props.dynamic ? this.props.total_record : this.props.records.length,
568
+ filterRecords: this.filterRecords.bind(this),
569
+ changePageSize: this.changePageSize.bind(this),
570
+ exportToExcel: this.exportToExcel.bind(this),
571
+ exportToCSV: this.exportToCSV.bind(this),
572
+ exportToPDF: this.exportToPDF.bind(this),
573
+ extraButtons: this.props.extraButtons
574
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
575
+ className: "row table-body asrt-table-body",
576
+ style: _style2["default"].table_body,
577
+ id: this.props.id ? this.props.id + '-table-body' : '',
578
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
579
+ className: "col-md-12",
580
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("table", {
581
+ className: this.props.className,
582
+ id: this.props.id,
583
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("thead", {
584
+ className: this.props.tHeadClassName ? this.props.tHeadClassName : '',
585
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
586
+ children: this.props.columns.map(function (column, index) {
587
+ var classText = column.sortable ? 'sortable ' : '',
588
+ width = column.width ? column.width : '',
589
+ align = column.align ? column.align : '',
590
+ sortOrder = '',
591
+ columnStyle = {};
592
+ if (column.sortable && _this9.state.sort.column == column.key) {
593
+ sortOrder = _this9.state.sort.order;
594
+ classText += sortOrder ? ' ' + sortOrder : '';
595
+ columnStyle = sortOrder == 'asc' ? _style2["default"].sort_asc : _style2["default"].sort_desc;
596
+ }
597
+ classText += ' text-' + align;
598
+ if (column.TrOnlyClassName) classText += ' ' + column.TrOnlyClassName;
599
+ var isCheckBox = isCheckBoxColumn(column);
600
+ var allSelected = _this9.props.records.length > 0 && _this9.props.checkSelectedIds && _this9.props.checkSelectedIds.length === _this9.props.records.length;
601
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
602
+ className: classText,
603
+ width: width,
604
+ style: columnStyle,
605
+ onClick: function onClick(event) {
606
+ return _this9.sortColumn(event, column, sortOrder);
607
+ },
608
+ children: isCheckBox ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
609
+ onClick: function onClick(e) {
610
+ return e.stopPropagation();
611
+ },
612
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputCheck["default"], {
613
+ name: "selectAll",
614
+ value: allSelected,
615
+ onChange: function onChange(ev) {
616
+ return _this9.props.onCheckRowChange(undefined, ev.target.value);
617
+ },
618
+ styleContainer: {
619
+ justifyContent: 'center'
620
+ }
621
+ })
622
+ }) : column.text
623
+ }, column.key ? column.key : column.text);
624
+ })
625
+ })
626
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("tbody", {
627
+ children: this.props.loading === true ? /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
628
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
629
+ colSpan: this.props.columns.length,
630
+ className: "asrt-td-loading",
631
+ align: "center",
632
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
633
+ className: "asrt-loading-textwrap",
634
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
635
+ className: "asrt-loading-text",
636
+ children: this.config.language.loading_text
637
+ })
638
+ })
639
+ })
640
+ }) : filterRecords.length ? filterRecords.map(function (record, rowIndex) {
641
+ rowIndex = _lodash["default"].indexOf(_this9.props.records, record);
642
+ var rowId = record[_this9.config.key_column];
643
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
644
+ onClick: function onClick(e) {
645
+ return _this9.props.onRowClicked(e, record, rowIndex);
646
+ },
647
+ children: _this9.props.columns.map(function (column, colIndex) {
648
+ var isCheckBox = isCheckBoxColumn(column);
649
+ if (isCheckBox) {
650
+ var checked = _this9.props.checkSelectedIds && _this9.props.checkSelectedIds.includes(rowId);
651
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
652
+ className: column.className,
653
+ onClick: function onClick(e) {
654
+ return e.stopPropagation();
655
+ },
656
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputCheck["default"], {
657
+ name: String(rowId),
658
+ value: checked,
659
+ onChange: function onChange(payload) {
660
+ return _this9.handleCheckBoxRowChange(record, payload.target.value, payload.event, rowIndex);
661
+ },
662
+ styleContainer: {
663
+ justifyContent: 'center'
664
+ }
665
+ })
666
+ }, column.key ? column.key : column.text);
667
+ }
668
+ if (column.cell && typeof column.cell === 'function') {
669
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
670
+ className: column.className,
671
+ children: column.cell(record, rowIndex)
672
+ }, column.key ? column.key : column.text);
673
+ } else if (record[column.key]) {
674
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
675
+ className: column.className,
676
+ children: record[column.key]
677
+ }, column.key ? column.key : column.text);
678
+ } else {
679
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
680
+ className: column.className
681
+ }, column.key ? column.key : column.text);
682
+ }
683
+ })
684
+ }, rowId !== null && rowId !== void 0 ? rowId : rowIndex);
685
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
686
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
687
+ colSpan: this.props.columns.length,
688
+ align: "center",
689
+ children: this.config.language.no_data_text
690
+ })
691
+ })
692
+ })]
693
+ })
694
+ })
695
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableFooter["default"], {
696
+ config: this.config,
697
+ id: this.props.id,
698
+ isFirst: isFirst,
699
+ isLast: isLast,
700
+ paginationInfo: paginationInfo,
701
+ pages: pages,
702
+ page_number: this.state.page_number,
703
+ is_temp_page: this.state.is_temp_page,
704
+ temp_page_number: this.state.temp_page_number,
705
+ firstPage: this.firstPage.bind(this),
706
+ lastPage: this.lastPage.bind(this),
707
+ previousPage: this.previousPage.bind(this),
708
+ nextPage: this.nextPage.bind(this),
709
+ goToPage: this.goToPage.bind(this),
710
+ changePageSize: this.changePageSize.bind(this),
711
+ onPageChange: this.onPageChange.bind(this),
712
+ onPageBlur: this.onPageBlur.bind(this)
713
+ })]
714
+ });
715
+ }
716
+ }]);
717
+ }(_react.Component);
718
+ /**
719
+ * Define component display name
720
+ */
721
+ ReactDatatable.displayName = 'ReactDatatable';
722
+
723
+ /**
724
+ * Define defaultProps for this component
725
+ */
726
+ ReactDatatable.defaultProps = {
727
+ id: 'as-react-datatable',
728
+ className: 'table table-bordered table-striped',
729
+ columns: [],
730
+ config: {
731
+ button: {
732
+ excel: false,
733
+ print: false,
734
+ csv: false
735
+ },
736
+ filename: 'table',
737
+ key_column: 'id',
738
+ language: {
739
+ length_menu: 'Show _MENU_ records per page',
740
+ filter: 'Search in records...',
741
+ info: 'Showing _START_ to _END_ of _TOTAL_ entries',
742
+ pagination: {
743
+ first: 'First',
744
+ previous: 'Previous',
745
+ next: 'Next',
746
+ last: 'Last'
747
+ }
748
+ },
749
+ length_menu: [10, 25, 50, 75, 100],
750
+ no_data_text: 'No rows found',
751
+ page_size: 10,
752
+ sort: {
753
+ column: 'test',
754
+ order: 'asc'
755
+ },
756
+ show_length_menu: true,
757
+ show_filter: true,
758
+ show_pagination: true,
759
+ show_info: true,
760
+ show_first: true,
761
+ show_last: true
762
+ },
763
+ dynamic: false,
764
+ records: [],
765
+ total_record: 0,
766
+ onChange: function onChange() {},
767
+ onPageChange: function onPageChange() {},
768
+ onRowClicked: function onRowClicked() {},
769
+ checkSelectedIds: [],
770
+ onCheckRowChange: function onCheckRowChange() {}
771
+ };
772
+ var _default = exports["default"] = ReactDatatable;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _upArrow = _interopRequireDefault(require("../assets/img/up-arrow.png"));
8
+ var _downArrow = _interopRequireDefault(require("../assets/img/down-arrow.png"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ var _default = exports["default"] = {
11
+ table_body: {
12
+ marginTop: '12px'
13
+ },
14
+ table_size: {
15
+ background: 'none',
16
+ border: 'none',
17
+ padding: 0
18
+ },
19
+ table_size_dropdown: {
20
+ width: '70px',
21
+ flex: 'none',
22
+ margin: '0px 10px',
23
+ display: 'inline-block',
24
+ "float": 'none'
25
+ },
26
+ table_filter: {
27
+ display: 'inline-block',
28
+ verticalAlign: 'top',
29
+ marginRight: '5px',
30
+ width: '250px'
31
+ },
32
+ table_tool: {
33
+ display: 'inline-block',
34
+ verticalAlign: 'top'
35
+ },
36
+ table_tool_btn: {
37
+ marginRight: '5px'
38
+ },
39
+ sort_asc: {
40
+ backgroundImage: "url(".concat(_upArrow["default"], ")")
41
+ },
42
+ sort_desc: {
43
+ backgroundImage: "url(".concat(_downArrow["default"], ")")
44
+ }
45
+ };
@@ -4,11 +4,14 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports["default"] = InputComponent;
7
+ exports["default"] = InputCheck;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _syles = require("./syles");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
- var _excluded = ["value", "label", "onChange", "styleContainer", "styleLabel"];
11
+ var _excluded = ["value", "label", "onChange", "styleContainer", "styleLabel"]; //Exemplo de uso
12
+ //<InputCheck onChange={onSelectItem} name="isValido" value={values.isValido} />
13
+ //function onSelectItem(ev) { setValues({...values, [ev.target.name]: ev.target.value})}
14
+ //Compativel com a função onChange
12
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
14
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -24,7 +27,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
24
27
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
25
28
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
26
29
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
27
- function InputComponent(_ref) {
30
+ function InputCheck(_ref) {
28
31
  var value = _ref.value,
29
32
  label = _ref.label,
30
33
  onChange = _ref.onChange,
@@ -46,18 +49,25 @@ function InputComponent(_ref) {
46
49
  if (onChange) onChange({
47
50
  target: _objectSpread({
48
51
  value: checked
49
- }, inputProps)
52
+ }, inputProps),
53
+ event: ev
50
54
  });
51
55
  };
52
56
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_syles.Container, {
53
57
  style: styleContainer,
58
+ disabled: inputProps.disabled,
54
59
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
55
60
  className: "checkbox",
56
61
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_syles.SelectBox, _objectSpread({
57
62
  checked: state,
58
63
  type: "checkbox",
59
64
  onChange: onSelect
60
- }, inputProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
65
+ }, inputProps)), inputProps.disabled && state ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
66
+ className: "checkmark",
67
+ style: {
68
+ backgroundColor: '#666666'
69
+ }
70
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
61
71
  className: "checkmark"
62
72
  })]
63
73
  }), label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_syles.Label, {
@@ -9,9 +9,17 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
9
  var _templateObject, _templateObject2, _templateObject3;
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
11
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
12
- var Container = exports.Container = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: flex-start;\n margin: auto 0;\n\n .checkbox {\n display: block;\n position: relative;\n padding-left: 20px;\n margin-bottom: 20px;\n cursor: pointer;\n font-size: 22px;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n }\n\n .checkmark {\n position: absolute;\n top: 0;\n left: 0;\n height: 20px;\n width: 20px;\n background-color: #eee;\n border-radius: 3px;\n }\n .checkbox:hover input ~ .checkmark {\n background-color: #ccc;\n }\n .checkbox input:checked ~ .checkmark {\n background-color: var(--blue);\n }\n .checkmark:after {\n content: '';\n position: absolute;\n display: none;\n }\n .checkbox input:checked ~ .checkmark:after {\n display: block;\n }\n .checkbox .checkmark:after {\n left: 9px;\n top: 5px;\n width: 5px;\n height: 10px;\n border: solid white;\n border-width: 0 3px 3px 0;\n -webkit-transform: rotate(45deg);\n -ms-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n"])));
13
- var SelectBox = exports.SelectBox = (0, _styledComponents["default"])(_reactstrap.Input)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n opacity: 0;\n cursor: pointer;\n height: 0;\n width: 0;\n"])));
14
- var Label = exports.Label = _styledComponents["default"].label(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: ", ";\n font-size: ", ";\n font-weight: ", ";\n padding-top: 7px;\n"])), function (props) {
12
+ var Container = exports.Container = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: flex-start;\n margin: auto 0;\n\n .checkbox {\n display: block;\n position: relative;\n padding-left: 30px;\n margin-bottom: 20px;\n font-size: 22px;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n cursor: ", ";\n }\n\n .checkmark {\n position: absolute;\n top: 0;\n left: 0;\n height: 20px;\n width: 20px;\n border-radius: 3px;\n\n background-color: ", ";\n }\n .checkbox:hover input ~ .checkmark {\n background-color: ", ";\n }\n .checkbox input:checked ~ .checkmark {\n background-color: var(--blue);\n }\n .checkmark:after {\n content: '';\n position: absolute;\n display: none;\n }\n .checkbox input:checked ~ .checkmark:after {\n display: block;\n }\n .checkbox .checkmark:after {\n left: 9px;\n top: 5px;\n width: 5px;\n height: 10px;\n border: solid white;\n border-width: 0 3px 3px 0;\n -webkit-transform: rotate(45deg);\n -ms-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n"])), function (props) {
13
+ return !props.disabled ? 'pointer' : 'unset';
14
+ }, function (props) {
15
+ return props.disabled ? '#ccc' : '#eee';
16
+ }, function (props) {
17
+ return !props.disabled && '#ccc';
18
+ });
19
+ var SelectBox = exports.SelectBox = (0, _styledComponents["default"])(_reactstrap.Input)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n opacity: 0;\n height: 0;\n width: 0;\n\n cursor: ", ";\n"])), function (props) {
20
+ return !props.disabled ? 'pointer' : 'unset';
21
+ });
22
+ var Label = exports.Label = _styledComponents["default"].label(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: ", ";\n font-size: ", ";\n font-weight: ", ";\n"])), function (props) {
15
23
  return props.isHighlight && 'var(--primary)';
16
24
  }, function (props) {
17
25
  return props.isHighlight && '1.5rem';
package/dist/index.js CHANGED
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "CardFilter", {
9
9
  return _CardFilter["default"];
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "DataGridView", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _DataGridView["default"];
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "InputCheck", {
13
19
  enumerable: true,
14
20
  get: function get() {
@@ -17,4 +23,5 @@ Object.defineProperty(exports, "InputCheck", {
17
23
  });
18
24
  var _CardFilter = _interopRequireDefault(require("./CardFilter"));
19
25
  var _InputCheck = _interopRequireDefault(require("./InputCheck"));
26
+ var _DataGridView = _interopRequireDefault(require("./DataGridView"));
20
27
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bitys-react-components",
3
3
  "description": "",
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
7
7
  "license": "MIT",