@unbxd-ui/unbxd-react-components 0.2.101-beta.1 → 0.2.101-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/components/Form/RangeSlider.js +7 -3
  2. package/components/Tooltip/Tooltip.js +11 -2
  3. package/components/core.css +3 -1
  4. package/components/theme.css +2 -0
  5. package/core/Validators.js +48 -0
  6. package/core/customHooks.js +41 -0
  7. package/core/dataLoader.js +235 -0
  8. package/core/dataLoader.stories.js +153 -0
  9. package/core/index.js +31 -0
  10. package/core/utils.js +112 -0
  11. package/index.js +193 -0
  12. package/package.json +1 -1
  13. package/.babelrc +0 -4
  14. package/.eslintrc.js +0 -38
  15. package/CONTRIBUTE.md +0 -105
  16. package/src/Intro.stories.mdx +0 -119
  17. package/src/components/Accordian/Accordian.js +0 -89
  18. package/src/components/Accordian/Accordian.stories.js +0 -92
  19. package/src/components/Accordian/accordianCore.scss +0 -8
  20. package/src/components/Accordian/accordianTheme.scss +0 -6
  21. package/src/components/Accordian/index.js +0 -3
  22. package/src/components/Button/Button.js +0 -67
  23. package/src/components/Button/Button.stories.js +0 -103
  24. package/src/components/Button/DropdownButton.js +0 -60
  25. package/src/components/Button/DropdownButton.stories.js +0 -38
  26. package/src/components/Button/button.css +0 -1
  27. package/src/components/Button/buttonTheme.scss +0 -45
  28. package/src/components/Button/index.js +0 -5
  29. package/src/components/DataLoader/DataLoader.js +0 -86
  30. package/src/components/DataLoader/DataLoader.stories.js +0 -72
  31. package/src/components/DataLoader/index.js +0 -3
  32. package/src/components/Form/Checkbox.js +0 -73
  33. package/src/components/Form/DragDropFileUploader.js +0 -67
  34. package/src/components/Form/Dropdown.js +0 -415
  35. package/src/components/Form/FileUploader.js +0 -64
  36. package/src/components/Form/Form.js +0 -83
  37. package/src/components/Form/FormElementWrapper.js +0 -22
  38. package/src/components/Form/Input.js +0 -121
  39. package/src/components/Form/RadioList.js +0 -86
  40. package/src/components/Form/RangeSlider.js +0 -100
  41. package/src/components/Form/ServerPaginatedDDList.js +0 -226
  42. package/src/components/Form/Textarea.js +0 -76
  43. package/src/components/Form/Toggle.js +0 -96
  44. package/src/components/Form/form.css +0 -1
  45. package/src/components/Form/formCore.scss +0 -142
  46. package/src/components/Form/formTheme.scss +0 -27
  47. package/src/components/Form/index.js +0 -13
  48. package/src/components/Form/stories/Checkbox.stories.js +0 -41
  49. package/src/components/Form/stories/DragDropFileUploader.stories.js +0 -21
  50. package/src/components/Form/stories/Dropdown.stories.js +0 -124
  51. package/src/components/Form/stories/FileUploader.stories.js +0 -21
  52. package/src/components/Form/stories/FormDefault.stories.js +0 -87
  53. package/src/components/Form/stories/RadioList.stories.js +0 -48
  54. package/src/components/Form/stories/RangeSlider.stories.js +0 -84
  55. package/src/components/Form/stories/TextInput.stories.js +0 -77
  56. package/src/components/Form/stories/Textarea.stories.js +0 -43
  57. package/src/components/Form/stories/Toggle.stories.js +0 -14
  58. package/src/components/Form/stories/form.stories.js +0 -216
  59. package/src/components/InlineModal/InlineModal.js +0 -135
  60. package/src/components/InlineModal/InlineModal.stories.js +0 -54
  61. package/src/components/InlineModal/index.js +0 -4
  62. package/src/components/InlineModal/inlineModal.css +0 -1
  63. package/src/components/InlineModal/inlineModalCore.scss +0 -31
  64. package/src/components/InlineModal/inlineModalTheme.scss +0 -16
  65. package/src/components/List/List.js +0 -72
  66. package/src/components/List/index.js +0 -3
  67. package/src/components/List/list.css +0 -1
  68. package/src/components/List/list.stories.js +0 -28
  69. package/src/components/List/listCore.scss +0 -6
  70. package/src/components/List/listTheme.scss +0 -0
  71. package/src/components/Modal/Modal.js +0 -99
  72. package/src/components/Modal/Modal.stories.js +0 -54
  73. package/src/components/Modal/index.js +0 -3
  74. package/src/components/Modal/modal.css +0 -1
  75. package/src/components/Modal/modalCore.scss +0 -34
  76. package/src/components/Modal/modalTheme.scss +0 -0
  77. package/src/components/NotificationComponent/NotificationComponent.js +0 -58
  78. package/src/components/NotificationComponent/NotificationComponent.stories.js +0 -28
  79. package/src/components/NotificationComponent/index.js +0 -3
  80. package/src/components/NotificationComponent/notificationComponent.css +0 -1
  81. package/src/components/NotificationComponent/notificationTheme.scss +0 -30
  82. package/src/components/ProgressBar/ProgressBar.js +0 -45
  83. package/src/components/ProgressBar/ProgressBar.stories.js +0 -14
  84. package/src/components/ProgressBar/index.js +0 -3
  85. package/src/components/ProgressBar/progressBar.css +0 -1
  86. package/src/components/ProgressBar/progressBarCore.scss +0 -14
  87. package/src/components/ProgressBar/progressBarTheme.scss +0 -0
  88. package/src/components/Table/BaseTable.js +0 -306
  89. package/src/components/Table/PaginationComponent.js +0 -73
  90. package/src/components/Table/Table.js +0 -295
  91. package/src/components/Table/Table.stories.js +0 -198
  92. package/src/components/Table/index.js +0 -8
  93. package/src/components/Table/table.css +0 -1
  94. package/src/components/Table/tableCore.scss +0 -94
  95. package/src/components/Table/tableTheme.scss +0 -34
  96. package/src/components/TabsComponent/TabsComponent.js +0 -99
  97. package/src/components/TabsComponent/TabsComponent.stories.js +0 -69
  98. package/src/components/TabsComponent/index.js +0 -3
  99. package/src/components/TabsComponent/tabs.css +0 -1
  100. package/src/components/TabsComponent/tabsCore.scss +0 -59
  101. package/src/components/TabsComponent/tabsTheme.scss +0 -0
  102. package/src/components/Tooltip/Tooltip.js +0 -87
  103. package/src/components/Tooltip/Tooltip.stories.js +0 -16
  104. package/src/components/Tooltip/index.js +0 -3
  105. package/src/components/Tooltip/tooltipCore.scss +0 -22
  106. package/src/components/Tooltip/tooltipTheme.scss +0 -21
  107. package/src/components/core.css +0 -1
  108. package/src/components/core.scss +0 -29
  109. package/src/components/index.js +0 -38
  110. package/src/components/theme.css +0 -1
  111. package/src/components/theme.scss +0 -11
  112. package/src/core/Validators.js +0 -34
  113. package/src/core/customHooks.js +0 -20
  114. package/src/core/dataLoader.js +0 -143
  115. package/src/core/dataLoader.stories.js +0 -123
  116. package/src/core/index.js +0 -3
  117. package/src/core/utils.js +0 -95
  118. package/src/index.js +0 -68
  119. package/vscode-templates/NewStoryTemplate.stories.js +0 -8
  120. /package/{README.md → Readme.md} +0 -0
  121. /package/{src/components → components}/Accordian/accordianCore.css +0 -0
  122. /package/{src/components → components}/Accordian/accordianTheme.css +0 -0
  123. /package/{src/components → components}/Button/buttonTheme.css +0 -0
  124. /package/{src/components → components}/Form/formCore.css +0 -0
  125. /package/{src/components → components}/Form/formTheme.css +0 -0
  126. /package/{src/components → components}/InlineModal/inlineModalCore.css +0 -0
  127. /package/{src/components → components}/InlineModal/inlineModalTheme.css +0 -0
  128. /package/{src/components → components}/List/listCore.css +0 -0
  129. /package/{src/components → components}/List/listTheme.css +0 -0
  130. /package/{src/components → components}/Modal/modalCore.css +0 -0
  131. /package/{src/components → components}/Modal/modalTheme.css +0 -0
  132. /package/{src/components → components}/NotificationComponent/notificationTheme.css +0 -0
  133. /package/{src/components → components}/ProgressBar/progressBarCore.css +0 -0
  134. /package/{src/components → components}/ProgressBar/progressBarTheme.css +0 -0
  135. /package/{src/components → components}/Table/tableCore.css +0 -0
  136. /package/{src/components → components}/Table/tableTheme.css +0 -0
  137. /package/{src/components → components}/TabsComponent/tabsCore.css +0 -0
  138. /package/{src/components → components}/TabsComponent/tabsTheme.css +0 -0
  139. /package/{src/components → components}/Tooltip/tooltipCore.css +0 -0
  140. /package/{src/components → components}/Tooltip/tooltipTheme.css +0 -0
@@ -1,67 +0,0 @@
1
- import React, { useState, useContext } from "react";
2
- import PropTypes from "prop-types";
3
- import { FormContext } from "./Form";
4
- import FormElementWrapper from "./FormElementWrapper";
5
-
6
- const DragDropFileUploader = (props) => {
7
- const { name, label, children, onChange, className, appearance } = props;
8
- const [ isDragOver, setIsDragOver ] = useState(false);
9
- const { onValueChange } = useContext(FormContext);
10
-
11
- const onDragEnter = () => {
12
- setIsDragOver(true);
13
- };
14
-
15
- const onDragLeave = () => {
16
- setIsDragOver(false);
17
- };
18
-
19
- const onDragOver = (event) => {
20
- event.preventDefault();
21
- };
22
-
23
- const onDrop = (event) => {
24
- event.preventDefault();
25
- let value = event.dataTransfer.files;
26
-
27
- if (typeof(onChange) === "function") {
28
- onChange(value);
29
- }
30
-
31
- typeof(onValueChange) === "function" && onValueChange(name, value);
32
-
33
- setIsDragOver(false);
34
- };
35
-
36
- return (<FormElementWrapper className={className} appearance={appearance}>
37
- <label className="RCB-form-el-label">{label}</label>
38
- <div onDragEnter={onDragEnter} onDragLeave={onDragLeave}
39
- onDragOver={onDragOver} onDrop={onDrop}
40
- className={`RCB-drag-drop-uploader ${isDragOver ? "RCB-drag-over" : ""}`}>
41
- {children}
42
- </div>
43
- </FormElementWrapper>);
44
- };
45
-
46
- DragDropFileUploader.propTypes = {
47
- /** Pass any additional classNames to Input component */
48
- className: PropTypes.string,
49
- /** Label for the input element */
50
- label: PropTypes.string,
51
- /** Unique ID for the input element */
52
- name: PropTypes.string.isRequired,
53
- /** mime type of the acceptable files */
54
- accept: PropTypes.string,
55
- /** Define the appearance of the form element. Accepted values are either "inline" or "block" */
56
- appearance: PropTypes.oneOf(["inline", "block"]),
57
- /** Becomes a controlled component if onChange function is given */
58
- onChange: PropTypes.func
59
- };
60
-
61
- DragDropFileUploader.defaultProps = {
62
- className: "",
63
- appearance: "inline",
64
- accept: "image/*"
65
- };
66
-
67
- export default DragDropFileUploader;
@@ -1,415 +0,0 @@
1
- import React, { useState, useContext, useRef, Fragment, useEffect, forwardRef, useImperativeHandle } from "react";
2
- import PropTypes from "prop-types";
3
- import InlineModal, { InlineModalActivator, InlineModalBody } from "../InlineModal";
4
- import List from "../List";
5
- import { FormContext } from "./Form";
6
- import FormElementWrapper from "./FormElementWrapper";
7
- import ServerPaginatedDDList from "./ServerPaginatedDDList";
8
- import utils from "../../core/utils";
9
-
10
- const convertToArray = (value) => {
11
- if (!value) {
12
- return [];
13
- }
14
-
15
- return Array.isArray(value) ? value : [value];
16
- };
17
-
18
- const getFilteredOptions = (options = [], searchQuery = "", nameAttribute) => {
19
- return options.filter(obj => {
20
- const nameValue = obj[nameAttribute].toLowerCase();
21
- return nameValue.indexOf(searchQuery.toLowerCase()) !== -1;
22
- });
23
- };
24
-
25
- /* eslint-disable react/prop-types */
26
- const DefaultSelectionSummary = ({selectedItems = [], multiSelect, noSelectionLabel, nameAttribute, showClear, clearSelectedItems}) => {
27
- let summaryString = "";
28
- const selectedCount = selectedItems.length;
29
-
30
- if (multiSelect) {
31
- summaryString = selectedCount ? `${selectedCount} selected` : noSelectionLabel;
32
- } else {
33
- summaryString = selectedCount ? selectedItems[0][nameAttribute] : noSelectionLabel;
34
- }
35
-
36
- return (<Fragment><span className="RCB-dd-label">{summaryString}</span>
37
- <span className="RCB-selection-wrapper">
38
- { showClear && <span className="RCB-clear-selected" onClick={clearSelectedItems}>Clear</span> }
39
- <span className="RCB-select-arrow"></span>
40
- </span>
41
- </Fragment>);
42
- };
43
-
44
- export const DefaultDropdownItem = (props) => {
45
- const { itemData, selectItem, selectedItems = [], idAttribute, nameAttribute } = props;
46
- const idValue = itemData[idAttribute];
47
- const name = itemData[nameAttribute];
48
-
49
- const isSelected = selectedItems.find(obj => obj[idAttribute] === idValue) ? true : false;
50
- const className = "RCB-list-item " + (isSelected ? "selected" : "");
51
-
52
- return (<li onClick={() => selectItem(itemData)} className={className}>
53
- {name}
54
- </li>);
55
- };
56
-
57
- DefaultDropdownItem.propTypes = {
58
- itemData: PropTypes.object.isRequired,
59
- selectItem: PropTypes.func.isRequired,
60
- selectedItems: PropTypes.array,
61
- idAttribute: PropTypes.string,
62
- nameAttribute: PropTypes.string
63
- };
64
-
65
- const NormalList = ({ items = [], selectedItems, selectItem, idAttribute, nameAttribute, DropdownItem, ListHeaderItem, ...restProps }) => {
66
- return (
67
- <Fragment>
68
- {items.length ? ListHeaderItem : ""}
69
- <List items={items} {...restProps}
70
- showNoDataMsg={true}
71
- ListItem={DropdownItem} selectedItems={selectedItems} selectItem={selectItem}
72
- idAttribute={idAttribute} nameAttribute={nameAttribute} />
73
- </Fragment>
74
- )
75
- };
76
-
77
- NormalList.defaultProps = {
78
- DropdownItem: DefaultDropdownItem
79
- };
80
-
81
- /* eslint-enable react/prop-types */
82
-
83
- let Dropdown = (props, ref) => {
84
- const {
85
- halign,
86
- label,
87
- showLabel,
88
- name,
89
- SelectionSummary,
90
- className,
91
- value,
92
- defaultValue,
93
- onChange,
94
- disabled,
95
- options,
96
- showSearch,
97
- searchPlaceholder,
98
- idAttribute,
99
- nameAttribute,
100
- noSelectionLabel,
101
- appearance,
102
- multiSelect,
103
- DropdownItem,
104
- validations,
105
- paginationType,
106
- requestId,
107
- requestParams,
108
- pageNoKey,
109
- perPageKey,
110
- pageSize,
111
- searchAttribute,
112
- maxHeight,
113
- responseFormatter,
114
- getUrlParams,
115
- showCreateCTA,
116
- createCTAComponent,
117
- onCreateCTAClick,
118
- serverListClassName,
119
- showClear,
120
- onClear,
121
- minPageNo,
122
- ListHeaderItem,
123
- onSearchChange: propSearchChange,
124
- ...restProps
125
- } = props;
126
- const [ searchQuery, setSearchQuery ] = useState("");
127
- const debouncedFn = useRef();
128
- const searchIpRef = useRef();
129
-
130
- let initialSelected = [];
131
- const initialValue = typeof(onChange) === "function" ? value : defaultValue;
132
-
133
- if (typeof(initialValue) !== "undefined") {
134
- initialSelected = convertToArray(initialValue);
135
- }
136
-
137
- /* array of selected item objects */
138
- let [ selectedItems, setSelectedItems ] = useState(initialSelected);
139
-
140
- const { onValueChange } = useContext(FormContext);
141
- const inlineModalRef = useRef();
142
-
143
- const hideModal = () => {
144
- inlineModalRef.current.hideModal();
145
- };
146
-
147
- const postFormValueChange = (value) => {
148
- const { error } = utils.checkIfValid(value, validations);
149
- typeof(onValueChange) === "function" && onValueChange(name, value, error);
150
- };
151
-
152
- const selectItem = (item) => {
153
- const id = item[idAttribute];
154
-
155
- if (multiSelect) {
156
- const isPresent = selectedItems.find(obj => obj[idAttribute] === id);
157
- if (!isPresent) {
158
- selectedItems.push(item);
159
- postFormValueChange(selectedItems);
160
- typeof(onChange) === "function" && onChange(selectedItems);
161
- }
162
- } else {
163
- selectedItems = [item];
164
- postFormValueChange(item);
165
- typeof(onChange) === "function" && onChange(item);
166
- /* close the dropdown */
167
- hideModal();
168
- }
169
-
170
- setSelectedItems(selectedItems);
171
- }
172
-
173
- useEffect(() => {
174
- /* set the initial form element value in the form context */
175
- let postValue = typeof(onChange) === "function" ? value : defaultValue;
176
-
177
- if (typeof(postValue) !== "undefined") {
178
- let arrayPostValue = convertToArray(postValue);
179
-
180
- postValue = multiSelect ? arrayPostValue : postValue;
181
-
182
- setSelectedItems(arrayPostValue);
183
- }
184
- postFormValueChange(postValue);
185
-
186
- }, [value, defaultValue]);
187
-
188
- const debouncedSearchChange = (value) => {
189
- setSearchQuery(value);
190
- if (typeof propSearchChange === "function") {
191
- propSearchChange(value);
192
- }
193
- };
194
-
195
- const onSearchChange = (event) => {
196
- event.persist();
197
-
198
- if (!debouncedFn.current) {
199
- debouncedFn.current = utils.debounce(debouncedSearchChange, 300);
200
- }
201
-
202
- return debouncedFn.current(event.target.value);
203
- };
204
-
205
- const onModalStateChange = (isModalOpen) => {
206
- if (isModalOpen && showSearch) {
207
- searchIpRef.current && searchIpRef.current.focus();
208
- } else {
209
- /* modal is closed */
210
- setSearchQuery("");
211
- }
212
- };
213
-
214
- const clearSelectedItems = (evnt) => {
215
- evnt.stopPropagation();
216
- setSelectedItems([]);
217
- typeof(onClear) === "function" && onClear();
218
- typeof(onChange) === "function" && onChange(null);
219
- /** Close modal after reset */
220
- hideModal();
221
- }
222
-
223
- const commonAttributes = {
224
- selectedItems, selectItem, idAttribute, nameAttribute, DropdownItem, ListHeaderItem
225
- };
226
-
227
- useImperativeHandle(ref, () => ({
228
- closeDropdown: hideModal
229
- }));
230
-
231
- const serverListAttrs = {
232
- requestId,
233
- requestParams,
234
- pageNoKey,
235
- perPageKey,
236
- pageSize,
237
- maxHeight,
238
- searchQuery,
239
- searchAttribute,
240
- responseFormatter,
241
- getUrlParams,
242
- serverListClassName,
243
- minPageNo
244
- };
245
-
246
- const inlineModalClasses = "RCB-form-el " + (showCreateCTA ? "RCB-dd-with-create" : "");
247
-
248
- return (<FormElementWrapper className={`RCB-dropdown ${disabled ? "RCB-disabled" : ""} ${className}`} appearance={appearance}>
249
- {showLabel && <label className="RCB-form-el-label" htmlFor={name}>{label}</label>}
250
- <InlineModal className={inlineModalClasses} ref={inlineModalRef} halign={halign} onModalStateChange={onModalStateChange}>
251
- <InlineModalActivator>
252
- <SelectionSummary
253
- selectedItems={selectedItems}
254
- noSelectionLabel={noSelectionLabel}
255
- multiSelect={multiSelect} nameAttribute={nameAttribute} {...restProps}
256
- showClear={showClear} clearSelectedItems={clearSelectedItems} />
257
- </InlineModalActivator>
258
- <InlineModalBody>
259
- {showSearch && <div className="RCB-dd-search">
260
- <span className="RCB-dd-search-icon"></span>
261
- <input type="text" className="RCB-dd-search-ip" placeholder={searchPlaceholder} onChange={onSearchChange} ref={searchIpRef} />
262
- </div>}
263
- {paginationType === "SERVER" ?
264
- <ServerPaginatedDDList {...commonAttributes} {...serverListAttrs} {...restProps} /> :
265
- <NormalList {...commonAttributes} {...restProps}
266
- items={getFilteredOptions(options, searchQuery, nameAttribute)} />}
267
- {showCreateCTA && <div className="RCB-dd-create-cta" onClick={onCreateCTAClick}>{createCTAComponent}</div>}
268
- </InlineModalBody>
269
- </InlineModal>
270
- </FormElementWrapper>);
271
- };
272
-
273
- // const VALUE_SHAPE = PropTypes.shape({
274
- // id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
275
- // name: PropTypes.string
276
- // });
277
-
278
- Dropdown = forwardRef(Dropdown);
279
-
280
- Dropdown.propTypes = {
281
- /** Pass any additional classNames to Dropdown component */
282
- className: PropTypes.string,
283
- /** Pass infinite fixed list classname to Dropdown component */
284
- serverListClassName: PropTypes.string,
285
- /** Horizontal alignment of the dropdown body */
286
- halign: PropTypes.oneOf(["left", "right"]),
287
- /** Label for the dropdown element */
288
- label: PropTypes.string,
289
- /** indicates whether to show or hide label */
290
- showLabel: PropTypes.bool,
291
- /** Unique ID for the input element */
292
- name: PropTypes.string.isRequired,
293
- /** Label for dropdown activator */
294
- noSelectionLabel: PropTypes.string,
295
- /** Selection items list */
296
- options: PropTypes.arrayOf(PropTypes.shape({
297
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
298
- name: PropTypes.string
299
- })),
300
- /** array of selected item objects, only considered if onChange event is given */
301
- value: PropTypes.any,
302
- /** array of default selected item objects */
303
- defaultValue: PropTypes.any,
304
- onChange: PropTypes.func,
305
- /** pass true if dropdown has to be disabled */
306
- disabled: PropTypes.bool,
307
- /* set to true if you want search ability for dropdown items */
308
- showSearch: PropTypes.bool,
309
- /* placeholder to show in the search box */
310
- searchPlaceholder: PropTypes.string,
311
- /** Is dropdown multi select or single select */
312
- multiSelect: PropTypes.bool,
313
- /** ID attribute key to use when rendering the dropdown items, if the ID attribute is other than "id" */
314
- idAttribute: PropTypes.string,
315
- /** name attribute key to use when rendering the dropdown items, if the name attribute is other than "name" */
316
- nameAttribute: PropTypes.string,
317
- /** Provide a custom element for rendering dropdown item */
318
- DropdownItem: PropTypes.oneOfType([
319
- PropTypes.instanceOf(Element),
320
- PropTypes.func
321
- ]),
322
- /** Pass true to show a create CTA at the end of the dropdown */
323
- showCreateCTA: PropTypes.bool,
324
- /** Customize the create CTA HTML by passing a createCTAComponent */
325
- createCTAComponent: PropTypes.any,
326
- /** Callback that gets called when Create CTA button is clicked */
327
- onCreateCTAClick: PropTypes.func,
328
- /** Pass this component to customise the selection summary HTML.
329
- * The array of selected item objects will be sent as props
330
- */
331
- SelectionSummary: PropTypes.func,
332
- /** Define the appearance of the form element. Accepted values are either "inline" or "block" */
333
- appearance: PropTypes.oneOf(["inline", "block"]),
334
- /** Array of validations to perform on the form element value.
335
- * If the validation fails, you will get an "error" field in the form onSubmit event */
336
- validations: PropTypes.arrayOf(PropTypes.shape({
337
- type: PropTypes.oneOf(["REQUIRED", "CUSTOM"]).isRequired,
338
- message: PropTypes.string.isRequired,
339
- validator: PropTypes.func
340
- })),
341
- /** Type of pagination for the dropdown list items. Send "SERVER" for server side pagination */
342
- paginationType: PropTypes.oneOf(["NONE", "SERVER"]),
343
- /** If paginationType is "SERVER", pass the requestId for the server request */
344
- requestId: function(props, propName) {
345
- if (props["paginationType"] == "SERVER" && (!props[propName] || typeof(props[propName]) === "undefined")) {
346
- return new Error("Please provide a requestId for paginationType 'SERVER'!");
347
- }
348
- },
349
- /** If paginationType is "SERVER", pass any additional params to be sent to the server request */
350
- requestParams: PropTypes.object,
351
- /** If paginationType is "SERVER", pass the pageNo. attribute to be sent to the server request */
352
- pageNoKey: PropTypes.string,
353
- /** If paginationType is "SERVER", pass the pageSize attribute to be sent to the server request */
354
- perPageKey: PropTypes.string,
355
- /** If paginationType is "SERVER", max height of the dropdown container */
356
- maxHeight: PropTypes.number,
357
- /** If paginationType is "SERVER", height of each dropdown item */
358
- ddItemHeight: PropTypes.number,
359
- /** If paginationType is "SERVER", max number of items to show for one page in the dropdown container */
360
- pageSize: PropTypes.number,
361
- /** Default page number to use for server paginated list */
362
- minPageNo: PropTypes.number,
363
- /** If paginationType is "SERVER" & showSearch is true, pass the search attribute to be sent to the server request */
364
- searchAttribute: PropTypes.string,
365
- /** If paginationType is "SERVER",
366
- * component expects the response to be of the form
367
- * { [pageNoKey]: <pageNo>, [perPageKey]: <pageSize>, total: <totalCount>, entries: [{}] }
368
- * If your data is not in this format, use the responseFormatter to format the data to this structure.
369
- * Input to this function is the response received from your API
370
- * */
371
- responseFormatter: PropTypes.func,
372
- /** If paginationType is "SERVER", function that is expected to return the URL Params object */
373
- getUrlParams: PropTypes.func,
374
-
375
- /** Show the optional clear button for resetting selections */
376
- showClear: PropTypes.bool,
377
- /** Custom on clear function */
378
- onClear: PropTypes.func,
379
- /** Callback on query search in dropdown */
380
- onSearchChange: PropTypes.func,
381
- /** List header Component */
382
- ListHeaderItem: PropTypes.string
383
- };
384
-
385
- Dropdown.defaultProps = {
386
- className: "",
387
- label: "",
388
- showLabel: true,
389
- showSearch: false,
390
- searchPlaceholder: "Search",
391
- searchAttribute: "search",
392
- multiSelect: false,
393
- idAttribute: "id",
394
- nameAttribute: "name",
395
- noSelectionLabel: "Select",
396
- appearance: "inline",
397
- halign: "left",
398
- validations: [],
399
- paginationType: "NONE",
400
- pageNoKey: "page",
401
- perPageKey: "count",
402
- maxHeight: 200,
403
- pageSize: 10,
404
- getUrlParams: () => ({}),
405
- SelectionSummary: DefaultSelectionSummary,
406
- showCreateCTA: false,
407
- serverListClassName: "",
408
- createCTAComponent: <span>Create New</span>,
409
- onCreateCTAClick: () => {},
410
- showClear: false,
411
- ListHeaderItem: "",
412
- onClear: () => {}
413
- };
414
-
415
- export default Dropdown;
@@ -1,64 +0,0 @@
1
- import React, { useContext } from "react";
2
- import PropTypes from "prop-types";
3
- import { FormContext } from "./Form";
4
- import FormElementWrapper from "./FormElementWrapper";
5
-
6
- const FileUploader = (props) => {
7
- const { label, name, multiple, accept, className, appearance, onChange, children } = props;
8
- const { onValueChange } = useContext(FormContext);
9
-
10
- const onFileChange = (event) => {
11
- const value = event.target.files;
12
-
13
- if (typeof(onChange) === "function") {
14
- onChange(value);
15
- }
16
-
17
- typeof(onValueChange) === "function" && onValueChange(name, value);
18
- };
19
-
20
- let inputProps = {
21
- type: "file",
22
- label,
23
- name,
24
- id: name,
25
- multiple: multiple,
26
- accept: accept,
27
- className: "RCB-form-el",
28
- onChange: onFileChange
29
- };
30
-
31
- return (<FormElementWrapper className={className} appearance={appearance}>
32
- <label className="RCB-form-el-label">{label}</label>
33
- <input {...inputProps} className="RCB-hidden" />
34
- <label htmlFor={name} className="RCB-file-input">
35
- <div className="RCB-no-pointer">{children}</div>
36
- </label>
37
- </FormElementWrapper>);
38
- };
39
-
40
- FileUploader.propTypes = {
41
- /** Pass any additional classNames to Input component */
42
- className: PropTypes.string,
43
- /** Label for the input element */
44
- label: PropTypes.string,
45
- /** Unique ID for the input element */
46
- name: PropTypes.string.isRequired,
47
- /** set to true to upload multiple files at once */
48
- multiple: PropTypes.bool,
49
- /** mime type of the acceptable files */
50
- accept: PropTypes.string,
51
- /** Define the appearance of the form element. Accepted values are either "inline" or "block" */
52
- appearance: PropTypes.oneOf(["inline", "block"]),
53
- /** Becomes a controlled component if onChange function is given */
54
- onChange: PropTypes.func
55
- };
56
-
57
- FileUploader.defaultProps = {
58
- className: "",
59
- appearance: "inline",
60
- multiple: false,
61
- accept: "image/*"
62
- };
63
-
64
- export default FileUploader;
@@ -1,83 +0,0 @@
1
- import React, { useState, useRef, createContext, useImperativeHandle, forwardRef, useEffect } from "react";
2
- import PropTypes from "prop-types";
3
- import dequal from "dequal";
4
- import cloneDeep from "lodash.clonedeep";
5
-
6
- export const FormContext = createContext({
7
- onValueChange: () => {}
8
- });
9
-
10
- let Form = (props, ref) => {
11
- const [ formData, setFormData ] = useState({});
12
- const [ formErrors, setFormErrors ] = useState({});
13
- const [ formRefreshCount, setFormRefreshCount ] = useState(0);
14
- const { className, onChange, onSubmit } = props;
15
- const dataRef = useRef();
16
-
17
- const getFormData = () => {
18
- return { data: formData, errors: formErrors };
19
- };
20
-
21
- /* add methods that can be accessed via this component's ref */
22
- useImperativeHandle(ref, () => ({
23
- getFormData: getFormData
24
- }));
25
-
26
- const onValueChange = (key, value, error) => {
27
- formData[key] = value;
28
- setFormData(formData);
29
-
30
- if (error) {
31
- formErrors[key] = error;
32
- } else {
33
- /* remove the error value */
34
- delete formErrors[key];
35
- }
36
-
37
- setFormErrors(formErrors);
38
- setFormRefreshCount(formRefreshCount + 1);
39
- };
40
-
41
- const onFormSubmit = (event) => {
42
- event.preventDefault();
43
- onSubmit(getFormData());
44
- }
45
-
46
- useEffect(() => {
47
- /*
48
- As useEffect does not do a deep comparision on dependent props,
49
- do a manual deep comparision to decide whether data changed
50
- */
51
- if (typeof(onChange) === "function") {
52
- const formData = getFormData();
53
-
54
- if (!dequal(formData, dataRef.current)) {
55
- dataRef.current = cloneDeep(formData);
56
- onChange(formData);
57
- }
58
- }
59
- }, [formRefreshCount]);
60
-
61
- return (<form onSubmit={onFormSubmit} className={className}>
62
- <FormContext.Provider value={{onValueChange: onValueChange}}>
63
- {props.children}
64
- </FormContext.Provider>
65
- </form>);
66
- };
67
-
68
- Form = forwardRef(Form);
69
-
70
- Form.propTypes = {
71
- /** Pass any additional classNames to Form component */
72
- className: PropTypes.string,
73
- /** Pass a callback function to listen to changes on any of the form elements */
74
- onChange: PropTypes.func,
75
- /** Pass a callback function to listen to form submit event */
76
- onSubmit: PropTypes.func
77
- };
78
-
79
- Form.defaultProps = {
80
- className: ""
81
- };
82
-
83
- export default Form;
@@ -1,22 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
-
4
- const FormElementWrapper = (props) => {
5
- const { className, children, appearance } = props;
6
-
7
- return (<div className={`RCB-form-el-cont RCB-form-el-${appearance} ${className}`}>
8
- {children}
9
- </div>);
10
- };
11
-
12
- FormElementWrapper.propTypes = {
13
- /** Pass any additional classNames to Form component */
14
- className: PropTypes.string,
15
- appearance: PropTypes.string
16
- };
17
-
18
- FormElementWrapper.defaultProps = {
19
- appearance: "inline"
20
- };
21
-
22
- export default FormElementWrapper;