orc-shared 5.10.2-dev.1 → 5.99.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/components/AppFrame/MenuItem.js +3 -12
  2. package/dist/components/ApplicationModuleLoader.js +3 -2
  3. package/dist/components/Authenticate.js +29 -22
  4. package/dist/components/ErrorPlaceholder.js +8 -24
  5. package/dist/components/{IconButton.js → Form/Inputs/MultiSelector.js} +33 -31
  6. package/dist/components/Form/Inputs/index.js +1 -1
  7. package/dist/components/LoadingIcon.js +38 -17
  8. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +3 -3
  9. package/dist/components/MaterialUI/DataDisplay/Table.js +2 -1
  10. package/dist/components/MaterialUI/DataDisplay/TableProps.js +3 -1
  11. package/dist/components/MaterialUI/Inputs/Select.js +10 -0
  12. package/dist/components/MaterialUI/Inputs/SelectProps.js +3 -1
  13. package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
  14. package/dist/components/MaterialUI/Surfaces/SectionExpansionPanel.js +3 -2
  15. package/dist/components/MaterialUI/muiThemes.js +2 -0
  16. package/dist/components/Provision.js +30 -13
  17. package/dist/components/Routing/SegmentPage.js +115 -56
  18. package/dist/components/Scope/ScopeNode.js +64 -57
  19. package/dist/components/Sidepanel.js +57 -23
  20. package/dist/components/Spritesheet.js +33 -17
  21. package/dist/components/Text.js +1 -60
  22. package/dist/components/ToastList.js +95 -64
  23. package/dist/components/Treeview/Branch.js +82 -20
  24. package/dist/components/Treeview/Label.js +108 -31
  25. package/dist/components/Treeview/Leaf.js +56 -12
  26. package/dist/components/Treeview/Node.js +22 -9
  27. package/dist/components/Treeview/index.js +7 -1
  28. package/dist/components/Treeview/settings.js +7 -5
  29. package/dist/utils/index.js +0 -4
  30. package/dist/utils/testUtils.js +1 -12
  31. package/dist/{components/Modal/Background.js → utils/toastHelper.js} +11 -14
  32. package/package.json +2 -2
  33. package/src/components/AppFrame/MenuItem.js +1 -9
  34. package/src/components/ApplicationModuleLoader.js +2 -2
  35. package/src/components/ApplicationModuleLoader.test.js +15 -28
  36. package/src/components/Authenticate.js +21 -23
  37. package/src/components/Authenticate.test.js +19 -27
  38. package/src/components/ErrorPlaceholder.js +4 -21
  39. package/src/components/ErrorPlaceholder.test.js +7 -14
  40. package/src/components/Form/InputField.test.js +2 -1
  41. package/src/components/Form/Inputs/MultiSelector.js +23 -0
  42. package/src/components/Form/Inputs/MultiSelector.test.js +112 -0
  43. package/src/components/Form/Inputs/index.js +1 -1
  44. package/src/components/Loader.test.js +50 -59
  45. package/src/components/LoadingIcon.js +27 -14
  46. package/src/components/LoadingIcon.test.js +11 -15
  47. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +2 -2
  48. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.test.js +0 -74
  49. package/src/components/MaterialUI/DataDisplay/Table.js +6 -1
  50. package/src/components/MaterialUI/DataDisplay/Table.test.js +21 -1
  51. package/src/components/MaterialUI/DataDisplay/TableProps.js +2 -0
  52. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +20 -2
  53. package/src/components/MaterialUI/Inputs/Select.js +7 -0
  54. package/src/components/MaterialUI/Inputs/Select.test.js +45 -0
  55. package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
  56. package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
  57. package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
  58. package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
  59. package/src/components/MaterialUI/Surfaces/SectionExpansionPanel.js +2 -1
  60. package/src/components/MaterialUI/muiThemes.js +3 -0
  61. package/src/components/Navigation/Navigation.test.js +0 -5
  62. package/src/components/Navigation/useNavigationState.test.js +79 -222
  63. package/src/components/Provision.js +36 -42
  64. package/src/components/Provision.test.js +10 -26
  65. package/src/components/Routing/SegmentPage.js +68 -52
  66. package/src/components/Routing/SegmentPage.test.js +4 -12
  67. package/src/components/Scope/ScopeNode.js +45 -55
  68. package/src/components/Scope/ScopeNode.test.js +84 -163
  69. package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
  70. package/src/components/Sidepanel.js +38 -32
  71. package/src/components/Sidepanel.test.js +49 -27
  72. package/src/components/Spritesheet.js +23 -21
  73. package/src/components/Spritesheet.test.js +10 -10
  74. package/src/components/Text.js +0 -49
  75. package/src/components/ToastList.js +79 -90
  76. package/src/components/ToastList.test.js +29 -103
  77. package/src/components/Treeview/Branch.js +63 -45
  78. package/src/components/Treeview/Branch.test.js +21 -24
  79. package/src/components/Treeview/Label.js +66 -52
  80. package/src/components/Treeview/Label.test.js +42 -60
  81. package/src/components/Treeview/Leaf.js +41 -22
  82. package/src/components/Treeview/Leaf.test.js +15 -10
  83. package/src/components/Treeview/Node.js +16 -9
  84. package/src/components/Treeview/Node.test.js +269 -200
  85. package/src/components/Treeview/Treeview.test.js +248 -248
  86. package/src/components/Treeview/index.js +6 -0
  87. package/src/components/Treeview/settings.js +7 -6
  88. package/src/utils/index.js +0 -4
  89. package/src/utils/testUtils.js +0 -10
  90. package/src/utils/testUtils.test.js +0 -68
  91. package/src/utils/toastHelper.js +8 -0
  92. package/src/utils/toastHelper.test.js +41 -0
  93. package/dist/components/Button.js +0 -70
  94. package/dist/components/CategoryList.js +0 -197
  95. package/dist/components/Checkbox.js +0 -103
  96. package/dist/components/Icon.js +0 -69
  97. package/dist/components/Input.js +0 -101
  98. package/dist/components/List/DataCell.js +0 -129
  99. package/dist/components/List/HeadCell.js +0 -125
  100. package/dist/components/List/HeadRow.js +0 -73
  101. package/dist/components/List/List.js +0 -274
  102. package/dist/components/List/Row.js +0 -109
  103. package/dist/components/List/enhanceColumnDefs.js +0 -111
  104. package/dist/components/List/index.js +0 -59
  105. package/dist/components/Modal/Dialog.js +0 -75
  106. package/dist/components/Modal/Wrapper.js +0 -69
  107. package/dist/components/Modal/index.js +0 -86
  108. package/dist/components/MultiSelector.js +0 -187
  109. package/dist/components/Navigation/Bar.js +0 -293
  110. package/dist/components/Navigation/Tab.js +0 -182
  111. package/dist/components/Placeholder.js +0 -114
  112. package/dist/components/Scope/Selector.js +0 -123
  113. package/dist/components/Selector.js +0 -185
  114. package/dist/components/Switch.js +0 -128
  115. package/dist/components/Toolbar.js +0 -227
  116. package/dist/components/Tooltip.js +0 -66
  117. package/dist/getTheme.js +0 -158
  118. package/dist/getThemeOverrides.js +0 -93
  119. package/dist/hocs/withAuthentication.js +0 -72
  120. package/dist/utils/styledPropFuncs.js +0 -88
  121. package/src/components/Button.js +0 -90
  122. package/src/components/Button.test.js +0 -49
  123. package/src/components/CategoryList.js +0 -140
  124. package/src/components/CategoryList.test.js +0 -667
  125. package/src/components/Checkbox.js +0 -63
  126. package/src/components/Checkbox.test.js +0 -122
  127. package/src/components/Icon.js +0 -18
  128. package/src/components/IconButton.js +0 -30
  129. package/src/components/IconButton.test.js +0 -61
  130. package/src/components/Input.js +0 -35
  131. package/src/components/Input.test.js +0 -34
  132. package/src/components/List/DataCell.js +0 -77
  133. package/src/components/List/DataCell.test.js +0 -357
  134. package/src/components/List/HeadCell.js +0 -105
  135. package/src/components/List/HeadCell.test.js +0 -331
  136. package/src/components/List/HeadRow.js +0 -21
  137. package/src/components/List/HeadRow.test.js +0 -27
  138. package/src/components/List/List.js +0 -162
  139. package/src/components/List/List.test.js +0 -705
  140. package/src/components/List/Row.js +0 -72
  141. package/src/components/List/Row.test.js +0 -194
  142. package/src/components/List/enhanceColumnDefs.js +0 -54
  143. package/src/components/List/enhanceColumnDefs.test.js +0 -179
  144. package/src/components/List/index.js +0 -6
  145. package/src/components/Modal/Background.js +0 -10
  146. package/src/components/Modal/Dialog.js +0 -27
  147. package/src/components/Modal/Dialog.test.js +0 -20
  148. package/src/components/Modal/Modal.test.js +0 -52
  149. package/src/components/Modal/Wrapper.js +0 -32
  150. package/src/components/Modal/Wrapper.test.js +0 -55
  151. package/src/components/Modal/index.js +0 -22
  152. package/src/components/MultiSelector.js +0 -104
  153. package/src/components/MultiSelector.test.js +0 -348
  154. package/src/components/Navigation/Bar.js +0 -212
  155. package/src/components/Navigation/Bar.test.js +0 -552
  156. package/src/components/Navigation/Tab.js +0 -156
  157. package/src/components/Navigation/Tab.test.js +0 -404
  158. package/src/components/Placeholder.js +0 -61
  159. package/src/components/Placeholder.test.js +0 -106
  160. package/src/components/Scope/Selector.js +0 -70
  161. package/src/components/Scope/Selector.test.js +0 -138
  162. package/src/components/Selector.js +0 -191
  163. package/src/components/Selector.test.js +0 -157
  164. package/src/components/Switch.js +0 -112
  165. package/src/components/Switch.test.js +0 -130
  166. package/src/components/Text.test.js +0 -132
  167. package/src/components/Toolbar.js +0 -178
  168. package/src/components/Toolbar.test.js +0 -478
  169. package/src/components/Tooltip.js +0 -51
  170. package/src/components/Tooltip.test.js +0 -21
  171. package/src/getTheme.js +0 -103
  172. package/src/getTheme.test.js +0 -92
  173. package/src/getThemeOverrides.js +0 -27
  174. package/src/hocs/withAuthentication.js +0 -18
  175. package/src/hocs/withAuthentication.test.js +0 -120
  176. package/src/utils/styledPropFuncs.js +0 -20
  177. 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);