@primer/components 0.0.0-2021821174731 → 0.0.0-2021821193917
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +2 -28
- package/dist/browser.esm.js +619 -665
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +386 -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 +36 -0
- package/lib/Autocomplete/Autocomplete.js +55 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +13 -0
- package/lib/Autocomplete/AutocompleteContext.js +14 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib/Autocomplete/AutocompleteInput.js +128 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +54 -0
- package/lib/Autocomplete/AutocompleteMenu.js +268 -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.js +1 -1
- 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.js +2 -2
- 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 +5 -5
- 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 +337 -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/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 +6 -6
- package/lib/TextInput.js +16 -21
- package/lib/TextInputTokens.d.ts +32 -0
- package/lib/TextInputTokens.js +241 -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 +69 -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/_AddTokenButton.d.ts +3 -0
- package/lib/Token/_AddTokenButton.js +42 -0
- package/lib/Token/_RemoveTokenButton.d.ts +3 -0
- package/lib/Token/_RemoveTokenButton.js +42 -0
- package/lib/Token/_tokenButtonUtils.d.ts +8 -0
- package/lib/Token/_tokenButtonUtils.js +42 -0
- package/lib/Tooltip.js +1 -1
- package/lib/UnderlineNav.js +2 -2
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +11 -6
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -14
- package/lib/theme-preval.d.ts +6 -12
- package/lib/theme-preval.js +0 -940
- package/lib/utils/testing.d.ts +0 -1854
- 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 +36 -0
- package/lib-esm/Autocomplete/Autocomplete.js +36 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +13 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +5 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +109 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +54 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +244 -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.js +1 -1
- 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.js +2 -2
- 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 +5 -5
- 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 +337 -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/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 +6 -6
- package/lib-esm/TextInput.js +16 -22
- package/lib-esm/TextInputTokens.d.ts +32 -0
- package/lib-esm/TextInputTokens.js +211 -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 +49 -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/_AddTokenButton.d.ts +3 -0
- package/lib-esm/Token/_AddTokenButton.js +27 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +3 -0
- package/lib-esm/Token/_RemoveTokenButton.js +27 -0
- package/lib-esm/Token/_tokenButtonUtils.d.ts +8 -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/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +11 -6
- package/lib-esm/index.d.ts +0 -1
- package/lib-esm/index.js +1 -2
- package/lib-esm/theme-preval.d.ts +6 -12
- package/lib-esm/theme-preval.js +0 -940
- package/lib-esm/utils/testing.d.ts +0 -1854
- package/lib-esm/utils/uniqueId.js +0 -1
- package/package.json +7 -6
- package/lib/utils/ssr.d.ts +0 -1
- package/lib/utils/ssr.js +0 -19
- 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,36 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ComponentProps } from '../utils/types';
|
3
|
+
declare const Autocomplete: React.FC;
|
4
|
+
export declare type AutocompleteProps = ComponentProps<typeof Autocomplete>;
|
5
|
+
export type { AutocompleteInputProps } from './AutocompleteInput';
|
6
|
+
export type { AutocompleteMenuProps } from './AutocompleteMenu';
|
7
|
+
declare const _default: React.FC<{}> & {
|
8
|
+
AutocompleteContext: React.Context<{
|
9
|
+
activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
|
10
|
+
autocompleteSuggestion?: string | undefined;
|
11
|
+
inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
|
12
|
+
inputValue?: string | undefined;
|
13
|
+
showMenu?: boolean | undefined;
|
14
|
+
setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
15
|
+
setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
16
|
+
setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
17
|
+
isMenuDirectlyActivated?: boolean | undefined;
|
18
|
+
setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
19
|
+
}>;
|
20
|
+
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
|
21
|
+
as?: React.ComponentType<any> | undefined;
|
22
|
+
}>;
|
23
|
+
Menu: React.ForwardRefExoticComponent<{
|
24
|
+
addNewItem?: Omit<import("../ActionList/List").ItemInput, "onAction"> | undefined;
|
25
|
+
emptyStateText?: React.ReactNode;
|
26
|
+
filterFn?: ((item: import("../ActionList/List").ItemInput, i: number) => boolean) | undefined;
|
27
|
+
items: import("../ActionList/List").ItemInput[];
|
28
|
+
onItemDeselect?: ((item: import("../ActionList").ItemProps, event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
29
|
+
onItemSelect?: ((item: import("../ActionList").ItemProps, event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
30
|
+
loading?: boolean | undefined;
|
31
|
+
selectedItemIds: (string | number)[];
|
32
|
+
selectedSortFn?: ((itemIdA: string | number, itemIdB: string | number) => number) | undefined;
|
33
|
+
selectionVariant?: "multiple" | "single" | undefined;
|
34
|
+
} & Pick<import("..").OverlayProps, "height" | "maxHeight" | "width"> & React.RefAttributes<HTMLInputElement>>;
|
35
|
+
};
|
36
|
+
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,14 @@
|
|
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
|
+
const AutocompleteContext = /*#__PURE__*/(0, _react.createContext)({});
|
14
|
+
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,128 @@
|
|
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
|
+
onChange,
|
28
|
+
onKeyDown,
|
29
|
+
onKeyPress,
|
30
|
+
value,
|
31
|
+
...props
|
32
|
+
}, forwardedRef) => {
|
33
|
+
const {
|
34
|
+
activeDescendantRef,
|
35
|
+
autocompleteSuggestion = '',
|
36
|
+
inputRef,
|
37
|
+
inputValue = '',
|
38
|
+
isMenuDirectlyActivated,
|
39
|
+
setInputValue,
|
40
|
+
setShowMenu,
|
41
|
+
showMenu
|
42
|
+
} = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
|
43
|
+
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(inputRef, forwardedRef);
|
44
|
+
const [highlightRemainingText, setHighlightRemainingText] = (0, _react.useState)(true);
|
45
|
+
|
46
|
+
const handleInputFocus = () => {
|
47
|
+
if (setShowMenu) {
|
48
|
+
setShowMenu(true);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
const handleInputBlur = e => {
|
53
|
+
// 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
|
+
setTimeout(() => {
|
57
|
+
if (setShowMenu && document.activeElement !== combinedInputRef.current) {
|
58
|
+
setShowMenu(false);
|
59
|
+
}
|
60
|
+
}, 0);
|
61
|
+
};
|
62
|
+
|
63
|
+
const handleInputChange = e => {
|
64
|
+
if (setInputValue) {
|
65
|
+
setInputValue(e.currentTarget.value);
|
66
|
+
}
|
67
|
+
|
68
|
+
if (setShowMenu && !showMenu) {
|
69
|
+
setShowMenu(true);
|
70
|
+
}
|
71
|
+
};
|
72
|
+
|
73
|
+
const handleInputKeyDown = e => {
|
74
|
+
if (e.key === 'Backspace') {
|
75
|
+
setHighlightRemainingText(false);
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
const handleInputKeyUp = e => {
|
80
|
+
if (e.key === 'Backspace') {
|
81
|
+
setHighlightRemainingText(true);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
const onInputKeyPress = (0, _react.useCallback)(event => {
|
86
|
+
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
87
|
+
event.preventDefault();
|
88
|
+
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
89
|
+
|
90
|
+
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
91
|
+
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
92
|
+
}
|
93
|
+
}, [activeDescendantRef]);
|
94
|
+
(0, _react.useEffect)(() => {
|
95
|
+
if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (!autocompleteSuggestion) {
|
100
|
+
inputRef.current.value = inputValue;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
104
|
+
inputRef.current.value = autocompleteSuggestion;
|
105
|
+
|
106
|
+
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
107
|
+
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}, [autocompleteSuggestion, inputValue]);
|
111
|
+
(0, _react.useEffect)(() => {
|
112
|
+
if (value && setInputValue) {
|
113
|
+
setInputValue(value.toString());
|
114
|
+
}
|
115
|
+
}, [value]);
|
116
|
+
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
117
|
+
onFocus: handleInputFocus,
|
118
|
+
onBlur: handleInputBlur,
|
119
|
+
onChange: handleInputChange,
|
120
|
+
onKeyDown: handleInputKeyDown,
|
121
|
+
onKeyPress: onInputKeyPress,
|
122
|
+
onKeyUp: handleInputKeyUp,
|
123
|
+
ref: combinedInputRef
|
124
|
+
}, props));
|
125
|
+
});
|
126
|
+
|
127
|
+
var _default = AutocompleteInput;
|
128
|
+
exports.default = _default;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ItemProps } from '../ActionList';
|
3
|
+
import { ItemInput } from '../ActionList/List';
|
4
|
+
import { OverlayProps } from '../Overlay';
|
5
|
+
import { ComponentProps } from '../utils/types';
|
6
|
+
declare type AutocompleteMenuInternalProps = {
|
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<ItemInput, 'onAction'>;
|
12
|
+
/**
|
13
|
+
* The text that appears in the menu when there are no options in the array passed to the `items` prop.
|
14
|
+
*/
|
15
|
+
emptyStateText?: React.ReactNode | false;
|
16
|
+
/**
|
17
|
+
* A custom function used to filter the options in the array passed to the `items` prop.
|
18
|
+
* By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
|
19
|
+
*/
|
20
|
+
filterFn?: (item: ItemInput, i: number) => boolean;
|
21
|
+
/**
|
22
|
+
* The options for field values that are displayed in the dropdown menu.
|
23
|
+
* One or more may be selected depending on the value of the `selectionVariant` prop.
|
24
|
+
*/
|
25
|
+
items: ItemInput[];
|
26
|
+
/**
|
27
|
+
* The function that is called when an item in the list is de-selected
|
28
|
+
*/
|
29
|
+
onItemDeselect?: NonNullable<ItemProps['onAction']>;
|
30
|
+
/**
|
31
|
+
* The function that is called when an item in the list is selected
|
32
|
+
*/
|
33
|
+
onItemSelect?: NonNullable<ItemProps['onAction']>;
|
34
|
+
/**
|
35
|
+
* Whether the data is loaded for the menu items
|
36
|
+
*/
|
37
|
+
loading?: boolean;
|
38
|
+
/**
|
39
|
+
* The IDs of the selected items
|
40
|
+
*/
|
41
|
+
selectedItemIds: Array<string | number>;
|
42
|
+
/**
|
43
|
+
* The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
|
44
|
+
* By default, selected items are sorted to the top after the user closes the menu.
|
45
|
+
*/
|
46
|
+
selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
|
47
|
+
/**
|
48
|
+
* Whether there can be one item selected from the menu or multiple items selected from the menu
|
49
|
+
*/
|
50
|
+
selectionVariant?: 'single' | 'multiple';
|
51
|
+
};
|
52
|
+
declare const AutocompleteMenu: React.ForwardRefExoticComponent<AutocompleteMenuInternalProps & Pick<OverlayProps, "height" | "maxHeight" | "width"> & React.RefAttributes<HTMLInputElement>>;
|
53
|
+
export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
|
54
|
+
export default AutocompleteMenu;
|