orc-shared 5.10.1-dev.7 → 5.10.1-dev.9
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/dist/components/Authenticate.js +41 -17
- package/dist/components/ErrorPlaceholder.js +8 -24
- package/dist/components/{Icon.js → Form/Inputs/MultiSelector.js} +33 -20
- package/dist/components/Form/Inputs/index.js +1 -1
- package/dist/components/LoadingIcon.js +6 -16
- package/dist/components/MaterialUI/Inputs/Select.js +10 -0
- package/dist/components/MaterialUI/Inputs/SelectProps.js +3 -1
- package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
- package/dist/components/Provision.js +30 -13
- package/dist/components/Routing/SegmentPage.js +115 -56
- package/dist/components/Scope/ScopeNode.js +68 -45
- package/dist/components/Sidepanel.js +57 -23
- package/dist/components/Spritesheet.js +33 -17
- package/dist/components/Text.js +1 -60
- package/dist/components/Treeview/Branch.js +82 -20
- package/dist/components/Treeview/Label.js +108 -31
- package/dist/components/Treeview/Leaf.js +56 -12
- package/dist/components/Treeview/Node.js +22 -9
- package/dist/components/Treeview/index.js +7 -1
- package/dist/components/Treeview/settings.js +7 -5
- package/dist/utils/index.js +0 -4
- package/dist/utils/testUtils.js +1 -12
- package/package.json +1 -1
- package/src/components/ApplicationModuleLoader.test.js +14 -27
- package/src/components/Authenticate.js +29 -21
- package/src/components/Authenticate.test.js +18 -27
- package/src/components/ErrorPlaceholder.js +4 -21
- package/src/components/ErrorPlaceholder.test.js +7 -14
- package/src/components/Form/InputField.test.js +2 -1
- package/src/components/Form/Inputs/MultiSelector.js +23 -0
- package/src/components/Form/Inputs/MultiSelector.test.js +112 -0
- package/src/components/Form/Inputs/index.js +1 -1
- package/src/components/Loader.test.js +21 -33
- package/src/components/LoadingIcon.js +2 -15
- package/src/components/LoadingIcon.test.js +2 -20
- package/src/components/MaterialUI/DataDisplay/Table.test.js +1 -1
- package/src/components/MaterialUI/Inputs/Select.js +7 -0
- package/src/components/MaterialUI/Inputs/Select.test.js +45 -0
- package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
- package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
- package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
- package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
- package/src/components/Navigation/Navigation.test.js +0 -5
- package/src/components/Navigation/useNavigationState.test.js +79 -222
- package/src/components/Provision.js +36 -42
- package/src/components/Provision.test.js +10 -26
- package/src/components/Routing/SegmentPage.js +68 -52
- package/src/components/Routing/SegmentPage.test.js +4 -12
- package/src/components/Scope/ScopeNode.js +61 -54
- package/src/components/Scope/ScopeNode.test.js +61 -154
- package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
- package/src/components/Sidepanel.js +38 -32
- package/src/components/Sidepanel.test.js +49 -27
- package/src/components/Spritesheet.js +23 -21
- package/src/components/Spritesheet.test.js +10 -10
- package/src/components/Text.js +0 -49
- package/src/components/Treeview/Branch.js +63 -45
- package/src/components/Treeview/Branch.test.js +21 -24
- package/src/components/Treeview/Label.js +66 -52
- package/src/components/Treeview/Label.test.js +42 -60
- package/src/components/Treeview/Leaf.js +41 -22
- package/src/components/Treeview/Leaf.test.js +15 -10
- package/src/components/Treeview/Node.js +16 -9
- package/src/components/Treeview/Node.test.js +269 -200
- package/src/components/Treeview/Treeview.test.js +248 -248
- package/src/components/Treeview/index.js +6 -0
- package/src/components/Treeview/settings.js +7 -6
- package/src/utils/index.js +0 -4
- package/src/utils/testUtils.js +0 -10
- package/src/utils/testUtils.test.js +0 -68
- package/dist/components/Button.js +0 -70
- package/dist/components/Checkbox.js +0 -103
- package/dist/components/IconButton.js +0 -80
- package/dist/components/Input.js +0 -101
- package/dist/components/Modal/Background.js +0 -55
- package/dist/components/Modal/Dialog.js +0 -75
- package/dist/components/Modal/Wrapper.js +0 -69
- package/dist/components/Modal/index.js +0 -86
- package/dist/components/MultiSelector.js +0 -187
- package/dist/components/Navigation/Bar.js +0 -293
- package/dist/components/Navigation/Tab.js +0 -182
- package/dist/components/Placeholder.js +0 -114
- package/dist/components/Scope/Selector.js +0 -123
- package/dist/components/Selector.js +0 -185
- package/dist/components/Switch.js +0 -128
- package/dist/components/Toolbar.js +0 -227
- package/dist/components/Tooltip.js +0 -66
- package/dist/getTheme.js +0 -153
- package/dist/getThemeOverrides.js +0 -93
- package/dist/hocs/withAuthentication.js +0 -72
- package/dist/utils/styledPropFuncs.js +0 -88
- package/src/components/Button.js +0 -90
- package/src/components/Button.test.js +0 -49
- package/src/components/Checkbox.js +0 -63
- package/src/components/Checkbox.test.js +0 -122
- package/src/components/Icon.js +0 -18
- package/src/components/IconButton.js +0 -30
- package/src/components/IconButton.test.js +0 -61
- package/src/components/Input.js +0 -35
- package/src/components/Input.test.js +0 -34
- package/src/components/Modal/Background.js +0 -10
- package/src/components/Modal/Dialog.js +0 -27
- package/src/components/Modal/Dialog.test.js +0 -20
- package/src/components/Modal/Modal.test.js +0 -52
- package/src/components/Modal/Wrapper.js +0 -32
- package/src/components/Modal/Wrapper.test.js +0 -55
- package/src/components/Modal/index.js +0 -22
- package/src/components/MultiSelector.js +0 -104
- package/src/components/MultiSelector.test.js +0 -348
- package/src/components/Navigation/Bar.js +0 -212
- package/src/components/Navigation/Bar.test.js +0 -552
- package/src/components/Navigation/Tab.js +0 -156
- package/src/components/Navigation/Tab.test.js +0 -404
- package/src/components/Placeholder.js +0 -61
- package/src/components/Placeholder.test.js +0 -106
- package/src/components/Scope/Selector.js +0 -70
- package/src/components/Scope/Selector.test.js +0 -138
- package/src/components/Selector.js +0 -191
- package/src/components/Selector.test.js +0 -157
- package/src/components/Switch.js +0 -112
- package/src/components/Switch.test.js +0 -130
- package/src/components/Text.test.js +0 -132
- package/src/components/Toolbar.js +0 -178
- package/src/components/Toolbar.test.js +0 -478
- package/src/components/Tooltip.js +0 -51
- package/src/components/Tooltip.test.js +0 -21
- package/src/getTheme.js +0 -98
- package/src/getTheme.test.js +0 -92
- package/src/getThemeOverrides.js +0 -27
- package/src/hocs/withAuthentication.js +0 -18
- package/src/hocs/withAuthentication.test.js +0 -120
- package/src/utils/styledPropFuncs.js +0 -20
- package/src/utils/styledPropFuncs.test.js +0 -166
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Provider } from "react-redux";
|
|
3
|
-
import { IntlProvider } from "react-intl";
|
|
4
|
-
import FullSwitch, { Switch, Wrapper, ContainedCheckbox, Caption } from "./Switch";
|
|
5
|
-
|
|
6
|
-
describe("Switch", () => {
|
|
7
|
-
it("renders a switch in the on position", () =>
|
|
8
|
-
expect(
|
|
9
|
-
<Switch value={true} onChange={() => {}} />,
|
|
10
|
-
"when mounted",
|
|
11
|
-
"to satisfy",
|
|
12
|
-
<Wrapper value={true}>
|
|
13
|
-
<ContainedCheckbox checked={true} onChange={() => {}} />
|
|
14
|
-
</Wrapper>,
|
|
15
|
-
));
|
|
16
|
-
|
|
17
|
-
it("renders a switch in the off position", () =>
|
|
18
|
-
expect(
|
|
19
|
-
<Switch value={false} onChange={() => {}} />,
|
|
20
|
-
"when mounted",
|
|
21
|
-
"to satisfy",
|
|
22
|
-
<Wrapper value={false}>
|
|
23
|
-
<ContainedCheckbox checked={false} onChange={() => {}} />
|
|
24
|
-
</Wrapper>,
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
it("renders captions on the switch", () =>
|
|
28
|
-
expect(
|
|
29
|
-
<Provider
|
|
30
|
-
store={{
|
|
31
|
-
subscribe: () => {},
|
|
32
|
-
dispatch: () => {},
|
|
33
|
-
getState: () => ({}),
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
<IntlProvider locale="en">
|
|
37
|
-
<Switch
|
|
38
|
-
value={true}
|
|
39
|
-
onChange={() => {}}
|
|
40
|
-
onCaption={{ id: "foo", defaultMessage: "Foo!" }}
|
|
41
|
-
offCaption={{ id: "bar", defaultMessage: "Bar!" }}
|
|
42
|
-
/>
|
|
43
|
-
</IntlProvider>
|
|
44
|
-
</Provider>,
|
|
45
|
-
"when mounted",
|
|
46
|
-
"to satisfy",
|
|
47
|
-
<Wrapper value={true}>
|
|
48
|
-
<ContainedCheckbox checked onChange={() => {}} />
|
|
49
|
-
<Caption value={true}>Foo!</Caption>
|
|
50
|
-
<Caption value={false}>Bar!</Caption>
|
|
51
|
-
</Wrapper>,
|
|
52
|
-
));
|
|
53
|
-
|
|
54
|
-
it("sets onChange handler on the checkbox", () => {
|
|
55
|
-
const onChange = () => {};
|
|
56
|
-
return expect(
|
|
57
|
-
<Switch onChange={onChange} />,
|
|
58
|
-
"when mounted",
|
|
59
|
-
"to contain",
|
|
60
|
-
<ContainedCheckbox onChange={onChange} />,
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("with id handling", () => {
|
|
65
|
-
it("passes through a given id", () =>
|
|
66
|
-
expect(
|
|
67
|
-
<FullSwitch onChange={() => {}} value={true} id="fixedID" />,
|
|
68
|
-
"when mounted",
|
|
69
|
-
"queried for first",
|
|
70
|
-
"input",
|
|
71
|
-
"to have attributes",
|
|
72
|
-
{ id: "fixedID" },
|
|
73
|
-
));
|
|
74
|
-
|
|
75
|
-
it("sets an id if none given", () =>
|
|
76
|
-
expect(
|
|
77
|
-
<FullSwitch onChange={() => {}} value={true} />,
|
|
78
|
-
"when mounted",
|
|
79
|
-
"queried for first",
|
|
80
|
-
"input",
|
|
81
|
-
"to have attributes",
|
|
82
|
-
{ id: expect.it("to match", /^switch\d+$/) },
|
|
83
|
-
));
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe("Wrapper", () => {
|
|
88
|
-
it("sets active colors when on", () =>
|
|
89
|
-
expect(
|
|
90
|
-
<Wrapper value={true} />,
|
|
91
|
-
"when mounted",
|
|
92
|
-
"to have style rules satisfying",
|
|
93
|
-
expect.it("to match", /\scolor: #ffffff;.*::after/).and("to match", /\sbackground-color: #ff0000;.*::after/),
|
|
94
|
-
));
|
|
95
|
-
|
|
96
|
-
it("sets background color according to theme when on", () =>
|
|
97
|
-
expect(
|
|
98
|
-
<Wrapper value={true} theme={{ colors: { application: { base: "#990099" } } }} />,
|
|
99
|
-
"when mounted",
|
|
100
|
-
"to have style rules satisfying",
|
|
101
|
-
"to match",
|
|
102
|
-
/\sbackground-color: #990099;.*::after/,
|
|
103
|
-
));
|
|
104
|
-
|
|
105
|
-
it("sets custom background color when on", () =>
|
|
106
|
-
expect(
|
|
107
|
-
<Wrapper value={true} onColor="#ff00ff" />,
|
|
108
|
-
"when mounted",
|
|
109
|
-
"to have style rules satisfying",
|
|
110
|
-
"to match",
|
|
111
|
-
/\sbackground-color: #ff00ff;.*::after/,
|
|
112
|
-
));
|
|
113
|
-
|
|
114
|
-
it("sets inactive colors when off", () =>
|
|
115
|
-
expect(
|
|
116
|
-
<Wrapper value={false} />,
|
|
117
|
-
"when mounted",
|
|
118
|
-
"to have style rules satisfying",
|
|
119
|
-
expect.it("to match", /\scolor: #333333;.*::after/).and("to match", /\sbackground-color: #cccccc;.*::after/),
|
|
120
|
-
));
|
|
121
|
-
|
|
122
|
-
it("sets custom background color when off", () =>
|
|
123
|
-
expect(
|
|
124
|
-
<Wrapper value={false} offColor="#00cc00" />,
|
|
125
|
-
"when mounted",
|
|
126
|
-
"to have style rules satisfying",
|
|
127
|
-
"to match",
|
|
128
|
-
/\sbackground-color: #00cc00;.*::after/,
|
|
129
|
-
));
|
|
130
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import Text, { Placeholder } from "./Text";
|
|
3
|
-
import { createMuiTheme, TestWrapper } from "../utils/testUtils";
|
|
4
|
-
|
|
5
|
-
const theme = createMuiTheme();
|
|
6
|
-
|
|
7
|
-
describe("Text", () => {
|
|
8
|
-
let state, store;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
state = { dataVal: { foo: 3 } };
|
|
11
|
-
store = {
|
|
12
|
-
subscribe: () => {},
|
|
13
|
-
dispatch: () => {},
|
|
14
|
-
getState: () => state,
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("renders a simple message", () =>
|
|
19
|
-
expect(
|
|
20
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
21
|
-
<Text message="Test message" />
|
|
22
|
-
</TestWrapper>,
|
|
23
|
-
"when mounted",
|
|
24
|
-
"to satisfy",
|
|
25
|
-
"Test message",
|
|
26
|
-
));
|
|
27
|
-
|
|
28
|
-
it("renders an empty string", () =>
|
|
29
|
-
expect(
|
|
30
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
31
|
-
<Text message="" />
|
|
32
|
-
</TestWrapper>,
|
|
33
|
-
"when mounted",
|
|
34
|
-
"to satisfy",
|
|
35
|
-
"",
|
|
36
|
-
));
|
|
37
|
-
|
|
38
|
-
it("renders a translated message", () =>
|
|
39
|
-
expect(
|
|
40
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
41
|
-
<Text message={{ id: "test.msg", defaultMessage: "Test message" }} />
|
|
42
|
-
</TestWrapper>,
|
|
43
|
-
"when mounted",
|
|
44
|
-
"to satisfy",
|
|
45
|
-
"Test message",
|
|
46
|
-
));
|
|
47
|
-
|
|
48
|
-
it("renders a translated message with values", () =>
|
|
49
|
-
expect(
|
|
50
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
51
|
-
<Text
|
|
52
|
-
message={{
|
|
53
|
-
id: "test.msg",
|
|
54
|
-
defaultMessage: "Test message {foo}",
|
|
55
|
-
values: { foo: 3 },
|
|
56
|
-
}}
|
|
57
|
-
/>
|
|
58
|
-
</TestWrapper>,
|
|
59
|
-
"when mounted",
|
|
60
|
-
"to satisfy",
|
|
61
|
-
"Test message 3",
|
|
62
|
-
));
|
|
63
|
-
|
|
64
|
-
it("renders a translated message with a value selector", () =>
|
|
65
|
-
expect(
|
|
66
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
67
|
-
<Text
|
|
68
|
-
message={{
|
|
69
|
-
id: "test.msg",
|
|
70
|
-
defaultMessage: "Test message {foo}",
|
|
71
|
-
values: state => state.dataVal,
|
|
72
|
-
}}
|
|
73
|
-
/>
|
|
74
|
-
</TestWrapper>,
|
|
75
|
-
"when mounted",
|
|
76
|
-
"to satisfy",
|
|
77
|
-
"Test message 3",
|
|
78
|
-
));
|
|
79
|
-
|
|
80
|
-
it("renders a translated message missing its values as a placeholder", () =>
|
|
81
|
-
expect(
|
|
82
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
83
|
-
<Text
|
|
84
|
-
message={{
|
|
85
|
-
id: "test.msg",
|
|
86
|
-
defaultMessage: "Test message {foo}",
|
|
87
|
-
}}
|
|
88
|
-
/>
|
|
89
|
-
</TestWrapper>,
|
|
90
|
-
"when mounted",
|
|
91
|
-
"to satisfy",
|
|
92
|
-
<Placeholder />,
|
|
93
|
-
));
|
|
94
|
-
|
|
95
|
-
it("renders an error", () =>
|
|
96
|
-
expect(
|
|
97
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
98
|
-
<Text message="Test message" error={{ message: "This failed" }} />
|
|
99
|
-
</TestWrapper>,
|
|
100
|
-
"when mounted",
|
|
101
|
-
"to satisfy",
|
|
102
|
-
<span
|
|
103
|
-
style={{
|
|
104
|
-
color: "red",
|
|
105
|
-
backgroundColor: "white",
|
|
106
|
-
fontWeight: "bold",
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
{"Errored: "}
|
|
110
|
-
{"This failed"}
|
|
111
|
-
</span>,
|
|
112
|
-
));
|
|
113
|
-
|
|
114
|
-
it("renders an error if no message given", () =>
|
|
115
|
-
expect(
|
|
116
|
-
<TestWrapper provider={{ store }} intlProvider memoryRouter stylesProvider muiThemeProvider={{ theme }}>
|
|
117
|
-
<Text />
|
|
118
|
-
</TestWrapper>,
|
|
119
|
-
"when mounted",
|
|
120
|
-
"to satisfy",
|
|
121
|
-
<span
|
|
122
|
-
style={{
|
|
123
|
-
color: "red",
|
|
124
|
-
backgroundColor: "white",
|
|
125
|
-
fontWeight: "bold",
|
|
126
|
-
}}
|
|
127
|
-
>
|
|
128
|
-
{"Errored: "}
|
|
129
|
-
{"No message provided"}
|
|
130
|
-
</span>,
|
|
131
|
-
));
|
|
132
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import pt from "prop-types";
|
|
3
|
-
import styled from "styled-components";
|
|
4
|
-
import { getThemeProp } from "../utils";
|
|
5
|
-
import IconButton from "./IconButton";
|
|
6
|
-
import Input from "./Input";
|
|
7
|
-
import Text, { ptLabel } from "./Text";
|
|
8
|
-
import Radio from "./MaterialUI/Inputs/Radio";
|
|
9
|
-
import RadioProps from "./MaterialUI/Inputs/RadioProps";
|
|
10
|
-
|
|
11
|
-
export const Bar = styled.div`
|
|
12
|
-
flex: 0 0 auto;
|
|
13
|
-
min-height: 64px;
|
|
14
|
-
border-bottom: 1px solid ${getThemeProp(["colors", "borderLight"], "#cccccc")};
|
|
15
|
-
display: flex;
|
|
16
|
-
align-items: center;
|
|
17
|
-
padding: 5px 24px;
|
|
18
|
-
box-sizing: border-box;
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
export const ToolGroup = styled.div`
|
|
22
|
-
flex: 0 0 auto;
|
|
23
|
-
display: flex;
|
|
24
|
-
|
|
25
|
-
& > *:not(:last-child) {
|
|
26
|
-
margin-right: -1px;
|
|
27
|
-
border-top-right-radius: 0;
|
|
28
|
-
border-bottom-right-radius: 0;
|
|
29
|
-
}
|
|
30
|
-
& > *:not(:first-child) {
|
|
31
|
-
margin-left: 0;
|
|
32
|
-
border-top-left-radius: 0;
|
|
33
|
-
border-bottom-left-radius: 0;
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
export const ToolbarButton = styled(IconButton)`
|
|
38
|
-
flex: 0 0 auto;
|
|
39
|
-
margin: 0 5px;
|
|
40
|
-
min-width: auto;
|
|
41
|
-
|
|
42
|
-
&:focus,
|
|
43
|
-
&:hover {
|
|
44
|
-
z-index: 10;
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
export const ToolbarInput = styled(Input)`
|
|
49
|
-
height: 30px;
|
|
50
|
-
flex: 0 0 auto;
|
|
51
|
-
margin: 0 5px;
|
|
52
|
-
|
|
53
|
-
&:focus {
|
|
54
|
-
z-index: 10;
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
export const ToolbarRadioWrapper = styled.div`
|
|
59
|
-
min-width: 250px;
|
|
60
|
-
padding-left: 10px;
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
export const ToolbarRadio = styled(Radio)`
|
|
64
|
-
height: 30px;
|
|
65
|
-
flex: 0 0 auto;
|
|
66
|
-
margin: 0 5px;
|
|
67
|
-
|
|
68
|
-
&:focus {
|
|
69
|
-
z-index: 10;
|
|
70
|
-
}
|
|
71
|
-
`;
|
|
72
|
-
|
|
73
|
-
export const Separator = styled.div`
|
|
74
|
-
flex: 0 0 1px;
|
|
75
|
-
height: 30px;
|
|
76
|
-
margin: 0 16px;
|
|
77
|
-
background-color: ${getThemeProp(["colors", "borderLight"], "#cccccc")};
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
export const Spacer = styled.div`
|
|
81
|
-
flex: 100%;
|
|
82
|
-
`;
|
|
83
|
-
|
|
84
|
-
export const ToolbarLabel = styled.div`
|
|
85
|
-
font-family: ${getThemeProp(["fonts", "base"], "sans-serif")};
|
|
86
|
-
font-size: 14px;
|
|
87
|
-
color: ${getThemeProp(["colors", "application", "base"], "#999999")};
|
|
88
|
-
`;
|
|
89
|
-
|
|
90
|
-
// Define the dictionary so we can use it below
|
|
91
|
-
export const toolComponents = {};
|
|
92
|
-
|
|
93
|
-
// Turns a tool definition into a rendered React element
|
|
94
|
-
const renderToolComponent = ({ key, type, subType, ...props }) => {
|
|
95
|
-
const Comp = toolComponents[type];
|
|
96
|
-
return <Comp key={key} type={subType} {...props} />;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Fill in the tool types
|
|
100
|
-
toolComponents.input = ToolbarInput;
|
|
101
|
-
toolComponents.input.displayName = "ToolInput";
|
|
102
|
-
|
|
103
|
-
toolComponents.button = ({ label = {}, ...props }) => <ToolbarButton {...props} icon={label.icon} label={label.text} />;
|
|
104
|
-
toolComponents.button.displayName = "ToolButton";
|
|
105
|
-
|
|
106
|
-
toolComponents.radio = props => {
|
|
107
|
-
const radioProps = new RadioProps();
|
|
108
|
-
|
|
109
|
-
radioProps.set(RadioProps.propNames.name, props?.name);
|
|
110
|
-
radioProps.set(RadioProps.propNames.label, props?.label);
|
|
111
|
-
radioProps.set(RadioProps.propNames.defaultVal, props?.defaultVal);
|
|
112
|
-
radioProps.set(RadioProps.propNames.value, props?.value);
|
|
113
|
-
radioProps.set(RadioProps.propNames.update, props?.update);
|
|
114
|
-
radioProps.set(RadioProps.propNames.radios, props?.radios);
|
|
115
|
-
radioProps.set(RadioProps.propNames.row, props?.row);
|
|
116
|
-
radioProps.set(RadioProps.propNames.error, props?.error);
|
|
117
|
-
return (
|
|
118
|
-
<ToolbarRadioWrapper>
|
|
119
|
-
<ToolbarRadio radioProps={radioProps} />
|
|
120
|
-
</ToolbarRadioWrapper>
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
toolComponents.radio.displayName = "ToolRadio";
|
|
124
|
-
|
|
125
|
-
toolComponents.group = ({ tools }) => <ToolGroup>{tools.map(renderToolComponent)}</ToolGroup>;
|
|
126
|
-
toolComponents.group.displayName = "ToolGroup";
|
|
127
|
-
|
|
128
|
-
toolComponents.spacer = () => <Spacer />;
|
|
129
|
-
toolComponents.spacer.displayName = "ToolSpacer";
|
|
130
|
-
|
|
131
|
-
toolComponents.separator = () => <Separator />;
|
|
132
|
-
toolComponents.separator.displayName = "ToolSeparator";
|
|
133
|
-
|
|
134
|
-
export const Toolbar = ({ tools }) => <Bar>{tools.map(renderToolComponent)}</Bar>;
|
|
135
|
-
|
|
136
|
-
toolComponents.label = ({ label }) => (
|
|
137
|
-
<ToolbarLabel>
|
|
138
|
-
<Text message={label} />
|
|
139
|
-
</ToolbarLabel>
|
|
140
|
-
);
|
|
141
|
-
toolComponents.label.displayName = "ToolLabel";
|
|
142
|
-
|
|
143
|
-
// These tools are allowed inside tool groups
|
|
144
|
-
const ptTool = pt.oneOfType([
|
|
145
|
-
pt.shape({
|
|
146
|
-
type: pt.oneOf(["input"]).isRequired,
|
|
147
|
-
}),
|
|
148
|
-
pt.shape({
|
|
149
|
-
type: pt.oneOf(["radio"]).isRequired,
|
|
150
|
-
}),
|
|
151
|
-
pt.shape({
|
|
152
|
-
type: pt.oneOf(["button"]).isRequired,
|
|
153
|
-
label: pt.oneOfType([
|
|
154
|
-
pt.shape({ icon: pt.string.isRequired, text: ptLabel }),
|
|
155
|
-
pt.shape({ icon: pt.string, text: ptLabel.isRequired }),
|
|
156
|
-
]).isRequired,
|
|
157
|
-
}),
|
|
158
|
-
]);
|
|
159
|
-
|
|
160
|
-
// These tools are only allowed outside groups
|
|
161
|
-
const ptToolWithGroup = pt.oneOfType([
|
|
162
|
-
ptTool,
|
|
163
|
-
pt.shape({
|
|
164
|
-
type: pt.oneOf(["label"]).isRequired,
|
|
165
|
-
label: ptLabel.isRequired,
|
|
166
|
-
}),
|
|
167
|
-
pt.shape({ type: pt.oneOf(["separator", "spacer"]).isRequired }),
|
|
168
|
-
pt.shape({
|
|
169
|
-
type: pt.oneOf(["group"]).isRequired,
|
|
170
|
-
tools: pt.arrayOf(ptTool),
|
|
171
|
-
}),
|
|
172
|
-
]);
|
|
173
|
-
|
|
174
|
-
Toolbar.propTypes = {
|
|
175
|
-
tools: pt.arrayOf(ptToolWithGroup).isRequired,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export default Toolbar;
|