@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.
- package/components/Form/RangeSlider.js +7 -3
- package/components/Tooltip/Tooltip.js +11 -2
- package/components/core.css +3 -1
- package/components/theme.css +2 -0
- package/core/Validators.js +48 -0
- package/core/customHooks.js +41 -0
- package/core/dataLoader.js +235 -0
- package/core/dataLoader.stories.js +153 -0
- package/core/index.js +31 -0
- package/core/utils.js +112 -0
- package/index.js +193 -0
- package/package.json +1 -1
- package/.babelrc +0 -4
- package/.eslintrc.js +0 -38
- package/CONTRIBUTE.md +0 -105
- package/src/Intro.stories.mdx +0 -119
- package/src/components/Accordian/Accordian.js +0 -89
- package/src/components/Accordian/Accordian.stories.js +0 -92
- package/src/components/Accordian/accordianCore.scss +0 -8
- package/src/components/Accordian/accordianTheme.scss +0 -6
- package/src/components/Accordian/index.js +0 -3
- package/src/components/Button/Button.js +0 -67
- package/src/components/Button/Button.stories.js +0 -103
- package/src/components/Button/DropdownButton.js +0 -60
- package/src/components/Button/DropdownButton.stories.js +0 -38
- package/src/components/Button/button.css +0 -1
- package/src/components/Button/buttonTheme.scss +0 -45
- package/src/components/Button/index.js +0 -5
- package/src/components/DataLoader/DataLoader.js +0 -86
- package/src/components/DataLoader/DataLoader.stories.js +0 -72
- package/src/components/DataLoader/index.js +0 -3
- package/src/components/Form/Checkbox.js +0 -73
- package/src/components/Form/DragDropFileUploader.js +0 -67
- package/src/components/Form/Dropdown.js +0 -415
- package/src/components/Form/FileUploader.js +0 -64
- package/src/components/Form/Form.js +0 -83
- package/src/components/Form/FormElementWrapper.js +0 -22
- package/src/components/Form/Input.js +0 -121
- package/src/components/Form/RadioList.js +0 -86
- package/src/components/Form/RangeSlider.js +0 -100
- package/src/components/Form/ServerPaginatedDDList.js +0 -226
- package/src/components/Form/Textarea.js +0 -76
- package/src/components/Form/Toggle.js +0 -96
- package/src/components/Form/form.css +0 -1
- package/src/components/Form/formCore.scss +0 -142
- package/src/components/Form/formTheme.scss +0 -27
- package/src/components/Form/index.js +0 -13
- package/src/components/Form/stories/Checkbox.stories.js +0 -41
- package/src/components/Form/stories/DragDropFileUploader.stories.js +0 -21
- package/src/components/Form/stories/Dropdown.stories.js +0 -124
- package/src/components/Form/stories/FileUploader.stories.js +0 -21
- package/src/components/Form/stories/FormDefault.stories.js +0 -87
- package/src/components/Form/stories/RadioList.stories.js +0 -48
- package/src/components/Form/stories/RangeSlider.stories.js +0 -84
- package/src/components/Form/stories/TextInput.stories.js +0 -77
- package/src/components/Form/stories/Textarea.stories.js +0 -43
- package/src/components/Form/stories/Toggle.stories.js +0 -14
- package/src/components/Form/stories/form.stories.js +0 -216
- package/src/components/InlineModal/InlineModal.js +0 -135
- package/src/components/InlineModal/InlineModal.stories.js +0 -54
- package/src/components/InlineModal/index.js +0 -4
- package/src/components/InlineModal/inlineModal.css +0 -1
- package/src/components/InlineModal/inlineModalCore.scss +0 -31
- package/src/components/InlineModal/inlineModalTheme.scss +0 -16
- package/src/components/List/List.js +0 -72
- package/src/components/List/index.js +0 -3
- package/src/components/List/list.css +0 -1
- package/src/components/List/list.stories.js +0 -28
- package/src/components/List/listCore.scss +0 -6
- package/src/components/List/listTheme.scss +0 -0
- package/src/components/Modal/Modal.js +0 -99
- package/src/components/Modal/Modal.stories.js +0 -54
- package/src/components/Modal/index.js +0 -3
- package/src/components/Modal/modal.css +0 -1
- package/src/components/Modal/modalCore.scss +0 -34
- package/src/components/Modal/modalTheme.scss +0 -0
- package/src/components/NotificationComponent/NotificationComponent.js +0 -58
- package/src/components/NotificationComponent/NotificationComponent.stories.js +0 -28
- package/src/components/NotificationComponent/index.js +0 -3
- package/src/components/NotificationComponent/notificationComponent.css +0 -1
- package/src/components/NotificationComponent/notificationTheme.scss +0 -30
- package/src/components/ProgressBar/ProgressBar.js +0 -45
- package/src/components/ProgressBar/ProgressBar.stories.js +0 -14
- package/src/components/ProgressBar/index.js +0 -3
- package/src/components/ProgressBar/progressBar.css +0 -1
- package/src/components/ProgressBar/progressBarCore.scss +0 -14
- package/src/components/ProgressBar/progressBarTheme.scss +0 -0
- package/src/components/Table/BaseTable.js +0 -306
- package/src/components/Table/PaginationComponent.js +0 -73
- package/src/components/Table/Table.js +0 -295
- package/src/components/Table/Table.stories.js +0 -198
- package/src/components/Table/index.js +0 -8
- package/src/components/Table/table.css +0 -1
- package/src/components/Table/tableCore.scss +0 -94
- package/src/components/Table/tableTheme.scss +0 -34
- package/src/components/TabsComponent/TabsComponent.js +0 -99
- package/src/components/TabsComponent/TabsComponent.stories.js +0 -69
- package/src/components/TabsComponent/index.js +0 -3
- package/src/components/TabsComponent/tabs.css +0 -1
- package/src/components/TabsComponent/tabsCore.scss +0 -59
- package/src/components/TabsComponent/tabsTheme.scss +0 -0
- package/src/components/Tooltip/Tooltip.js +0 -87
- package/src/components/Tooltip/Tooltip.stories.js +0 -16
- package/src/components/Tooltip/index.js +0 -3
- package/src/components/Tooltip/tooltipCore.scss +0 -22
- package/src/components/Tooltip/tooltipTheme.scss +0 -21
- package/src/components/core.css +0 -1
- package/src/components/core.scss +0 -29
- package/src/components/index.js +0 -38
- package/src/components/theme.css +0 -1
- package/src/components/theme.scss +0 -11
- package/src/core/Validators.js +0 -34
- package/src/core/customHooks.js +0 -20
- package/src/core/dataLoader.js +0 -143
- package/src/core/dataLoader.stories.js +0 -123
- package/src/core/index.js +0 -3
- package/src/core/utils.js +0 -95
- package/src/index.js +0 -68
- package/vscode-templates/NewStoryTemplate.stories.js +0 -8
- /package/{README.md → Readme.md} +0 -0
- /package/{src/components → components}/Accordian/accordianCore.css +0 -0
- /package/{src/components → components}/Accordian/accordianTheme.css +0 -0
- /package/{src/components → components}/Button/buttonTheme.css +0 -0
- /package/{src/components → components}/Form/formCore.css +0 -0
- /package/{src/components → components}/Form/formTheme.css +0 -0
- /package/{src/components → components}/InlineModal/inlineModalCore.css +0 -0
- /package/{src/components → components}/InlineModal/inlineModalTheme.css +0 -0
- /package/{src/components → components}/List/listCore.css +0 -0
- /package/{src/components → components}/List/listTheme.css +0 -0
- /package/{src/components → components}/Modal/modalCore.css +0 -0
- /package/{src/components → components}/Modal/modalTheme.css +0 -0
- /package/{src/components → components}/NotificationComponent/notificationTheme.css +0 -0
- /package/{src/components → components}/ProgressBar/progressBarCore.css +0 -0
- /package/{src/components → components}/ProgressBar/progressBarTheme.css +0 -0
- /package/{src/components → components}/Table/tableCore.css +0 -0
- /package/{src/components → components}/Table/tableTheme.css +0 -0
- /package/{src/components → components}/TabsComponent/tabsCore.css +0 -0
- /package/{src/components → components}/TabsComponent/tabsTheme.css +0 -0
- /package/{src/components → components}/Tooltip/tooltipCore.css +0 -0
- /package/{src/components → components}/Tooltip/tooltipTheme.css +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React, { Fragment, useState } from "react";
|
|
2
|
-
import Accordian from "./Accordian";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Accordian',
|
|
7
|
-
component: Accordian,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const AccordianBody = () => {
|
|
11
|
-
const [count, setRandomNumber] = useState(1);
|
|
12
|
-
const onSetRandom = ()=>{
|
|
13
|
-
setRandomNumber(Math.round(Math.random()*10))
|
|
14
|
-
}
|
|
15
|
-
return <div style={{padding:'20px'}}>
|
|
16
|
-
<h3>This is accordian body</h3>
|
|
17
|
-
<button onClick={onSetRandom}> changed to {count}</button>
|
|
18
|
-
</div>
|
|
19
|
-
}
|
|
20
|
-
const AccordianTitle = ({id}) => {
|
|
21
|
-
return <div>
|
|
22
|
-
{`Title ${id}`}
|
|
23
|
-
</div>
|
|
24
|
-
}
|
|
25
|
-
const Template = (args) => <Accordian {...args} />;
|
|
26
|
-
|
|
27
|
-
export const Default = Template.bind();
|
|
28
|
-
Default.args = {
|
|
29
|
-
items: [{
|
|
30
|
-
id: "41",
|
|
31
|
-
titleComponent: <AccordianTitle id={'41'}/>,
|
|
32
|
-
bodyComponent: <AccordianBody/>,
|
|
33
|
-
}, {
|
|
34
|
-
id: "42",
|
|
35
|
-
titleComponent: <AccordianTitle id={'42'}/>,
|
|
36
|
-
bodyComponent: <AccordianBody/>
|
|
37
|
-
}, {
|
|
38
|
-
id: "43",
|
|
39
|
-
titleComponent: <AccordianTitle id={'43'}/>,
|
|
40
|
-
bodyComponent: <AccordianBody/>
|
|
41
|
-
}, {
|
|
42
|
-
id: "44",
|
|
43
|
-
titleComponent: <AccordianTitle id={'44'}/>,
|
|
44
|
-
bodyComponent: <AccordianBody/>
|
|
45
|
-
}],
|
|
46
|
-
defaultOpen:""
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const DefaultOpen = Template.bind();
|
|
50
|
-
DefaultOpen.args = {
|
|
51
|
-
items: [{
|
|
52
|
-
id: "41",
|
|
53
|
-
titleComponent: <AccordianTitle id={'41'}/>,
|
|
54
|
-
bodyComponent: <AccordianBody/>,
|
|
55
|
-
}, {
|
|
56
|
-
id: "42",
|
|
57
|
-
titleComponent: <AccordianTitle id={'42'}/>,
|
|
58
|
-
bodyComponent: <AccordianBody/>
|
|
59
|
-
}, {
|
|
60
|
-
id: "43",
|
|
61
|
-
titleComponent: <AccordianTitle id={'43'}/>,
|
|
62
|
-
bodyComponent: <AccordianBody/>
|
|
63
|
-
}, {
|
|
64
|
-
id: "44",
|
|
65
|
-
titleComponent: <AccordianTitle id={'44'}/>,
|
|
66
|
-
bodyComponent: <AccordianBody/>
|
|
67
|
-
}],
|
|
68
|
-
defaultOpen:"42"
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const OpenAtLeastOneAlways = Template.bind();
|
|
72
|
-
OpenAtLeastOneAlways.args = {
|
|
73
|
-
items: [{
|
|
74
|
-
id: "411",
|
|
75
|
-
titleComponent: <AccordianTitle id={'41'}/>,
|
|
76
|
-
bodyComponent: <AccordianBody/>,
|
|
77
|
-
}, {
|
|
78
|
-
id: "421",
|
|
79
|
-
titleComponent: <AccordianTitle id={'42'}/>,
|
|
80
|
-
bodyComponent: <AccordianBody/>
|
|
81
|
-
}, {
|
|
82
|
-
id: "431",
|
|
83
|
-
titleComponent: <AccordianTitle id={'43'}/>,
|
|
84
|
-
bodyComponent: <AccordianBody/>
|
|
85
|
-
}, {
|
|
86
|
-
id: "441",
|
|
87
|
-
titleComponent: <AccordianTitle id={'44'}/>,
|
|
88
|
-
bodyComponent: <AccordianBody/>
|
|
89
|
-
}],
|
|
90
|
-
defaultOpen:"421",
|
|
91
|
-
allowOneOpen:true
|
|
92
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
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;
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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}
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
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;
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
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;
|