@atlaskit/dropdown-menu 10.1.8 → 11.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +148 -0
- package/__perf__/default.tsx +1 -1
- package/__perf__/dropdown-menu.tsx +216 -0
- package/codemods/11.0.0-lite-mode.tsx +39 -0
- package/codemods/__tests__/11.0.0-lite-mode.test.tsx +48 -0
- package/codemods/__tests__/convert-position.test.tsx +88 -0
- package/codemods/__tests__/convert-triggerType.test.tsx +100 -0
- package/codemods/__tests__/deprecate-items.test.tsx +108 -0
- package/codemods/__tests__/deprecate-onItemActivated.test.tsx +108 -0
- package/codemods/__tests__/deprecate-onPositioned.test.tsx +108 -0
- package/codemods/__tests__/deprecate-shouldFitContainer.tsx +108 -0
- package/codemods/__tests__/rename-imports.tsx +136 -0
- package/codemods/__tests__/replace-position-to-placement.test.tsx +84 -0
- package/codemods/__tests__/replace-shouldAllowMultipleLine.test.tsx +122 -0
- package/codemods/__tests__/update-component-callsites.tsx +66 -0
- package/codemods/migrates/convert-trigger-type.tsx +57 -0
- package/codemods/migrates/deprecate-items.tsx +9 -0
- package/codemods/migrates/deprecate-onItemActivated.tsx +9 -0
- package/codemods/migrates/deprecate-onPositioned.tsx +9 -0
- package/codemods/migrates/deprecate-shouldFitContainer.tsx +9 -0
- package/codemods/migrates/rename-imports.tsx +22 -0
- package/codemods/migrates/replace-position-to-placement.tsx +38 -0
- package/codemods/migrates/replace-shouldAllowMultiline.tsx +47 -0
- package/codemods/migrates/update-component-callsites.tsx +13 -0
- package/codemods/utils/convert-position.tsx +24 -0
- package/codemods/utils/create-rename-import.tsx +41 -0
- package/codemods/utils/create-update-callsite.tsx +32 -0
- package/dist/cjs/checkbox/dropdown-item-checkbox-group.js +31 -0
- package/dist/cjs/checkbox/dropdown-item-checkbox.js +108 -0
- package/dist/cjs/dropdown-menu-item-group.js +22 -0
- package/dist/cjs/dropdown-menu-item.js +67 -0
- package/dist/cjs/dropdown-menu.js +194 -0
- package/dist/cjs/index.js +21 -29
- package/dist/cjs/{components/item/DropdownItemRadio.js → internal/components/focus-manager.js} +40 -9
- package/dist/cjs/internal/components/menu-wrapper.js +68 -0
- package/dist/cjs/internal/context/checkbox-group-context.js +14 -0
- package/dist/cjs/internal/context/selection-store.js +76 -0
- package/dist/cjs/internal/hooks/use-checkbox-state.js +68 -0
- package/dist/cjs/internal/hooks/use-radio-state.js +84 -0
- package/dist/cjs/internal/hooks/use-register-item-with-focus-manager.js +29 -0
- package/dist/cjs/internal/utils/get-icon-colors.js +25 -0
- package/dist/cjs/internal/utils/handle-focus.js +58 -0
- package/dist/cjs/internal/utils/is-checkbox-item.js +11 -0
- package/dist/cjs/internal/utils/is-radio-item.js +11 -0
- package/dist/cjs/internal/utils/is-voice-over-supported.js +23 -0
- package/dist/cjs/internal/utils/reset-options-in-group.js +23 -0
- package/dist/cjs/radio/dropdown-item-radio-group.js +89 -0
- package/dist/cjs/radio/dropdown-item-radio.js +108 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/checkbox/dropdown-item-checkbox-group.js +21 -0
- package/dist/es2019/checkbox/dropdown-item-checkbox.js +67 -0
- package/dist/es2019/dropdown-menu-item-group.js +11 -0
- package/dist/es2019/dropdown-menu-item.js +49 -0
- package/dist/es2019/dropdown-menu.js +151 -0
- package/dist/es2019/index.js +7 -11
- package/dist/es2019/internal/components/focus-manager.js +40 -0
- package/dist/es2019/internal/components/menu-wrapper.js +44 -0
- package/dist/es2019/internal/context/checkbox-group-context.js +6 -0
- package/dist/es2019/internal/context/selection-store.js +54 -0
- package/dist/es2019/internal/hooks/use-checkbox-state.js +45 -0
- package/dist/es2019/internal/hooks/use-radio-state.js +56 -0
- package/dist/es2019/internal/hooks/use-register-item-with-focus-manager.js +19 -0
- package/dist/es2019/internal/utils/get-icon-colors.js +17 -0
- package/dist/es2019/internal/utils/handle-focus.js +48 -0
- package/dist/es2019/internal/utils/is-checkbox-item.js +4 -0
- package/dist/es2019/internal/utils/is-radio-item.js +4 -0
- package/dist/es2019/internal/utils/is-voice-over-supported.js +11 -0
- package/dist/es2019/internal/utils/reset-options-in-group.js +7 -0
- package/dist/es2019/radio/dropdown-item-radio-group.js +56 -0
- package/dist/es2019/radio/dropdown-item-radio.js +67 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/checkbox/dropdown-item-checkbox-group.js +19 -0
- package/dist/esm/checkbox/dropdown-item-checkbox.js +81 -0
- package/dist/esm/dropdown-menu-item-group.js +11 -0
- package/dist/esm/dropdown-menu-item.js +52 -0
- package/dist/esm/dropdown-menu.js +168 -0
- package/dist/esm/index.js +7 -11
- package/dist/esm/internal/components/focus-manager.js +39 -0
- package/dist/esm/internal/components/menu-wrapper.js +45 -0
- package/dist/esm/internal/context/checkbox-group-context.js +6 -0
- package/dist/esm/internal/context/selection-store.js +58 -0
- package/dist/esm/internal/hooks/use-checkbox-state.js +55 -0
- package/dist/esm/internal/hooks/use-radio-state.js +70 -0
- package/dist/esm/internal/hooks/use-register-item-with-focus-manager.js +19 -0
- package/dist/esm/internal/utils/get-icon-colors.js +17 -0
- package/dist/esm/internal/utils/handle-focus.js +47 -0
- package/dist/esm/internal/utils/is-checkbox-item.js +4 -0
- package/dist/esm/internal/utils/is-radio-item.js +4 -0
- package/dist/esm/internal/utils/is-voice-over-supported.js +15 -0
- package/dist/esm/internal/utils/reset-options-in-group.js +13 -0
- package/dist/esm/radio/dropdown-item-radio-group.js +66 -0
- package/dist/esm/radio/dropdown-item-radio.js +81 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/checkbox/dropdown-item-checkbox-group.d.ts +16 -0
- package/dist/types/checkbox/dropdown-item-checkbox.d.ts +13 -0
- package/dist/types/dropdown-menu-item-group.d.ts +11 -0
- package/dist/types/dropdown-menu-item.d.ts +13 -0
- package/dist/types/dropdown-menu.d.ts +13 -0
- package/dist/types/index.d.ts +8 -10
- package/dist/types/internal/components/focus-manager.d.ts +19 -0
- package/dist/types/internal/components/menu-wrapper.d.ts +11 -0
- package/dist/types/internal/context/checkbox-group-context.d.ts +5 -0
- package/dist/types/internal/context/selection-store.d.ts +27 -0
- package/dist/types/internal/hooks/use-checkbox-state.d.ts +14 -0
- package/dist/types/internal/hooks/use-radio-state.d.ts +9 -0
- package/dist/types/internal/hooks/use-register-item-with-focus-manager.d.ts +4 -0
- package/dist/types/internal/utils/get-icon-colors.d.ts +8 -0
- package/dist/types/internal/utils/handle-focus.d.ts +2 -0
- package/dist/types/internal/utils/is-checkbox-item.d.ts +1 -0
- package/dist/types/internal/utils/is-radio-item.d.ts +1 -0
- package/dist/types/internal/utils/is-voice-over-supported.d.ts +2 -0
- package/dist/types/internal/utils/reset-options-in-group.d.ts +4 -0
- package/dist/types/radio/dropdown-item-radio-group.d.ts +25 -0
- package/dist/types/radio/dropdown-item-radio.d.ts +13 -0
- package/dist/types/types.d.ts +254 -79
- package/package.json +39 -23
- package/dist/cjs/components/DropdownMenu.js +0 -230
- package/dist/cjs/components/DropdownMenuStateless.js +0 -523
- package/dist/cjs/components/context/DropdownItemClickManager.js +0 -72
- package/dist/cjs/components/context/DropdownItemFocusManager.js +0 -178
- package/dist/cjs/components/context/DropdownItemSelectionCache.js +0 -131
- package/dist/cjs/components/context/DropdownItemSelectionManager.js +0 -185
- package/dist/cjs/components/group/DropdownItemGroup.js +0 -61
- package/dist/cjs/components/group/DropdownItemGroupCheckbox.js +0 -16
- package/dist/cjs/components/group/DropdownItemGroupRadio.js +0 -16
- package/dist/cjs/components/group/ert-group-selection.js +0 -8
- package/dist/cjs/components/hoc/withItemSelectionManager.js +0 -66
- package/dist/cjs/components/hoc/withToggleInteraction.js +0 -175
- package/dist/cjs/components/item/DropdownItem.js +0 -19
- package/dist/cjs/components/item/DropdownItemCheckbox.js +0 -28
- package/dist/cjs/components/item/ert-item-checkbox.js +0 -8
- package/dist/cjs/components/item/ert-item-radio.js +0 -8
- package/dist/cjs/components/item/ert-item.js +0 -8
- package/dist/cjs/styled/WidthConstrainer.js +0 -21
- package/dist/cjs/util/contextNamespace.js +0 -19
- package/dist/cjs/util/getDisplayName.js +0 -14
- package/dist/cjs/util/keys.js +0 -18
- package/dist/cjs/util/safeContextCall.js +0 -27
- package/dist/cjs/util/supportsVoiceover.js +0 -17
- package/dist/es2019/components/DropdownMenu.js +0 -156
- package/dist/es2019/components/DropdownMenuStateless.js +0 -459
- package/dist/es2019/components/context/DropdownItemClickManager.js +0 -31
- package/dist/es2019/components/context/DropdownItemFocusManager.js +0 -134
- package/dist/es2019/components/context/DropdownItemSelectionCache.js +0 -68
- package/dist/es2019/components/context/DropdownItemSelectionManager.js +0 -140
- package/dist/es2019/components/group/DropdownItemGroup.js +0 -17
- package/dist/es2019/components/group/DropdownItemGroupCheckbox.js +0 -3
- package/dist/es2019/components/group/DropdownItemGroupRadio.js +0 -3
- package/dist/es2019/components/group/ert-group-selection.js +0 -1
- package/dist/es2019/components/hoc/withItemSelectionManager.js +0 -20
- package/dist/es2019/components/hoc/withToggleInteraction.js +0 -119
- package/dist/es2019/components/item/DropdownItem.js +0 -3
- package/dist/es2019/components/item/DropdownItemCheckbox.js +0 -5
- package/dist/es2019/components/item/DropdownItemRadio.js +0 -5
- package/dist/es2019/components/item/ert-item-checkbox.js +0 -1
- package/dist/es2019/components/item/ert-item-radio.js +0 -1
- package/dist/es2019/components/item/ert-item.js +0 -1
- package/dist/es2019/styled/WidthConstrainer.js +0 -6
- package/dist/es2019/util/contextNamespace.js +0 -6
- package/dist/es2019/util/getDisplayName.js +0 -4
- package/dist/es2019/util/keys.js +0 -6
- package/dist/es2019/util/safeContextCall.js +0 -10
- package/dist/es2019/util/supportsVoiceover.js +0 -5
- package/dist/esm/components/DropdownMenu.js +0 -215
- package/dist/esm/components/DropdownMenuStateless.js +0 -516
- package/dist/esm/components/context/DropdownItemClickManager.js +0 -59
- package/dist/esm/components/context/DropdownItemFocusManager.js +0 -164
- package/dist/esm/components/context/DropdownItemSelectionCache.js +0 -113
- package/dist/esm/components/context/DropdownItemSelectionManager.js +0 -174
- package/dist/esm/components/group/DropdownItemGroup.js +0 -43
- package/dist/esm/components/group/DropdownItemGroupCheckbox.js +0 -3
- package/dist/esm/components/group/DropdownItemGroupRadio.js +0 -3
- package/dist/esm/components/group/ert-group-selection.js +0 -1
- package/dist/esm/components/hoc/withItemSelectionManager.js +0 -47
- package/dist/esm/components/hoc/withToggleInteraction.js +0 -155
- package/dist/esm/components/item/DropdownItem.js +0 -3
- package/dist/esm/components/item/DropdownItemCheckbox.js +0 -7
- package/dist/esm/components/item/DropdownItemRadio.js +0 -7
- package/dist/esm/components/item/ert-item-checkbox.js +0 -1
- package/dist/esm/components/item/ert-item-radio.js +0 -1
- package/dist/esm/components/item/ert-item.js +0 -1
- package/dist/esm/styled/WidthConstrainer.js +0 -9
- package/dist/esm/util/contextNamespace.js +0 -8
- package/dist/esm/util/getDisplayName.js +0 -6
- package/dist/esm/util/keys.js +0 -6
- package/dist/esm/util/safeContextCall.js +0 -18
- package/dist/esm/util/supportsVoiceover.js +0 -9
- package/dist/types/components/DropdownMenu.d.ts +0 -36
- package/dist/types/components/DropdownMenuStateless.d.ts +0 -82
- package/dist/types/components/context/DropdownItemClickManager.d.ts +0 -19
- package/dist/types/components/context/DropdownItemFocusManager.d.ts +0 -35
- package/dist/types/components/context/DropdownItemSelectionCache.d.ts +0 -31
- package/dist/types/components/context/DropdownItemSelectionManager.d.ts +0 -34
- package/dist/types/components/group/DropdownItemGroup.d.ts +0 -12
- package/dist/types/components/group/DropdownItemGroupCheckbox.d.ts +0 -55
- package/dist/types/components/group/DropdownItemGroupRadio.d.ts +0 -55
- package/dist/types/components/group/ert-group-selection.d.ts +0 -6
- package/dist/types/components/hoc/withItemSelectionManager.d.ts +0 -63
- package/dist/types/components/hoc/withToggleInteraction.d.ts +0 -98
- package/dist/types/components/item/DropdownItem.d.ts +0 -65
- package/dist/types/components/item/DropdownItemCheckbox.d.ts +0 -80
- package/dist/types/components/item/DropdownItemRadio.d.ts +0 -80
- package/dist/types/components/item/ert-item-checkbox.d.ts +0 -2
- package/dist/types/components/item/ert-item-radio.d.ts +0 -2
- package/dist/types/components/item/ert-item.d.ts +0 -2
- package/dist/types/styled/WidthConstrainer.d.ts +0 -7
- package/dist/types/util/contextNamespace.d.ts +0 -4
- package/dist/types/util/getDisplayName.d.ts +0 -3
- package/dist/types/util/keys.d.ts +0 -6
- package/dist/types/util/safeContextCall.d.ts +0 -6
- package/dist/types/util/supportsVoiceover.d.ts +0 -2
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import React, { Component } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { selectionCacheContext, selectionManagerContext } from '../../util/contextNamespace';
|
|
5
|
-
export default class DropdownItemSelectionManager extends Component {
|
|
6
|
-
constructor(...args) {
|
|
7
|
-
super(...args);
|
|
8
|
-
|
|
9
|
-
_defineProperty(this, "setItemSelected", (itemId, isSelected, defaultSelected) => {
|
|
10
|
-
const {
|
|
11
|
-
behavior,
|
|
12
|
-
groupId
|
|
13
|
-
} = this.props;
|
|
14
|
-
|
|
15
|
-
const setSelected = finalBool => {
|
|
16
|
-
if (behavior === 'checkbox' || behavior === 'menuitemcheckbox') {
|
|
17
|
-
this.setCheckboxItemSelected(itemId, finalBool);
|
|
18
|
-
} else if (behavior === 'radio' || behavior === 'menuitemradio') {
|
|
19
|
-
this.setRadioItemSelected(itemId, finalBool);
|
|
20
|
-
}
|
|
21
|
-
}; // If a radio or checkbox item has defaultSelected set on it, that it will try to set its
|
|
22
|
-
// selected state to true each time it mounts (which happens whenever the dropdown is re-
|
|
23
|
-
// opened by the user. The following check makes sure that the defaultSelected behaviour
|
|
24
|
-
// only applies on the first mount of the radio/checkbox.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (typeof isSelected === 'boolean') {
|
|
28
|
-
// If isSelected is explicitly provided, set it to that
|
|
29
|
-
setSelected(isSelected);
|
|
30
|
-
} else if (defaultSelected) {
|
|
31
|
-
if (!this.hasAlreadyAppliedDefaultSelected(itemId)) {
|
|
32
|
-
// If using defaultSelected and this is first mount, select the item
|
|
33
|
-
setSelected(true);
|
|
34
|
-
this.context[selectionCacheContext].markItemAsDefaultApplied(groupId, itemId);
|
|
35
|
-
} else {
|
|
36
|
-
// If using defaultSelected and not first mount, set isSelected to cached value
|
|
37
|
-
setSelected(this.isItemSelectedInCache(itemId));
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
setSelected(this.isItemSelectedInCache(itemId));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
_defineProperty(this, "setCheckboxItemSelected", (itemId, isSelected) => {
|
|
45
|
-
const {
|
|
46
|
-
[selectionCacheContext]: cache
|
|
47
|
-
} = this.context;
|
|
48
|
-
const alreadySelected = cache.itemsInGroup(this.props.groupId);
|
|
49
|
-
const isAlreadySelected = cache.isItemSelected(this.props.groupId, itemId);
|
|
50
|
-
|
|
51
|
-
if (isSelected && !isAlreadySelected) {
|
|
52
|
-
this.updateCacheContextWithSelections([...alreadySelected, {
|
|
53
|
-
id: itemId,
|
|
54
|
-
groupId: this.props.groupId
|
|
55
|
-
}]);
|
|
56
|
-
} else if (!isSelected && isAlreadySelected) {
|
|
57
|
-
const withoutCurrentItem = alreadySelected.filter(item => item.id !== itemId);
|
|
58
|
-
this.updateCacheContextWithSelections(withoutCurrentItem);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
_defineProperty(this, "setRadioItemSelected", (itemId, isSelected) => {
|
|
63
|
-
const {
|
|
64
|
-
[selectionCacheContext]: cache
|
|
65
|
-
} = this.context;
|
|
66
|
-
const isAlreadySelected = cache.isItemSelected(this.props.groupId, itemId);
|
|
67
|
-
|
|
68
|
-
if (isAlreadySelected && !isSelected) {
|
|
69
|
-
this.updateCacheContextWithSelections([]);
|
|
70
|
-
} else if (!isAlreadySelected && isSelected) {
|
|
71
|
-
this.updateCacheContextWithSelections([{
|
|
72
|
-
id: itemId,
|
|
73
|
-
groupId: this.props.groupId
|
|
74
|
-
}]);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
_defineProperty(this, "isItemSelectedInCache", itemId => this.context[selectionCacheContext].isItemSelected(this.props.groupId, itemId));
|
|
79
|
-
|
|
80
|
-
_defineProperty(this, "handleItemClicked", clickedItemId => {
|
|
81
|
-
const {
|
|
82
|
-
behavior
|
|
83
|
-
} = this.props;
|
|
84
|
-
|
|
85
|
-
if (behavior === 'checkbox' || behavior === 'menuitemcheckbox') {
|
|
86
|
-
this.handleCheckboxItemClicked(clickedItemId);
|
|
87
|
-
} else if (behavior === 'radio' || behavior === 'menuitemradio') {
|
|
88
|
-
this.handleRadioItemClicked(clickedItemId);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
_defineProperty(this, "hasAlreadyAppliedDefaultSelected", itemId => this.context[selectionCacheContext].hasItemAlreadyHadDefaultSelectedApplied(this.props.groupId, itemId));
|
|
93
|
-
|
|
94
|
-
_defineProperty(this, "handleCheckboxItemClicked", clickedItemId => {
|
|
95
|
-
const {
|
|
96
|
-
[selectionCacheContext]: cache
|
|
97
|
-
} = this.context;
|
|
98
|
-
const itemsInGroup = cache.itemsInGroup(this.props.groupId);
|
|
99
|
-
const newSelections = cache.isItemSelected(this.props.groupId, clickedItemId) ? itemsInGroup.filter(item => item.id !== clickedItemId) : [...itemsInGroup, {
|
|
100
|
-
id: clickedItemId,
|
|
101
|
-
groupId: this.props.groupId
|
|
102
|
-
}];
|
|
103
|
-
this.updateCacheContextWithSelections(newSelections);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
_defineProperty(this, "handleRadioItemClicked", clickedItemId => {
|
|
107
|
-
this.updateCacheContextWithSelections([{
|
|
108
|
-
id: clickedItemId,
|
|
109
|
-
groupId: this.props.groupId
|
|
110
|
-
}]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
_defineProperty(this, "updateCacheContextWithSelections", itemSelections => {
|
|
114
|
-
this.context[selectionCacheContext].itemSelectionsChanged(this.props.groupId, itemSelections);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getChildContext() {
|
|
119
|
-
return {
|
|
120
|
-
[selectionManagerContext]: {
|
|
121
|
-
isItemSelected: itemId => this.context[selectionCacheContext].isItemSelected(this.props.groupId, itemId),
|
|
122
|
-
itemClicked: this.handleItemClicked,
|
|
123
|
-
setItemSelected: this.setItemSelected
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
render() {
|
|
129
|
-
return /*#__PURE__*/React.createElement("div", null, this.props.children);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
_defineProperty(DropdownItemSelectionManager, "childContextTypes", {
|
|
135
|
-
[selectionManagerContext]: PropTypes.object
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
_defineProperty(DropdownItemSelectionManager, "contextTypes", {
|
|
139
|
-
[selectionCacheContext]: PropTypes.object.isRequired
|
|
140
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import { ItemGroup } from '@atlaskit/item';
|
|
3
|
-
export default class DropdownItemGroup extends Component {
|
|
4
|
-
render() {
|
|
5
|
-
const {
|
|
6
|
-
children,
|
|
7
|
-
elemAfter,
|
|
8
|
-
title
|
|
9
|
-
} = this.props;
|
|
10
|
-
return /*#__PURE__*/React.createElement(ItemGroup, {
|
|
11
|
-
elemAfter: elemAfter,
|
|
12
|
-
title: title,
|
|
13
|
-
role: "menu"
|
|
14
|
-
}, children);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (_) {}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import DropdownItemSelectionManager from '../context/DropdownItemSelectionManager';
|
|
3
|
-
|
|
4
|
-
// HOC that typically wraps @atlaskit/item/ItemGroup
|
|
5
|
-
const withDropdownItemSelectionManager = (WrappedComponent, selectionBehavior) => class WithDropdownItemSelectionManager extends Component {
|
|
6
|
-
render() {
|
|
7
|
-
const {
|
|
8
|
-
children,
|
|
9
|
-
id,
|
|
10
|
-
...otherProps
|
|
11
|
-
} = this.props;
|
|
12
|
-
return /*#__PURE__*/React.createElement(WrappedComponent, otherProps, /*#__PURE__*/React.createElement(DropdownItemSelectionManager, {
|
|
13
|
-
groupId: id,
|
|
14
|
-
behavior: selectionBehavior
|
|
15
|
-
}, children));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default withDropdownItemSelectionManager;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import React, { Component } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { B400, N40 } from '@atlaskit/theme/colors';
|
|
5
|
-
import { selectionManagerContext } from '../../util/contextNamespace';
|
|
6
|
-
import getDisplayName from '../../util/getDisplayName';
|
|
7
|
-
import { KEY_ENTER, KEY_SPACE } from '../../util/keys';
|
|
8
|
-
import safeContextCall from '../../util/safeContextCall';
|
|
9
|
-
|
|
10
|
-
// HOC that typically wraps @atlaskit/item
|
|
11
|
-
const withToggleInteraction = (WrappedComponent, SelectionIcon, getAriaRole) => {
|
|
12
|
-
var _class, _temp;
|
|
13
|
-
|
|
14
|
-
return _temp = _class = class WithToggleInteraction extends Component {
|
|
15
|
-
constructor(...args) {
|
|
16
|
-
super(...args);
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "getIconColors", (isSelected = false) => {
|
|
19
|
-
if (isSelected) {
|
|
20
|
-
return {
|
|
21
|
-
primary: B400,
|
|
22
|
-
secondary: N40
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
primary: N40,
|
|
28
|
-
secondary: N40
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
_defineProperty(this, "warnIfUseControlledAndUncontrolledState", () => {
|
|
33
|
-
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
34
|
-
if (this.props.defaultSelected && this.props.isSelected) {
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
console.warn('DropdownItem defaultSelected and isSelected props should not be used at the same time.');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
_defineProperty(this, "callContextFn", safeContextCall(this, selectionManagerContext));
|
|
42
|
-
|
|
43
|
-
_defineProperty(this, "handleKeyboard", event => {
|
|
44
|
-
const {
|
|
45
|
-
key
|
|
46
|
-
} = event;
|
|
47
|
-
|
|
48
|
-
if (key === KEY_ENTER || key === KEY_SPACE) {
|
|
49
|
-
// We prevent default here to avoid page scroll
|
|
50
|
-
event.preventDefault();
|
|
51
|
-
this.handleItemActivated(event);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
_defineProperty(this, "handleItemActivated", event => {
|
|
56
|
-
if (this.props.onClick) {
|
|
57
|
-
this.props.onClick(event);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.callContextFn('itemClicked', this.props.id);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
_defineProperty(this, "isSelectedInDropdown", () => this.callContextFn('isItemSelected', this.props.id));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
componentDidMount() {
|
|
67
|
-
const {
|
|
68
|
-
defaultSelected,
|
|
69
|
-
isSelected,
|
|
70
|
-
id
|
|
71
|
-
} = this.props;
|
|
72
|
-
this.warnIfUseControlledAndUncontrolledState();
|
|
73
|
-
this.callContextFn('setItemSelected', id, isSelected, defaultSelected);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
77
|
-
const {
|
|
78
|
-
id,
|
|
79
|
-
defaultSelected,
|
|
80
|
-
isSelected
|
|
81
|
-
} = nextProps;
|
|
82
|
-
|
|
83
|
-
if (this.props.isSelected !== isSelected) {
|
|
84
|
-
this.callContextFn('setItemSelected', id, isSelected, defaultSelected);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
render() {
|
|
89
|
-
const {
|
|
90
|
-
children,
|
|
91
|
-
...otherProps
|
|
92
|
-
} = this.props;
|
|
93
|
-
const isSelected = this.isSelectedInDropdown();
|
|
94
|
-
const iconColors = this.getIconColors(!!isSelected);
|
|
95
|
-
const ariaRole = getAriaRole();
|
|
96
|
-
const wrappedCompProps = { ...otherProps,
|
|
97
|
-
role: ariaRole,
|
|
98
|
-
'aria-checked': isSelected,
|
|
99
|
-
isSelected: isSelected,
|
|
100
|
-
onClick: this.handleItemActivated,
|
|
101
|
-
onKeyDown: this.handleKeyboard,
|
|
102
|
-
elemBefore: /*#__PURE__*/React.createElement(SelectionIcon, {
|
|
103
|
-
primaryColor: iconColors.primary,
|
|
104
|
-
secondaryColor: iconColors.secondary,
|
|
105
|
-
size: "medium",
|
|
106
|
-
label: ""
|
|
107
|
-
})
|
|
108
|
-
};
|
|
109
|
-
return /*#__PURE__*/React.createElement(WrappedComponent, wrappedCompProps, children);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}, _defineProperty(_class, "displayName", `WithToggleInteraction(${getDisplayName(WrappedComponent)})`), _defineProperty(_class, "defaultProps", {
|
|
113
|
-
onClick: () => {}
|
|
114
|
-
}), _defineProperty(_class, "contextTypes", {
|
|
115
|
-
[selectionManagerContext]: PropTypes.object.isRequired
|
|
116
|
-
}), _temp;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export default withToggleInteraction;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import CheckboxIcon from '@atlaskit/icon/glyph/checkbox';
|
|
2
|
-
import Item, { withItemFocus } from '@atlaskit/item';
|
|
3
|
-
import supportsVoiceover from '../../util/supportsVoiceover';
|
|
4
|
-
import withToggleInteraction from '../hoc/withToggleInteraction';
|
|
5
|
-
export default withToggleInteraction(withItemFocus(Item), CheckboxIcon, () => supportsVoiceover() ? 'checkbox' : 'menuitemcheckbox');
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import RadioIcon from '@atlaskit/icon/glyph/radio';
|
|
2
|
-
import Item, { withItemFocus } from '@atlaskit/item';
|
|
3
|
-
import supportsVoiceover from '../../util/supportsVoiceover';
|
|
4
|
-
import withToggleInteraction from '../hoc/withToggleInteraction';
|
|
5
|
-
export default withToggleInteraction(withItemFocus(Item), RadioIcon, () => supportsVoiceover() ? 'radio' : 'menuitemradio');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (_) {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (_) {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (_) {}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
const prefix = key => `@atlaskit-private-do-not-use/dropdown-menu:${key}`;
|
|
2
|
-
|
|
3
|
-
export const focusManagerContext = prefix('focus-manager');
|
|
4
|
-
export const selectionCacheContext = prefix('selection-cache');
|
|
5
|
-
export const selectionManagerContext = prefix('selection-manager');
|
|
6
|
-
export const clickManagerContext = prefix('click-manager');
|
package/dist/es2019/util/keys.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// There are cases where the context is not available, such as when a dropdown item is used
|
|
2
|
-
// inside @atlaskit/navigation. For this reason we have this helper function which safely calls
|
|
3
|
-
// the context functions if they are available.
|
|
4
|
-
export default ((instance, contextKey) => (fnToCall, ...args) => {
|
|
5
|
-
if (!instance.context[contextKey]) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return instance.context[contextKey][fnToCall](...args);
|
|
10
|
-
});
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
5
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
|
-
|
|
10
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
-
|
|
12
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
-
|
|
14
|
-
import React, { Component } from 'react';
|
|
15
|
-
import StatelessMenu from './DropdownMenuStateless';
|
|
16
|
-
|
|
17
|
-
var DropdownMenu = /*#__PURE__*/function (_Component) {
|
|
18
|
-
_inherits(DropdownMenu, _Component);
|
|
19
|
-
|
|
20
|
-
var _super = _createSuper(DropdownMenu);
|
|
21
|
-
|
|
22
|
-
function DropdownMenu() {
|
|
23
|
-
var _this;
|
|
24
|
-
|
|
25
|
-
_classCallCheck(this, DropdownMenu);
|
|
26
|
-
|
|
27
|
-
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
28
|
-
_args[_key] = arguments[_key];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_this = _super.call.apply(_super, [this].concat(_args));
|
|
32
|
-
|
|
33
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
34
|
-
isOpen: _this.props.defaultOpen,
|
|
35
|
-
items: _toConsumableArray(_this.props.items)
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
_defineProperty(_assertThisInitialized(_this), "findActivatedGroup", function (item) {
|
|
39
|
-
return _this.state.items.filter(function (group) {
|
|
40
|
-
return group.items.indexOf(item) > -1;
|
|
41
|
-
})[0];
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
_defineProperty(_assertThisInitialized(_this), "handleItemActivation", function (attrs) {
|
|
45
|
-
var activatedItem = attrs.item;
|
|
46
|
-
|
|
47
|
-
var activatedGroup = _this.findActivatedGroup(activatedItem);
|
|
48
|
-
|
|
49
|
-
var items = _toConsumableArray(_this.state.items);
|
|
50
|
-
|
|
51
|
-
switch (activatedItem.type) {
|
|
52
|
-
case 'checkbox':
|
|
53
|
-
activatedItem.isChecked = !activatedItem.isChecked;
|
|
54
|
-
|
|
55
|
-
_this.props.onItemActivated({
|
|
56
|
-
item: activatedItem
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
_this.setState({
|
|
60
|
-
items: items
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case 'radio':
|
|
66
|
-
activatedGroup.items.forEach(function (i) {
|
|
67
|
-
if (i === activatedItem) {
|
|
68
|
-
i.isChecked = true; // eslint-disable-line no-param-reassign
|
|
69
|
-
} else {
|
|
70
|
-
i.isChecked = false; // eslint-disable-line no-param-reassign
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
_this.props.onItemActivated({
|
|
75
|
-
item: activatedItem
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
_this.setState({
|
|
79
|
-
items: items
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'link':
|
|
85
|
-
default:
|
|
86
|
-
_this.props.onItemActivated({
|
|
87
|
-
item: activatedItem
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
_this.close();
|
|
91
|
-
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
_defineProperty(_assertThisInitialized(_this), "handleOpenChange", function (attrs) {
|
|
97
|
-
var _this$props;
|
|
98
|
-
|
|
99
|
-
if (_this.state.isOpen === attrs.isOpen) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_this.setState({
|
|
104
|
-
isOpen: attrs.isOpen
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
108
|
-
args[_key2 - 1] = arguments[_key2];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
(_this$props = _this.props).onOpenChange.apply(_this$props, [attrs].concat(args));
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
_defineProperty(_assertThisInitialized(_this), "close", function () {
|
|
115
|
-
var _this$props2;
|
|
116
|
-
|
|
117
|
-
if (_this.state.isOpen === false) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_this.setState({
|
|
122
|
-
isOpen: false
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
126
|
-
args[_key3] = arguments[_key3];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
(_this$props2 = _this.props).onOpenChange.apply(_this$props2, [{
|
|
130
|
-
isOpen: false
|
|
131
|
-
}].concat(args));
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return _this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
_createClass(DropdownMenu, [{
|
|
138
|
-
key: "UNSAFE_componentWillReceiveProps",
|
|
139
|
-
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
140
|
-
if (nextProps.items !== this.state.items) {
|
|
141
|
-
this.setState({
|
|
142
|
-
items: _toConsumableArray(nextProps.items)
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (nextProps.isOpen !== this.props.isOpen) {
|
|
147
|
-
this.setState({
|
|
148
|
-
isOpen: nextProps.isOpen
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}, {
|
|
153
|
-
key: "render",
|
|
154
|
-
value: function render() {
|
|
155
|
-
var isOpen = this.state.isOpen;
|
|
156
|
-
var _this$props3 = this.props,
|
|
157
|
-
appearance = _this$props3.appearance,
|
|
158
|
-
boundariesElement = _this$props3.boundariesElement,
|
|
159
|
-
children = _this$props3.children,
|
|
160
|
-
isLoading = _this$props3.isLoading,
|
|
161
|
-
items = _this$props3.items,
|
|
162
|
-
position = _this$props3.position,
|
|
163
|
-
isMenuFixed = _this$props3.isMenuFixed,
|
|
164
|
-
shouldAllowMultilineItems = _this$props3.shouldAllowMultilineItems,
|
|
165
|
-
shouldFitContainer = _this$props3.shouldFitContainer,
|
|
166
|
-
shouldFlip = _this$props3.shouldFlip,
|
|
167
|
-
testId = _this$props3.testId,
|
|
168
|
-
trigger = _this$props3.trigger,
|
|
169
|
-
triggerButtonProps = _this$props3.triggerButtonProps,
|
|
170
|
-
triggerType = _this$props3.triggerType,
|
|
171
|
-
onPositioned = _this$props3.onPositioned;
|
|
172
|
-
return /*#__PURE__*/React.createElement(StatelessMenu, {
|
|
173
|
-
appearance: appearance,
|
|
174
|
-
boundariesElement: boundariesElement,
|
|
175
|
-
isOpen: isOpen,
|
|
176
|
-
isLoading: isLoading,
|
|
177
|
-
items: items,
|
|
178
|
-
onItemActivated: this.handleItemActivation,
|
|
179
|
-
onOpenChange: this.handleOpenChange,
|
|
180
|
-
position: position,
|
|
181
|
-
isMenuFixed: isMenuFixed,
|
|
182
|
-
shouldAllowMultilineItems: shouldAllowMultilineItems,
|
|
183
|
-
shouldFitContainer: shouldFitContainer,
|
|
184
|
-
shouldFlip: shouldFlip,
|
|
185
|
-
trigger: trigger,
|
|
186
|
-
triggerButtonProps: triggerButtonProps,
|
|
187
|
-
triggerType: triggerType,
|
|
188
|
-
onPositioned: onPositioned,
|
|
189
|
-
testId: testId
|
|
190
|
-
}, children);
|
|
191
|
-
}
|
|
192
|
-
}]);
|
|
193
|
-
|
|
194
|
-
return DropdownMenu;
|
|
195
|
-
}(Component);
|
|
196
|
-
|
|
197
|
-
_defineProperty(DropdownMenu, "defaultProps", {
|
|
198
|
-
appearance: 'default',
|
|
199
|
-
boundariesElement: 'viewport',
|
|
200
|
-
defaultOpen: false,
|
|
201
|
-
isLoading: false,
|
|
202
|
-
isOpen: false,
|
|
203
|
-
items: [],
|
|
204
|
-
onItemActivated: function onItemActivated() {},
|
|
205
|
-
onOpenChange: function onOpenChange() {},
|
|
206
|
-
position: 'bottom left',
|
|
207
|
-
isMenuFixed: false,
|
|
208
|
-
shouldAllowMultilineItems: false,
|
|
209
|
-
shouldFitContainer: false,
|
|
210
|
-
shouldFlip: true,
|
|
211
|
-
triggerType: 'default',
|
|
212
|
-
onPositioned: function onPositioned() {}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
export { DropdownMenu as default };
|