@dhis2-ui/transfer 9.10.3 → 9.11.1-beta.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 (156) hide show
  1. package/build/cjs/__e2e__/{add_remove-highlighted-options.stories.e2e.js → add_remove-highlighted-options.e2e.stories.js} +2 -13
  2. package/build/cjs/__e2e__/common/options.js +2 -3
  3. package/build/cjs/__e2e__/common/stateful-decorator.js +3 -8
  4. package/build/cjs/__e2e__/{disabled-transfer-buttons.stories.e2e.js → disabled-transfer-buttons.e2e.stories.js} +4 -20
  5. package/build/cjs/__e2e__/{disabled-transfer-options.stories.e2e.js → disabled-transfer-options.e2e.stories.js} +4 -12
  6. package/build/cjs/__e2e__/{display-order.stories.e2e.js → display-order.e2e.stories.js} +2 -13
  7. package/build/cjs/__e2e__/{filter-options-list.stories.e2e.js → filter-options-list.e2e.stories.js} +3 -24
  8. package/build/cjs/__e2e__/{highlight-range-of-options.stories.e2e.js → highlight-range-of-options.e2e.stories.js} +2 -15
  9. package/build/cjs/__e2e__/{loading_lists.stories.e2e.js → loading_lists.e2e.stories.js} +2 -16
  10. package/build/cjs/__e2e__/{notify_at_end_of_list.stories.e2e.js → notify_at_end_of_list.e2e.stories.js} +2 -17
  11. package/build/cjs/__e2e__/{reorder-with-buttons.stories.e2e.js → reorder-with-buttons.e2e.stories.js} +2 -11
  12. package/build/cjs/__e2e__/{set_unset-highlighted-option.stories.e2e.js → set_unset-highlighted-option.e2e.stories.js} +2 -13
  13. package/build/cjs/__e2e__/{transferring-items.stories.e2e.js → transferring-items.e2e.stories.js} +2 -13
  14. package/build/cjs/__tests__/common.test.js +0 -1
  15. package/build/cjs/__tests__/helper/add-all-selectable-source-options.test.js +0 -1
  16. package/build/cjs/__tests__/helper/add-individual-source-options.test.js +0 -1
  17. package/build/cjs/__tests__/helper/default-filter-callback.test.js +0 -1
  18. package/build/cjs/__tests__/helper/is-reorder-down-disabled.test.js +0 -1
  19. package/build/cjs/__tests__/helper/is-reorder-up-disabled.test.js +0 -1
  20. package/build/cjs/__tests__/helper/move-highlighted-picked-option-down.test.js +0 -1
  21. package/build/cjs/__tests__/helper/move-highlighted-picked-option-up.test.js +0 -1
  22. package/build/cjs/__tests__/helper/remove-all-picked-options.test.js +0 -1
  23. package/build/cjs/__tests__/helper/remove-individual-picked-options.test.js +0 -1
  24. package/build/cjs/__tests__/helper/use-highlighted-option/create-toggle-highlighted-option.test.js +2 -9
  25. package/build/cjs/__tests__/helper/use-highlighted-option/toggle-add.test.js +0 -1
  26. package/build/cjs/__tests__/helper/use-highlighted-option/toggle-range.test.js +2 -3
  27. package/build/cjs/__tests__/helper/use-highlighted-option/toggle-replace.test.js +0 -1
  28. package/build/cjs/__tests__/helper/use-highlighted-option.test.js +1 -5
  29. package/build/cjs/__tests__/transfer.test.js +1 -5
  30. package/build/cjs/actions.js +2 -9
  31. package/build/cjs/add-all.js +2 -9
  32. package/build/cjs/add-individual.js +2 -9
  33. package/build/cjs/common/find-option-index.js +0 -3
  34. package/build/cjs/common/get-mode-by-modifier-key.js +2 -8
  35. package/build/cjs/common/index.js +0 -6
  36. package/build/cjs/common/is-option.js +0 -2
  37. package/build/cjs/common/modes.js +6 -9
  38. package/build/cjs/common/remove-option.js +0 -6
  39. package/build/cjs/common/styles.js +3 -8
  40. package/build/cjs/common/toggle-value.js +0 -4
  41. package/build/cjs/container.js +2 -8
  42. package/build/cjs/end-intersection-detector.js +1 -8
  43. package/build/cjs/features/add_remove-highlighted-options/index.js +0 -1
  44. package/build/cjs/features/common/index.js +0 -2
  45. package/build/cjs/features/disabled-transfer-buttons/index.js +0 -1
  46. package/build/cjs/features/disabled-transfer-options/index.js +0 -2
  47. package/build/cjs/features/display-order/index.js +6 -5
  48. package/build/cjs/features/filter-options-list/index.js +6 -8
  49. package/build/cjs/features/highlight-range-of-options/index.js +8 -5
  50. package/build/cjs/features/loading_lists/index.js +2 -3
  51. package/build/cjs/features/notify_at_end_of_list/index.js +1 -2
  52. package/build/cjs/features/reorder-with-buttons/index.js +3 -3
  53. package/build/cjs/features/set_unset-highlighted-option/index.js +0 -2
  54. package/build/cjs/features/transferring-items/index.js +6 -6
  55. package/build/cjs/filter.js +5 -14
  56. package/build/cjs/icons.js +17 -35
  57. package/build/cjs/index.js +0 -2
  58. package/build/cjs/left-footer.js +2 -10
  59. package/build/cjs/left-header.js +2 -10
  60. package/build/cjs/left-side.js +2 -9
  61. package/build/cjs/options-container.js +9 -20
  62. package/build/cjs/picked-options.js +2 -10
  63. package/build/cjs/remove-all.js +2 -9
  64. package/build/cjs/remove-individual.js +2 -9
  65. package/build/cjs/reordering-actions.js +7 -16
  66. package/build/cjs/right-footer.js +2 -10
  67. package/build/cjs/right-header.js +2 -10
  68. package/build/cjs/right-side.js +2 -9
  69. package/build/cjs/source-options.js +2 -10
  70. package/build/cjs/transfer/add-all-selectable-source-options.js +3 -4
  71. package/build/cjs/transfer/add-individual-source-options.js +1 -4
  72. package/build/cjs/transfer/create-double-click-handlers.js +0 -5
  73. package/build/cjs/transfer/default-filter-callback.js +0 -2
  74. package/build/cjs/transfer/get-option-click-handlers.js +0 -3
  75. package/build/cjs/transfer/index.js +0 -26
  76. package/build/cjs/transfer/is-reorder-down-disabled.js +4 -4
  77. package/build/cjs/transfer/is-reorder-up-disabled.js +4 -4
  78. package/build/cjs/transfer/move-highlighted-picked-option-down.js +4 -5
  79. package/build/cjs/transfer/move-highlighted-picked-option-up.js +4 -5
  80. package/build/cjs/transfer/remove-all-picked-options.js +0 -2
  81. package/build/cjs/transfer/remove-individual-picked-options.js +1 -4
  82. package/build/cjs/transfer/use-filter.js +0 -4
  83. package/build/cjs/transfer/use-highlighted-options/create-toggle-highlighted-option.js +2 -12
  84. package/build/cjs/transfer/use-highlighted-options/toggle-add.js +0 -3
  85. package/build/cjs/transfer/use-highlighted-options/toggle-range.js +3 -8
  86. package/build/cjs/transfer/use-highlighted-options/toggle-replace.js +0 -4
  87. package/build/cjs/transfer/use-highlighted-options.js +0 -5
  88. package/build/cjs/transfer-option.js +4 -16
  89. package/build/cjs/transfer.js +29 -54
  90. package/build/cjs/{transfer.stories.js → transfer.prod.stories.js} +83 -103
  91. package/build/cjs/use-resize-counter.js +0 -4
  92. package/build/es/__e2e__/common/stateful-decorator.js +1 -2
  93. package/build/es/__e2e__/{disabled-transfer-buttons.stories.e2e.js → disabled-transfer-buttons.e2e.stories.js} +2 -1
  94. package/build/es/__e2e__/{disabled-transfer-options.stories.e2e.js → disabled-transfer-options.e2e.stories.js} +2 -1
  95. package/build/es/__e2e__/{filter-options-list.stories.e2e.js → filter-options-list.e2e.stories.js} +1 -3
  96. package/build/es/__tests__/helper/use-highlighted-option/create-toggle-highlighted-option.test.js +2 -1
  97. package/build/es/__tests__/helper/use-highlighted-option/toggle-range.test.js +2 -2
  98. package/build/es/__tests__/helper/use-highlighted-option.test.js +1 -1
  99. package/build/es/actions.js +1 -1
  100. package/build/es/add-all.js +1 -1
  101. package/build/es/add-individual.js +1 -1
  102. package/build/es/common/find-option-index.js +1 -1
  103. package/build/es/common/get-mode-by-modifier-key.js +3 -6
  104. package/build/es/common/modes.js +5 -4
  105. package/build/es/common/remove-option.js +1 -4
  106. package/build/es/common/toggle-value.js +0 -2
  107. package/build/es/container.js +1 -1
  108. package/build/es/features/display-order/index.js +6 -3
  109. package/build/es/features/filter-options-list/index.js +6 -6
  110. package/build/es/features/highlight-range-of-options/index.js +8 -3
  111. package/build/es/features/loading_lists/index.js +2 -2
  112. package/build/es/features/notify_at_end_of_list/index.js +1 -1
  113. package/build/es/features/reorder-with-buttons/index.js +3 -2
  114. package/build/es/features/transferring-items/index.js +6 -3
  115. package/build/es/filter.js +4 -4
  116. package/build/es/icons.js +16 -16
  117. package/build/es/left-footer.js +1 -1
  118. package/build/es/left-header.js +1 -1
  119. package/build/es/left-side.js +1 -1
  120. package/build/es/options-container.js +6 -5
  121. package/build/es/picked-options.js +1 -1
  122. package/build/es/remove-all.js +1 -1
  123. package/build/es/remove-individual.js +1 -1
  124. package/build/es/reordering-actions.js +6 -6
  125. package/build/es/right-footer.js +1 -1
  126. package/build/es/right-header.js +1 -1
  127. package/build/es/right-side.js +1 -1
  128. package/build/es/source-options.js +1 -1
  129. package/build/es/transfer/add-all-selectable-source-options.js +3 -2
  130. package/build/es/transfer/add-individual-source-options.js +1 -2
  131. package/build/es/transfer/create-double-click-handlers.js +0 -3
  132. package/build/es/transfer/get-option-click-handlers.js +1 -1
  133. package/build/es/transfer/is-reorder-down-disabled.js +4 -2
  134. package/build/es/transfer/is-reorder-up-disabled.js +4 -2
  135. package/build/es/transfer/move-highlighted-picked-option-down.js +4 -3
  136. package/build/es/transfer/move-highlighted-picked-option-up.js +4 -3
  137. package/build/es/transfer/remove-individual-picked-options.js +1 -2
  138. package/build/es/transfer/use-filter.js +0 -2
  139. package/build/es/transfer/use-highlighted-options/create-toggle-highlighted-option.js +3 -7
  140. package/build/es/transfer/use-highlighted-options/toggle-add.js +1 -1
  141. package/build/es/transfer/use-highlighted-options/toggle-range.js +4 -6
  142. package/build/es/transfer/use-highlighted-options/toggle-replace.js +0 -2
  143. package/build/es/transfer/use-highlighted-options.js +1 -2
  144. package/build/es/transfer-option.js +1 -2
  145. package/build/es/transfer.js +28 -32
  146. package/build/es/{transfer.stories.js → transfer.prod.stories.js} +65 -50
  147. package/build/es/use-resize-counter.js +1 -2
  148. package/package.json +10 -10
  149. /package/build/es/__e2e__/{add_remove-highlighted-options.stories.e2e.js → add_remove-highlighted-options.e2e.stories.js} +0 -0
  150. /package/build/es/__e2e__/{display-order.stories.e2e.js → display-order.e2e.stories.js} +0 -0
  151. /package/build/es/__e2e__/{highlight-range-of-options.stories.e2e.js → highlight-range-of-options.e2e.stories.js} +0 -0
  152. /package/build/es/__e2e__/{loading_lists.stories.e2e.js → loading_lists.e2e.stories.js} +0 -0
  153. /package/build/es/__e2e__/{notify_at_end_of_list.stories.e2e.js → notify_at_end_of_list.e2e.stories.js} +0 -0
  154. /package/build/es/__e2e__/{reorder-with-buttons.stories.e2e.js → reorder-with-buttons.e2e.stories.js} +0 -0
  155. /package/build/es/__e2e__/{set_unset-highlighted-option.stories.e2e.js → set_unset-highlighted-option.e2e.stories.js} +0 -0
  156. /package/build/es/__e2e__/{transferring-items.stories.e2e.js → transferring-items.e2e.stories.js} +0 -0
@@ -4,29 +4,48 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.SourceEmptyPlaceholder = exports.SingleSelection = exports.Reordering = exports.RTL = exports.PickedEmptyComponent = exports.OptionsFooter = exports.Multiple = exports.LoadingSource = exports.LoadingPicked = exports.InfiniteLoading = exports.IndividualCustomOption = exports.IncreasedOptionsHeight = exports.Header = exports.FilteredPlaceholder = exports.FilteredPicked = exports.Filtered = exports.DifferentWidths = exports.CustomListOptions = exports.CustomFilteringWithoutFilterInput = exports.CustomFilteringWithFilterInput = exports.CustomButtonText = void 0;
7
-
8
7
  var _select = require("@dhis2-ui/select");
9
-
10
8
  var _tab = require("@dhis2-ui/tab");
11
-
12
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
10
  var _react = _interopRequireWildcard(require("react"));
15
-
16
11
  var _transferOption = require("./transfer-option.js");
17
-
18
12
  var _transfer = require("./transfer.js");
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
17
+ const subtitle = 'Allows users to select options from a list';
18
+ const description = `
19
+ #### Usage
19
20
 
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+ Use a transfer component wherever a user needs to make a complex selection. Simple selections can be achieved with checkboxes, radio buttons or a select.
21
22
 
22
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+ There are use-cases that are particularly suitable for a transfer component:
23
24
 
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ - when a user needs to select some options from several different groups at the same time
26
+ - if the selection needs to have a defined order
27
+ - when the user will be interacting with and editing the selection often
28
+ - if a user needs to easily compare non-selected and selected options
29
+ - if a user is making selections as part of a complex flow, especially where there are many options to choose from
25
30
 
26
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
31
+ #### Terminology
27
32
 
28
- const subtitle = 'Allows users to select options from a list';
29
- const description = "\n#### Usage\n\nUse a transfer component wherever a user needs to make a complex selection. Simple selections can be achieved with checkboxes, radio buttons or a select.\n\nThere are use-cases that are particularly suitable for a transfer component:\n\n- when a user needs to select some options from several different groups at the same time\n- if the selection needs to have a defined order\n- when the user will be interacting with and editing the selection often\n- if a user needs to easily compare non-selected and selected options\n- if a user is making selections as part of a complex flow, especially where there are many options to choose from\n\n#### Terminology\n\nThis component has to differentiate between different types of options,\nhere's an explanation of their meaning:\n\n- source options: These are options listed on the left and are available for selection\n- picked options: These options have been selected by the user and are on the right side\n- highlighted option: These are visually highlighted options than can be on either side and are ready for transferral with the action buttons to the other side\n- filtered options: These are the displayed source options filtered by a search term or a custom search algorithm. The api surface uses \"selected\" for \"picked\" to be consistent with the rest of the library\n\n#### More details\n\nSee more about the options available for Transfers at [Design System: Transfer](https://github.com/dhis2/design-system/blob/master/organisms/transfer.md#transfer).\n\n```js\nimport { Transfer, TransferOption } from '@dhis2/ui'\n```\n";
33
+ This component has to differentiate between different types of options,
34
+ here's an explanation of their meaning:
35
+
36
+ - source options: These are options listed on the left and are available for selection
37
+ - picked options: These options have been selected by the user and are on the right side
38
+ - highlighted option: These are visually highlighted options than can be on either side and are ready for transferral with the action buttons to the other side
39
+ - filtered options: These are the displayed source options filtered by a search term or a custom search algorithm. The api surface uses "selected" for "picked" to be consistent with the rest of the library
40
+
41
+ #### More details
42
+
43
+ See more about the options available for Transfers at [Design System: Transfer](https://github.com/dhis2/design-system/blob/master/organisms/transfer.md#transfer).
44
+
45
+ \`\`\`js
46
+ import { Transfer, TransferOption } from '@dhis2/ui'
47
+ \`\`\`
48
+ `;
30
49
  const options = [{
31
50
  label: 'ANC 1st visit',
32
51
  value: 'anc_1st_visit'
@@ -94,6 +113,7 @@ const options = [{
94
113
  label: 'ART entry point: No PMTCT',
95
114
  value: 'art_entry_point:_no_pmtct'
96
115
  }];
116
+
97
117
  /**
98
118
  * Default args are needed because storybook currently struggles with
99
119
  * functions as default props: they are sent to the component as strings when
@@ -102,8 +122,7 @@ const options = [{
102
122
  *
103
123
  * https://github.com/storybookjs/storybook/issues/12455#issuecomment-702763930
104
124
  */
105
-
106
- var _default = {
125
+ var _default = exports.default = {
107
126
  title: 'Transfer',
108
127
  component: _transfer.Transfer,
109
128
  parameters: {
@@ -118,51 +137,43 @@ var _default = {
118
137
  }
119
138
  },
120
139
  // Default args:
121
- args: { ..._transfer.Transfer.defaultProps,
140
+ args: {
141
+ ..._transfer.Transfer.defaultProps,
122
142
  options: options
123
143
  }
124
144
  };
125
- exports.default = _default;
126
-
127
145
  const StatefulTemplate = _ref => {
128
146
  let {
129
147
  initiallySelected,
130
148
  ...args
131
149
  } = _ref;
132
150
  const [selected, setSelected] = (0, _react.useState)(initiallySelected);
133
-
134
151
  const onChange = payload => setSelected(payload.selected);
135
-
136
152
  return /*#__PURE__*/_react.default.createElement(_transfer.Transfer, _extends({}, args, {
137
153
  selected: selected,
138
154
  onChange: onChange
139
155
  }));
140
156
  };
141
-
142
157
  StatefulTemplate.defaultProps = {
143
158
  initiallySelected: []
144
159
  };
145
160
  StatefulTemplate.propTypes = {
146
161
  initiallySelected: _propTypes.default.array
147
162
  };
148
- const SingleSelection = StatefulTemplate.bind({});
149
- exports.SingleSelection = SingleSelection;
163
+ const SingleSelection = exports.SingleSelection = StatefulTemplate.bind({});
150
164
  SingleSelection.args = {
151
165
  maxSelections: 1
152
166
  };
153
- const Multiple = StatefulTemplate.bind({});
154
- exports.Multiple = Multiple;
167
+ const Multiple = exports.Multiple = StatefulTemplate.bind({});
155
168
  Multiple.args = {
156
169
  options: options.slice(0, 3)
157
170
  };
158
- const Header = StatefulTemplate.bind({});
159
- exports.Header = Header;
171
+ const Header = exports.Header = StatefulTemplate.bind({});
160
172
  Header.args = {
161
173
  leftHeader: /*#__PURE__*/_react.default.createElement("h3", null, "Header on the left side"),
162
174
  rightHeader: /*#__PURE__*/_react.default.createElement("h4", null, "Header on the right side")
163
175
  };
164
- const OptionsFooter = StatefulTemplate.bind({});
165
- exports.OptionsFooter = OptionsFooter;
176
+ const OptionsFooter = exports.OptionsFooter = StatefulTemplate.bind({});
166
177
  OptionsFooter.args = {
167
178
  leftFooter: /*#__PURE__*/_react.default.createElement("a", {
168
179
  href: "#",
@@ -173,14 +184,12 @@ OptionsFooter.args = {
173
184
  }
174
185
  }, "Reload list")
175
186
  };
176
- const Filtered = StatefulTemplate.bind({});
177
- exports.Filtered = Filtered;
187
+ const Filtered = exports.Filtered = StatefulTemplate.bind({});
178
188
  Filtered.args = {
179
189
  filterable: true,
180
190
  initialSearchTerm: 'ANC'
181
191
  };
182
- const FilteredPicked = StatefulTemplate.bind({});
183
- exports.FilteredPicked = FilteredPicked;
192
+ const FilteredPicked = exports.FilteredPicked = StatefulTemplate.bind({});
184
193
  FilteredPicked.args = {
185
194
  filterablePicked: true,
186
195
  initialSearchTermPicked: 'ANC',
@@ -191,14 +200,12 @@ FilteredPicked.args = {
191
200
  return value;
192
201
  })
193
202
  };
194
- const FilteredPlaceholder = StatefulTemplate.bind({});
195
- exports.FilteredPlaceholder = FilteredPlaceholder;
203
+ const FilteredPlaceholder = exports.FilteredPlaceholder = StatefulTemplate.bind({});
196
204
  FilteredPlaceholder.args = {
197
205
  filterable: true,
198
206
  filterLabel: 'Filter with placeholder',
199
207
  filterPlaceholder: 'Search'
200
208
  };
201
-
202
209
  const renderOption = _ref3 => {
203
210
  let {
204
211
  label,
@@ -218,33 +225,36 @@ const renderOption = _ref3 => {
218
225
  }
219
226
  }, "Custom: ", label, " (label), ", value, " (value)");
220
227
  };
221
-
222
- const RenderOptionCode = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("strong", null, "Custom option code:"), /*#__PURE__*/_react.default.createElement("code", null, /*#__PURE__*/_react.default.createElement("pre", null, "const renderOption = ({ label, value, onClick, highlighted, selected }) => (\n <p\n onClick={event => onClick({ label, value }, event)}\n style={{\n background: highlighted ? 'green' : 'blue',\n color: selected ? 'orange' : 'white',\n }}\n >\n Custom: {label} (label), {value} (value)\n </p>\n )")));
223
-
228
+ const RenderOptionCode = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("strong", null, "Custom option code:"), /*#__PURE__*/_react.default.createElement("code", null, /*#__PURE__*/_react.default.createElement("pre", null, `const renderOption = ({ label, value, onClick, highlighted, selected }) => (
229
+ <p
230
+ onClick={event => onClick({ label, value }, event)}
231
+ style={{
232
+ background: highlighted ? 'green' : 'blue',
233
+ color: selected ? 'orange' : 'white',
234
+ }}
235
+ >
236
+ Custom: {label} (label), {value} (value)
237
+ </p>
238
+ )`)));
224
239
  const StatefulTemplateCustomRenderOption = _ref4 => {
225
240
  let {
226
241
  initiallySelected,
227
242
  ...args
228
243
  } = _ref4;
229
244
  const [selected, setSelected] = (0, _react.useState)(initiallySelected);
230
-
231
245
  const onChange = payload => setSelected(payload.selected);
232
-
233
246
  return /*#__PURE__*/_react.default.createElement(_transfer.Transfer, _extends({}, args, {
234
247
  selected: selected,
235
248
  onChange: onChange
236
249
  }));
237
250
  };
238
-
239
251
  StatefulTemplateCustomRenderOption.defaultProps = {
240
252
  initiallySelected: []
241
253
  };
242
254
  StatefulTemplateCustomRenderOption.propTypes = {
243
255
  initiallySelected: _propTypes.default.array
244
256
  };
245
-
246
257
  const CustomListOptions = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(RenderOptionCode, null), /*#__PURE__*/_react.default.createElement(StatefulTemplateCustomRenderOption, args));
247
-
248
258
  exports.CustomListOptions = CustomListOptions;
249
259
  CustomListOptions.args = {
250
260
  renderOption,
@@ -256,8 +266,7 @@ CustomListOptions.args = {
256
266
  return value;
257
267
  })
258
268
  };
259
- const IndividualCustomOption = StatefulTemplateCustomRenderOption.bind({});
260
- exports.IndividualCustomOption = IndividualCustomOption;
269
+ const IndividualCustomOption = exports.IndividualCustomOption = StatefulTemplateCustomRenderOption.bind({});
261
270
  IndividualCustomOption.args = {
262
271
  addAllText: 'Add all',
263
272
  addIndividualText: 'Add individual',
@@ -267,20 +276,17 @@ IndividualCustomOption.args = {
267
276
  if (option.value === options[0].value) {
268
277
  return renderOption(option);
269
278
  }
270
-
271
279
  return /*#__PURE__*/_react.default.createElement(_transferOption.TransferOption, option);
272
280
  }
273
281
  };
274
- const CustomButtonText = StatefulTemplate.bind({});
275
- exports.CustomButtonText = CustomButtonText;
282
+ const CustomButtonText = exports.CustomButtonText = StatefulTemplate.bind({});
276
283
  CustomButtonText.args = {
277
284
  addAllText: 'Add all',
278
285
  addIndividualText: 'Add individual',
279
286
  removeAllText: 'Remove all',
280
287
  removeIndividualText: 'Remove individual'
281
288
  };
282
- const SourceEmptyPlaceholder = StatefulTemplate.bind({});
283
- exports.SourceEmptyPlaceholder = SourceEmptyPlaceholder;
289
+ const SourceEmptyPlaceholder = exports.SourceEmptyPlaceholder = StatefulTemplate.bind({});
284
290
  SourceEmptyPlaceholder.args = {
285
291
  sourceEmptyPlaceholder: /*#__PURE__*/_react.default.createElement("p", {
286
292
  style: {
@@ -294,8 +300,7 @@ SourceEmptyPlaceholder.args = {
294
300
  }, "Add option")),
295
301
  options: []
296
302
  };
297
- const PickedEmptyComponent = StatefulTemplate.bind({});
298
- exports.PickedEmptyComponent = PickedEmptyComponent;
303
+ const PickedEmptyComponent = exports.PickedEmptyComponent = StatefulTemplate.bind({});
299
304
  PickedEmptyComponent.args = {
300
305
  selectedEmptyComponent: /*#__PURE__*/_react.default.createElement("p", {
301
306
  style: {
@@ -303,8 +308,7 @@ PickedEmptyComponent.args = {
303
308
  }
304
309
  }, "You have not selected anything yet", /*#__PURE__*/_react.default.createElement("br", null))
305
310
  };
306
- const Reordering = StatefulTemplate.bind({});
307
- exports.Reordering = Reordering;
311
+ const Reordering = exports.Reordering = StatefulTemplate.bind({});
308
312
  Reordering.args = {
309
313
  enableOrderChange: true,
310
314
  options: options.slice(0, 4),
@@ -315,31 +319,29 @@ Reordering.args = {
315
319
  return value;
316
320
  })
317
321
  };
318
- const IncreasedOptionsHeight = StatefulTemplate.bind({});
319
- exports.IncreasedOptionsHeight = IncreasedOptionsHeight;
322
+ const IncreasedOptionsHeight = exports.IncreasedOptionsHeight = StatefulTemplate.bind({});
320
323
  IncreasedOptionsHeight.args = {
321
324
  maxSelections: Infinity,
322
325
  filterable: true,
323
326
  height: '400px'
324
327
  };
325
- const DifferentWidths = StatefulTemplate.bind({});
326
- exports.DifferentWidths = DifferentWidths;
328
+ const DifferentWidths = exports.DifferentWidths = StatefulTemplate.bind({});
327
329
  DifferentWidths.args = {
328
330
  optionsWidth: '500px',
329
331
  selectedWidth: '240px'
330
332
  };
331
-
332
333
  const createCustomFilteringInHeader = hideFilterInput => {
333
- const relativePeriods = options.slice(0, 10).map((option, index) => ({ ...option,
334
+ const relativePeriods = options.slice(0, 10).map((option, index) => ({
335
+ ...option,
334
336
  relativePeriod: true,
335
337
  year: index < 5 ? '2020' : '2019'
336
338
  }));
337
- const fixedPeriods = options.slice(10, 20).map((option, index) => ({ ...option,
339
+ const fixedPeriods = options.slice(10, 20).map((option, index) => ({
340
+ ...option,
338
341
  relativePeriod: false,
339
342
  year: index < 5 ? '2020' : '2019'
340
343
  }));
341
344
  const allOptions = [...relativePeriods, ...fixedPeriods];
342
-
343
345
  const Header = _ref7 => {
344
346
  let {
345
347
  onClick,
@@ -376,20 +378,16 @@ const createCustomFilteringInHeader = hideFilterInput => {
376
378
  };
377
379
  /* eslint-enable react/prop-types */
378
380
 
379
-
380
381
  const CustomTransfer = props => {
381
382
  const [filter, setFilter] = (0, _react.useState)('');
382
383
  const [relativePeriod, setRelativePeriod] = (0, _react.useState)(true);
383
384
  const [year, setYear] = (0, _react.useState)('2020');
384
-
385
385
  const filterCallback = (options, filter) => {
386
386
  const optionsWithYear = options.filter(option => option.year === year);
387
387
  const optionsWithPeriod = optionsWithYear.filter(option => option.relativePeriod === relativePeriod);
388
-
389
388
  if (filter === '') {
390
389
  return optionsWithPeriod;
391
390
  }
392
-
393
391
  return optionsWithPeriod.filter(_ref8 => {
394
392
  let {
395
393
  label
@@ -397,7 +395,6 @@ const createCustomFilteringInHeader = hideFilterInput => {
397
395
  return label.indexOf(filter) !== -1;
398
396
  });
399
397
  };
400
-
401
398
  const header = /*#__PURE__*/_react.default.createElement(Header, {
402
399
  relativePeriod: relativePeriod,
403
400
  selectedYear: year,
@@ -414,7 +411,6 @@ const createCustomFilteringInHeader = hideFilterInput => {
414
411
  return setRelativePeriod(newRelativePeriod);
415
412
  }
416
413
  });
417
-
418
414
  return /*#__PURE__*/_react.default.createElement(_transfer.Transfer, _extends({}, props, {
419
415
  options: allOptions,
420
416
  filterable: true,
@@ -434,69 +430,62 @@ const createCustomFilteringInHeader = hideFilterInput => {
434
430
  filterPlaceholder: "Search"
435
431
  }));
436
432
  };
437
-
438
433
  return _ref12 => {
439
434
  let {
440
435
  initiallySelected,
441
436
  ...args
442
437
  } = _ref12;
443
438
  const [selected, setSelected] = (0, _react.useState)(initiallySelected);
444
-
445
439
  const onChange = payload => setSelected(payload.selected);
446
-
447
440
  return /*#__PURE__*/_react.default.createElement(CustomTransfer, _extends({}, args, {
448
441
  selected: selected,
449
442
  onChange: onChange
450
443
  }));
451
444
  };
452
445
  };
453
-
454
- const CustomFilteringWithFilterInput = createCustomFilteringInHeader(false);
455
- exports.CustomFilteringWithFilterInput = CustomFilteringWithFilterInput;
456
- const CustomFilteringWithoutFilterInput = createCustomFilteringInHeader(true);
457
- exports.CustomFilteringWithoutFilterInput = CustomFilteringWithoutFilterInput;
446
+ const CustomFilteringWithFilterInput = exports.CustomFilteringWithFilterInput = createCustomFilteringInHeader(false);
447
+ const CustomFilteringWithoutFilterInput = exports.CustomFilteringWithoutFilterInput = createCustomFilteringInHeader(true);
458
448
  const optionsPool = options;
459
449
  const pageSize = 5;
450
+
460
451
  /*
461
452
  * The page size is: 5
462
453
  * To keep the code as small as possible, handling selecting items is not
463
454
  included
464
455
  */
465
-
466
456
  const InfiniteLoading = args => {
467
457
  (0, _react.useEffect)(() => {
468
458
  console.clear();
469
- }, []); // state for whether the next page's options are being loaded
470
-
471
- const [loading, setLoading] = (0, _react.useState)(false); // captures the current page
472
-
473
- const [page, setPage] = (0, _react.useState)(0); // all options (incl. available AND selected options)
474
-
475
- const [options, setOptions] = (0, _react.useState)([]); // selected options
476
-
477
- const [selected] = (0, _react.useState)( // second page is already selected
459
+ }, []);
460
+
461
+ // state for whether the next page's options are being loaded
462
+ const [loading, setLoading] = (0, _react.useState)(false);
463
+ // captures the current page
464
+ const [page, setPage] = (0, _react.useState)(0);
465
+ // all options (incl. available AND selected options)
466
+ const [options, setOptions] = (0, _react.useState)([]);
467
+ // selected options
468
+ const [selected] = (0, _react.useState)(
469
+ // second page is already selected
478
470
  optionsPool.slice(pageSize, pageSize * 2).map(_ref13 => {
479
471
  let {
480
472
  value
481
473
  } = _ref13;
482
474
  return value;
483
475
  }));
484
-
485
476
  const onEndReached = () => {
486
477
  // do nothing when loading already
487
478
  if (loading) {
488
479
  return;
489
480
  }
490
-
491
481
  setPage(page + 1);
492
- }; // fake fetch request
493
-
482
+ };
494
483
 
484
+ // fake fetch request
495
485
  const fetchOptions = nextPage => new Promise(resolve => setTimeout(() => {
496
486
  const nextOptions = optionsPool.slice(options.length, nextPage * pageSize);
497
487
  resolve(nextOptions);
498
488
  }, 2000));
499
-
500
489
  const loadNextOptions = async () => {
501
490
  setLoading(true);
502
491
  const nextOptions = await fetchOptions(page);
@@ -508,12 +497,10 @@ const InfiniteLoading = args => {
508
497
  } = nextOption;
509
498
  return selected.includes(value);
510
499
  });
511
-
512
500
  if (allAlreadySelected) {
513
501
  onEndReached();
514
502
  }
515
503
  };
516
-
517
504
  (0, _react.useEffect)(() => {
518
505
  // prevent initial call
519
506
  if (page > 0) {
@@ -524,22 +511,17 @@ const InfiniteLoading = args => {
524
511
  loading: loading,
525
512
  options: options,
526
513
  selected: selected,
527
- onChange: () => null
528
- /* noop */
529
- ,
514
+ onChange: () => null /* noop */,
530
515
  onEndReached: onEndReached
531
516
  }));
532
517
  };
533
-
534
518
  exports.InfiniteLoading = InfiniteLoading;
535
- const LoadingSource = StatefulTemplate.bind({});
536
- exports.LoadingSource = LoadingSource;
519
+ const LoadingSource = exports.LoadingSource = StatefulTemplate.bind({});
537
520
  LoadingSource.args = {
538
521
  loading: true,
539
522
  options: options.slice(0, 3)
540
523
  };
541
- const LoadingPicked = StatefulTemplate.bind({});
542
- exports.LoadingPicked = LoadingPicked;
524
+ const LoadingPicked = exports.LoadingPicked = StatefulTemplate.bind({});
543
525
  LoadingPicked.args = {
544
526
  loadingPicked: true,
545
527
  options: options.slice(0, 3),
@@ -550,11 +532,9 @@ LoadingPicked.args = {
550
532
  return value;
551
533
  })
552
534
  };
553
-
554
535
  const RTL = args => /*#__PURE__*/_react.default.createElement("div", {
555
536
  dir: "rtl"
556
537
  }, /*#__PURE__*/_react.default.createElement(Multiple, args));
557
-
558
538
  exports.RTL = RTL;
559
539
  RTL.args = {
560
540
  options: options.slice(0, 3),
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useResizeCounter = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  /*
11
9
  * The initial call is irrelevant as there has been
12
10
  * no resize yet that we want to react to
@@ -24,7 +22,6 @@ const useResizeCounter = element => {
24
22
  // it's executed as the callback passed to `ResizeObserver`
25
23
  // will be executed on construction
26
24
  let internalCounter = counter;
27
-
28
25
  if (element) {
29
26
  const observer = new ResizeObserver(() => {
30
27
  ++internalCounter;
@@ -36,5 +33,4 @@ const useResizeCounter = element => {
36
33
  }, [element, setCounter]);
37
34
  return counter < 1 ? 0 : counter;
38
35
  };
39
-
40
36
  exports.useResizeCounter = useResizeCounter;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/display-name */
2
- import React, { useState } from 'react';
3
2
 
3
+ import React, { useState } from 'react';
4
4
  const WithState = _ref => {
5
5
  let {
6
6
  fn,
@@ -22,7 +22,6 @@ const WithState = _ref => {
22
22
  } : undefined
23
23
  });
24
24
  };
25
-
26
25
  export const statefulDecorator = function () {
27
26
  let {
28
27
  initialState = [],
@@ -47,7 +47,8 @@ export const OnlyDisabledSourceOptions = (_, _ref4) => {
47
47
  return /*#__PURE__*/React.createElement(Transfer, {
48
48
  selected: selected,
49
49
  onChange: onChange,
50
- options: [{ ...options[0],
50
+ options: [{
51
+ ...options[0],
51
52
  disabled: true
52
53
  }]
53
54
  });
@@ -14,7 +14,8 @@ export const OneDisabled = (_, _ref) => {
14
14
  return /*#__PURE__*/React.createElement(Transfer, {
15
15
  selected: selected,
16
16
  onChange: onChange,
17
- options: [...options.slice(0, 3), { ...options[3],
17
+ options: [...options.slice(0, 3), {
18
+ ...options[3],
18
19
  disabled: true
19
20
  }, ...options.slice(4)]
20
21
  });
@@ -74,12 +74,11 @@ export const AncCustomFilter = (_, _ref5) => {
74
74
  let {
75
75
  label
76
76
  } = _ref6;
77
- return label.match("(^| )ANC .*".concat(filter));
77
+ return label.match(`(^| )ANC .*${filter}`);
78
78
  }),
79
79
  options: options
80
80
  });
81
81
  };
82
-
83
82
  window.customFilterCallback = (options, filter) => {
84
83
  return options.filter(_ref7 => {
85
84
  let {
@@ -88,7 +87,6 @@ window.customFilterCallback = (options, filter) => {
88
87
  return label.indexOf(filter) !== -1;
89
88
  });
90
89
  };
91
-
92
90
  window.Cypress && window.Cypress.cy.spy(window, 'customFilterCallback');
93
91
  export const ControlledFilter = (_, _ref8) => {
94
92
  let {
@@ -92,7 +92,8 @@ describe('Transfer- useHighlightedOptions - createToggleHighlightedOption', () =
92
92
  expect(toggleRange).toHaveBeenCalledTimes(0);
93
93
  });
94
94
  it('should do nothing when disabled is true', () => {
95
- toggleHighlightedOption = createToggleHighlightedOption({ ...createToggleHighlightedOptionDefaultPayload,
95
+ toggleHighlightedOption = createToggleHighlightedOption({
96
+ ...createToggleHighlightedOptionDefaultPayload,
96
97
  disabled: true
97
98
  });
98
99
  toggleHighlightedOption({
@@ -115,10 +115,10 @@ describe('Transfer- useHighlightedOptions - toggleRange', () => {
115
115
  });
116
116
  expect(setHighlightedOptions).toHaveBeenCalledWith(expected);
117
117
  });
118
+
118
119
  /**
119
120
  * E. g. lastClicked is hidden because of a filter change
120
121
  */
121
-
122
122
  it('should highlight from the highest in list to the clicked when last clicked not visible anymore', () => {
123
123
  const expected = options.slice(1, 6).map(_ref5 => {
124
124
  let {
@@ -141,11 +141,11 @@ describe('Transfer- useHighlightedOptions - toggleRange', () => {
141
141
  });
142
142
  expect(setHighlightedOptions).toHaveBeenCalledWith(expected);
143
143
  });
144
+
144
145
  /**
145
146
  * E. g. lastClicked is null because all options so far
146
147
  * have been clicked with shift
147
148
  */
148
-
149
149
  it('should highlight from the highest in list to the clicked when last clicked null', () => {
150
150
  const expected = options.slice(1, 6).map(_ref7 => {
151
151
  let {
@@ -1,5 +1,5 @@
1
- import { useHighlightedOptions } from '../../transfer/use-highlighted-options.js';
2
1
  import { createToggleHighlightedOption } from '../../transfer/use-highlighted-options/create-toggle-highlighted-option.js';
2
+ import { useHighlightedOptions } from '../../transfer/use-highlighted-options.js';
3
3
  jest.mock('../../transfer/use-highlighted-options/create-toggle-highlighted-option.js', () => ({
4
4
  createToggleHighlightedOption: jest.fn()
5
5
  }));
@@ -13,7 +13,7 @@ export const Actions = _ref => {
13
13
  }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
14
14
  id: "1457814848",
15
15
  dynamic: [spacers.dp8]
16
- }, ["div.__jsx-style-dynamic-selector{-webkit-align-content:center;-ms-flex-line-pack:center;align-content:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:1;-ms-flex-negative:1;flex-shrink:1;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin:0 ".concat(spacers.dp8, ";}"), "div.__jsx-style-dynamic-selector>button{margin-top:8px;}", "div.__jsx-style-dynamic-selector>button:first-child{margin-top:0;}"]));
16
+ }, [`div.__jsx-style-dynamic-selector{-webkit-align-content:center;-ms-flex-line-pack:center;align-content:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:1;-ms-flex-negative:1;flex-shrink:1;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin:0 ${spacers.dp8};}`, "div.__jsx-style-dynamic-selector>button{margin-top:8px;}", "div.__jsx-style-dynamic-selector>button:first-child{margin-top:0;}"]));
17
17
  };
18
18
  Actions.propTypes = {
19
19
  dataTest: PropTypes.string.isRequired,
@@ -14,7 +14,7 @@ export const AddAll = _ref => {
14
14
  disabled: disabled,
15
15
  onClick: onClick,
16
16
  icon: /*#__PURE__*/React.createElement(IconAddAll, {
17
- dataTest: "".concat(dataTest, "-iconaddall"),
17
+ dataTest: `${dataTest}-iconaddall`,
18
18
  disabled: disabled
19
19
  })
20
20
  }, label);
@@ -15,7 +15,7 @@ export const AddIndividual = _ref => {
15
15
  onClick: onClick,
16
16
  icon: /*#__PURE__*/React.createElement(IconAddIndividual, {
17
17
  disabled: disabled,
18
- dataTest: "".concat(dataTest, "-iconaddindividual")
18
+ dataTest: `${dataTest}-iconaddindividual`
19
19
  })
20
20
  }, label);
21
21
  };
@@ -1,8 +1,8 @@
1
1
  import { isOption } from './is-option.js';
2
+
2
3
  /**
3
4
  * @param {Object[]} options
4
5
  * @param {Object} option
5
6
  * @returns {Int}
6
7
  */
7
-
8
8
  export const findOptionIndex = (options, option) => options.findIndex(current => isOption(current, option));