@primer/components 0.0.0-202111619107 → 0.0.0-2021116202529

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 (91) 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/ActionList2/Item.js +6 -4
  8. package/lib/ActionList2/List.js +2 -2
  9. package/lib/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
  10. package/lib/ActionList2/{ActionListContainerContext.js → MenuContext.js} +3 -3
  11. package/lib/ActionList2/Selection.js +4 -4
  12. package/lib/ActionMenu2.d.ts +9 -13
  13. package/lib/ActionMenu2.js +29 -63
  14. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  15. package/lib/Autocomplete/AutocompleteMenu.js +5 -10
  16. package/lib/Checkbox.d.ts +1 -1
  17. package/lib/Dialog/ConfirmationDialog.js +2 -2
  18. package/lib/Dialog/Dialog.js +2 -2
  19. package/lib/FilteredActionList/FilteredActionList.js +3 -10
  20. package/lib/Overlay.d.ts +1 -1
  21. package/lib/TextInputWithTokens.js +4 -4
  22. package/lib/behaviors/anchoredPosition.d.ts +89 -0
  23. package/lib/behaviors/anchoredPosition.js +316 -0
  24. package/lib/behaviors/focusTrap.d.ts +12 -0
  25. package/lib/behaviors/focusTrap.js +179 -0
  26. package/lib/behaviors/focusZone.d.ts +137 -0
  27. package/lib/behaviors/focusZone.js +578 -0
  28. package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
  29. package/lib/behaviors/scrollIntoViewingArea.js +39 -0
  30. package/lib/hooks/index.d.ts +0 -1
  31. package/lib/hooks/index.js +1 -9
  32. package/lib/hooks/useAnchoredPosition.d.ts +1 -1
  33. package/lib/hooks/useAnchoredPosition.js +2 -2
  34. package/lib/hooks/useFocusTrap.js +2 -2
  35. package/lib/hooks/useFocusZone.d.ts +1 -1
  36. package/lib/hooks/useFocusZone.js +2 -2
  37. package/lib/hooks/useOpenAndCloseFocus.js +2 -2
  38. package/lib/index.d.ts +0 -2
  39. package/lib/index.js +0 -8
  40. package/lib/utils/iterateFocusableElements.d.ts +42 -0
  41. package/lib/utils/iterateFocusableElements.js +113 -0
  42. package/lib/utils/uniqueId.d.ts +1 -0
  43. package/lib/utils/uniqueId.js +12 -0
  44. package/lib/utils/userAgent.d.ts +1 -0
  45. package/lib/utils/userAgent.js +15 -0
  46. package/lib-esm/ActionList/Item.js +1 -1
  47. package/lib-esm/ActionList/List.js +1 -1
  48. package/lib-esm/ActionList2/Item.js +6 -4
  49. package/lib-esm/ActionList2/List.js +2 -2
  50. package/lib-esm/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
  51. package/lib-esm/ActionList2/{ActionListContainerContext.js → MenuContext.js} +1 -1
  52. package/lib-esm/ActionList2/Selection.js +4 -4
  53. package/lib-esm/ActionMenu2.d.ts +9 -13
  54. package/lib-esm/ActionMenu2.js +27 -60
  55. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  56. package/lib-esm/Autocomplete/AutocompleteMenu.js +4 -9
  57. package/lib-esm/Checkbox.d.ts +1 -1
  58. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  59. package/lib-esm/Dialog/Dialog.js +1 -1
  60. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -9
  61. package/lib-esm/Overlay.d.ts +1 -1
  62. package/lib-esm/TextInputWithTokens.js +2 -2
  63. package/lib-esm/behaviors/anchoredPosition.d.ts +89 -0
  64. package/lib-esm/behaviors/anchoredPosition.js +309 -0
  65. package/lib-esm/behaviors/focusTrap.d.ts +12 -0
  66. package/lib-esm/behaviors/focusTrap.js +170 -0
  67. package/lib-esm/behaviors/focusZone.d.ts +137 -0
  68. package/lib-esm/behaviors/focusZone.js +560 -0
  69. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
  70. package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
  71. package/lib-esm/hooks/index.d.ts +0 -1
  72. package/lib-esm/hooks/index.js +1 -2
  73. package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
  74. package/lib-esm/hooks/useAnchoredPosition.js +1 -1
  75. package/lib-esm/hooks/useFocusTrap.js +1 -1
  76. package/lib-esm/hooks/useFocusZone.d.ts +1 -1
  77. package/lib-esm/hooks/useFocusZone.js +1 -1
  78. package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
  79. package/lib-esm/index.d.ts +0 -2
  80. package/lib-esm/index.js +0 -1
  81. package/lib-esm/utils/iterateFocusableElements.d.ts +42 -0
  82. package/lib-esm/utils/iterateFocusableElements.js +102 -0
  83. package/lib-esm/utils/uniqueId.d.ts +1 -0
  84. package/lib-esm/utils/uniqueId.js +5 -0
  85. package/lib-esm/utils/userAgent.d.ts +1 -0
  86. package/lib-esm/utils/userAgent.js +8 -0
  87. package/package.json +5 -2
  88. package/lib/Radio.d.ts +0 -38
  89. package/lib/Radio.js +0 -55
  90. package/lib-esm/Radio.d.ts +0 -38
  91. package/lib-esm/Radio.js +0 -40
@@ -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,102 @@
1
+ /**
2
+ * Options to the focusable elements iterator
3
+ */
4
+
5
+ /**
6
+ * Returns an iterator over all of the focusable elements within `container`.
7
+ * Note: If `container` is itself focusable it will be included in the results.
8
+ * @param container The container over which to find focusable elements.
9
+ * @param reverse If true, iterate backwards through focusable elements.
10
+ */
11
+ export function* iterateFocusableElements(container, options = {}) {
12
+ var _options$strict, _options$onlyTabbable;
13
+
14
+ const strict = (_options$strict = options.strict) !== null && _options$strict !== void 0 ? _options$strict : false;
15
+ const acceptFn = ((_options$onlyTabbable = options.onlyTabbable) !== null && _options$onlyTabbable !== void 0 ? _options$onlyTabbable : false) ? isTabbable : isFocusable;
16
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
17
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
18
+ });
19
+ let nextNode = null; // Allow the container to participate
20
+
21
+ if (!options.reverse && acceptFn(container, strict)) {
22
+ yield container;
23
+ } // If iterating in reverse, continue traversing down into the last child until we reach
24
+ // a leaf DOM node
25
+
26
+
27
+ if (options.reverse) {
28
+ let lastChild = walker.lastChild();
29
+
30
+ while (lastChild) {
31
+ nextNode = lastChild;
32
+ lastChild = walker.lastChild();
33
+ }
34
+ } else {
35
+ nextNode = walker.firstChild();
36
+ }
37
+
38
+ while (nextNode instanceof HTMLElement) {
39
+ yield nextNode;
40
+ nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
41
+ } // Allow the container to participate (in reverse)
42
+
43
+
44
+ if (options.reverse && acceptFn(container, strict)) {
45
+ yield container;
46
+ }
47
+
48
+ return undefined;
49
+ }
50
+ /**
51
+ * Determines whether the given element is focusable. If `strict` is true, we may
52
+ * perform additional checks that require a reflow (less performant).
53
+ * @param elem
54
+ * @param strict
55
+ */
56
+
57
+ export function isFocusable(elem, strict = false) {
58
+ // Certain conditions cause an element to never be focusable, even if they have tabindex="0"
59
+ const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
60
+ const hiddenInert = elem.hidden;
61
+ const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
62
+
63
+ if (disabledAttrInert || hiddenInert || hiddenInputInert) {
64
+ return false;
65
+ } // Each of the conditions checked below require a reflow, thus are gated by the `strict`
66
+ // argument. If any are true, the element is not focusable, even if tabindex is set.
67
+
68
+
69
+ if (strict) {
70
+ const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
71
+ const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
72
+ const clientRectsInert = elem.getClientRects().length === 0;
73
+
74
+ if (sizeInert || visibilityInert || clientRectsInert) {
75
+ return false;
76
+ }
77
+ } // Any element with `tabindex` explicitly set can be focusable, even if it's set to "-1"
78
+
79
+
80
+ if (elem.getAttribute('tabindex') != null) {
81
+ return true;
82
+ } // One last way `elem.tabIndex` can be wrong.
83
+
84
+
85
+ if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
86
+ return false;
87
+ }
88
+
89
+ return elem.tabIndex !== -1;
90
+ }
91
+ /**
92
+ * Determines whether the given element is tabbable. If `strict` is true, we may
93
+ * perform additional checks that require a reflow (less performant). This check
94
+ * ensures that the element is focusable and that its tabindex is not explicitly
95
+ * set to "-1" (which makes it focusable, but removes it from the tab order).
96
+ * @param elem
97
+ * @param strict
98
+ */
99
+
100
+ export function isTabbable(elem, strict = false) {
101
+ return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
102
+ }
@@ -0,0 +1 @@
1
+ export declare function uniqueId(): string;
@@ -0,0 +1,5 @@
1
+ // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
2
+ let idSeed = 10000;
3
+ export function uniqueId() {
4
+ return `__primer_id_${idSeed++}`;
5
+ }
@@ -0,0 +1 @@
1
+ export declare function isMacOS(): boolean;
@@ -0,0 +1,8 @@
1
+ let isMac = undefined;
2
+ export function isMacOS() {
3
+ if (isMac === undefined) {
4
+ isMac = /^mac/i.test(window.navigator.platform);
5
+ }
6
+
7
+ return isMac;
8
+ }
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-202111619107",
3
+ "version": "0.0.0-2021116202529",
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
+ ],
8
12
  "scripts": {
9
13
  "setup": "./script/setup",
10
14
  "build": "./script/build",
@@ -39,7 +43,6 @@
39
43
  "author": "GitHub, Inc.",
40
44
  "license": "MIT",
41
45
  "dependencies": {
42
- "@primer/behaviors": "^1.0.2",
43
46
  "@primer/octicons-react": "^16.1.0",
44
47
  "@primer/primitives": "7.1.1",
45
48
  "@radix-ui/react-polymorphic": "0.0.14",
package/lib/Radio.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import React, { InputHTMLAttributes } from 'react';
2
- import { SxProp } from './sx';
3
- export declare type RadioProps = {
4
- /**
5
- * A unique value that is never shown to the user.
6
- * Used during form submission and to identify which radio button in a group is selected
7
- */
8
- value: string;
9
- /**
10
- * Name attribute of the input element. Required for grouping radio inputs
11
- */
12
- name: string;
13
- /**
14
- * Apply inactive visual appearance to the radio button
15
- */
16
- disabled?: boolean;
17
- /**
18
- * Indicates whether the radio button is selected
19
- */
20
- checked?: boolean;
21
- /**
22
- * Forward a ref to the underlying input element
23
- */
24
- ref?: React.RefObject<HTMLInputElement>;
25
- /**
26
- * Indicates whether the radio button must be checked before the form can be submitted
27
- */
28
- required?: boolean;
29
- /**
30
- * Indicates whether the radio button validation state is non-standard
31
- */
32
- validationStatus?: 'error' | 'success';
33
- } & InputHTMLAttributes<HTMLInputElement> & SxProp;
34
- /**
35
- * An accessible, native radio component for selecting one option from a list.
36
- */
37
- declare const Radio: React.ForwardRefExoticComponent<Pick<RadioProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "validationStatus"> & React.RefAttributes<HTMLInputElement>>;
38
- export default Radio;
package/lib/Radio.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _styledComponents = _interopRequireDefault(require("styled-components"));
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _sx = _interopRequireDefault(require("./sx"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- 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); }
17
-
18
- const StyledRadio = _styledComponents.default.input.withConfig({
19
- displayName: "Radio__StyledRadio",
20
- componentId: "sc-1ak1fjg-0"
21
- })(["cursor:pointer;", " ", ""], props => props.disabled && `cursor: not-allowed;`, _sx.default);
22
- /**
23
- * An accessible, native radio component for selecting one option from a list.
24
- */
25
-
26
-
27
- const Radio = /*#__PURE__*/_react.default.forwardRef(({
28
- checked,
29
- disabled,
30
- sx: sxProp,
31
- required,
32
- validationStatus,
33
- value,
34
- name,
35
- ...rest
36
- }, ref) => {
37
- return /*#__PURE__*/_react.default.createElement(StyledRadio, _extends({
38
- type: "radio",
39
- value: value,
40
- name: name,
41
- ref: ref,
42
- disabled: disabled,
43
- "aria-disabled": disabled ? 'true' : 'false',
44
- checked: checked,
45
- "aria-checked": checked ? 'true' : 'false',
46
- required: required,
47
- "aria-required": required ? 'true' : 'false',
48
- "aria-invalid": validationStatus === 'error' ? 'true' : 'false',
49
- sx: sxProp
50
- }, rest));
51
- });
52
-
53
- Radio.displayName = 'Radio';
54
- var _default = Radio;
55
- exports.default = _default;
@@ -1,38 +0,0 @@
1
- import React, { InputHTMLAttributes } from 'react';
2
- import { SxProp } from './sx';
3
- export declare type RadioProps = {
4
- /**
5
- * A unique value that is never shown to the user.
6
- * Used during form submission and to identify which radio button in a group is selected
7
- */
8
- value: string;
9
- /**
10
- * Name attribute of the input element. Required for grouping radio inputs
11
- */
12
- name: string;
13
- /**
14
- * Apply inactive visual appearance to the radio button
15
- */
16
- disabled?: boolean;
17
- /**
18
- * Indicates whether the radio button is selected
19
- */
20
- checked?: boolean;
21
- /**
22
- * Forward a ref to the underlying input element
23
- */
24
- ref?: React.RefObject<HTMLInputElement>;
25
- /**
26
- * Indicates whether the radio button must be checked before the form can be submitted
27
- */
28
- required?: boolean;
29
- /**
30
- * Indicates whether the radio button validation state is non-standard
31
- */
32
- validationStatus?: 'error' | 'success';
33
- } & InputHTMLAttributes<HTMLInputElement> & SxProp;
34
- /**
35
- * An accessible, native radio component for selecting one option from a list.
36
- */
37
- declare const Radio: React.ForwardRefExoticComponent<Pick<RadioProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "validationStatus"> & React.RefAttributes<HTMLInputElement>>;
38
- export default Radio;
package/lib-esm/Radio.js DELETED
@@ -1,40 +0,0 @@
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 styled from 'styled-components';
4
- import React from 'react';
5
- import sx from './sx';
6
- const StyledRadio = styled.input.withConfig({
7
- displayName: "Radio__StyledRadio",
8
- componentId: "sc-1ak1fjg-0"
9
- })(["cursor:pointer;", " ", ""], props => props.disabled && `cursor: not-allowed;`, sx);
10
- /**
11
- * An accessible, native radio component for selecting one option from a list.
12
- */
13
-
14
- const Radio = /*#__PURE__*/React.forwardRef(({
15
- checked,
16
- disabled,
17
- sx: sxProp,
18
- required,
19
- validationStatus,
20
- value,
21
- name,
22
- ...rest
23
- }, ref) => {
24
- return /*#__PURE__*/React.createElement(StyledRadio, _extends({
25
- type: "radio",
26
- value: value,
27
- name: name,
28
- ref: ref,
29
- disabled: disabled,
30
- "aria-disabled": disabled ? 'true' : 'false',
31
- checked: checked,
32
- "aria-checked": checked ? 'true' : 'false',
33
- required: required,
34
- "aria-required": required ? 'true' : 'false',
35
- "aria-invalid": validationStatus === 'error' ? 'true' : 'false',
36
- sx: sxProp
37
- }, rest));
38
- });
39
- Radio.displayName = 'Radio';
40
- export default Radio;