@knovator/pagecreator-admin 1.2.2 → 1.2.3

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 (166) hide show
  1. package/README.md +205 -205
  2. package/index.d.ts +1 -0
  3. package/package.json +38 -42
  4. package/src/{index.d.ts → index.ts} +1 -0
  5. package/src/lib/api/index.ts +70 -0
  6. package/src/lib/api/list.ts +59 -0
  7. package/src/lib/components/Page/AddButton/AddButton.tsx +16 -0
  8. package/src/lib/components/Page/AddButton/{index.d.ts → index.ts} +1 -0
  9. package/src/lib/components/Page/Form/PageForm.tsx +194 -0
  10. package/src/lib/components/Page/Form/{index.d.ts → index.ts} +1 -0
  11. package/src/lib/components/Page/Page/Page.tsx +151 -0
  12. package/src/lib/components/Page/Page/{index.d.ts → index.ts} +1 -0
  13. package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +50 -0
  14. package/src/lib/components/Page/PageFormActions/{index.d.ts → index.ts} +1 -0
  15. package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +16 -0
  16. package/src/lib/components/Page/PageFormWrapper/{index.d.ts → index.ts} +1 -0
  17. package/src/lib/components/Page/Pagination/PagePagination.tsx +26 -0
  18. package/src/lib/components/Page/Pagination/{index.d.ts → index.ts} +1 -0
  19. package/src/lib/components/Page/Search/PageSearch.tsx +32 -0
  20. package/src/lib/components/Page/Search/{index.d.ts → index.tsx} +1 -0
  21. package/src/lib/components/Page/Table/PageTable.tsx +36 -0
  22. package/src/lib/components/Page/Table/{index.d.ts → index.ts} +1 -0
  23. package/src/lib/components/Page/{index.d.ts → index.ts} +1 -0
  24. package/src/lib/components/Widget/AddButton/AddButton.tsx +16 -0
  25. package/src/lib/components/Widget/AddButton/{index.d.ts → index.ts} +1 -0
  26. package/src/lib/components/Widget/Form/ItemsAccordian.tsx +354 -0
  27. package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +43 -0
  28. package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +190 -0
  29. package/src/lib/components/Widget/Form/Tabs/{index.d.ts → index.ts} +1 -0
  30. package/src/lib/components/Widget/Form/WidgetForm.tsx +771 -0
  31. package/src/lib/components/Widget/Form/{index.d.ts → index.ts} +1 -0
  32. package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +26 -0
  33. package/src/lib/components/Widget/Pagination/{index.d.ts → index.ts} +1 -0
  34. package/src/lib/components/Widget/Search/WidgetSearch.tsx +32 -0
  35. package/src/lib/components/Widget/Search/{index.d.ts → index.tsx} +1 -0
  36. package/src/lib/components/Widget/Table/WidgetTable.tsx +70 -0
  37. package/src/lib/components/Widget/Table/{index.d.ts → index.ts} +1 -0
  38. package/src/lib/components/Widget/Widget/Widget.tsx +173 -0
  39. package/src/lib/components/Widget/Widget/{index.d.ts → index.ts} +1 -0
  40. package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +50 -0
  41. package/src/lib/components/Widget/WidgetFormActions/{index.d.ts → index.ts} +1 -0
  42. package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +16 -0
  43. package/src/lib/components/Widget/WidgetFormWrapper/{index.d.ts → index.ts} +1 -0
  44. package/src/lib/components/Widget/{index.d.ts → index.tsx} +1 -0
  45. package/src/lib/components/common/Accordian/Accordian.tsx +56 -0
  46. package/src/lib/components/common/Accordian/{index.d.ts → index.ts} +1 -0
  47. package/src/lib/components/common/Button/Button.tsx +45 -0
  48. package/src/lib/components/common/Button/{index.d.ts → index.ts} +1 -0
  49. package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +47 -0
  50. package/src/lib/components/common/ConfirmPopover/{index.d.ts → index.ts} +1 -0
  51. package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +53 -0
  52. package/src/lib/components/common/DNDItemsList/{index.d.ts → index.ts} +1 -0
  53. package/src/lib/components/common/DeleteModal/DeleteModal.tsx +72 -0
  54. package/src/lib/components/common/DeleteModal/index.tsx +3 -0
  55. package/src/lib/components/common/Drawer/Drawer.tsx +79 -0
  56. package/src/lib/components/common/Drawer/{index.d.ts → index.ts} +1 -0
  57. package/src/lib/components/common/Form/Form.tsx +256 -0
  58. package/src/lib/components/common/Form/SimpleForm.tsx +314 -0
  59. package/src/lib/components/common/Form/{index.d.ts → index.ts} +1 -0
  60. package/src/lib/components/common/FormActions/FormActions.tsx +37 -0
  61. package/src/lib/components/common/FormActions/{index.d.ts → index.ts} +1 -0
  62. package/src/lib/components/common/ImageUpload/ImageUpload.tsx +113 -0
  63. package/src/lib/components/common/ImageUpload/index.tsx +3 -0
  64. package/src/lib/components/common/Input/Checkbox.tsx +25 -0
  65. package/src/lib/components/common/Input/Input.tsx +51 -0
  66. package/src/lib/components/common/Input/ReactSelect.tsx +60 -0
  67. package/src/lib/components/common/Input/Select.tsx +47 -0
  68. package/src/lib/components/common/Input/SrcSet.tsx +143 -0
  69. package/src/lib/components/common/Input/index.ts +20 -0
  70. package/src/lib/components/common/Modal/Modal.tsx +57 -0
  71. package/src/lib/components/common/Modal/index.tsx +3 -0
  72. package/src/lib/components/common/Pagination/Pagination.tsx +88 -0
  73. package/src/lib/components/common/Pagination/{index.d.ts → index.ts} +1 -0
  74. package/src/lib/components/common/Table/Table.tsx +133 -0
  75. package/src/lib/components/common/Table/{index.d.ts → index.ts} +1 -0
  76. package/src/lib/components/common/Toggle/Toggle.tsx +23 -0
  77. package/src/lib/components/common/Toggle/{index.d.ts → index.ts} +1 -0
  78. package/src/lib/constants/common.ts +145 -0
  79. package/src/lib/context/PageContext.tsx +100 -0
  80. package/src/lib/context/ProviderContext.tsx +52 -0
  81. package/src/lib/context/WidgetContext.tsx +127 -0
  82. package/src/lib/helper/utils.ts +46 -0
  83. package/src/lib/hooks/usePage.tsx +307 -0
  84. package/src/lib/hooks/usePagination.tsx +41 -0
  85. package/src/lib/hooks/useWidget.tsx +503 -0
  86. package/src/lib/icons/chevronDown.tsx +21 -0
  87. package/src/lib/icons/chevronLeft.tsx +20 -0
  88. package/src/lib/icons/chevronRight.tsx +20 -0
  89. package/src/lib/icons/chevronUp.tsx +21 -0
  90. package/src/lib/icons/close.tsx +21 -0
  91. package/src/lib/icons/pencil.tsx +21 -0
  92. package/src/lib/icons/plus.tsx +23 -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 +427 -0
  97. package/src/lib/types/context.ts +184 -0
  98. package/src/styles/index.css +469 -0
  99. package/index.cjs +0 -7714
  100. package/index.css +0 -2258
  101. package/index.js +0 -7700
  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 -43
  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/trash.d.ts +0 -4
  162. package/src/lib/types/api.d.ts +0 -34
  163. package/src/lib/types/common.d.ts +0 -29
  164. package/src/lib/types/components.d.ts +0 -420
  165. package/src/lib/types/context.d.ts +0 -135
  166. /package/src/lib/types/{index.d.ts → index.ts} +0 -0
@@ -1,2 +1,3 @@
1
1
  import MasterForm from "./WidgetForm";
2
+
2
3
  export default MasterForm;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import Pagination from '../../common/Pagination';
3
+ import { useWidgetState } from '../../../context/WidgetContext';
4
+ import { useProviderState } from '../../../context/ProviderContext';
5
+
6
+ const WidgetPagination = () => {
7
+ const { commonTranslations } = useProviderState();
8
+ const { totalPages, totalRecords, currentPage, pageSize, setCurrentPage } =
9
+ useWidgetState();
10
+ return (
11
+ <Pagination
12
+ ofText={commonTranslations.of}
13
+ pageText={commonTranslations.page}
14
+ showingText={commonTranslations.showing}
15
+ nextContent={commonTranslations.next}
16
+ previousContent={commonTranslations.previous}
17
+ totalPages={totalPages}
18
+ totalRecords={totalRecords}
19
+ currentPage={currentPage}
20
+ pageSize={pageSize}
21
+ setCurrentPage={setCurrentPage}
22
+ />
23
+ );
24
+ };
25
+
26
+ export default WidgetPagination;
@@ -1,2 +1,3 @@
1
1
  import WidgetPagination from "./WidgetPagination";
2
+
2
3
  export default WidgetPagination;
@@ -0,0 +1,32 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import Input from '../../common/Input';
3
+ import { useWidgetState } from '../../../context/WidgetContext';
4
+
5
+ const WidgetSearch = () => {
6
+ const { changeSearch, widgetTranslations, canList, setCurrentPage } =
7
+ useWidgetState();
8
+ const callerRef = useRef<NodeJS.Timeout | null>(null);
9
+ const [searchVal, setSearchVal] = useState<string>();
10
+
11
+ const onChangeSearch = (str: string) => {
12
+ setSearchVal(str);
13
+ changeSearch(str);
14
+ if (callerRef.current) clearTimeout(callerRef.current);
15
+
16
+ callerRef.current = setTimeout(() => {
17
+ setCurrentPage(1);
18
+ }, 300);
19
+ };
20
+
21
+ return (
22
+ <Input
23
+ type="search"
24
+ value={searchVal}
25
+ disabled={!canList}
26
+ onChange={(e) => onChangeSearch(e.target.value)}
27
+ placeholder={widgetTranslations.searchPlaceholder}
28
+ />
29
+ );
30
+ };
31
+
32
+ export default WidgetSearch;
@@ -1,2 +1,3 @@
1
1
  import WidgetSearch from "./WidgetSearch";
2
+
2
3
  export default WidgetSearch;
@@ -0,0 +1,70 @@
1
+ import React, { useCallback } from 'react';
2
+ import Table from '../../common/Table';
3
+ import ToggleWidget from '../../common/Toggle';
4
+ import { useWidgetState } from '../../../context/WidgetContext';
5
+ import {
6
+ CombineObjectType,
7
+ DerivedTableProps,
8
+ ObjectType,
9
+ ValuesType,
10
+ } from '../../../types';
11
+ import { useProviderState } from '../../../context/ProviderContext';
12
+
13
+ const WidgetTable = ({ extraActions, extraColumns }: DerivedTableProps) => {
14
+ const { commonTranslations, switchClass } = useProviderState();
15
+ const {
16
+ list,
17
+ canUpdate,
18
+ canDelete,
19
+ canPartialUpdate,
20
+ onChangeFormState,
21
+ onPartialUpdateWidget,
22
+ loading,
23
+ loader,
24
+ } = useWidgetState();
25
+ const updateClosure = useCallback(
26
+ (item: ObjectType, key: string, value: ValuesType) => {
27
+ onPartialUpdateWidget({ [key]: value }, item['_id']);
28
+ },
29
+ [onPartialUpdateWidget]
30
+ );
31
+ const onUpdateClick = (item: CombineObjectType) =>
32
+ onChangeFormState('UPDATE', item);
33
+ const onDeleteClick = (item: CombineObjectType) =>
34
+ onChangeFormState('DELETE', item);
35
+
36
+ const dataKeys: any[] = [
37
+ { label: commonTranslations.name, dataKey: 'name', highlight: true },
38
+ { label: commonTranslations.code, dataKey: 'code' },
39
+ ];
40
+ if (canPartialUpdate)
41
+ dataKeys.push({
42
+ label: commonTranslations.active,
43
+ dataKey: 'isActive',
44
+ Cell: ({ row }: any) =>
45
+ canPartialUpdate ? (
46
+ <ToggleWidget
47
+ switchClass={switchClass}
48
+ isChecked={row?.isActive}
49
+ onChange={(status) => updateClosure(row, 'isActive', status)}
50
+ />
51
+ ) : null,
52
+ });
53
+
54
+ return (
55
+ <Table
56
+ data={list}
57
+ loader={loader}
58
+ loading={loading}
59
+ dataKeys={dataKeys}
60
+ actionsLabel={commonTranslations.actions}
61
+ extraColumns={extraColumns}
62
+ extraActions={extraActions}
63
+ actions={{
64
+ edit: canUpdate ? onUpdateClick : false,
65
+ delete: canDelete ? onDeleteClick : false,
66
+ }}
67
+ />
68
+ );
69
+ };
70
+ export default WidgetTable;
@@ -1,2 +1,3 @@
1
1
  import WidgetTable from "./WidgetTable";
2
+
2
3
  export default WidgetTable;
@@ -0,0 +1,173 @@
1
+ import React, { useRef } from 'react';
2
+ import useWidget from '../../../hooks/useWidget';
3
+ import WidgetContextProvider from '../../../context/WidgetContext';
4
+ import {
5
+ TRANSLATION_PAIRS_WIDGET,
6
+ DEFAULT_PERMISSIONS,
7
+ } from '../../../constants/common';
8
+ import { WidgetProps } from '../../../types';
9
+
10
+ import Table from '../Table';
11
+ import WidgetForm from '../Form';
12
+ import AddButton from '../AddButton';
13
+ import Pagination from '../Pagination';
14
+ import WidgetSearch from '../Search';
15
+ import Drawer from '../../common/Drawer';
16
+ import DeleteModal from '../../common/DeleteModal';
17
+ import WidgetFormActions from '../WidgetFormActions';
18
+ import WiddgetFormWrapper from '../WidgetFormWrapper';
19
+ import { useProviderState } from '../../../context/ProviderContext';
20
+
21
+ const Widget = ({
22
+ routes,
23
+ loader,
24
+ explicitForm = false,
25
+ imageBaseUrl,
26
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
27
+ // @ts-ignore
28
+ permissions = {},
29
+ preConfirmDelete,
30
+ formatListItem,
31
+ formatOptionLabel,
32
+ imageMaxSize,
33
+ translations,
34
+ children,
35
+ }: WidgetProps) => {
36
+ const { commonTranslations } = useProviderState();
37
+ const derivedPermissions = Object.assign(DEFAULT_PERMISSIONS, permissions);
38
+ const widgetFormRef = useRef<HTMLFormElement | null>(null);
39
+ const derivedT = {
40
+ ...TRANSLATION_PAIRS_WIDGET,
41
+ ...(translations || {}),
42
+ };
43
+ const {
44
+ list,
45
+ loading,
46
+ searchText,
47
+ changeSearch,
48
+ onChangeFormState,
49
+ formState,
50
+ onCloseForm,
51
+ onWidgetFormSubmit,
52
+ itemData,
53
+ getWidgets,
54
+ onCofirmDeleteWidget,
55
+ onImageRemove,
56
+ onImageUpload,
57
+ onPartialUpdateWidget,
58
+ itemsTypes,
59
+ widgetTypes,
60
+ getCollectionData,
61
+ collectionData,
62
+ collectionDataLoading,
63
+ // Pagination
64
+ totalPages,
65
+ totalRecords,
66
+ currentPage,
67
+ pageSize,
68
+ languages,
69
+ setCurrentPage,
70
+ } = useWidget({
71
+ canList: derivedPermissions.list,
72
+ routes,
73
+ defaultLimit: 10,
74
+ preConfirmDelete,
75
+ imageBaseUrl,
76
+ });
77
+ return (
78
+ <WidgetContextProvider
79
+ loading={loading}
80
+ list={list}
81
+ languages={languages}
82
+ imageBaseUrl={imageBaseUrl}
83
+ onChangeFormState={onChangeFormState}
84
+ searchText={searchText}
85
+ changeSearch={changeSearch}
86
+ loader={loader}
87
+ onWidgetFormSubmit={onWidgetFormSubmit}
88
+ data={itemData}
89
+ getWidgets={getWidgets}
90
+ onImageRemove={onImageRemove}
91
+ onImageUpload={onImageUpload}
92
+ onPartialUpdateWidget={onPartialUpdateWidget}
93
+ itemsTypes={itemsTypes}
94
+ widgetTypes={widgetTypes}
95
+ getCollectionData={getCollectionData}
96
+ collectionData={collectionData}
97
+ collectionDataLoading={collectionDataLoading}
98
+ formatListItem={formatListItem}
99
+ formatOptionLabel={formatOptionLabel}
100
+ // Pagination
101
+ totalPages={totalPages}
102
+ totalRecords={totalRecords}
103
+ currentPage={currentPage}
104
+ pageSize={pageSize}
105
+ setCurrentPage={setCurrentPage}
106
+ // Permissions
107
+ canAdd={derivedPermissions.add}
108
+ canDelete={derivedPermissions.delete}
109
+ canList={derivedPermissions.list}
110
+ canUpdate={derivedPermissions.update}
111
+ canPartialUpdate={derivedPermissions.partialUpdate}
112
+ formState={formState}
113
+ closeForm={onCloseForm}
114
+ imageMaxSize={imageMaxSize}
115
+ widgetTranslations={translations}
116
+ >
117
+ {children ? (
118
+ children
119
+ ) : (
120
+ <>
121
+ <AddButton />
122
+ <WidgetSearch />
123
+ <div className="khb_table-wrapper">
124
+ <Table />
125
+ <Pagination />
126
+ </div>
127
+ </>
128
+ )}
129
+
130
+ {!explicitForm && (
131
+ <Drawer
132
+ open={formState === 'ADD' || formState === 'UPDATE'}
133
+ onClose={onCloseForm}
134
+ title={
135
+ formState === 'ADD'
136
+ ? derivedT.addWidgetTitle
137
+ : formState === 'UPDATE'
138
+ ? derivedT.updateWidgetTitle
139
+ : ''
140
+ }
141
+ footerContent={<WidgetFormActions formRef={widgetFormRef} />}
142
+ >
143
+ <WidgetForm formRef={widgetFormRef} />
144
+ </Drawer>
145
+ )}
146
+ {itemData && (
147
+ <DeleteModal
148
+ formState={formState}
149
+ itemData={itemData}
150
+ onClose={onCloseForm}
151
+ onConfirmDelete={onCofirmDeleteWidget}
152
+ confirmationRequired={commonTranslations.confirmationRequired}
153
+ confirm={commonTranslations.confirm}
154
+ lossOfData={commonTranslations.lossOfData}
155
+ permanentlyDelete={commonTranslations.permanentlyDelete}
156
+ pleaseType={commonTranslations.pleaseType}
157
+ toProceedOrCancel={commonTranslations.toProceedOrCancel}
158
+ typeHerePlaceholder={commonTranslations.typeHerePlaceholder}
159
+ />
160
+ )}
161
+ </WidgetContextProvider>
162
+ );
163
+ };
164
+
165
+ Widget.Table = Table;
166
+ Widget.Form = WidgetForm;
167
+ Widget.AddButton = AddButton;
168
+ Widget.Search = WidgetSearch;
169
+ Widget.Pagination = Pagination;
170
+ Widget.FormWrapper = WiddgetFormWrapper;
171
+ Widget.FormActions = WidgetFormActions;
172
+
173
+ export default Widget;
@@ -1,2 +1,3 @@
1
1
  import Widget from "./Widget";
2
+
2
3
  export default Widget;
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import FormActions from '../../common/FormActions';
3
+ import { FormActionWrapperProps } from '../../../types';
4
+ import { CALLBACK_CODES } from '../../../constants/common';
5
+ import { useWidgetState } from '../../../context/WidgetContext';
6
+ import { useProviderState } from '../../../context/ProviderContext';
7
+
8
+ const WidgetFormActions = ({ formRef }: FormActionWrapperProps) => {
9
+ const { onError, commonTranslations } = useProviderState();
10
+ const { closeForm, loading, canAdd, canUpdate, formState } = useWidgetState();
11
+ const onSubmitClick = (
12
+ e?: React.MouseEvent<HTMLButtonElement, MouseEvent>
13
+ ) => {
14
+ if (!formRef) {
15
+ return onError(
16
+ CALLBACK_CODES.INTERNAL,
17
+ 'error',
18
+ `formRef is required to submit the form!`
19
+ );
20
+ } else if (!formRef.current) {
21
+ return onError(
22
+ CALLBACK_CODES.INTERNAL,
23
+ 'error',
24
+ `formRef is empty, make sure it's passed as 'formRef' prop to the form!`
25
+ );
26
+ }
27
+ // formRef is provided
28
+ e?.preventDefault();
29
+ formRef.current?.dispatchEvent(
30
+ new Event('submit', { cancelable: true, bubbles: true })
31
+ );
32
+ };
33
+
34
+ if (!canAdd && !canUpdate) return null;
35
+ return (
36
+ <FormActions
37
+ loading={loading}
38
+ primaryLabel={
39
+ formState === 'ADD'
40
+ ? commonTranslations.create
41
+ : commonTranslations.update
42
+ }
43
+ onPrimaryButtonClick={onSubmitClick}
44
+ onSecondaryButtonClick={closeForm}
45
+ secondaryLabel={commonTranslations.cancel}
46
+ />
47
+ );
48
+ };
49
+
50
+ export default WidgetFormActions;
@@ -1,2 +1,3 @@
1
1
  import WidgetFormActions from './WidgetFormActions';
2
+
2
3
  export default WidgetFormActions;
@@ -0,0 +1,16 @@
1
+ import { FormWrapperProps } from '../../../types';
2
+ import { useWidgetState } from '../../../context/WidgetContext';
3
+
4
+ const WiddgetFormWrapper = ({ children }: FormWrapperProps) => {
5
+ const { formState, closeForm } = useWidgetState();
6
+
7
+ return typeof children === 'function'
8
+ ? children({
9
+ formState,
10
+ onClose: closeForm,
11
+ open: formState === 'ADD' || formState === 'UPDATE',
12
+ })
13
+ : null;
14
+ };
15
+
16
+ export default WiddgetFormWrapper;
@@ -1,2 +1,3 @@
1
1
  import WiddgetFormWrapper from './WidgetFormWrapper';
2
+
2
3
  export default WiddgetFormWrapper;
@@ -1,2 +1,3 @@
1
1
  import Widget from "./Widget";
2
+
2
3
  export { Widget };
@@ -0,0 +1,56 @@
1
+ import classNames from 'classnames';
2
+ import React from 'react';
3
+ import ChevronDown from '../../../icons/chevronDown';
4
+ import ChevronUp from '../../../icons/chevronUp';
5
+
6
+ interface AccordianProps {
7
+ id?: string;
8
+ collapseId?: string;
9
+ className?: string;
10
+ children?: React.ReactNode;
11
+ open?: boolean;
12
+ onToggle?: (status: boolean) => void;
13
+ title?: string;
14
+ footerContent?: React.ReactNode;
15
+ }
16
+
17
+ const Accordian = ({
18
+ id,
19
+ className,
20
+ children,
21
+ open,
22
+ onToggle,
23
+ title,
24
+ collapseId,
25
+ footerContent,
26
+ }: AccordianProps) => {
27
+ return (
28
+ <div>
29
+ <h2 id={id}>
30
+ <button
31
+ type="button"
32
+ className="khb_accordian-header"
33
+ data-accordion-target={`#${collapseId}`}
34
+ aria-expanded="true"
35
+ aria-controls={collapseId}
36
+ onClick={() => onToggle && onToggle(!open)}
37
+ >
38
+ <span>{title}</span>
39
+ {open ? <ChevronUp /> : <ChevronDown />}
40
+ </button>
41
+ </h2>
42
+ <div
43
+ id={collapseId}
44
+ className={classNames('khb_accordian-body', { hidden: !open })}
45
+ aria-labelledby={id}
46
+ >
47
+ <div className="khb_accordian-content">{children}</div>
48
+ {footerContent && (
49
+ <div className="khb_accordian-footer">{footerContent}</div>
50
+ )}
51
+ </div>
52
+ </div>
53
+ );
54
+ };
55
+
56
+ export default Accordian;
@@ -1,2 +1,3 @@
1
1
  import Accordian from "./Accordian";
2
+
2
3
  export default Accordian;
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import { ButtonProps } from '../../../types';
4
+
5
+ const Button = ({
6
+ type = 'primary',
7
+ size = 'base',
8
+ onClick,
9
+ className,
10
+ children,
11
+ disabled,
12
+ loading,
13
+ }: ButtonProps) => {
14
+ return (
15
+ <button
16
+ className={classNames(
17
+ 'khb_btn',
18
+ `khb_btn-${type}`,
19
+ `khb_btn-${size}`,
20
+ className
21
+ )}
22
+ onClick={onClick}
23
+ disabled={disabled || loading}
24
+ >
25
+ {loading && (
26
+ <svg
27
+ className="khb_btn-loader"
28
+ xmlns="http://www.w3.org/2000/svg"
29
+ width="12"
30
+ height="13"
31
+ viewBox="0 0 12 13"
32
+ >
33
+ <path
34
+ // style={{ fill: kind }}
35
+ d="M5.5,12a1,1,0,1,1,1,1A1,1,0,0,1,5.5,12ZM1.75,10.5A1.25,1.25,0,1,1,3,11.75,1.25,1.25,0,0,1,1.75,10.5Zm7.531.031a.75.75,0,1,1,.75.75A.75.75,0,0,1,9.281,10.531ZM0,7A1.5,1.5,0,1,1,1.5,8.5,1.5,1.5,0,0,1,0,7ZM11,7a.5.5,0,1,1,.5.5A.5.5,0,0,1,11,7ZM1.875,4.637a1.62,1.62,0,0,1,0-2.275,1.582,1.582,0,0,1,2.253,0,1.62,1.62,0,0,1,0,2.275,1.582,1.582,0,0,1-2.253,0ZM4.5,2a2,2,0,1,1,2,2A2,2,0,0,1,4.5,2ZM9.75,3.5a.25.25,0,1,1,.25.25A.25.25,0,0,1,9.75,3.5Z"
36
+ />
37
+ </svg>
38
+ )}
39
+
40
+ {children}
41
+ </button>
42
+ );
43
+ };
44
+
45
+ export default Button;
@@ -1,2 +1,3 @@
1
1
  import Button from "./Button";
2
+
2
3
  export default Button;
@@ -0,0 +1,47 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
3
+ /* eslint-disable react/no-unstable-nested-components */
4
+ import React, { useState } from 'react';
5
+ import { Popover } from 'react-tiny-popover';
6
+ import { ConfirmPopoverProps } from '../../../types';
7
+ import Button from '../Button';
8
+
9
+ const ConfirmPopOver = ({
10
+ children,
11
+ onConfirm,
12
+ title,
13
+ confirmText = 'Yes',
14
+ cancelText = 'No',
15
+ }: ConfirmPopoverProps) => {
16
+ const [isPopoverOpen, setIsPopoverOpen] = useState(false);
17
+
18
+ const onConfirmClick = () => {
19
+ setIsPopoverOpen(false);
20
+ onConfirm();
21
+ };
22
+
23
+ return (
24
+ <Popover
25
+ containerClassName="khb_confirm-popover"
26
+ isOpen={isPopoverOpen}
27
+ padding={10}
28
+ onClickOutside={() => setIsPopoverOpen(false)}
29
+ content={() => (
30
+ <div className="khb_confirm-popover-content">
31
+ <div className="khb_confirm-popover-title">{title}</div>
32
+ <div className="khb_confirm-popover-footer">
33
+ <Button type="secondary" onClick={() => setIsPopoverOpen(false)}>
34
+ {cancelText}
35
+ </Button>
36
+ <Button type="primary" onClick={onConfirmClick}>
37
+ {confirmText}
38
+ </Button>
39
+ </div>
40
+ </div>
41
+ )}
42
+ >
43
+ <div onClick={() => setIsPopoverOpen(true)}>{children}</div>
44
+ </Popover>
45
+ );
46
+ };
47
+ export default ConfirmPopOver;
@@ -1,2 +1,3 @@
1
1
  import ConfirmPopover from './ConfirmPopover';
2
+
2
3
  export default ConfirmPopover;
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import { DNDItemsListProps } from '../../../types';
3
+ import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
4
+
5
+ const DNDItemsList = ({
6
+ onDragEnd,
7
+ items,
8
+ formatItem,
9
+ listCode,
10
+ }: DNDItemsListProps) => {
11
+ return (
12
+ <DragDropContext onDragEnd={onDragEnd}>
13
+ <Droppable droppableId="droppable">
14
+ {(droppableProvided) => (
15
+ <div
16
+ className="khb_DND-items"
17
+ ref={droppableProvided.innerRef}
18
+ {...droppableProvided.droppableProps}
19
+ >
20
+ {items
21
+ ? items.map((item, index) => (
22
+ <Draggable
23
+ key={item.value}
24
+ draggableId={item.value}
25
+ index={index}
26
+ >
27
+ {(provided) => (
28
+ <div
29
+ className="khb_DND-item"
30
+ key={item.value}
31
+ ref={provided.innerRef}
32
+ {...provided.draggableProps}
33
+ {...provided.dragHandleProps}
34
+ >
35
+ {typeof formatItem === 'function' && listCode ? (
36
+ formatItem(listCode, item)
37
+ ) : (
38
+ <p className="khb_DND-item-text">{item.label}</p>
39
+ )}
40
+ </div>
41
+ )}
42
+ </Draggable>
43
+ ))
44
+ : null}
45
+ {droppableProvided.placeholder}
46
+ </div>
47
+ )}
48
+ </Droppable>
49
+ </DragDropContext>
50
+ );
51
+ };
52
+
53
+ export default DNDItemsList;
@@ -1,2 +1,3 @@
1
1
  import DNDItemsList from "./DNDItemsList";
2
+
2
3
  export default DNDItemsList;