@primer/components 0.0.0-20219151326 → 0.0.0-202191514518
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 +27 -3
- package/codemods/deprecateUtilityComponents.js +1 -1
- package/dist/browser.esm.js +874 -769
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +877 -772
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +1 -1
- package/lib/ActionList/List.d.ts +2 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib/Autocomplete/Autocomplete.d.ts +304 -0
- package/lib/Autocomplete/Autocomplete.js +145 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteContext.js +11 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +292 -0
- package/lib/Autocomplete/AutocompleteInput.js +157 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib/Autocomplete/AutocompleteMenu.js +224 -0
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/BaseStyles.js +1 -1
- package/lib/BorderBox.js +1 -1
- package/lib/Caret.js +2 -2
- package/lib/Dialog.js +1 -1
- package/lib/FilteredActionList/FilteredActionList.d.ts +3 -2
- package/lib/FilteredActionList/FilteredActionList.js +8 -32
- package/lib/Flash.js +16 -16
- package/lib/Label.js +1 -1
- package/lib/Overlay.d.ts +1 -0
- package/lib/Overlay.js +3 -1
- package/lib/ProgressBar.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib/SelectPanel/SelectPanel.d.ts +1 -1
- package/lib/SelectPanel/SelectPanel.js +9 -11
- package/lib/StateLabel.js +13 -19
- package/lib/TextInput.d.ts +5 -13
- package/lib/TextInput.js +4 -46
- package/lib/TextInputWithTokens.d.ts +323 -0
- package/lib/TextInputWithTokens.js +245 -0
- package/lib/Token/AvatarToken.d.ts +7 -0
- package/lib/Token/AvatarToken.js +64 -0
- package/lib/Token/IssueLabelToken.d.ts +14 -0
- package/lib/Token/IssueLabelToken.js +144 -0
- package/lib/Token/Token.d.ts +15 -0
- package/lib/Token/Token.js +94 -0
- package/lib/Token/TokenBase.d.ts +31 -0
- package/lib/Token/TokenBase.js +108 -0
- package/lib/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib/Token/_RemoveTokenButton.js +77 -0
- package/lib/Token/_TokenTextContainer.d.ts +3 -0
- package/lib/Token/_TokenTextContainer.js +17 -0
- package/lib/Token/index.d.ts +3 -0
- package/lib/Token/index.js +31 -0
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib/behaviors/scrollIntoViewingArea.js +39 -0
- package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +4 -2
- package/lib/index.d.ts +5 -0
- package/lib/index.js +36 -0
- package/lib/theme-preval.js +370 -3100
- package/lib/utils/testing.d.ts +50 -493
- package/lib/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib/utils/types/ComponentProps.d.ts +9 -0
- package/lib/utils/types/ComponentProps.js +1 -0
- package/lib/utils/types/Flatten.d.ts +4 -0
- package/lib/utils/types/Flatten.js +1 -0
- package/lib/utils/types/MandateProps.d.ts +3 -0
- package/lib/utils/types/MandateProps.js +1 -0
- package/lib/utils/types/Merge.d.ts +19 -0
- package/lib/utils/types/Merge.js +1 -0
- package/lib/utils/types/index.d.ts +5 -0
- package/lib/utils/types/index.js +70 -0
- package/lib-esm/ActionList/Item.js +1 -1
- package/lib-esm/ActionList/List.d.ts +2 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib-esm/Autocomplete/Autocomplete.d.ts +304 -0
- package/lib-esm/Autocomplete/Autocomplete.js +123 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +292 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/BaseStyles.js +1 -1
- package/lib-esm/BorderBox.js +1 -1
- package/lib-esm/Caret.js +2 -2
- package/lib-esm/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.d.ts +3 -2
- package/lib-esm/FilteredActionList/FilteredActionList.js +6 -32
- package/lib-esm/Flash.js +16 -16
- package/lib-esm/Label.js +1 -1
- package/lib-esm/Overlay.d.ts +1 -0
- package/lib-esm/Overlay.js +3 -1
- package/lib-esm/ProgressBar.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib-esm/SelectPanel/SelectPanel.d.ts +1 -1
- package/lib-esm/SelectPanel/SelectPanel.js +9 -8
- package/lib-esm/StateLabel.js +13 -19
- package/lib-esm/TextInput.d.ts +5 -13
- package/lib-esm/TextInput.js +4 -37
- package/lib-esm/TextInputWithTokens.d.ts +323 -0
- package/lib-esm/TextInputWithTokens.js +220 -0
- package/lib-esm/Token/AvatarToken.d.ts +7 -0
- package/lib-esm/Token/AvatarToken.js +43 -0
- package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
- package/lib-esm/Token/IssueLabelToken.js +124 -0
- package/lib-esm/Token/Token.d.ts +15 -0
- package/lib-esm/Token/Token.js +73 -0
- package/lib-esm/Token/TokenBase.d.ts +31 -0
- package/lib-esm/Token/TokenBase.js +87 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib-esm/Token/_RemoveTokenButton.js +60 -0
- package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
- package/lib-esm/Token/_TokenTextContainer.js +6 -0
- package/lib-esm/Token/index.d.ts +3 -0
- package/lib-esm/Token/index.js +3 -0
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib-esm/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +4 -2
- package/lib-esm/index.d.ts +5 -0
- package/lib-esm/index.js +3 -0
- package/lib-esm/theme-preval.js +370 -3100
- package/lib-esm/utils/testing.d.ts +50 -493
- package/lib-esm/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib-esm/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
- package/lib-esm/utils/types/ComponentProps.js +1 -0
- package/lib-esm/utils/types/Flatten.d.ts +4 -0
- package/lib-esm/utils/types/Flatten.js +1 -0
- package/lib-esm/utils/types/MandateProps.d.ts +3 -0
- package/lib-esm/utils/types/MandateProps.js +1 -0
- package/lib-esm/utils/types/Merge.d.ts +19 -0
- package/lib-esm/utils/types/Merge.js +1 -0
- package/lib-esm/utils/types/index.d.ts +5 -0
- package/lib-esm/utils/types/index.js +5 -0
- package/package.json +4 -3
@@ -0,0 +1,87 @@
|
|
1
|
+
import styled from 'styled-components';
|
2
|
+
import { variant } from 'styled-system';
|
3
|
+
import { get } from '../constants';
|
4
|
+
import sx from '../sx';
|
5
|
+
export const tokenSizes = {
|
6
|
+
small: '16px',
|
7
|
+
medium: '20px',
|
8
|
+
large: '24px',
|
9
|
+
extralarge: '32px'
|
10
|
+
};
|
11
|
+
export const defaultTokenSize = 'medium';
|
12
|
+
export const isTokenInteractive = ({
|
13
|
+
as = 'span',
|
14
|
+
onClick,
|
15
|
+
onFocus,
|
16
|
+
tabIndex = -1
|
17
|
+
}) => Boolean(onFocus || onClick || tabIndex > -1 || ['a', 'button'].includes(as));
|
18
|
+
const variants = variant({
|
19
|
+
prop: 'size',
|
20
|
+
variants: {
|
21
|
+
small: {
|
22
|
+
fontSize: 0,
|
23
|
+
gap: 1,
|
24
|
+
height: tokenSizes.small,
|
25
|
+
// without setting lineHeight to match height, the "x" appears vertically mis-aligned
|
26
|
+
lineHeight: tokenSizes.small,
|
27
|
+
paddingLeft: 1,
|
28
|
+
paddingRight: 1,
|
29
|
+
// need to explicitly set padding top and bottom to "0" to override default `<button>` element styles
|
30
|
+
// without setting these, the "x" appears vertically mis-aligned
|
31
|
+
paddingTop: 0,
|
32
|
+
paddingBottom: 0
|
33
|
+
},
|
34
|
+
medium: {
|
35
|
+
fontSize: 0,
|
36
|
+
gap: 1,
|
37
|
+
height: tokenSizes.medium,
|
38
|
+
lineHeight: tokenSizes.medium,
|
39
|
+
paddingLeft: 2,
|
40
|
+
paddingRight: 2,
|
41
|
+
paddingTop: 0,
|
42
|
+
paddingBottom: 0
|
43
|
+
},
|
44
|
+
large: {
|
45
|
+
fontSize: 0,
|
46
|
+
gap: 2,
|
47
|
+
height: tokenSizes.large,
|
48
|
+
lineHeight: tokenSizes.large,
|
49
|
+
paddingLeft: 2,
|
50
|
+
paddingRight: 2,
|
51
|
+
paddingTop: 0,
|
52
|
+
paddingBottom: 0
|
53
|
+
},
|
54
|
+
extralarge: {
|
55
|
+
fontSize: 1,
|
56
|
+
gap: 2,
|
57
|
+
height: tokenSizes.extralarge,
|
58
|
+
lineHeight: tokenSizes.extralarge,
|
59
|
+
paddingLeft: 3,
|
60
|
+
paddingRight: 3,
|
61
|
+
paddingTop: 0,
|
62
|
+
paddingBottom: 0
|
63
|
+
}
|
64
|
+
}
|
65
|
+
});
|
66
|
+
const TokenBase = styled.span.attrs(({
|
67
|
+
text,
|
68
|
+
onRemove,
|
69
|
+
onKeyDown
|
70
|
+
}) => ({
|
71
|
+
onKeyDown: event => {
|
72
|
+
onKeyDown && onKeyDown(event);
|
73
|
+
|
74
|
+
if ((event.key === 'Backspace' || event.key === 'Delete') && onRemove) {
|
75
|
+
onRemove();
|
76
|
+
}
|
77
|
+
},
|
78
|
+
'aria-label': onRemove ? `${text}, press backspace or delete to remove` : undefined
|
79
|
+
})).withConfig({
|
80
|
+
displayName: "TokenBase",
|
81
|
+
componentId: "opajvp-0"
|
82
|
+
})(["align-items:center;border-radius:999px;cursor:", ";display:inline-flex;font-weight:", ";font-family:inherit;text-decoration:none;white-space:nowrap;", " ", ""], props => isTokenInteractive(props) ? 'pointer' : 'auto', get('fontWeights.bold'), variants, sx);
|
83
|
+
TokenBase.defaultProps = {
|
84
|
+
as: 'span',
|
85
|
+
size: defaultTokenSize
|
86
|
+
};
|
87
|
+
export default TokenBase;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { SxProp } from '../sx';
|
3
|
+
import { ComponentProps } from '../utils/types';
|
4
|
+
import { TokenSizeKeys } from './TokenBase';
|
5
|
+
interface TokenButtonProps {
|
6
|
+
borderOffset?: number;
|
7
|
+
size?: TokenSizeKeys;
|
8
|
+
isParentInteractive?: boolean;
|
9
|
+
}
|
10
|
+
declare const StyledTokenButton: import("styled-components").StyledComponent<"span", any, TokenButtonProps & SxProp, never>;
|
11
|
+
declare const RemoveTokenButton: React.FC<ComponentProps<typeof StyledTokenButton>>;
|
12
|
+
export default RemoveTokenButton;
|
@@ -0,0 +1,60 @@
|
|
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 { XIcon } from '@primer/octicons-react';
|
5
|
+
import styled from 'styled-components';
|
6
|
+
import { variant } from 'styled-system';
|
7
|
+
import { get } from '../constants';
|
8
|
+
import sx from '../sx';
|
9
|
+
import { tokenSizes, defaultTokenSize } from './TokenBase';
|
10
|
+
const variants = variant({
|
11
|
+
prop: 'size',
|
12
|
+
variants: {
|
13
|
+
small: {
|
14
|
+
height: tokenSizes.small,
|
15
|
+
width: tokenSizes.small
|
16
|
+
},
|
17
|
+
medium: {
|
18
|
+
height: tokenSizes.medium,
|
19
|
+
width: tokenSizes.medium
|
20
|
+
},
|
21
|
+
large: {
|
22
|
+
height: tokenSizes.large,
|
23
|
+
width: tokenSizes.large
|
24
|
+
},
|
25
|
+
extralarge: {
|
26
|
+
height: tokenSizes.extralarge,
|
27
|
+
width: tokenSizes.extralarge
|
28
|
+
}
|
29
|
+
}
|
30
|
+
});
|
31
|
+
|
32
|
+
const getTokenButtonIconSize = size => parseInt(tokenSizes[size || defaultTokenSize], 10) * 0.75;
|
33
|
+
|
34
|
+
const StyledTokenButton = styled.span.withConfig({
|
35
|
+
displayName: "_RemoveTokenButton__StyledTokenButton",
|
36
|
+
componentId: "sc-14lvcw1-0"
|
37
|
+
})(["background-color:transparent;font-family:inherit;color:currentColor;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;user-select:none;appearance:none;text-decoration:none;padding:0;transform:", ";align-self:baseline;border:0;border-radius:999px;&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}", " ", ""], props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`, get('colors.neutral.muted'), get('colors.neutral.subtle'), variants, sx);
|
38
|
+
|
39
|
+
const RemoveTokenButton = ({
|
40
|
+
'aria-label': ariaLabel,
|
41
|
+
isParentInteractive,
|
42
|
+
size,
|
43
|
+
...rest
|
44
|
+
}) => {
|
45
|
+
delete rest.children;
|
46
|
+
return /*#__PURE__*/React.createElement(StyledTokenButton, _extends({
|
47
|
+
as: isParentInteractive ? 'span' : 'button',
|
48
|
+
tabIndex: isParentInteractive ? -1 : undefined,
|
49
|
+
"aria-label": !isParentInteractive ? 'Remove token' : ariaLabel,
|
50
|
+
size: size
|
51
|
+
}, rest), /*#__PURE__*/React.createElement(XIcon, {
|
52
|
+
size: getTokenButtonIconSize(size)
|
53
|
+
}));
|
54
|
+
};
|
55
|
+
|
56
|
+
RemoveTokenButton.displayName = "RemoveTokenButton";
|
57
|
+
RemoveTokenButton.defaultProps = {
|
58
|
+
size: defaultTokenSize
|
59
|
+
};
|
60
|
+
export default RemoveTokenButton;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import styled from 'styled-components';
|
2
|
+
const TokenTextContainer = styled('span').withConfig({
|
3
|
+
displayName: "_TokenTextContainer__TokenTextContainer",
|
4
|
+
componentId: "sc-4t2bev-0"
|
5
|
+
})(["flex-grow:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background:transparent;border:none;color:inherit;font:inherit;margin:0;overflow:visible;padding:0;width:auto;-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-webkit-appearance:none;line-height:1;color:currentColor;text-decoration:none;&:is(a,button,[tabIndex='0']){cursor:pointer;&:after{content:'';position:absolute;left:0;top:0;right:0;bottom:0;}}"]);
|
6
|
+
export default TokenTextContainer;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
2
|
+
import { SxProp } from './sx';
|
3
|
+
declare const TextInputWrapper: import("styled-components").StyledComponent<"span", any, {
|
4
|
+
disabled?: boolean | undefined;
|
5
|
+
hasIcon?: boolean | undefined;
|
6
|
+
block?: boolean | undefined;
|
7
|
+
contrast?: boolean | undefined;
|
8
|
+
variant?: "large" | "small" | undefined;
|
9
|
+
} & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
|
10
|
+
export default TextInputWrapper;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import styled, { css } from 'styled-components';
|
2
|
+
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
3
|
+
import { get } from './constants';
|
4
|
+
import sx from './sx';
|
5
|
+
const sizeVariants = variant({
|
6
|
+
variants: {
|
7
|
+
small: {
|
8
|
+
minHeight: '28px',
|
9
|
+
px: 2,
|
10
|
+
py: '3px',
|
11
|
+
fontSize: 0,
|
12
|
+
lineHeight: '20px'
|
13
|
+
},
|
14
|
+
large: {
|
15
|
+
px: 2,
|
16
|
+
py: '10px',
|
17
|
+
fontSize: 3
|
18
|
+
}
|
19
|
+
}
|
20
|
+
});
|
21
|
+
const TextInputWrapper = styled.span.withConfig({
|
22
|
+
displayName: "_TextInputWrapper__TextInputWrapper",
|
23
|
+
componentId: "sc-5vfcis-0"
|
24
|
+
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
|
25
|
+
if (props.hasIcon) {
|
26
|
+
return css(["padding:0;"]);
|
27
|
+
} else {
|
28
|
+
return css(["padding:6px 12px;"]);
|
29
|
+
}
|
30
|
+
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx);
|
31
|
+
export default TextInputWrapper;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import styled from 'styled-components';
|
2
|
+
import sx from './sx';
|
3
|
+
const UnstyledTextInput = styled.input.withConfig({
|
4
|
+
displayName: "_UnstyledTextInput__UnstyledTextInput",
|
5
|
+
componentId: "sc-1jgl33s-0"
|
6
|
+
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}", ";"], sx);
|
7
|
+
export default UnstyledTextInput;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const scrollIntoViewingArea: (child: HTMLElement, viewingArea: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export const scrollIntoViewingArea = (child, viewingArea, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
|
2
|
+
const startSide = direction === 'vertical' ? 'top' : 'left';
|
3
|
+
const endSide = direction === 'vertical' ? 'bottom' : 'right';
|
4
|
+
const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
|
5
|
+
const {
|
6
|
+
[startSide]: childStart,
|
7
|
+
[endSide]: childEnd
|
8
|
+
} = child.getBoundingClientRect();
|
9
|
+
const {
|
10
|
+
[startSide]: viewingAreaStart,
|
11
|
+
[endSide]: viewingAreaEnd
|
12
|
+
} = viewingArea.getBoundingClientRect();
|
13
|
+
const isChildStartAboveViewingArea = childStart < viewingAreaStart + endMargin;
|
14
|
+
const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - startMargin;
|
15
|
+
|
16
|
+
if (isChildStartAboveViewingArea) {
|
17
|
+
const scrollHeightToChildStart = childStart - viewingAreaStart + viewingArea[scrollSide];
|
18
|
+
viewingArea.scrollTo({
|
19
|
+
behavior,
|
20
|
+
[startSide]: scrollHeightToChildStart - endMargin
|
21
|
+
});
|
22
|
+
} else if (isChildBottomBelowViewingArea) {
|
23
|
+
const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
|
24
|
+
viewingArea.scrollTo({
|
25
|
+
behavior,
|
26
|
+
[startSide]: scrollHeightToChildBottom + startMargin
|
27
|
+
});
|
28
|
+
} // either completely in view or outside viewing area on both ends, don't scroll
|
29
|
+
|
30
|
+
};
|
@@ -3,5 +3,6 @@ export declare type UseOpenAndCloseFocusSettings = {
|
|
3
3
|
initialFocusRef?: React.RefObject<HTMLElement>;
|
4
4
|
containerRef: React.RefObject<HTMLElement>;
|
5
5
|
returnFocusRef: React.RefObject<HTMLElement>;
|
6
|
+
preventFocusOnOpen?: boolean;
|
6
7
|
};
|
7
|
-
export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef }: UseOpenAndCloseFocusSettings): void;
|
8
|
+
export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen }: UseOpenAndCloseFocusSettings): void;
|
@@ -3,9 +3,14 @@ import { iterateFocusableElements } from '../utils/iterateFocusableElements';
|
|
3
3
|
export function useOpenAndCloseFocus({
|
4
4
|
initialFocusRef,
|
5
5
|
returnFocusRef,
|
6
|
-
containerRef
|
6
|
+
containerRef,
|
7
|
+
preventFocusOnOpen
|
7
8
|
}) {
|
8
9
|
useEffect(() => {
|
10
|
+
if (preventFocusOnOpen) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
9
14
|
const returnRef = returnFocusRef.current;
|
10
15
|
|
11
16
|
if (initialFocusRef && initialFocusRef.current) {
|
@@ -18,5 +23,5 @@ export function useOpenAndCloseFocus({
|
|
18
23
|
return function () {
|
19
24
|
returnRef === null || returnRef === void 0 ? void 0 : returnRef.focus();
|
20
25
|
};
|
21
|
-
}, [initialFocusRef, returnFocusRef, containerRef]);
|
26
|
+
}, [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen]);
|
22
27
|
}
|
@@ -7,8 +7,9 @@ export declare type UseOverlaySettings = {
|
|
7
7
|
onEscape: (e: KeyboardEvent) => void;
|
8
8
|
onClickOutside: (e: TouchOrMouseEvent) => void;
|
9
9
|
overlayRef?: React.RefObject<HTMLDivElement>;
|
10
|
+
preventFocusOnOpen?: boolean;
|
10
11
|
};
|
11
12
|
export declare type OverlayReturnProps = {
|
12
13
|
ref: React.RefObject<HTMLDivElement>;
|
13
14
|
};
|
14
|
-
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside }: UseOverlaySettings) => OverlayReturnProps;
|
15
|
+
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen }: UseOverlaySettings) => OverlayReturnProps;
|
@@ -8,13 +8,15 @@ export const useOverlay = ({
|
|
8
8
|
initialFocusRef,
|
9
9
|
onEscape,
|
10
10
|
ignoreClickRefs,
|
11
|
-
onClickOutside
|
11
|
+
onClickOutside,
|
12
|
+
preventFocusOnOpen
|
12
13
|
}) => {
|
13
14
|
const overlayRef = useProvidedRefOrCreate(_overlayRef);
|
14
15
|
useOpenAndCloseFocus({
|
15
16
|
containerRef: overlayRef,
|
16
17
|
returnFocusRef,
|
17
|
-
initialFocusRef
|
18
|
+
initialFocusRef,
|
19
|
+
preventFocusOnOpen
|
18
20
|
});
|
19
21
|
useOnOutsideClick({
|
20
22
|
containerRef: overlayRef,
|
package/lib-esm/index.d.ts
CHANGED
@@ -24,6 +24,8 @@ export { useConfirm } from './Dialog/ConfirmationDialog';
|
|
24
24
|
export { ActionList } from './ActionList';
|
25
25
|
export { ActionMenu } from './ActionMenu';
|
26
26
|
export type { ActionMenuProps } from './ActionMenu';
|
27
|
+
export { default as Autocomplete } from './Autocomplete';
|
28
|
+
export type { AutocompleteMenuProps, AutocompleteInputProps, AutocompleteOverlayProps } from './Autocomplete';
|
27
29
|
export { default as Avatar } from './Avatar';
|
28
30
|
export type { AvatarProps } from './Avatar';
|
29
31
|
export { default as AvatarPair } from './AvatarPair';
|
@@ -98,10 +100,13 @@ export { default as TabNav } from './TabNav';
|
|
98
100
|
export type { TabNavProps, TabNavLinkProps } from './TabNav';
|
99
101
|
export { default as TextInput } from './TextInput';
|
100
102
|
export type { TextInputProps } from './TextInput';
|
103
|
+
export { default as TextInputWithTokens } from './TextInputWithTokens';
|
104
|
+
export type { TextInputWithTokensProps } from './TextInputWithTokens';
|
101
105
|
export { default as Text } from './Text';
|
102
106
|
export type { TextProps } from './Text';
|
103
107
|
export { default as Timeline } from './Timeline';
|
104
108
|
export type { TimelineProps, TimelineBadgeProps, TimelineBodyProps, TimelineBreakProps, TimelineItemsProps } from './Timeline';
|
109
|
+
export { default as Token, IssueLabelToken, AvatarToken } from './Token';
|
105
110
|
export { default as Tooltip } from './Tooltip';
|
106
111
|
export type { TooltipProps } from './Tooltip';
|
107
112
|
export { default as Truncate } from './Truncate';
|
package/lib-esm/index.js
CHANGED
@@ -19,6 +19,7 @@ export { useConfirm } from './Dialog/ConfirmationDialog'; // Components
|
|
19
19
|
|
20
20
|
export { ActionList } from './ActionList';
|
21
21
|
export { ActionMenu } from './ActionMenu';
|
22
|
+
export { default as Autocomplete } from './Autocomplete';
|
22
23
|
export { default as Avatar } from './Avatar';
|
23
24
|
export { default as AvatarPair } from './AvatarPair';
|
24
25
|
export { default as AvatarStack } from './AvatarStack';
|
@@ -61,8 +62,10 @@ export { default as StyledOcticon } from './StyledOcticon';
|
|
61
62
|
export { default as SubNav } from './SubNav';
|
62
63
|
export { default as TabNav } from './TabNav';
|
63
64
|
export { default as TextInput } from './TextInput';
|
65
|
+
export { default as TextInputWithTokens } from './TextInputWithTokens';
|
64
66
|
export { default as Text } from './Text';
|
65
67
|
export { default as Timeline } from './Timeline';
|
68
|
+
export { default as Token, IssueLabelToken, AvatarToken } from './Token';
|
66
69
|
export { default as Tooltip } from './Tooltip';
|
67
70
|
export { default as Truncate } from './Truncate';
|
68
71
|
export { default as UnderlineNav } from './UnderlineNav';
|