@bodynarf/react.components 1.1.6 → 1.2.2
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/components/anchor/components/anchorWithIcon/index.d.ts +0 -1
- package/components/anchor/components/anchorWithIcon/index.d.ts.map +1 -1
- package/components/anchor/components/anchorWithIcon/index.js +2 -2
- package/components/button/components/buttonWithIcon/index.d.ts +0 -1
- package/components/button/components/buttonWithIcon/index.d.ts.map +1 -1
- package/components/button/components/buttonWithIcon/index.js +2 -2
- package/components/button/index.d.ts +2 -2
- package/components/button/index.d.ts.map +1 -1
- package/components/dropdown/components/dropdownLabel/index.js +1 -1
- package/components/dropdown/index.d.ts +1 -3
- package/components/dropdown/index.d.ts.map +1 -1
- package/components/icon/index.d.ts +10 -6
- package/components/icon/index.d.ts.map +1 -1
- package/components/icon/index.js +9 -3
- package/components/paginator/index.d.ts +34 -0
- package/components/paginator/index.d.ts.map +1 -0
- package/components/paginator/index.js +46 -0
- package/components/paginator/utils.d.ts +10 -0
- package/components/paginator/utils.d.ts.map +1 -0
- package/components/paginator/utils.js +18 -0
- package/components/search/index.d.ts +2 -2
- package/components/search/index.d.ts.map +1 -1
- package/components/types.d.ts +5 -3
- package/components/types.d.ts.map +1 -1
- package/dist +32 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.d.ts.map +1 -1
- package/hooks/index.js +1 -0
- package/hooks/usePagination.d.ts +18 -0
- package/hooks/usePagination.d.ts.map +1 -0
- package/hooks/usePagination.js +26 -0
- package/package.json +8 -4
- package/readme.md +21 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/anchor/components/anchorWithIcon/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/anchor/components/anchorWithIcon/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,iCAAiC;AACjC,eAAO,MAAM,cAAc,+DAAgE,mBAAmB,KAAG,WAqChH,CAAC"}
|
|
@@ -10,7 +10,7 @@ export const AnchorWithIcon = ({ href, className, onClick, caption, title, targe
|
|
|
10
10
|
? `${icon.className} app-icon--left`
|
|
11
11
|
: `${icon.className} app-icon--right`;
|
|
12
12
|
if (iconPosition === 'left') {
|
|
13
|
-
return (_jsxs("a", { href: href, className: className, title: title, target: target, onClick: onClick, children: [_jsx(Icon, { ...icon,
|
|
13
|
+
return (_jsxs("a", { href: href, className: className, title: title, target: target, onClick: onClick, children: [_jsx(Icon, { ...icon, name: iconClassName }), caption] }));
|
|
14
14
|
}
|
|
15
|
-
return (_jsxs("a", { href: href, className: className, title: title, target: target, onClick: onClick, children: [caption, _jsx(Icon, { ...icon,
|
|
15
|
+
return (_jsxs("a", { href: href, className: className, title: title, target: target, onClick: onClick, children: [caption, _jsx(Icon, { ...icon, name: iconClassName })] }));
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/buttonWithIcon/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/buttonWithIcon/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,iCAAiC;AACjC,eAAO,MAAM,cAAc,2DAA4D,mBAAmB,KAAG,WAsC5G,CAAC"}
|
|
@@ -13,7 +13,7 @@ export const ButtonWithIcon = ({ className, disabled, onClick, caption, title, i
|
|
|
13
13
|
? `${className} button--icon-only`
|
|
14
14
|
: className;
|
|
15
15
|
if (iconPosition === 'left') {
|
|
16
|
-
return (_jsxs("button", { className: className, disabled: disabled, onClick: onClick, title: title, children: [_jsx(Icon, { ...icon,
|
|
16
|
+
return (_jsxs("button", { className: className, disabled: disabled, onClick: onClick, title: title, children: [_jsx(Icon, { ...icon, name: iconClassName }), caption] }));
|
|
17
17
|
}
|
|
18
|
-
return (_jsxs("button", { className: className, disabled: disabled, onClick: onClick, title: title, children: [caption, _jsx(Icon, { ...icon,
|
|
18
|
+
return (_jsxs("button", { className: className, disabled: disabled, onClick: onClick, title: title, children: [caption, _jsx(Icon, { ...icon, name: iconClassName })] }));
|
|
19
19
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import './button.scss';
|
|
3
|
-
import { ElementIcon,
|
|
3
|
+
import { ElementIcon, ElementSize } from '../types';
|
|
4
4
|
import { ButtonType } from './types';
|
|
5
5
|
export declare type ButtonProps = {
|
|
6
6
|
/** Button displaying text */
|
|
@@ -10,7 +10,7 @@ export declare type ButtonProps = {
|
|
|
10
10
|
/** Configuration of inner icon */
|
|
11
11
|
icon?: ElementIcon;
|
|
12
12
|
/** Button size */
|
|
13
|
-
size?:
|
|
13
|
+
size?: ElementSize;
|
|
14
14
|
/** Title on hover */
|
|
15
15
|
title?: string;
|
|
16
16
|
/** Is button uses light version of color */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/button/index.tsx"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/button/index.tsx"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,oBAAY,WAAW,GAAG;IACtB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8BAA8B;IAC9B,IAAI,EAAE,UAAU,CAAC;IAEjB,kCAAkC;IAClC,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,mBAAmB;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,6CAA6C;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAkC9D"}
|
|
@@ -15,6 +15,6 @@ const DropdownLabel = ({ caption, selectedItem, onClick, deselectable }) => {
|
|
|
15
15
|
"button"
|
|
16
16
|
]);
|
|
17
17
|
return (_jsxs("label", { className: className, onClick: onClick, children: [deselectVisible &&
|
|
18
|
-
_jsx(Icon, {
|
|
18
|
+
_jsx(Icon, { name: "plus-lg" }), _jsx("span", { className: deselectVisible ? "mx-2" : "mr-2", title: itemSelected ? text : undefined, children: text }), _jsx(Icon, { name: "arrow-up" })] }));
|
|
19
19
|
};
|
|
20
20
|
export default DropdownLabel;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import './dropdown.scss';
|
|
3
2
|
import { SelectableItem } from './types';
|
|
4
3
|
import { BaseElementProps } from '../types';
|
|
@@ -11,8 +10,7 @@ export declare type DropdownProps = BaseElementProps & {
|
|
|
11
10
|
*/
|
|
12
11
|
value?: SelectableItem;
|
|
13
12
|
/**
|
|
14
|
-
* Action to update selected value,
|
|
15
|
-
* which stored outside
|
|
13
|
+
* Action to update selected value, which stored outside
|
|
16
14
|
*/
|
|
17
15
|
onSelect: (item?: SelectableItem) => void;
|
|
18
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/dropdown/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/dropdown/index.tsx"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK5C,oBAAY,aAAa,GAAG,gBAAgB,GAAG;IAC3C,kCAAkC;IAClC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAE7B;;;MAGE;IACF,KAAK,CAAC,EAAE,cAAc,CAAC;IAEvB;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAE1C;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB,gEAAgE;IAChE,gBAAgB,EAAE,OAAO,CAAC;IAE1B,wBAAwB;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAA;AAED,yBAAyB;AACzB,QAAA,MAAM,QAAQ,mFAAoF,aAAa,KAAG,WA2FjH,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import './icon.scss';
|
|
3
|
-
import {
|
|
3
|
+
import { ElementSize } from '../types';
|
|
4
4
|
/** Icon component props */
|
|
5
5
|
export declare type IconProps = {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Icon name. Must be without `bi-`
|
|
8
|
+
* @example ["Arrow repeat", "arrow-repeat"]
|
|
9
|
+
* // Icon name to icon class name.
|
|
10
|
+
* // For class name check bootstrap icons website
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
name: string;
|
|
13
|
+
/** Additional classname */
|
|
14
|
+
className?: string;
|
|
11
15
|
/** Icon size */
|
|
12
|
-
size?:
|
|
16
|
+
size?: ElementSize;
|
|
13
17
|
};
|
|
14
18
|
/**
|
|
15
19
|
* Icon component. Based on bootstrap icons
|
|
16
20
|
*/
|
|
17
|
-
export default function Icon(
|
|
21
|
+
export default function Icon({ size, name, className }: IconProps): JSX.Element;
|
|
18
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icon/index.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icon/index.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,2BAA2B;AAC3B,oBAAY,SAAS,GAAG;IACpB;;;;;MAKE;IACF,IAAI,EAAE,MAAM,CAAC;IAEb,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,gBAAgB;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;CACtB,CAAA;AAQD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,IAAe,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CAYzF"}
|
package/components/icon/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import './icon.scss';
|
|
3
|
+
import { getClassName } from '@bodynarf/utils';
|
|
3
4
|
const sizeToClassMap = new Map([
|
|
4
5
|
['small', ' app-icon--smal'],
|
|
5
6
|
['medium', ''],
|
|
@@ -8,8 +9,13 @@ const sizeToClassMap = new Map([
|
|
|
8
9
|
/**
|
|
9
10
|
* Icon component. Based on bootstrap icons
|
|
10
11
|
*/
|
|
11
|
-
export default function Icon(
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
export default function Icon({ size = 'medium', name, className }) {
|
|
13
|
+
const classNames = getClassName([
|
|
14
|
+
"app-icon",
|
|
15
|
+
"bi",
|
|
16
|
+
`bi-${name}`,
|
|
17
|
+
sizeToClassMap.has(size) ? sizeToClassMap.get(size) : "",
|
|
18
|
+
className
|
|
19
|
+
]);
|
|
14
20
|
return (_jsx("i", { className: className }));
|
|
15
21
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ElementSize } from '../types';
|
|
3
|
+
export declare type PaginatorProps = {
|
|
4
|
+
/** Amount of pages */
|
|
5
|
+
count: number;
|
|
6
|
+
/** Page change handler */
|
|
7
|
+
onPageChange: (page: number) => void;
|
|
8
|
+
/** Current page */
|
|
9
|
+
currentPage?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Page numbers position.
|
|
12
|
+
* Usefull with `showNextButtons = true`
|
|
13
|
+
*/
|
|
14
|
+
position?: 'left' | 'center' | 'right';
|
|
15
|
+
/** Buttons should have rounded borders */
|
|
16
|
+
rounded?: boolean;
|
|
17
|
+
/** Size of paginator component elements */
|
|
18
|
+
size?: ElementSize;
|
|
19
|
+
/** Additional class names */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** Display "Previous" \ "Next" buttons */
|
|
22
|
+
showNextButtons?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Max amount of pages from left & right from current page. `3` by default
|
|
25
|
+
* @description If set to 2 it will show `[1, 2], 3, [4, 5]`
|
|
26
|
+
*/
|
|
27
|
+
nearPagesCount?: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Paginator component.
|
|
31
|
+
* Used for visualization of pagging configuration
|
|
32
|
+
*/
|
|
33
|
+
export default function Paginator({ count, onPageChange, currentPage, position, rounded, size, className, showNextButtons, nearPagesCount }: PaginatorProps): JSX.Element;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/paginator/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC,oBAAY,cAAc,GAAG;IACzB,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IAEd,0BAA0B;IAC1B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAErC,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;MAGE;IACF,QAAQ,CAAC,EACP,MAAM,GACN,QAAQ,GACR,OAAO,CACR;IAED,0CAA0C;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,0CAA0C;IAC1C,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;MAGE;IACF,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAA;AAED;;;EAGE;AACF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAC9B,KAAK,EAAE,YAAY,EAAE,WAAW,EAChC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAClC,eAAe,EAAE,cAAc,EAClC,EAAE,cAAc,GAAG,GAAG,CAAC,OAAO,CA2G9B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { getClassName, isNullOrEmpty } from '@bodynarf/utils';
|
|
4
|
+
import { generatePageNumbers } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* Paginator component.
|
|
7
|
+
* Used for visualization of pagging configuration
|
|
8
|
+
*/
|
|
9
|
+
export default function Paginator({ count, onPageChange, currentPage, position, rounded, size, className, showNextButtons, nearPagesCount }) {
|
|
10
|
+
const page = currentPage || 0;
|
|
11
|
+
const pageChange = useCallback((event) => {
|
|
12
|
+
const target = event.target;
|
|
13
|
+
const pageRaw = target.dataset['page'];
|
|
14
|
+
if (isNullOrEmpty(pageRaw)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const page = +pageRaw;
|
|
18
|
+
if (page !== currentPage && page > 0 && page <= count) {
|
|
19
|
+
onPageChange(page);
|
|
20
|
+
}
|
|
21
|
+
}, [onPageChange, currentPage, count]);
|
|
22
|
+
const pageNumbers = useMemo(() => generatePageNumbers(page, count, nearPagesCount), [page, count]);
|
|
23
|
+
const canGoBack = useMemo(() => page > 1, [page]);
|
|
24
|
+
const canGoForward = useMemo(() => page < count, [page, count]);
|
|
25
|
+
if (pageNumbers.length === 0) {
|
|
26
|
+
return _jsx(_Fragment, {});
|
|
27
|
+
}
|
|
28
|
+
const classNames = getClassName([
|
|
29
|
+
"pagination",
|
|
30
|
+
paginationPositionToClassMap.has(position || "") ? paginationPositionToClassMap.get(position || "") : "",
|
|
31
|
+
rounded == true ? "is-rounded" : "",
|
|
32
|
+
isNullOrEmpty(size) ? "" : `is-${size}`,
|
|
33
|
+
className
|
|
34
|
+
]);
|
|
35
|
+
return (_jsxs("nav", { className: classNames, role: "navigation", "aria-label": "pagination", children: [showNextButtons === true &&
|
|
36
|
+
_jsxs(_Fragment, { children: [_jsx("a", { className: `pagination-previous${canGoBack ? "" : " is-disabled"}`, "data-page": page - 1, onClick: pageChange, children: "Previous" }), _jsx("a", { className: `pagination-next${canGoForward ? "" : " is-disabled"}`, "data-page": page + 1, onClick: pageChange, children: "Next page" })] }), _jsxs("ul", { className: "pagination-list", children: [page !== 1 && !pageNumbers.includes(1) &&
|
|
37
|
+
_jsxs(_Fragment, { children: [_jsx("li", { children: _jsx("a", { className: "pagination-link", "aria-label": "Goto page 1", "data-page": 1, onClick: pageChange, children: "1" }) }), _jsx("li", { children: _jsx("span", { className: "pagination-ellipsis", children: "\u2026" }) })] }), pageNumbers.map(x => _jsx("li", { children: _jsx("a", { className: `pagination-link${page === x ? " is-current" : ""}`, "aria-label": `Goto page ${x}`, "data-page": x, onClick: pageChange, children: x }) }, x)), page != count && !pageNumbers.includes(count) &&
|
|
38
|
+
_jsxs(_Fragment, { children: [_jsx("li", { children: _jsx("span", { className: "pagination-ellipsis", children: "\u2026" }) }), _jsx("li", { children: _jsx("a", { className: "pagination-link", "aria-label": `Goto page ${count}`, "data-page": count, onClick: pageChange, children: count }) })] })] })] }));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Position setting to css class name map
|
|
42
|
+
*/
|
|
43
|
+
const paginationPositionToClassMap = new Map([
|
|
44
|
+
["center", "is-centered"],
|
|
45
|
+
["right", "is-right"]
|
|
46
|
+
]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get nearest numbers from each side (left & right)
|
|
3
|
+
* @param page Number of current page
|
|
4
|
+
* @param count Amount of pages
|
|
5
|
+
* @param size Amount of pages from left & right to current page. Default is 3
|
|
6
|
+
* @throws Current page is greater than pages amount
|
|
7
|
+
* @returns Array of nearest numbers to current page
|
|
8
|
+
*/
|
|
9
|
+
export declare const generatePageNumbers: (page: number, count: number, size?: number) => Array<number>;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/paginator/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,SAAU,MAAM,SAAS,MAAM,SAAQ,MAAM,KAAO,MAAM,MAAM,CAU/F,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get nearest numbers from each side (left & right)
|
|
3
|
+
* @param page Number of current page
|
|
4
|
+
* @param count Amount of pages
|
|
5
|
+
* @param size Amount of pages from left & right to current page. Default is 3
|
|
6
|
+
* @throws Current page is greater than pages amount
|
|
7
|
+
* @returns Array of nearest numbers to current page
|
|
8
|
+
*/
|
|
9
|
+
export const generatePageNumbers = (page, count, size = 3) => {
|
|
10
|
+
if (page < 0 || count <= 0 || page > count || size > count) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return [
|
|
14
|
+
...new Array(size).fill(page).map((_, i) => page - i - 1).filter(x => x > 0 && x < page).reverse(),
|
|
15
|
+
page,
|
|
16
|
+
...new Array(size).fill(page).map((_, i) => page + i + 1).filter(x => x > 0 && x > page && x <= count)
|
|
17
|
+
];
|
|
18
|
+
};
|
|
@@ -10,7 +10,7 @@ export declare type SearchProps = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Search type: by typing, starts from minimum characters to search
|
|
12
12
|
* or by clicking on button next to search bar.
|
|
13
|
-
* Default is byTyping
|
|
13
|
+
* Default `is byTyping`
|
|
14
14
|
*/
|
|
15
15
|
searchType?: 'byTyping' | 'byButton';
|
|
16
16
|
/** Control name. If empty - will be replaced by random guid */
|
|
@@ -23,7 +23,7 @@ export declare type SearchProps = {
|
|
|
23
23
|
rounded?: boolean;
|
|
24
24
|
/** Is search bar disabled */
|
|
25
25
|
disabled?: boolean;
|
|
26
|
-
/** Should loading icon be displayed in search bar*/
|
|
26
|
+
/** Should loading icon be displayed in search bar */
|
|
27
27
|
isLoading?: boolean;
|
|
28
28
|
};
|
|
29
29
|
/** Search component */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/search/index.tsx"],"names":[],"mappings":";AAIA,OAAO,eAAe,CAAC;AAIvB,oBAAY,WAAW,GAAG;IACtB,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAEhB,qBAAqB;IACrB,QAAQ,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;MAIE;IACF,UAAU,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAErC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,yBAAyB;IACzB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAE/C,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/search/index.tsx"],"names":[],"mappings":";AAIA,OAAO,eAAe,CAAC;AAIvB,oBAAY,WAAW,GAAG;IACtB,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAEhB,qBAAqB;IACrB,QAAQ,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;MAIE;IACF,UAAU,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAErC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,yBAAyB;IACzB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAE/C,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,qDAAqD;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,uBAAuB;AACvB,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CA+E9D"}
|
package/components/types.d.ts
CHANGED
|
@@ -10,9 +10,11 @@ export declare type BaseElementProps = {
|
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
/** Allowed element sizes */
|
|
14
|
+
export declare type ElementSize = 'small' | 'medium' /** default size */ | 'large';
|
|
15
|
+
/** Allowed icon position */
|
|
14
16
|
export declare type IconPosition = 'left' | 'right';
|
|
15
|
-
/** Icon for component
|
|
17
|
+
/** Icon for component */
|
|
16
18
|
export declare type ElementIcon = {
|
|
17
19
|
/**
|
|
18
20
|
* Class name for icon.
|
|
@@ -20,7 +22,7 @@ export declare type ElementIcon = {
|
|
|
20
22
|
*/
|
|
21
23
|
className: string;
|
|
22
24
|
/** Icon size */
|
|
23
|
-
size?:
|
|
25
|
+
size?: ElementSize;
|
|
24
26
|
/**
|
|
25
27
|
* Position
|
|
26
28
|
* Works only with other content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oBAAY,gBAAgB,GAAG;IAC3B,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8BAA8B;IAC9B,IAAI,CAAC,EAAE;QACH,8CAA8C;QAC9C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACtB,CAAC;CACL,CAAC;AAEF,oBAAY,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oBAAY,gBAAgB,GAAG;IAC3B,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8BAA8B;IAC9B,IAAI,CAAC,EAAE;QACH,8CAA8C;QAC9C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACtB,CAAC;CACL,CAAC;AAEF,4BAA4B;AAC5B,oBAAY,WAAW,GACjB,OAAO,GACP,QAAQ,CAAC,mBAAmB,GAC5B,OAAO,CAAC;AAEd,4BAA4B;AAC5B,oBAAY,YAAY,GAClB,MAAM,GACN,OAAO,CAAC;AAEd,0BAA0B;AAC1B,oBAAY,WAAW,GAAG;IACtB;;;MAGE;IACF,SAAS,EAAE,MAAM,CAAC;IAElB,gBAAgB;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB;;;MAGE;IACF,QAAQ,CAAC,EAAE,YAAY,CAAC;CAC3B,CAAC"}
|
package/dist
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# About
|
|
2
|
+
Small library with react components based on Bulma CSS framework <a href="https://bulma.io" title="Bulma css framework">
|
|
3
|
+
<img
|
|
4
|
+
src="https://bulma.io/images/made-with-bulma.png"
|
|
5
|
+
alt="Made with Bulma"
|
|
6
|
+
width="128"
|
|
7
|
+
height="24"/>
|
|
8
|
+
</a>
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
1. Install [React](https://reactjs.org/)
|
|
12
|
+
2. Install [Bulma](https://bulma.io/)
|
|
13
|
+
3. Make sure you imported bulma styles in parent container
|
|
14
|
+
4. *(Optional)* To use **Icon** component - install [Bootstrap Icons](https://icons.getbootstrap.com/) and make sure you imported these styles in parent container
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
### Simple components
|
|
18
|
+
Simple react components based on html elements.
|
|
19
|
+
|
|
20
|
+
- **Date** - date input;
|
|
21
|
+
- **Multiline** - multiline text input;
|
|
22
|
+
- **Text**- single line text input;
|
|
23
|
+
- **Anchor**
|
|
24
|
+
- **Button**
|
|
25
|
+
- **Icon** - *see p.4 of installation*
|
|
26
|
+
- **Dropdown** - custom dropdown component, based on html div elements & css. Allows to use icon in elements
|
|
27
|
+
|
|
28
|
+
### Complex components
|
|
29
|
+
Complex components is set of components built via combining simple components or represent complex logical component
|
|
30
|
+
- **Search** - Search bar with optional button to perform search
|
|
31
|
+
- **Paginator** - Pagination elements to navigate through paged list
|
|
32
|
+
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC"}
|
package/hooks/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Paginator hook state */
|
|
2
|
+
export interface PaginationState {
|
|
3
|
+
/** Number of current page */
|
|
4
|
+
currentPage: number;
|
|
5
|
+
/** Amount of pages */
|
|
6
|
+
pagesCount: number;
|
|
7
|
+
/** Handler of page change */
|
|
8
|
+
onPageChange: (page: number) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Hook to pagination state, return hooked values and handler for pagination
|
|
12
|
+
* @param length Pagionation items count
|
|
13
|
+
* @param size Page size. Default is 30
|
|
14
|
+
* @param initPage Initial page. Default is 1
|
|
15
|
+
* @returns Pair of hook-stored state and handler for slicing current page items
|
|
16
|
+
*/
|
|
17
|
+
export declare const usePagination: (length: number, size?: number, initPage?: number) => [PaginationState, (data: Array<any>) => Array<any>];
|
|
18
|
+
//# sourceMappingURL=usePagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePagination.d.ts","sourceRoot":"","sources":["../../src/hooks/usePagination.ts"],"names":[],"mappings":"AAEA,2BAA2B;AAC3B,MAAM,WAAW,eAAe;IAC5B,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IAEpB,sBAAsB;IACtB,UAAU,EAAE,MAAM,CAAC;IAEnB,6BAA6B;IAC7B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,WAAY,MAAM,SAAQ,MAAM,aAA8B,MAAM,8BAAgC,MAAM,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC,CAsBtJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
/** Default page size */
|
|
3
|
+
const defaultPageSize = 30;
|
|
4
|
+
/**
|
|
5
|
+
* Hook to pagination state, return hooked values and handler for pagination
|
|
6
|
+
* @param length Pagionation items count
|
|
7
|
+
* @param size Page size. Default is 30
|
|
8
|
+
* @param initPage Initial page. Default is 1
|
|
9
|
+
* @returns Pair of hook-stored state and handler for slicing current page items
|
|
10
|
+
*/
|
|
11
|
+
export const usePagination = (length, size = defaultPageSize, initPage = 1) => {
|
|
12
|
+
const [currentPage, setCurrentPage] = useState(initPage);
|
|
13
|
+
const count = useMemo(() => Math.ceil(length / size), [size, length]);
|
|
14
|
+
const onChange = useCallback((page) => setCurrentPage(page), [setCurrentPage]);
|
|
15
|
+
const paginate = useCallback((data) => {
|
|
16
|
+
const limit = size;
|
|
17
|
+
const offstet = (currentPage - 1) * size;
|
|
18
|
+
return data.slice(offstet, offstet + limit);
|
|
19
|
+
}, [size, currentPage]);
|
|
20
|
+
const state = useMemo(() => ({
|
|
21
|
+
currentPage: currentPage,
|
|
22
|
+
pagesCount: count,
|
|
23
|
+
onPageChange: onChange
|
|
24
|
+
}), [currentPage, count, onChange]);
|
|
25
|
+
return [state, paginate];
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodynarf/react.components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Artem",
|
|
6
6
|
"email": "bodynar@gmail.com"
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"react component",
|
|
21
21
|
"bulma"
|
|
22
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "npx tsc",
|
|
25
|
+
"publish": "npx tsc && copy package.json dist && copy readme.md dist && cd dist && npm publish --access=public"
|
|
26
|
+
},
|
|
23
27
|
"devDependencies": {
|
|
24
28
|
"@types/react": "^18.0.11",
|
|
25
29
|
"@types/react-dom": "^18.0.5",
|
|
@@ -27,8 +31,8 @@
|
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"@bodynarf/utils": "^1.0.10",
|
|
34
|
+
"bulma": "^0.9.4",
|
|
30
35
|
"react": "^18.1.0",
|
|
31
|
-
"react-dom": "^18.1.0"
|
|
32
|
-
"bulma": "^0.9.4"
|
|
36
|
+
"react-dom": "^18.1.0"
|
|
33
37
|
}
|
|
34
|
-
}
|
|
38
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# About
|
|
2
|
-
Small library with react components based on Bulma
|
|
3
|
-
|
|
4
|
-
<a href="https://bulma.io" title="Bulma css framework">
|
|
2
|
+
Small library with react components based on Bulma CSS framework <a href="https://bulma.io" title="Bulma css framework">
|
|
5
3
|
<img
|
|
6
4
|
src="https://bulma.io/images/made-with-bulma.png"
|
|
7
5
|
alt="Made with Bulma"
|
|
@@ -9,13 +7,26 @@ Small library with react components based on Bulma
|
|
|
9
7
|
height="24"/>
|
|
10
8
|
</a>
|
|
11
9
|
|
|
10
|
+
## Installation
|
|
11
|
+
1. Install [React](https://reactjs.org/)
|
|
12
|
+
2. Install [Bulma](https://bulma.io/)
|
|
13
|
+
3. Make sure you imported bulma styles in parent container
|
|
14
|
+
4. *(Optional)* To use **Icon** component - install [Bootstrap Icons](https://icons.getbootstrap.com/) and make sure you imported these styles in parent container
|
|
15
|
+
|
|
12
16
|
## Description
|
|
13
|
-
|
|
17
|
+
### Simple components
|
|
18
|
+
Simple react components based on html elements.
|
|
19
|
+
|
|
20
|
+
- **Date** - date input;
|
|
21
|
+
- **Multiline** - multiline text input;
|
|
22
|
+
- **Text**- single line text input;
|
|
14
23
|
- **Anchor**
|
|
15
24
|
- **Button**
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- **
|
|
25
|
+
- **Icon** - *see p.4 of installation*
|
|
26
|
+
- **Dropdown** - custom dropdown component, based on html div elements & css. Allows to use icon in elements
|
|
27
|
+
|
|
28
|
+
### Complex components
|
|
29
|
+
Complex components is set of components built via combining simple components or represent complex logical component
|
|
30
|
+
- **Search** - Search bar with optional button to perform search
|
|
31
|
+
- **Paginator** - Pagination elements to navigate through paged list
|
|
32
|
+
|