venice-ui 2.2.11 → 2.3.0
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/dist/cjs/components/Input/Input.styles.js +2 -0
- package/dist/cjs/components/Pagination/Pagination.js +56 -0
- package/dist/cjs/components/Pagination/Pagination.styles.js +30 -0
- package/dist/cjs/components/Pagination/index.js +17 -0
- package/dist/cjs/components/Table/Table.js +13 -3
- package/dist/cjs/index.js +1 -0
- package/dist/esm/components/Input/Input.styles.js +2 -0
- package/dist/esm/components/Pagination/Pagination.js +49 -0
- package/dist/esm/components/Pagination/Pagination.styles.js +24 -0
- package/dist/esm/components/Pagination/index.js +1 -0
- package/dist/esm/components/Table/Table.js +13 -3
- package/dist/esm/index.js +1 -0
- package/dist/types/components/Pagination/Pagination.d.ts +11 -0
- package/dist/types/components/Pagination/Pagination.styles.d.ts +2 -0
- package/dist/types/components/Pagination/index.d.ts +1 -0
- package/dist/types/components/Table/Table.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -69,6 +69,8 @@ exports.InputReadOnlyElement = styled_components_1.default.div `
|
|
|
69
69
|
exports.InputLabelElement = (0, styled_components_1.default)(Typography_1.TextLabel) `
|
|
70
70
|
${(p) => p.labelPosition === 'top' && `margin-bottom: ${Theme_1.Theme.padding.s};`}
|
|
71
71
|
${(p) => p.labelPosition === 'left' && `margin-left: ${Theme_1.Theme.padding.s};`}
|
|
72
|
+
${(p) => p.labelPosition === 'left' && `margin-right: ${Theme_1.Theme.padding.s};`}
|
|
73
|
+
white-space: nowrap;
|
|
72
74
|
`;
|
|
73
75
|
exports.InputWrapper = styled_components_1.default.div `
|
|
74
76
|
display: flex;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Pagination = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const Icons_1 = require("../Icons");
|
|
9
|
+
const Theme_1 = require("../../Theme/Theme");
|
|
10
|
+
const Dropdown_1 = require("../Dropdown");
|
|
11
|
+
const Pagination_styles_1 = require("./Pagination.styles");
|
|
12
|
+
const getPageNumbers = (current, total) => {
|
|
13
|
+
const pages = [];
|
|
14
|
+
if (total <= 5) {
|
|
15
|
+
for (let i = 1; i <= total; i++)
|
|
16
|
+
pages.push(i);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (current <= 3) {
|
|
20
|
+
pages.push(1, 2, 3, '...', total);
|
|
21
|
+
}
|
|
22
|
+
else if (current >= total - 2) {
|
|
23
|
+
pages.push(1, '...', total - 2, total - 1, total);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
pages.push(1, '...', current - 1, current, current + 1, '...', total);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return pages;
|
|
30
|
+
};
|
|
31
|
+
const Pagination = ({ currentPage, totalPages, pageSize, onPageChange, onPageSizeChange, availableValues = [10, 20, 50], }) => {
|
|
32
|
+
const pageNumbers = getPageNumbers(currentPage, totalPages);
|
|
33
|
+
const pageSizeStr = !isNaN(pageSize) ? String(pageSize) : '10';
|
|
34
|
+
let dropdownOptions = availableValues.map(size => ({
|
|
35
|
+
value: size.toString(),
|
|
36
|
+
label: size.toString(),
|
|
37
|
+
}));
|
|
38
|
+
if (!dropdownOptions.some(opt => opt.value === pageSizeStr)) {
|
|
39
|
+
dropdownOptions = [
|
|
40
|
+
{ value: pageSizeStr, label: pageSizeStr },
|
|
41
|
+
...dropdownOptions,
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
return (react_1.default.createElement(Pagination_styles_1.PaginationElement, null,
|
|
45
|
+
react_1.default.createElement(Icons_1.Icon, { name: 'back', size: 16, iconColor: Theme_1.Theme.colors.text, onClick: () => onPageChange(Math.max(1, currentPage - 1)), isDisabled: currentPage === 1 }),
|
|
46
|
+
pageNumbers.map((num, idx) => num === '...' ? (react_1.default.createElement("span", { key: `ellipsis-${idx}` }, "...")) : (react_1.default.createElement(Pagination_styles_1.PaginationButton, { key: num, onClick: () => onPageChange(Number(num)), disabled: num === currentPage }, num))),
|
|
47
|
+
react_1.default.createElement(Icons_1.Icon, { name: 'forward', size: 16, iconColor: Theme_1.Theme.colors.text, onClick: () => onPageChange(Math.min(totalPages, currentPage + 1)), isDisabled: currentPage === totalPages }),
|
|
48
|
+
react_1.default.createElement("div", null,
|
|
49
|
+
react_1.default.createElement(Dropdown_1.Dropdown, { size: "small", label: "Ilo\u015B\u0107 na stron\u0119:", labelPosition: "left", handleSelect: (name, value) => {
|
|
50
|
+
const num = Number(value);
|
|
51
|
+
if (!isNaN(num) && num > 0) {
|
|
52
|
+
onPageSizeChange(num);
|
|
53
|
+
}
|
|
54
|
+
}, name: "pageSize", value: String(pageSize), options: dropdownOptions }))));
|
|
55
|
+
};
|
|
56
|
+
exports.Pagination = Pagination;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PaginationButton = exports.PaginationElement = void 0;
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const Theme_1 = require("../../Theme/Theme");
|
|
9
|
+
exports.PaginationElement = styled_components_1.default.div `
|
|
10
|
+
margin-top: 16px;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: right;
|
|
13
|
+
align-items: center;
|
|
14
|
+
`;
|
|
15
|
+
exports.PaginationButton = styled_components_1.default.button `
|
|
16
|
+
font-weight: normal;
|
|
17
|
+
background: transparent;
|
|
18
|
+
border: none;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
padding: ${Theme_1.Theme.padding.s}
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
color: ${Theme_1.Theme.colors.text};
|
|
23
|
+
margin: 0 6px;
|
|
24
|
+
&:disabled {
|
|
25
|
+
background: ${Theme_1.Theme.colors.primary};
|
|
26
|
+
color: ${Theme_1.Theme.colors.white};
|
|
27
|
+
cursor: not-allowed;
|
|
28
|
+
border-radius: 4px;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Pagination"), exports);
|
|
@@ -31,10 +31,11 @@ const Theme_1 = require("../../Theme");
|
|
|
31
31
|
const tableHelper_1 = require("./tableHelper");
|
|
32
32
|
const HeaderCell_1 = require("./HeaderCell");
|
|
33
33
|
const Cell_1 = require("./Cell");
|
|
34
|
+
const Pagination_1 = require("../Pagination");
|
|
34
35
|
const Table = ({ theme = Theme_1.mainTheme, headers, elements, hover = true, selectable = true, sortable = true, sort = {
|
|
35
36
|
name: '',
|
|
36
37
|
order: 'none',
|
|
37
|
-
}, moreActions = [], onRowClick, }) => {
|
|
38
|
+
}, pageSize = 10, ifPagination = false, moreActions = [], onRowClick, }) => {
|
|
38
39
|
const checkHeaders = () => {
|
|
39
40
|
const tableHeaders = [...headers];
|
|
40
41
|
if (moreActions.length > 0) {
|
|
@@ -74,12 +75,21 @@ const Table = ({ theme = Theme_1.mainTheme, headers, elements, hover = true, sel
|
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
};
|
|
78
|
+
// PAGINACJA
|
|
79
|
+
const [currentPage, setCurrentPage] = (0, react_1.useState)(1);
|
|
80
|
+
const [currentPageSize, setCurrentPageSize] = (0, react_1.useState)(pageSize || 10);
|
|
81
|
+
const totalPages = Math.ceil(tableProps.elements.length / currentPageSize);
|
|
82
|
+
const paginatedElements = tableProps.elements.slice((currentPage - 1) * currentPageSize, currentPage * currentPageSize);
|
|
83
|
+
(0, react_1.useEffect)(() => {
|
|
84
|
+
setCurrentPage(1);
|
|
85
|
+
}, [elements, currentPageSize]);
|
|
77
86
|
return (react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme },
|
|
78
87
|
react_1.default.createElement(Table_styles_1.TableWrapper, { cellPadding: "0", cellSpacing: "0" },
|
|
79
88
|
react_1.default.createElement(Table_styles_1.TableHead, null,
|
|
80
89
|
react_1.default.createElement(Table_styles_1.TableRow, { hover: false, selectable: false, active: false }, tableProps.headers.map((header) => (react_1.default.createElement(HeaderCell_1.HeaderCell, { key: `header_${header.name}`, header: header, sortable: sortable, handleSort: handleHeaderCellClick, sort: tableProps.sort }))))),
|
|
81
|
-
react_1.default.createElement("tbody", null,
|
|
90
|
+
react_1.default.createElement("tbody", null, paginatedElements.map((item) => (react_1.default.createElement(Table_styles_1.TableRow, { key: `table_row_${item.id}`, hover: hover, active: selectedRow === item.id, selectable: selectable, onClick: () => handleRowClick(item.id) }, tableProps.headers.map((header, index) => {
|
|
82
91
|
return (react_1.default.createElement(Cell_1.Cell, { key: `cell_${header.name}_${item.id}`, header: header, moreActions: moreActions, item: item, theme: theme, marked: item.marked && index === 0 }));
|
|
83
|
-
}))))))
|
|
92
|
+
})))))),
|
|
93
|
+
ifPagination && (react_1.default.createElement(Pagination_1.Pagination, { currentPage: currentPage, totalPages: totalPages, pageSize: currentPageSize, onPageChange: setCurrentPage, onPageSizeChange: setCurrentPageSize }))));
|
|
84
94
|
};
|
|
85
95
|
exports.Table = Table;
|
package/dist/cjs/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __exportStar(require("./components/Input"), exports);
|
|
|
34
34
|
__exportStar(require("./components/List"), exports);
|
|
35
35
|
__exportStar(require("./components/Loader"), exports);
|
|
36
36
|
__exportStar(require("./components/Modal"), exports);
|
|
37
|
+
__exportStar(require("./components/Pagination"), exports);
|
|
37
38
|
__exportStar(require("./components/Section"), exports);
|
|
38
39
|
__exportStar(require("./components/Selector"), exports);
|
|
39
40
|
__exportStar(require("./components/Sidepanel"), exports);
|
|
@@ -63,6 +63,8 @@ export const InputReadOnlyElement = styled.div `
|
|
|
63
63
|
export const InputLabelElement = styled(TextLabel) `
|
|
64
64
|
${(p) => p.labelPosition === 'top' && `margin-bottom: ${Theme.padding.s};`}
|
|
65
65
|
${(p) => p.labelPosition === 'left' && `margin-left: ${Theme.padding.s};`}
|
|
66
|
+
${(p) => p.labelPosition === 'left' && `margin-right: ${Theme.padding.s};`}
|
|
67
|
+
white-space: nowrap;
|
|
66
68
|
`;
|
|
67
69
|
export const InputWrapper = styled.div `
|
|
68
70
|
display: flex;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Icon } from '../Icons';
|
|
3
|
+
import { Theme } from '../../Theme/Theme';
|
|
4
|
+
import { Dropdown } from '../Dropdown';
|
|
5
|
+
import { PaginationElement, PaginationButton } from './Pagination.styles';
|
|
6
|
+
const getPageNumbers = (current, total) => {
|
|
7
|
+
const pages = [];
|
|
8
|
+
if (total <= 5) {
|
|
9
|
+
for (let i = 1; i <= total; i++)
|
|
10
|
+
pages.push(i);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (current <= 3) {
|
|
14
|
+
pages.push(1, 2, 3, '...', total);
|
|
15
|
+
}
|
|
16
|
+
else if (current >= total - 2) {
|
|
17
|
+
pages.push(1, '...', total - 2, total - 1, total);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
pages.push(1, '...', current - 1, current, current + 1, '...', total);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return pages;
|
|
24
|
+
};
|
|
25
|
+
export const Pagination = ({ currentPage, totalPages, pageSize, onPageChange, onPageSizeChange, availableValues = [10, 20, 50], }) => {
|
|
26
|
+
const pageNumbers = getPageNumbers(currentPage, totalPages);
|
|
27
|
+
const pageSizeStr = !isNaN(pageSize) ? String(pageSize) : '10';
|
|
28
|
+
let dropdownOptions = availableValues.map(size => ({
|
|
29
|
+
value: size.toString(),
|
|
30
|
+
label: size.toString(),
|
|
31
|
+
}));
|
|
32
|
+
if (!dropdownOptions.some(opt => opt.value === pageSizeStr)) {
|
|
33
|
+
dropdownOptions = [
|
|
34
|
+
{ value: pageSizeStr, label: pageSizeStr },
|
|
35
|
+
...dropdownOptions,
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
return (React.createElement(PaginationElement, null,
|
|
39
|
+
React.createElement(Icon, { name: 'back', size: 16, iconColor: Theme.colors.text, onClick: () => onPageChange(Math.max(1, currentPage - 1)), isDisabled: currentPage === 1 }),
|
|
40
|
+
pageNumbers.map((num, idx) => num === '...' ? (React.createElement("span", { key: `ellipsis-${idx}` }, "...")) : (React.createElement(PaginationButton, { key: num, onClick: () => onPageChange(Number(num)), disabled: num === currentPage }, num))),
|
|
41
|
+
React.createElement(Icon, { name: 'forward', size: 16, iconColor: Theme.colors.text, onClick: () => onPageChange(Math.min(totalPages, currentPage + 1)), isDisabled: currentPage === totalPages }),
|
|
42
|
+
React.createElement("div", null,
|
|
43
|
+
React.createElement(Dropdown, { size: "small", label: "Ilo\u015B\u0107 na stron\u0119:", labelPosition: "left", handleSelect: (name, value) => {
|
|
44
|
+
const num = Number(value);
|
|
45
|
+
if (!isNaN(num) && num > 0) {
|
|
46
|
+
onPageSizeChange(num);
|
|
47
|
+
}
|
|
48
|
+
}, name: "pageSize", value: String(pageSize), options: dropdownOptions }))));
|
|
49
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Theme } from '../../Theme/Theme';
|
|
3
|
+
export const PaginationElement = styled.div `
|
|
4
|
+
margin-top: 16px;
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: right;
|
|
7
|
+
align-items: center;
|
|
8
|
+
`;
|
|
9
|
+
export const PaginationButton = styled.button `
|
|
10
|
+
font-weight: normal;
|
|
11
|
+
background: transparent;
|
|
12
|
+
border: none;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
padding: ${Theme.padding.s}
|
|
15
|
+
border-radius: 4px;
|
|
16
|
+
color: ${Theme.colors.text};
|
|
17
|
+
margin: 0 6px;
|
|
18
|
+
&:disabled {
|
|
19
|
+
background: ${Theme.colors.primary};
|
|
20
|
+
color: ${Theme.colors.white};
|
|
21
|
+
cursor: not-allowed;
|
|
22
|
+
border-radius: 4px;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Pagination';
|
|
@@ -5,10 +5,11 @@ import { mainTheme } from '../../Theme';
|
|
|
5
5
|
import { applySort, setSortParams } from './tableHelper';
|
|
6
6
|
import { HeaderCell } from './HeaderCell';
|
|
7
7
|
import { Cell } from './Cell';
|
|
8
|
+
import { Pagination } from '../Pagination';
|
|
8
9
|
export const Table = ({ theme = mainTheme, headers, elements, hover = true, selectable = true, sortable = true, sort = {
|
|
9
10
|
name: '',
|
|
10
11
|
order: 'none',
|
|
11
|
-
}, moreActions = [], onRowClick, }) => {
|
|
12
|
+
}, pageSize = 10, ifPagination = false, moreActions = [], onRowClick, }) => {
|
|
12
13
|
const checkHeaders = () => {
|
|
13
14
|
const tableHeaders = [...headers];
|
|
14
15
|
if (moreActions.length > 0) {
|
|
@@ -48,11 +49,20 @@ export const Table = ({ theme = mainTheme, headers, elements, hover = true, sele
|
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
};
|
|
52
|
+
// PAGINACJA
|
|
53
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
54
|
+
const [currentPageSize, setCurrentPageSize] = useState(pageSize || 10);
|
|
55
|
+
const totalPages = Math.ceil(tableProps.elements.length / currentPageSize);
|
|
56
|
+
const paginatedElements = tableProps.elements.slice((currentPage - 1) * currentPageSize, currentPage * currentPageSize);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setCurrentPage(1);
|
|
59
|
+
}, [elements, currentPageSize]);
|
|
51
60
|
return (React.createElement(ThemeProvider, { theme: theme },
|
|
52
61
|
React.createElement(TableWrapper, { cellPadding: "0", cellSpacing: "0" },
|
|
53
62
|
React.createElement(TableHead, null,
|
|
54
63
|
React.createElement(TableRow, { hover: false, selectable: false, active: false }, tableProps.headers.map((header) => (React.createElement(HeaderCell, { key: `header_${header.name}`, header: header, sortable: sortable, handleSort: handleHeaderCellClick, sort: tableProps.sort }))))),
|
|
55
|
-
React.createElement("tbody", null,
|
|
64
|
+
React.createElement("tbody", null, paginatedElements.map((item) => (React.createElement(TableRow, { key: `table_row_${item.id}`, hover: hover, active: selectedRow === item.id, selectable: selectable, onClick: () => handleRowClick(item.id) }, tableProps.headers.map((header, index) => {
|
|
56
65
|
return (React.createElement(Cell, { key: `cell_${header.name}_${item.id}`, header: header, moreActions: moreActions, item: item, theme: theme, marked: item.marked && index === 0 }));
|
|
57
|
-
}))))))
|
|
66
|
+
})))))),
|
|
67
|
+
ifPagination && (React.createElement(Pagination, { currentPage: currentPage, totalPages: totalPages, pageSize: currentPageSize, onPageChange: setCurrentPage, onPageSizeChange: setCurrentPageSize }))));
|
|
58
68
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from './components/Input';
|
|
|
18
18
|
export * from './components/List';
|
|
19
19
|
export * from './components/Loader';
|
|
20
20
|
export * from './components/Modal';
|
|
21
|
+
export * from './components/Pagination';
|
|
21
22
|
export * from './components/Section';
|
|
22
23
|
export * from './components/Selector';
|
|
23
24
|
export * from './components/Sidepanel';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IPaginationProps {
|
|
3
|
+
currentPage: number;
|
|
4
|
+
totalPages: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
onPageChange: (page: number) => void;
|
|
7
|
+
onPageSizeChange: (size: number) => void;
|
|
8
|
+
availableValues?: number[];
|
|
9
|
+
}
|
|
10
|
+
export declare const Pagination: React.FC<IPaginationProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Pagination';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './components/Input';
|
|
|
18
18
|
export * from './components/List';
|
|
19
19
|
export * from './components/Loader';
|
|
20
20
|
export * from './components/Modal';
|
|
21
|
+
export * from './components/Pagination';
|
|
21
22
|
export * from './components/Section';
|
|
22
23
|
export * from './components/Selector';
|
|
23
24
|
export * from './components/Sidepanel';
|