@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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
var _actionMap;
|
|
4
|
+
|
|
5
|
+
import { KEY_DOWN, KEY_END, KEY_HOME, KEY_UP } from '@atlaskit/ds-lib/keycodes';
|
|
6
|
+
var actionMap = (_actionMap = {}, _defineProperty(_actionMap, KEY_DOWN, 'next'), _defineProperty(_actionMap, KEY_UP, 'prev'), _defineProperty(_actionMap, KEY_HOME, 'first'), _defineProperty(_actionMap, KEY_END, 'last'), _actionMap);
|
|
7
|
+
export default function handleFocus(refs) {
|
|
8
|
+
return function (e) {
|
|
9
|
+
var currentFocusedIdx = refs.findIndex(function (el) {
|
|
10
|
+
var _document$activeEleme;
|
|
11
|
+
|
|
12
|
+
return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.isSameNode(el);
|
|
13
|
+
});
|
|
14
|
+
var action = actionMap[e.key];
|
|
15
|
+
|
|
16
|
+
switch (action) {
|
|
17
|
+
case 'next':
|
|
18
|
+
if (currentFocusedIdx < refs.length - 1) {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
refs[currentFocusedIdx + 1].focus();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case 'prev':
|
|
26
|
+
if (currentFocusedIdx > 0) {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
refs[currentFocusedIdx - 1].focus();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case 'first':
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
refs[0].focus();
|
|
36
|
+
break;
|
|
37
|
+
|
|
38
|
+
case 'last':
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
refs[refs.length - 1].focus();
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
default:
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var canUseDOM = function canUseDOM() {
|
|
2
|
+
return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
3
|
+
};
|
|
4
|
+
/*
|
|
5
|
+
* Making sure we can fallback to browsers doesn't support voice over -
|
|
6
|
+
* we would using menuitemcheckbox / menuitemradio for these that supports voice over, and
|
|
7
|
+
* will fallback to checkbox / radio for these doesn't
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var isVoiceOverSupported = function isVoiceOverSupported() {
|
|
12
|
+
return /Mac OS X/.test(canUseDOM() ? navigator.userAgent : '');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default isVoiceOverSupported;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
|
|
7
|
+
var resetOptionsInGroup = function resetOptionsInGroup(group) {
|
|
8
|
+
return Object.keys(group || {}).reduce(function (accumulator, current) {
|
|
9
|
+
return _objectSpread(_objectSpread({}, accumulator), {}, _defineProperty({}, current, typeof group[current] === 'undefined' ? undefined : false));
|
|
10
|
+
}, {});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default resetOptionsInGroup;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
|
|
8
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
9
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
10
|
+
import Section from '@atlaskit/menu/section';
|
|
11
|
+
import { SelectionStoreContext } from '../internal/context/selection-store';
|
|
12
|
+
import resetOptionsInGroup from '../internal/utils/reset-options-in-group';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* __Radio group context__
|
|
16
|
+
* Context provider that wraps each DropdownItemRadioGroup
|
|
17
|
+
*/
|
|
18
|
+
export var RadioGroupContext = /*#__PURE__*/createContext({
|
|
19
|
+
id: '',
|
|
20
|
+
radioGroupState: {},
|
|
21
|
+
selectRadioItem: noop
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* __Dropdown item radio group__
|
|
25
|
+
* Store which manages the selection state for each DropdownItemRadio
|
|
26
|
+
* across mount and unmounts.
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
var DropdownItemRadioGroup = function DropdownItemRadioGroup(props) {
|
|
31
|
+
var children = props.children,
|
|
32
|
+
id = props.id;
|
|
33
|
+
|
|
34
|
+
var _useContext = useContext(SelectionStoreContext),
|
|
35
|
+
setGroupState = _useContext.setGroupState,
|
|
36
|
+
getGroupState = _useContext.getGroupState;
|
|
37
|
+
/**
|
|
38
|
+
* - initially `radioGroupState` is from selection store, so it's safe to update without re-rendering
|
|
39
|
+
* - we flush a render by updating this local radio group state
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
var _useState = useState(function () {
|
|
44
|
+
return getGroupState(id);
|
|
45
|
+
}),
|
|
46
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
47
|
+
radioGroupState = _useState2[0],
|
|
48
|
+
setRadioGroupState = _useState2[1];
|
|
49
|
+
|
|
50
|
+
var selectRadioItem = function selectRadioItem(childId, value) {
|
|
51
|
+
var newValue = _objectSpread(_objectSpread({}, resetOptionsInGroup(getGroupState(id))), {}, _defineProperty({}, childId, value));
|
|
52
|
+
|
|
53
|
+
setRadioGroupState(newValue);
|
|
54
|
+
setGroupState(id, newValue);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return /*#__PURE__*/React.createElement(RadioGroupContext.Provider, {
|
|
58
|
+
value: {
|
|
59
|
+
id: id,
|
|
60
|
+
radioGroupState: radioGroupState,
|
|
61
|
+
selectRadioItem: selectRadioItem
|
|
62
|
+
}
|
|
63
|
+
}, /*#__PURE__*/React.createElement(Section, props, children));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default DropdownItemRadioGroup;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["id", "isSelected", "defaultSelected", "onClick", "shouldTitleWrap", "shouldDescriptionWrap"];
|
|
5
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
7
|
+
import RadioIcon from '@atlaskit/icon/glyph/radio';
|
|
8
|
+
import ButtonItem from '@atlaskit/menu/button-item';
|
|
9
|
+
import useRadioState from '../internal/hooks/use-radio-state';
|
|
10
|
+
import useRegisterItemWithFocusManager from '../internal/hooks/use-register-item-with-focus-manager';
|
|
11
|
+
import getIconColors from '../internal/utils/get-icon-colors';
|
|
12
|
+
import isVoiceOverSupported from '../internal/utils/is-voice-over-supported';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* __Dropdown item radio__
|
|
16
|
+
*
|
|
17
|
+
* A dropdown item radio displays groups that have a single selection.
|
|
18
|
+
*
|
|
19
|
+
* - [Examples](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/examples)
|
|
20
|
+
* - [Code](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/code)
|
|
21
|
+
* - [Usage](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/usage)
|
|
22
|
+
*/
|
|
23
|
+
var DropdownItemRadio = function DropdownItemRadio(props) {
|
|
24
|
+
var id = props.id,
|
|
25
|
+
isSelected = props.isSelected,
|
|
26
|
+
defaultSelected = props.defaultSelected,
|
|
27
|
+
_props$onClick = props.onClick,
|
|
28
|
+
providedOnClick = _props$onClick === void 0 ? noop : _props$onClick,
|
|
29
|
+
_props$shouldTitleWra = props.shouldTitleWrap,
|
|
30
|
+
shouldTitleWrap = _props$shouldTitleWra === void 0 ? true : _props$shouldTitleWra,
|
|
31
|
+
_props$shouldDescript = props.shouldDescriptionWrap,
|
|
32
|
+
shouldDescriptionWrap = _props$shouldDescript === void 0 ? true : _props$shouldDescript,
|
|
33
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV !== 'production' && typeof isSelected !== 'undefined' && typeof defaultSelected !== 'undefined') {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.warn("[DropdownItemRadio] You've used both `defaultSelected` and `isSelected` props. This is dangerous and can lead to unexpected results. Use one or the other depending if you want to control the components state yourself.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var _useRadioState = useRadioState({
|
|
41
|
+
id: id,
|
|
42
|
+
isSelected: isSelected,
|
|
43
|
+
defaultSelected: defaultSelected
|
|
44
|
+
}),
|
|
45
|
+
_useRadioState2 = _slicedToArray(_useRadioState, 2),
|
|
46
|
+
selected = _useRadioState2[0],
|
|
47
|
+
setSelected = _useRadioState2[1];
|
|
48
|
+
|
|
49
|
+
var _useState = useState(getIconColors(defaultSelected)),
|
|
50
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
51
|
+
iconColors = _useState2[0],
|
|
52
|
+
setIconColors = _useState2[1];
|
|
53
|
+
|
|
54
|
+
var onClickHandler = useCallback(function (event) {
|
|
55
|
+
setSelected(function (selected) {
|
|
56
|
+
return !selected;
|
|
57
|
+
});
|
|
58
|
+
providedOnClick(event);
|
|
59
|
+
}, [providedOnClick, setSelected]);
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
setIconColors(getIconColors(selected));
|
|
62
|
+
}, [selected]);
|
|
63
|
+
var itemRef = useRegisterItemWithFocusManager();
|
|
64
|
+
return /*#__PURE__*/React.createElement(ButtonItem, _extends({
|
|
65
|
+
id: id,
|
|
66
|
+
onClick: onClickHandler,
|
|
67
|
+
role: isVoiceOverSupported() ? 'radio' : 'menuitemradio',
|
|
68
|
+
"aria-checked": selected,
|
|
69
|
+
shouldTitleWrap: shouldTitleWrap,
|
|
70
|
+
shouldDescriptionWrap: shouldDescriptionWrap,
|
|
71
|
+
iconBefore: /*#__PURE__*/React.createElement(RadioIcon, {
|
|
72
|
+
label: "",
|
|
73
|
+
size: "medium",
|
|
74
|
+
primaryColor: iconColors.primary,
|
|
75
|
+
secondaryColor: iconColors.secondary
|
|
76
|
+
}),
|
|
77
|
+
ref: itemRef
|
|
78
|
+
}, rest));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default DropdownItemRadio;
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { SectionProps } from '@atlaskit/menu';
|
|
3
|
+
interface DropdownItemCheckboxGroupProps extends SectionProps {
|
|
4
|
+
/**
|
|
5
|
+
* Unique identifier for the checkbox group.
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* __Dropdown item checkbox group__
|
|
11
|
+
*
|
|
12
|
+
* A wrapping element for dropdown menu checkbox items.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
declare const DropdownItemCheckboxGroup: (props: DropdownItemCheckboxGroupProps) => JSX.Element;
|
|
16
|
+
export default DropdownItemCheckboxGroup;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DropdownItemCheckboxProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* __Dropdown item checkbox__
|
|
5
|
+
*
|
|
6
|
+
* A dropdown item checkbox creates groups that have multiple selections.
|
|
7
|
+
*
|
|
8
|
+
* - [Examples](https://atlassian.design/components/dropdown-menu/dropdown-item-checkbox/examples)
|
|
9
|
+
* - [Code](https://atlassian.design/components/dropdown-menu/dropdown-item-checkbox/code)
|
|
10
|
+
* - [Usage](https://atlassian.design/components/dropdown-menu/dropdown-item-checkbox/usage)
|
|
11
|
+
*/
|
|
12
|
+
declare const DropdownItemCheckbox: (props: DropdownItemCheckboxProps) => JSX.Element;
|
|
13
|
+
export default DropdownItemCheckbox;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* __Section__
|
|
3
|
+
*
|
|
4
|
+
* A dropdown item group includes all the actions or items in a dropdown menu.
|
|
5
|
+
*
|
|
6
|
+
* - [Examples](https://atlassian.design/components/dropdown-menu/dropdown-item-group/examples)
|
|
7
|
+
* - [Code](https://atlassian.design/components/dropdown-menu/dropdown-item-group/code)
|
|
8
|
+
* - [Usage](https://atlassian.design/components/dropdown-menu/dropdown-item-group/usage)
|
|
9
|
+
*/
|
|
10
|
+
import Section from '@atlaskit/menu/section';
|
|
11
|
+
export default Section;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DropdownItemProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* __Dropdown menu item__
|
|
5
|
+
*
|
|
6
|
+
* A dropdown item populates the dropdown menu with items. Every item should be inside a dropdown item group.
|
|
7
|
+
*
|
|
8
|
+
* - [Examples](https://atlassian.design/components/dropdown-item/examples)
|
|
9
|
+
* - [Code](https://atlassian.design/components/dropdown-item/code)
|
|
10
|
+
* - [Usage](https://atlassian.design/components/dropdown-item/usage)
|
|
11
|
+
*/
|
|
12
|
+
declare const DropdownMenuItem: (props: DropdownItemProps) => JSX.Element;
|
|
13
|
+
export default DropdownMenuItem;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DropdownMenuProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* __Dropdown menu__
|
|
5
|
+
*
|
|
6
|
+
* A dropdown menu displays a list of actions or options to a user.
|
|
7
|
+
*
|
|
8
|
+
* - [Examples](https://atlassian.design/components/dropdown-menu/examples)
|
|
9
|
+
* - [Code](https://atlassian.design/components/dropdown-menu/code)
|
|
10
|
+
* - [Usage](https://atlassian.design/components/dropdown-menu/usage)
|
|
11
|
+
*/
|
|
12
|
+
declare const DropdownMenu: (props: DropdownMenuProps) => JSX.Element;
|
|
13
|
+
export default DropdownMenu;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export { default } from './
|
|
2
|
-
export { default as
|
|
3
|
-
export { default as DropdownItem } from './
|
|
4
|
-
export { default as
|
|
5
|
-
export { default as
|
|
6
|
-
export { default as
|
|
7
|
-
export { default as
|
|
8
|
-
export {
|
|
9
|
-
export type { DropdownMenuStatefulProps } from './types';
|
|
10
|
-
export type { Props as WithToggleInteractionProps } from './components/hoc/withToggleInteraction';
|
|
1
|
+
export { default } from './dropdown-menu';
|
|
2
|
+
export { default as DropdownItemGroup } from './dropdown-menu-item-group';
|
|
3
|
+
export { default as DropdownItem } from './dropdown-menu-item';
|
|
4
|
+
export { default as DropdownItemCheckbox } from './checkbox/dropdown-item-checkbox';
|
|
5
|
+
export { default as DropdownItemCheckboxGroup } from './checkbox/dropdown-item-checkbox-group';
|
|
6
|
+
export { default as DropdownItemRadio } from './radio/dropdown-item-radio';
|
|
7
|
+
export { default as DropdownItemRadioGroup } from './radio/dropdown-item-radio-group';
|
|
8
|
+
export type { DropdownMenuProps, DropdownMenuGroupProps, DropdownItemProps, OnOpenChangeArgs, CustomTriggerProps, } from './types';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { FocusableElement } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Context provider which maintains the list of focusable elements and a method to
|
|
7
|
+
* register new menu items.
|
|
8
|
+
* This list drives the keyboard navgation of the menu.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare const FocusManagerContext: React.Context<{
|
|
12
|
+
menuItemRefs: FocusableElement[];
|
|
13
|
+
registerRef: (ref: FocusableElement) => void;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Focus manager logic
|
|
17
|
+
*/
|
|
18
|
+
declare const FocusManager: FC;
|
|
19
|
+
export default FocusManager;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MenuWrapperProps } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* MenuWrapper wraps all the menu items.
|
|
6
|
+
* It handles the logic to close the menu when a MenuItem is clicked, but leaves it open
|
|
7
|
+
* if a CheckboxItem or RadioItem is clicked.
|
|
8
|
+
* It also sets focus to the first menu item when opened.
|
|
9
|
+
*/
|
|
10
|
+
declare const MenuWrapper: ({ onClose, setInitialFocusRef, ...props }: MenuWrapperProps) => JSX.Element;
|
|
11
|
+
export default MenuWrapper;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type OptionsInGroup = {
|
|
3
|
+
[key: string]: boolean | undefined;
|
|
4
|
+
};
|
|
5
|
+
declare type SelectionStoreContextProps = {
|
|
6
|
+
setItemState: (group: string, id: string, value: boolean | undefined) => void;
|
|
7
|
+
getItemState: (group: string, id: string) => boolean | undefined;
|
|
8
|
+
setGroupState: (group: string, value: OptionsInGroup) => void;
|
|
9
|
+
getGroupState: (group: string) => OptionsInGroup;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* SelectionStoreContext maintains the state of the selected items
|
|
14
|
+
* and getter setters.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const SelectionStoreContext: React.Context<SelectionStoreContextProps>;
|
|
18
|
+
declare type SelectionStoreProps = {
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Selection store will persist data as long as it remains mounted.
|
|
23
|
+
* It handles the uncontrolled story for dropdown menu when the menu
|
|
24
|
+
* items can be mounted/unmounted depending if the menu is open or closed.
|
|
25
|
+
*/
|
|
26
|
+
declare const SelectionStore: (props: SelectionStoreProps) => JSX.Element;
|
|
27
|
+
export default SelectionStore;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare type CheckboxStateArgs = {
|
|
2
|
+
id: string;
|
|
3
|
+
isSelected: boolean | undefined;
|
|
4
|
+
defaultSelected: boolean | undefined;
|
|
5
|
+
};
|
|
6
|
+
declare type SetStateCallback = (value: boolean | undefined) => boolean;
|
|
7
|
+
declare type CheckboxStateValue = [boolean, (newValue: SetStateCallback) => void];
|
|
8
|
+
/**
|
|
9
|
+
* Custom hook to handle checkbox state for dropdown menu.
|
|
10
|
+
* It works in tandem with the selection store context when the
|
|
11
|
+
* component is uncontrolled.
|
|
12
|
+
*/
|
|
13
|
+
declare const useCheckboxState: ({ isSelected, id, defaultSelected, }: CheckboxStateArgs) => CheckboxStateValue;
|
|
14
|
+
export default useCheckboxState;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type RadioStateArgs = {
|
|
2
|
+
id: string;
|
|
3
|
+
isSelected: boolean | undefined;
|
|
4
|
+
defaultSelected: boolean | undefined;
|
|
5
|
+
};
|
|
6
|
+
declare type SetStateCallback = (value: boolean | undefined) => boolean;
|
|
7
|
+
declare type RadioStateValue = [boolean, (newValue: SetStateCallback) => void];
|
|
8
|
+
declare function useRadioState({ id, isSelected, defaultSelected, }: RadioStateArgs): RadioStateValue;
|
|
9
|
+
export default useRadioState;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const getIconColors: (isSelected: boolean | undefined) => {
|
|
2
|
+
primary: "var(--ds-background-boldBrand-resting)";
|
|
3
|
+
secondary: "var(--ds-background-default)";
|
|
4
|
+
} | {
|
|
5
|
+
primary: "var(--ds-border-neutral)";
|
|
6
|
+
secondary: "var(--ds-UNSAFE_util-transparent)";
|
|
7
|
+
};
|
|
8
|
+
export default getIconColors;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isCheckboxItem(element: HTMLElement): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isCheckboxItem(element: HTMLElement): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SectionProps } from '@atlaskit/menu';
|
|
3
|
+
interface DropdownItemRadioGroupProps extends SectionProps {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
interface RadioGroupContextProps {
|
|
7
|
+
id: string;
|
|
8
|
+
radioGroupState: {
|
|
9
|
+
[key: string]: boolean | undefined;
|
|
10
|
+
};
|
|
11
|
+
selectRadioItem: (id: string, value: boolean) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* __Radio group context__
|
|
15
|
+
* Context provider that wraps each DropdownItemRadioGroup
|
|
16
|
+
*/
|
|
17
|
+
export declare const RadioGroupContext: React.Context<RadioGroupContextProps>;
|
|
18
|
+
/**
|
|
19
|
+
* __Dropdown item radio group__
|
|
20
|
+
* Store which manages the selection state for each DropdownItemRadio
|
|
21
|
+
* across mount and unmounts.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare const DropdownItemRadioGroup: (props: DropdownItemRadioGroupProps) => JSX.Element;
|
|
25
|
+
export default DropdownItemRadioGroup;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DropdownItemRadioProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* __Dropdown item radio__
|
|
5
|
+
*
|
|
6
|
+
* A dropdown item radio displays groups that have a single selection.
|
|
7
|
+
*
|
|
8
|
+
* - [Examples](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/examples)
|
|
9
|
+
* - [Code](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/code)
|
|
10
|
+
* - [Usage](https://atlassian.design/components/dropdown-menu/dropdown-item-radio/usage)
|
|
11
|
+
*/
|
|
12
|
+
declare const DropdownItemRadio: (props: DropdownItemRadioProps) => JSX.Element;
|
|
13
|
+
export default DropdownItemRadio;
|