@devtron-labs/devtron-fe-common-lib 0.0.54 → 0.0.55

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { PageSizeSelectorProps } from './types';
3
+ declare const PageSizeSelector: ({ pageSizeOptions, pageSize, changePageSize }: PageSizeSelectorProps) => JSX.Element;
4
+ export default PageSizeSelector;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { PaginationProps } from './types';
3
+ import './pagination.scss';
4
+ declare const Pagination: ({ size, pageSize, offset, changePage, changePageSize, isPageSizeFix, pageSizeOptions, rootClassName, }: PaginationProps) => JSX.Element;
5
+ export default Pagination;
@@ -0,0 +1,5 @@
1
+ export declare const VISIBLE_PAGES_LIMIT = 5;
2
+ export declare const FALLBACK_PAGE_SIZE_OPTIONS: {
3
+ value: number;
4
+ selected: boolean;
5
+ }[];
@@ -0,0 +1 @@
1
+ export { default as Pagination } from './Pagination';
@@ -0,0 +1,51 @@
1
+ /// <reference types="react" />
2
+ export interface PageSizeOption {
3
+ value: number;
4
+ selected: boolean;
5
+ }
6
+ export interface PaginationProps {
7
+ /**
8
+ * number of items
9
+ */
10
+ size: number;
11
+ /**
12
+ * pageSize
13
+ */
14
+ pageSize: number;
15
+ offset: number;
16
+ changePage: (pageNo: number) => void;
17
+ changePageSize?: (pageSize: number) => void;
18
+ /**
19
+ * If true will not show page size selector
20
+ */
21
+ isPageSizeFix?: boolean;
22
+ /**
23
+ * If given would show these options in page size selector else [20,40,50] with 20 as selected
24
+ */
25
+ pageSizeOptions?: PageSizeOption[];
26
+ /**
27
+ * class for wrapper
28
+ */
29
+ rootClassName?: string;
30
+ }
31
+ export interface Page {
32
+ value: number;
33
+ selected: boolean;
34
+ isVisible: boolean;
35
+ }
36
+ export interface CreatePageArrType extends Pick<PaginationProps, 'size' | 'pageSize'> {
37
+ selectedPageNo: number;
38
+ }
39
+ export interface PageSizeSelectorProps extends Pick<PaginationProps, 'pageSizeOptions' | 'pageSize' | 'changePageSize'> {
40
+ }
41
+ export interface PageSizeItemsProps extends Pick<PageSizeSelectorProps, 'changePageSize'> {
42
+ optionValue: PageSizeOption['value'];
43
+ options: PageSizeOption[];
44
+ setOptions: React.Dispatch<React.SetStateAction<PageSizeOption[]>>;
45
+ handleCloseDropdown: () => void;
46
+ }
47
+ export interface PageValueItemProps {
48
+ value: PageSizeOption['value'];
49
+ isSelected: PageSizeOption['selected'];
50
+ selectPage: (selectedPageNo: number) => void;
51
+ }
@@ -0,0 +1,6 @@
1
+ import { CreatePageArrType, Page, PageSizeOption } from './types';
2
+ /**
3
+ * Returns an array of pages numbers and whether they are selected, visible or not
4
+ */
5
+ export declare const createPageArr: ({ size, pageSize, selectedPageNo }: CreatePageArrType) => Page[];
6
+ export declare const getDefaultPageValueOptions: (pageSizeOptions: PageSizeOption[]) => PageSizeOption[];
@@ -47,3 +47,4 @@ export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSel
47
47
  export * from './AddCDButton';
48
48
  export * from './CustomInput';
49
49
  export * from './DraggableWrapper';
50
+ export * from './Pagination';
package/dist/index.js CHANGED
@@ -752,8 +752,8 @@ function styleInject(css, ref) {
752
752
  }
753
753
  }
754
754
 
755
- var css_248z$8 = ".empty-state {\n height: 100%;\n}\n.empty-state img {\n height: 40%;\n max-height: 200px;\n width: auto;\n max-width: 250px;\n}\n.empty-state svg {\n height: 40%;\n max-height: 200px;\n width: auto;\n}\n.empty-state h1,\n.empty-state h2,\n.empty-state h3,\n.empty-state h4,\n.empty-state h5,\n.empty-state h6 {\n color: var(--N900);\n}\n.empty-state .subtitle {\n font-size: 13px;\n font-weight: 400;\n text-align: center;\n line-height: 1.5;\n margin-bottom: 6px;\n}\n.empty-state .subtitle--text-start {\n text-align: start;\n}\n.empty-state .cta {\n height: 36px;\n}\n.empty-state p {\n text-align: center;\n font-size: 13px;\n color: var(--N700);\n}\n.empty-state strong {\n font-size: 16px;\n margin-bottom: 4px;\n color: var(--N900);\n font-weight: normal;\n}\n.empty-state .select-popup {\n height: min-content;\n max-height: 250px;\n overflow: auto;\n padding: 8px 0;\n}\n.empty-state .empty-state__loader {\n width: 34px;\n height: 34px;\n margin-bottom: 16px;\n}\n.empty-state .empty-state__loading-text {\n font-size: 12px;\n width: 200px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.5;\n letter-spacing: normal;\n text-align: center;\n color: var(--N900);\n}\n.empty-state .button__icon {\n width: 16px;\n height: 16px;\n margin-left: 8px;\n}";
756
- styleInject(css_248z$8);
755
+ var css_248z$9 = ".empty-state {\n height: 100%;\n}\n.empty-state img {\n height: 40%;\n max-height: 200px;\n width: auto;\n max-width: 250px;\n}\n.empty-state svg {\n height: 40%;\n max-height: 200px;\n width: auto;\n}\n.empty-state h1,\n.empty-state h2,\n.empty-state h3,\n.empty-state h4,\n.empty-state h5,\n.empty-state h6 {\n color: var(--N900);\n}\n.empty-state .subtitle {\n font-size: 13px;\n font-weight: 400;\n text-align: center;\n line-height: 1.5;\n margin-bottom: 6px;\n}\n.empty-state .subtitle--text-start {\n text-align: start;\n}\n.empty-state .cta {\n height: 36px;\n}\n.empty-state p {\n text-align: center;\n font-size: 13px;\n color: var(--N700);\n}\n.empty-state strong {\n font-size: 16px;\n margin-bottom: 4px;\n color: var(--N900);\n font-weight: normal;\n}\n.empty-state .select-popup {\n height: min-content;\n max-height: 250px;\n overflow: auto;\n padding: 8px 0;\n}\n.empty-state .empty-state__loader {\n width: 34px;\n height: 34px;\n margin-bottom: 16px;\n}\n.empty-state .empty-state__loading-text {\n font-size: 12px;\n width: 200px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.5;\n letter-spacing: normal;\n text-align: center;\n color: var(--N900);\n}\n.empty-state .button__icon {\n width: 16px;\n height: 16px;\n margin-left: 8px;\n}";
756
+ styleInject(css_248z$9);
757
757
 
758
758
  var _g$7;
759
759
  function _extends$o() { _extends$o = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$o.apply(this, arguments); }
@@ -11918,8 +11918,8 @@ var VisibleModal = /** @class */ (function (_super) {
11918
11918
  return VisibleModal;
11919
11919
  }(React.Component));
11920
11920
 
11921
- var css_248z$7 = ".drawer {\n position: absolute;\n overflow: hidden;\n}\n.drawer.left, .drawer.right {\n top: 0;\n bottom: 0;\n width: 0;\n transition: width 200ms;\n}\n.drawer.left.show, .drawer.right.show {\n min-width: var(--minWidth);\n width: var(--width);\n max-width: var(--maxWidth);\n}\n.drawer.top, .drawer.bottom {\n left: 0;\n right: 0;\n height: 0;\n transition: height 200ms;\n}\n.drawer.top.show, .drawer.bottom.show {\n height: var(--height);\n}\n.drawer.right {\n right: 0;\n}\n.drawer.left {\n left: 0;\n}\n.drawer.top {\n top: 0;\n}\n.drawer.bottom {\n bottom: 0;\n}";
11922
- styleInject(css_248z$7);
11921
+ var css_248z$8 = ".drawer {\n position: absolute;\n overflow: hidden;\n}\n.drawer.left, .drawer.right {\n top: 0;\n bottom: 0;\n width: 0;\n transition: width 200ms;\n}\n.drawer.left.show, .drawer.right.show {\n min-width: var(--minWidth);\n width: var(--width);\n max-width: var(--maxWidth);\n}\n.drawer.top, .drawer.bottom {\n left: 0;\n right: 0;\n height: 0;\n transition: height 200ms;\n}\n.drawer.top.show, .drawer.bottom.show {\n height: var(--height);\n}\n.drawer.right {\n right: 0;\n}\n.drawer.left {\n left: 0;\n}\n.drawer.top {\n top: 0;\n}\n.drawer.bottom {\n bottom: 0;\n}";
11922
+ styleInject(css_248z$8);
11923
11923
 
11924
11924
  var Drawer = function (_a) {
11925
11925
  var children = _a.children, position = _a.position, height = _a.height, width = _a.width, minWidth = _a.minWidth, maxWidth = _a.maxWidth, parentClassName = _a.parentClassName, onEscape = _a.onEscape;
@@ -16331,8 +16331,8 @@ var SvgIcHelpOutline = function SvgIcHelpOutline(props) {
16331
16331
  })));
16332
16332
  };
16333
16333
 
16334
- var css_248z$6 = ".tippy-box[data-animation=shift-toward-subtle][data-state=hidden]{opacity:0}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=top][data-state=hidden]{transform:translateY(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=bottom][data-state=hidden]{transform:translateY(5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=left][data-state=hidden]{transform:translateX(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=right][data-state=hidden]{transform:translateX(5px)}";
16335
- styleInject(css_248z$6);
16334
+ var css_248z$7 = ".tippy-box[data-animation=shift-toward-subtle][data-state=hidden]{opacity:0}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=top][data-state=hidden]{transform:translateY(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=bottom][data-state=hidden]{transform:translateY(5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=left][data-state=hidden]{transform:translateX(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=right][data-state=hidden]{transform:translateX(5px)}";
16335
+ styleInject(css_248z$7);
16336
16336
 
16337
16337
  // This component will handle some of the new tippy designs and interactions
16338
16338
  // So this can be updated to support further for new features or interactions
@@ -24292,8 +24292,8 @@ var CustomSelect = function (props) {
24292
24292
  return jsxRuntime.jsx(ReactSelect, __assign({}, props));
24293
24293
  };
24294
24294
 
24295
- var css_248z$5 = ".info-bar-container .info_text .success {\n background-color: var(--G100);\n}\n.info-bar-container .warn {\n background: var(--Y100);\n border: solid var(--Y200);\n}\n.info-bar-container .warn .warning-icon path:nth-child(2) {\n fill: var(--Y700);\n}\n.info-bar-container .info_bar {\n background-color: var(--B100);\n border: 1px solid var(--B200);\n}\n.info-bar-container .error_bar {\n background-color: var(--R100);\n border: 1px solid var(--R200);\n}\n.info-bar-container .question-bar {\n background-color: var(--V100);\n border: 1px solid var(--V200);\n}";
24296
- styleInject(css_248z$5);
24295
+ var css_248z$6 = ".info-bar-container .info_text .success {\n background-color: var(--G100);\n}\n.info-bar-container .warn {\n background: var(--Y100);\n border: solid var(--Y200);\n}\n.info-bar-container .warn .warning-icon path:nth-child(2) {\n fill: var(--Y700);\n}\n.info-bar-container .info_bar {\n background-color: var(--B100);\n border: 1px solid var(--B200);\n}\n.info-bar-container .error_bar {\n background-color: var(--R100);\n border: 1px solid var(--R200);\n}\n.info-bar-container .question-bar {\n background-color: var(--V100);\n border: 1px solid var(--V200);\n}";
24296
+ styleInject(css_248z$6);
24297
24297
 
24298
24298
  function InfoColourBar(_a) {
24299
24299
  var message = _a.message, classname = _a.classname, Icon = _a.Icon, iconClass = _a.iconClass, iconSize = _a.iconSize, renderActionButton = _a.renderActionButton, linkText = _a.linkText, redirectLink = _a.redirectLink, linkOnClick = _a.linkOnClick, linkClass = _a.linkClass, internalLink = _a.internalLink, styles = _a.styles;
@@ -24613,8 +24613,8 @@ var SvgIcErrorCross = function SvgIcErrorCross(props) {
24613
24613
  }))));
24614
24614
  };
24615
24615
 
24616
- var css_248z$4 = ".search-bar:focus, .search-bar:focus-within {\n outline: none;\n border: solid 1px var(--B500);\n}\n.search-bar__input:focus, .search-bar__input:focus-visible {\n border: none;\n outline: none;\n}\n.search-bar__icon {\n z-index: 1;\n top: 50%;\n left: 8px;\n transform: translateY(-50%);\n}\n.search-bar__clear-button {\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: 1;\n}";
24617
- styleInject(css_248z$4);
24616
+ var css_248z$5 = ".search-bar:focus, .search-bar:focus-within {\n outline: none;\n border: solid 1px var(--B500);\n}\n.search-bar__input:focus, .search-bar__input:focus-visible {\n border: none;\n outline: none;\n}\n.search-bar__icon {\n z-index: 1;\n top: 50%;\n left: 8px;\n transform: translateY(-50%);\n}\n.search-bar__clear-button {\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: 1;\n}";
24617
+ styleInject(css_248z$5);
24618
24618
 
24619
24619
  /**
24620
24620
  * Generic search input component with support for enter based and debounced search
@@ -24687,8 +24687,8 @@ var SearchBar = function (_a) {
24687
24687
  return (jsxRuntime.jsx("div", __assign({ className: containerClassName }, { children: jsxRuntime.jsxs("div", __assign({ className: "search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32" }, { children: [jsxRuntime.jsx(SvgIcSearch, { className: "search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" }), jsxRuntime.jsx("input", __assign({ placeholder: "Search", "data-testid": "search-bar", type: "text" }, inputProps, { defaultValue: initialSearchText, className: "search-bar__input bcn-0 dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ".concat(showClearButton ? 'pr-30' : 'pr-10'), onChange: handleChange, onKeyDown: handleKeyDown, ref: inputRef })), showClearButton && (jsxRuntime.jsx("button", __assign({ className: "flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5", type: "button", onClick: clearSearch, "aria-label": "Clear search" }, { children: jsxRuntime.jsx(SvgIcErrorCross, { className: "icon-dim-18 icon-n4 dc__vertical-align-middle" }) })))] })) })));
24688
24688
  };
24689
24689
 
24690
- var css_248z$3 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n.toggle__slider.round {\n border-radius: 34px;\n}\n.toggle__slider.round:before {\n border-radius: 50%;\n}\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n.toggle__slider.with-icon {\n background-color: var(--N000) !important;\n}\n.toggle__slider.with-icon svg {\n position: absolute;\n content: \"\";\n top: -1px;\n left: -1px;\n background-color: var(--N300);\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\ninput:checked + .toggle__slider.with-icon svg {\n transform: translateX(100%);\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}";
24691
- styleInject(css_248z$3);
24690
+ var css_248z$4 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n.toggle__slider.round {\n border-radius: 34px;\n}\n.toggle__slider.round:before {\n border-radius: 50%;\n}\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n.toggle__slider.with-icon {\n background-color: var(--N000) !important;\n}\n.toggle__slider.with-icon svg {\n position: absolute;\n content: \"\";\n top: -1px;\n left: -1px;\n background-color: var(--N300);\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\ninput:checked + .toggle__slider.with-icon svg {\n transform: translateX(100%);\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}";
24691
+ styleInject(css_248z$4);
24692
24692
 
24693
24693
  var Toggle = function (_a) {
24694
24694
  var _b;
@@ -24712,8 +24712,8 @@ var Toggle = function (_a) {
24712
24712
  return (jsxRuntime.jsxs("label", __assign({}, props, { className: "".concat(rootClassName, " toggle__switch ").concat(disabled ? 'disabled' : ''), style: (_b = {}, _b['--color'] = color, _b) }, { children: [jsxRuntime.jsx("input", { type: "checkbox", checked: !!active, onChange: handleClick, className: "toggle__input" }), jsxRuntime.jsx("span", __assign({ className: "toggle__slider ".concat(Icon ? 'with-icon br-4 dc__border' : 'round'), "data-testid": dataTestId }, { children: Icon && jsxRuntime.jsx(Icon, { className: "icon-dim-20 br-4 p-2 ".concat(iconClass) }) }))] })));
24713
24713
  };
24714
24714
 
24715
- var css_248z$2 = ".modal-body--scan-details {\n position: fixed;\n top: 0;\n right: 0;\n background: var(--N000);\n width: 800px;\n}\n\n.security-tab__table {\n width: 100%;\n}\n\n.security-tab__table-header {\n border-bottom: solid 1px var(--N200);\n}\n\n.security-cell-header {\n font-size: 12px;\n font-weight: 600;\n line-height: 1.5;\n letter-spacing: normal;\n text-transform: uppercase;\n color: var(--N500);\n}\n\n.dc__security-tab__table-row {\n font-size: 13px;\n font-weight: normal;\n line-height: 1.54;\n letter-spacing: normal;\n color: var(--N900);\n box-shadow: inset 0 -1px 0 0 #f5f5f5;\n}\n\n.security-tab__cell-cve,\n.security-tab__cell-severity,\n.security-tab__cell-package,\n.security-tab__cell-current-ver,\n.security-tab__cell-fixed-ver,\n.security-tab__cell-policy {\n padding: 10px;\n max-width: 120px;\n word-wrap: break-word;\n}\n\n.security-tab__cell-cve {\n padding-left: 0px;\n text-align: left;\n width: 20%;\n}\n\n.security-tab__cell-policy {\n padding-right: 0px;\n}\n\n.security-tab__cell-policy--whitelist,\n.security-tab__cell-policy--whitelisted {\n color: var(--G500);\n text-transform: capitalize;\n}\n\n.security-tab__cell-policy--block {\n color: var(--R500);\n text-transform: capitalize;\n}\n\n.scanned-object__results {\n margin: 0 20px;\n}";
24716
- styleInject(css_248z$2);
24715
+ var css_248z$3 = ".modal-body--scan-details {\n position: fixed;\n top: 0;\n right: 0;\n background: var(--N000);\n width: 800px;\n}\n\n.security-tab__table {\n width: 100%;\n}\n\n.security-tab__table-header {\n border-bottom: solid 1px var(--N200);\n}\n\n.security-cell-header {\n font-size: 12px;\n font-weight: 600;\n line-height: 1.5;\n letter-spacing: normal;\n text-transform: uppercase;\n color: var(--N500);\n}\n\n.dc__security-tab__table-row {\n font-size: 13px;\n font-weight: normal;\n line-height: 1.54;\n letter-spacing: normal;\n color: var(--N900);\n box-shadow: inset 0 -1px 0 0 #f5f5f5;\n}\n\n.security-tab__cell-cve,\n.security-tab__cell-severity,\n.security-tab__cell-package,\n.security-tab__cell-current-ver,\n.security-tab__cell-fixed-ver,\n.security-tab__cell-policy {\n padding: 10px;\n max-width: 120px;\n word-wrap: break-word;\n}\n\n.security-tab__cell-cve {\n padding-left: 0px;\n text-align: left;\n width: 20%;\n}\n\n.security-tab__cell-policy {\n padding-right: 0px;\n}\n\n.security-tab__cell-policy--whitelist,\n.security-tab__cell-policy--whitelisted {\n color: var(--G500);\n text-transform: capitalize;\n}\n\n.security-tab__cell-policy--block {\n color: var(--R500);\n text-transform: capitalize;\n}\n\n.scanned-object__results {\n margin: 0 20px;\n}";
24716
+ styleInject(css_248z$3);
24717
24717
 
24718
24718
  function ScanVulnerabilitiesTable(_a) {
24719
24719
  var vulnerabilities = _a.vulnerabilities;
@@ -24728,8 +24728,8 @@ function ScanVulnerabilitiesTable(_a) {
24728
24728
  })] }) })));
24729
24729
  }
24730
24730
 
24731
- var css_248z$1 = ".radio-group {\n height: 30px;\n background: white;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 4px;\n border-radius: 4px;\n}\n.radio-group .label,\n.radio-group .radio,\n.radio-group .checkbox {\n margin: 0;\n}\n.radio-group .radio {\n height: 100%;\n width: auto;\n color: var(--N400);\n display: flex;\n align-items: center;\n}\n.radio-group .radio + .radio {\n margin-top: 0;\n}\n.radio-group input[type=checkbox] {\n display: contents;\n overflow: hidden;\n max-width: 0px;\n height: 0;\n opacity: 0;\n margin: unset;\n}\n.radio-group input + .radio__item-label {\n padding: 4px 6px;\n height: 100%;\n width: 100%;\n display: flex;\n align-items: center;\n transition: all 0.5s;\n cursor: pointer;\n}\n.radio-group input[type=checkbox]:checked + .radio__item-label {\n background: #2c3354;\n color: white;\n border-radius: 4px;\n}";
24732
- styleInject(css_248z$1);
24731
+ var css_248z$2 = ".radio-group {\n height: 30px;\n background: white;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 4px;\n border-radius: 4px;\n}\n.radio-group .label,\n.radio-group .radio,\n.radio-group .checkbox {\n margin: 0;\n}\n.radio-group .radio {\n height: 100%;\n width: auto;\n color: var(--N400);\n display: flex;\n align-items: center;\n}\n.radio-group .radio + .radio {\n margin-top: 0;\n}\n.radio-group input[type=checkbox] {\n display: contents;\n overflow: hidden;\n max-width: 0px;\n height: 0;\n opacity: 0;\n margin: unset;\n}\n.radio-group input + .radio__item-label {\n padding: 4px 6px;\n height: 100%;\n width: 100%;\n display: flex;\n align-items: center;\n transition: all 0.5s;\n cursor: pointer;\n}\n.radio-group input[type=checkbox]:checked + .radio__item-label {\n background: #2c3354;\n color: white;\n border-radius: 4px;\n}";
24732
+ styleInject(css_248z$2);
24733
24733
 
24734
24734
  var RadioContext = React.createContext(null);
24735
24735
  function useRadioContext() {
@@ -28320,8 +28320,8 @@ var templates = {
28320
28320
  WrapIfAdditionalTemplate: WrapIfAdditionalTemplate,
28321
28321
  };
28322
28322
 
28323
- var css_248z = ".rjsf-form-template__field {\n grid-template-columns: 250px 1fr;\n}\n.rjsf-form-template__additional-fields {\n grid-template-columns: 1fr 1fr minmax(20px, auto);\n}\n.rjsf-form-template__array-field-item {\n grid-template-columns: 1fr auto;\n}\n.rjsf-form-template__array-field-item > :first-child {\n margin: 0;\n}";
28324
- styleInject(css_248z);
28323
+ var css_248z$1 = ".rjsf-form-template__field {\n grid-template-columns: 250px 1fr;\n}\n.rjsf-form-template__additional-fields {\n grid-template-columns: 1fr 1fr minmax(20px, auto);\n}\n.rjsf-form-template__array-field-item {\n grid-template-columns: 1fr auto;\n}\n.rjsf-form-template__array-field-item > :first-child {\n margin: 0;\n}";
28324
+ styleInject(css_248z$1);
28325
28325
 
28326
28326
  // Need to use this way because the default import was not working as expected
28327
28327
  // The default import resolves to an object intead of a function
@@ -28626,6 +28626,117 @@ function DraggableButton(_a) {
28626
28626
  return (jsxRuntime.jsx("button", __assign({ type: "button", className: "".concat(dragClassName, " dc__outline-none-imp dc__no-border p-0 dc__transparent h-20") }, { children: jsxRuntime.jsx(SvgIcDrag, { className: "dc__grabbable icon-dim-20 fcn-6" }) })));
28627
28627
  }
28628
28628
 
28629
+ var VISIBLE_PAGES_LIMIT = 5;
28630
+ var FALLBACK_PAGE_SIZE_OPTIONS = [
28631
+ { value: 20, selected: true },
28632
+ { value: 40, selected: false },
28633
+ { value: 50, selected: false },
28634
+ ];
28635
+
28636
+ /**
28637
+ * Returns an array of pages numbers and whether they are selected, visible or not
28638
+ */
28639
+ var createPageArr = function (_a) {
28640
+ var size = _a.size, pageSize = _a.pageSize, selectedPageNo = _a.selectedPageNo;
28641
+ var arr = [];
28642
+ var numberOfPages = Math.ceil(size / pageSize);
28643
+ // we are showing 2 numbers before and after the selected page, so computing the lower and upper bounds
28644
+ var lowerBound = selectedPageNo - 2 < 1 ? 1 : selectedPageNo - 2;
28645
+ var upperBound = selectedPageNo + 2 > numberOfPages ? numberOfPages : selectedPageNo + 2;
28646
+ for (var i = 1; i <= numberOfPages; i++) {
28647
+ arr.push({
28648
+ value: i,
28649
+ selected: i === selectedPageNo,
28650
+ isVisible: upperBound - VISIBLE_PAGES_LIMIT < i && i < lowerBound + VISIBLE_PAGES_LIMIT,
28651
+ });
28652
+ }
28653
+ return arr;
28654
+ };
28655
+ var getDefaultPageValueOptions = function (pageSizeOptions) {
28656
+ return (pageSizeOptions === null || pageSizeOptions === void 0 ? void 0 : pageSizeOptions.length) ? pageSizeOptions : FALLBACK_PAGE_SIZE_OPTIONS;
28657
+ };
28658
+
28659
+ var PageSizeItems = function (_a) {
28660
+ var optionValue = _a.optionValue, options = _a.options, setOptions = _a.setOptions, handleCloseDropdown = _a.handleCloseDropdown, changePageSize = _a.changePageSize;
28661
+ var handlePageSizeSelect = function () {
28662
+ var newOptions = options.map(function (_option) { return ({
28663
+ value: _option.value,
28664
+ selected: _option.value === optionValue,
28665
+ }); });
28666
+ setOptions(__spreadArray([], __read(newOptions), false));
28667
+ handleCloseDropdown();
28668
+ changePageSize(optionValue);
28669
+ };
28670
+ return (jsxRuntime.jsx("div", __assign({ className: "select__item", onClick: handlePageSizeSelect }, { children: optionValue }), optionValue));
28671
+ };
28672
+ var PageSizeSelector = function (_a) {
28673
+ var pageSizeOptions = _a.pageSizeOptions, pageSize = _a.pageSize, changePageSize = _a.changePageSize;
28674
+ var defaultOptions = getDefaultPageValueOptions(pageSizeOptions).map(function (option) { return ({
28675
+ value: option.value,
28676
+ selected: option.value === pageSize,
28677
+ }); });
28678
+ var _b = __read(React.useState(false), 2), isDropdownOpen = _b[0], setIsDropdownOpen = _b[1];
28679
+ var _c = __read(React.useState(defaultOptions), 2), options = _c[0], setOptions = _c[1];
28680
+ var handleCloseDropdown = function () {
28681
+ setIsDropdownOpen(false);
28682
+ };
28683
+ var handleDropdownToggle = function () {
28684
+ setIsDropdownOpen(!isDropdownOpen);
28685
+ };
28686
+ var dropdownRef = React.useRef(null);
28687
+ useClickOutside(dropdownRef, handleCloseDropdown);
28688
+ var selectedOption = options.find(function (option) { return option.selected; });
28689
+ var font = isDropdownOpen ? 'fa fa-caret-up' : 'fa fa-caret-down';
28690
+ return (jsxRuntime.jsxs("div", __assign({ ref: dropdownRef }, { children: [isDropdownOpen && (jsxRuntime.jsx("div", __assign({ className: "pagination__select-menu" }, { children: options.map(function (_option) { return (jsxRuntime.jsx(PageSizeItems, { optionValue: _option.value, options: options, setOptions: setOptions, handleCloseDropdown: handleCloseDropdown, changePageSize: changePageSize })); }) }))), jsxRuntime.jsxs("button", __assign({ type: "button", className: "select__button", onClick: handleDropdownToggle }, { children: [jsxRuntime.jsx("span", { children: selectedOption ? selectedOption.value : '' }), jsxRuntime.jsx("span", __assign({ className: "select__icon" }, { children: jsxRuntime.jsx("i", { className: font }) }))] }))] })));
28691
+ };
28692
+
28693
+ var css_248z = ".pagination-wrapper {\n display: flex;\n align-items: center;\n padding: 0px 24px;\n justify-content: space-between;\n margin: 0px;\n background-color: var(--white);\n}\n\n.pagination {\n margin-top: 16px;\n margin-bottom: 16px;\n padding: 0px;\n}\n\n.select {\n display: flex;\n align-items: center;\n position: relative;\n}\n\n.select__placeholder {\n font-size: 12px;\n font-weight: normal;\n font-style: normal;\n font-stretch: normal;\n line-height: 1.5;\n letter-spacing: normal;\n color: var(--N700);\n margin-right: 8px;\n}\n\n.pagination__select-menu {\n padding: 0px;\n list-style: none;\n overflow: hidden;\n border: solid 1px var(--N200);\n border-radius: 4px;\n width: 64px;\n position: absolute;\n bottom: 31px;\n background-color: var(--white);\n}\n\n.select__button {\n width: 64px;\n background-color: transparent;\n border-radius: 4px;\n border: solid 1px var(--N200);\n padding: 5px 10px;\n text-align: left;\n}\n\n.select__item {\n padding: 5px 10px;\n cursor: pointer;\n}\n\n.select__icon {\n margin-left: 18px;\n}\n\n.page {\n margin: 0px 8px;\n display: inline-block;\n}\n\n.page-number {\n font-size: 12px;\n font-weight: normal;\n font-style: normal;\n font-stretch: normal;\n line-height: 1.5;\n letter-spacing: normal;\n color: var(--N700);\n}\n\n.page__button {\n width: 24px;\n height: 24px;\n border-radius: 8px;\n color: var(--B500);\n background-color: var(--white);\n padding: 0px;\n user-select: none;\n}\n\n.page__button--icon {\n background-color: var(--white);\n color: var(--B500);\n}\n\n/* MODIFIERS */\n.page__button--selected {\n color: var(--white);\n background-color: var(--B500);\n}\n\n/* States and Selectorys */\n.page__button:disabled {\n opacity: 0.5;\n}\n\n.select__item:hover {\n background-color: var(--N50);\n}\n\n.page__button:hover ~ :disabled {\n background-color: var(--B100);\n}\n\n.page__button--selected:hover {\n color: var(--white);\n background-color: var(--B500);\n}\n\n@media (min-width: 1024px) {\n .pagination {\n margin: 16px auto;\n }\n}";
28694
+ styleInject(css_248z);
28695
+
28696
+ var PageValueItem = function (_a) {
28697
+ var value = _a.value, isSelected = _a.isSelected, selectPage = _a.selectPage;
28698
+ var classes = isSelected ? 'page__button page__button--selected' : 'page__button';
28699
+ var handlePageSelection = function () {
28700
+ selectPage(value);
28701
+ };
28702
+ return (jsxRuntime.jsx("li", __assign({ className: "page" }, { children: jsxRuntime.jsx("button", __assign({ className: classes, onClick: handlePageSelection, type: "button" }, { children: value })) })));
28703
+ };
28704
+ // NOTE: This component will heavily benefit from data normalization
28705
+ var Pagination = function (_a) {
28706
+ var size = _a.size, pageSize = _a.pageSize, offset = _a.offset, changePage = _a.changePage, changePageSize = _a.changePageSize, isPageSizeFix = _a.isPageSizeFix, pageSizeOptions = _a.pageSizeOptions, rootClassName = _a.rootClassName;
28707
+ var _b = __read(React.useState([]), 2), pages = _b[0], setPages = _b[1];
28708
+ React.useEffect(function () {
28709
+ var _pages = createPageArr({ size: size, pageSize: pageSize, selectedPageNo: 1 });
28710
+ setPages(_pages);
28711
+ }, [size, pageSize]);
28712
+ React.useEffect(function () {
28713
+ var selectedPageNo = 1 + Math.floor(offset / pageSize);
28714
+ var _pages = createPageArr({ size: size, pageSize: pageSize, selectedPageNo: selectedPageNo });
28715
+ setPages(_pages);
28716
+ }, [offset]);
28717
+ var selectPage = function (selectedPageNo) {
28718
+ var _pages = createPageArr({ size: size, pageSize: pageSize, selectedPageNo: selectedPageNo });
28719
+ setPages(_pages);
28720
+ changePage(selectedPageNo);
28721
+ };
28722
+ var selectPreviousPage = function () {
28723
+ var currPage = pages.find(function (page) { return page.selected; });
28724
+ var selectedPageNo = currPage.value - 1;
28725
+ selectPage(selectedPageNo);
28726
+ };
28727
+ var selectNextPage = function () {
28728
+ var currPage = pages.find(function (page) { return page.selected; });
28729
+ var selectedPageNo = currPage.value + 1;
28730
+ selectPage(selectedPageNo);
28731
+ };
28732
+ var lastPageNo = offset + pageSize < size ? offset + pageSize : size;
28733
+ var pageNoIndex = pages.findIndex(function (page) { return page.selected; });
28734
+ var visiblePages = pages.filter(function (page) { return page.isVisible; });
28735
+ return (
28736
+ // TODO: Remove pagination-wrapper from dashboard
28737
+ jsxRuntime.jsxs("div", __assign({ className: rootClassName || '' }, { children: [jsxRuntime.jsxs("div", __assign({ className: "page-number" }, { children: [offset + 1, " - ", lastPageNo, " of ", size] })), jsxRuntime.jsxs("ul", __assign({ className: "pagination" }, { children: [jsxRuntime.jsx("li", __assign({ className: "page" }, { children: jsxRuntime.jsx("button", __assign({ className: "page__button page__button--icon", disabled: !pageNoIndex, onClick: selectPreviousPage, type: "button", "aria-label": "Previous page" }, { children: jsxRuntime.jsx("span", __assign({ className: "left-icon" }, { children: jsxRuntime.jsx("i", { className: "fa fa-chevron-left" }) })) })) })), visiblePages.map(function (page) { return (jsxRuntime.jsx(PageValueItem, { value: page.value, isSelected: page.selected, selectPage: selectPage }, page.value)); }), jsxRuntime.jsx("li", __assign({ className: "page" }, { children: jsxRuntime.jsx("button", __assign({ className: "page__button page__button--icon", disabled: pageNoIndex === pages.length - 1, onClick: selectNextPage, type: "button", "aria-label": "Next page" }, { children: jsxRuntime.jsx("span", __assign({ className: "left-icon" }, { children: jsxRuntime.jsx("i", { className: "fa fa-chevron-right" }) })) })) }))] })), !isPageSizeFix && (jsxRuntime.jsxs("div", __assign({ className: "select" }, { children: [jsxRuntime.jsx("span", __assign({ className: "select__placeholder" }, { children: "Rows per page" })), jsxRuntime.jsx(PageSizeSelector, { pageSizeOptions: pageSizeOptions, pageSize: pageSize, changePageSize: changePageSize })] })))] })));
28738
+ };
28739
+
28629
28740
  exports.AddCDButton = AddCDButton;
28630
28741
  exports.AppStatus = AppStatus;
28631
28742
  exports.BreadCrumb = BreadCrumb;
@@ -28673,6 +28784,7 @@ exports.MultiValueRemove = MultiValueRemove;
28673
28784
  exports.OpaqueModal = OpaqueModal;
28674
28785
  exports.Option = Option;
28675
28786
  exports.PATTERNS = PATTERNS;
28787
+ exports.Pagination = Pagination;
28676
28788
  exports.PopupMenu = PopupMenu;
28677
28789
  exports.Progressing = Progressing;
28678
28790
  exports.PropagateTagInfo = PropagateTagInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,78 @@
1
+ import { useRef, useState } from 'react'
2
+ import { PageSizeItemsProps, PageSizeOption, PageSizeSelectorProps } from './types'
3
+ import { useClickOutside } from '../Hooks'
4
+ import { getDefaultPageValueOptions } from './utils'
5
+
6
+ const PageSizeItems = ({
7
+ optionValue,
8
+ options,
9
+ setOptions,
10
+ handleCloseDropdown,
11
+ changePageSize,
12
+ }: PageSizeItemsProps) => {
13
+ const handlePageSizeSelect = () => {
14
+ const newOptions = options.map((_option) => ({
15
+ value: _option.value,
16
+ selected: _option.value === optionValue,
17
+ }))
18
+ setOptions([...newOptions])
19
+ handleCloseDropdown()
20
+ changePageSize(optionValue)
21
+ }
22
+
23
+ return (
24
+ <div key={optionValue} className="select__item" onClick={handlePageSizeSelect}>
25
+ {optionValue}
26
+ </div>
27
+ )
28
+ }
29
+
30
+ const PageSizeSelector = ({ pageSizeOptions, pageSize, changePageSize }: PageSizeSelectorProps) => {
31
+ const defaultOptions = getDefaultPageValueOptions(pageSizeOptions).map((option) => ({
32
+ value: option.value,
33
+ selected: option.value === pageSize,
34
+ }))
35
+
36
+ const [isDropdownOpen, setIsDropdownOpen] = useState<boolean>(false)
37
+ const [options, setOptions] = useState<PageSizeOption[]>(defaultOptions)
38
+
39
+ const handleCloseDropdown = () => {
40
+ setIsDropdownOpen(false)
41
+ }
42
+
43
+ const handleDropdownToggle = () => {
44
+ setIsDropdownOpen(!isDropdownOpen)
45
+ }
46
+
47
+ const dropdownRef = useRef<HTMLDivElement>(null)
48
+ useClickOutside(dropdownRef, handleCloseDropdown)
49
+
50
+ const selectedOption = options.find((option) => option.selected)
51
+ const font = isDropdownOpen ? 'fa fa-caret-up' : 'fa fa-caret-down'
52
+ return (
53
+ <div ref={dropdownRef}>
54
+ {isDropdownOpen && (
55
+ <div className="pagination__select-menu">
56
+ {options.map((_option) => (
57
+ <PageSizeItems
58
+ optionValue={_option.value}
59
+ options={options}
60
+ setOptions={setOptions}
61
+ handleCloseDropdown={handleCloseDropdown}
62
+ changePageSize={changePageSize}
63
+ />
64
+ ))}
65
+ </div>
66
+ )}
67
+
68
+ <button type="button" className="select__button" onClick={handleDropdownToggle}>
69
+ <span>{selectedOption ? selectedOption.value : ''}</span>
70
+ <span className="select__icon">
71
+ <i className={font} />
72
+ </span>
73
+ </button>
74
+ </div>
75
+ )
76
+ }
77
+
78
+ export default PageSizeSelector
@@ -0,0 +1,127 @@
1
+ import { useEffect, useState } from 'react'
2
+ import PageSizeSelector from './PageSizeSelector'
3
+ import { Page, PageValueItemProps, PaginationProps } from './types'
4
+ import { createPageArr } from './utils'
5
+ import './pagination.scss'
6
+
7
+ const PageValueItem = ({ value, isSelected, selectPage }: PageValueItemProps) => {
8
+ const classes = isSelected ? 'page__button page__button--selected' : 'page__button'
9
+ const handlePageSelection = () => {
10
+ selectPage(value)
11
+ }
12
+
13
+ return (
14
+ <li className="page">
15
+ <button className={classes} onClick={handlePageSelection} type="button">
16
+ {value}
17
+ </button>
18
+ </li>
19
+ )
20
+ }
21
+
22
+ // NOTE: This component will heavily benefit from data normalization
23
+ const Pagination = ({
24
+ size,
25
+ pageSize,
26
+ offset,
27
+ changePage,
28
+ changePageSize,
29
+ isPageSizeFix,
30
+ pageSizeOptions,
31
+ rootClassName,
32
+ }: PaginationProps) => {
33
+ const [pages, setPages] = useState<Page[]>([])
34
+
35
+ useEffect(() => {
36
+ const _pages = createPageArr({ size, pageSize, selectedPageNo: 1 })
37
+ setPages(_pages)
38
+ }, [size, pageSize])
39
+
40
+ useEffect(() => {
41
+ const selectedPageNo = 1 + Math.floor(offset / pageSize)
42
+ const _pages = createPageArr({ size, pageSize, selectedPageNo })
43
+ setPages(_pages)
44
+ }, [offset])
45
+
46
+ const selectPage = (selectedPageNo: number): void => {
47
+ const _pages = createPageArr({ size, pageSize, selectedPageNo })
48
+ setPages(_pages)
49
+ changePage(selectedPageNo)
50
+ }
51
+
52
+ const selectPreviousPage = (): void => {
53
+ const currPage = pages.find((page) => page.selected)
54
+ const selectedPageNo = currPage.value - 1
55
+ selectPage(selectedPageNo)
56
+ }
57
+
58
+ const selectNextPage = (): void => {
59
+ const currPage = pages.find((page) => page.selected)
60
+ const selectedPageNo = currPage.value + 1
61
+ selectPage(selectedPageNo)
62
+ }
63
+
64
+ const lastPageNo = offset + pageSize < size ? offset + pageSize : size
65
+ const pageNoIndex = pages.findIndex((page) => page.selected)
66
+ const visiblePages = pages.filter((page) => page.isVisible)
67
+ return (
68
+ // TODO: Remove pagination-wrapper from dashboard
69
+ <div className={rootClassName || ''}>
70
+ <div className="page-number">
71
+ {offset + 1} - {lastPageNo} of {size}
72
+ </div>
73
+
74
+ <ul className="pagination">
75
+ <li className="page">
76
+ <button
77
+ className="page__button page__button--icon"
78
+ disabled={!pageNoIndex}
79
+ onClick={selectPreviousPage}
80
+ type="button"
81
+ aria-label="Previous page"
82
+ >
83
+ <span className="left-icon">
84
+ <i className="fa fa-chevron-left" />
85
+ </span>
86
+ </button>
87
+ </li>
88
+
89
+ {visiblePages.map((page) => (
90
+ <PageValueItem
91
+ value={page.value}
92
+ isSelected={page.selected}
93
+ key={page.value}
94
+ selectPage={selectPage}
95
+ />
96
+ ))}
97
+
98
+ <li className="page">
99
+ <button
100
+ className="page__button page__button--icon"
101
+ disabled={pageNoIndex === pages.length - 1}
102
+ onClick={selectNextPage}
103
+ type="button"
104
+ aria-label="Next page"
105
+ >
106
+ <span className="left-icon">
107
+ <i className="fa fa-chevron-right" />
108
+ </span>
109
+ </button>
110
+ </li>
111
+ </ul>
112
+
113
+ {!isPageSizeFix && (
114
+ <div className="select">
115
+ <span className="select__placeholder">Rows per page</span>
116
+ <PageSizeSelector
117
+ pageSizeOptions={pageSizeOptions}
118
+ pageSize={pageSize}
119
+ changePageSize={changePageSize}
120
+ />
121
+ </div>
122
+ )}
123
+ </div>
124
+ )
125
+ }
126
+
127
+ export default Pagination
@@ -0,0 +1,6 @@
1
+ export const VISIBLE_PAGES_LIMIT = 5
2
+ export const FALLBACK_PAGE_SIZE_OPTIONS = [
3
+ { value: 20, selected: true },
4
+ { value: 40, selected: false },
5
+ { value: 50, selected: false },
6
+ ]
@@ -0,0 +1,3 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ // Disabling since might need to export types as well
3
+ export { default as Pagination } from './Pagination'
@@ -0,0 +1,123 @@
1
+ .pagination-wrapper {
2
+ display: flex;
3
+ align-items: center;
4
+ padding: 0px 24px;
5
+ justify-content: space-between;
6
+ margin: 0px;
7
+ background-color: var(--white);
8
+ }
9
+
10
+ .pagination {
11
+ margin-top: 16px;
12
+ margin-bottom: 16px;
13
+ padding: 0px;
14
+ }
15
+
16
+ .select {
17
+ display: flex;
18
+ align-items: center;
19
+ position: relative;
20
+ }
21
+
22
+ .select__placeholder {
23
+ font-size: 12px;
24
+ font-weight: normal;
25
+ font-style: normal;
26
+ font-stretch: normal;
27
+ line-height: 1.5;
28
+ letter-spacing: normal;
29
+ color: var(--N700);
30
+ margin-right: 8px;
31
+ }
32
+
33
+ .pagination__select-menu {
34
+ padding: 0px;
35
+ list-style: none;
36
+ overflow: hidden;
37
+ border: solid 1px var(--N200);
38
+ border-radius: 4px;
39
+ width: 64px;
40
+ position: absolute;
41
+ bottom: 31px;
42
+ background-color: var(--white);;
43
+ }
44
+
45
+ .select__button {
46
+ width: 64px;
47
+ background-color: transparent;
48
+ border-radius: 4px;
49
+ border: solid 1px var(--N200);
50
+ padding: 5px 10px;
51
+ text-align: left;
52
+ }
53
+
54
+ .select__item {
55
+ padding: 5px 10px;
56
+ cursor: pointer;
57
+ }
58
+
59
+ .select__icon {
60
+ margin-left: 18px;
61
+ }
62
+
63
+ .page {
64
+ margin: 0px 8px;
65
+ display: inline-block;
66
+ }
67
+
68
+ .page-number {
69
+ font-size: 12px;
70
+ font-weight: normal;
71
+ font-style: normal;
72
+ font-stretch: normal;
73
+ line-height: 1.5;
74
+ letter-spacing: normal;
75
+ color: var(--N700);
76
+ }
77
+
78
+ .page__button {
79
+ width: 24px;
80
+ height: 24px;
81
+ border-radius: 8px;
82
+ color: var(--B500);
83
+ background-color: var(--white);
84
+ padding: 0px;
85
+ user-select: none;
86
+ }
87
+
88
+ .page__button--icon {
89
+ background-color: var(--white);
90
+ color: var(--B500);
91
+ }
92
+
93
+ /* MODIFIERS */
94
+
95
+ .page__button--selected {
96
+ color: var(--white);
97
+ background-color: var(--B500);
98
+ }
99
+
100
+ /* States and Selectorys */
101
+
102
+ .page__button:disabled {
103
+ opacity: 0.5;
104
+ }
105
+
106
+ .select__item:hover {
107
+ background-color: var(--N50);
108
+ }
109
+
110
+ .page__button:hover ~ :disabled {
111
+ background-color: var(--B100);
112
+ }
113
+
114
+ .page__button--selected:hover {
115
+ color: var(--white);
116
+ background-color: var(--B500);
117
+ }
118
+
119
+ @media (min-width: 1024px) {
120
+ .pagination {
121
+ margin: 16px auto;
122
+ }
123
+ }
@@ -0,0 +1,55 @@
1
+ export interface PageSizeOption {
2
+ value: number
3
+ selected: boolean
4
+ }
5
+ export interface PaginationProps {
6
+ /**
7
+ * number of items
8
+ */
9
+ size: number
10
+ /**
11
+ * pageSize
12
+ */
13
+ pageSize: number
14
+ offset: number
15
+ changePage: (pageNo: number) => void
16
+ changePageSize?: (pageSize: number) => void
17
+ /**
18
+ * If true will not show page size selector
19
+ */
20
+ isPageSizeFix?: boolean
21
+ /**
22
+ * If given would show these options in page size selector else [20,40,50] with 20 as selected
23
+ */
24
+ pageSizeOptions?: PageSizeOption[]
25
+ /**
26
+ * class for wrapper
27
+ */
28
+ rootClassName?: string
29
+ }
30
+
31
+ export interface Page {
32
+ value: number
33
+ selected: boolean
34
+ isVisible: boolean
35
+ }
36
+
37
+ export interface CreatePageArrType extends Pick<PaginationProps, 'size' | 'pageSize'> {
38
+ selectedPageNo: number
39
+ }
40
+
41
+ export interface PageSizeSelectorProps
42
+ extends Pick<PaginationProps, 'pageSizeOptions' | 'pageSize' | 'changePageSize'> {}
43
+
44
+ export interface PageSizeItemsProps extends Pick<PageSizeSelectorProps, 'changePageSize'> {
45
+ optionValue: PageSizeOption['value']
46
+ options: PageSizeOption[]
47
+ setOptions: React.Dispatch<React.SetStateAction<PageSizeOption[]>>
48
+ handleCloseDropdown: () => void
49
+ }
50
+
51
+ export interface PageValueItemProps {
52
+ value: PageSizeOption['value']
53
+ isSelected: PageSizeOption['selected']
54
+ selectPage: (selectedPageNo: number) => void
55
+ }
@@ -0,0 +1,24 @@
1
+ import { CreatePageArrType, Page, PageSizeOption } from './types'
2
+ import { FALLBACK_PAGE_SIZE_OPTIONS, VISIBLE_PAGES_LIMIT } from './constants'
3
+
4
+ /**
5
+ * Returns an array of pages numbers and whether they are selected, visible or not
6
+ */
7
+ export const createPageArr = ({ size, pageSize, selectedPageNo }: CreatePageArrType): Page[] => {
8
+ const arr = []
9
+ const numberOfPages = Math.ceil(size / pageSize)
10
+ // we are showing 2 numbers before and after the selected page, so computing the lower and upper bounds
11
+ const lowerBound = selectedPageNo - 2 < 1 ? 1 : selectedPageNo - 2
12
+ const upperBound = selectedPageNo + 2 > numberOfPages ? numberOfPages : selectedPageNo + 2
13
+ for (let i = 1; i <= numberOfPages; i++) {
14
+ arr.push({
15
+ value: i,
16
+ selected: i === selectedPageNo,
17
+ isVisible: upperBound - VISIBLE_PAGES_LIMIT < i && i < lowerBound + VISIBLE_PAGES_LIMIT,
18
+ })
19
+ }
20
+ return arr
21
+ }
22
+
23
+ export const getDefaultPageValueOptions = (pageSizeOptions: PageSizeOption[]): PageSizeOption[] =>
24
+ pageSizeOptions?.length ? pageSizeOptions : FALLBACK_PAGE_SIZE_OPTIONS
@@ -47,3 +47,4 @@ export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSel
47
47
  export * from './AddCDButton'
48
48
  export * from './CustomInput'
49
49
  export * from './DraggableWrapper'
50
+ export * from './Pagination'