@dhis2-ui/transfer 10.16.1 → 10.16.3-alpha.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 (109) hide show
  1. package/package.json +10 -9
  2. package/src/__e2e__/add_remove-highlighted-options.e2e.stories.js +30 -0
  3. package/src/__e2e__/common/options.js +90 -0
  4. package/src/__e2e__/common/stateful-decorator.js +33 -0
  5. package/src/__e2e__/common.js +0 -0
  6. package/src/__e2e__/disabled-transfer-buttons.e2e.stories.js +49 -0
  7. package/src/__e2e__/disabled-transfer-options.e2e.stories.js +21 -0
  8. package/src/__e2e__/display-order.e2e.stories.js +24 -0
  9. package/src/__e2e__/filter-options-list.e2e.stories.js +87 -0
  10. package/src/__e2e__/highlight-range-of-options.e2e.stories.js +52 -0
  11. package/src/__e2e__/loading_lists.e2e.stories.js +26 -0
  12. package/src/__e2e__/notify_at_end_of_list.e2e.stories.js +116 -0
  13. package/src/__e2e__/reorder-with-buttons.e2e.stories.js +35 -0
  14. package/src/__e2e__/set_unset-highlighted-option.e2e.stories.js +30 -0
  15. package/src/__e2e__/transferring-items.e2e.stories.js +27 -0
  16. package/src/__tests__/common.test.js +131 -0
  17. package/src/__tests__/helper/add-all-selectable-source-options.test.js +46 -0
  18. package/src/__tests__/helper/add-individual-source-options.test.js +80 -0
  19. package/src/__tests__/helper/default-filter-callback.test.js +45 -0
  20. package/src/__tests__/helper/is-reorder-down-disabled.test.js +96 -0
  21. package/src/__tests__/helper/is-reorder-up-disabled.test.js +96 -0
  22. package/src/__tests__/helper/move-highlighted-picked-option-down.test.js +111 -0
  23. package/src/__tests__/helper/move-highlighted-picked-option-to-bottom.test.js +101 -0
  24. package/src/__tests__/helper/move-highlighted-picked-option-to-top.test.js +101 -0
  25. package/src/__tests__/helper/move-highlighted-picked-option-up.test.js +111 -0
  26. package/src/__tests__/helper/remove-all-picked-options.test.js +29 -0
  27. package/src/__tests__/helper/remove-individual-picked-options.test.js +38 -0
  28. package/src/__tests__/helper/use-highlighted-option/create-toggle-highlighted-option.test.js +104 -0
  29. package/src/__tests__/helper/use-highlighted-option/toggle-add.test.js +84 -0
  30. package/src/__tests__/helper/use-highlighted-option/toggle-range.test.js +150 -0
  31. package/src/__tests__/helper/use-highlighted-option/toggle-replace.test.js +39 -0
  32. package/src/__tests__/helper/use-highlighted-option.test.js +41 -0
  33. package/src/__tests__/reordering-actions.test.js +165 -0
  34. package/src/__tests__/transfer.test.js +137 -0
  35. package/src/actions.js +33 -0
  36. package/src/add-all.js +27 -0
  37. package/src/add-individual.js +27 -0
  38. package/src/common/find-option-index.js +9 -0
  39. package/src/common/get-mode-by-modifier-key.js +35 -0
  40. package/src/common/index.js +5 -0
  41. package/src/common/is-option.js +7 -0
  42. package/src/common/modes.js +11 -0
  43. package/src/common/remove-option.js +19 -0
  44. package/src/common/toggle-value.js +18 -0
  45. package/src/container.js +23 -0
  46. package/src/end-intersection-detector.js +37 -0
  47. package/src/features/add_remove-highlighted-options/index.js +92 -0
  48. package/src/features/add_remove-highlighted-options.feature +41 -0
  49. package/src/features/common/index.js +8 -0
  50. package/src/features/disabled-transfer-buttons/index.js +118 -0
  51. package/src/features/disabled-transfer-buttons.feature +46 -0
  52. package/src/features/disabled-transfer-options/index.js +182 -0
  53. package/src/features/disabled-transfer-options.feature +42 -0
  54. package/src/features/display-order/index.js +205 -0
  55. package/src/features/display-order.feature +30 -0
  56. package/src/features/filter-options-list/index.js +133 -0
  57. package/src/features/filter-options-list.feature +40 -0
  58. package/src/features/highlight-range-of-options/index.js +336 -0
  59. package/src/features/highlight-range-of-options.feature +70 -0
  60. package/src/features/loading_lists/index.js +43 -0
  61. package/src/features/loading_lists.feature +19 -0
  62. package/src/features/notify_at_end_of_list/index.js +125 -0
  63. package/src/features/notify_at_end_of_list.feature +64 -0
  64. package/src/features/reorder-with-buttons/index.js +181 -0
  65. package/src/features/reorder-with-buttons.feature +138 -0
  66. package/src/features/set_unset-highlighted-option/index.js +121 -0
  67. package/src/features/set_unset-highlighted-option.feature +42 -0
  68. package/src/features/transferring-items/index.js +375 -0
  69. package/src/features/transferring-items.feature +44 -0
  70. package/src/filter.js +38 -0
  71. package/src/icons.js +194 -0
  72. package/src/index.js +2 -0
  73. package/src/left-footer.js +22 -0
  74. package/src/left-header.js +22 -0
  75. package/src/left-side.js +34 -0
  76. package/src/locales/en/translations.json +7 -0
  77. package/src/locales/index.js +16 -0
  78. package/src/options-container.js +127 -0
  79. package/src/remove-all.js +27 -0
  80. package/src/remove-individual.js +27 -0
  81. package/src/reordering-actions.js +136 -0
  82. package/src/right-footer.js +22 -0
  83. package/src/right-header.js +22 -0
  84. package/src/right-side.js +33 -0
  85. package/src/transfer/add-all-selectable-source-options.js +37 -0
  86. package/src/transfer/add-individual-source-options.js +61 -0
  87. package/src/transfer/create-double-click-handlers.js +36 -0
  88. package/src/transfer/default-filter-callback.js +17 -0
  89. package/src/transfer/get-highlighted-picked-indices.js +26 -0
  90. package/src/transfer/get-option-click-handlers.js +19 -0
  91. package/src/transfer/index.js +17 -0
  92. package/src/transfer/is-reorder-down-disabled.js +34 -0
  93. package/src/transfer/is-reorder-up-disabled.js +30 -0
  94. package/src/transfer/move-highlighted-picked-option-down.js +54 -0
  95. package/src/transfer/move-highlighted-picked-option-to-bottom.js +44 -0
  96. package/src/transfer/move-highlighted-picked-option-to-top.js +38 -0
  97. package/src/transfer/move-highlighted-picked-option-up.js +47 -0
  98. package/src/transfer/remove-all-picked-options.js +13 -0
  99. package/src/transfer/remove-individual-picked-options.js +49 -0
  100. package/src/transfer/use-filter.js +17 -0
  101. package/src/transfer/use-highlighted-options/create-toggle-highlighted-option.js +64 -0
  102. package/src/transfer/use-highlighted-options/toggle-add.js +20 -0
  103. package/src/transfer/use-highlighted-options/toggle-range.js +61 -0
  104. package/src/transfer/use-highlighted-options/toggle-replace.js +26 -0
  105. package/src/transfer/use-highlighted-options.js +34 -0
  106. package/src/transfer/use-options-key-monitor.js +41 -0
  107. package/src/transfer-option.js +91 -0
  108. package/src/transfer.js +539 -0
  109. package/src/transfer.prod.stories.js +621 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/transfer",
3
- "version": "10.16.1",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Transfer",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,19 +34,20 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.1.2",
37
- "@dhis2-ui/button": "10.16.1",
38
- "@dhis2-ui/field": "10.16.1",
39
- "@dhis2-ui/input": "10.16.1",
40
- "@dhis2-ui/intersection-detector": "10.16.1",
41
- "@dhis2-ui/loader": "10.16.1",
42
- "@dhis2-ui/tooltip": "10.16.1",
43
- "@dhis2/ui-constants": "10.16.1",
37
+ "@dhis2-ui/button": "10.16.3-alpha.1",
38
+ "@dhis2-ui/field": "10.16.3-alpha.1",
39
+ "@dhis2-ui/input": "10.16.3-alpha.1",
40
+ "@dhis2-ui/intersection-detector": "10.16.3-alpha.1",
41
+ "@dhis2-ui/loader": "10.16.3-alpha.1",
42
+ "@dhis2-ui/tooltip": "10.16.3-alpha.1",
43
+ "@dhis2/ui-constants": "10.16.3-alpha.1",
44
44
  "classnames": "^2.3.1",
45
45
  "prop-types": "^15.7.2"
46
46
  },
47
47
  "files": [
48
48
  "build",
49
- "types"
49
+ "types",
50
+ "src"
50
51
  ],
51
52
  "devDependencies": {
52
53
  "react": "^18.3.1",
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer add & remove highlighted options',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const HasOptions = (_, { onChange, selected }) => (
12
+ <Transfer
13
+ filterable
14
+ selected={selected}
15
+ onChange={onChange}
16
+ options={options}
17
+ />
18
+ )
19
+
20
+ export const HasSelected = (_, { onChange, selected }) => (
21
+ <Transfer onChange={onChange} selected={selected} options={options} />
22
+ )
23
+
24
+ HasSelected.story = {
25
+ decorators: [
26
+ statefulDecorator({
27
+ initialState: options.slice(0, 4).map(({ value }) => value),
28
+ }),
29
+ ],
30
+ }
@@ -0,0 +1,90 @@
1
+ export const options = [
2
+ {
3
+ label: 'ANC 1st visit',
4
+ value: 'anc_1st_visit',
5
+ },
6
+ {
7
+ label: 'ANC 2nd visit',
8
+ value: 'anc_2nd_visit',
9
+ },
10
+ {
11
+ label: 'ANC 3rd visit',
12
+ value: 'anc_3rd_visit',
13
+ },
14
+ {
15
+ label: 'ANC 4th or more visits',
16
+ value: 'anc_4th_or_more_visits',
17
+ },
18
+ {
19
+ label: 'ARI treated with antibiotics (pneumonia) follow-up',
20
+ value: 'ari_treated_with_antibiotics_(pneumonia)_follow-up',
21
+ },
22
+ {
23
+ label: 'ARI treated with antibiotics (pneumonia) new',
24
+ value: 'ari_treated_with_antibiotics_(pneumonia)_new',
25
+ },
26
+ {
27
+ label: 'ARI treated with antibiotics (pneumonia) referrals',
28
+ value: 'ari_treated_with_antibiotics_(pneumonia)_referrals',
29
+ },
30
+ {
31
+ label: 'ARI treated without antibiotics (cough) follow-up',
32
+ value: 'ari_treated_without_antibiotics_(cough)_follow-up',
33
+ },
34
+ {
35
+ label: 'ARI treated without antibiotics (cough) new',
36
+ value: 'ari_treated_without_antibiotics_(cough)_new',
37
+ },
38
+ {
39
+ label: 'ARI treated without antibiotics (cough) referrals',
40
+ value: 'ari_treated_without_antibiotics_(cough)_referrals',
41
+ },
42
+ {
43
+ label: 'ART No clients who stopped TRT due to TRT failure',
44
+ value: 'art_no_clients_who_stopped_trt_due_to_trt_failure',
45
+ },
46
+ {
47
+ label: 'ART No clients who stopped TRT due to adverse clinical status/event',
48
+ value: 'art_no_clients_who_stopped_trt_due_to_adverse_clinical_status/event',
49
+ },
50
+ {
51
+ label: 'ART No clients with change of regimen due to drug toxicity',
52
+ value: 'art_no_clients_with_change_of_regimen_due_to_drug_toxicity',
53
+ },
54
+ {
55
+ label: 'ART No clients with new adverse drug reaction',
56
+ value: 'art_no_clients_with_new_adverse_drug_reaction',
57
+ },
58
+ {
59
+ label: 'ART No started Opportunist Infection prophylaxis',
60
+ value: 'art_no_started_opportunist_infection_prophylaxis',
61
+ },
62
+ {
63
+ label: 'ART clients with new adverse clinical event',
64
+ value: 'art_clients_with_new_adverse_clinical_event',
65
+ },
66
+ {
67
+ label: 'ART defaulters',
68
+ value: 'art_defaulters',
69
+ },
70
+ {
71
+ label: 'ART enrollment stage 1',
72
+ value: 'art_enrollment_stage_1',
73
+ },
74
+ {
75
+ label: 'ART enrollment stage 2',
76
+ value: 'art_enrollment_stage_2',
77
+ },
78
+ {
79
+ label: 'ART enrollment stage 3',
80
+ value: 'art_enrollment_stage_3',
81
+ },
82
+ {
83
+ label: 'ART enrollment stage 4',
84
+ value: 'art_enrollment_stage_4',
85
+ },
86
+ {
87
+ label: 'ART entry point: No PMTCT',
88
+ value: 'art_entry_point:_no_pmtct',
89
+ },
90
+ ]
@@ -0,0 +1,33 @@
1
+ /* eslint-disable react/display-name */
2
+
3
+ import React, { useState } from 'react'
4
+
5
+ const WithState = ({ fn, initialState, initialSearchTerm, controlFilter }) => {
6
+ const [selected, setSelected] = useState(initialState)
7
+ const [searchTerm, setSearchTerm] = useState(initialSearchTerm)
8
+
9
+ return fn({
10
+ selected,
11
+ searchTerm: controlFilter ? searchTerm : undefined,
12
+ onChange: (payload) => setSelected(payload.selected),
13
+ onFilterChange: controlFilter
14
+ ? ({ value }) => setSearchTerm(value)
15
+ : undefined,
16
+ })
17
+ }
18
+
19
+ export const statefulDecorator =
20
+ ({
21
+ initialState = [],
22
+ controlFilter = false,
23
+ initialSearchTerm = '',
24
+ } = {}) =>
25
+ (fn) =>
26
+ (
27
+ <WithState
28
+ initialState={initialState}
29
+ initialSearchTerm={initialSearchTerm}
30
+ controlFilter={controlFilter}
31
+ fn={fn}
32
+ />
33
+ )
File without changes
@@ -0,0 +1,49 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer Disabled Transfer Buttons',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const NoOptions = (_, { selected, onChange }) => (
12
+ <Transfer selected={selected} onChange={onChange} options={[]} />
13
+ )
14
+
15
+ export const HasOptions = (_, { selected, onChange }) => (
16
+ <Transfer selected={selected} onChange={onChange} options={options} />
17
+ )
18
+
19
+ export const SomeOptionsSelected = (_, { selected, onChange }) => (
20
+ <Transfer selected={selected} onChange={onChange} options={options} />
21
+ )
22
+
23
+ export const OnlyDisabledSourceOptions = (_, { selected, onChange }) => (
24
+ <Transfer
25
+ selected={selected}
26
+ onChange={onChange}
27
+ options={[{ ...options[0], disabled: true }]}
28
+ />
29
+ )
30
+
31
+ SomeOptionsSelected.story = {
32
+ decorators: [
33
+ statefulDecorator({
34
+ initialState: options.slice(0, 4).map(({ value }) => value),
35
+ }),
36
+ ],
37
+ }
38
+
39
+ export const AllOptionsSelected = (_, { selected, onChange }) => (
40
+ <Transfer selected={selected} onChange={onChange} options={options} />
41
+ )
42
+
43
+ AllOptionsSelected.story = {
44
+ decorators: [
45
+ statefulDecorator({
46
+ initialState: options.map(({ value }) => value),
47
+ }),
48
+ ],
49
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Disabled Source Options',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const OneDisabled = (_, { selected, onChange }) => (
12
+ <Transfer
13
+ selected={selected}
14
+ onChange={onChange}
15
+ options={[
16
+ ...options.slice(0, 3),
17
+ { ...options[3], disabled: true },
18
+ ...options.slice(4),
19
+ ]}
20
+ />
21
+ )
@@ -0,0 +1,24 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default { title: 'Transfer Display Order' }
7
+
8
+ window.options = options
9
+
10
+ export const NoSelection = (_, { selected, onChange }) => (
11
+ <Transfer selected={selected} onChange={onChange} options={options} />
12
+ )
13
+
14
+ export const SomeSelected = (_, { selected, onChange }) => (
15
+ <Transfer selected={selected} onChange={onChange} options={options} />
16
+ )
17
+
18
+ SomeSelected.story = {
19
+ decorators: [
20
+ statefulDecorator({
21
+ initialState: options.slice(0, 4).map(({ value }) => value),
22
+ }),
23
+ ],
24
+ }
@@ -0,0 +1,87 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer filtering',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const EmptyResult = (_, { selected, onChange }) => (
12
+ <Transfer
13
+ filterable
14
+ initialSearchTerm="Foobarbaz"
15
+ selected={selected}
16
+ onChange={onChange}
17
+ sourceEmptyPlaceholder={<span data-test="no-results">No results</span>}
18
+ options={options}
19
+ />
20
+ )
21
+
22
+ export const SomeResults = (_, { selected, onChange }) => (
23
+ <Transfer
24
+ selected={selected}
25
+ filterable
26
+ initialSearchTerm="ANC"
27
+ onChange={onChange}
28
+ options={options}
29
+ />
30
+ )
31
+
32
+ export const UppercaseSearch = (_, { selected, onChange }) => (
33
+ <Transfer
34
+ selected={selected}
35
+ filterable
36
+ initialSearchTerm="ANC"
37
+ onChange={onChange}
38
+ options={options}
39
+ />
40
+ )
41
+
42
+ export const LowercaseSearch = (_, { selected, onChange }) => (
43
+ <Transfer
44
+ filterable
45
+ initialSearchTerm="anc"
46
+ selected={selected}
47
+ onChange={onChange}
48
+ options={options}
49
+ />
50
+ )
51
+
52
+ export const AncCustomFilter = (_, { selected, onChange }) => (
53
+ <Transfer
54
+ filterable
55
+ selected={selected}
56
+ onChange={onChange}
57
+ filterCallback={(options, filter) =>
58
+ options.filter(({ label }) => label.match(`(^| )ANC .*${filter}`))
59
+ }
60
+ options={options}
61
+ />
62
+ )
63
+
64
+ window.customFilterCallback = (options, filter) => {
65
+ return options.filter(({ label }) => label.indexOf(filter) !== -1)
66
+ }
67
+
68
+ window.Cypress && window.Cypress.cy.spy(window, 'customFilterCallback')
69
+
70
+ export const ControlledFilter = (
71
+ _,
72
+ { filter, onChange, onFilterChange, selected }
73
+ ) => (
74
+ <Transfer
75
+ selected={selected}
76
+ onChange={onChange}
77
+ filterable
78
+ filterCallback={window.customFilterCallback}
79
+ searchTerm={filter}
80
+ onFilterChange={onFilterChange}
81
+ options={options}
82
+ />
83
+ )
84
+
85
+ ControlledFilter.story = {
86
+ decorators: [statefulDecorator()],
87
+ }
@@ -0,0 +1,52 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer highlight range of options',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const HasOptions = (_, { onChange, selected }) => (
12
+ <Transfer
13
+ filterable
14
+ selected={selected}
15
+ onChange={onChange}
16
+ options={options}
17
+ />
18
+ )
19
+
20
+ export const HasSelected = (_, { onChange, selected }) => (
21
+ <Transfer
22
+ filterable
23
+ onChange={onChange}
24
+ selected={selected}
25
+ options={options}
26
+ />
27
+ )
28
+
29
+ HasSelected.story = {
30
+ decorators: [
31
+ statefulDecorator({
32
+ initialState: options.slice(0, 4).map(({ value }) => value),
33
+ }),
34
+ ],
35
+ }
36
+
37
+ export const AllSelected = (_, { onChange, selected }) => (
38
+ <Transfer
39
+ filterable
40
+ onChange={onChange}
41
+ selected={selected}
42
+ options={options}
43
+ />
44
+ )
45
+
46
+ AllSelected.story = {
47
+ decorators: [
48
+ statefulDecorator({
49
+ initialState: options.map(({ value }) => value),
50
+ }),
51
+ ],
52
+ }
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+
5
+ export default { title: 'Transfer Loading Lists' }
6
+
7
+ export const LoadingSource = () => (
8
+ <Transfer loading selected={[]} onChange={() => null} options={options} />
9
+ )
10
+
11
+ export const LoadingPicked = () => (
12
+ <Transfer
13
+ loadingPicked
14
+ selected={[]}
15
+ onChange={() => null}
16
+ options={options}
17
+ />
18
+ )
19
+
20
+ export const NotLoadingSource = () => (
21
+ <Transfer selected={[]} onChange={() => null} options={options} />
22
+ )
23
+
24
+ export const NotLoadingPicked = () => (
25
+ <Transfer selected={[]} onChange={() => null} options={options} />
26
+ )
@@ -0,0 +1,116 @@
1
+ import React, { useMemo, useState } from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer End Of List',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ window.onEndReached = window.Cypress
12
+ ? window.Cypress.cy.stub()
13
+ : () => console.log('onEndReached')
14
+
15
+ window.onEndReachedPicked = window.Cypress
16
+ ? window.Cypress.cy.stub()
17
+ : () => console.log('onEndReachedPicked')
18
+
19
+ export const FullSourceList = (_, { selected, onChange }) => (
20
+ <Transfer
21
+ options={options}
22
+ selected={selected}
23
+ onChange={onChange}
24
+ onEndReached={window.onEndReached}
25
+ />
26
+ )
27
+
28
+ export const FullPickedList = (_, { selected, onChange }) => (
29
+ <Transfer
30
+ options={options}
31
+ selected={selected}
32
+ onChange={onChange}
33
+ onEndReachedPicked={window.onEndReachedPicked}
34
+ />
35
+ )
36
+
37
+ FullPickedList.story = {
38
+ decorators: [
39
+ statefulDecorator({
40
+ initialState: options.map(({ value }) => value),
41
+ }),
42
+ ],
43
+ }
44
+
45
+ export const PartialSourceList = (_, { selected, onChange }) => (
46
+ <Transfer
47
+ options={options.slice(0, 4)}
48
+ selected={selected}
49
+ onChange={onChange}
50
+ onEndReached={window.onEndReached}
51
+ />
52
+ )
53
+
54
+ export const PartialPickedList = (_, { selected, onChange }) => (
55
+ <Transfer
56
+ options={options}
57
+ selected={selected}
58
+ onChange={onChange}
59
+ onEndReachedPicked={window.onEndReachedPicked}
60
+ />
61
+ )
62
+
63
+ PartialPickedList.story = {
64
+ decorators: [
65
+ statefulDecorator({
66
+ initialState: options.slice(0, 4).map(({ value }) => value),
67
+ }),
68
+ ],
69
+ }
70
+
71
+ const selectedOptionsLookup = {
72
+ 'val-9': {
73
+ value: 'val-9',
74
+ label: 'Option nr. 9',
75
+ },
76
+ }
77
+
78
+ export const OptionChangesForShortList = (_, { onChange, selected }) => {
79
+ const [optionsCount, setOptionsCount] = useState(7)
80
+ const myOptions = useMemo(() => {
81
+ let counter = 1
82
+ const newOptions = []
83
+ while (counter <= optionsCount) {
84
+ newOptions.push({
85
+ value: `val-${counter}`,
86
+ label: `Option nr. ${counter}`,
87
+ })
88
+ counter++
89
+ }
90
+ return newOptions
91
+ }, [optionsCount])
92
+
93
+ return (
94
+ <>
95
+ <button onClick={() => setOptionsCount((curr) => curr + 1)}>
96
+ Increment options lists
97
+ </button>
98
+ <Transfer
99
+ filterable
100
+ selected={selected}
101
+ selectedOptionsLookup={selectedOptionsLookup}
102
+ onChange={onChange}
103
+ options={myOptions}
104
+ onEndReached={window.onEndReached}
105
+ onEndReachedPicked={window.onEndReachedPicked}
106
+ />
107
+ </>
108
+ )
109
+ }
110
+ OptionChangesForShortList.story = {
111
+ decorators: [
112
+ statefulDecorator({
113
+ initialState: ['val-9'],
114
+ }),
115
+ ],
116
+ }
@@ -0,0 +1,35 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default { title: 'Transfer Reorder Buttons' }
7
+
8
+ const renderReorderTransfer = (_, { selected, onChange }) => (
9
+ <Transfer
10
+ enableOrderChange
11
+ selected={selected}
12
+ onChange={onChange}
13
+ options={options}
14
+ />
15
+ )
16
+
17
+ export const HasSomeSelected = renderReorderTransfer.bind({})
18
+
19
+ HasSomeSelected.story = {
20
+ decorators: [
21
+ statefulDecorator({
22
+ initialState: options.slice(0, 8).map(({ value }) => value),
23
+ }),
24
+ ],
25
+ }
26
+
27
+ export const HasThreeSelected = renderReorderTransfer.bind({})
28
+
29
+ HasThreeSelected.story = {
30
+ decorators: [
31
+ statefulDecorator({
32
+ initialState: options.slice(0, 3).map(({ value }) => value),
33
+ }),
34
+ ],
35
+ }
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer set & unset higlighted options',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ export const HasOptions = (_, { onChange, selected }) => (
12
+ <Transfer
13
+ filterable
14
+ selected={selected}
15
+ onChange={onChange}
16
+ options={options}
17
+ />
18
+ )
19
+
20
+ export const HasSelected = (_, { onChange, selected }) => (
21
+ <Transfer onChange={onChange} selected={selected} options={options} />
22
+ )
23
+
24
+ HasSelected.story = {
25
+ decorators: [
26
+ statefulDecorator({
27
+ initialState: options.slice(0, 4).map(({ value }) => value),
28
+ }),
29
+ ],
30
+ }
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+ import { Transfer } from '../transfer.js'
3
+ import { options } from './common/options.js'
4
+ import { statefulDecorator } from './common/stateful-decorator.js'
5
+
6
+ export default {
7
+ title: 'Transfer Transferring Items',
8
+ decorators: [statefulDecorator()],
9
+ }
10
+
11
+ window.options = options
12
+
13
+ export const HasOptions = (_, { selected, onChange }) => (
14
+ <Transfer selected={selected} onChange={onChange} options={options} />
15
+ )
16
+
17
+ export const SomeSelected = (_, { selected, onChange }) => (
18
+ <Transfer selected={selected} onChange={onChange} options={options} />
19
+ )
20
+
21
+ SomeSelected.story = {
22
+ decorators: [
23
+ statefulDecorator({
24
+ initialState: options.slice(0, 4).map(({ value }) => value),
25
+ }),
26
+ ],
27
+ }