@primer/components 0.0.0-202182720420 → 0.0.0-202182722258
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 +2 -40
- package/dist/browser.esm.js +627 -670
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +389 -432
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Divider.js +1 -1
- package/lib/ActionList/Header.js +2 -2
- package/lib/ActionList/Item.js +13 -13
- package/lib/ActionList/List.js +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
- package/lib/Autocomplete/Autocomplete.d.ts +26 -0
- package/lib/Autocomplete/Autocomplete.js +55 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +13 -0
- package/lib/Autocomplete/AutocompleteContext.js +15 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib/Autocomplete/AutocompleteInput.js +139 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +67 -0
- package/lib/Autocomplete/AutocompleteMenu.js +284 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/Avatar.d.ts +0 -4
- package/lib/AvatarPair.js +1 -1
- package/lib/AvatarStack.d.ts +8 -4
- package/lib/AvatarStack.js +7 -6
- package/lib/Badge/Badge.d.ts +8 -0
- package/lib/Badge/Badge.js +59 -0
- package/lib/Badge/BadgeState.d.ts +13 -0
- package/lib/Badge/BadgeState.js +51 -0
- package/lib/Badge/_badgeStyleUtils.d.ts +3 -0
- package/lib/Badge/_badgeStyleUtils.js +39 -0
- package/lib/BranchName.js +1 -1
- package/lib/Breadcrumb.d.ts +23 -0
- package/lib/{Breadcrumbs.js → Breadcrumb.js} +23 -33
- package/lib/Button/Button.d.ts +1 -0
- package/lib/Button/Button.js +1 -1
- package/lib/Button/ButtonClose.d.ts +2 -1
- package/lib/Button/ButtonClose.js +1 -1
- package/lib/Button/ButtonDanger.d.ts +1 -0
- package/lib/Button/ButtonInvisible.d.ts +1 -0
- package/lib/Button/ButtonInvisible.js +1 -1
- package/lib/Button/ButtonOutline.d.ts +1 -0
- package/lib/Button/ButtonPrimary.d.ts +1 -0
- package/lib/Button/ButtonTableList.js +1 -1
- package/lib/CircleBadge.js +1 -1
- package/lib/CircleOcticon.d.ts +1 -0
- package/lib/CircleOcticon.js +1 -1
- package/lib/CounterLabel.js +2 -2
- package/lib/Dialog/ConfirmationDialog.js +1 -1
- package/lib/Dialog/Dialog.js +9 -9
- package/lib/Dialog.d.ts +3 -2
- package/lib/Dialog.js +4 -4
- package/lib/Dropdown.d.ts +4 -0
- package/lib/Dropdown.js +2 -2
- package/lib/DropdownMenu/DropdownButton.d.ts +2 -1
- package/lib/DropdownStyles.js +6 -6
- package/lib/FilterList.d.ts +1 -0
- package/lib/FilterList.js +1 -1
- package/lib/FilteredActionList/FilteredActionList.js +8 -34
- package/lib/Flash.js +1 -1
- package/lib/Label.js +2 -2
- package/lib/Link.js +1 -1
- package/lib/Overlay.d.ts +2 -1
- package/lib/Overlay.js +11 -6
- package/lib/Pagehead.js +1 -1
- package/lib/Pagination/Pagination.js +1 -1
- package/lib/Popover.js +1 -1
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +344 -15
- package/lib/SelectMenu/SelectMenuDivider.js +1 -1
- package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuFilter.js +1 -1
- package/lib/SelectMenu/SelectMenuFooter.js +1 -1
- package/lib/SelectMenu/SelectMenuHeader.js +2 -2
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuItem.js +1 -1
- package/lib/SelectMenu/SelectMenuList.js +1 -1
- package/lib/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.js +2 -2
- package/lib/SelectMenu/SelectMenuTab.js +1 -1
- package/lib/SelectMenu/SelectMenuTabPanel.js +1 -1
- package/lib/SelectPanel/SelectPanel.js +2 -3
- package/lib/SideNav.js +5 -5
- package/lib/StateLabel.js +1 -1
- package/lib/SubNav.js +1 -1
- package/lib/TabNav.js +2 -2
- package/lib/TextInput.d.ts +10 -7
- package/lib/TextInput.js +24 -29
- package/lib/TextInputTokens.d.ts +43 -0
- package/lib/TextInputTokens.js +227 -0
- package/lib/TextInputWithTokens.d.ts +41 -0
- package/lib/TextInputWithTokens.js +396 -0
- package/lib/Timeline.d.ts +1 -0
- package/lib/Timeline.js +19 -16
- package/lib/Token/Token.d.ts +7 -0
- package/lib/Token/Token.js +63 -0
- package/lib/Token/TokenBase.d.ts +16 -0
- package/lib/Token/TokenBase.js +76 -0
- package/lib/Token/TokenLabel.d.ts +10 -0
- package/lib/Token/TokenLabel.js +115 -0
- package/lib/Token/TokenProfile.d.ts +7 -0
- package/lib/Token/TokenProfile.js +45 -0
- package/lib/Token/_RemoveTokenButton.d.ts +3 -0
- package/lib/Token/_RemoveTokenButton.js +43 -0
- package/lib/Token/_tokenButtonUtils.d.ts +9 -0
- package/lib/Token/_tokenButtonUtils.js +42 -0
- package/lib/Tooltip.js +1 -1
- package/lib/UnderlineNav.js +2 -2
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +11 -6
- package/lib/index.d.ts +2 -3
- package/lib/index.js +2 -22
- package/lib/theme-preval.d.ts +6 -12
- package/lib/theme-preval.js +0 -940
- package/lib/utils/scrollIntoViewingArea.d.ts +1 -0
- package/lib/utils/scrollIntoViewingArea.js +39 -0
- package/lib/utils/testing.d.ts +0 -1854
- package/lib/utils/types.d.ts +3 -0
- package/lib/utils/uniqueId.js +0 -1
- package/lib-esm/ActionList/Divider.js +1 -1
- package/lib-esm/ActionList/Header.js +2 -2
- package/lib-esm/ActionList/Item.js +14 -14
- package/lib-esm/ActionList/List.js +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
- package/lib-esm/Autocomplete/Autocomplete.d.ts +26 -0
- package/lib-esm/Autocomplete/Autocomplete.js +36 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +13 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +6 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +120 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +67 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +258 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/Avatar.d.ts +0 -4
- package/lib-esm/AvatarPair.js +1 -1
- package/lib-esm/AvatarStack.d.ts +8 -4
- package/lib-esm/AvatarStack.js +8 -7
- package/lib-esm/Badge/Badge.d.ts +8 -0
- package/lib-esm/Badge/Badge.js +44 -0
- package/lib-esm/Badge/BadgeState.d.ts +13 -0
- package/lib-esm/Badge/BadgeState.js +40 -0
- package/lib-esm/Badge/_badgeStyleUtils.d.ts +3 -0
- package/lib-esm/Badge/_badgeStyleUtils.js +29 -0
- package/lib-esm/BranchName.js +1 -1
- package/lib-esm/Breadcrumb.d.ts +23 -0
- package/lib-esm/{Breadcrumbs.js → Breadcrumb.js} +21 -30
- package/lib-esm/Button/Button.d.ts +1 -0
- package/lib-esm/Button/Button.js +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +2 -1
- package/lib-esm/Button/ButtonClose.js +1 -1
- package/lib-esm/Button/ButtonDanger.d.ts +1 -0
- package/lib-esm/Button/ButtonInvisible.d.ts +1 -0
- package/lib-esm/Button/ButtonInvisible.js +1 -1
- package/lib-esm/Button/ButtonOutline.d.ts +1 -0
- package/lib-esm/Button/ButtonPrimary.d.ts +1 -0
- package/lib-esm/Button/ButtonTableList.js +1 -1
- package/lib-esm/CircleBadge.js +1 -1
- package/lib-esm/CircleOcticon.d.ts +1 -0
- package/lib-esm/CircleOcticon.js +1 -1
- package/lib-esm/CounterLabel.js +2 -2
- package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
- package/lib-esm/Dialog/Dialog.js +8 -8
- package/lib-esm/Dialog.d.ts +3 -2
- package/lib-esm/Dialog.js +4 -4
- package/lib-esm/Dropdown.d.ts +4 -0
- package/lib-esm/Dropdown.js +2 -2
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +2 -1
- package/lib-esm/DropdownStyles.js +6 -6
- package/lib-esm/FilterList.d.ts +1 -0
- package/lib-esm/FilterList.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.js +6 -34
- package/lib-esm/Flash.js +1 -1
- package/lib-esm/Label.js +2 -2
- package/lib-esm/Link.js +1 -1
- package/lib-esm/Overlay.d.ts +2 -1
- package/lib-esm/Overlay.js +9 -6
- package/lib-esm/Pagehead.js +1 -1
- package/lib-esm/Pagination/Pagination.js +1 -1
- package/lib-esm/Popover.js +1 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +344 -15
- package/lib-esm/SelectMenu/SelectMenuDivider.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuFilter.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuFooter.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuHeader.js +2 -2
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuItem.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuList.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.js +2 -2
- package/lib-esm/SelectMenu/SelectMenuTab.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuTabPanel.js +1 -1
- package/lib-esm/SelectPanel/SelectPanel.js +2 -3
- package/lib-esm/SideNav.js +5 -5
- package/lib-esm/StateLabel.js +1 -1
- package/lib-esm/SubNav.js +1 -1
- package/lib-esm/TabNav.js +2 -2
- package/lib-esm/TextInput.d.ts +10 -7
- package/lib-esm/TextInput.js +23 -29
- package/lib-esm/TextInputTokens.d.ts +43 -0
- package/lib-esm/TextInputTokens.js +200 -0
- package/lib-esm/TextInputWithTokens.d.ts +41 -0
- package/lib-esm/TextInputWithTokens.js +361 -0
- package/lib-esm/Timeline.d.ts +1 -0
- package/lib-esm/Timeline.js +17 -12
- package/lib-esm/Token/Token.d.ts +7 -0
- package/lib-esm/Token/Token.js +44 -0
- package/lib-esm/Token/TokenBase.d.ts +16 -0
- package/lib-esm/Token/TokenBase.js +56 -0
- package/lib-esm/Token/TokenLabel.d.ts +10 -0
- package/lib-esm/Token/TokenLabel.js +99 -0
- package/lib-esm/Token/TokenProfile.d.ts +7 -0
- package/lib-esm/Token/TokenProfile.js +28 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +3 -0
- package/lib-esm/Token/_RemoveTokenButton.js +28 -0
- package/lib-esm/Token/_tokenButtonUtils.d.ts +9 -0
- package/lib-esm/Token/_tokenButtonUtils.js +26 -0
- package/lib-esm/Tooltip.js +1 -1
- package/lib-esm/UnderlineNav.js +2 -2
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +11 -6
- package/lib-esm/index.d.ts +2 -3
- package/lib-esm/index.js +2 -3
- package/lib-esm/theme-preval.d.ts +6 -12
- package/lib-esm/theme-preval.js +0 -940
- package/lib-esm/utils/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/utils/scrollIntoViewingArea.js +30 -0
- package/lib-esm/utils/testing.d.ts +0 -1854
- package/lib-esm/utils/types.d.ts +3 -0
- package/lib-esm/utils/uniqueId.js +0 -1
- package/package.json +14 -14
- package/lib/Breadcrumbs.d.ts +0 -40
- package/lib/utils/ssr.d.ts +0 -1
- package/lib/utils/ssr.js +0 -19
- package/lib-esm/Breadcrumbs.d.ts +0 -40
- package/lib-esm/utils/ssr.d.ts +0 -1
- package/lib-esm/utils/ssr.js +0 -1
@@ -17,7 +17,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
17
17
|
const StyledDivider = _styledComponents.default.div.withConfig({
|
18
18
|
displayName: "Divider__StyledDivider",
|
19
19
|
componentId: "sc-42656i-0"
|
20
|
-
})(["height:1px;background:", ";margin-top:calc(", " - 1px);margin-bottom:", ";"], (0, _constants.get)('colors.
|
20
|
+
})(["height:1px;background:", ";margin-top:calc(", " - 1px);margin-bottom:", ";"], (0, _constants.get)('colors.selectMenu.borderSecondary'), (0, _constants.get)('space.2'), (0, _constants.get)('space.2'));
|
21
21
|
/**
|
22
22
|
* Visually separates `Item`s or `Group`s in an `ActionList`.
|
23
23
|
*/
|
package/lib/ActionList/Header.js
CHANGED
@@ -25,9 +25,9 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
25
25
|
const StyledHeader = _styledComponents.default.div.withConfig({
|
26
26
|
displayName: "Header__StyledHeader",
|
27
27
|
componentId: "qmofje-0"
|
28
|
-
})(["{}padding:6px ", ";font-size:", ";font-weight:", ";color:", ";", " ", ""], (0, _constants.get)('space.3'), (0, _constants.get)('fontSizes.0'), (0, _constants.get)('fontWeights.bold'), (0, _constants.get)('colors.
|
28
|
+
})(["{}padding:6px ", ";font-size:", ";font-weight:", ";color:", ";", " ", ""], (0, _constants.get)('space.3'), (0, _constants.get)('fontSizes.0'), (0, _constants.get)('fontWeights.bold'), (0, _constants.get)('colors.text.secondary'), ({
|
29
29
|
variant
|
30
|
-
}) => variant === 'filled' && (0, _styledComponents.css)(["background:", ";margin:", " 0;border-top:1px solid ", ";border-bottom:1px solid ", ";&:first-child{margin-top:0;}"], (0, _constants.get)('colors.
|
30
|
+
}) => variant === 'filled' && (0, _styledComponents.css)(["background:", ";margin:", " 0;border-top:1px solid ", ";border-bottom:1px solid ", ";&:first-child{margin-top:0;}"], (0, _constants.get)('colors.bg.tertiary'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.border.tertiary'), (0, _constants.get)('colors.border.tertiary')), _sx.default);
|
31
31
|
/**
|
32
32
|
* Displays the name and description of a `Group`.
|
33
33
|
*/
|
package/lib/ActionList/Item.js
CHANGED
@@ -26,7 +26,7 @@ var _ThemeProvider = require("../ThemeProvider");
|
|
26
26
|
|
27
27
|
var _focusZone = require("../behaviors/focusZone");
|
28
28
|
|
29
|
-
var
|
29
|
+
var _uniqueId = require("../utils/uniqueId");
|
30
30
|
|
31
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
32
32
|
|
@@ -72,9 +72,9 @@ const customItemThemes = {
|
|
72
72
|
const getItemVariant = (variant = 'default', disabled) => {
|
73
73
|
if (disabled) {
|
74
74
|
return {
|
75
|
-
color: (0, _constants.get)('colors.
|
76
|
-
iconColor: (0, _constants.get)('colors.
|
77
|
-
annotationColor: (0, _constants.get)('colors.
|
75
|
+
color: (0, _constants.get)('colors.text.disabled'),
|
76
|
+
iconColor: (0, _constants.get)('colors.text.disabled'),
|
77
|
+
annotationColor: (0, _constants.get)('colors.text.disabled'),
|
78
78
|
hoverCursor: 'default'
|
79
79
|
};
|
80
80
|
}
|
@@ -82,17 +82,17 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
82
82
|
switch (variant) {
|
83
83
|
case 'danger':
|
84
84
|
return {
|
85
|
-
color: (0, _constants.get)('colors.danger
|
86
|
-
iconColor: (0, _constants.get)('colors.danger
|
87
|
-
annotationColor: (0, _constants.get)('colors.
|
85
|
+
color: (0, _constants.get)('colors.text.danger'),
|
86
|
+
iconColor: (0, _constants.get)('colors.icon.danger'),
|
87
|
+
annotationColor: (0, _constants.get)('colors.text.disabled'),
|
88
88
|
hoverCursor: 'pointer'
|
89
89
|
};
|
90
90
|
|
91
91
|
default:
|
92
92
|
return {
|
93
93
|
color: 'inherit',
|
94
|
-
iconColor: (0, _constants.get)('colors.
|
95
|
-
annotationColor: (0, _constants.get)('colors.
|
94
|
+
iconColor: (0, _constants.get)('colors.text.secondary'),
|
95
|
+
annotationColor: (0, _constants.get)('colors.text.secondary'),
|
96
96
|
hoverCursor: 'pointer'
|
97
97
|
};
|
98
98
|
}
|
@@ -121,7 +121,7 @@ const StyledItem = _styledComponents.default.div.withConfig({
|
|
121
121
|
item
|
122
122
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverCursor, _Divider.StyledDivider, _Header.StyledHeader, ({
|
123
123
|
showDivider
|
124
|
-
}) => showDivider ? `1px` : '0', DividedContent, (0, _constants.get)('colors.
|
124
|
+
}) => showDivider ? `1px` : '0', DividedContent, (0, _constants.get)('colors.selectMenu.borderSecondary'), ({
|
125
125
|
showDivider
|
126
126
|
}) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedDirectly, ({
|
127
127
|
focusBackground
|
@@ -167,7 +167,7 @@ const TrailingContent = (0, _styledComponents.default)(ColoredVisualContainer).w
|
|
167
167
|
const DescriptionContainer = _styledComponents.default.span.withConfig({
|
168
168
|
displayName: "Item__DescriptionContainer",
|
169
169
|
componentId: "jqpvy8-8"
|
170
|
-
})(["color:", ";font-size:", ";line-height:16px;margin-left:var(--description-container-margin-left);min-width:0;flex-grow:1;flex-basis:var(--description-container-flex-basis);"], (0, _constants.get)('colors.
|
170
|
+
})(["color:", ";font-size:", ";line-height:16px;margin-left:var(--description-container-margin-left);min-width:0;flex-grow:1;flex-basis:var(--description-container-flex-basis);"], (0, _constants.get)('colors.text.secondary'), (0, _constants.get)('fontSizes.0'));
|
171
171
|
|
172
172
|
const MultiSelectInput = _styledComponents.default.input.withConfig({
|
173
173
|
displayName: "Item__MultiSelectInput",
|
@@ -198,8 +198,8 @@ function Item(itemProps) {
|
|
198
198
|
id,
|
199
199
|
...props
|
200
200
|
} = itemProps;
|
201
|
-
const labelId = (0,
|
202
|
-
const descriptionId = (0,
|
201
|
+
const labelId = (0, _react.useMemo)(() => (0, _uniqueId.uniqueId)(), []);
|
202
|
+
const descriptionId = (0, _react.useMemo)(() => (0, _uniqueId.uniqueId)(), []);
|
203
203
|
const keyPressHandler = (0, _react.useCallback)(event => {
|
204
204
|
if (disabled) {
|
205
205
|
return;
|
package/lib/ActionList/List.js
CHANGED
@@ -38,7 +38,7 @@ function isGroupedListProps(props) {
|
|
38
38
|
const StyledList = _styledComponents.default.div.withConfig({
|
39
39
|
displayName: "List__StyledList",
|
40
40
|
componentId: "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.
|
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.selectMenu.borderSecondary'));
|
42
42
|
/**
|
43
43
|
* Returns `sx` prop values for `List` children matching the given `List` style variation.
|
44
44
|
* @param variant `List` style variation.
|
@@ -15,7 +15,7 @@ var _useFocusZone = require("../hooks/useFocusZone");
|
|
15
15
|
|
16
16
|
var _hooks = require("../hooks");
|
17
17
|
|
18
|
-
var
|
18
|
+
var _uniqueId = require("../utils/uniqueId");
|
19
19
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
21
|
|
@@ -44,7 +44,7 @@ const AnchoredOverlay = ({
|
|
44
44
|
}) => {
|
45
45
|
const anchorRef = (0, _hooks.useProvidedRefOrCreate)(externalAnchorRef);
|
46
46
|
const [overlayRef, updateOverlayRef] = (0, _hooks.useRenderForcingRef)();
|
47
|
-
const anchorId = (0,
|
47
|
+
const anchorId = (0, _react.useMemo)(_uniqueId.uniqueId, []);
|
48
48
|
const onClickOutside = (0, _react.useCallback)(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
|
49
49
|
const onEscape = (0, _react.useCallback)(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
|
50
50
|
const onAnchorKeyDown = (0, _react.useCallback)(event => {
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ComponentProps } from '../utils/types';
|
3
|
+
import AutocompleteMenu from './AutocompleteMenu';
|
4
|
+
declare const Autocomplete: React.FC;
|
5
|
+
export declare type AutocompleteProps = ComponentProps<typeof Autocomplete>;
|
6
|
+
export type { AutocompleteInputProps } from './AutocompleteInput';
|
7
|
+
export type { AutocompleteMenuProps } from './AutocompleteMenu';
|
8
|
+
declare const _default: React.FC<{}> & {
|
9
|
+
AutocompleteContext: React.Context<{
|
10
|
+
activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
|
11
|
+
autocompleteSuggestion?: string | undefined;
|
12
|
+
inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
|
13
|
+
inputValue?: string | undefined;
|
14
|
+
showMenu?: boolean | undefined;
|
15
|
+
setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
16
|
+
setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
17
|
+
setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
18
|
+
isMenuDirectlyActivated?: boolean | undefined;
|
19
|
+
setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
20
|
+
}>;
|
21
|
+
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
|
22
|
+
as?: React.ComponentType<any> | undefined;
|
23
|
+
}>;
|
24
|
+
Menu: typeof AutocompleteMenu;
|
25
|
+
};
|
26
|
+
export default _default;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _AutocompleteContext = require("./AutocompleteContext");
|
11
|
+
|
12
|
+
var _AutocompleteInput = _interopRequireDefault(require("./AutocompleteInput"));
|
13
|
+
|
14
|
+
var _AutocompleteMenu = _interopRequireDefault(require("./AutocompleteMenu"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
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); }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
const Autocomplete = ({
|
23
|
+
children
|
24
|
+
}) => {
|
25
|
+
const activeDescendantRef = (0, _react.useRef)(null);
|
26
|
+
const inputRef = (0, _react.useRef)(null);
|
27
|
+
const [inputValue, setInputValue] = (0, _react.useState)('');
|
28
|
+
const [showMenu, setShowMenu] = (0, _react.useState)(false);
|
29
|
+
const [autocompleteSuggestion, setAutocompleteSuggestion] = (0, _react.useState)('');
|
30
|
+
const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = (0, _react.useState)(false);
|
31
|
+
return /*#__PURE__*/_react.default.createElement(_AutocompleteContext.AutocompleteContext.Provider, {
|
32
|
+
value: {
|
33
|
+
activeDescendantRef,
|
34
|
+
autocompleteSuggestion,
|
35
|
+
inputRef,
|
36
|
+
inputValue,
|
37
|
+
isMenuDirectlyActivated,
|
38
|
+
setAutocompleteSuggestion,
|
39
|
+
setInputValue,
|
40
|
+
setIsMenuDirectlyActivated,
|
41
|
+
setShowMenu,
|
42
|
+
showMenu
|
43
|
+
}
|
44
|
+
}, children);
|
45
|
+
};
|
46
|
+
|
47
|
+
Autocomplete.displayName = "Autocomplete";
|
48
|
+
|
49
|
+
var _default = Object.assign(Autocomplete, {
|
50
|
+
AutocompleteContext: _AutocompleteContext.AutocompleteContext,
|
51
|
+
Input: _AutocompleteInput.default,
|
52
|
+
Menu: _AutocompleteMenu.default
|
53
|
+
});
|
54
|
+
|
55
|
+
exports.default = _default;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare const AutocompleteContext: import("react").Context<{
|
3
|
+
activeDescendantRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
|
4
|
+
autocompleteSuggestion?: string | undefined;
|
5
|
+
inputRef?: import("react").MutableRefObject<HTMLInputElement | null> | undefined;
|
6
|
+
inputValue?: string | undefined;
|
7
|
+
showMenu?: boolean | undefined;
|
8
|
+
setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
9
|
+
setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
|
10
|
+
setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
11
|
+
isMenuDirectlyActivated?: boolean | undefined;
|
12
|
+
setIsMenuDirectlyActivated?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
|
13
|
+
}>;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.AutocompleteContext = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
// TODO:
|
11
|
+
// - figure out how we can make all of these properties required without having to define them when calling `createContext`
|
12
|
+
// - figure out how we can reduce the number of properties that need to be passed
|
13
|
+
// COLEHELP
|
14
|
+
const AutocompleteContext = /*#__PURE__*/(0, _react.createContext)({});
|
15
|
+
exports.AutocompleteContext = AutocompleteContext;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import type * as Polymorphic from "@radix-ui/react-polymorphic";
|
3
|
+
import { ComponentProps } from '../utils/types';
|
4
|
+
declare type InternalAutocompleteInputProps = {
|
5
|
+
as?: React.ComponentType<any>;
|
6
|
+
};
|
7
|
+
declare const AutocompleteInput: Polymorphic.ForwardRefComponent<"input", InternalAutocompleteInputProps>;
|
8
|
+
export declare type AutocompleteInputProps = ComponentProps<typeof AutocompleteInput>;
|
9
|
+
export default AutocompleteInput;
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _AutocompleteContext = require("./AutocompleteContext");
|
11
|
+
|
12
|
+
var _TextInput = _interopRequireDefault(require("../TextInput"));
|
13
|
+
|
14
|
+
var _useCombinedRefs = require("../hooks/useCombinedRefs");
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
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); }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
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); }
|
23
|
+
|
24
|
+
const AutocompleteInput = /*#__PURE__*/_react.default.forwardRef(({
|
25
|
+
as: Component = _TextInput.default,
|
26
|
+
onFocus,
|
27
|
+
onBlur,
|
28
|
+
onChange,
|
29
|
+
onKeyDown,
|
30
|
+
onKeyPress,
|
31
|
+
value,
|
32
|
+
...props
|
33
|
+
}, forwardedRef) => {
|
34
|
+
const {
|
35
|
+
activeDescendantRef,
|
36
|
+
autocompleteSuggestion = '',
|
37
|
+
inputRef,
|
38
|
+
inputValue = '',
|
39
|
+
isMenuDirectlyActivated,
|
40
|
+
setInputValue,
|
41
|
+
setShowMenu,
|
42
|
+
showMenu
|
43
|
+
} = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
|
44
|
+
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(inputRef, forwardedRef);
|
45
|
+
const [highlightRemainingText, setHighlightRemainingText] = (0, _react.useState)(true);
|
46
|
+
|
47
|
+
const handleInputFocus = e => {
|
48
|
+
onFocus && onFocus(e);
|
49
|
+
setShowMenu && setShowMenu(true);
|
50
|
+
};
|
51
|
+
|
52
|
+
const handleInputBlur = e => {
|
53
|
+
onBlur && onBlur(e); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
|
54
|
+
// this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
|
55
|
+
// but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
|
56
|
+
// COLEHELP
|
57
|
+
|
58
|
+
setTimeout(() => {
|
59
|
+
if (setShowMenu && document.activeElement !== combinedInputRef.current) {
|
60
|
+
setShowMenu(false);
|
61
|
+
}
|
62
|
+
}, 0);
|
63
|
+
};
|
64
|
+
|
65
|
+
const handleInputChange = e => {
|
66
|
+
if (onChange) {
|
67
|
+
onChange(e);
|
68
|
+
}
|
69
|
+
|
70
|
+
if (setInputValue) {
|
71
|
+
setInputValue(e.currentTarget.value);
|
72
|
+
}
|
73
|
+
|
74
|
+
if (setShowMenu && !showMenu) {
|
75
|
+
setShowMenu(true);
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
const handleInputKeyDown = e => {
|
80
|
+
if (e.key === 'Backspace') {
|
81
|
+
setHighlightRemainingText(false);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
const handleInputKeyUp = e => {
|
86
|
+
if (e.key === 'Backspace') {
|
87
|
+
setHighlightRemainingText(true);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
const onInputKeyPress = (0, _react.useCallback)(event => {
|
92
|
+
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
93
|
+
event.preventDefault();
|
94
|
+
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
95
|
+
|
96
|
+
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
97
|
+
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
98
|
+
}
|
99
|
+
}, [activeDescendantRef]);
|
100
|
+
(0, _react.useEffect)(() => {
|
101
|
+
if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
|
102
|
+
return;
|
103
|
+
} // resets input value to being empty after a selection has been made
|
104
|
+
|
105
|
+
|
106
|
+
if (!autocompleteSuggestion) {
|
107
|
+
inputRef.current.value = inputValue;
|
108
|
+
} // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
|
109
|
+
// is the same as what I'm typing
|
110
|
+
// e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
|
111
|
+
// COLEHELP
|
112
|
+
|
113
|
+
|
114
|
+
if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
115
|
+
inputRef.current.value = autocompleteSuggestion;
|
116
|
+
|
117
|
+
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
118
|
+
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}, [autocompleteSuggestion, inputValue]);
|
122
|
+
(0, _react.useEffect)(() => {
|
123
|
+
if (value && setInputValue) {
|
124
|
+
setInputValue(value.toString());
|
125
|
+
}
|
126
|
+
}, [value]);
|
127
|
+
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
128
|
+
onFocus: handleInputFocus,
|
129
|
+
onBlur: handleInputBlur,
|
130
|
+
onChange: handleInputChange,
|
131
|
+
onKeyDown: handleInputKeyDown,
|
132
|
+
onKeyPress: onInputKeyPress,
|
133
|
+
onKeyUp: handleInputKeyUp,
|
134
|
+
ref: combinedInputRef
|
135
|
+
}, props));
|
136
|
+
});
|
137
|
+
|
138
|
+
var _default = AutocompleteInput;
|
139
|
+
exports.default = _default;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ItemProps } from '../ActionList';
|
3
|
+
import { OverlayProps } from '../Overlay';
|
4
|
+
import { ComponentProps, MandateProps } from '../utils/types';
|
5
|
+
declare type OnAction<T> = (item: T, event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
6
|
+
declare type AutocompleteMenuInternalProps<T extends MandateProps<ItemProps, 'id'>> = {
|
7
|
+
/**
|
8
|
+
* A menu item that is used to allow users make a selection that is not available in the array passed to the `items` prop.
|
9
|
+
* This menu item gets appended to the end of the list of options.
|
10
|
+
*/
|
11
|
+
addNewItem?: Omit<T, 'onAction' | 'leadingVisual' | 'id'> & {
|
12
|
+
handleAddItem: (item: Omit<T, 'onAction' | 'leadingVisual'>) => void;
|
13
|
+
};
|
14
|
+
/**
|
15
|
+
* The text that appears in the menu when there are no options in the array passed to the `items` prop.
|
16
|
+
*/
|
17
|
+
emptyStateText?: React.ReactNode | false;
|
18
|
+
/**
|
19
|
+
* A custom function used to filter the options in the array passed to the `items` prop.
|
20
|
+
* By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
|
21
|
+
*/
|
22
|
+
filterFn?: (item: T, i: number) => boolean;
|
23
|
+
/**
|
24
|
+
* The options for field values that are displayed in the dropdown menu.
|
25
|
+
* One or more may be selected depending on the value of the `selectionVariant` prop.
|
26
|
+
*/
|
27
|
+
items: T[];
|
28
|
+
/**
|
29
|
+
* The function that is called when an item in the list is de-selected
|
30
|
+
*/
|
31
|
+
onItemDeselect?: OnAction<T>;
|
32
|
+
/**
|
33
|
+
* The function that is called when an item in the list is selected
|
34
|
+
*/
|
35
|
+
onItemSelect?: OnAction<T>;
|
36
|
+
/**
|
37
|
+
* Whether the data is loaded for the menu items
|
38
|
+
*/
|
39
|
+
loading?: boolean;
|
40
|
+
/**
|
41
|
+
* The IDs of the selected items
|
42
|
+
*/
|
43
|
+
selectedItemIds: Array<string | number>;
|
44
|
+
/**
|
45
|
+
* The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
|
46
|
+
* By default, selected items are sorted to the top after the user closes the menu.
|
47
|
+
*/
|
48
|
+
selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
|
49
|
+
/**
|
50
|
+
* Whether there can be one item selected from the menu or multiple items selected from the menu
|
51
|
+
*/
|
52
|
+
selectionVariant?: 'single' | 'multiple';
|
53
|
+
/**
|
54
|
+
* The ref of the element that the position of the menu is based on. By default, the menu is positioned based on the text input
|
55
|
+
*/
|
56
|
+
menuAnchorRef?: React.RefObject<Element>;
|
57
|
+
};
|
58
|
+
declare function AutocompleteMenu<T extends MandateProps<ItemProps, 'id'>>(props: AutocompleteMenuInternalProps<T> & Pick<OverlayProps, 'width' | 'height' | 'maxHeight'>): JSX.Element;
|
59
|
+
declare namespace AutocompleteMenu {
|
60
|
+
var defaultProps: {
|
61
|
+
emptyStateText: string;
|
62
|
+
selectionVariant: string;
|
63
|
+
};
|
64
|
+
var displayName: string;
|
65
|
+
}
|
66
|
+
export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
|
67
|
+
export default AutocompleteMenu;
|