@unbxd-ui/unbxd-react-components 0.2.99 → 0.2.101-beta.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 (139) hide show
  1. package/.babelrc +4 -0
  2. package/.eslintrc.js +38 -0
  3. package/CONTRIBUTE.md +105 -0
  4. package/components/Form/RangeSlider.js +3 -7
  5. package/components/core.css +1 -3
  6. package/components/theme.css +0 -2
  7. package/package.json +23 -13
  8. package/src/Intro.stories.mdx +119 -0
  9. package/src/components/Accordian/Accordian.js +89 -0
  10. package/src/components/Accordian/Accordian.stories.js +92 -0
  11. package/src/components/Accordian/accordianCore.scss +8 -0
  12. package/src/components/Accordian/accordianTheme.scss +6 -0
  13. package/src/components/Accordian/index.js +3 -0
  14. package/src/components/Button/Button.js +67 -0
  15. package/src/components/Button/Button.stories.js +103 -0
  16. package/src/components/Button/DropdownButton.js +60 -0
  17. package/src/components/Button/DropdownButton.stories.js +38 -0
  18. package/src/components/Button/buttonTheme.css +1 -0
  19. package/src/components/Button/buttonTheme.scss +45 -0
  20. package/src/components/Button/index.js +5 -0
  21. package/src/components/DataLoader/DataLoader.js +86 -0
  22. package/src/components/DataLoader/DataLoader.stories.js +72 -0
  23. package/src/components/DataLoader/index.js +3 -0
  24. package/src/components/Form/Checkbox.js +73 -0
  25. package/src/components/Form/DragDropFileUploader.js +67 -0
  26. package/src/components/Form/Dropdown.js +415 -0
  27. package/src/components/Form/FileUploader.js +64 -0
  28. package/src/components/Form/Form.js +83 -0
  29. package/src/components/Form/FormElementWrapper.js +22 -0
  30. package/src/components/Form/Input.js +121 -0
  31. package/src/components/Form/RadioList.js +86 -0
  32. package/src/components/Form/RangeSlider.js +100 -0
  33. package/src/components/Form/ServerPaginatedDDList.js +226 -0
  34. package/src/components/Form/Textarea.js +76 -0
  35. package/src/components/Form/Toggle.js +96 -0
  36. package/src/components/Form/form.css +1 -0
  37. package/src/components/Form/formCore.scss +142 -0
  38. package/src/components/Form/formTheme.scss +27 -0
  39. package/src/components/Form/index.js +13 -0
  40. package/src/components/Form/stories/Checkbox.stories.js +41 -0
  41. package/src/components/Form/stories/DragDropFileUploader.stories.js +21 -0
  42. package/src/components/Form/stories/Dropdown.stories.js +124 -0
  43. package/src/components/Form/stories/FileUploader.stories.js +21 -0
  44. package/src/components/Form/stories/FormDefault.stories.js +87 -0
  45. package/src/components/Form/stories/RadioList.stories.js +48 -0
  46. package/src/components/Form/stories/RangeSlider.stories.js +84 -0
  47. package/src/components/Form/stories/TextInput.stories.js +77 -0
  48. package/src/components/Form/stories/Textarea.stories.js +43 -0
  49. package/src/components/Form/stories/Toggle.stories.js +14 -0
  50. package/src/components/Form/stories/form.stories.js +216 -0
  51. package/src/components/InlineModal/InlineModal.js +135 -0
  52. package/src/components/InlineModal/InlineModal.stories.js +54 -0
  53. package/src/components/InlineModal/index.js +4 -0
  54. package/src/components/InlineModal/inlineModal.css +1 -0
  55. package/src/components/InlineModal/inlineModalCore.scss +31 -0
  56. package/src/components/InlineModal/inlineModalTheme.scss +16 -0
  57. package/src/components/List/List.js +72 -0
  58. package/src/components/List/index.js +3 -0
  59. package/src/components/List/list.stories.js +28 -0
  60. package/src/components/List/listCore.css +1 -0
  61. package/src/components/List/listCore.scss +6 -0
  62. package/src/components/Modal/Modal.js +99 -0
  63. package/src/components/Modal/Modal.stories.js +54 -0
  64. package/src/components/Modal/index.js +3 -0
  65. package/src/components/Modal/modal.css +1 -0
  66. package/src/components/Modal/modalCore.scss +34 -0
  67. package/src/components/NotificationComponent/NotificationComponent.js +58 -0
  68. package/src/components/NotificationComponent/NotificationComponent.stories.js +28 -0
  69. package/src/components/NotificationComponent/index.js +3 -0
  70. package/src/components/NotificationComponent/notificationComponent.css +1 -0
  71. package/src/components/NotificationComponent/notificationTheme.scss +30 -0
  72. package/src/components/ProgressBar/ProgressBar.js +45 -0
  73. package/src/components/ProgressBar/ProgressBar.stories.js +14 -0
  74. package/src/components/ProgressBar/index.js +3 -0
  75. package/src/components/ProgressBar/progressBarCore.css +1 -0
  76. package/src/components/ProgressBar/progressBarCore.scss +14 -0
  77. package/src/components/ProgressBar/progressBarTheme.css +0 -0
  78. package/src/components/ProgressBar/progressBarTheme.scss +0 -0
  79. package/src/components/Table/BaseTable.js +306 -0
  80. package/src/components/Table/PaginationComponent.js +73 -0
  81. package/src/components/Table/Table.js +295 -0
  82. package/src/components/Table/Table.stories.js +198 -0
  83. package/src/components/Table/index.js +8 -0
  84. package/src/components/Table/table.css +1 -0
  85. package/src/components/Table/tableCore.scss +94 -0
  86. package/src/components/Table/tableTheme.scss +34 -0
  87. package/src/components/TabsComponent/TabsComponent.js +99 -0
  88. package/src/components/TabsComponent/TabsComponent.stories.js +69 -0
  89. package/src/components/TabsComponent/index.js +3 -0
  90. package/src/components/TabsComponent/tabs.css +1 -0
  91. package/src/components/TabsComponent/tabsCore.scss +59 -0
  92. package/src/components/TabsComponent/tabsTheme.css +0 -0
  93. package/src/components/TabsComponent/tabsTheme.scss +0 -0
  94. package/src/components/Tooltip/Tooltip.js +87 -0
  95. package/src/components/Tooltip/Tooltip.stories.js +16 -0
  96. package/src/components/Tooltip/index.js +3 -0
  97. package/src/components/Tooltip/tooltipCore.scss +22 -0
  98. package/src/components/Tooltip/tooltipTheme.scss +21 -0
  99. package/src/components/core.css +1 -0
  100. package/src/components/core.scss +29 -0
  101. package/src/components/index.js +38 -0
  102. package/src/components/theme.css +1 -0
  103. package/src/components/theme.scss +11 -0
  104. package/src/core/Validators.js +34 -0
  105. package/src/core/customHooks.js +20 -0
  106. package/src/core/dataLoader.js +143 -0
  107. package/src/core/dataLoader.stories.js +123 -0
  108. package/src/core/index.js +3 -0
  109. package/src/core/utils.js +95 -0
  110. package/src/index.js +68 -0
  111. package/vscode-templates/NewStoryTemplate.stories.js +8 -0
  112. package/core/Validators.js +0 -48
  113. package/core/customHooks.js +0 -41
  114. package/core/dataLoader.js +0 -235
  115. package/core/dataLoader.stories.js +0 -153
  116. package/core/index.js +0 -31
  117. package/core/utils.js +0 -112
  118. package/index.js +0 -193
  119. /package/{Readme.md → README.md} +0 -0
  120. /package/{components → src/components}/Accordian/accordianCore.css +0 -0
  121. /package/{components → src/components}/Accordian/accordianTheme.css +0 -0
  122. /package/{components/Button/buttonTheme.css → src/components/Button/button.css} +0 -0
  123. /package/{components → src/components}/Form/formCore.css +0 -0
  124. /package/{components → src/components}/Form/formTheme.css +0 -0
  125. /package/{components → src/components}/InlineModal/inlineModalCore.css +0 -0
  126. /package/{components → src/components}/InlineModal/inlineModalTheme.css +0 -0
  127. /package/{components/List/listCore.css → src/components/List/list.css} +0 -0
  128. /package/{components → src/components}/List/listTheme.css +0 -0
  129. /package/{components/Modal/modalTheme.css → src/components/List/listTheme.scss} +0 -0
  130. /package/{components → src/components}/Modal/modalCore.css +0 -0
  131. /package/{components/ProgressBar/progressBarTheme.css → src/components/Modal/modalTheme.css} +0 -0
  132. /package/{components/TabsComponent/tabsTheme.css → src/components/Modal/modalTheme.scss} +0 -0
  133. /package/{components → src/components}/NotificationComponent/notificationTheme.css +0 -0
  134. /package/{components/ProgressBar/progressBarCore.css → src/components/ProgressBar/progressBar.css} +0 -0
  135. /package/{components → src/components}/Table/tableCore.css +0 -0
  136. /package/{components → src/components}/Table/tableTheme.css +0 -0
  137. /package/{components → src/components}/TabsComponent/tabsCore.css +0 -0
  138. /package/{components → src/components}/Tooltip/tooltipCore.css +0 -0
  139. /package/{components → src/components}/Tooltip/tooltipTheme.css +0 -0
@@ -0,0 +1,67 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+
4
+ /** ButtonAppearance enum */
5
+ export const ButtonAppearance = {
6
+ DEFAULT: "default",
7
+ PRIMARY: "primary",
8
+ SECONDARY: "secondary"
9
+ };
10
+ /** ButtonSize enum */
11
+ export const ButtonSize = {
12
+ SMALL: "small",
13
+ MEDIUM: "medium",
14
+ LARGE: "large"
15
+ };
16
+
17
+ /**
18
+ *
19
+ * Displays a Button component
20
+ */
21
+ const Button = (props) => {
22
+ const { children, className, loading, disabled, appearance, size, onClick, ...restProps } = props;
23
+ const btnClassName = `RCB-btn RCB-btn-${appearance} RCB-btn-${size} ${className}` + (loading ? " RCB-btn-loading" : "");
24
+
25
+ return (<button className={btnClassName} disabled={disabled} onClick={onClick} {...restProps}>
26
+ {children}
27
+ </button>);
28
+ };
29
+
30
+ Button.propTypes = {
31
+ /** Add any additional classes to Button component */
32
+ className: PropTypes.string,
33
+ /** Boolean indicating whether the button should render as disabled */
34
+ disabled: PropTypes.bool,
35
+ /** Boolean indicating whether the button is in loading state */
36
+ loading: PropTypes.bool,
37
+ /** String indicating how Button should be rendered.
38
+ * Must be one of,
39
+ * ButtonAppearance = {
40
+ DEFAULT: "default",
41
+ PRIMARY: "primary",
42
+ SECONDARY: "secondary"
43
+ }
44
+ */
45
+ appearance: PropTypes.oneOf(Object.values(ButtonAppearance)),
46
+ /** String indicating the size of the Button
47
+ * Must be one of,
48
+ * ButtonSize = {
49
+ SMALL: "small",
50
+ MEDIUM: "medium",
51
+ LARGE: "large"
52
+ }
53
+ */
54
+ size: PropTypes.oneOf(Object.values(ButtonSize)),
55
+ /** Button onClick handler */
56
+ onClick: PropTypes.func
57
+ };
58
+
59
+ Button.defaultProps = {
60
+ onClick: () => {},
61
+ appearance: ButtonAppearance.DEFAULT,
62
+ size: ButtonSize.SMALL,
63
+ className: ""
64
+ };
65
+
66
+ export default Button;
67
+
@@ -0,0 +1,103 @@
1
+ import React from "react";
2
+ import { action } from "@storybook/addon-actions";
3
+ import Button, { ButtonAppearance, ButtonSize } from "./Button";
4
+
5
+ export const SimpleUsage = () => {
6
+ return (
7
+ <div className="margin-btns">
8
+ <Button size={ButtonSize.SMALL} onClick={action("clicked")}>
9
+ SMALL
10
+ </Button>
11
+ <Button size={ButtonSize.MEDIUM} onClick={action("clicked")}>
12
+ MEDIUM
13
+ </Button>
14
+ <Button size={ButtonSize.LARGE} onClick={action("clicked")}>
15
+ LARGE
16
+ </Button>
17
+ </div>
18
+ );
19
+ };
20
+
21
+ SimpleUsage.story = {
22
+ parameters: {
23
+ docs: {
24
+ storyDescription: "Depicts a simple usage of the button",
25
+ },
26
+ },
27
+ };
28
+
29
+ export const PrimaryButton = () => {
30
+ return (
31
+ <div className="margin-btns">
32
+ <Button
33
+ appearance={ButtonAppearance.PRIMARY}
34
+ size={ButtonSize.SMALL}
35
+ onClick={action("clicked")}
36
+ >
37
+ SMALL
38
+ </Button>
39
+ <Button
40
+ appearance={ButtonAppearance.PRIMARY}
41
+ size={ButtonSize.MEDIUM}
42
+ onClick={action("clicked")}
43
+ >
44
+ MEDIUM
45
+ </Button>
46
+ <Button
47
+ appearance={ButtonAppearance.PRIMARY}
48
+ size={ButtonSize.LARGE}
49
+ onClick={action("clicked")}
50
+ >
51
+ LARGE
52
+ </Button>
53
+ </div>
54
+ );
55
+ };
56
+
57
+ PrimaryButton.story = {
58
+ parameters: {
59
+ docs: {
60
+ storyDescription: "Depicts a primary button",
61
+ },
62
+ },
63
+ };
64
+
65
+ export const SecondaryButton = () => {
66
+ return (
67
+ <div className="margin-btns">
68
+ <Button
69
+ appearance={ButtonAppearance.SECONDARY}
70
+ size={ButtonSize.SMALL}
71
+ onClick={action("clicked")}
72
+ >
73
+ SMALL
74
+ </Button>
75
+ <Button
76
+ appearance={ButtonAppearance.SECONDARY}
77
+ size={ButtonSize.MEDIUM}
78
+ onClick={action("clicked")}
79
+ >
80
+ MEDIUM
81
+ </Button>
82
+ <Button
83
+ appearance={ButtonAppearance.SECONDARY}
84
+ size={ButtonSize.LARGE}
85
+ onClick={action("clicked")}
86
+ >
87
+ LARGE
88
+ </Button>
89
+ </div>
90
+ );
91
+ };
92
+
93
+ SecondaryButton.story = {
94
+ parameters: {
95
+ docs: {
96
+ storyDescription: "Depicts a secondary button",
97
+ },
98
+ },
99
+ };
100
+
101
+ export default {
102
+ title: "Button",
103
+ };
@@ -0,0 +1,60 @@
1
+ import React, { useRef } from "react";
2
+ import PropTypes from "prop-types";
3
+ import InlineModal, { InlineModalActivator, InlineModalBody } from "../InlineModal";
4
+ import List from "../List";
5
+
6
+ const DefaultDropdownButtonItem = (props) => {
7
+ let { itemData = {}, onClick } = props;
8
+ let { name } = itemData;
9
+
10
+ const onItemClicked = () => {
11
+ onClick(itemData);
12
+ };
13
+
14
+ return (<li className="RCB-list-item" onClick={onItemClicked}>{name}</li>);
15
+ };
16
+
17
+ DefaultDropdownButtonItem.propTypes = {
18
+ itemData: PropTypes.shape({
19
+ id: PropTypes.string.isRequired,
20
+ name: PropTypes.string.isRequired
21
+ }).isRequired,
22
+ onClick: PropTypes.func.isRequired
23
+ };
24
+
25
+ const DropdownButton = (props) => {
26
+ const { label, options, className, onClick, DropdownButtonItem, ...restProps } = props;
27
+ const modalRef = useRef();
28
+
29
+ const onItemClicked = (itemData) => {
30
+ onClick(itemData);
31
+ modalRef.current.hideModal();
32
+ };
33
+
34
+ return (<InlineModal className={`RCB-dropdown-button ${className}`} ref={modalRef}>
35
+ <InlineModalActivator>{label}</InlineModalActivator>
36
+ <InlineModalBody>
37
+ <List items={options} ListItem={DropdownButtonItem} onClick={onItemClicked} {...restProps} />
38
+ </InlineModalBody>
39
+ </InlineModal>);
40
+ };
41
+
42
+ DropdownButton.propTypes = {
43
+ label: PropTypes.string,
44
+ /** Dropdown items list */
45
+ options: PropTypes.arrayOf(PropTypes.shape({
46
+ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
47
+ name: PropTypes.string,
48
+ })).isRequired,
49
+ onClick: PropTypes.func.isRequired,
50
+ DropdownButtonItem: PropTypes.any,
51
+ className: PropTypes.string
52
+ };
53
+
54
+ DropdownButton.defaultProps = {
55
+ label: "Select",
56
+ DropdownButtonItem: DefaultDropdownButtonItem,
57
+ className: ""
58
+ };
59
+
60
+ export default DropdownButton;
@@ -0,0 +1,38 @@
1
+ import React, { useState } from "react";
2
+ import { Fragment } from "react";
3
+ import DropdownButton from "./DropdownButton";
4
+
5
+ const DROPDOWN_OPTIONS = [{
6
+ id: "PrintApple",
7
+ name: "Print Apple",
8
+ message: "Apple"
9
+ }, {
10
+ id: "PrintMango",
11
+ name: "Print Mango",
12
+ message: "Mango"
13
+ }, {
14
+ id: "PrintGrapes",
15
+ name: "Print Grapes",
16
+ message: "Grapes"
17
+ }];
18
+
19
+ export const DefaultDropdownButton = () => {
20
+ const [ message, setMessage ] = useState();
21
+
22
+ const printMessage = (data) => {
23
+ const { message } = data;
24
+ setMessage(message);
25
+ };
26
+
27
+ return (<Fragment>
28
+ <DropdownButton
29
+ label="Actions"
30
+ options={DROPDOWN_OPTIONS}
31
+ onClick={printMessage} />
32
+ <div>{`Message is ${message}`}</div>
33
+ </Fragment>);
34
+ };
35
+
36
+ export default {
37
+ title: "Dropdown Button"
38
+ };
@@ -0,0 +1 @@
1
+ .RCB-btn{border-radius:3px;cursor:pointer}.RCB-btn-default:hover{background:#f3f3f3}.RCB-btn-primary{background:#1fa7fd;color:#FFF;border:0}.RCB-btn-primary:hover{background:#208dd2}.RCB-btn-secondary{background:#FFF;border:1px solid #95c7e7}.RCB-btn-secondary:hover{background:#eef8ff}.RCB-btn-small{padding:6px 8px}.RCB-btn-medium{padding:10px 15px}.RCB-btn-large{padding:15px 22px}
@@ -0,0 +1,45 @@
1
+ .RCB {
2
+ &-btn {
3
+ border-radius: 3px;
4
+ cursor: pointer;
5
+ }
6
+
7
+ &-btn {
8
+ &-default {
9
+ &:hover {
10
+ background: #f3f3f3;
11
+ }
12
+ }
13
+
14
+ &-primary {
15
+ background: #1fa7fd;
16
+ color: #FFF;
17
+ border: 0;
18
+
19
+ &:hover {
20
+ background: #208dd2;
21
+ }
22
+ }
23
+
24
+ &-secondary {
25
+ background: #FFF;
26
+ border: 1px solid #95c7e7;
27
+
28
+ &:hover {
29
+ background: #eef8ff;
30
+ }
31
+ }
32
+
33
+ &-small {
34
+ padding: 6px 8px;
35
+ }
36
+
37
+ &-medium {
38
+ padding: 10px 15px;
39
+ }
40
+
41
+ &-large {
42
+ padding: 15px 22px;
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ import Button, { ButtonAppearance, ButtonSize } from "./Button";
2
+ import DropdownButton from "./DropdownButton";
3
+
4
+ export default Button;
5
+ export { ButtonAppearance, ButtonSize, DropdownButton };
@@ -0,0 +1,86 @@
1
+ import React, { useState, useEffect, Fragment } from "react";
2
+ import PropTypes from "prop-types";
3
+ import Promise from "bluebird";
4
+ import dequal from "dequal";
5
+ import dataLoader from "../../core/dataLoader";
6
+ import cloneDeep from "lodash.clonedeep";
7
+ import utils from "../../core/utils";
8
+
9
+ const DefaultLoader = () => {
10
+ return (<div>Loading...</div>);
11
+ };
12
+
13
+ const loadData = (requests) => {
14
+ let promisesArray = requests.map(reqObj => {
15
+ return dataLoader.getRequestDef(reqObj);
16
+ });
17
+
18
+ return Promise.all(promisesArray);
19
+ };
20
+
21
+ const DataLoader = (props) => {
22
+ const [ isLoading, setIsLoading ] = useState(true);
23
+ const dataRef = React.useRef();
24
+ const { children, Loader, requests, onDataLoaded, onDataFailed } = props;
25
+
26
+ const renderLoader = () => {
27
+ const LoaderComponent = Loader || utils.getDefaultConfig("DefaultLoader") || DefaultLoader;
28
+ return <LoaderComponent />;
29
+ };
30
+
31
+ const renderChildren = () => {
32
+ return children;
33
+ };
34
+
35
+ const fetchData = () => {
36
+ setIsLoading(true);
37
+ loadData(requests)
38
+ .then(resultsArray => {
39
+ onDataLoaded(resultsArray);
40
+ })
41
+ .catch(exception => {
42
+ onDataFailed(exception);
43
+ })
44
+ .finally(() => {
45
+ setIsLoading(false);
46
+ });
47
+ }
48
+
49
+ useEffect(() => {
50
+ /*
51
+ As useEffect does not do a deep comparision on dependent props,
52
+ do a manual deep comparision to decide whether to load data
53
+ */
54
+ if (!dequal(requests, dataRef.current)) {
55
+ dataRef.current = cloneDeep(requests);
56
+ fetchData();
57
+ }
58
+ });
59
+
60
+ return (<Fragment>
61
+ {isLoading ?
62
+ renderLoader()
63
+ : renderChildren()}
64
+ </Fragment>);
65
+ };
66
+
67
+ DataLoader.propTypes = {
68
+ /** Requests array */
69
+ requests: PropTypes.array.isRequired,
70
+ /** Callback function which is called when data is loaded */
71
+ onDataLoaded: PropTypes.func,
72
+ /** Callback function which is called when data fetching fails */
73
+ onDataFailed: PropTypes.func,
74
+ /** Custom loader component */
75
+ Loader: PropTypes.oneOfType([
76
+ PropTypes.instanceOf(Element),
77
+ PropTypes.func
78
+ ])
79
+ };
80
+
81
+ DataLoader.defaultProps = {
82
+ onDataLoaded: () => {},
83
+ onDataFailed: () => {}
84
+ }
85
+
86
+ export default DataLoader;
@@ -0,0 +1,72 @@
1
+ import React, { Fragment } from "react";
2
+ import DataLoader from "./DataLoader";
3
+ import dataLoader from "../../core/dataLoader";
4
+
5
+ export const SimpleUsage = () => {
6
+ dataLoader.addRequestConfig("getTodos", {
7
+ method: "GET",
8
+ url: "https://jsonplaceholder.typicode.com/todos",
9
+ });
10
+
11
+ const onDataLoaded = ([todos]) => {
12
+ console.log(todos);
13
+ };
14
+
15
+ const onDataFailed = e => {
16
+ console.log("Error ", e);
17
+ };
18
+
19
+ const requests = [
20
+ {
21
+ requestId: "getTodos",
22
+ },
23
+ ];
24
+
25
+ return (<Fragment>
26
+ <p>Use the <code>DataLoader</code> component to make implicit API calls by wrapping the JSX content where you want the API data with this component.
27
+ This would mostly be used for GET calls.</p>
28
+ <DataLoader requests={requests} onDataLoaded={onDataLoaded} onDataFailed={onDataFailed}>
29
+ <div>Received the data</div>
30
+ </DataLoader>
31
+ </Fragment>);
32
+ };
33
+
34
+ export const FunctionUrl = () => {
35
+ dataLoader.addRequestConfig("getTodoById", {
36
+ method: "GET",
37
+ url: function(params) {
38
+ return `https://jsonplaceholder.typicode.com/todos/${params.id}`;
39
+ },
40
+ });
41
+
42
+ const onDataLoaded = ([todo]) => {
43
+ console.log(todo);
44
+ };
45
+
46
+ const onDataFailed = e => {
47
+ console.log("Error ", e);
48
+ };
49
+
50
+ const requests = [
51
+ {
52
+ requestId: "getTodoById",
53
+ urlParams: {
54
+ id: 1,
55
+ },
56
+ },
57
+ ];
58
+
59
+ return (
60
+ <DataLoader requests={requests} onDataLoaded={onDataLoaded} onDataFailed={onDataFailed}>
61
+ <div>Recieved todo data</div>
62
+ </DataLoader>
63
+ );
64
+ };
65
+
66
+ FunctionUrl.story = {
67
+ name: "Function URL",
68
+ };
69
+
70
+ export default {
71
+ title: "Data fetching|DataLoader (Component)"
72
+ };
@@ -0,0 +1,3 @@
1
+ import DataLoader from "./DataLoader";
2
+
3
+ export default DataLoader;
@@ -0,0 +1,73 @@
1
+ import React, { useContext, useEffect } from "react";
2
+ import PropTypes from "prop-types";
3
+ import { FormContext } from "./Form";
4
+ import FormElementWrapper from "./FormElementWrapper";
5
+
6
+ const Checkbox = (props) => {
7
+ const { label, name, className, value, defaultValue, appearance, onChange, ...restProps } = props;
8
+ const { onValueChange } = useContext(FormContext);
9
+
10
+ const postFormValueChange = (value) => {
11
+ typeof(onValueChange) === "function" && onValueChange(name, value);
12
+ };
13
+
14
+ const onInputChange = (event) => {
15
+ const value = event.target.checked;
16
+
17
+ if (typeof(onChange) === "function") {
18
+ onChange(value);
19
+ }
20
+
21
+ postFormValueChange(value);
22
+ }
23
+
24
+ useEffect(() => {
25
+ /* set the initial form element value in the form context */
26
+ const postValue = typeof(onChange) === "function" ? value : defaultValue;
27
+ postFormValueChange(postValue);
28
+ }, [value, defaultValue]);
29
+
30
+ let inputProps = {
31
+ type: "checkbox",
32
+ label,
33
+ name,
34
+ id: name,
35
+ defaultChecked: defaultValue,
36
+ className: "RCB-form-el",
37
+ onChange: onInputChange,
38
+ ...restProps
39
+ };
40
+
41
+ if (typeof(onChange) === "function") {
42
+ /* make it a controlled component if onChange function is given */
43
+ inputProps.checked = value;
44
+ }
45
+
46
+ return (<FormElementWrapper className={className} appearance={appearance}>
47
+ <input {...inputProps} />
48
+ <label className="RCB-form-el-label" htmlFor={name}>{label}</label>
49
+ </FormElementWrapper>);
50
+ };
51
+
52
+ Checkbox.propTypes = {
53
+ /** Pass any additional classNames to Input component */
54
+ className: PropTypes.string,
55
+ /** Label for the input element */
56
+ label: PropTypes.any,
57
+ /** Unique ID for the input element */
58
+ name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
59
+ /** Will be used only with onChange function, or else ignored */
60
+ value: PropTypes.bool,
61
+ defaultValue: PropTypes.bool,
62
+ /** Define the appearance of the form element. Accepted values are either "inline" or "block" */
63
+ appearance: PropTypes.oneOf(["inline", "block"]),
64
+ /** Becomes a controlled component if onChange function is given */
65
+ onChange: PropTypes.func
66
+ };
67
+
68
+ Checkbox.defaultProps = {
69
+ className: "",
70
+ appearance: "inline"
71
+ };
72
+
73
+ export default Checkbox;
@@ -0,0 +1,67 @@
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;