@bodynarf/react.components 1.1.4 → 1.2.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.
Files changed (42) hide show
  1. package/components/anchor/components/anchorWithIcon/index.d.ts +0 -1
  2. package/components/anchor/components/anchorWithIcon/index.d.ts.map +1 -1
  3. package/components/anchor/components/anchorWithIcon/index.js +2 -2
  4. package/components/anchor/index.js +4 -4
  5. package/components/button/components/buttonWithIcon/index.d.ts +0 -1
  6. package/components/button/components/buttonWithIcon/index.d.ts.map +1 -1
  7. package/components/button/components/buttonWithIcon/index.js +3 -3
  8. package/components/button/index.d.ts +2 -2
  9. package/components/button/index.d.ts.map +1 -1
  10. package/components/button/index.js +12 -10
  11. package/components/dropdown/components/dropdownLabel/index.d.ts.map +1 -1
  12. package/components/dropdown/components/dropdownLabel/index.js +4 -5
  13. package/components/dropdown/index.d.ts +0 -1
  14. package/components/dropdown/index.d.ts.map +1 -1
  15. package/components/dropdown/index.js +7 -9
  16. package/components/icon/index.d.ts +2 -2
  17. package/components/icon/index.d.ts.map +1 -1
  18. package/components/paginator/index.d.ts +29 -0
  19. package/components/paginator/index.d.ts.map +1 -0
  20. package/components/paginator/index.js +47 -0
  21. package/components/paginator/utils.d.ts +10 -0
  22. package/components/paginator/utils.d.ts.map +1 -0
  23. package/components/paginator/utils.js +18 -0
  24. package/components/primitives/date/index.js +5 -5
  25. package/components/primitives/multiline/components/multilineWithLabel/index.js +4 -4
  26. package/components/primitives/multiline/components/multilineWithoutLabel/index.js +4 -4
  27. package/components/primitives/multiline/index.js +2 -2
  28. package/components/primitives/text/components/textWithLabel/index.js +4 -4
  29. package/components/primitives/text/components/textWithoutLabel/index.js +4 -4
  30. package/components/primitives/text/index.js +2 -2
  31. package/components/search/index.d.ts.map +1 -1
  32. package/components/search/index.js +15 -13
  33. package/components/types.d.ts +5 -3
  34. package/components/types.d.ts.map +1 -1
  35. package/hooks/index.d.ts +1 -0
  36. package/hooks/index.d.ts.map +1 -1
  37. package/hooks/index.js +1 -0
  38. package/hooks/useComponentOutsideClick.js +4 -4
  39. package/hooks/usePagination.d.ts +18 -0
  40. package/hooks/usePagination.d.ts.map +1 -0
  41. package/hooks/usePagination.js +26 -0
  42. package/package.json +8 -4
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { AnchorWithIconProps } from "../../types";
3
2
  /** Anchor with icon component */
4
3
  export declare const AnchorWithIcon: ({ href, className, onClick, caption, title, target, icon }: AnchorWithIconProps) => JSX.Element;
@@ -1 +1 @@
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"}
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"}
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrEmpty } from '@bodynarf/utils';
3
3
  import Icon from '../../../icon';
4
4
  /** Anchor with icon component */
5
5
  export const AnchorWithIcon = ({ href, className, onClick, caption, title, target, icon }) => {
6
6
  const iconPosition = icon.position || 'left';
7
- const iconClassName = utils.isNullOrEmpty(caption)
7
+ const iconClassName = isNullOrEmpty(caption)
8
8
  ? icon.className
9
9
  : iconPosition === 'left'
10
10
  ? `${icon.className} app-icon--left`
@@ -1,17 +1,17 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrUndefined, isNullOrEmpty } from '@bodynarf/utils';
3
3
  import './anchor.scss';
4
4
  import { SimpleAnchor } from './components/simpleAnchor';
5
5
  import { AnchorWithIcon } from './components/anchorWithIcon';
6
6
  /** Anchor component */
7
7
  export default function Anchor(props) {
8
- if (utils.isNullOrUndefined(props.caption) && utils.isNullOrUndefined(props.icon)) {
8
+ if (isNullOrUndefined(props.caption) && isNullOrUndefined(props.icon)) {
9
9
  throw new Error("No anchor content provided");
10
10
  }
11
11
  const className = 'app-anchor'
12
- + (!utils.isNullOrEmpty(props.className) ? ` ${props.className}` : '')
12
+ + (!isNullOrEmpty(props.className) ? ` ${props.className}` : '')
13
13
  + (props.disableHovering === true ? ' app-anchor--unhoverable' : '');
14
- if (utils.isNullOrUndefined(props.icon)) {
14
+ if (isNullOrUndefined(props.icon)) {
15
15
  return (_jsx(SimpleAnchor, { ...props, className: className, onClick: props.onClick }));
16
16
  }
17
17
  return (_jsx(AnchorWithIcon, { ...props, className: className, onClick: props.onClick, icon: props.icon }));
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ButtonWithIconProps } from '../../types';
3
2
  /** Button with icon component */
4
3
  export declare const ButtonWithIcon: ({ className, disabled, onClick, caption, title, icon }: ButtonWithIconProps) => JSX.Element;
@@ -1 +1 @@
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"}
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"}
@@ -1,15 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrEmpty } from '@bodynarf/utils';
3
3
  import Icon from '../../../icon';
4
4
  /** Button with icon component */
5
5
  export const ButtonWithIcon = ({ className, disabled, onClick, caption, title, icon }) => {
6
6
  const iconPosition = icon.position || 'left';
7
- const iconClassName = utils.isNullOrEmpty(caption)
7
+ const iconClassName = isNullOrEmpty(caption)
8
8
  ? icon.className
9
9
  : iconPosition === 'left'
10
10
  ? `${icon.className} app-icon--left`
11
11
  : `${icon.className} app-icon--right`;
12
- className = utils.isNullOrEmpty(caption)
12
+ className = isNullOrEmpty(caption)
13
13
  ? `${className} button--icon-only`
14
14
  : className;
15
15
  if (iconPosition === 'left') {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import './button.scss';
3
- import { ElementIcon, IconSize } from '../types';
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?: IconSize;
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,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEjD,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,QAAQ,CAAC;IAEhB,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,CAiC9D"}
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"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrEmpty, isStringEmpty, isNullOrUndefined, getClassName } from '@bodynarf/utils';
3
3
  import './button.scss';
4
4
  import { ButtonWithIcon } from './components/buttonWithIcon';
5
5
  import { SimpleButton } from './components/simpleButton';
@@ -8,17 +8,19 @@ import { SimpleButton } from './components/simpleButton';
8
8
  * @throws Caption is not defined and icon configuration is not defined at the same time
9
9
  */
10
10
  export default function Button(props) {
11
- if ((utils.isNullOrEmpty(props.caption))
12
- && (utils.isNullOrUndefined(props.icon) || utils.isStringEmpty(props.icon?.className))) {
11
+ if ((isNullOrEmpty(props.caption))
12
+ && (isNullOrUndefined(props.icon) || isStringEmpty(props.icon?.className))) {
13
13
  throw new Error("No button content provided.");
14
14
  }
15
- const className = `button is-${props.type}`
16
- + (props.light === true ? ' is-light' : '')
17
- + (!utils.isNullOrUndefined(props.size) ? ` is-${props.size}` : '')
18
- + (props.outlined === true ? ' is-outlined' : '')
19
- + (props.rounded === true ? ' is-rounded' : '')
20
- + (props.isLoading === true ? ' is-loading' : '');
21
- if (!utils.isNullOrUndefined(props.icon)) {
15
+ const className = getClassName([
16
+ `button is-${props.type}`,
17
+ props.light === true ? 'is-light' : '',
18
+ !isNullOrUndefined(props.size) ? `is-${props.size}` : '',
19
+ props.outlined === true ? 'is-outlined' : '',
20
+ props.rounded === true ? 'is-rounded' : '',
21
+ props.isLoading === true ? 'is-loading' : '',
22
+ ]);
23
+ if (!isNullOrUndefined(props.icon)) {
22
24
  return (_jsx(ButtonWithIcon, { ...props, className: className, onClick: props.onClick, icon: props.icon }));
23
25
  }
24
26
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/dropdown/components/dropdownLabel/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,UAAU,kBAAkB;IACxB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAEhB,wBAAwB;IACxB,YAAY,EAAE,OAAO,CAAC;IAEtB,oBAAoB;IACpB,YAAY,CAAC,EAAE,cAAc,CAAC;IAE9B,mBAAmB;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CAC1D;AAED,sBAAsB;AACtB,QAAA,MAAM,aAAa,qDAAsD,kBAAkB,KAAG,WAkC7F,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/dropdown/components/dropdownLabel/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,UAAU,kBAAkB;IACxB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAEhB,wBAAwB;IACxB,YAAY,EAAE,OAAO,CAAC;IAEtB,oBAAoB;IACpB,YAAY,CAAC,EAAE,cAAc,CAAC;IAE9B,mBAAmB;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CAC1D;AAED,sBAAsB;AACtB,QAAA,MAAM,aAAa,qDAAsD,kBAAkB,KAAG,WAiC7F,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,20 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import utils from "@bodynarf/utils";
2
+ import { getClassName, isNullOrUndefined } from "@bodynarf/utils";
3
3
  import Icon from '../../../icon';
4
4
  /** Label component */
5
5
  const DropdownLabel = ({ caption, selectedItem, onClick, deselectable }) => {
6
- const itemSelected = !utils.isNullOrUndefined(selectedItem);
6
+ const itemSelected = !isNullOrUndefined(selectedItem);
7
7
  const text = itemSelected
8
8
  ? selectedItem?.displayValue
9
9
  : caption;
10
10
  const deselectVisible = deselectable && itemSelected;
11
- const className = [
11
+ const className = getClassName([
12
12
  "dropdown-trigger",
13
13
  "app-dropdown__label",
14
14
  itemSelected ? "" : "app-dropdown__label--default",
15
15
  "button"
16
- ].filter(x => !utils.isNullOrEmpty(x))
17
- .join(" ");
16
+ ]);
18
17
  return (_jsxs("label", { className: className, onClick: onClick, children: [deselectVisible &&
19
18
  _jsx(Icon, { className: "plus-lg" }), _jsx("span", { className: deselectVisible ? "mx-2" : "mr-2", title: itemSelected ? text : undefined, children: text }), _jsx(Icon, { className: "arrow-up" })] }));
20
19
  };
@@ -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';
@@ -1 +1 @@
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;;;OAGG;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,WA6FjH,CAAC;AAEF,eAAe,QAAQ,CAAC"}
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;;;OAGG;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,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useId, useState } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { isNullOrUndefined, isNullOrEmpty, getClassName } from '@bodynarf/utils';
4
4
  import './dropdown.scss';
5
5
  import { useComponentOutsideClick } from '../../hooks/useComponentOutsideClick';
6
6
  import DropdownItem from './components/dropdownItem';
@@ -11,15 +11,15 @@ const Dropdown = ({ value, items, onSelect, caption, deselectable, className, hi
11
11
  const [isListVisible, setListVisible] = useState(false);
12
12
  const onItemClick = useCallback((event) => {
13
13
  const target = event.target;
14
- if (utils.isNullOrUndefined(target)) {
14
+ if (isNullOrUndefined(target)) {
15
15
  return;
16
16
  }
17
17
  const dataValue = target.dataset['dropdownItemValue'];
18
- if (utils.isNullOrEmpty(dataValue)) {
18
+ if (isNullOrEmpty(dataValue)) {
19
19
  return;
20
20
  }
21
21
  const item = items.find(x => x.value === dataValue);
22
- if (utils.isNullOrUndefined(item)) {
22
+ if (isNullOrUndefined(item)) {
23
23
  return;
24
24
  }
25
25
  if (value === item) {
@@ -31,7 +31,7 @@ const Dropdown = ({ value, items, onSelect, caption, deselectable, className, hi
31
31
  }, [setListVisible, value, items, onSelect]);
32
32
  const onLabelClick = useCallback((event) => {
33
33
  const target = event.target;
34
- if (utils.isNullOrUndefined(target)) {
34
+ if (isNullOrUndefined(target)) {
35
35
  return;
36
36
  }
37
37
  if (target.classList.contains("bi-plus-lg")) {
@@ -42,14 +42,12 @@ const Dropdown = ({ value, items, onSelect, caption, deselectable, className, hi
42
42
  }
43
43
  }, [onSelect, setListVisible]);
44
44
  useComponentOutsideClick(`[data-dropdown-id="${id}"]`, isListVisible, () => setListVisible(false), hideOnOuterClick);
45
- const classNames = [
45
+ const classNames = getClassName([
46
46
  "app-dropdown",
47
47
  isListVisible ? "is-active" : "",
48
48
  className,
49
49
  "dropdown"
50
- ]
51
- .filter(x => !utils.isNullOrEmpty(x))
52
- .join(" ");
50
+ ]);
53
51
  return (_jsxs("div", { className: classNames, "data-dropdown-id": id, children: [_jsx(DropdownLabel, { caption: caption, deselectable: deselectable === true, selectedItem: value, onClick: onLabelClick }), _jsx("div", { className: "dropdown-menu", children: items.length > 0
54
52
  ? _jsx("ul", { className: "dropdown-content", children: items.map(item => _jsx(DropdownItem, { item: item, selected: value?.value === item.value, onClick: onItemClick }, item.id)) })
55
53
  : _jsx("span", { className: "dropdown-content dropdown-item", children: "No items found" }) })] }, id));
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import './icon.scss';
3
- import { IconSize } from '../types';
3
+ import { ElementSize } from '../types';
4
4
  /** Icon component props */
5
5
  export declare type IconProps = {
6
6
  /**
@@ -9,7 +9,7 @@ export declare type IconProps = {
9
9
  */
10
10
  className: string;
11
11
  /** Icon size */
12
- size?: IconSize;
12
+ size?: ElementSize;
13
13
  };
14
14
  /**
15
15
  * Icon component. Based on bootstrap icons
@@ -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,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,2BAA2B;AAC3B,oBAAY,SAAS,GAAG;IACpB;;;MAGE;IACF,SAAS,EAAE,MAAM,CAAC;IAElB,gBAAgB;IAChB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAA;AAQD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CAQ1D"}
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;AAEvC,2BAA2B;AAC3B,oBAAY,SAAS,GAAG;IACpB;;;MAGE;IACF,SAAS,EAAE,MAAM,CAAC;IAElB,gBAAgB;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;CACtB,CAAA;AAQD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CAQ1D"}
@@ -0,0 +1,29 @@
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. Starts from 1 */
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
+ /**
25
+ * Paginator component.
26
+ * Used for visualization of pagging configuration
27
+ */
28
+ export default function Paginator({ count, onPageChange, currentPage, position, rounded, size, className, showNextButtons, }: PaginatorProps): JSX.Element;
29
+ //# 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,kCAAkC;IAClC,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;CAC7B,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,GAClB,EAAE,cAAc,GAAG,GAAG,CAAC,OAAO,CA4G9B"}
@@ -0,0 +1,47 @@
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, }) {
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
19
+ && page > 0 && page <= count) {
20
+ onPageChange(page);
21
+ }
22
+ }, [onPageChange, currentPage, count]);
23
+ const pageNumbers = useMemo(() => generatePageNumbers(page, count), [page, count]);
24
+ const canGoBack = useMemo(() => page > 1, [page]);
25
+ const canGoForward = useMemo(() => page < count, [page, count]);
26
+ if (pageNumbers.length === 0) {
27
+ return _jsx(_Fragment, {});
28
+ }
29
+ const classNames = getClassName([
30
+ "pagination",
31
+ paginationPositionToClassMap.has(position || "") ? paginationPositionToClassMap.get(position || "") : "",
32
+ rounded == true ? "is-rounded" : "",
33
+ isNullOrEmpty(size) ? "" : `is-${size}`,
34
+ className
35
+ ]);
36
+ return (_jsxs("nav", { className: classNames, role: "navigation", "aria-label": "pagination", children: [showNextButtons === true &&
37
+ _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) &&
38
+ _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) &&
39
+ _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 }) })] })] })] }));
40
+ }
41
+ /**
42
+ * Position setting to css class name map
43
+ */
44
+ const paginationPositionToClassMap = new Map([
45
+ ["center", "is-centered"],
46
+ ["right", "is-right"]
47
+ ]);
@@ -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
+ throw new Error("getPageNumbers has ivalid config");
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
+ };
@@ -1,22 +1,22 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName, isStringEmpty } from '@bodynarf/utils';
4
4
  /** Date input component */
5
5
  const DatePicker = (props) => {
6
- const onValueChange = useCallback((event) => props.onValueChange(utils.isStringEmpty(event.target.value)
6
+ const onValueChange = useCallback((event) => props.onValueChange(isStringEmpty(event.target.value)
7
7
  ? undefined
8
8
  : new Date(event.target.value)),
9
9
  // eslint-disable-next-line react-hooks/exhaustive-deps
10
10
  [props.onValueChange]);
11
- const id = props.name || utils.generateGuid();
11
+ const id = props.name || generateGuid();
12
12
  const size = `is-${(props.size || 'normal')}`;
13
- const className = utils.getClassName([
13
+ const className = getClassName([
14
14
  props.className,
15
15
  size,
16
16
  props.rounded === true ? 'is-rounded' : '',
17
17
  "input",
18
18
  ]);
19
- const inputContainerClassName = utils.getClassName([
19
+ const inputContainerClassName = getClassName([
20
20
  "control",
21
21
  props.loading === true ? 'is-loading' : '',
22
22
  (props.style || 'default') === 'default' ? '' : `is-${props.style}`
@@ -1,21 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName } from '@bodynarf/utils';
4
4
  /** Multiline textual input component with describing label */
5
5
  const MultilineWithLabel = (props) => {
6
6
  const onValueChange = useCallback((event) => props.onValueChange(event.target.value),
7
7
  // eslint-disable-next-line react-hooks/exhaustive-deps
8
8
  [props.onValueChange]);
9
- const id = props.name || utils.generateGuid();
9
+ const id = props.name || generateGuid();
10
10
  const size = `is-${(props.size || 'normal')}`;
11
- const className = utils.getClassName([
11
+ const className = getClassName([
12
12
  props.className,
13
13
  size,
14
14
  props.rounded === true ? 'is-rounded' : '',
15
15
  "textarea",
16
16
  props.fixed === true ? 'has-fixed-size' : '',
17
17
  ]);
18
- const inputContainerClassName = utils.getClassName([
18
+ const inputContainerClassName = getClassName([
19
19
  "control",
20
20
  props.loading === true ? 'is-loading' : '',
21
21
  (props.style || 'default') === 'default' ? '' : `is-${props.style}`
@@ -1,21 +1,21 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName } from '@bodynarf/utils';
4
4
  /** Multiline textual input component without describing label*/
5
5
  const MultilineWithoutLabel = (props) => {
6
6
  const onValueChange = useCallback((event) => props.onValueChange(event.target.value),
7
7
  // eslint-disable-next-line react-hooks/exhaustive-deps
8
8
  [props.onValueChange]);
9
- const id = props.name || utils.generateGuid();
9
+ const id = props.name || generateGuid();
10
10
  const size = `is-${(props.size || 'normal')}`;
11
- const className = utils.getClassName([
11
+ const className = getClassName([
12
12
  props.className,
13
13
  size,
14
14
  props.rounded === true ? 'is-rounded' : '',
15
15
  "textarea",
16
16
  props.fixed === true ? 'has-fixed-size' : '',
17
17
  ]);
18
- const inputContainerClassName = utils.getClassName([
18
+ const inputContainerClassName = getClassName([
19
19
  "control",
20
20
  props.loading === true ? 'is-loading' : '',
21
21
  (props.style || 'default') === 'default' ? '' : `is-${props.style}`
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrUndefined } from '@bodynarf/utils';
3
3
  import MultilineWithoutLabel from './components/multilineWithoutLabel';
4
4
  import MultilineWithLabel from './components/multilineWithLabel';
5
5
  /** Multiline textual input component */
6
6
  const Multiline = (props) => {
7
- if (utils.isNullOrUndefined(props.label)) {
7
+ if (isNullOrUndefined(props.label)) {
8
8
  return (_jsx(MultilineWithoutLabel, { ...props }));
9
9
  }
10
10
  else {
@@ -1,20 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName, } from '@bodynarf/utils';
4
4
  /** Textual input with describing label */
5
5
  const TextWithLabel = (props) => {
6
6
  const onValueChange = useCallback((event) => props.onValueChange(event.target.value),
7
7
  // eslint-disable-next-line react-hooks/exhaustive-deps
8
8
  [props.onValueChange]);
9
- const id = props.name || utils.generateGuid();
9
+ const id = props.name || generateGuid();
10
10
  const size = `is-${(props.size || 'normal')}`;
11
- const className = utils.getClassName([
11
+ const className = getClassName([
12
12
  props.className,
13
13
  size,
14
14
  props.rounded === true ? 'is-rounded' : '',
15
15
  "input",
16
16
  ]);
17
- const inputContainerClassName = utils.getClassName([
17
+ const inputContainerClassName = getClassName([
18
18
  "control",
19
19
  props.loading === true ? 'is-loading' : '',
20
20
  (props.style || 'default') === 'default' ? '' : `is-${props.style}`
@@ -1,24 +1,24 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName } from '@bodynarf/utils';
4
4
  /** Textual input without describing label */
5
5
  const TextWithoutLabel = (props) => {
6
6
  const onValueChange = useCallback((event) => props.onValueChange(event.target.value),
7
7
  // eslint-disable-next-line react-hooks/exhaustive-deps
8
8
  [props.onValueChange]);
9
- const className = utils.getClassName([
9
+ const className = getClassName([
10
10
  props.className,
11
11
  `is-${(props.size || 'normal')}`,
12
12
  props.rounded === true ? 'is-rounded' : '',
13
13
  "input",
14
14
  ]);
15
- const containerClassName = utils.getClassName([
15
+ const containerClassName = getClassName([
16
16
  "app-input",
17
17
  "control",
18
18
  props.loading === true ? 'is-loading' : '',
19
19
  (props.style || 'default') === 'default' ? '' : `is-${props.style}`
20
20
  ]);
21
- const id = props.name || utils.generateGuid();
21
+ const id = props.name || generateGuid();
22
22
  return (_jsx("div", { className: containerClassName, children: _jsx("input", { className: className, type: "text", placeholder: props.placeholder, readOnly: props.readonly, disabled: props.disabled, defaultValue: props.defaultValue, onChange: onValueChange, name: id, id: id }) }));
23
23
  };
24
24
  export default TextWithoutLabel;
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import utils from '@bodynarf/utils';
2
+ import { isNullOrUndefined } from '@bodynarf/utils';
3
3
  import TextWithLabel from './components/textWithLabel';
4
4
  import TextWithoutLabel from './components/textWithoutLabel';
5
5
  /** Textual input component */
6
6
  const Text = (props) => {
7
- if (utils.isNullOrUndefined(props.label)) {
7
+ if (isNullOrUndefined(props.label)) {
8
8
  return (_jsx(TextWithoutLabel, { ...props }));
9
9
  }
10
10
  else {
@@ -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,oDAAoD;IACpD,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,uBAAuB;AACvB,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAgF9D"}
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,oDAAoD;IACpD,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"}
@@ -1,17 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useState } from 'react';
3
- import utils from '@bodynarf/utils';
3
+ import { generateGuid, getClassName, isNullOrUndefined } from '@bodynarf/utils';
4
4
  import './search.scss';
5
5
  import Button from '../button';
6
6
  /** Search component */
7
7
  export default function Search(props) {
8
- const [name] = useState(props.name || utils.generateGuid());
8
+ const [name] = useState(props.name || generateGuid());
9
9
  const [searchValue, setSearchValue] = useState(props.defaultValue || '');
10
10
  const searchType = props.searchType || 'byTyping';
11
11
  const onChange = useCallback((event) => {
12
12
  const elementValue = event.target.value;
13
13
  if (searchType === 'byTyping') {
14
- const minCharsToSearch = utils.isNullOrUndefined(props.minCharsToSearch)
14
+ const minCharsToSearch = isNullOrUndefined(props.minCharsToSearch)
15
15
  ? 3
16
16
  : props.minCharsToSearch;
17
17
  if (elementValue.length >= minCharsToSearch) {
@@ -20,16 +20,18 @@ export default function Search(props) {
20
20
  }
21
21
  setSearchValue(elementValue);
22
22
  }, [props, searchType]);
23
- const onSearchButtonClick = useCallback(() => {
24
- props.onSearch(searchValue);
25
- }, [props, searchValue]);
26
- const className = 'app-search control'
27
- + ` is-${(props.size || 'normal')}`
28
- + (props.isLoading === true ? ' is-loading' : '')
29
- + (searchType === 'byButton' ? ' is-expanded' : '');
30
- const inputClassName = 'input is-unselectable'
31
- + ` is-${(props.size || 'normal')}`
32
- + (props.rounded === true ? ' is-rounded' : '');
23
+ const onSearchButtonClick = useCallback(() => props.onSearch(searchValue), [props, searchValue]);
24
+ const className = getClassName([
25
+ 'app-search control',
26
+ `is-${(props.size || 'normal')}`,
27
+ props.isLoading === true ? 'is-loading' : '',
28
+ searchType === 'byButton' ? 'is-expanded' : '',
29
+ ]);
30
+ const inputClassName = getClassName([
31
+ 'input is-unselectable',
32
+ `is-${(props.size || 'normal')}`,
33
+ props.rounded === true ? 'is-rounded' : '',
34
+ ]);
33
35
  if (searchType === 'byButton') {
34
36
  return (_jsxs("div", { className: "field has-addons", children: [_jsx("div", { className: className, children: _jsx("input", { type: 'search', name: name, defaultValue: searchValue, className: inputClassName, disabled: props.disabled, onChange: onChange, placeholder: props.caption }) }), _jsx("div", { className: "control", children: _jsx(Button, { caption: "Search", type: "info", onClick: onSearchButtonClick, isLoading: props.isLoading }) })] }));
35
37
  }
@@ -10,9 +10,11 @@ export declare type BaseElementProps = {
10
10
  [key: string]: any;
11
11
  };
12
12
  };
13
- export declare type IconSize = 'small' | 'medium' /** default size */ | 'large';
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 configuration */
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?: IconSize;
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,QAAQ,GACd,OAAO,GACP,QAAQ,CAAC,mBAAmB,GAC5B,OAAO,CAAC;AAEd,oBAAY,YAAY,GAClB,MAAM,GACN,OAAO,CAAC;AAEd,uCAAuC;AACvC,oBAAY,WAAW,GAAG;IACtB;;;MAGE;IACF,SAAS,EAAE,MAAM,CAAC;IAElB,gBAAgB;IAChB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAEhB;;;MAGE;IACF,QAAQ,CAAC,EAAE,YAAY,CAAC;CAC3B,CAAC"}
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/hooks/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './useComponentOutsideClick';
2
+ export * from './usePagination';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -1 +1,2 @@
1
1
  export * from './useComponentOutsideClick';
2
+ export * from './usePagination';
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect } from "react";
2
- import utils from "@bodynarf/utils";
2
+ import { isNullOrUndefined, isNull } from "@bodynarf/utils";
3
3
  /**
4
4
  * Subscribe to component outside click
5
5
  * @param selector Component root selector
@@ -12,18 +12,18 @@ export const useComponentOutsideClick = (selector, clickHandleCondition, clickHa
12
12
  const onDocumentClick = useCallback((event) => {
13
13
  if (clickHandleCondition) {
14
14
  const target = event.target;
15
- if (utils.isNullOrUndefined(target)) {
15
+ if (isNullOrUndefined(target)) {
16
16
  return;
17
17
  }
18
18
  const relatedComponent = target.closest(selector);
19
- if (utils.isNull(relatedComponent)) {
19
+ if (isNull(relatedComponent)) {
20
20
  clickHandleChange();
21
21
  }
22
22
  }
23
23
  // eslint-disable-next-line react-hooks/exhaustive-deps
24
24
  }, [clickHandleCondition, selector, clickHandleChange, dependencies]);
25
25
  useEffect(() => {
26
- if (utils.isNullOrUndefined(clickListenCondition) || clickListenCondition === true) {
26
+ if (isNullOrUndefined(clickListenCondition) || clickListenCondition === true) {
27
27
  document.addEventListener('click', onDocumentClick);
28
28
  return () => document.removeEventListener('click', onDocumentClick);
29
29
  }
@@ -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.1.4",
3
+ "version": "1.2.0",
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 && 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
+ }