@primer/components 0.0.0-2021116182158 → 0.0.0-202111619107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/browser.esm.js +2 -2
  2. package/dist/browser.esm.js.map +1 -1
  3. package/dist/browser.umd.js +2 -2
  4. package/dist/browser.umd.js.map +1 -1
  5. package/lib/ActionList/Item.js +3 -3
  6. package/lib/ActionList/List.js +2 -2
  7. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  8. package/lib/Autocomplete/AutocompleteMenu.js +10 -5
  9. package/lib/Dialog/ConfirmationDialog.js +2 -2
  10. package/lib/Dialog/Dialog.js +2 -2
  11. package/lib/FilteredActionList/FilteredActionList.js +10 -3
  12. package/lib/Overlay.d.ts +1 -1
  13. package/lib/TextInputWithTokens.js +4 -4
  14. package/lib/hooks/useAnchoredPosition.d.ts +1 -1
  15. package/lib/hooks/useAnchoredPosition.js +2 -2
  16. package/lib/hooks/useFocusTrap.js +2 -2
  17. package/lib/hooks/useFocusZone.d.ts +1 -1
  18. package/lib/hooks/useFocusZone.js +2 -2
  19. package/lib/hooks/useOpenAndCloseFocus.js +2 -2
  20. package/lib-esm/ActionList/Item.js +1 -1
  21. package/lib-esm/ActionList/List.js +1 -1
  22. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  23. package/lib-esm/Autocomplete/AutocompleteMenu.js +9 -4
  24. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  25. package/lib-esm/Dialog/Dialog.js +1 -1
  26. package/lib-esm/FilteredActionList/FilteredActionList.js +9 -3
  27. package/lib-esm/Overlay.d.ts +1 -1
  28. package/lib-esm/TextInputWithTokens.js +2 -2
  29. package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
  30. package/lib-esm/hooks/useAnchoredPosition.js +1 -1
  31. package/lib-esm/hooks/useFocusTrap.js +1 -1
  32. package/lib-esm/hooks/useFocusZone.d.ts +1 -1
  33. package/lib-esm/hooks/useFocusZone.js +1 -1
  34. package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
  35. package/package.json +2 -5
  36. package/lib/behaviors/anchoredPosition.d.ts +0 -89
  37. package/lib/behaviors/anchoredPosition.js +0 -316
  38. package/lib/behaviors/focusTrap.d.ts +0 -12
  39. package/lib/behaviors/focusTrap.js +0 -179
  40. package/lib/behaviors/focusZone.d.ts +0 -137
  41. package/lib/behaviors/focusZone.js +0 -578
  42. package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
  43. package/lib/behaviors/scrollIntoViewingArea.js +0 -39
  44. package/lib/utils/iterateFocusableElements.d.ts +0 -42
  45. package/lib/utils/iterateFocusableElements.js +0 -113
  46. package/lib/utils/uniqueId.d.ts +0 -1
  47. package/lib/utils/uniqueId.js +0 -12
  48. package/lib/utils/userAgent.d.ts +0 -1
  49. package/lib/utils/userAgent.js +0 -15
  50. package/lib-esm/behaviors/anchoredPosition.d.ts +0 -89
  51. package/lib-esm/behaviors/anchoredPosition.js +0 -309
  52. package/lib-esm/behaviors/focusTrap.d.ts +0 -12
  53. package/lib-esm/behaviors/focusTrap.js +0 -170
  54. package/lib-esm/behaviors/focusZone.d.ts +0 -137
  55. package/lib-esm/behaviors/focusZone.js +0 -560
  56. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
  57. package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
  58. package/lib-esm/utils/iterateFocusableElements.d.ts +0 -42
  59. package/lib-esm/utils/iterateFocusableElements.js +0 -102
  60. package/lib-esm/utils/uniqueId.d.ts +0 -1
  61. package/lib-esm/utils/uniqueId.js +0 -5
  62. package/lib-esm/utils/userAgent.d.ts +0 -1
  63. package/lib-esm/utils/userAgent.js +0 -8
@@ -23,7 +23,7 @@ var _Divider = require("./Divider");
23
23
 
24
24
  var _ThemeProvider = require("../ThemeProvider");
25
25
 
26
- var _focusZone = require("../behaviors/focusZone");
26
+ var _behaviors = require("@primer/behaviors");
27
27
 
28
28
  var _ssr = require("@react-aria/ssr");
29
29
 
@@ -98,10 +98,10 @@ const StyledItem = _styledComponents.default.div.withConfig({
98
98
  showDivider
99
99
  }) => showDivider ? `1px` : '0', DividedContent, (0, _constants.get)('colors.border.muted'), ({
100
100
  showDivider
101
- }) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedDirectly, ({
101
+ }) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, _behaviors.isActiveDescendantAttribute, DividedContent, _behaviors.isActiveDescendantAttribute, DividedContent, _behaviors.isActiveDescendantAttribute, _behaviors.activeDescendantActivatedDirectly, ({
102
102
  variant,
103
103
  item
104
- }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedIndirectly, ({
104
+ }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, _behaviors.isActiveDescendantAttribute, _behaviors.activeDescendantActivatedIndirectly, ({
105
105
  variant,
106
106
  item
107
107
  }) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
@@ -17,7 +17,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
17
17
 
18
18
  var _constants = require("../constants");
19
19
 
20
- var _focusZone = require("../behaviors/focusZone");
20
+ var _behaviors = require("@primer/behaviors");
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
@@ -38,7 +38,7 @@ function isGroupedListProps(props) {
38
38
  const StyledList = _styledComponents.default.div.withConfig({
39
39
  displayName: "List__StyledList",
40
40
  componentId: "sc-yr2k7d-0"
41
- })(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], (0, _constants.get)('fontSizes.1'), _focusZone.hasActiveDescendantAttribute, (0, _constants.get)('colors.border.muted'));
41
+ })(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], (0, _constants.get)('fontSizes.1'), _behaviors.hasActiveDescendantAttribute, (0, _constants.get)('colors.border.muted'));
42
42
  /**
43
43
  * Returns `sx` prop values for `List` children matching the given `List` style variation.
44
44
  * @param variant `List` style variation.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { OverlayProps } from '../Overlay';
3
3
  import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
4
  import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
- import { PositionSettings } from '../behaviors/anchoredPosition';
5
+ import type { PositionSettings } from '@primer/behaviors';
6
6
  interface AnchoredOverlayPropsWithAnchor {
7
7
  /**
8
8
  * A custom function component used to render the anchor element.
@@ -17,9 +17,9 @@ var _AutocompleteContext = require("./AutocompleteContext");
17
17
 
18
18
  var _octiconsReact = require("@primer/octicons-react");
19
19
 
20
- var _uniqueId = require("../utils/uniqueId");
20
+ var _utils = require("@primer/behaviors/utils");
21
21
 
22
- var _scrollIntoViewingArea = require("../behaviors/scrollIntoViewingArea");
22
+ var _behaviors = require("@primer/behaviors");
23
23
 
24
24
  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); }
25
25
 
@@ -27,6 +27,11 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
27
27
 
28
28
  const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
29
29
 
30
+ const menuScrollMargins = {
31
+ startMargin: 0,
32
+ endMargin: 8
33
+ };
34
+
30
35
  function getDefaultItemFilter(filterValue) {
31
36
  return function (item, _i) {
32
37
  var _item$text;
@@ -125,7 +130,7 @@ function AutocompleteMenu(props) {
125
130
  onAction: item => {
126
131
  // TODO: make it possible to pass a leadingVisual when using `addNewItem`
127
132
  addNewItem.handleAddItem({ ...item,
128
- id: item.id || (0, _uniqueId.uniqueId)(),
133
+ id: item.id || (0, _utils.uniqueId)(),
129
134
  leadingVisual: undefined
130
135
  });
131
136
 
@@ -152,9 +157,9 @@ function AutocompleteMenu(props) {
152
157
  }
153
158
 
154
159
  if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
155
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, customScrollContainerRef.current);
160
+ (0, _behaviors.scrollIntoView)(current, customScrollContainerRef.current, menuScrollMargins);
156
161
  } else if (current && scrollContainerRef.current && directlyActivated) {
157
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
162
+ (0, _behaviors.scrollIntoView)(current, scrollContainerRef.current, menuScrollMargins);
158
163
  }
159
164
  }
160
165
  }, [loading]);
@@ -16,7 +16,7 @@ var _Box = _interopRequireDefault(require("../Box"));
16
16
 
17
17
  var _ThemeProvider = require("../ThemeProvider");
18
18
 
19
- var _focusZone = require("../behaviors/focusZone");
19
+ var _behaviors = require("@primer/behaviors");
20
20
 
21
21
  var _constants = require("../constants");
22
22
 
@@ -81,7 +81,7 @@ const ConfirmationFooter = ({
81
81
  const {
82
82
  containerRef: footerRef
83
83
  } = (0, _useFocusZone.useFocusZone)({
84
- bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.Tab,
84
+ bindKeys: _behaviors.FocusKeys.ArrowHorizontal | _behaviors.FocusKeys.Tab,
85
85
  focusInStrategy: 'closest'
86
86
  }); // Must have exactly 2 buttons!
87
87
 
@@ -27,7 +27,7 @@ var _octiconsReact = require("@primer/octicons-react");
27
27
 
28
28
  var _useFocusZone = require("../hooks/useFocusZone");
29
29
 
30
- var _focusZone = require("../behaviors/focusZone");
30
+ var _behaviors = require("@primer/behaviors");
31
31
 
32
32
  var _Portal = _interopRequireDefault(require("../Portal"));
33
33
 
@@ -121,7 +121,7 @@ const DefaultFooter = ({
121
121
  const {
122
122
  containerRef: footerRef
123
123
  } = (0, _useFocusZone.useFocusZone)({
124
- bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.Tab,
124
+ bindKeys: _behaviors.FocusKeys.ArrowHorizontal | _behaviors.FocusKeys.Tab,
125
125
  focusInStrategy: 'closest'
126
126
  });
127
127
  return footerButtons ? /*#__PURE__*/_react.default.createElement(Dialog.Footer, {
@@ -29,7 +29,7 @@ var _useProvidedRefOrCreate = require("../hooks/useProvidedRefOrCreate");
29
29
 
30
30
  var _useScrollFlash = _interopRequireDefault(require("../hooks/useScrollFlash"));
31
31
 
32
- var _scrollIntoViewingArea = require("../behaviors/scrollIntoViewingArea");
32
+ var _behaviors = require("@primer/behaviors");
33
33
 
34
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
35
 
@@ -39,6 +39,11 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
39
39
 
40
40
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
41
41
 
42
+ const menuScrollMargins = {
43
+ startMargin: 0,
44
+ endMargin: 8
45
+ };
46
+
42
47
  const StyledHeader = _styledComponents.default.div.withConfig({
43
48
  displayName: "FilteredActionList__StyledHeader",
44
49
  componentId: "sc-yg3jkv-0"
@@ -86,7 +91,7 @@ function FilteredActionList({
86
91
  activeDescendantRef.current = current;
87
92
 
88
93
  if (current && scrollContainerRef.current && directlyActivated) {
89
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
94
+ (0, _behaviors.scrollIntoView)(current, scrollContainerRef.current, menuScrollMargins);
90
95
  }
91
96
  }
92
97
  }, [// List ref isn't set while loading. Need to re-bind focus zone when it changes
@@ -94,7 +99,9 @@ function FilteredActionList({
94
99
  (0, _react.useEffect)(() => {
95
100
  // if items changed, we want to instantly move active descendant into view
96
101
  if (activeDescendantRef.current && scrollContainerRef.current) {
97
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
102
+ (0, _behaviors.scrollIntoView)(activeDescendantRef.current, scrollContainerRef.current, { ...menuScrollMargins,
103
+ behavior: 'auto'
104
+ });
98
105
  }
99
106
  }, [items]);
100
107
  (0, _useScrollFlash.default)(scrollContainerRef);
package/lib/Overlay.d.ts CHANGED
@@ -2,7 +2,7 @@ import React, { ComponentPropsWithRef } from 'react';
2
2
  import { AriaRole, Merge } from './utils/types';
3
3
  import { TouchOrMouseEvent } from './hooks';
4
4
  import { SxProp } from './sx';
5
- import { AnchorSide } from './behaviors/anchoredPosition';
5
+ import type { AnchorSide } from '@primer/behaviors';
6
6
  import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
7
7
  declare type StyledOverlayProps = {
8
8
  width?: keyof typeof widthMap;
@@ -9,7 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _props = require("@styled-system/props");
11
11
 
12
- var _focusZone = require("./behaviors/focusZone");
12
+ var _behaviors = require("@primer/behaviors");
13
13
 
14
14
  var _useCombinedRefs = require("./hooks/useCombinedRefs");
15
15
 
@@ -27,7 +27,7 @@ var _Box = _interopRequireDefault(require("./Box"));
27
27
 
28
28
  var _Text = _interopRequireDefault(require("./Text"));
29
29
 
30
- var _iterateFocusableElements = require("./utils/iterateFocusableElements");
30
+ var _utils = require("@primer/behaviors/utils");
31
31
 
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
33
 
@@ -81,7 +81,7 @@ function TextInputWithTokensInnerComponent({
81
81
  containerRef
82
82
  } = (0, _useFocusZone.useFocusZone)({
83
83
  focusOutBehavior: 'wrap',
84
- bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
84
+ bindKeys: _behaviors.FocusKeys.ArrowHorizontal | _behaviors.FocusKeys.HomeAndEnd,
85
85
  focusableElementFilter: element => {
86
86
  return !element.getAttributeNames().includes('aria-hidden');
87
87
  },
@@ -119,7 +119,7 @@ function TextInputWithTokensInnerComponent({
119
119
  const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
120
120
  // `nextFocusableElement` is the div that wraps the input
121
121
 
122
- const firstFocusable = nextElementToFocus && (0, _iterateFocusableElements.isFocusable)(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => (0, _iterateFocusableElements.isFocusable)(el));
122
+ const firstFocusable = nextElementToFocus && (0, _utils.isFocusable)(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => (0, _utils.isFocusable)(el));
123
123
 
124
124
  if (firstFocusable) {
125
125
  firstFocusable.focus();
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PositionSettings, AnchorPosition } from '../behaviors/anchoredPosition';
2
+ import type { AnchorPosition, PositionSettings } from '@primer/behaviors';
3
3
  export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
4
4
  floatingElementRef?: React.RefObject<Element>;
5
5
  anchorElementRef?: React.RefObject<Element>;
@@ -7,7 +7,7 @@ exports.useAnchoredPosition = useAnchoredPosition;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _anchoredPosition = require("../behaviors/anchoredPosition");
10
+ var _behaviors = require("@primer/behaviors");
11
11
 
12
12
  var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
13
13
 
@@ -34,7 +34,7 @@ function useAnchoredPosition(settings, dependencies = []) {
34
34
 
35
35
  const updatePosition = _react.default.useCallback(() => {
36
36
  if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
37
- setPosition((0, _anchoredPosition.getAnchoredPosition)(floatingElementRef.current, anchorElementRef.current, settings));
37
+ setPosition((0, _behaviors.getAnchoredPosition)(floatingElementRef.current, anchorElementRef.current, settings));
38
38
  } else {
39
39
  setPosition(undefined);
40
40
  }
@@ -7,7 +7,7 @@ exports.useFocusTrap = useFocusTrap;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _focusTrap = require("../behaviors/focusTrap");
10
+ var _behaviors = require("@primer/behaviors");
11
11
 
12
12
  var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
13
13
 
@@ -51,7 +51,7 @@ function useFocusTrap(settings, dependencies = []) {
51
51
  if (!disabled) {
52
52
  var _initialFocusRef$curr;
53
53
 
54
- abortController.current = (0, _focusTrap.focusTrap)(containerRef.current, (_initialFocusRef$curr = initialFocusRef.current) !== null && _initialFocusRef$curr !== void 0 ? _initialFocusRef$curr : undefined);
54
+ abortController.current = (0, _behaviors.focusTrap)(containerRef.current, (_initialFocusRef$curr = initialFocusRef.current) !== null && _initialFocusRef$curr !== void 0 ? _initialFocusRef$curr : undefined);
55
55
  return () => {
56
56
  disableTrap();
57
57
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { FocusZoneSettings } from '../behaviors/focusZone';
2
+ import type { FocusZoneSettings } from '@primer/behaviors';
3
3
  export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
4
4
  /**
5
5
  * Optional ref for the container that holds all elements participating in arrow key focus.
@@ -7,7 +7,7 @@ exports.useFocusZone = useFocusZone;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _focusZone = require("../behaviors/focusZone");
10
+ var _behaviors = require("@primer/behaviors");
11
11
 
12
12
  var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
13
13
 
@@ -32,7 +32,7 @@ function useFocusZone(settings = {}, dependencies = []) {
32
32
  const vanillaSettings = { ...settings,
33
33
  activeDescendantControl: (_activeDescendantCont = activeDescendantControlRef.current) !== null && _activeDescendantCont !== void 0 ? _activeDescendantCont : undefined
34
34
  };
35
- abortController.current = (0, _focusZone.focusZone)(containerRef.current, vanillaSettings);
35
+ abortController.current = (0, _behaviors.focusZone)(containerRef.current, vanillaSettings);
36
36
  return () => {
37
37
  var _abortController$curr;
38
38
 
@@ -7,7 +7,7 @@ exports.useOpenAndCloseFocus = useOpenAndCloseFocus;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _iterateFocusableElements = require("../utils/iterateFocusableElements");
10
+ var _utils = require("@primer/behaviors/utils");
11
11
 
12
12
  function useOpenAndCloseFocus({
13
13
  initialFocusRef,
@@ -25,7 +25,7 @@ function useOpenAndCloseFocus({
25
25
  if (initialFocusRef && initialFocusRef.current) {
26
26
  initialFocusRef.current.focus();
27
27
  } else if (containerRef.current) {
28
- const firstItem = (0, _iterateFocusableElements.iterateFocusableElements)(containerRef.current).next().value;
28
+ const firstItem = (0, _utils.iterateFocusableElements)(containerRef.current).next().value;
29
29
  firstItem === null || firstItem === void 0 ? void 0 : firstItem.focus();
30
30
  }
31
31
 
@@ -9,7 +9,7 @@ import styled from 'styled-components';
9
9
  import { StyledHeader } from './Header';
10
10
  import { StyledDivider } from './Divider';
11
11
  import { useTheme } from '../ThemeProvider';
12
- import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
12
+ import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '@primer/behaviors';
13
13
  import { useSSRSafeId } from '@react-aria/ssr';
14
14
 
15
15
  const getItemVariant = (variant = 'default', disabled) => {
@@ -6,7 +6,7 @@ import { Item } from './Item';
6
6
  import { Divider } from './Divider';
7
7
  import styled from 'styled-components';
8
8
  import { get } from '../constants';
9
- import { hasActiveDescendantAttribute } from '../behaviors/focusZone';
9
+ import { hasActiveDescendantAttribute } from '@primer/behaviors';
10
10
 
11
11
  /**
12
12
  * Asserts that the given value fulfills the `GroupedListProps` contract.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { OverlayProps } from '../Overlay';
3
3
  import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
4
  import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
- import { PositionSettings } from '../behaviors/anchoredPosition';
5
+ import type { PositionSettings } from '@primer/behaviors';
6
6
  interface AnchoredOverlayPropsWithAnchor {
7
7
  /**
8
8
  * A custom function component used to render the anchor element.
@@ -4,11 +4,16 @@ import { useFocusZone } from '../hooks/useFocusZone';
4
4
  import { Box, Spinner } from '../';
5
5
  import { AutocompleteContext } from './AutocompleteContext';
6
6
  import { PlusIcon } from '@primer/octicons-react';
7
- import { uniqueId } from '../utils/uniqueId';
8
- import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
7
+ import { uniqueId } from '@primer/behaviors/utils';
8
+ import { scrollIntoView } from '@primer/behaviors';
9
9
 
10
10
  const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
11
11
 
12
+ const menuScrollMargins = {
13
+ startMargin: 0,
14
+ endMargin: 8
15
+ };
16
+
12
17
  function getDefaultItemFilter(filterValue) {
13
18
  return function (item, _i) {
14
19
  var _item$text;
@@ -134,9 +139,9 @@ function AutocompleteMenu(props) {
134
139
  }
135
140
 
136
141
  if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
137
- scrollIntoViewingArea(current, customScrollContainerRef.current);
142
+ scrollIntoView(current, customScrollContainerRef.current, menuScrollMargins);
138
143
  } else if (current && scrollContainerRef.current && directlyActivated) {
139
- scrollIntoViewingArea(current, scrollContainerRef.current);
144
+ scrollIntoView(current, scrollContainerRef.current, menuScrollMargins);
140
145
  }
141
146
  }
142
147
  }, [loading]);
@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';
5
5
  import styled from 'styled-components';
6
6
  import Box from '../Box';
7
7
  import { ThemeProvider, useTheme } from '../ThemeProvider';
8
- import { FocusKeys } from '../behaviors/focusZone';
8
+ import { FocusKeys } from '@primer/behaviors';
9
9
  import { get } from '../constants';
10
10
  import { Dialog } from '../Dialog/Dialog';
11
11
  import { useFocusZone } from '../hooks/useFocusZone';
@@ -11,7 +11,7 @@ import sx from '../sx';
11
11
  import StyledOcticon from '../StyledOcticon';
12
12
  import { XIcon } from '@primer/octicons-react';
13
13
  import { useFocusZone } from '../hooks/useFocusZone';
14
- import { FocusKeys } from '../behaviors/focusZone';
14
+ import { FocusKeys } from '@primer/behaviors';
15
15
  import Portal from '../Portal';
16
16
  import { useCombinedRefs } from '../hooks/useCombinedRefs';
17
17
  import { useSSRSafeId } from '@react-aria/ssr';
@@ -12,7 +12,11 @@ import styled from 'styled-components';
12
12
  import { get } from '../constants';
13
13
  import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate';
14
14
  import useScrollFlash from '../hooks/useScrollFlash';
15
- import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
15
+ import { scrollIntoView } from '@primer/behaviors';
16
+ const menuScrollMargins = {
17
+ startMargin: 0,
18
+ endMargin: 8
19
+ };
16
20
  const StyledHeader = styled.div.withConfig({
17
21
  displayName: "FilteredActionList__StyledHeader",
18
22
  componentId: "sc-yg3jkv-0"
@@ -59,7 +63,7 @@ export function FilteredActionList({
59
63
  activeDescendantRef.current = current;
60
64
 
61
65
  if (current && scrollContainerRef.current && directlyActivated) {
62
- scrollIntoViewingArea(current, scrollContainerRef.current);
66
+ scrollIntoView(current, scrollContainerRef.current, menuScrollMargins);
63
67
  }
64
68
  }
65
69
  }, [// List ref isn't set while loading. Need to re-bind focus zone when it changes
@@ -67,7 +71,9 @@ export function FilteredActionList({
67
71
  useEffect(() => {
68
72
  // if items changed, we want to instantly move active descendant into view
69
73
  if (activeDescendantRef.current && scrollContainerRef.current) {
70
- scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
74
+ scrollIntoView(activeDescendantRef.current, scrollContainerRef.current, { ...menuScrollMargins,
75
+ behavior: 'auto'
76
+ });
71
77
  }
72
78
  }, [items]);
73
79
  useScrollFlash(scrollContainerRef);
@@ -2,7 +2,7 @@ import React, { ComponentPropsWithRef } from 'react';
2
2
  import { AriaRole, Merge } from './utils/types';
3
3
  import { TouchOrMouseEvent } from './hooks';
4
4
  import { SxProp } from './sx';
5
- import { AnchorSide } from './behaviors/anchoredPosition';
5
+ import type { AnchorSide } from '@primer/behaviors';
6
6
  import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
7
7
  declare type StyledOverlayProps = {
8
8
  width?: keyof typeof widthMap;
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React, { useRef, useState } from 'react';
4
4
  import { omit } from '@styled-system/props';
5
- import { FocusKeys } from './behaviors/focusZone';
5
+ import { FocusKeys } from '@primer/behaviors';
6
6
  import { useCombinedRefs } from './hooks/useCombinedRefs';
7
7
  import { useFocusZone } from './hooks/useFocusZone';
8
8
  import Token from './Token/Token';
@@ -11,7 +11,7 @@ import UnstyledTextInput from './_UnstyledTextInput';
11
11
  import TextInputWrapper from './_TextInputWrapper';
12
12
  import Box from './Box';
13
13
  import Text from './Text';
14
- import { isFocusable } from './utils/iterateFocusableElements'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ import { isFocusable } from '@primer/behaviors/utils'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
15
 
16
16
  const overflowCountFontSizeMap = {
17
17
  small: 0,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PositionSettings, AnchorPosition } from '../behaviors/anchoredPosition';
2
+ import type { AnchorPosition, PositionSettings } from '@primer/behaviors';
3
3
  export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
4
4
  floatingElementRef?: React.RefObject<Element>;
5
5
  anchorElementRef?: React.RefObject<Element>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { getAnchoredPosition } from '../behaviors/anchoredPosition';
2
+ import { getAnchoredPosition } from '@primer/behaviors';
3
3
  import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
4
4
  import { useResizeObserver } from './useResizeObserver';
5
5
  import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { focusTrap } from '../behaviors/focusTrap';
2
+ import { focusTrap } from '@primer/behaviors';
3
3
  import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { FocusZoneSettings } from '../behaviors/focusZone';
2
+ import type { FocusZoneSettings } from '@primer/behaviors';
3
3
  export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
4
4
  /**
5
5
  * Optional ref for the container that holds all elements participating in arrow key focus.
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect } from 'react';
2
- import { focusZone } from '../behaviors/focusZone';
2
+ import { focusZone } from '@primer/behaviors';
3
3
  import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
4
4
  export function useFocusZone(settings = {}, dependencies = []) {
5
5
  const containerRef = useProvidedRefOrCreate(settings.containerRef);
@@ -1,5 +1,5 @@
1
1
  import { useEffect } from 'react';
2
- import { iterateFocusableElements } from '../utils/iterateFocusableElements';
2
+ import { iterateFocusableElements } from '@primer/behaviors/utils';
3
3
  export function useOpenAndCloseFocus({
4
4
  initialFocusRef,
5
5
  returnFocusRef,
package/package.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021116182158",
3
+ "version": "0.0.0-202111619107",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
7
7
  "typings": "lib/index.d.ts",
8
- "sideEffects": [
9
- "(lib|lib-esm)/behaviors/focusZone.js",
10
- "(lib|lib-esm)/behaviors/focusTrap.js"
11
- ],
12
8
  "scripts": {
13
9
  "setup": "./script/setup",
14
10
  "build": "./script/build",
@@ -43,6 +39,7 @@
43
39
  "author": "GitHub, Inc.",
44
40
  "license": "MIT",
45
41
  "dependencies": {
42
+ "@primer/behaviors": "^1.0.2",
46
43
  "@primer/octicons-react": "^16.1.0",
47
44
  "@primer/primitives": "7.1.1",
48
45
  "@radix-ui/react-polymorphic": "0.0.14",
@@ -1,89 +0,0 @@
1
- export declare type AnchorAlignment = 'start' | 'center' | 'end';
2
- export declare type AnchorSide = 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right';
3
- /**
4
- * Settings that customize how a floating element is positioned
5
- * with respect to an anchor element.
6
- */
7
- export interface PositionSettings {
8
- /**
9
- * Sets the side of the anchor element that the floating element should be
10
- * pinned to. This side is given by a string starting with either "inside" or
11
- * "outside", followed by a hyphen, followed by either "top", "right", "bottom",
12
- * or "left". Additionally, "inside-center" is an allowed value.
13
- *
14
- * The first part of this string, "inside" or "outside", determines whether the
15
- * floating element should be attempted to be placed "inside" the anchor element
16
- * or "outside" of it. Using "inside" is useful for making it appear that the
17
- * anchor _contains_ the floating element, and it can be used for implementing a
18
- * dialog that is centered on the screen. The "outside" value is more common and
19
- * can be used for tooltips, popovers, menus, etc.
20
- *
21
- * The second part of this string determines the _edge_ on the anchor element that
22
- * the floating element will be anchored to. If side is "inside-center", then
23
- * the floating element will be centered in the X-direction (while align is used
24
- * to position it in the Y-direction).
25
- * Note: "outside-center" is _not_ a valid value for this property.
26
- */
27
- side: AnchorSide;
28
- /**
29
- * Determines how the floating element should align with the anchor element. If
30
- * set to "start", the floating element's first edge (top or left) will align
31
- * with the anchor element's first edge. If set to "center", the floating
32
- * element will be centered along the axis of the anchor edge. If set to "end",
33
- * the floating element's last edge will align with the anchor element's last edge.
34
- */
35
- align: AnchorAlignment;
36
- /**
37
- * The number of pixels between the anchor edge and the floating element.
38
- *
39
- * Positive values move the floating element farther from the anchor element
40
- * (for outside positioning) or further inside the anchor element (for inside
41
- * positioning). Negative values have the opposite effect.
42
- */
43
- anchorOffset: number;
44
- /**
45
- * An additional offset, in pixels, to move the floating element from
46
- * the aligning edge.
47
- *
48
- * Positive values move the floating element in the direction of center-
49
- * alignment. Negative values move the floating element away from center-
50
- * alignment. When align is "center", positive offsets move the floating
51
- * element right (top or bottom anchor side) or down (left or right
52
- * anchor side).
53
- */
54
- alignmentOffset: number;
55
- /**
56
- * If false, when the above settings result in rendering the floating element
57
- * wholly or partially outside of the bounds of the containing element, attempt
58
- * to adjust the settings to prevent this. Only applies to "outside" positioning.
59
- *
60
- * First, attempt to flip to the opposite edge of the anchor if the floating
61
- * element is getting clipped in that direction. If flipping results in a
62
- * similar clipping, try moving to the adjacent sides.
63
- *
64
- * Once we find a side that does not clip the overlay in its own dimension,
65
- * check the rest of the sides to see if we need to adjust the alignment offset
66
- * to fit in other dimensions.
67
- *
68
- * If we try all four sides and get clipped each time, settle for overflowing
69
- * and use the "bottom" side, since the ability to scroll is most likely in
70
- * this direction.
71
- */
72
- allowOutOfBounds: boolean;
73
- }
74
- export interface AnchorPosition {
75
- top: number;
76
- left: number;
77
- anchorSide: AnchorSide;
78
- }
79
- /**
80
- * Given a floating element and an anchor element, return coordinates for the top-left
81
- * of the floating element in order to absolutely position it such that it appears
82
- * near the anchor element.
83
- *
84
- * @param floatingElement Element intended to be positioned near or within an anchor
85
- * @param anchorElement The element to serve as the position anchor
86
- * @param settings Settings to determine the rules for positioning the floating element
87
- * @returns {top: number, left: number} coordinates for the floating element
88
- */
89
- export declare function getAnchoredPosition(floatingElement: Element, anchorElement: Element | DOMRect, settings?: Partial<PositionSettings>): AnchorPosition;