@knovator/pagecreator-admin 1.4.0 → 1.4.1

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 (167) hide show
  1. package/index.d.ts +1 -0
  2. package/package.json +38 -42
  3. package/src/{index.d.ts → index.ts} +1 -0
  4. package/src/lib/api/index.ts +70 -0
  5. package/src/lib/api/list.ts +59 -0
  6. package/src/lib/components/Page/AddButton/AddButton.tsx +16 -0
  7. package/src/lib/components/Page/AddButton/{index.d.ts → index.ts} +1 -0
  8. package/src/lib/components/Page/Form/PageForm.tsx +206 -0
  9. package/src/lib/components/Page/Form/{index.d.ts → index.ts} +1 -0
  10. package/src/lib/components/Page/Page/Page.tsx +151 -0
  11. package/src/lib/components/Page/Page/{index.d.ts → index.ts} +1 -0
  12. package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +50 -0
  13. package/src/lib/components/Page/PageFormActions/{index.d.ts → index.ts} +1 -0
  14. package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +16 -0
  15. package/src/lib/components/Page/PageFormWrapper/{index.d.ts → index.ts} +1 -0
  16. package/src/lib/components/Page/Pagination/PagePagination.tsx +26 -0
  17. package/src/lib/components/Page/Pagination/{index.d.ts → index.ts} +1 -0
  18. package/src/lib/components/Page/Search/PageSearch.tsx +32 -0
  19. package/src/lib/components/Page/Search/{index.d.ts → index.tsx} +1 -0
  20. package/src/lib/components/Page/Table/PageTable.tsx +36 -0
  21. package/src/lib/components/Page/Table/{index.d.ts → index.ts} +1 -0
  22. package/src/lib/components/Page/{index.d.ts → index.ts} +1 -0
  23. package/src/lib/components/Widget/AddButton/AddButton.tsx +16 -0
  24. package/src/lib/components/Widget/AddButton/{index.d.ts → index.ts} +1 -0
  25. package/src/lib/components/Widget/Form/ItemsAccordian.tsx +354 -0
  26. package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +43 -0
  27. package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +190 -0
  28. package/src/lib/components/Widget/Form/Tabs/{index.d.ts → index.ts} +1 -0
  29. package/src/lib/components/Widget/Form/WidgetForm.tsx +771 -0
  30. package/src/lib/components/Widget/Form/{index.d.ts → index.ts} +1 -0
  31. package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +26 -0
  32. package/src/lib/components/Widget/Pagination/{index.d.ts → index.ts} +1 -0
  33. package/src/lib/components/Widget/Search/WidgetSearch.tsx +32 -0
  34. package/src/lib/components/Widget/Search/{index.d.ts → index.tsx} +1 -0
  35. package/src/lib/components/Widget/Table/WidgetTable.tsx +70 -0
  36. package/src/lib/components/Widget/Table/{index.d.ts → index.ts} +1 -0
  37. package/src/lib/components/Widget/Widget/Widget.tsx +173 -0
  38. package/src/lib/components/Widget/Widget/{index.d.ts → index.ts} +1 -0
  39. package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +50 -0
  40. package/src/lib/components/Widget/WidgetFormActions/{index.d.ts → index.ts} +1 -0
  41. package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +16 -0
  42. package/src/lib/components/Widget/WidgetFormWrapper/{index.d.ts → index.ts} +1 -0
  43. package/src/lib/components/Widget/{index.d.ts → index.tsx} +1 -0
  44. package/src/lib/components/common/Accordian/Accordian.tsx +56 -0
  45. package/src/lib/components/common/Accordian/{index.d.ts → index.ts} +1 -0
  46. package/src/lib/components/common/Button/Button.tsx +45 -0
  47. package/src/lib/components/common/Button/{index.d.ts → index.ts} +1 -0
  48. package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +47 -0
  49. package/src/lib/components/common/ConfirmPopover/{index.d.ts → index.ts} +1 -0
  50. package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +74 -0
  51. package/src/lib/components/common/DNDItemsList/{index.d.ts → index.ts} +1 -0
  52. package/src/lib/components/common/DeleteModal/DeleteModal.tsx +72 -0
  53. package/src/lib/components/common/DeleteModal/index.tsx +3 -0
  54. package/src/lib/components/common/Drawer/Drawer.tsx +79 -0
  55. package/src/lib/components/common/Drawer/{index.d.ts → index.ts} +1 -0
  56. package/src/lib/components/common/Form/Form.tsx +256 -0
  57. package/src/lib/components/common/Form/SimpleForm.tsx +314 -0
  58. package/src/lib/components/common/Form/{index.d.ts → index.ts} +1 -0
  59. package/src/lib/components/common/FormActions/FormActions.tsx +37 -0
  60. package/src/lib/components/common/FormActions/{index.d.ts → index.ts} +1 -0
  61. package/src/lib/components/common/ImageUpload/ImageUpload.tsx +113 -0
  62. package/src/lib/components/common/ImageUpload/index.tsx +3 -0
  63. package/src/lib/components/common/Input/Checkbox.tsx +25 -0
  64. package/src/lib/components/common/Input/Input.tsx +51 -0
  65. package/src/lib/components/common/Input/ReactSelect.tsx +61 -0
  66. package/src/lib/components/common/Input/Select.tsx +47 -0
  67. package/src/lib/components/common/Input/SrcSet.tsx +143 -0
  68. package/src/lib/components/common/Input/index.ts +20 -0
  69. package/src/lib/components/common/Modal/Modal.tsx +57 -0
  70. package/src/lib/components/common/Modal/index.tsx +3 -0
  71. package/src/lib/components/common/Pagination/Pagination.tsx +88 -0
  72. package/src/lib/components/common/Pagination/{index.d.ts → index.ts} +1 -0
  73. package/src/lib/components/common/Table/Table.tsx +133 -0
  74. package/src/lib/components/common/Table/{index.d.ts → index.ts} +1 -0
  75. package/src/lib/components/common/Toggle/Toggle.tsx +23 -0
  76. package/src/lib/components/common/Toggle/{index.d.ts → index.ts} +1 -0
  77. package/src/lib/constants/common.ts +145 -0
  78. package/src/lib/context/PageContext.tsx +100 -0
  79. package/src/lib/context/ProviderContext.tsx +52 -0
  80. package/src/lib/context/WidgetContext.tsx +127 -0
  81. package/src/lib/helper/utils.ts +46 -0
  82. package/src/lib/hooks/usePage.tsx +306 -0
  83. package/src/lib/hooks/usePagination.tsx +41 -0
  84. package/src/lib/hooks/useWidget.tsx +503 -0
  85. package/src/lib/icons/chevronDown.tsx +21 -0
  86. package/src/lib/icons/chevronLeft.tsx +20 -0
  87. package/src/lib/icons/chevronRight.tsx +20 -0
  88. package/src/lib/icons/chevronUp.tsx +21 -0
  89. package/src/lib/icons/close.tsx +21 -0
  90. package/src/lib/icons/pencil.tsx +21 -0
  91. package/src/lib/icons/plus.tsx +23 -0
  92. package/src/lib/icons/settings.tsx +35 -0
  93. package/src/lib/icons/trash.tsx +21 -0
  94. package/src/lib/types/api.ts +44 -0
  95. package/src/lib/types/common.ts +31 -0
  96. package/src/lib/types/components.ts +430 -0
  97. package/src/lib/types/context.ts +184 -0
  98. package/src/styles/index.css +481 -0
  99. package/index.cjs +0 -7881
  100. package/index.css +0 -2
  101. package/index.js +0 -7867
  102. package/src/lib/api/index.d.ts +0 -10
  103. package/src/lib/api/list.d.ts +0 -56
  104. package/src/lib/components/Page/AddButton/AddButton.d.ts +0 -3
  105. package/src/lib/components/Page/Form/PageForm.d.ts +0 -4
  106. package/src/lib/components/Page/Page/Page.d.ts +0 -13
  107. package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +0 -4
  108. package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +0 -4
  109. package/src/lib/components/Page/Pagination/PagePagination.d.ts +0 -3
  110. package/src/lib/components/Page/Search/PageSearch.d.ts +0 -3
  111. package/src/lib/components/Page/Table/PageTable.d.ts +0 -4
  112. package/src/lib/components/Widget/AddButton/AddButton.d.ts +0 -3
  113. package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +0 -4
  114. package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +0 -4
  115. package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +0 -4
  116. package/src/lib/components/Widget/Form/WidgetForm.d.ts +0 -4
  117. package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +0 -3
  118. package/src/lib/components/Widget/Search/WidgetSearch.d.ts +0 -3
  119. package/src/lib/components/Widget/Table/WidgetTable.d.ts +0 -4
  120. package/src/lib/components/Widget/Widget/Widget.d.ts +0 -13
  121. package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +0 -4
  122. package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +0 -4
  123. package/src/lib/components/common/Accordian/Accordian.d.ts +0 -13
  124. package/src/lib/components/common/Button/Button.d.ts +0 -4
  125. package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +0 -4
  126. package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +0 -4
  127. package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +0 -4
  128. package/src/lib/components/common/DeleteModal/index.d.ts +0 -2
  129. package/src/lib/components/common/Drawer/Drawer.d.ts +0 -9
  130. package/src/lib/components/common/Form/Form.d.ts +0 -15
  131. package/src/lib/components/common/Form/SimpleForm.d.ts +0 -18
  132. package/src/lib/components/common/FormActions/FormActions.d.ts +0 -10
  133. package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +0 -4
  134. package/src/lib/components/common/ImageUpload/index.d.ts +0 -2
  135. package/src/lib/components/common/Input/Checkbox.d.ts +0 -4
  136. package/src/lib/components/common/Input/Input.d.ts +0 -4
  137. package/src/lib/components/common/Input/ReactSelect.d.ts +0 -4
  138. package/src/lib/components/common/Input/Select.d.ts +0 -4
  139. package/src/lib/components/common/Input/SrcSet.d.ts +0 -4
  140. package/src/lib/components/common/Input/index.d.ts +0 -12
  141. package/src/lib/components/common/Modal/Modal.d.ts +0 -8
  142. package/src/lib/components/common/Modal/index.d.ts +0 -2
  143. package/src/lib/components/common/Pagination/Pagination.d.ts +0 -4
  144. package/src/lib/components/common/Table/Table.d.ts +0 -4
  145. package/src/lib/components/common/Toggle/Toggle.d.ts +0 -4
  146. package/src/lib/constants/common.d.ts +0 -122
  147. package/src/lib/context/PageContext.d.ts +0 -7
  148. package/src/lib/context/ProviderContext.d.ts +0 -5
  149. package/src/lib/context/WidgetContext.d.ts +0 -7
  150. package/src/lib/helper/utils.d.ts +0 -10
  151. package/src/lib/hooks/usePage.d.ts +0 -37
  152. package/src/lib/hooks/usePagination.d.ts +0 -15
  153. package/src/lib/hooks/useWidget.d.ts +0 -46
  154. package/src/lib/icons/chevronDown.d.ts +0 -4
  155. package/src/lib/icons/chevronLeft.d.ts +0 -4
  156. package/src/lib/icons/chevronRight.d.ts +0 -4
  157. package/src/lib/icons/chevronUp.d.ts +0 -4
  158. package/src/lib/icons/close.d.ts +0 -4
  159. package/src/lib/icons/pencil.d.ts +0 -4
  160. package/src/lib/icons/plus.d.ts +0 -4
  161. package/src/lib/icons/settings.d.ts +0 -4
  162. package/src/lib/icons/trash.d.ts +0 -4
  163. package/src/lib/types/api.d.ts +0 -34
  164. package/src/lib/types/common.d.ts +0 -30
  165. package/src/lib/types/components.d.ts +0 -423
  166. package/src/lib/types/context.d.ts +0 -135
  167. /package/src/lib/types/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,143 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import { useFieldArray } from 'react-hook-form';
4
+ import Close from '../../../icons/close';
5
+ import Plus from '../../../icons/plus';
6
+ import { InputProps, InputSizes, SrcSetMessageProps } from '../../../types';
7
+
8
+ const SrcSetInput = ({
9
+ size,
10
+ className,
11
+ rest,
12
+ error,
13
+ placeholder,
14
+ disabled = false,
15
+ }: {
16
+ size: InputSizes;
17
+ rest: any;
18
+ index: number;
19
+ error?: string;
20
+ className?: string;
21
+ placeholder?: string;
22
+ disabled?: boolean;
23
+ }) => {
24
+ return (
25
+ <div>
26
+ <input
27
+ className={classNames('khb_input', `khb_input-${size}`, className)}
28
+ type={'number'}
29
+ placeholder={placeholder}
30
+ disabled={disabled}
31
+ {...(rest || {})}
32
+ />
33
+ {error && <p className="khb_input-error">{error}</p>}
34
+ </div>
35
+ );
36
+ };
37
+
38
+ const SrcSet = ({
39
+ label,
40
+ size = 'base',
41
+ required,
42
+ error,
43
+ className,
44
+ register,
45
+ wrapperClassName,
46
+ control,
47
+ errors,
48
+ name,
49
+ disabled = false,
50
+
51
+ screenSizeRequired,
52
+ heightRequired,
53
+ minHeight,
54
+ minScreenSize,
55
+ minWidth,
56
+ widthRequired,
57
+ }: InputProps & SrcSetMessageProps) => {
58
+ const { fields, append, remove } = useFieldArray({
59
+ control,
60
+ name: name!,
61
+ });
62
+
63
+ return (
64
+ <div className={classNames('khb_input-wrapper', wrapperClassName)}>
65
+ {label && (
66
+ <label className="khb_input-label">
67
+ {label}
68
+ {required ? (
69
+ <span className="khb_input-label-required">*</span>
70
+ ) : null}
71
+ </label>
72
+ )}
73
+ <div className="khb_input-srcset-items">
74
+ {fields?.map((item, index) => (
75
+ <div key={index} className="khb_input-srcset">
76
+ <SrcSetInput
77
+ error={errors?.[index]?.['screenSize']?.message?.toString()}
78
+ index={index}
79
+ className={className}
80
+ size={size}
81
+ placeholder="Screen Size"
82
+ rest={register(`${name}.${index}.screenSize`, {
83
+ required: screenSizeRequired,
84
+ validate: (value: string) =>
85
+ Number(value) <= 0 ? minScreenSize : true,
86
+ })}
87
+ disabled={disabled}
88
+ />
89
+
90
+ <span className="p-2">=</span>
91
+ <SrcSetInput
92
+ error={errors?.[index]?.['width']?.message?.toString()}
93
+ index={index}
94
+ rest={register(`${name}.${index}.width`, {
95
+ required: widthRequired,
96
+ validate: (value: string) =>
97
+ Number(value) <= 0 ? minWidth : true,
98
+ })}
99
+ className={className}
100
+ size={size}
101
+ placeholder="Width"
102
+ disabled={disabled}
103
+ />
104
+
105
+ <span className="p-2">x</span>
106
+ <SrcSetInput
107
+ error={errors?.[index]?.['height']?.message?.toString()}
108
+ index={index}
109
+ rest={register(`${name}.${index}.height`, {
110
+ required: heightRequired,
111
+ validate: (value: string) =>
112
+ Number(value) <= 0 ? minHeight : true,
113
+ })}
114
+ className={className}
115
+ size={size}
116
+ placeholder="Height"
117
+ disabled={disabled}
118
+ />
119
+ <button
120
+ type="button"
121
+ className="khb_btn khb_btn-danger khb_btn-xs"
122
+ onClick={() => remove(index)}
123
+ disabled={disabled}
124
+ >
125
+ <Close />
126
+ </button>
127
+ </div>
128
+ ))}
129
+ <button
130
+ type="button"
131
+ disabled={disabled}
132
+ onClick={() => append({ screenSize: '', width: '', height: '' })}
133
+ className="khb_btn khb_btn-primary khb_btn-xs"
134
+ >
135
+ <Plus className="khb_srcset-remove" />
136
+ </button>
137
+ </div>
138
+ {error && <p className="khb_input-error ">{error}</p>}
139
+ </div>
140
+ );
141
+ };
142
+
143
+ export default SrcSet;
@@ -0,0 +1,20 @@
1
+ import Checkbox from "./Checkbox";
2
+ import Input from "./Input";
3
+ import Select from "./Select";
4
+ import ReactSelect from "./ReactSelect";
5
+ import SrcSet from './SrcSet';
6
+
7
+ export default Object.assign<
8
+ typeof Input,
9
+ {
10
+ Select: typeof Select;
11
+ ReactSelect: typeof ReactSelect;
12
+ Checkbox: typeof Checkbox;
13
+ SrcSet: typeof SrcSet;
14
+ }
15
+ >(Input, {
16
+ Select,
17
+ ReactSelect,
18
+ Checkbox,
19
+ SrcSet,
20
+ });
@@ -0,0 +1,57 @@
1
+ import React, { useRef } from "react";
2
+ import CSSTransition from "react-transition-group/CSSTransition";
3
+
4
+ import CloseIcon from "../../../icons/close";
5
+
6
+ interface ModalProps extends React.PropsWithChildren {
7
+ open: boolean;
8
+ onClose: () => void;
9
+ title?: string;
10
+ }
11
+
12
+ const Modal = ({ open, onClose, title, children }: ModalProps) => {
13
+ const nodeRef = useRef(null);
14
+ return (
15
+ <CSSTransition
16
+ ref={nodeRef}
17
+ in={open}
18
+ timeout={{ enter: 250, exit: 350 }}
19
+ classNames="khb_modal"
20
+ mountOnEnter
21
+ unmountOnExit
22
+ >
23
+ <div className="khb_modal-wrapper-1" ref={nodeRef} data-testid="modal">
24
+ <div className="khb_modal-wrapper-2">
25
+ <div
26
+ className="khb_modal-backdrop"
27
+ role="button"
28
+ onClick={onClose}
29
+ onKeyDown={onClose}
30
+ tabIndex={0}
31
+ />
32
+ <div className="khb_modal-container-1">
33
+ <div className="khb_modal-container-2">
34
+ <div className="khb_modal-main">
35
+ <div className="khb_modal-header">
36
+ <span className="khb_modal-title">{title}</span>
37
+ <button
38
+ className="khb_modal-close"
39
+ onClick={onClose}
40
+ onKeyDown={onClose}
41
+ tabIndex={-1}
42
+ data-testid="modal-close"
43
+ >
44
+ <CloseIcon />
45
+ </button>
46
+ </div>
47
+ <div className="p-4">{children}</div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </CSSTransition>
54
+ );
55
+ };
56
+
57
+ export default Modal;
@@ -0,0 +1,3 @@
1
+ import Modal from "./Modal"
2
+
3
+ export default Modal
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import { PaginationProps } from '../../../types';
3
+ import { TRANSLATION_PAIRS_COMMON } from '../../../constants/common';
4
+ import ChevronLeft from '../../../icons/chevronLeft';
5
+ import ChevronRight from '../../../icons/chevronRight';
6
+ import Button from '../Button';
7
+ import Input from '../Input';
8
+
9
+ const Pagination = ({
10
+ currentPage,
11
+ pageSize,
12
+ totalPages,
13
+ totalRecords,
14
+ setCurrentPage,
15
+ showingText = TRANSLATION_PAIRS_COMMON.showing,
16
+ pageText = TRANSLATION_PAIRS_COMMON.page,
17
+ ofText = TRANSLATION_PAIRS_COMMON.of,
18
+ previousContent,
19
+ nextContent,
20
+ }: PaginationProps) => {
21
+ const updatePagination = (newValue: number | string | undefined) => {
22
+ if (newValue && typeof newValue === 'number') {
23
+ if (newValue <= 0) {
24
+ newValue = 1;
25
+ } else if (newValue > totalPages) {
26
+ newValue = totalPages;
27
+ }
28
+ setCurrentPage(newValue);
29
+ }
30
+ };
31
+ const onPaginationButtonClick = (dir: 'next' | 'previous') => {
32
+ if (dir === 'next') {
33
+ updatePagination(currentPage + 1);
34
+ } else {
35
+ updatePagination(currentPage - 1);
36
+ }
37
+ };
38
+ return (
39
+ <nav className="khb_pagination" aria-label="Table navigation">
40
+ <span className="khb_pagination-total">
41
+ {showingText}{' '}
42
+ <span className="khb_pagination-total-showing">
43
+ {!totalRecords ? 0 : (currentPage - 1) * pageSize + 1}
44
+ </span>{' '}
45
+ -{' '}
46
+ <span className="khb_pagination-total-showing">
47
+ {Math.min(currentPage * pageSize, totalRecords)}
48
+ </span>{' '}
49
+ {ofText} {totalRecords}
50
+ </span>
51
+ <ul className="khb_pagination-actions">
52
+ <Button
53
+ size="xs"
54
+ type="secondary"
55
+ className="khb_pagination-previous"
56
+ disabled={currentPage - 1 <= 0}
57
+ onClick={() => onPaginationButtonClick('previous')}
58
+ >
59
+ {previousContent || <ChevronLeft srText="Previous" />}
60
+ </Button>
61
+ <div className="khb_pagination-pager">
62
+ {pageText}{' '}
63
+ <Input
64
+ className="mx-2"
65
+ size="xs"
66
+ type="number"
67
+ id="page"
68
+ value={currentPage}
69
+ onChange={(e) => updatePagination(Number(e.target.value))}
70
+ disabled={!totalRecords}
71
+ />{' '}
72
+ / {totalPages}
73
+ </div>
74
+ <Button
75
+ size="xs"
76
+ type="secondary"
77
+ className="khb_pagination-next"
78
+ disabled={currentPage >= totalPages}
79
+ onClick={() => onPaginationButtonClick('next')}
80
+ >
81
+ {nextContent || <ChevronRight srText="Next" />}
82
+ </Button>
83
+ </ul>
84
+ </nav>
85
+ );
86
+ };
87
+
88
+ export default Pagination;
@@ -1,2 +1,3 @@
1
1
  import Pagination from "./Pagination";
2
+
2
3
  export default Pagination;
@@ -0,0 +1,133 @@
1
+ import React from 'react';
2
+ import Pencil from '../../../icons/pencil';
3
+ import Trash from '../../../icons/trash';
4
+ import { ObjectType, TableDataItemFormat, TableProps } from '../../../types';
5
+
6
+ const Table = ({
7
+ data,
8
+ dataKeys,
9
+ actions,
10
+ loader,
11
+ loading,
12
+ extraActions,
13
+ actionsLabel,
14
+ extraColumns,
15
+ }: TableProps) => {
16
+ const cellItemRenderer = (
17
+ item: ObjectType,
18
+ dataKey: TableDataItemFormat,
19
+ index: number
20
+ ) => {
21
+ if (dataKey.highlight)
22
+ return (
23
+ <th scope="row" className="khb_table-row-heading" key={index}>
24
+ {item[dataKey.dataKey]}
25
+ </th>
26
+ );
27
+ else if (dataKey.Cell)
28
+ return (
29
+ <td className="khb_table-row-data" key={index}>
30
+ {dataKey.Cell({ row: item })}
31
+ </td>
32
+ );
33
+ else
34
+ return (
35
+ <td className="khb_table-row-data" key={index}>
36
+ {item[dataKey.dataKey]}
37
+ </td>
38
+ );
39
+ };
40
+ return (
41
+ <div className={`khb_table-container`} data-testid="table">
42
+ <div className={`khb_table-height`}>
43
+ {loading && loader ? (
44
+ <div className="khb_table-height">{loader}</div>
45
+ ) : (
46
+ <table
47
+ className={`khb_table ${data.length > 0 ? '' : 'empty-table'}`}
48
+ >
49
+ <thead className="khb_thead">
50
+ <tr>
51
+ {dataKeys.map((key, i) => (
52
+ <th scope="col" className="khb_table-heading" key={i}>
53
+ {key.label}
54
+ </th>
55
+ ))}
56
+ {Array.isArray(extraColumns)
57
+ ? extraColumns.map((action) => (
58
+ <th scope="col" className="khb_table-heading">
59
+ {action.label}
60
+ </th>
61
+ ))
62
+ : null}
63
+ {(actions && (actions?.edit || actions?.delete)) ||
64
+ typeof extraActions === 'function' ? (
65
+ <th scope="col" className="khb_table-heading">
66
+ {actionsLabel}
67
+ </th>
68
+ ) : null}
69
+ </tr>
70
+ </thead>
71
+ <tbody className="khb_tbody">
72
+ {data.length > 0 ? (
73
+ data.map((item: ObjectType, i: number) => (
74
+ <tr
75
+ className="khb_table-row"
76
+ key={item['id'] || item['_id'] || i}
77
+ >
78
+ {dataKeys.map((key, j) => cellItemRenderer(item, key, j))}
79
+ {Array.isArray(extraColumns)
80
+ ? extraColumns.map((column) => (
81
+ <td className="khb_table-row-data" key={i}>
82
+ {column.Cell(item)}
83
+ </td>
84
+ ))
85
+ : null}
86
+ {(actions && (actions?.edit || actions?.delete)) ||
87
+ typeof extraActions === 'function' ? (
88
+ <td className="khb_table-row-actions">
89
+ {actions &&
90
+ actions.edit &&
91
+ typeof actions.edit === 'function' ? (
92
+ <button
93
+ className="khb_actions-update"
94
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
95
+ // @ts-ignore
96
+ onClick={() => actions.edit(item)}
97
+ >
98
+ <Pencil />
99
+ </button>
100
+ ) : null}
101
+ {actions &&
102
+ actions.delete &&
103
+ typeof actions.delete === 'function' && !!item['canDel'] !== false && (
104
+ <button
105
+ className="khb_actions-delete"
106
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
107
+ // @ts-ignore
108
+ onClick={() => actions.delete!(item)}
109
+ >
110
+ <Trash />
111
+ </button>
112
+ )}
113
+ {typeof extraActions === 'function'
114
+ ? extraActions(item)
115
+ : null}
116
+ </td>
117
+ ) : null}
118
+ </tr>
119
+ ))
120
+ ) : (
121
+ <tr className="empty-row">
122
+ <td colSpan={(dataKeys?.length || 0) + 1}>No data found</td>
123
+ </tr>
124
+ )}
125
+ </tbody>
126
+ </table>
127
+ )}
128
+ </div>
129
+ </div>
130
+ );
131
+ };
132
+
133
+ export default Table;
@@ -1,2 +1,3 @@
1
1
  import Table from './Table';
2
+
2
3
  export default Table;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { ToggleProps } from '../../../types';
3
+
4
+ const Toggle = ({
5
+ isChecked,
6
+ disabled,
7
+ onChange,
8
+ switchClass,
9
+ }: ToggleProps) => {
10
+ return (
11
+ <label className={switchClass || 'khb_switch'} data-testid="khb_switch">
12
+ <input
13
+ type="checkbox"
14
+ onChange={() => onChange && onChange(!isChecked)}
15
+ checked={isChecked}
16
+ disabled={disabled}
17
+ />
18
+ <span className="slider round" />
19
+ </label>
20
+ );
21
+ };
22
+
23
+ export default Toggle;
@@ -1,2 +1,3 @@
1
1
  import Toggle from "./Toggle";
2
+
2
3
  export default Toggle;
@@ -0,0 +1,145 @@
1
+ const DEFAULT_OFFSET_PAYLOAD = 0;
2
+ const DECIMAL_REDIX = 10;
3
+ const DEFAULT_CURRENT_PAGE = 1;
4
+ const INTERNAL_ERROR_CODE = 'INTERNAL_ERROR';
5
+ const DEFAULT_LIMIT = 10;
6
+ const PAGE_LIMITS = [10, 20, 30];
7
+
8
+ enum CALLBACK_CODES {
9
+ 'GET_ALL' = 'GET_ALL',
10
+ 'GET_SINGLE' = 'GET_SINGLE',
11
+ 'CREATE' = 'CREATE',
12
+ 'UPDATE' = 'UPDATE',
13
+ 'PARTIAL_UPDATE' = 'PARTIAL_UPDATE',
14
+ 'DELETE' = 'DELETE',
15
+ 'IMAGE_UPLOAD' = 'IMAGE_UPLOAD',
16
+ 'IMAGE_REMOVE' = 'IMAGE_REMOVE',
17
+ 'INTERNAL' = 'INTERNAL',
18
+ }
19
+
20
+ const CONSTANTS = {
21
+ EMPTY_REGEX: / /g,
22
+ SLUG_REGEX: /^[\da-z-]*$/,
23
+ SLUG_REPLACE_REGEX: /[^\da-z-]/gi,
24
+ };
25
+
26
+ const DEFAULT_PERMISSIONS = {
27
+ list: true,
28
+ add: true,
29
+ delete: true,
30
+ partialUpdate: true,
31
+ update: true,
32
+ };
33
+
34
+ const TRANSLATION_PAIRS_COMMON = {
35
+ confirmationRequired: 'Confirmation Required',
36
+ permanentlyDelete: 'You are about to permanently delete the',
37
+ lossOfData:
38
+ 'This action can lead to data loss. To prevent accidental actions we ask you to confirm your intention.',
39
+ pleaseType: 'Please type',
40
+ toProceedOrCancel: 'to processed or close this modal to cancel.',
41
+ confirm: 'Confirm',
42
+ next: 'Next',
43
+ previous: 'Previous',
44
+ page: 'Page',
45
+ indicatesRequired: 'Indicates fields are required',
46
+ cancel: 'Cancel',
47
+ yes: 'Yes',
48
+ delete: 'Delete',
49
+ create: 'Create',
50
+ update: 'Update',
51
+ showing: 'Showing',
52
+ add: 'Add',
53
+ of: 'of',
54
+ typeHerePlaceholder: 'Type Here',
55
+
56
+ code: 'Code',
57
+ codePlaceholder: 'Enter code',
58
+ codeRequired: 'Code is required',
59
+ name: 'Name',
60
+ namePlaceholder: 'Enter name',
61
+ nameRequired: 'Name is required',
62
+ title: 'Title',
63
+ titlePlaceholder: 'Enter title',
64
+ titleRequired: 'Title is required',
65
+
66
+ active: 'Active',
67
+ actions: 'Actions',
68
+ };
69
+
70
+ const TRANSLATION_PAIRS_WIDGET = {
71
+ itemsType: 'Items Type',
72
+ itemsTypePlaceholder: 'Select Items Type',
73
+ widgetType: 'Widget Type',
74
+ widgetTypeRequired: 'Widget Type is required',
75
+ color: 'Color',
76
+ webPerRow: 'Web Per Row',
77
+ webPerRowPlaceholder: 'Enter web per row',
78
+ mobilePerRow: 'Mobile Per Row',
79
+ mobilePerRowPlaceholder: 'Enter mobile per row',
80
+ tabletPerRow: 'Tablet Per Row',
81
+ tabletPerRowPlaceholder: 'Enter tablet per row',
82
+ mobileItems: 'Mobile Items',
83
+ webItems: 'Web Items',
84
+ searchPlaceholder: 'Search Widgets...',
85
+ autoPlay: 'Auto Play',
86
+ addWidgetTitle: 'Add Widget',
87
+ updateWidgetTitle: 'Update Widget',
88
+ webPerRowRequired: 'Web Per Row is required',
89
+ tabletPerRowRequired: 'Tablet Per Row is required',
90
+ mobilePerRowRequired: 'Mobile Per Row is required',
91
+ tabDeleteTitle: 'Are you sure you want to delete this tab?',
92
+ widgetTitleInfo: 'HTML is supported',
93
+ minPerRow: 'Value must be greater than zero',
94
+ // actionsLabel': 'Actions', -> 'actions'
95
+ tabNameRequired: 'Tab Name is required',
96
+
97
+ subtitle: 'Subtitle',
98
+ subTitlePlaceholder: 'Enter Subtitle',
99
+ altText: 'Alt Text',
100
+ altTextPlaceholder: 'Enter alt text',
101
+ link: 'Link',
102
+ linkPlaceholder: 'Enter link',
103
+ image: 'Image',
104
+ uploadFile: 'Upload File',
105
+ dragDrop: 'or drag and drop',
106
+ allowedFormat: 'PNG, JPG, SVG up to 2 MB',
107
+ srcset: 'Srcset',
108
+ screenSizeRequired: 'ScreenSize is required',
109
+ widthRequired: 'Width is required',
110
+ heightRequired: 'Height is required',
111
+ minScreenSize: 'ScreenSize should be greater than 0',
112
+ minWidth: 'Width should be greater than 0',
113
+ minHeight: 'Height should be greater than 0',
114
+ deleteTitle: 'Are you sure you want to delete this item?',
115
+ htmlContent: 'HTML',
116
+ htmlContentPlaceholder: 'Enter your html',
117
+ htmlContentRequired: 'html is required',
118
+ textContent: 'Text',
119
+ textContentRequired: 'Text is required',
120
+ textContentInfo: 'HTML is supported',
121
+ textContentPlaceholder: 'Enter text',
122
+ };
123
+ const TRANSLATION_PAIRS_PAGE = {
124
+ widgets: 'Widgets',
125
+ slug: 'Slug',
126
+ slugPlaceholder: 'Enter Slug',
127
+ slugRequired: 'Slug is required',
128
+ addPage: 'Add Page',
129
+ updatePage: 'Update Page',
130
+ searchPages: 'Search Pages...',
131
+ };
132
+ export {
133
+ CONSTANTS,
134
+ CALLBACK_CODES,
135
+ DECIMAL_REDIX,
136
+ DEFAULT_CURRENT_PAGE,
137
+ DEFAULT_OFFSET_PAYLOAD,
138
+ INTERNAL_ERROR_CODE,
139
+ DEFAULT_PERMISSIONS,
140
+ TRANSLATION_PAIRS_COMMON,
141
+ DEFAULT_LIMIT,
142
+ PAGE_LIMITS,
143
+ TRANSLATION_PAIRS_WIDGET,
144
+ TRANSLATION_PAIRS_PAGE,
145
+ };