@primer/components 0.0.0-2021109221452 → 0.0.0-2021109223232
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 +5 -3
- package/dist/browser.esm.js +178 -178
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +179 -179
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/index.js +23 -12
- package/lib/AnchoredOverlay/index.js +12 -4
- package/lib/Autocomplete/index.js +14 -7
- package/lib/Button/index.js +70 -21
- package/lib/DropdownMenu/index.js +20 -6
- package/lib/DropdownStyles.js +26 -18
- package/lib/FilteredActionList/index.js +12 -4
- package/lib/Overlay.js +3 -1
- package/lib/Pagination/index.js +12 -6
- package/lib/Portal/Portal.js +3 -2
- package/lib/Portal/index.js +16 -5
- package/lib/SelectMenu/hooks/useKeyboardNav.js +96 -80
- package/lib/SelectMenu/index.js +14 -7
- package/lib/SelectPanel/index.js +12 -4
- package/lib/Token/index.js +30 -11
- package/lib/behaviors/anchoredPosition.js +234 -205
- package/lib/behaviors/focusTrap.js +157 -121
- package/lib/behaviors/focusZone.js +509 -434
- package/lib/behaviors/scrollIntoViewingArea.js +35 -18
- package/lib/constants.js +43 -39
- package/lib/hooks/index.js +60 -16
- package/lib/hooks/useAnchoredPosition.js +40 -31
- package/lib/hooks/useCombinedRefs.d.ts +2 -2
- package/lib/hooks/useCombinedRefs.js +35 -46
- package/lib/hooks/useDialog.js +96 -72
- package/lib/hooks/useFocusTrap.js +60 -43
- package/lib/hooks/useFocusZone.js +50 -54
- package/lib/hooks/useOnEscapePress.js +36 -25
- package/lib/hooks/useOpenAndCloseFocus.js +34 -22
- package/lib/hooks/useProvidedRefOrCreate.js +14 -10
- package/lib/hooks/useProvidedStateOrCreate.js +16 -13
- package/lib/hooks/useRenderForcingRef.js +17 -13
- package/lib/hooks/useResizeObserver.js +18 -15
- package/lib/hooks/useSafeTimeout.js +30 -22
- package/lib/hooks/useScrollFlash.js +23 -16
- package/lib/index.js +636 -161
- package/lib/polyfills/eventListenerSignal.js +45 -37
- package/lib/sx.js +14 -7
- package/lib/theme-preval.js +2945 -64
- package/lib/theme.js +12 -3
- package/lib/utils/iterateFocusableElements.js +85 -63
- package/lib/utils/theme.js +47 -33
- package/lib/utils/types/AriaRole.js +1 -2
- package/lib/utils/types/ComponentProps.js +1 -2
- package/lib/utils/types/Flatten.js +1 -2
- package/lib/utils/types/KeyPaths.js +1 -2
- package/lib/utils/types/MandateProps.js +1 -16
- package/lib/utils/types/Merge.js +1 -2
- package/lib/utils/types/index.js +69 -16
- package/lib/utils/uniqueId.js +8 -5
- package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
- package/lib/utils/userAgent.js +12 -8
- package/lib-esm/Overlay.js +2 -1
- package/lib-esm/Portal/Portal.js +2 -1
- package/lib-esm/hooks/useAnchoredPosition.js +2 -1
- package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
- package/lib-esm/hooks/useCombinedRefs.js +3 -2
- package/lib-esm/hooks/useResizeObserver.js +2 -2
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/package.json +2 -3
- package/lib/ActionList/Divider.jsx +0 -29
- package/lib/ActionList/Group.jsx +0 -23
- package/lib/ActionList/Header.jsx +0 -66
- package/lib/ActionList/Item.jsx +0 -301
- package/lib/ActionList/List.jsx +0 -138
- package/lib/ActionMenu.jsx +0 -73
- package/lib/AnchoredOverlay/AnchoredOverlay.jsx +0 -100
- package/lib/Autocomplete/Autocomplete.jsx +0 -100
- package/lib/Autocomplete/AutocompleteContext.jsx +0 -5
- package/lib/Autocomplete/AutocompleteInput.jsx +0 -113
- package/lib/Autocomplete/AutocompleteMenu.jsx +0 -190
- package/lib/Autocomplete/AutocompleteOverlay.jsx +0 -55
- package/lib/Avatar.jsx +0 -34
- package/lib/AvatarPair.jsx +0 -29
- package/lib/AvatarStack.jsx +0 -151
- package/lib/BaseStyles.jsx +0 -65
- package/lib/BorderBox.jsx +0 -18
- package/lib/Box.jsx +0 -10
- package/lib/BranchName.jsx +0 -20
- package/lib/Breadcrumbs.jsx +0 -74
- package/lib/Button/Button.jsx +0 -60
- package/lib/Button/ButtonBase.jsx +0 -36
- package/lib/Button/ButtonClose.jsx +0 -55
- package/lib/Button/ButtonDanger.jsx +0 -63
- package/lib/Button/ButtonGroup.jsx +0 -55
- package/lib/Button/ButtonInvisible.jsx +0 -52
- package/lib/Button/ButtonOutline.jsx +0 -63
- package/lib/Button/ButtonPrimary.jsx +0 -62
- package/lib/Button/ButtonStyles.jsx +0 -37
- package/lib/Button/ButtonTableList.jsx +0 -49
- package/lib/Caret.jsx +0 -93
- package/lib/CircleBadge.jsx +0 -43
- package/lib/CircleOcticon.jsx +0 -21
- package/lib/CounterLabel.jsx +0 -44
- package/lib/Details.jsx +0 -21
- package/lib/Dialog/ConfirmationDialog.jsx +0 -146
- package/lib/Dialog/Dialog.jsx +0 -273
- package/lib/Dialog.jsx +0 -131
- package/lib/Dropdown.jsx +0 -134
- package/lib/DropdownMenu/DropdownButton.jsx +0 -14
- package/lib/DropdownMenu/DropdownMenu.jsx +0 -70
- package/lib/FilterList.jsx +0 -63
- package/lib/FilteredActionList/FilteredActionList.jsx +0 -100
- package/lib/FilteredSearch.jsx +0 -29
- package/lib/Flash.jsx +0 -70
- package/lib/Flex.jsx +0 -15
- package/lib/FormGroup.jsx +0 -25
- package/lib/Grid.jsx +0 -15
- package/lib/Header.jsx +0 -90
- package/lib/Heading.jsx +0 -21
- package/lib/Label.jsx +0 -84
- package/lib/LabelGroup.jsx +0 -19
- package/lib/Link.jsx +0 -38
- package/lib/Overlay.jsx +0 -155
- package/lib/Pagehead.jsx +0 -18
- package/lib/Pagination/Pagination.jsx +0 -163
- package/lib/Pagination/model.jsx +0 -174
- package/lib/PointerBox.jsx +0 -25
- package/lib/Popover.jsx +0 -210
- package/lib/Portal/Portal.jsx +0 -78
- package/lib/Position.jsx +0 -46
- package/lib/ProgressBar.jsx +0 -39
- package/lib/SelectMenu/SelectMenu.jsx +0 -114
- package/lib/SelectMenu/SelectMenuContext.jsx +0 -5
- package/lib/SelectMenu/SelectMenuDivider.jsx +0 -43
- package/lib/SelectMenu/SelectMenuFilter.jsx +0 -59
- package/lib/SelectMenu/SelectMenuFooter.jsx +0 -46
- package/lib/SelectMenu/SelectMenuHeader.jsx +0 -44
- package/lib/SelectMenu/SelectMenuItem.jsx +0 -143
- package/lib/SelectMenu/SelectMenuList.jsx +0 -60
- package/lib/SelectMenu/SelectMenuLoadingAnimation.jsx +0 -21
- package/lib/SelectMenu/SelectMenuModal.jsx +0 -119
- package/lib/SelectMenu/SelectMenuTab.jsx +0 -93
- package/lib/SelectMenu/SelectMenuTabPanel.jsx +0 -43
- package/lib/SelectMenu/SelectMenuTabs.jsx +0 -58
- package/lib/SelectPanel/SelectPanel.jsx +0 -105
- package/lib/SideNav.jsx +0 -177
- package/lib/Spinner.jsx +0 -35
- package/lib/StateLabel.jsx +0 -89
- package/lib/StyledOcticon.jsx +0 -20
- package/lib/SubNav.jsx +0 -104
- package/lib/TabNav.jsx +0 -60
- package/lib/Text.jsx +0 -14
- package/lib/TextInput.jsx +0 -23
- package/lib/TextInputWithTokens.jsx +0 -218
- package/lib/ThemeProvider.jsx +0 -130
- package/lib/Timeline.jsx +0 -124
- package/lib/Token/AvatarToken.jsx +0 -54
- package/lib/Token/IssueLabelToken.jsx +0 -125
- package/lib/Token/Token.jsx +0 -103
- package/lib/Token/TokenBase.jsx +0 -88
- package/lib/Token/_RemoveTokenButton.jsx +0 -108
- package/lib/Token/_TokenTextContainer.jsx +0 -49
- package/lib/Tooltip.jsx +0 -246
- package/lib/Truncate.jsx +0 -27
- package/lib/UnderlineNav.jsx +0 -90
- package/lib/_TextInputWrapper.jsx +0 -114
- package/lib/_UnstyledTextInput.jsx +0 -22
- package/lib/hooks/useDetails.jsx +0 -39
- package/lib/hooks/useOnOutsideClick.jsx +0 -61
- package/lib/hooks/useOverlay.jsx +0 -15
- package/lib/utils/deprecate.jsx +0 -59
- package/lib/utils/isNumeric.jsx +0 -7
- package/lib/utils/ssr.jsx +0 -6
- package/lib/utils/test-deprecations.jsx +0 -20
- package/lib/utils/test-helpers.jsx +0 -8
- package/lib/utils/test-matchers.jsx +0 -100
- package/lib/utils/testing.jsx +0 -206
@@ -1,22 +1,39 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.scrollIntoViewingArea = void 0;
|
7
|
+
|
4
8
|
const scrollIntoViewingArea = (child, viewingArea, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
const startSide = direction === 'vertical' ? 'top' : 'left';
|
10
|
+
const endSide = direction === 'vertical' ? 'bottom' : 'right';
|
11
|
+
const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
|
12
|
+
const {
|
13
|
+
[startSide]: childStart,
|
14
|
+
[endSide]: childEnd
|
15
|
+
} = child.getBoundingClientRect();
|
16
|
+
const {
|
17
|
+
[startSide]: viewingAreaStart,
|
18
|
+
[endSide]: viewingAreaEnd
|
19
|
+
} = viewingArea.getBoundingClientRect();
|
20
|
+
const isChildStartAboveViewingArea = childStart < viewingAreaStart + endMargin;
|
21
|
+
const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - startMargin;
|
22
|
+
|
23
|
+
if (isChildStartAboveViewingArea) {
|
24
|
+
const scrollHeightToChildStart = childStart - viewingAreaStart + viewingArea[scrollSide];
|
25
|
+
viewingArea.scrollTo({
|
26
|
+
behavior,
|
27
|
+
[startSide]: scrollHeightToChildStart - endMargin
|
28
|
+
});
|
29
|
+
} else if (isChildBottomBelowViewingArea) {
|
30
|
+
const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
|
31
|
+
viewingArea.scrollTo({
|
32
|
+
behavior,
|
33
|
+
[startSide]: scrollHeightToChildBottom + startMargin
|
34
|
+
});
|
35
|
+
} // either completely in view or outside viewing area on both ends, don't scroll
|
36
|
+
|
21
37
|
};
|
22
|
-
|
38
|
+
|
39
|
+
exports.scrollIntoViewingArea = scrollIntoViewingArea;
|
package/lib/constants.js
CHANGED
@@ -1,52 +1,56 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}) : (function(o, m, k, k2) {
|
6
|
-
if (k2 === undefined) k2 = k;
|
7
|
-
o[k2] = m[k];
|
8
|
-
}));
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
-
}) : function(o, v) {
|
12
|
-
o["default"] = v;
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
13
5
|
});
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
-
if (mod && mod.__esModule) return mod;
|
16
|
-
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
-
__setModuleDefault(result, mod);
|
19
|
-
return result;
|
20
|
-
};
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
23
|
-
};
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
25
6
|
exports.GRID = exports.FLEX = exports.POSITION = exports.LAYOUT = exports.BORDER = exports.TYPOGRAPHY = exports.COMMON = exports.get = void 0;
|
26
|
-
|
7
|
+
|
8
|
+
var _themeGet = require("@styled-system/theme-get");
|
9
|
+
|
10
|
+
var styledSystem = _interopRequireWildcard(require("styled-system"));
|
11
|
+
|
12
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17
|
+
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19
|
+
|
27
20
|
// eslint-disable-next-line import/no-namespace
|
28
|
-
const
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
const {
|
22
|
+
get: getKey,
|
23
|
+
compose,
|
24
|
+
system
|
25
|
+
} = styledSystem;
|
26
|
+
|
27
|
+
const get = key => (0, _themeGet.themeGet)(key, getKey(_theme.default, key)); // Common props
|
28
|
+
|
29
|
+
|
32
30
|
exports.get = get;
|
33
|
-
|
34
|
-
exports.COMMON =
|
31
|
+
const COMMON = compose(styledSystem.space, styledSystem.color, styledSystem.display);
|
32
|
+
exports.COMMON = COMMON;
|
35
33
|
// Typography props
|
36
34
|
const whiteSpace = system({
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
whiteSpace: {
|
36
|
+
property: 'whiteSpace' // cssProperty: 'whiteSpace',
|
37
|
+
|
38
|
+
}
|
41
39
|
});
|
42
|
-
|
40
|
+
const TYPOGRAPHY = compose(styledSystem.typography, whiteSpace);
|
41
|
+
exports.TYPOGRAPHY = TYPOGRAPHY;
|
43
42
|
// Border props
|
44
|
-
|
43
|
+
const BORDER = compose(styledSystem.border, styledSystem.shadow);
|
44
|
+
exports.BORDER = BORDER;
|
45
45
|
// Layout props
|
46
|
-
|
46
|
+
const LAYOUT = styledSystem.layout;
|
47
|
+
exports.LAYOUT = LAYOUT;
|
47
48
|
// Position props
|
48
|
-
|
49
|
+
const POSITION = styledSystem.position;
|
50
|
+
exports.POSITION = POSITION;
|
49
51
|
// Flex props
|
50
|
-
|
52
|
+
const FLEX = styledSystem.flexbox;
|
53
|
+
exports.FLEX = FLEX;
|
51
54
|
// Grid props
|
52
|
-
|
55
|
+
const GRID = styledSystem.grid;
|
56
|
+
exports.GRID = GRID;
|
package/lib/hooks/index.js
CHANGED
@@ -1,17 +1,61 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "useOnOutsideClick", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _useOnOutsideClick.useOnOutsideClick;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "useProvidedRefOrCreate", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _useProvidedRefOrCreate.useProvidedRefOrCreate;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "useOnEscapePress", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _useOnEscapePress.useOnEscapePress;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
Object.defineProperty(exports, "useOpenAndCloseFocus", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function () {
|
27
|
+
return _useOpenAndCloseFocus.useOpenAndCloseFocus;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
Object.defineProperty(exports, "useAnchoredPosition", {
|
31
|
+
enumerable: true,
|
32
|
+
get: function () {
|
33
|
+
return _useAnchoredPosition.useAnchoredPosition;
|
34
|
+
}
|
35
|
+
});
|
36
|
+
Object.defineProperty(exports, "useOverlay", {
|
37
|
+
enumerable: true,
|
38
|
+
get: function () {
|
39
|
+
return _useOverlay.useOverlay;
|
40
|
+
}
|
41
|
+
});
|
42
|
+
Object.defineProperty(exports, "useRenderForcingRef", {
|
43
|
+
enumerable: true,
|
44
|
+
get: function () {
|
45
|
+
return _useRenderForcingRef.useRenderForcingRef;
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
var _useOnOutsideClick = require("./useOnOutsideClick");
|
50
|
+
|
51
|
+
var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
|
52
|
+
|
53
|
+
var _useOnEscapePress = require("./useOnEscapePress");
|
54
|
+
|
55
|
+
var _useOpenAndCloseFocus = require("./useOpenAndCloseFocus");
|
56
|
+
|
57
|
+
var _useAnchoredPosition = require("./useAnchoredPosition");
|
58
|
+
|
59
|
+
var _useOverlay = require("./useOverlay");
|
60
|
+
|
61
|
+
var _useRenderForcingRef = require("./useRenderForcingRef");
|
@@ -1,13 +1,22 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
exports.useAnchoredPosition =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useAnchoredPosition = useAnchoredPosition;
|
7
|
+
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
|
10
|
+
var _anchoredPosition = require("../behaviors/anchoredPosition");
|
11
|
+
|
12
|
+
var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
|
13
|
+
|
14
|
+
var _useResizeObserver = require("./useResizeObserver");
|
15
|
+
|
16
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
11
20
|
/**
|
12
21
|
* Calculates the top and left values for an absolutely-positioned floating element
|
13
22
|
* to be anchored to some anchor element. Returns refs for the floating element
|
@@ -18,25 +27,25 @@ const useResizeObserver_1 = require("./useResizeObserver");
|
|
18
27
|
* floating element.
|
19
28
|
*/
|
20
29
|
function useAnchoredPosition(settings, dependencies = []) {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
|
30
|
+
const floatingElementRef = (0, _useProvidedRefOrCreate.useProvidedRefOrCreate)(settings === null || settings === void 0 ? void 0 : settings.floatingElementRef);
|
31
|
+
const anchorElementRef = (0, _useProvidedRefOrCreate.useProvidedRefOrCreate)(settings === null || settings === void 0 ? void 0 : settings.anchorElementRef);
|
32
|
+
|
33
|
+
const [position, setPosition] = _react.default.useState(undefined);
|
34
|
+
|
35
|
+
const updatePosition = _react.default.useCallback(() => {
|
36
|
+
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
37
|
+
setPosition((0, _anchoredPosition.getAnchoredPosition)(floatingElementRef.current, anchorElementRef.current, settings));
|
38
|
+
} else {
|
39
|
+
setPosition(undefined);
|
40
|
+
}
|
41
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
42
|
+
[floatingElementRef, anchorElementRef, ...dependencies]);
|
43
|
+
|
44
|
+
(0, _useIsomorphicLayoutEffect.default)(updatePosition, [updatePosition]);
|
45
|
+
(0, _useResizeObserver.useResizeObserver)(updatePosition);
|
46
|
+
return {
|
47
|
+
floatingElementRef,
|
48
|
+
anchorElementRef,
|
49
|
+
position
|
50
|
+
};
|
51
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { ForwardedRef } from 'react';
|
2
2
|
/**
|
3
3
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
4
4
|
* should be passed as the ref for the element that needs to be shared. This is
|
@@ -7,4 +7,4 @@ import React, { ForwardedRef } from 'react';
|
|
7
7
|
* though, as it breaks encapsulation.
|
8
8
|
* @param refs
|
9
9
|
*/
|
10
|
-
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]):
|
10
|
+
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
|
@@ -1,26 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}) : (function(o, m, k, k2) {
|
6
|
-
if (k2 === undefined) k2 = k;
|
7
|
-
o[k2] = m[k];
|
8
|
-
}));
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
-
}) : function(o, v) {
|
12
|
-
o["default"] = v;
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
13
5
|
});
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
};
|
21
|
-
|
22
|
-
exports.useCombinedRefs = void 0;
|
23
|
-
const react_1 = __importStar(require("react"));
|
6
|
+
exports.useCombinedRefs = useCombinedRefs;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
24
14
|
/**
|
25
15
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
26
16
|
* should be passed as the ref for the element that needs to be shared. This is
|
@@ -30,29 +20,28 @@ const react_1 = __importStar(require("react"));
|
|
30
20
|
* @param refs
|
31
21
|
*/
|
32
22
|
function useCombinedRefs(...refs) {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
if (typeof ref === 'function') {
|
41
|
-
ref(current);
|
42
|
-
}
|
43
|
-
else {
|
44
|
-
ref.current = current;
|
45
|
-
}
|
46
|
-
}
|
23
|
+
const combinedRef = (0, _react.useRef)(null);
|
24
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
25
|
+
function setRefs(current = null) {
|
26
|
+
for (const ref of refs) {
|
27
|
+
if (!ref) {
|
28
|
+
return;
|
47
29
|
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
30
|
+
|
31
|
+
if (typeof ref === 'function') {
|
32
|
+
ref(current);
|
33
|
+
} else {
|
34
|
+
ref.current = current;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
setRefs(combinedRef.current);
|
40
|
+
return () => {
|
41
|
+
// ensure the refs get updated on unmount
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
43
|
+
setRefs(combinedRef.current);
|
44
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
45
|
+
}, [...refs, combinedRef.current]);
|
46
|
+
return combinedRef;
|
47
|
+
}
|
package/lib/hooks/useDialog.js
CHANGED
@@ -1,80 +1,104 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
4
10
|
const noop = () => null;
|
11
|
+
|
5
12
|
function visible(el) {
|
6
|
-
|
13
|
+
return !el.hidden && (!el.type || el.type !== 'hidden') && (el.offsetWidth > 0 || el.offsetHeight > 0);
|
7
14
|
}
|
15
|
+
|
8
16
|
function focusable(el) {
|
9
|
-
|
10
|
-
|
17
|
+
const inputEl = el;
|
18
|
+
return inputEl.tabIndex >= 0 && !inputEl.disabled && visible(inputEl);
|
11
19
|
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
20
|
+
|
21
|
+
function useDialog({
|
22
|
+
modalRef,
|
23
|
+
overlayRef,
|
24
|
+
isOpen,
|
25
|
+
onDismiss = noop,
|
26
|
+
initialFocusRef,
|
27
|
+
closeButtonRef
|
28
|
+
}) {
|
29
|
+
const onClickOutside = (0, _react.useCallback)(e => {
|
30
|
+
if (modalRef.current && overlayRef.current && !modalRef.current.contains(e.target) && overlayRef.current.contains(e.target)) {
|
31
|
+
onDismiss();
|
32
|
+
}
|
33
|
+
}, [onDismiss, modalRef, overlayRef]);
|
34
|
+
(0, _react.useEffect)(() => {
|
35
|
+
if (isOpen) {
|
36
|
+
document.addEventListener('click', onClickOutside);
|
37
|
+
return () => {
|
38
|
+
document.removeEventListener('click', onClickOutside);
|
39
|
+
};
|
40
|
+
}
|
41
|
+
}, [isOpen, onClickOutside]);
|
42
|
+
(0, _react.useEffect)(() => {
|
43
|
+
if (isOpen) {
|
44
|
+
if (initialFocusRef && initialFocusRef.current) {
|
45
|
+
initialFocusRef.current.focus();
|
46
|
+
} else if (closeButtonRef && closeButtonRef.current) {
|
47
|
+
closeButtonRef.current.focus();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}, [isOpen, initialFocusRef, closeButtonRef]);
|
51
|
+
const getFocusableItem = (0, _react.useCallback)((e, movement) => {
|
52
|
+
if (modalRef.current) {
|
53
|
+
const items = Array.from(modalRef.current.querySelectorAll('*')).filter(focusable);
|
54
|
+
if (items.length === 0) return;
|
55
|
+
e.preventDefault();
|
56
|
+
const focusedElement = document.activeElement;
|
57
|
+
|
58
|
+
if (!focusedElement) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
|
62
|
+
const index = items.indexOf(focusedElement);
|
63
|
+
const offsetIndex = index + movement;
|
64
|
+
const fallbackIndex = movement === 1 ? 0 : items.length - 1;
|
65
|
+
const focusableItem = items[offsetIndex] || items[fallbackIndex];
|
66
|
+
return focusableItem;
|
67
|
+
}
|
68
|
+
}, [modalRef]);
|
69
|
+
const handleTab = (0, _react.useCallback)(e => {
|
70
|
+
const movement = e.shiftKey ? -1 : 1;
|
71
|
+
const focusableItem = getFocusableItem(e, movement);
|
72
|
+
|
73
|
+
if (!focusableItem) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
|
77
|
+
focusableItem.focus();
|
78
|
+
}, [getFocusableItem]);
|
79
|
+
const onKeyDown = (0, _react.useCallback)(event => {
|
80
|
+
switch (event.key) {
|
81
|
+
case 'Tab':
|
82
|
+
handleTab(event);
|
83
|
+
break;
|
84
|
+
|
85
|
+
case 'Escape':
|
86
|
+
onDismiss();
|
87
|
+
event.stopPropagation();
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
}, [handleTab, onDismiss]);
|
91
|
+
|
92
|
+
const getDialogProps = () => {
|
93
|
+
return {
|
94
|
+
onKeyDown
|
77
95
|
};
|
78
|
-
|
96
|
+
};
|
97
|
+
|
98
|
+
return {
|
99
|
+
getDialogProps
|
100
|
+
};
|
79
101
|
}
|
80
|
-
|
102
|
+
|
103
|
+
var _default = useDialog;
|
104
|
+
exports.default = _default;
|