orc-shared 5.10.1-dev.8 → 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.
Files changed (133) hide show
  1. package/dist/components/Authenticate.js +41 -17
  2. package/dist/components/ErrorPlaceholder.js +8 -24
  3. package/dist/components/{Icon.js → Form/Inputs/MultiSelector.js} +33 -20
  4. package/dist/components/Form/Inputs/index.js +1 -1
  5. package/dist/components/LoadingIcon.js +6 -16
  6. package/dist/components/MaterialUI/Inputs/Select.js +10 -0
  7. package/dist/components/MaterialUI/Inputs/SelectProps.js +3 -1
  8. package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
  9. package/dist/components/Provision.js +30 -13
  10. package/dist/components/Routing/SegmentPage.js +115 -56
  11. package/dist/components/Scope/ScopeNode.js +68 -45
  12. package/dist/components/Sidepanel.js +57 -23
  13. package/dist/components/Spritesheet.js +33 -17
  14. package/dist/components/Text.js +1 -60
  15. package/dist/components/Treeview/Branch.js +82 -20
  16. package/dist/components/Treeview/Label.js +108 -31
  17. package/dist/components/Treeview/Leaf.js +56 -12
  18. package/dist/components/Treeview/Node.js +22 -9
  19. package/dist/components/Treeview/index.js +7 -1
  20. package/dist/components/Treeview/settings.js +7 -5
  21. package/dist/utils/index.js +0 -4
  22. package/dist/utils/testUtils.js +1 -12
  23. package/package.json +1 -1
  24. package/src/components/ApplicationModuleLoader.test.js +14 -27
  25. package/src/components/Authenticate.js +29 -21
  26. package/src/components/Authenticate.test.js +18 -27
  27. package/src/components/ErrorPlaceholder.js +4 -21
  28. package/src/components/ErrorPlaceholder.test.js +7 -14
  29. package/src/components/Form/InputField.test.js +2 -1
  30. package/src/components/Form/Inputs/MultiSelector.js +23 -0
  31. package/src/components/Form/Inputs/MultiSelector.test.js +112 -0
  32. package/src/components/Form/Inputs/index.js +1 -1
  33. package/src/components/Loader.test.js +21 -33
  34. package/src/components/LoadingIcon.js +2 -15
  35. package/src/components/LoadingIcon.test.js +2 -20
  36. package/src/components/MaterialUI/DataDisplay/Table.test.js +1 -1
  37. package/src/components/MaterialUI/Inputs/Select.js +7 -0
  38. package/src/components/MaterialUI/Inputs/Select.test.js +45 -0
  39. package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
  40. package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
  41. package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
  42. package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
  43. package/src/components/Navigation/Navigation.test.js +0 -5
  44. package/src/components/Navigation/useNavigationState.test.js +79 -222
  45. package/src/components/Provision.js +36 -42
  46. package/src/components/Provision.test.js +10 -26
  47. package/src/components/Routing/SegmentPage.js +68 -52
  48. package/src/components/Routing/SegmentPage.test.js +4 -12
  49. package/src/components/Scope/ScopeNode.js +61 -54
  50. package/src/components/Scope/ScopeNode.test.js +61 -154
  51. package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
  52. package/src/components/Sidepanel.js +38 -32
  53. package/src/components/Sidepanel.test.js +49 -27
  54. package/src/components/Spritesheet.js +23 -21
  55. package/src/components/Spritesheet.test.js +10 -10
  56. package/src/components/Text.js +0 -49
  57. package/src/components/Treeview/Branch.js +63 -45
  58. package/src/components/Treeview/Branch.test.js +21 -24
  59. package/src/components/Treeview/Label.js +66 -52
  60. package/src/components/Treeview/Label.test.js +42 -60
  61. package/src/components/Treeview/Leaf.js +41 -22
  62. package/src/components/Treeview/Leaf.test.js +15 -10
  63. package/src/components/Treeview/Node.js +16 -9
  64. package/src/components/Treeview/Node.test.js +269 -200
  65. package/src/components/Treeview/Treeview.test.js +248 -248
  66. package/src/components/Treeview/index.js +6 -0
  67. package/src/components/Treeview/settings.js +7 -6
  68. package/src/utils/index.js +0 -4
  69. package/src/utils/testUtils.js +0 -10
  70. package/src/utils/testUtils.test.js +0 -68
  71. package/dist/components/Button.js +0 -70
  72. package/dist/components/Checkbox.js +0 -103
  73. package/dist/components/IconButton.js +0 -80
  74. package/dist/components/Input.js +0 -101
  75. package/dist/components/Modal/Background.js +0 -55
  76. package/dist/components/Modal/Dialog.js +0 -75
  77. package/dist/components/Modal/Wrapper.js +0 -69
  78. package/dist/components/Modal/index.js +0 -86
  79. package/dist/components/MultiSelector.js +0 -187
  80. package/dist/components/Navigation/Bar.js +0 -293
  81. package/dist/components/Navigation/Tab.js +0 -182
  82. package/dist/components/Placeholder.js +0 -114
  83. package/dist/components/Scope/Selector.js +0 -123
  84. package/dist/components/Selector.js +0 -185
  85. package/dist/components/Switch.js +0 -128
  86. package/dist/components/Toolbar.js +0 -227
  87. package/dist/components/Tooltip.js +0 -66
  88. package/dist/getTheme.js +0 -153
  89. package/dist/getThemeOverrides.js +0 -93
  90. package/dist/hocs/withAuthentication.js +0 -72
  91. package/dist/utils/styledPropFuncs.js +0 -88
  92. package/src/components/Button.js +0 -90
  93. package/src/components/Button.test.js +0 -49
  94. package/src/components/Checkbox.js +0 -63
  95. package/src/components/Checkbox.test.js +0 -122
  96. package/src/components/Icon.js +0 -18
  97. package/src/components/IconButton.js +0 -30
  98. package/src/components/IconButton.test.js +0 -61
  99. package/src/components/Input.js +0 -35
  100. package/src/components/Input.test.js +0 -34
  101. package/src/components/Modal/Background.js +0 -10
  102. package/src/components/Modal/Dialog.js +0 -27
  103. package/src/components/Modal/Dialog.test.js +0 -20
  104. package/src/components/Modal/Modal.test.js +0 -52
  105. package/src/components/Modal/Wrapper.js +0 -32
  106. package/src/components/Modal/Wrapper.test.js +0 -55
  107. package/src/components/Modal/index.js +0 -22
  108. package/src/components/MultiSelector.js +0 -104
  109. package/src/components/MultiSelector.test.js +0 -348
  110. package/src/components/Navigation/Bar.js +0 -212
  111. package/src/components/Navigation/Bar.test.js +0 -552
  112. package/src/components/Navigation/Tab.js +0 -156
  113. package/src/components/Navigation/Tab.test.js +0 -404
  114. package/src/components/Placeholder.js +0 -61
  115. package/src/components/Placeholder.test.js +0 -106
  116. package/src/components/Scope/Selector.js +0 -70
  117. package/src/components/Scope/Selector.test.js +0 -138
  118. package/src/components/Selector.js +0 -191
  119. package/src/components/Selector.test.js +0 -157
  120. package/src/components/Switch.js +0 -112
  121. package/src/components/Switch.test.js +0 -130
  122. package/src/components/Text.test.js +0 -132
  123. package/src/components/Toolbar.js +0 -178
  124. package/src/components/Toolbar.test.js +0 -478
  125. package/src/components/Tooltip.js +0 -51
  126. package/src/components/Tooltip.test.js +0 -21
  127. package/src/getTheme.js +0 -98
  128. package/src/getTheme.test.js +0 -92
  129. package/src/getThemeOverrides.js +0 -27
  130. package/src/hocs/withAuthentication.js +0 -18
  131. package/src/hocs/withAuthentication.test.js +0 -120
  132. package/src/utils/styledPropFuncs.js +0 -20
  133. package/src/utils/styledPropFuncs.test.js +0 -166
@@ -1,47 +1,65 @@
1
- import styled, { css } from "styled-components";
2
- import { ifFlag, getThemeProp } from "../../utils";
1
+ import React from "react";
2
+ import { makeStyles } from "@material-ui/core/styles";
3
3
  import { branchIndent, branchLength, branchHeight } from "./settings";
4
+ import classNames from "classnames";
4
5
 
5
- const baseBranch = css`
6
- margin: 0;
7
- font-size: 13px;
8
- list-style-type: none;
9
- border-width: 0;
10
- border-style: solid;
11
- border-color: #666;
12
- position: relative;
13
- `;
14
-
15
- export const Branch = styled.ul`
16
- ${baseBranch}
17
-
18
- margin-left: ${branchIndent}px;
19
- padding: 0;
20
- padding-left: ${branchLength}px;
21
- border-left-width: 1px;
22
-
23
- &:last-child::after {
24
- /* blocker - hides lowest part of vertical branch */
25
- content: " ";
26
- background-color: ${ifFlag("dark", getThemeProp(["colors", "bgDark"], "#333333"), "#fff")};
27
- position: absolute;
28
- left: -${props => branchIndent(props) + branchLength(props) + 2}px;
29
- bottom: 0;
30
- top: -${branchHeight}px;
31
- width: 1px;
32
- }
33
- `;
34
-
35
- export const Wrapper = styled.ul`
36
- ${baseBranch}
37
-
38
- overflow-y: auto;
39
- overflow-x: hidden;
40
- margin-left: 0;
41
- padding: ${props => branchLength(props) - 5}px;
42
-
43
- & > ${Branch} {
44
- /* First Branch immediately under Wrapper needs margin adjusted to look right */
45
- margin-left: ${props => 1.5 * branchIndent(props)}px;
46
- }
47
- `;
6
+ const useStyles = makeStyles(theme => {
7
+ const base = {
8
+ margin: 0,
9
+ fontSize: "13px",
10
+ listStyleType: "none",
11
+ borderWidth: 0,
12
+ borderStyle: "solid",
13
+ borderColor: "#666",
14
+ position: "relative",
15
+ };
16
+
17
+ return {
18
+ branch: props => ({
19
+ ...base,
20
+ marginLeft: `${branchIndent}px`,
21
+ padding: "0",
22
+ paddingLeft: `${branchLength}px`,
23
+ borderLeftWidth: "1px",
24
+
25
+ "&:last-child::after": {
26
+ /* blocker - hides lowest part of vertical branch */
27
+ content: '""',
28
+ backgroundColor: props.dark ? theme.palette.grey.dark : "#fff",
29
+ position: "absolute",
30
+ left: `-${branchIndent + branchLength + 2}px`,
31
+ bottom: 0,
32
+ top: `-${branchHeight}px`,
33
+ width: "1px",
34
+ },
35
+ }),
36
+ wrapper: {
37
+ ...base,
38
+ overflowY: "auto",
39
+ overflowX: "hidden",
40
+ marginLeft: 0,
41
+ padding: `${branchLength - 5}px`,
42
+
43
+ "& > $branch": {
44
+ /* First Branch immediately under Wrapper needs margin adjusted to look right */
45
+ marginLeft: `${1.5 * branchIndent}px`,
46
+ },
47
+ },
48
+ };
49
+ });
50
+
51
+ export const Branch = ({ dark, branchClassName, children }) => {
52
+ const classes = useStyles({ dark });
53
+
54
+ return (
55
+ <ul className={classNames(classes.branch, branchClassName)} data-qa="branch">
56
+ {children}
57
+ </ul>
58
+ );
59
+ };
60
+
61
+ export const Wrapper = ({ children }) => {
62
+ const classes = useStyles();
63
+
64
+ return <ul className={classes.wrapper}>{children}</ul>;
65
+ };
@@ -1,27 +1,32 @@
1
1
  import React from "react";
2
+ import { createMuiTheme, TestWrapper } from "../../utils/testUtils";
2
3
  import { Branch, Wrapper } from "./Branch";
3
4
 
4
5
  describe("Branch", () => {
6
+ const theme = createMuiTheme();
7
+
5
8
  it("renders a <ul>", () => expect(<Branch />, "when mounted", "to satisfy", <ul />));
6
9
 
7
10
  it("sets styling for showing a branch structure", () =>
8
11
  expect(
9
- <Branch
10
- theme={{
11
- treeSettings: {
12
- branchIndent: 10,
13
- branchLength: 12,
14
- branchHeight: 14,
15
- },
16
- }}
17
- />,
12
+ <Branch />,
18
13
  "when mounted",
19
14
  "to have style rules satisfying",
20
15
  expect
21
- .it("to contain", "margin-left: 10px;")
22
- .and("to contain", "padding-left: 12px;")
23
- .and("to match", /:last-child::after {[^}]*left: -24px;[^}]*}/)
24
- .and("to match", /:last-child::after {[^}]*top: -14px;[^}]*}/),
16
+ .it("to contain", "margin-left: 14px;")
17
+ .and("to contain", "padding-left: 15px;")
18
+ .and("to match", /:last-child::after {[^}]*left: -31px;[^}]*}/)
19
+ .and("to match", /:last-child::after {[^}]*top: -20px;[^}]*}/),
20
+ ));
21
+
22
+ it("sets styling for a dark theme", () =>
23
+ expect(
24
+ <TestWrapper muiThemeProvider={{ theme }}>
25
+ <Branch dark />
26
+ </TestWrapper>,
27
+ "when mounted",
28
+ "to have style rules satisfying",
29
+ expect.it("to match", /:last-child::after {[^}]*background-color: #333;[^}]*}/),
25
30
  ));
26
31
  });
27
32
 
@@ -30,20 +35,12 @@ describe("Wrapper", () => {
30
35
 
31
36
  it("sets styling for showing the root of a tree structure", () =>
32
37
  expect(
33
- <Wrapper
34
- theme={{
35
- treeSettings: {
36
- branchIndent: 10,
37
- branchLength: 12,
38
- branchHeight: 14,
39
- },
40
- }}
41
- />,
38
+ <Wrapper />,
42
39
  "when mounted",
43
40
  "to have style rules satisfying",
44
41
  expect
45
42
  .it("to contain", "margin-left: 0;")
46
- .and("to contain", "padding: 7px;")
47
- .and("to contain", "> ." + Branch.styledComponentId + " {margin-left: 15px;}"),
43
+ .and("to contain", "padding: 10px;")
44
+ .and("to contain", "{margin-left: 21px;}"),
48
45
  ));
49
46
  });
@@ -1,54 +1,68 @@
1
- import styled, { css } from "styled-components";
2
- import Icon from "../Icon";
3
- import { getThemeProp, ifFlag } from "../../utils";
1
+ import React from "react";
2
+ import { makeStyles } from "@material-ui/core/styles";
3
+ import Icon from "../MaterialUI/DataDisplay/Icon";
4
4
  import { branchLength } from "./settings";
5
+ import classNames from "classnames";
5
6
 
6
- export const Indicator = styled(Icon).attrs(props => ({
7
- id: ifFlag(
8
- "open",
9
- getThemeProp(["icons", "indicators", "down"], "chevron-down"),
10
- getThemeProp(["icons", "indicators", "right"], "chevron-right"),
11
- )(props),
12
- }))`
13
- font-size: 10px;
14
- padding: 10px 0 10px 10px;
15
- cursor: pointer;
16
- flex: 0 0 auto;
17
- color: ${ifFlag(
18
- "open",
19
- ifFlag("dark", getThemeProp(["colors", "textLight"], "#cccccc"), getThemeProp(["colors", "text"], "#333333")),
20
- getThemeProp(["colors", "application", "base"], "#ffffff"),
21
- )};
22
- `;
23
-
24
- export const BeforeIndicator = styled.div`
25
- background-color: #666;
26
- margin-left: -${props => branchLength(props) + 1}px;
27
- width: ${props => branchLength(props) + 1}px;
28
- height: 1px;
29
- z-index: 99;
30
- position: absolute;
31
- `;
32
-
33
- export const NonIndicator = styled.div`
34
- height: 1px;
35
- width: ${props => branchLength(props) + 21}px;
36
- margin: auto 0 auto -${props => branchLength(props) + 1}px;
37
- background-color: #666;
38
- align-self: stretch;
39
- flex: 0 0 auto;
40
- z-index: 99;
41
- `;
42
-
43
- export const Label = styled.div`
44
- cursor: pointer;
45
- flex-grow: 1;
46
- width: 100%;
47
- ${ifFlag(
48
- "isSelectedNode",
49
- css`
50
- background-color: #222;
51
- border: 1px solid ${getThemeProp(["colors", "application", "base"], "#0F4E66")};
52
- `,
53
- )};
54
- `;
7
+ const useStyles = makeStyles(theme => ({
8
+ beforeIndicator: {
9
+ backgroundColor: "#666",
10
+ marginLeft: `-${branchLength + 1}px`,
11
+ width: `${branchLength + 1}px`,
12
+ height: "1px",
13
+ zIndex: 99,
14
+ position: "absolute",
15
+ },
16
+ nonIndicator: {
17
+ height: "1px",
18
+ width: `${branchLength + 21}px`,
19
+ margin: `auto 0 auto -${branchLength + 1}px`,
20
+ backgroundColor: "#666",
21
+ alignSelf: "stretch",
22
+ flex: "0 0 auto",
23
+ zIndex: 99,
24
+ },
25
+ label: props => ({
26
+ cursor: "pointer",
27
+ flexGrow: 1,
28
+ width: "100%",
29
+ backgroundColor: props.isSelectedNode ? "#222" : undefined,
30
+ border: props.isSelectedNode ? `1px solid ${theme.palette.grey.borders}` : undefined,
31
+ }),
32
+ indicator: props => ({
33
+ fontSize: "10px",
34
+ padding: "10px 0 10px 10px",
35
+ cursor: "pointer",
36
+ flex: "0 0 auto",
37
+ color: props.open
38
+ ? props.dark
39
+ ? theme.palette.primary.light
40
+ : theme.palette.text.primary
41
+ : theme.palette.primary.main,
42
+ }),
43
+ }));
44
+
45
+ export const BeforeIndicator = ({ children }) => {
46
+ const classes = useStyles();
47
+
48
+ return <div className={classes.beforeIndicator}>{children}</div>;
49
+ };
50
+
51
+ export const NonIndicator = ({ children }) => {
52
+ const classes = useStyles();
53
+
54
+ return <div className={classes.nonIndicator}>{children}</div>;
55
+ };
56
+
57
+ export const Label = ({ isSelectedNode, labelClassName, children }) => {
58
+ const classes = useStyles({ isSelectedNode });
59
+
60
+ return <div className={classNames(classes.label, labelClassName)}>{children}</div>;
61
+ };
62
+
63
+ export const Indicator = ({ open, dark, onClick }) => {
64
+ const classes = useStyles({ open, dark });
65
+ const iconId = open ? "dropdown-chevron-down" : "dropdown-chevron-right";
66
+
67
+ return <Icon id={iconId} className={classes.indicator} onClick={onClick} data-qa="indicator" />;
68
+ };
@@ -1,72 +1,50 @@
1
1
  import React from "react";
2
+ import { MuiThemeProvider } from "@material-ui/core";
2
3
  import { Label, Indicator, BeforeIndicator, NonIndicator } from "./Label";
3
- import Icon from "../Icon";
4
+ import Icon from "../MaterialUI/DataDisplay/Icon";
5
+ import { createMuiTheme } from "../../utils/testUtils";
6
+
7
+ const theme = createMuiTheme();
4
8
 
5
9
  describe("Indicator", () => {
6
10
  it("renders a closed arrow icon", () =>
7
- expect(<Indicator />, "when mounted", "to satisfy", <Icon id="chevron-right" />));
11
+ expect(<Indicator />, "when mounted", "to satisfy", <Icon id="dropdown-chevron-right" />));
8
12
 
9
13
  it("renders an open arrow icon", () =>
10
- expect(<Indicator open />, "when mounted", "to satisfy", <Icon id="chevron-down" />));
14
+ expect(<Indicator open />, "when mounted", "to satisfy", <Icon id="dropdown-chevron-down" />));
11
15
 
12
16
  it("renders closed arrows in highlight color", () =>
13
- expect(<Indicator />, "when mounted", "to have style rules satisfying", "to contain", "color: #ffffff;"));
17
+ expect(
18
+ <MuiThemeProvider theme={theme}>
19
+ <Indicator />
20
+ </MuiThemeProvider>,
21
+ "when mounted",
22
+ "to have style rules satisfying",
23
+ "to contain",
24
+ "color: #333;",
25
+ ));
14
26
 
15
27
  it("renders open arrows in dark grey", () =>
16
- expect(<Indicator open />, "when mounted", "to have style rules satisfying", "to contain", "color: #333333;"));
28
+ expect(
29
+ <MuiThemeProvider theme={theme}>
30
+ <Indicator open />
31
+ </MuiThemeProvider>,
32
+ "when mounted",
33
+ "to have style rules satisfying",
34
+ "to contain",
35
+ "color: #333;",
36
+ ));
17
37
 
18
38
  it("renders open arrows in light grey when dark", () =>
19
- expect(<Indicator open dark />, "when mounted", "to have style rules satisfying", "to contain", "color: #cccccc;"));
20
-
21
- describe("with theme", () => {
22
- let theme;
23
- beforeEach(() => {
24
- theme = {
25
- colors: { application: { base: "red" } },
26
- icons: {
27
- indicators: {
28
- up: "arrow-up",
29
- down: "arrow-down",
30
- right: "arrow-right",
31
- left: "arrow-left",
32
- },
33
- },
34
- };
35
- });
36
-
37
- it("renders a closed arrow icon", () =>
38
- expect(<Indicator theme={theme} />, "when mounted", "to satisfy", <Icon id="arrow-right" />));
39
-
40
- it("renders an open arrow icon", () =>
41
- expect(<Indicator theme={theme} open />, "when mounted", "to satisfy", <Icon id="arrow-down" />));
42
-
43
- it("renders closed arrows in highlight color", () =>
44
- expect(
45
- <Indicator theme={theme} />,
46
- "when mounted",
47
- "to have style rules satisfying",
48
- "to contain",
49
- "color: red;",
50
- ));
51
-
52
- it("renders open arrows in dark grey", () =>
53
- expect(
54
- <Indicator theme={theme} open />,
55
- "when mounted",
56
- "to have style rules satisfying",
57
- "to contain",
58
- "color: #333333;",
59
- ));
60
-
61
- it("renders open arrows in light grey when dark", () =>
62
- expect(
63
- <Indicator theme={theme} open dark />,
64
- "when mounted",
65
- "to have style rules satisfying",
66
- "to contain",
67
- "color: #cccccc;",
68
- ));
69
- });
39
+ expect(
40
+ <MuiThemeProvider theme={theme}>
41
+ <Indicator open dark />
42
+ </MuiThemeProvider>,
43
+ "when mounted",
44
+ "to have style rules satisfying",
45
+ "to contain",
46
+ "color: #CCC;",
47
+ ));
70
48
  });
71
49
 
72
50
  describe("BeforeIndicator", () => {
@@ -90,17 +68,21 @@ describe("Label", () => {
90
68
 
91
69
  it("renders a label without border", () =>
92
70
  expect(
93
- <Label />,
71
+ <MuiThemeProvider theme={theme}>
72
+ <Label />
73
+ </MuiThemeProvider>,
94
74
  "when mounted",
95
75
  "to have style rules satisfying",
96
- expect.it("not to contain", "background-color: #222;").and("not to contain", "border: 1px solid #0F4E66"),
76
+ expect.it("not to contain", "background-color: #222;").and("not to contain", "border: 1px solid #CCC"),
97
77
  ));
98
78
 
99
79
  it("renders a label with border", () =>
100
80
  expect(
101
- <Label isSelectedNode={true} />,
81
+ <MuiThemeProvider theme={theme}>
82
+ <Label isSelectedNode={true} />
83
+ </MuiThemeProvider>,
102
84
  "when mounted",
103
85
  "to have style rules satisfying",
104
- expect.it("to contain", "background-color: #222;").and("to contain", "border: 1px solid #0F4E66"),
86
+ expect.it("to contain", "background-color: #222;").and("to contain", "border: 1px solid #CCC"),
105
87
  ));
106
88
  });
@@ -1,24 +1,43 @@
1
- import styled from "styled-components";
2
- import { ifFlag, getThemeProp } from "../../utils";
3
- import { branchLength, branchHeight } from "./settings";
1
+ import React from "react";
2
+ import { makeStyles } from "@material-ui/core/styles";
3
+ import { branchLength } from "./settings";
4
+ import classNames from "classnames";
4
5
 
5
- export const Root = styled.li`
6
- position: relative;
7
- display: flex;
8
- align-items: center;
9
- `;
6
+ const useStyles = makeStyles(theme => ({
7
+ root: {
8
+ position: "relative",
9
+ display: "flex",
10
+ alignItems: "center",
11
+ },
12
+ leaf: props => ({
13
+ "&:last-child::after": {
14
+ /* blocker - hides lowest part of vertical branch */
15
+ content: '""',
16
+ backgroundColor: props.dark ? theme.palette.grey.dark : "#fff",
17
+ position: "absolute",
18
+ top: "calc(50%)",
19
+ left: `-${branchLength + 1}px`,
20
+ bottom: 0,
21
+ width: "1px",
22
+ height: "50%",
23
+ },
24
+ }),
25
+ }));
10
26
 
11
- export const Leaf = styled(Root)`
12
- &:last-child::after {
13
- /* blocker - hides lowest part of vertical branch */
14
- content: " ";
15
- background-color: ${ifFlag("dark", getThemeProp(["colors", "bgDark"], "#333333"), "#fff")};
16
- position: absolute;
17
- top: calc(50%);
18
- left: -${props => branchLength(props) + 1}px;
19
- bottom: 0;
20
- height: ${branchHeight}px;
21
- width: 1px;
22
- height: 50%;
23
- }
24
- `;
27
+ export const Root = ({ dark, leafClassName, children }) => {
28
+ const classes = useStyles({ dark });
29
+
30
+ return (
31
+ <li className={classNames(classes.root, classes.leaf, leafClassName)} data-qa="leaf">
32
+ {children}
33
+ </li>
34
+ );
35
+ };
36
+
37
+ export const Leaf = ({ dark, leafClassName, children }) => {
38
+ return (
39
+ <Root leafClassName={leafClassName} dark={dark}>
40
+ {children}
41
+ </Root>
42
+ );
43
+ };
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { createMuiTheme, TestWrapper } from "../../utils/testUtils";
2
3
  import { Root, Leaf } from "./Leaf";
3
4
 
4
5
  describe("Root", () => {
@@ -6,21 +7,25 @@ describe("Root", () => {
6
7
  });
7
8
 
8
9
  describe("Leaf", () => {
10
+ const theme = createMuiTheme();
11
+
9
12
  it("renders a <li>", () => expect(<Leaf />, "when mounted", "to satisfy", <li />));
10
13
 
11
14
  it("sets styling for a branch structure", () =>
12
15
  expect(
13
- <Leaf
14
- theme={{
15
- treeSettings: {
16
- branchIndent: 10,
17
- branchLength: 12,
18
- branchHeight: 14,
19
- },
20
- }}
21
- />,
16
+ <Leaf />,
17
+ "when mounted",
18
+ "to have style rules satisfying",
19
+ expect.it("to match", /:last-child::after {[^}]*left: -16px;[^}]*}/),
20
+ ));
21
+
22
+ it("sets styling for a dark theme", () =>
23
+ expect(
24
+ <TestWrapper muiThemeProvider={{ theme }}>
25
+ <Leaf dark />
26
+ </TestWrapper>,
22
27
  "when mounted",
23
28
  "to have style rules satisfying",
24
- expect.it("to match", /:last-child::after {[^}]*left: -13px;[^}]*}/),
29
+ expect.it("to match", /:last-child::after {[^}]*background-color: #333;[^}]*}/),
25
30
  ));
26
31
  });
@@ -6,8 +6,8 @@ import { safeGet, stripKey } from "../../utils";
6
6
 
7
7
  export const TreeContext = React.createContext();
8
8
 
9
- export const LeafNode = ({ dark, isSelectedNode, ...nodeData }) => (
10
- <Leaf dark={dark}>
9
+ export const LeafNode = ({ dark, isSelectedNode, labelClassName, leafClassName, ...nodeData }) => (
10
+ <Leaf dark={dark} leafClassName={leafClassName}>
11
11
  <TreeContext.Consumer>
12
12
  {({ Content, nodeState, updateNodeState, dark, otherProps }) => {
13
13
  const toggle = () => updateNodeState({ ...nodeState, [nodeData.id]: !nodeData.open });
@@ -18,7 +18,7 @@ export const LeafNode = ({ dark, isSelectedNode, ...nodeData }) => (
18
18
  ) : (
19
19
  <NonIndicator />
20
20
  )}
21
- <Label isSelectedNode={isSelectedNode}>
21
+ <Label isSelectedNode={isSelectedNode} labelClassName={labelClassName}>
22
22
  <Content {...stripKey("children", nodeData)} {...otherProps} />
23
23
  </Label>
24
24
  </React.Fragment>
@@ -29,9 +29,9 @@ export const LeafNode = ({ dark, isSelectedNode, ...nodeData }) => (
29
29
  );
30
30
  LeafNode.displayName = "LeafNode";
31
31
 
32
- export const RootNode = ({ isSelectedNode, ...nodeData }) => (
32
+ export const RootNode = ({ isSelectedNode, labelClassName, ...nodeData }) => (
33
33
  <Root>
34
- <Label isSelectedNode={isSelectedNode}>
34
+ <Label isSelectedNode={isSelectedNode} labelClassName={labelClassName}>
35
35
  <TreeContext.Consumer>
36
36
  {({ Content, otherProps }) => <Content {...stripKey("children", nodeData)} {...otherProps} />}
37
37
  </TreeContext.Consumer>
@@ -42,7 +42,7 @@ RootNode.displayName = "RootNode";
42
42
 
43
43
  export const Node = ({ root, id }) => (
44
44
  <TreeContext.Consumer>
45
- {({ openAll, getNode, selectedNodeId, nodeState, dark }) => {
45
+ {({ openAll, getNode, selectedNodeId, nodeState, dark, labelClassName, leafClassName, branchClassName }) => {
46
46
  const nodeData = getNode(id);
47
47
  if (!nodeData) return null;
48
48
  const isSelectedNode = selectedNodeId === id;
@@ -51,12 +51,19 @@ export const Node = ({ root, id }) => (
51
51
  return (
52
52
  <React.Fragment>
53
53
  {root ? (
54
- <RootNode {...nodeData} isSelectedNode={isSelectedNode} />
54
+ <RootNode {...nodeData} isSelectedNode={isSelectedNode} labelClassName={labelClassName} />
55
55
  ) : (
56
- <LeafNode {...nodeData} open={open} dark={dark} isSelectedNode={isSelectedNode} />
56
+ <LeafNode
57
+ {...nodeData}
58
+ open={open}
59
+ dark={dark}
60
+ isSelectedNode={isSelectedNode}
61
+ labelClassName={labelClassName}
62
+ leafClassName={leafClassName}
63
+ />
57
64
  )}
58
65
  {open && safeGet(nodeData, "children", "length") ? (
59
- <Branch dark={dark}>
66
+ <Branch dark={dark} branchClassName={branchClassName}>
60
67
  {nodeData.children.map(id => (
61
68
  <Node key={id} id={id} />
62
69
  ))}