orc-shared 5.10.2-dev.4 → 5.99.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/components/AppFrame/About.js +13 -13
  2. package/dist/components/AppFrame/Anchor.js +7 -7
  3. package/dist/components/AppFrame/AppFrame.js +3 -3
  4. package/dist/components/AppFrame/Help.js +4 -4
  5. package/dist/components/AppFrame/MenuItem.js +17 -26
  6. package/dist/components/AppFrame/Preferences.js +14 -14
  7. package/dist/components/AppFrame/Sidebar.js +6 -6
  8. package/dist/components/AppFrame/Topbar.js +6 -6
  9. package/dist/components/ApplicationModuleLoader.js +3 -2
  10. package/dist/components/Authenticate.js +29 -22
  11. package/dist/components/DropMenu/Menu.js +9 -9
  12. package/dist/components/ErrorPlaceholder.js +8 -24
  13. package/dist/components/Form/Field.js +4 -4
  14. package/dist/components/Form/Inputs/Button.js +2 -2
  15. package/dist/components/{IconButton.js → Form/Inputs/MultiSelector.js} +33 -31
  16. package/dist/components/Form/Inputs/index.js +1 -1
  17. package/dist/components/InternetExplorerWarningMessage.js +15 -15
  18. package/dist/components/LoadingIcon.js +38 -17
  19. package/dist/components/MaterialUI/DataDisplay/Modal.js +3 -3
  20. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  21. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +4 -4
  22. package/dist/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  23. package/dist/components/MaterialUI/DataDisplay/Table.js +2 -1
  24. package/dist/components/MaterialUI/DataDisplay/TableProps.js +3 -1
  25. package/dist/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  26. package/dist/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  27. package/dist/components/MaterialUI/Inputs/DatePicker.js +1 -1
  28. package/dist/components/MaterialUI/Inputs/InputBase.js +20 -188
  29. package/dist/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  30. package/dist/components/MaterialUI/Inputs/Select.js +10 -0
  31. package/dist/components/MaterialUI/Inputs/SelectProps.js +3 -1
  32. package/dist/components/MaterialUI/Inputs/Switch.js +1 -1
  33. package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
  34. package/dist/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -1
  35. package/dist/components/MaterialUI/ScopeSelector/TreeItem.js +27 -42
  36. package/dist/components/MaterialUI/Surfaces/Paper.js +1 -1
  37. package/dist/components/MaterialUI/Surfaces/SectionExpansionPanel.js +3 -2
  38. package/dist/components/MaterialUI/muiThemes.js +2 -0
  39. package/dist/components/Provision.js +30 -13
  40. package/dist/components/Routing/SegmentPage.js +115 -56
  41. package/dist/components/Scope/ScopeNode.js +62 -57
  42. package/dist/components/Sidepanel.js +59 -23
  43. package/dist/components/Spritesheet.js +35 -17
  44. package/dist/components/Text.js +1 -60
  45. package/dist/components/ToastList.js +95 -64
  46. package/dist/components/Treeview/Branch.js +82 -20
  47. package/dist/components/Treeview/Label.js +108 -31
  48. package/dist/components/Treeview/Leaf.js +56 -12
  49. package/dist/components/Treeview/Node.js +22 -9
  50. package/dist/components/Treeview/index.js +7 -1
  51. package/dist/components/Treeview/settings.js +17 -6
  52. package/dist/utils/index.js +0 -4
  53. package/dist/utils/testUtils.js +1 -12
  54. package/dist/{components/Modal/Background.js → utils/toastHelper.js} +11 -14
  55. package/package.json +2 -2
  56. package/src/components/AppFrame/About.js +13 -13
  57. package/src/components/AppFrame/Anchor.js +7 -7
  58. package/src/components/AppFrame/AppFrame.js +3 -3
  59. package/src/components/AppFrame/Help.js +4 -4
  60. package/src/components/AppFrame/MenuItem.js +15 -23
  61. package/src/components/AppFrame/Preferences.js +14 -14
  62. package/src/components/AppFrame/Sidebar.js +6 -6
  63. package/src/components/AppFrame/Topbar.js +6 -6
  64. package/src/components/ApplicationModuleLoader.js +2 -2
  65. package/src/components/ApplicationModuleLoader.test.js +15 -28
  66. package/src/components/Authenticate.js +21 -23
  67. package/src/components/Authenticate.test.js +19 -27
  68. package/src/components/DropMenu/Menu.js +9 -9
  69. package/src/components/ErrorPlaceholder.js +4 -21
  70. package/src/components/ErrorPlaceholder.test.js +7 -14
  71. package/src/components/Form/Field.js +4 -4
  72. package/src/components/Form/InputField.test.js +2 -1
  73. package/src/components/Form/Inputs/Button.js +2 -2
  74. package/src/components/Form/Inputs/MultiSelector.js +23 -0
  75. package/src/components/Form/Inputs/MultiSelector.test.js +112 -0
  76. package/src/components/Form/Inputs/index.js +1 -1
  77. package/src/components/InternetExplorerWarningMessage.js +15 -15
  78. package/src/components/Loader.test.js +50 -59
  79. package/src/components/LoadingIcon.js +27 -14
  80. package/src/components/LoadingIcon.test.js +11 -15
  81. package/src/components/MaterialUI/DataDisplay/Modal.js +3 -3
  82. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  83. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +3 -3
  84. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.test.js +0 -74
  85. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.test.js +6 -18
  86. package/src/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  87. package/src/components/MaterialUI/DataDisplay/Table.js +6 -1
  88. package/src/components/MaterialUI/DataDisplay/Table.test.js +21 -1
  89. package/src/components/MaterialUI/DataDisplay/TableProps.js +2 -0
  90. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +20 -2
  91. package/src/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  92. package/src/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  93. package/src/components/MaterialUI/Inputs/DatePicker.js +1 -1
  94. package/src/components/MaterialUI/Inputs/InputBase.js +31 -214
  95. package/src/components/MaterialUI/Inputs/InputBase.test.js +1 -460
  96. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  97. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.test.js +1 -1
  98. package/src/components/MaterialUI/Inputs/Select.js +7 -0
  99. package/src/components/MaterialUI/Inputs/Select.test.js +45 -0
  100. package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
  101. package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
  102. package/src/components/MaterialUI/Inputs/Switch.js +1 -1
  103. package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
  104. package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
  105. package/src/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -2
  106. package/src/components/MaterialUI/ScopeSelector/TreeItem.js +8 -31
  107. package/src/components/MaterialUI/Surfaces/Paper.js +1 -1
  108. package/src/components/MaterialUI/Surfaces/SectionExpansionPanel.js +2 -1
  109. package/src/components/MaterialUI/muiThemes.js +3 -0
  110. package/src/components/Navigation/Navigation.test.js +0 -5
  111. package/src/components/Navigation/useNavigationState.test.js +79 -222
  112. package/src/components/Provision.js +36 -42
  113. package/src/components/Provision.test.js +10 -26
  114. package/src/components/Routing/SegmentPage.js +68 -52
  115. package/src/components/Routing/SegmentPage.test.js +4 -12
  116. package/src/components/Scope/ScopeNode.js +44 -55
  117. package/src/components/Scope/ScopeNode.test.js +84 -163
  118. package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
  119. package/src/components/Sidepanel.js +38 -32
  120. package/src/components/Sidepanel.test.js +54 -27
  121. package/src/components/Spritesheet.js +23 -21
  122. package/src/components/Spritesheet.test.js +10 -10
  123. package/src/components/Text.js +0 -49
  124. package/src/components/ToastList.js +79 -90
  125. package/src/components/ToastList.test.js +29 -103
  126. package/src/components/Treeview/Branch.js +65 -47
  127. package/src/components/Treeview/Branch.test.js +2 -43
  128. package/src/components/Treeview/Label.js +68 -54
  129. package/src/components/Treeview/Label.test.js +55 -63
  130. package/src/components/Treeview/Leaf.js +41 -22
  131. package/src/components/Treeview/Leaf.test.js +1 -15
  132. package/src/components/Treeview/Node.js +16 -9
  133. package/src/components/Treeview/Node.test.js +269 -200
  134. package/src/components/Treeview/Treeview.test.js +248 -248
  135. package/src/components/Treeview/index.js +6 -0
  136. package/src/components/Treeview/settings.js +10 -6
  137. package/src/utils/index.js +0 -4
  138. package/src/utils/testUtils.js +0 -10
  139. package/src/utils/testUtils.test.js +0 -68
  140. package/src/utils/toastHelper.js +8 -0
  141. package/src/utils/toastHelper.test.js +41 -0
  142. package/dist/components/Button.js +0 -70
  143. package/dist/components/CategoryList.js +0 -197
  144. package/dist/components/Checkbox.js +0 -103
  145. package/dist/components/Icon.js +0 -69
  146. package/dist/components/Input.js +0 -101
  147. package/dist/components/List/DataCell.js +0 -129
  148. package/dist/components/List/HeadCell.js +0 -125
  149. package/dist/components/List/HeadRow.js +0 -73
  150. package/dist/components/List/List.js +0 -274
  151. package/dist/components/List/Row.js +0 -109
  152. package/dist/components/List/enhanceColumnDefs.js +0 -111
  153. package/dist/components/List/index.js +0 -59
  154. package/dist/components/Modal/Dialog.js +0 -75
  155. package/dist/components/Modal/Wrapper.js +0 -69
  156. package/dist/components/Modal/index.js +0 -86
  157. package/dist/components/MultiSelector.js +0 -187
  158. package/dist/components/Navigation/Bar.js +0 -293
  159. package/dist/components/Navigation/Tab.js +0 -182
  160. package/dist/components/Placeholder.js +0 -114
  161. package/dist/components/Scope/Selector.js +0 -123
  162. package/dist/components/Selector.js +0 -185
  163. package/dist/components/Switch.js +0 -128
  164. package/dist/components/Toolbar.js +0 -227
  165. package/dist/components/Tooltip.js +0 -66
  166. package/dist/getTheme.js +0 -158
  167. package/dist/getThemeOverrides.js +0 -93
  168. package/dist/hocs/withAuthentication.js +0 -72
  169. package/dist/utils/styledPropFuncs.js +0 -88
  170. package/src/components/Button.js +0 -90
  171. package/src/components/Button.test.js +0 -49
  172. package/src/components/CategoryList.js +0 -140
  173. package/src/components/CategoryList.test.js +0 -667
  174. package/src/components/Checkbox.js +0 -63
  175. package/src/components/Checkbox.test.js +0 -122
  176. package/src/components/Icon.js +0 -18
  177. package/src/components/IconButton.js +0 -30
  178. package/src/components/IconButton.test.js +0 -61
  179. package/src/components/Input.js +0 -35
  180. package/src/components/Input.test.js +0 -34
  181. package/src/components/List/DataCell.js +0 -77
  182. package/src/components/List/DataCell.test.js +0 -357
  183. package/src/components/List/HeadCell.js +0 -105
  184. package/src/components/List/HeadCell.test.js +0 -331
  185. package/src/components/List/HeadRow.js +0 -21
  186. package/src/components/List/HeadRow.test.js +0 -27
  187. package/src/components/List/List.js +0 -162
  188. package/src/components/List/List.test.js +0 -705
  189. package/src/components/List/Row.js +0 -72
  190. package/src/components/List/Row.test.js +0 -194
  191. package/src/components/List/enhanceColumnDefs.js +0 -54
  192. package/src/components/List/enhanceColumnDefs.test.js +0 -179
  193. package/src/components/List/index.js +0 -6
  194. package/src/components/Modal/Background.js +0 -10
  195. package/src/components/Modal/Dialog.js +0 -27
  196. package/src/components/Modal/Dialog.test.js +0 -20
  197. package/src/components/Modal/Modal.test.js +0 -52
  198. package/src/components/Modal/Wrapper.js +0 -32
  199. package/src/components/Modal/Wrapper.test.js +0 -55
  200. package/src/components/Modal/index.js +0 -22
  201. package/src/components/MultiSelector.js +0 -104
  202. package/src/components/MultiSelector.test.js +0 -348
  203. package/src/components/Navigation/Bar.js +0 -212
  204. package/src/components/Navigation/Bar.test.js +0 -552
  205. package/src/components/Navigation/Tab.js +0 -156
  206. package/src/components/Navigation/Tab.test.js +0 -404
  207. package/src/components/Placeholder.js +0 -61
  208. package/src/components/Placeholder.test.js +0 -106
  209. package/src/components/Scope/Selector.js +0 -70
  210. package/src/components/Scope/Selector.test.js +0 -138
  211. package/src/components/Selector.js +0 -191
  212. package/src/components/Selector.test.js +0 -157
  213. package/src/components/Switch.js +0 -112
  214. package/src/components/Switch.test.js +0 -130
  215. package/src/components/Text.test.js +0 -132
  216. package/src/components/Toolbar.js +0 -178
  217. package/src/components/Toolbar.test.js +0 -478
  218. package/src/components/Tooltip.js +0 -51
  219. package/src/components/Tooltip.test.js +0 -21
  220. package/src/getTheme.js +0 -103
  221. package/src/getTheme.test.js +0 -92
  222. package/src/getThemeOverrides.js +0 -27
  223. package/src/hocs/withAuthentication.js +0 -18
  224. package/src/hocs/withAuthentication.test.js +0 -120
  225. package/src/utils/styledPropFuncs.js +0 -20
  226. package/src/utils/styledPropFuncs.test.js +0 -166
@@ -1,138 +0,0 @@
1
- import React from "react";
2
- import Immutable from "immutable";
3
- import { Provider } from "react-redux";
4
- import { MemoryRouter } from "react-router-dom";
5
- import { IntlProvider } from "react-intl";
6
- import { Selector, Wrapper, SearchInput, InputBox } from "./Selector";
7
- import { Wrapper as BranchWrapper } from "../Treeview/Branch";
8
- import { Root } from "../Treeview/Leaf";
9
- import { Label } from "../Treeview/Label";
10
- import { ScopeIcon, ContentLabel, ScopeText } from "./ScopeNode";
11
-
12
- describe("Selector", () => {
13
- let props, modalRoot, state, store, nodes;
14
- beforeEach(() => {
15
- nodes = {
16
- Global: {
17
- id: "Global",
18
- name: "Global",
19
- type: "test",
20
- childrenIds: ["Foo", "Bar"],
21
- },
22
- Foo: { id: "Foo", name: "Foo", type: "test" },
23
- Bar: { id: "Bar", name: "Bar", type: "test" },
24
- };
25
- modalRoot = document.createElement("div");
26
- modalRoot.id = "modal";
27
- document.body.appendChild(modalRoot);
28
- props = {
29
- id: "Global",
30
- show: true,
31
- reset: () => {},
32
- intl: { formatMessage: msg => msg.defaultMessage },
33
- getScope: id => nodes[id],
34
- defaultNodeState: { foo: true, bar: true },
35
- filter: "",
36
- updateFilter: () => {},
37
- filterPlaceholder: { defaultMessage: "Type a scope name" },
38
- };
39
- state = Immutable.fromJS({
40
- view: {},
41
- navigation: {
42
- route: {
43
- match: {
44
- path: "/:scope/Bar",
45
- params: { scope: "Foo" },
46
- },
47
- },
48
- },
49
- router: {},
50
- });
51
- store = { subscribe: () => {}, dispatch: () => {}, getState: () => state };
52
- });
53
- afterEach(() => {
54
- document.body.removeChild(modalRoot);
55
- });
56
-
57
- it("shows a side panel with search and tree with a current node", () => {
58
- props.currentScope = nodes["Global"];
59
- expect(
60
- <Provider store={store}>
61
- <MemoryRouter>
62
- <IntlProvider locale="en">
63
- <Selector {...props} />
64
- </IntlProvider>
65
- </MemoryRouter>
66
- </Provider>,
67
- "when mounted",
68
- "to satisfy",
69
- null,
70
- ).then(() =>
71
- expect(
72
- modalRoot,
73
- "to satisfy",
74
- <div>
75
- <div>
76
- <Wrapper>
77
- <InputBox>
78
- <IntlProvider locale="en">
79
- <SearchInput />
80
- </IntlProvider>
81
- </InputBox>
82
- <BranchWrapper>
83
- <Root>
84
- <Label isSelectedNode={true}>
85
- <ContentLabel id="selectorNodeGlobal">
86
- <ScopeIcon type="test" />
87
- <ScopeText>Global</ScopeText>
88
- </ContentLabel>
89
- </Label>
90
- </Root>
91
- </BranchWrapper>
92
- </Wrapper>
93
- </div>
94
- </div>,
95
- ),
96
- );
97
- });
98
-
99
- it("shows a side panel with search and tree", () =>
100
- expect(
101
- <Provider store={store}>
102
- <MemoryRouter>
103
- <IntlProvider locale="en">
104
- <Selector {...props} />
105
- </IntlProvider>
106
- </MemoryRouter>
107
- </Provider>,
108
- "when mounted",
109
- "to satisfy",
110
- null,
111
- ).then(() =>
112
- expect(
113
- modalRoot,
114
- "to satisfy",
115
- <div>
116
- <div>
117
- <Wrapper>
118
- <InputBox>
119
- <IntlProvider locale="en">
120
- <SearchInput />
121
- </IntlProvider>
122
- </InputBox>
123
- <BranchWrapper>
124
- <Root>
125
- <Label>
126
- <ContentLabel id="selectorNodeGlobal">
127
- <ScopeIcon type="test" />
128
- <ScopeText>Global</ScopeText>
129
- </ContentLabel>
130
- </Label>
131
- </Root>
132
- </BranchWrapper>
133
- </Wrapper>
134
- </div>
135
- </div>,
136
- ),
137
- ));
138
- });
@@ -1,191 +0,0 @@
1
- import React, { useCallback, useState } from "react";
2
- import styled, { css } from "styled-components";
3
- import { getThemeProp, ifFlag, memoize } from "../utils";
4
- import withId from "../hocs/withId";
5
- import ClickAwayListener from "@material-ui/core/ClickAwayListener";
6
-
7
- export const InnerSelect = styled.select`
8
- position: absolute;
9
- opacity: 0;
10
- font-size: 0;
11
- height: 0;
12
- width: 0;
13
- border: 0 none transparent;
14
- z-index: -1;
15
- transform: translateX(-99px);
16
- `;
17
-
18
- export const Wrapper = styled.div`
19
- position: relative;
20
- cursor: pointer;
21
- font-size: 12px;
22
- max-width: 700px;
23
- `;
24
-
25
- export const SelectBox = styled.label`
26
- position: relative;
27
- box-sizing: border-box;
28
- display: block;
29
- min-height: 30px;
30
- max-height: 70px;
31
- overflow: hidden;
32
- padding: 5px 10px;
33
- border: 1px solid ${getThemeProp(["colors", "borderLight"], "#cccccc")};
34
- border-radius: 4px;
35
- background-color: white;
36
-
37
- &::before {
38
- content: " ";
39
- position: absolute;
40
- top: 0;
41
- bottom: 0;
42
- right: 0;
43
- left: 0;
44
- box-shadow: 0 -10px 5px -5px inset white;
45
- }
46
-
47
- &::after {
48
- content: "ˇ";
49
- font-family: courier, monospace;
50
- font-size: 32px;
51
- position: absolute;
52
- right: 10px;
53
- top: 6px;
54
- }
55
-
56
- ${InnerSelect}:focus + & {
57
- border-color: #4fa1f0;
58
- box-shadow: 0 0 4px #4fa1f0;
59
- }
60
-
61
- ${InnerSelect}:focus + &::after {
62
- transform: rotate(0.5turn);
63
- transform-origin: center 8px;
64
- }
65
-
66
- ${InnerSelect}:invalid + & {
67
- border-color: ${getThemeProp(["colors", "error"], "#ce4844")};
68
- box-shadow: 0 0 4px ${getThemeProp(["colors", "error"], "#ce4844")};
69
- }
70
- `;
71
-
72
- export const SelectedValue = styled.span`
73
- display: inline-block;
74
- width: calc(100% - 20px);
75
- white-space: pre;
76
- overflow: hidden;
77
- `;
78
-
79
- export const Dropdown = styled.div`
80
- box-sizing: border-box;
81
- position: absolute;
82
- left: 0;
83
- top: calc(100% + 1px);
84
- z-index: 1;
85
- border: 1px solid ${getThemeProp(["colors", "borderLight"], "#cccccc")};
86
- border-radius: 4px;
87
- padding: 4px 0;
88
- width: 100%;
89
- max-height: 40vh;
90
- overflow-y: auto;
91
- background-color: white;
92
- opacity: 0;
93
- visibility: hidden;
94
- ${/* Enables click handling on Options while closing dropdown */ ""};
95
- transition: visibility 0.4s step-end;
96
-
97
- ${props => {
98
- /* istanbul ignore next */
99
- if (props.isVisible) {
100
- return `${InnerSelect} + ${SelectBox} + & {
101
- opacity: 1;
102
- visibility: visible;
103
- transition: visibility 0s step-end;
104
- }`;
105
- }
106
- }}
107
- `;
108
-
109
- export const Option = styled.div`
110
- box-sizing: border-box;
111
- height: 30px;
112
- padding: 6px 12px;
113
- white-space: pre;
114
- ${ifFlag(
115
- "active",
116
- css`
117
- background-color: #f0f0f0;
118
- `,
119
- )};
120
-
121
- &:hover {
122
- background-color: ${getThemeProp(["colors", "application", "base"], "#ccc")};
123
- color: #ffffff;
124
- }
125
- `;
126
-
127
- export const Placeholder = styled.span`
128
- color: rgb(117, 117, 117);
129
- `;
130
-
131
- export const Selector = ({ id, value, options, update, placeholder = "", required, ...props }) => {
132
- // eslint-disable-next-line react-hooks/exhaustive-deps
133
- const clickOption = useCallback(
134
- memoize(value => () => {
135
- update(value);
136
- setIsVisible(false);
137
- }),
138
- [update],
139
- );
140
- console.warn("Selector component has been deprecated in favor of Material-UI wrapper component Select");
141
- const onChange = useCallback(e => update(e.target.value), [update]);
142
- const [isVisible, setIsVisible] = useState(false);
143
- /* istanbul ignore next */
144
- const toggleVisibility = () => {
145
- setIsVisible(!isVisible);
146
- };
147
-
148
- /* istanbul ignore next */
149
- const handlerClickAway = () => {
150
- setIsVisible(false);
151
- };
152
-
153
- /* istanbul ignore next */
154
- return (
155
- <ClickAwayListener onClickAway={() => handlerClickAway()}>
156
- <Wrapper>
157
- <InnerSelect id={id} onChange={onChange} value={value} required={required} {...props}>
158
- {required ? <option></option> : null}
159
- {options.map(option => (
160
- <option key={option.value} value={option.value}>
161
- {option.label}
162
- </option>
163
- ))}
164
- </InnerSelect>
165
- <SelectBox htmlFor={id} onClick={() => toggleVisibility()}>
166
- {value ? (
167
- <SelectedValue>
168
- {options.filter(option => option.value === value).map(option => option.label)[0]}
169
- </SelectedValue>
170
- ) : (
171
- <Placeholder>{placeholder}</Placeholder>
172
- )}
173
- </SelectBox>
174
- <Dropdown isVisible={isVisible}>
175
- {options.map(option => (
176
- <Option
177
- key={option.value}
178
- active={option.value === value}
179
- onClick={clickOption(option.value)}
180
- data-test-id={option.value}
181
- >
182
- {option.label}
183
- </Option>
184
- ))}
185
- </Dropdown>
186
- </Wrapper>
187
- </ClickAwayListener>
188
- );
189
- };
190
-
191
- export default withId("selector")(Selector);
@@ -1,157 +0,0 @@
1
- import React from "react";
2
- import sinon from "sinon";
3
- import { Ignore } from "unexpected-reaction";
4
- import Selector, { InnerSelect, Wrapper, SelectBox, SelectedValue, Dropdown, Option, Placeholder } from "./Selector";
5
-
6
- describe("Selector", () => {
7
- let updater;
8
- beforeEach(() => {
9
- updater = sinon.spy().named("updater");
10
- });
11
-
12
- it("renders a wrapped, hidden select element, and visual cover elements", () =>
13
- expect(
14
- <Selector
15
- id="test"
16
- update={updater}
17
- options={[
18
- { value: "1", label: "Opt 1" },
19
- { value: "2", label: "Opt 2" },
20
- { value: "3", label: "Opt 3" },
21
- { value: "4", label: "Opt 4" },
22
- ]}
23
- value="3"
24
- />,
25
- "when mounted",
26
- "to satisfy",
27
- <Wrapper>
28
- <InnerSelect id="test" value="3" onChange={() => {}}>
29
- <option key="1" value="1">
30
- Opt 1
31
- </option>
32
- <option key="2" value="2">
33
- Opt 2
34
- </option>
35
- <option key="3" value="3">
36
- Opt 3
37
- </option>
38
- <option key="4" value="4">
39
- Opt 4
40
- </option>
41
- </InnerSelect>
42
- <SelectBox htmlFor="test">
43
- <SelectedValue>Opt 3</SelectedValue>
44
- </SelectBox>
45
- <Dropdown>
46
- <Option key="1">Opt 1</Option>
47
- <Option key="2">Opt 2</Option>
48
- <Option key="3" active>
49
- Opt 3
50
- </Option>
51
- <Option key="4">Opt 4</Option>
52
- </Dropdown>
53
- </Wrapper>,
54
- ));
55
-
56
- it("renders a wrapped, hidden select element, and visual cover elements", () =>
57
- expect(
58
- <Selector
59
- id="test"
60
- update={updater}
61
- options={[
62
- { value: "1", label: "Opt 1" },
63
- { value: "2", label: "Opt 2" },
64
- { value: "3", label: "Opt 3" },
65
- { value: "4", label: "Opt 4" },
66
- ]}
67
- value=""
68
- required
69
- />,
70
- "when mounted",
71
- "to satisfy",
72
- <Wrapper>
73
- <InnerSelect id="test" required onChange={() => {}}>
74
- <option></option>
75
- <option key="1" value="1">
76
- Opt 1
77
- </option>
78
- <option key="2" value="2">
79
- Opt 2
80
- </option>
81
- <option key="3" value="3">
82
- Opt 3
83
- </option>
84
- <option key="4" value="4">
85
- Opt 4
86
- </option>
87
- </InnerSelect>
88
- <SelectBox htmlFor="test">
89
- <Placeholder />
90
- </SelectBox>
91
- <Dropdown>
92
- <Option key="1">Opt 1</Option>
93
- <Option key="2">Opt 2</Option>
94
- <Option key="3">Opt 3</Option>
95
- <Option key="4">Opt 4</Option>
96
- </Dropdown>
97
- </Wrapper>,
98
- ));
99
-
100
- it("renders a placeholder if no value set", () =>
101
- expect(
102
- <Selector
103
- id="test"
104
- placeholder="This space for rent"
105
- update={updater}
106
- options={[
107
- { value: "1", label: "Opt 1" },
108
- { value: "2", label: "Opt 2" },
109
- { value: "3", label: "Opt 3" },
110
- { value: "4", label: "Opt 4" },
111
- ]}
112
- />,
113
- "when mounted",
114
- "to satisfy",
115
- <Wrapper>
116
- <Ignore />
117
- <SelectBox htmlFor="test">
118
- <Placeholder>This space for rent</Placeholder>
119
- </SelectBox>
120
- <Ignore />
121
- </Wrapper>,
122
- ));
123
-
124
- it("can update value when inner selector changes", () =>
125
- expect(
126
- <Selector
127
- update={updater}
128
- options={[
129
- { value: "1", label: "Opt 1" },
130
- { value: "2", label: "Opt 2" },
131
- { value: "3", label: "Opt 3" },
132
- { value: "4", label: "Opt 4" },
133
- ]}
134
- value="3"
135
- />,
136
- "when mounted",
137
- "with event",
138
- { type: "change", target: "select", value: "2" },
139
- ).then(() => expect(updater, "to have calls satisfying", [{ args: ["2"] }])));
140
-
141
- it("can update value when clicking a visual option", () =>
142
- expect(
143
- <Selector
144
- update={updater}
145
- options={[
146
- { value: "1", label: "Opt 1" },
147
- { value: "2", label: "Opt 2" },
148
- { value: "3", label: "Opt 3" },
149
- { value: "4", label: "Opt 4" },
150
- ]}
151
- value="3"
152
- />,
153
- "when mounted",
154
- "with event",
155
- { type: "click", target: '[data-test-id="1"]' },
156
- ).then(() => expect(updater, "to have calls satisfying", [{ args: ["1"] }])));
157
- });
@@ -1,112 +0,0 @@
1
- import React from "react";
2
- import styled, { css } from "styled-components";
3
- import Text from "./Text";
4
- import { getThemeProp, ifFlag } from "../utils";
5
- import withId from "../hocs/withId";
6
-
7
- const switchSpeed = 200;
8
- const FilteredLabel = ({ onColor, offColor, onCaption, offCaption, ...props }) => <label {...props} />;
9
-
10
- export const Wrapper = styled(FilteredLabel)`
11
- display: inline-block;
12
- position: relative;
13
- height: 1.2em;
14
- width: 5em;
15
- border-radius: 0.6em;
16
- display: flex;
17
- cursor: pointer;
18
- ${ifFlag(
19
- "value",
20
- css`
21
- color: #ffffff;
22
- background-color: ${ifFlag(
23
- "onColor",
24
- props => props.onColor,
25
- getThemeProp(["colors", "application", "base"], "#ff0000"),
26
- )};
27
- `,
28
- css`
29
- color: ${getThemeProp(["colors", "text"], "#333333")};
30
- background-color: ${ifFlag(
31
- "offColor",
32
- props => props.offColor,
33
- getThemeProp(["colors", "borderLight"], "#cccccc"),
34
- )};
35
- `,
36
- )};
37
- transition: background-color ${switchSpeed}ms ease-in, color ${switchSpeed}ms ease-in;
38
-
39
- &::after {
40
- content: "";
41
- position: absolute;
42
- top: 2px;
43
- height: calc(1.2em - 4px);
44
- left: calc(50% - (0.5 * (1.2em - 4px)));
45
- width: calc(1.2em - 4px);
46
- background-color: #ffffff;
47
- border-radius: 50%;
48
- transition: transform ${switchSpeed}ms ease-in;
49
-
50
- ${ifFlag(
51
- "value",
52
- css`
53
- transform: translateX(-1.9em);
54
- `,
55
- css`
56
- transform: translateX(1.9em);
57
- `,
58
- )};
59
- }
60
-
61
- &:focus-within,
62
- &:hover {
63
- box-shadow: 0 0 4px #4fa1f0;
64
- }
65
- `;
66
-
67
- export const Caption = styled.span`
68
- position: absolute;
69
- left: 1.4em;
70
- right: 1.4em;
71
- overflow: hidden;
72
- white-space: nowrap;
73
- text-overflow: ellipsis;
74
- text-align: center;
75
- font-size: 0.8em;
76
- ${ifFlag(
77
- "value",
78
- css`
79
- opacity: 1;
80
- transition: opacity ${0.7 * switchSpeed}ms ${0.3 * switchSpeed}ms ease-in;
81
- `,
82
- css`
83
- opacity: 0;
84
- transition: opacity ${0.7 * switchSpeed}ms ease-in;
85
- `,
86
- )};
87
- `;
88
-
89
- export const ContainedCheckbox = styled.input.attrs(() => ({
90
- type: "checkbox",
91
- }))`
92
- position: absolute;
93
- opacity: 0;
94
- `;
95
-
96
- export const Switch = ({ value, onCaption, offCaption, onColor, offColor, id, ...checkboxProps }) => (
97
- <Wrapper htmlFor={id} value={value} onColor={onColor} offColor={offColor}>
98
- <ContainedCheckbox id={id} {...checkboxProps} checked={value} />
99
- {onCaption ? (
100
- <Caption value={value}>
101
- <Text message={onCaption} />
102
- </Caption>
103
- ) : null}
104
- {offCaption ? (
105
- <Caption value={!value}>
106
- <Text message={offCaption} />
107
- </Caption>
108
- ) : null}
109
- </Wrapper>
110
- );
111
-
112
- export default withId("switch")(Switch);