@primer/components 0.0.0-202111616587 → 0.0.0-2021116181214

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 (175) 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 +11 -23
  9. package/lib/CheckboxInputField.d.ts +11 -0
  10. package/lib/CheckboxInputField.js +73 -0
  11. package/lib/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
  12. package/lib/ChoiceFieldset/ChoiceFieldCaption.js +35 -0
  13. package/lib/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
  14. package/lib/ChoiceFieldset/ChoiceFieldLabel.js +35 -0
  15. package/lib/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
  16. package/lib/ChoiceFieldset/ChoiceFieldset.js +95 -0
  17. package/lib/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
  18. package/lib/ChoiceFieldset/ChoiceFieldsetDescription.js +29 -0
  19. package/lib/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
  20. package/lib/ChoiceFieldset/ChoiceFieldsetLegend.js +44 -0
  21. package/lib/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
  22. package/lib/ChoiceFieldset/ChoiceFieldsetList.js +69 -0
  23. package/lib/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
  24. package/lib/ChoiceFieldset/ChoiceFieldsetListContext.js +15 -0
  25. package/lib/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
  26. package/lib/ChoiceFieldset/ChoiceFieldsetListItem.js +75 -0
  27. package/lib/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
  28. package/lib/ChoiceFieldset/ChoiceFieldsetValidation.js +17 -0
  29. package/lib/ChoiceFieldset/index.d.ts +3 -0
  30. package/lib/ChoiceFieldset/index.js +23 -0
  31. package/lib/Dialog/ConfirmationDialog.js +2 -2
  32. package/lib/Dialog/Dialog.js +2 -2
  33. package/lib/FilteredActionList/FilteredActionList.js +3 -10
  34. package/lib/Overlay.d.ts +1 -1
  35. package/lib/RadioInputField.d.ts +10 -0
  36. package/lib/RadioInputField.js +74 -0
  37. package/lib/TextInputField.d.ts +583 -0
  38. package/lib/TextInputField.js +66 -0
  39. package/lib/TextInputWithTokens.js +4 -4
  40. package/lib/_InputCaption.d.ts +13 -0
  41. package/lib/_InputCaption.js +27 -0
  42. package/lib/_InputField/InputField.d.ts +39 -0
  43. package/lib/_InputField/InputField.js +90 -0
  44. package/lib/_InputField/InputFieldCaption.d.ts +3 -0
  45. package/lib/_InputField/InputFieldCaption.js +30 -0
  46. package/lib/_InputField/InputFieldLabel.d.ts +9 -0
  47. package/lib/_InputField/InputFieldLabel.js +34 -0
  48. package/lib/_InputField/InputFieldValidation.d.ts +6 -0
  49. package/lib/_InputField/InputFieldValidation.js +17 -0
  50. package/lib/_InputField/ToggleInputField.d.ts +13 -0
  51. package/lib/_InputField/ToggleInputField.js +71 -0
  52. package/lib/_InputField/ToggleInputLeadingVisual.d.ts +3 -0
  53. package/lib/_InputField/ToggleInputLeadingVisual.js +22 -0
  54. package/lib/_InputField/ValidationAnimationContainer.d.ts +6 -0
  55. package/lib/_InputField/ValidationAnimationContainer.js +48 -0
  56. package/lib/_InputField/index.d.ts +1 -0
  57. package/lib/_InputField/index.js +15 -0
  58. package/lib/_InputField/slots.d.ts +13 -0
  59. package/lib/_InputField/slots.js +17 -0
  60. package/lib/_InputLabel.d.ts +8 -0
  61. package/lib/_InputLabel.js +44 -0
  62. package/lib/_InputValidation.d.ts +8 -0
  63. package/lib/_InputValidation.js +56 -0
  64. package/lib/_VisuallyHidden.d.ts +6 -0
  65. package/lib/_VisuallyHidden.js +39 -0
  66. package/lib/behaviors/anchoredPosition.d.ts +89 -0
  67. package/lib/behaviors/anchoredPosition.js +316 -0
  68. package/lib/behaviors/focusTrap.d.ts +12 -0
  69. package/lib/behaviors/focusTrap.js +179 -0
  70. package/lib/behaviors/focusZone.d.ts +137 -0
  71. package/lib/behaviors/focusZone.js +578 -0
  72. package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
  73. package/lib/behaviors/scrollIntoViewingArea.js +39 -0
  74. package/lib/hooks/useAnchoredPosition.d.ts +1 -1
  75. package/lib/hooks/useAnchoredPosition.js +2 -2
  76. package/lib/hooks/useFocusTrap.js +2 -2
  77. package/lib/hooks/useFocusZone.d.ts +1 -1
  78. package/lib/hooks/useFocusZone.js +2 -2
  79. package/lib/hooks/useOpenAndCloseFocus.js +2 -2
  80. package/lib/index.d.ts +4 -0
  81. package/lib/index.js +38 -0
  82. package/lib/utils/iterateFocusableElements.d.ts +42 -0
  83. package/lib/utils/iterateFocusableElements.js +113 -0
  84. package/lib/utils/types/FormValidationStatus.d.ts +1 -0
  85. package/lib/utils/types/FormValidationStatus.js +1 -0
  86. package/lib/utils/uniqueId.d.ts +1 -0
  87. package/lib/utils/uniqueId.js +12 -0
  88. package/lib/utils/userAgent.d.ts +1 -0
  89. package/lib/utils/userAgent.js +15 -0
  90. package/lib-esm/ActionList/Item.js +1 -1
  91. package/lib-esm/ActionList/List.js +1 -1
  92. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  93. package/lib-esm/Autocomplete/AutocompleteMenu.js +7 -22
  94. package/lib-esm/CheckboxInputField.d.ts +11 -0
  95. package/lib-esm/CheckboxInputField.js +56 -0
  96. package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
  97. package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.js +20 -0
  98. package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
  99. package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.js +20 -0
  100. package/lib-esm/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
  101. package/lib-esm/ChoiceFieldset/ChoiceFieldset.js +72 -0
  102. package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
  103. package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.js +17 -0
  104. package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
  105. package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.js +31 -0
  106. package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
  107. package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.js +52 -0
  108. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
  109. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.js +5 -0
  110. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
  111. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.js +51 -0
  112. package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
  113. package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.js +7 -0
  114. package/lib-esm/ChoiceFieldset/index.d.ts +3 -0
  115. package/lib-esm/ChoiceFieldset/index.js +2 -0
  116. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  117. package/lib-esm/Dialog/Dialog.js +1 -1
  118. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -9
  119. package/lib-esm/Overlay.d.ts +1 -1
  120. package/lib-esm/RadioInputField.d.ts +10 -0
  121. package/lib-esm/RadioInputField.js +56 -0
  122. package/lib-esm/TextInputField.d.ts +583 -0
  123. package/lib-esm/TextInputField.js +50 -0
  124. package/lib-esm/TextInputWithTokens.js +2 -2
  125. package/lib-esm/_InputCaption.d.ts +13 -0
  126. package/lib-esm/_InputCaption.js +16 -0
  127. package/lib-esm/_InputField/InputField.d.ts +39 -0
  128. package/lib-esm/_InputField/InputField.js +70 -0
  129. package/lib-esm/_InputField/InputFieldCaption.d.ts +3 -0
  130. package/lib-esm/_InputField/InputFieldCaption.js +18 -0
  131. package/lib-esm/_InputField/InputFieldLabel.d.ts +9 -0
  132. package/lib-esm/_InputField/InputFieldLabel.js +22 -0
  133. package/lib-esm/_InputField/InputFieldValidation.d.ts +6 -0
  134. package/lib-esm/_InputField/InputFieldValidation.js +7 -0
  135. package/lib-esm/_InputField/ToggleInputField.d.ts +13 -0
  136. package/lib-esm/_InputField/ToggleInputField.js +54 -0
  137. package/lib-esm/_InputField/ToggleInputLeadingVisual.d.ts +3 -0
  138. package/lib-esm/_InputField/ToggleInputLeadingVisual.js +11 -0
  139. package/lib-esm/_InputField/ValidationAnimationContainer.d.ts +6 -0
  140. package/lib-esm/_InputField/ValidationAnimationContainer.js +33 -0
  141. package/lib-esm/_InputField/index.d.ts +1 -0
  142. package/lib-esm/_InputField/index.js +1 -0
  143. package/lib-esm/_InputField/slots.d.ts +13 -0
  144. package/lib-esm/_InputField/slots.js +5 -0
  145. package/lib-esm/_InputLabel.d.ts +8 -0
  146. package/lib-esm/_InputLabel.js +32 -0
  147. package/lib-esm/_InputValidation.d.ts +8 -0
  148. package/lib-esm/_InputValidation.js +43 -0
  149. package/lib-esm/_VisuallyHidden.d.ts +6 -0
  150. package/lib-esm/_VisuallyHidden.js +26 -0
  151. package/lib-esm/behaviors/anchoredPosition.d.ts +89 -0
  152. package/lib-esm/behaviors/anchoredPosition.js +309 -0
  153. package/lib-esm/behaviors/focusTrap.d.ts +12 -0
  154. package/lib-esm/behaviors/focusTrap.js +170 -0
  155. package/lib-esm/behaviors/focusZone.d.ts +137 -0
  156. package/lib-esm/behaviors/focusZone.js +560 -0
  157. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
  158. package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
  159. package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
  160. package/lib-esm/hooks/useAnchoredPosition.js +1 -1
  161. package/lib-esm/hooks/useFocusTrap.js +1 -1
  162. package/lib-esm/hooks/useFocusZone.d.ts +1 -1
  163. package/lib-esm/hooks/useFocusZone.js +1 -1
  164. package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
  165. package/lib-esm/index.d.ts +4 -0
  166. package/lib-esm/index.js +4 -0
  167. package/lib-esm/utils/iterateFocusableElements.d.ts +42 -0
  168. package/lib-esm/utils/iterateFocusableElements.js +102 -0
  169. package/lib-esm/utils/types/FormValidationStatus.d.ts +1 -0
  170. package/lib-esm/utils/types/FormValidationStatus.js +1 -0
  171. package/lib-esm/utils/uniqueId.d.ts +1 -0
  172. package/lib-esm/utils/uniqueId.js +5 -0
  173. package/lib-esm/utils/userAgent.d.ts +1 -0
  174. package/lib-esm/utils/userAgent.js +8 -0
  175. package/package.json +6 -3
@@ -7,7 +7,7 @@ exports.useFocusZone = useFocusZone;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _behaviors = require("@primer/behaviors");
10
+ var _focusZone = require("../behaviors/focusZone");
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, _behaviors.focusZone)(containerRef.current, vanillaSettings);
35
+ abortController.current = (0, _focusZone.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 _utils = require("@primer/behaviors/utils");
10
+ var _iterateFocusableElements = require("../utils/iterateFocusableElements");
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, _utils.iterateFocusableElements)(containerRef.current).next().value;
28
+ const firstItem = (0, _iterateFocusableElements.iterateFocusableElements)(containerRef.current).next().value;
29
29
  firstItem === null || firstItem === void 0 ? void 0 : firstItem.focus();
30
30
  }
31
31
 
package/lib/index.d.ts CHANGED
@@ -48,6 +48,8 @@ export { default as CircleBadge } from './CircleBadge';
48
48
  export type { CircleBadgeProps, CircleBadgeIconProps } from './CircleBadge';
49
49
  export { default as CircleOcticon } from './CircleOcticon';
50
50
  export type { CircleOcticonProps } from './CircleOcticon';
51
+ export { default as CheckboxInputField } from './CheckboxInputField';
52
+ export { default as ChoiceFieldset, Item } from './ChoiceFieldset';
51
53
  export { default as CounterLabel } from './CounterLabel';
52
54
  export type { CounterLabelProps } from './CounterLabel';
53
55
  export { default as Details } from './Details';
@@ -88,6 +90,7 @@ export { default as Popover } from './Popover';
88
90
  export type { PopoverProps, PopoverContentProps } from './Popover';
89
91
  export { default as ProgressBar } from './ProgressBar';
90
92
  export type { ProgressBarProps } from './ProgressBar';
93
+ export { default as RadioInputField } from './RadioInputField';
91
94
  export { default as SelectMenu } from './SelectMenu';
92
95
  export type { SelectMenuProps, SelectMenuDividerProps, SelectMenuFilterProps, SelectMenuFooterProps, SelectMenuItemProps, SelectMenuListProps, SelectMenuModalProps, SelectMenuTabsProps, SelectMenuHeaderProps, SelectMenuTabProps, SelectMenuTabPanelProps, SelectMenuLoadingAnimationProps } from './SelectMenu';
93
96
  export { default as SideNav } from './SideNav';
@@ -104,6 +107,7 @@ export { default as TabNav } from './TabNav';
104
107
  export type { TabNavProps, TabNavLinkProps } from './TabNav';
105
108
  export { default as TextInput } from './TextInput';
106
109
  export type { TextInputProps } from './TextInput';
110
+ export { default as TextInputField } from './TextInputField';
107
111
  export { default as TextInputWithTokens } from './TextInputWithTokens';
108
112
  export type { TextInputWithTokensProps } from './TextInputWithTokens';
109
113
  export { default as Text } from './Text';
package/lib/index.js CHANGED
@@ -273,6 +273,24 @@ Object.defineProperty(exports, "CircleOcticon", {
273
273
  return _CircleOcticon.default;
274
274
  }
275
275
  });
276
+ Object.defineProperty(exports, "CheckboxInputField", {
277
+ enumerable: true,
278
+ get: function () {
279
+ return _CheckboxInputField.default;
280
+ }
281
+ });
282
+ Object.defineProperty(exports, "ChoiceFieldset", {
283
+ enumerable: true,
284
+ get: function () {
285
+ return _ChoiceFieldset.default;
286
+ }
287
+ });
288
+ Object.defineProperty(exports, "Item", {
289
+ enumerable: true,
290
+ get: function () {
291
+ return _ChoiceFieldset.Item;
292
+ }
293
+ });
276
294
  Object.defineProperty(exports, "CounterLabel", {
277
295
  enumerable: true,
278
296
  get: function () {
@@ -399,6 +417,12 @@ Object.defineProperty(exports, "ProgressBar", {
399
417
  return _ProgressBar.default;
400
418
  }
401
419
  });
420
+ Object.defineProperty(exports, "RadioInputField", {
421
+ enumerable: true,
422
+ get: function () {
423
+ return _RadioInputField.default;
424
+ }
425
+ });
402
426
  Object.defineProperty(exports, "SelectMenu", {
403
427
  enumerable: true,
404
428
  get: function () {
@@ -447,6 +471,12 @@ Object.defineProperty(exports, "TextInput", {
447
471
  return _TextInput.default;
448
472
  }
449
473
  });
474
+ Object.defineProperty(exports, "TextInputField", {
475
+ enumerable: true,
476
+ get: function () {
477
+ return _TextInputField.default;
478
+ }
479
+ });
450
480
  Object.defineProperty(exports, "TextInputWithTokens", {
451
481
  enumerable: true,
452
482
  get: function () {
@@ -580,6 +610,10 @@ var _CircleBadge = _interopRequireDefault(require("./CircleBadge"));
580
610
 
581
611
  var _CircleOcticon = _interopRequireDefault(require("./CircleOcticon"));
582
612
 
613
+ var _CheckboxInputField = _interopRequireDefault(require("./CheckboxInputField"));
614
+
615
+ var _ChoiceFieldset = _interopRequireWildcard(require("./ChoiceFieldset"));
616
+
583
617
  var _CounterLabel = _interopRequireDefault(require("./CounterLabel"));
584
618
 
585
619
  var _Details = _interopRequireDefault(require("./Details"));
@@ -620,6 +654,8 @@ var _Popover = _interopRequireDefault(require("./Popover"));
620
654
 
621
655
  var _ProgressBar = _interopRequireDefault(require("./ProgressBar"));
622
656
 
657
+ var _RadioInputField = _interopRequireDefault(require("./RadioInputField"));
658
+
623
659
  var _SelectMenu = _interopRequireDefault(require("./SelectMenu"));
624
660
 
625
661
  var _SideNav = _interopRequireDefault(require("./SideNav"));
@@ -636,6 +672,8 @@ var _TabNav = _interopRequireDefault(require("./TabNav"));
636
672
 
637
673
  var _TextInput = _interopRequireDefault(require("./TextInput"));
638
674
 
675
+ var _TextInputField = _interopRequireDefault(require("./TextInputField"));
676
+
639
677
  var _TextInputWithTokens = _interopRequireDefault(require("./TextInputWithTokens"));
640
678
 
641
679
  var _Text = _interopRequireDefault(require("./Text"));
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Options to the focusable elements iterator
3
+ */
4
+ export interface IterateFocusableElements {
5
+ /**
6
+ * (Default: false) Iterate through focusable elements in reverse-order
7
+ */
8
+ reverse?: boolean;
9
+ /**
10
+ * (Default: false) Perform additional checks to determine tabbability
11
+ * which may adversely affect app performance.
12
+ */
13
+ strict?: boolean;
14
+ /**
15
+ * (Default: false) Only iterate tabbable elements, which is the subset
16
+ * of focusable elements that are part of the page's tab sequence.
17
+ */
18
+ onlyTabbable?: boolean;
19
+ }
20
+ /**
21
+ * Returns an iterator over all of the focusable elements within `container`.
22
+ * Note: If `container` is itself focusable it will be included in the results.
23
+ * @param container The container over which to find focusable elements.
24
+ * @param reverse If true, iterate backwards through focusable elements.
25
+ */
26
+ export declare function iterateFocusableElements(container: HTMLElement, options?: IterateFocusableElements): Generator<HTMLElement, undefined, undefined>;
27
+ /**
28
+ * Determines whether the given element is focusable. If `strict` is true, we may
29
+ * perform additional checks that require a reflow (less performant).
30
+ * @param elem
31
+ * @param strict
32
+ */
33
+ export declare function isFocusable(elem: HTMLElement, strict?: boolean): boolean;
34
+ /**
35
+ * Determines whether the given element is tabbable. If `strict` is true, we may
36
+ * perform additional checks that require a reflow (less performant). This check
37
+ * ensures that the element is focusable and that its tabindex is not explicitly
38
+ * set to "-1" (which makes it focusable, but removes it from the tab order).
39
+ * @param elem
40
+ * @param strict
41
+ */
42
+ export declare function isTabbable(elem: HTMLElement, strict?: boolean): boolean;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.iterateFocusableElements = iterateFocusableElements;
7
+ exports.isFocusable = isFocusable;
8
+ exports.isTabbable = isTabbable;
9
+
10
+ /**
11
+ * Options to the focusable elements iterator
12
+ */
13
+
14
+ /**
15
+ * Returns an iterator over all of the focusable elements within `container`.
16
+ * Note: If `container` is itself focusable it will be included in the results.
17
+ * @param container The container over which to find focusable elements.
18
+ * @param reverse If true, iterate backwards through focusable elements.
19
+ */
20
+ function* iterateFocusableElements(container, options = {}) {
21
+ var _options$strict, _options$onlyTabbable;
22
+
23
+ const strict = (_options$strict = options.strict) !== null && _options$strict !== void 0 ? _options$strict : false;
24
+ const acceptFn = ((_options$onlyTabbable = options.onlyTabbable) !== null && _options$onlyTabbable !== void 0 ? _options$onlyTabbable : false) ? isTabbable : isFocusable;
25
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
26
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
27
+ });
28
+ let nextNode = null; // Allow the container to participate
29
+
30
+ if (!options.reverse && acceptFn(container, strict)) {
31
+ yield container;
32
+ } // If iterating in reverse, continue traversing down into the last child until we reach
33
+ // a leaf DOM node
34
+
35
+
36
+ if (options.reverse) {
37
+ let lastChild = walker.lastChild();
38
+
39
+ while (lastChild) {
40
+ nextNode = lastChild;
41
+ lastChild = walker.lastChild();
42
+ }
43
+ } else {
44
+ nextNode = walker.firstChild();
45
+ }
46
+
47
+ while (nextNode instanceof HTMLElement) {
48
+ yield nextNode;
49
+ nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
50
+ } // Allow the container to participate (in reverse)
51
+
52
+
53
+ if (options.reverse && acceptFn(container, strict)) {
54
+ yield container;
55
+ }
56
+
57
+ return undefined;
58
+ }
59
+ /**
60
+ * Determines whether the given element is focusable. If `strict` is true, we may
61
+ * perform additional checks that require a reflow (less performant).
62
+ * @param elem
63
+ * @param strict
64
+ */
65
+
66
+
67
+ function isFocusable(elem, strict = false) {
68
+ // Certain conditions cause an element to never be focusable, even if they have tabindex="0"
69
+ const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
70
+ const hiddenInert = elem.hidden;
71
+ const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
72
+
73
+ if (disabledAttrInert || hiddenInert || hiddenInputInert) {
74
+ return false;
75
+ } // Each of the conditions checked below require a reflow, thus are gated by the `strict`
76
+ // argument. If any are true, the element is not focusable, even if tabindex is set.
77
+
78
+
79
+ if (strict) {
80
+ const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
81
+ const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
82
+ const clientRectsInert = elem.getClientRects().length === 0;
83
+
84
+ if (sizeInert || visibilityInert || clientRectsInert) {
85
+ return false;
86
+ }
87
+ } // Any element with `tabindex` explicitly set can be focusable, even if it's set to "-1"
88
+
89
+
90
+ if (elem.getAttribute('tabindex') != null) {
91
+ return true;
92
+ } // One last way `elem.tabIndex` can be wrong.
93
+
94
+
95
+ if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
96
+ return false;
97
+ }
98
+
99
+ return elem.tabIndex !== -1;
100
+ }
101
+ /**
102
+ * Determines whether the given element is tabbable. If `strict` is true, we may
103
+ * perform additional checks that require a reflow (less performant). This check
104
+ * ensures that the element is focusable and that its tabindex is not explicitly
105
+ * set to "-1" (which makes it focusable, but removes it from the tab order).
106
+ * @param elem
107
+ * @param strict
108
+ */
109
+
110
+
111
+ function isTabbable(elem, strict = false) {
112
+ return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
113
+ }
@@ -0,0 +1 @@
1
+ export declare type FormValidationStatus = 'error' | 'success';
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export declare function uniqueId(): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.uniqueId = uniqueId;
7
+ // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
8
+ let idSeed = 10000;
9
+
10
+ function uniqueId() {
11
+ return `__primer_id_${idSeed++}`;
12
+ }
@@ -0,0 +1 @@
1
+ export declare function isMacOS(): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isMacOS = isMacOS;
7
+ let isMac = undefined;
8
+
9
+ function isMacOS() {
10
+ if (isMac === undefined) {
11
+ isMac = /^mac/i.test(window.navigator.platform);
12
+ }
13
+
14
+ return isMac;
15
+ }
@@ -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 '@primer/behaviors';
12
+ import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
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 '@primer/behaviors';
9
+ import { hasActiveDescendantAttribute } from '../behaviors/focusZone';
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 type { PositionSettings } from '@primer/behaviors';
5
+ import { PositionSettings } from '../behaviors/anchoredPosition';
6
6
  interface AnchoredOverlayPropsWithAnchor {
7
7
  /**
8
8
  * A custom function component used to render the anchor element.
@@ -4,16 +4,12 @@ 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 '@primer/behaviors/utils';
8
- import { scrollIntoView } from '@primer/behaviors';
7
+ import { uniqueId } from '../utils/uniqueId';
8
+ import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
9
+ import VisuallyHidden from '../_VisuallyHidden';
9
10
 
10
11
  const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
11
12
 
12
- const menuScrollMargins = {
13
- startMargin: 0,
14
- endMargin: 8
15
- };
16
-
17
13
  function getDefaultItemFilter(filterValue) {
18
14
  return function (item, _i) {
19
15
  var _item$text;
@@ -139,9 +135,9 @@ function AutocompleteMenu(props) {
139
135
  }
140
136
 
141
137
  if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
142
- scrollIntoView(current, customScrollContainerRef.current, menuScrollMargins);
138
+ scrollIntoViewingArea(current, customScrollContainerRef.current);
143
139
  } else if (current && scrollContainerRef.current && directlyActivated) {
144
- scrollIntoView(current, scrollContainerRef.current, menuScrollMargins);
140
+ scrollIntoViewingArea(current, scrollContainerRef.current);
145
141
  }
146
142
  }
147
143
  }, [loading]);
@@ -169,19 +165,8 @@ function AutocompleteMenu(props) {
169
165
  setSelectedItemLength(selectedItemIds.length);
170
166
  }
171
167
  }, [selectedItemIds, setSelectedItemLength]);
172
- return /*#__PURE__*/React.createElement(Box, {
173
- sx: !showMenu ? {
174
- // visually hides this label for sighted users
175
- position: 'absolute',
176
- width: '1px',
177
- height: '1px',
178
- padding: '0',
179
- margin: '-1px',
180
- overflow: 'hidden',
181
- clip: 'rect(0, 0, 0, 0)',
182
- whiteSpace: 'nowrap',
183
- borderWidth: '0'
184
- } : {}
168
+ return /*#__PURE__*/React.createElement(VisuallyHidden, {
169
+ isVisible: showMenu
185
170
  }, loading ? /*#__PURE__*/React.createElement(Box, {
186
171
  p: 3,
187
172
  display: "flex",
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { ToggleInputFieldProps } from './_InputField/ToggleInputField';
3
+ declare const _default: React.FC<ToggleInputFieldProps> & {
4
+ Input: React.FC<React.HTMLProps<HTMLInputElement> & {
5
+ ref?: React.Ref<HTMLInputElement> | undefined;
6
+ }>;
7
+ Caption: React.FC<{}>;
8
+ Label: React.FC<import("./_InputField/InputFieldLabel").Props>;
9
+ LeadingVisual: React.FC<{}>;
10
+ };
11
+ export default _default;
@@ -0,0 +1,56 @@
1
+ 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); }
2
+
3
+ import React from 'react';
4
+ import { Checkbox } from '.';
5
+ import InputField from './_InputField/InputField';
6
+ import { Slot } from './_InputField/slots';
7
+ import ToggleInputField from './_InputField/ToggleInputField';
8
+ import ToggleInputLeadingVisual from './_InputField/ToggleInputLeadingVisual';
9
+
10
+ const Input = ({
11
+ id: idProp,
12
+ required: requiredProp,
13
+ disabled: disabledProp,
14
+ ...rest
15
+ }) => {
16
+ if (idProp) {
17
+ // eslint-disable-next-line no-console
18
+ console.warn("instead of passing the 'id' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
19
+ }
20
+
21
+ if (disabledProp) {
22
+ // eslint-disable-next-line no-console
23
+ console.warn("instead of passing the 'disabled' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
24
+ }
25
+
26
+ if (requiredProp) {
27
+ // eslint-disable-next-line no-console
28
+ console.warn("instead of passing the 'required' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
29
+ }
30
+
31
+ return /*#__PURE__*/React.createElement(Slot, {
32
+ name: "Input"
33
+ }, ({
34
+ disabled,
35
+ id,
36
+ required,
37
+ captionId
38
+ }) => /*#__PURE__*/React.createElement(Checkbox, _extends({
39
+ "aria-describedby": captionId,
40
+ id: id,
41
+ required: required,
42
+ disabled: disabled
43
+ }, rest)));
44
+ };
45
+
46
+ Input.displayName = "Input";
47
+
48
+ const CheckboxInputField = props => /*#__PURE__*/React.createElement(ToggleInputField, props);
49
+
50
+ CheckboxInputField.displayName = "CheckboxInputField";
51
+ export default Object.assign(CheckboxInputField, {
52
+ Input,
53
+ Caption: InputField.Caption,
54
+ Label: InputField.Label,
55
+ LeadingVisual: ToggleInputLeadingVisual
56
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChoiceFieldCaption: React.FC;
3
+ export default ChoiceFieldCaption;
@@ -0,0 +1,20 @@
1
+ import React, { useContext } from 'react';
2
+ import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
3
+
4
+ const ChoiceFieldCaption = ({
5
+ children
6
+ }) => {
7
+ const choiceFieldsetListContext = useContext(ChoiceFieldsetListContext);
8
+
9
+ if (choiceFieldsetListContext === null) {
10
+ throw new Error('ChoiceFieldsetListContext returned null');
11
+ }
12
+
13
+ const {
14
+ fieldComponent: FieldComponent
15
+ } = choiceFieldsetListContext;
16
+ return /*#__PURE__*/React.createElement(FieldComponent.Caption, null, children);
17
+ };
18
+
19
+ ChoiceFieldCaption.displayName = "ChoiceFieldCaption";
20
+ export default ChoiceFieldCaption;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChoiceFieldLabel: React.FC;
3
+ export default ChoiceFieldLabel;
@@ -0,0 +1,20 @@
1
+ import React, { useContext } from 'react';
2
+ import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
3
+
4
+ const ChoiceFieldLabel = ({
5
+ children
6
+ }) => {
7
+ const choiceFieldsetListContext = useContext(ChoiceFieldsetListContext);
8
+
9
+ if (choiceFieldsetListContext === null) {
10
+ throw new Error('ChoiceFieldsetListContext returned null');
11
+ }
12
+
13
+ const {
14
+ fieldComponent: FieldComponent
15
+ } = choiceFieldsetListContext;
16
+ return /*#__PURE__*/React.createElement(FieldComponent.Label, null, children);
17
+ };
18
+
19
+ ChoiceFieldLabel.displayName = "ChoiceFieldLabel";
20
+ export default ChoiceFieldLabel;
@@ -0,0 +1,65 @@
1
+ import React, { ComponentProps } from 'react';
2
+ import { FormValidationStatus } from '../utils/types/FormValidationStatus';
3
+ export interface ChoiceFieldsetProps<T = Record<string, FormValidationStatus>> {
4
+ children?: React.ReactNode;
5
+ /**
6
+ * Whether the fieldset is NOT ready for user input
7
+ */
8
+ disabled?: boolean;
9
+ /**
10
+ * The unique identifier for this fieldset. Used to associate the validation text with the fieldset
11
+ * If an ID is not passed, one will be automatically generated
12
+ */
13
+ id?: string;
14
+ /**
15
+ * The unique identifier used to associate radio inputs with eachother
16
+ * If a name is not passed and the fieldset renders radio inputs, a name will be automatically generated
17
+ */
18
+ name?: string;
19
+ /**
20
+ * The callback that is called when a user toggles a choice on or off
21
+ */
22
+ onSelect?: (selectedValues: string[]) => void;
23
+ /**
24
+ * Whether this field must have a value for the user to complete their task
25
+ */
26
+ required?: boolean;
27
+ /**
28
+ * The selected values
29
+ */
30
+ selected?: string[];
31
+ /**
32
+ * A map of validation statuses and their associated validation keys. When one of the validation keys is passed to the `validationResult` prop,
33
+ * the associated validation message will be rendered in the correct style
34
+ */
35
+ validationMap?: T;
36
+ /**
37
+ * The key of the validation message to show
38
+ */
39
+ validationResult?: keyof T;
40
+ }
41
+ export interface ChoiceFieldsetContext extends ChoiceFieldsetProps {
42
+ validationMessageId: string;
43
+ }
44
+ declare const Slot: React.FC<{
45
+ name: "Description" | "ChoiceList" | "Legend" | "Validation";
46
+ children: React.ReactNode;
47
+ }>;
48
+ export { Slot };
49
+ declare const ChoiceFieldset: <T extends Record<string, FormValidationStatus>>({ children, disabled, id, name, onSelect, required, selected, validationMap, validationResult }: ChoiceFieldsetProps<T>) => JSX.Element;
50
+ export declare type InputFieldComponentProps = ComponentProps<typeof ChoiceFieldset>;
51
+ export type { ChoiceFieldsetListProps } from './ChoiceFieldsetList';
52
+ export type { ChoiceFieldsetLegendProps } from './ChoiceFieldsetLegend';
53
+ export type { ChoiceFieldProps } from './ChoiceFieldsetListItem';
54
+ declare const _default: (<T extends Record<string, FormValidationStatus>>({ children, disabled, id, name, onSelect, required, selected, validationMap, validationResult }: ChoiceFieldsetProps<T>) => JSX.Element) & {
55
+ Description: React.FC<{}>;
56
+ Item: React.FC<import("./ChoiceFieldsetListItem").ChoiceFieldProps> & {
57
+ Caption: React.FC<{}>;
58
+ Label: React.FC<{}>;
59
+ LeadingVisual: React.FC<{}>;
60
+ };
61
+ Legend: React.FC<import("./ChoiceFieldsetLegend").ChoiceFieldsetLegendProps>;
62
+ List: React.FC<import("./ChoiceFieldsetList").ChoiceFieldsetListProps>;
63
+ Validation: React.FC<import("./ChoiceFieldsetValidation").ChoiceFieldsetValidationProps>;
64
+ };
65
+ export default _default;