@atlaskit/link-picker 1.11.2 → 1.13.0
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 +12 -0
- package/dist/cjs/services/use-plugins/index.js +7 -1
- package/dist/cjs/ui/link-picker/index.js +11 -7
- package/dist/cjs/ui/scrolling-tabs/index.js +192 -0
- package/dist/cjs/ui/scrolling-tabs/scrolling-tabs.js +123 -0
- package/dist/cjs/ui/scrolling-tabs/styles.js +64 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/services/use-plugins/index.js +7 -1
- package/dist/es2019/ui/link-picker/index.js +8 -5
- package/dist/es2019/ui/scrolling-tabs/index.js +127 -0
- package/dist/es2019/ui/scrolling-tabs/scrolling-tabs.js +90 -0
- package/dist/es2019/ui/scrolling-tabs/styles.js +49 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/services/use-plugins/index.js +7 -1
- package/dist/esm/ui/link-picker/index.js +10 -7
- package/dist/esm/ui/scrolling-tabs/index.js +165 -0
- package/dist/esm/ui/scrolling-tabs/scrolling-tabs.js +96 -0
- package/dist/esm/ui/scrolling-tabs/styles.js +49 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/ui/link-picker/index.d.ts +1 -0
- package/dist/types/ui/scrolling-tabs/index.d.ts +7 -0
- package/dist/types/ui/scrolling-tabs/scrolling-tabs.d.ts +11 -0
- package/dist/types/ui/scrolling-tabs/styles.d.ts +6 -0
- package/dist/types/ui/types.d.ts +2 -0
- package/dist/types-ts4.0/ui/link-picker/index.d.ts +1 -0
- package/dist/types-ts4.0/ui/scrolling-tabs/index.d.ts +7 -0
- package/dist/types-ts4.0/ui/scrolling-tabs/scrolling-tabs.d.ts +11 -0
- package/dist/types-ts4.0/ui/scrolling-tabs/styles.d.ts +6 -0
- package/dist/types-ts4.0/ui/types.d.ts +2 -0
- package/package.json +6 -6
- package/report.api.md +3 -0
- package/tmp/api-report-tmp.d.ts +3 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const BUTTON_SIZE = 24;
|
|
2
|
+
const GUTTER = 48;
|
|
3
|
+
const GHOST_WIDTH = 342 - GUTTER - 40;
|
|
4
|
+
export const scrollBack = ref => {
|
|
5
|
+
moveTabsScroll(ref, findPrevious);
|
|
6
|
+
};
|
|
7
|
+
export const scrollForward = ref => {
|
|
8
|
+
moveTabsScroll(ref, findNext);
|
|
9
|
+
};
|
|
10
|
+
export const calculateConditionalButtons = (container, hideButtons) => {
|
|
11
|
+
const initialState = {
|
|
12
|
+
back: false,
|
|
13
|
+
forward: false
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (!container || hideButtons) {
|
|
17
|
+
return initialState;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const maxScrollValue = container.scrollWidth - container.clientWidth;
|
|
21
|
+
return {
|
|
22
|
+
back: container.scrollLeft > 0,
|
|
23
|
+
forward: container.scrollLeft < maxScrollValue - GHOST_WIDTH
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const createGhost = () => {
|
|
27
|
+
const ghost = document.createElement('div');
|
|
28
|
+
ghost.setAttribute('id', 'scrolling-tabs-ghost');
|
|
29
|
+
ghost.style.minWidth = `${GHOST_WIDTH}px`;
|
|
30
|
+
ghost.style.pointerEvents = 'none';
|
|
31
|
+
return ghost;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const moveTabsScroll = (ref, findFn) => {
|
|
35
|
+
const container = getContainer(ref);
|
|
36
|
+
|
|
37
|
+
if (container) {
|
|
38
|
+
const tablist = container.children[0];
|
|
39
|
+
const tabs = [...tablist.children];
|
|
40
|
+
|
|
41
|
+
if (tabs.length > 0) {
|
|
42
|
+
const target = findFn(container, tabs);
|
|
43
|
+
|
|
44
|
+
if (target) {
|
|
45
|
+
const left = container.scrollLeft + target.getBoundingClientRect().left - container.getBoundingClientRect().left - BUTTON_SIZE;
|
|
46
|
+
scrollTo(container, left);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const scrollTo = (container, left) => {
|
|
53
|
+
container.scrollTo({
|
|
54
|
+
left
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getTabList = ref => {
|
|
59
|
+
var _ref$current;
|
|
60
|
+
|
|
61
|
+
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector('[role="tablist"]');
|
|
62
|
+
};
|
|
63
|
+
export const getContainer = ref => {
|
|
64
|
+
var _getTabList;
|
|
65
|
+
|
|
66
|
+
return (_getTabList = getTabList(ref)) === null || _getTabList === void 0 ? void 0 : _getTabList.parentElement;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const findPrevious = (container, tabs) => {
|
|
70
|
+
const previousTabs = tabs.filter(tab => {
|
|
71
|
+
const [containerRect, tabRect] = [container.getBoundingClientRect(), tab.getBoundingClientRect()];
|
|
72
|
+
const [containerArea, tabArea] = [containerRect.left + container.scrollLeft - GUTTER, container.scrollLeft + tabRect.left + tabRect.width];
|
|
73
|
+
return containerArea > tabArea;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (previousTabs.length < 3) {
|
|
77
|
+
return previousTabs[0];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return previousTabs[previousTabs.length - 1];
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const findNext = (container, tabs) => {
|
|
84
|
+
const containerRect = container.getBoundingClientRect();
|
|
85
|
+
return tabs.find(tab => {
|
|
86
|
+
const tabRect = tab.getBoundingClientRect();
|
|
87
|
+
const [containerArea, tabArea] = [container.clientWidth + containerRect.left - GUTTER, tabRect.left + tabRect.width];
|
|
88
|
+
return containerArea < tabArea;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { css } from '@emotion/react';
|
|
2
|
+
import { token } from '@atlaskit/tokens';
|
|
3
|
+
import { N0, N30 } from '@atlaskit/theme/colors';
|
|
4
|
+
export const scrollingContainerStyles = css({
|
|
5
|
+
overflowX: 'auto',
|
|
6
|
+
scrollBehavior: 'smooth',
|
|
7
|
+
scrollPadding: '0 24px',
|
|
8
|
+
scrollbarWidth: 'none',
|
|
9
|
+
'&::-webkit-scrollbar': {
|
|
10
|
+
display: 'none'
|
|
11
|
+
},
|
|
12
|
+
'&::before': {
|
|
13
|
+
content: '""',
|
|
14
|
+
borderRadius: 2,
|
|
15
|
+
bottom: 0,
|
|
16
|
+
margin: 0,
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
width: 'inherit',
|
|
19
|
+
left: 8,
|
|
20
|
+
right: 8,
|
|
21
|
+
height: 2,
|
|
22
|
+
backgroundColor: token('color.border', N30)
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export const containerStyles = css({
|
|
26
|
+
position: 'relative',
|
|
27
|
+
'[role="tablist"]': {
|
|
28
|
+
'&::before': {
|
|
29
|
+
display: 'none'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
// Overrides Atlaskit tabs styles to stop overflowing with ellipsis
|
|
33
|
+
'[role="tab"]': {
|
|
34
|
+
overflow: 'unset !important',
|
|
35
|
+
textOverflow: 'unset !important'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export const buttonContainerStyles = css({
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
top: 4,
|
|
41
|
+
zIndex: 999,
|
|
42
|
+
backgroundColor: token('elevation.surface', N0)
|
|
43
|
+
});
|
|
44
|
+
export const backButtonStyles = css([buttonContainerStyles, {
|
|
45
|
+
left: 0
|
|
46
|
+
}]);
|
|
47
|
+
export const nextButtonStyles = css([buttonContainerStyles, {
|
|
48
|
+
right: 0
|
|
49
|
+
}]);
|
package/dist/es2019/version.json
CHANGED
|
@@ -23,7 +23,13 @@ export function usePlugins(state, activeTab, plugins) {
|
|
|
23
23
|
pluginState = _usePluginReducer2[0],
|
|
24
24
|
dispatch = _usePluginReducer2[1];
|
|
25
25
|
|
|
26
|
-
var activePlugin = plugins === null || plugins === void 0 ? void 0 : plugins[activeTab];
|
|
26
|
+
var activePlugin = plugins === null || plugins === void 0 ? void 0 : plugins[activeTab]; // This useEffect block must be called before any other to ensure onActivation is fired at before resolve
|
|
27
|
+
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
if (activePlugin && activePlugin.UNSAFE_onActivation) {
|
|
30
|
+
activePlugin.UNSAFE_onActivation();
|
|
31
|
+
}
|
|
32
|
+
}, [activePlugin]);
|
|
27
33
|
useEffect(function () {
|
|
28
34
|
if (!activePlugin) {
|
|
29
35
|
return;
|
|
@@ -28,6 +28,7 @@ import TextInput, { testIds as textFieldTestIds } from './text-input';
|
|
|
28
28
|
import { rootContainerStyles, searchIconStyles, tabsWrapperStyles, flexColumnStyles, formFooterMargin } from './styled';
|
|
29
29
|
import { browser } from './browser';
|
|
30
30
|
import Announcer from './announcer';
|
|
31
|
+
import ScrollingTabList from '../scrolling-tabs';
|
|
31
32
|
import LinkSearchList, { testIds as listTestIds } from './link-search-list';
|
|
32
33
|
import LinkSearchError, { testIds as searchErrorTestIds } from './link-search-error';
|
|
33
34
|
import FormFooter, { testIds as formFooterTestIds } from './form-footer';
|
|
@@ -92,7 +93,8 @@ function LinkPicker(_ref) {
|
|
|
92
93
|
onContentResize = _ref.onContentResize,
|
|
93
94
|
plugins = _ref.plugins,
|
|
94
95
|
initUrl = _ref.url,
|
|
95
|
-
initDisplayText = _ref.displayText
|
|
96
|
+
initDisplayText = _ref.displayText,
|
|
97
|
+
featureFlags = _ref.featureFlags;
|
|
96
98
|
|
|
97
99
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
98
100
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
@@ -303,6 +305,12 @@ function LinkPicker(_ref) {
|
|
|
303
305
|
size: "medium",
|
|
304
306
|
label: ''
|
|
305
307
|
}));
|
|
308
|
+
var tabList = jsx(TabList, null, tabs.map(function (tab) {
|
|
309
|
+
return jsx(Tab, {
|
|
310
|
+
key: tab.tabTitle,
|
|
311
|
+
testId: testIds.tabItem
|
|
312
|
+
}, tab.tabTitle);
|
|
313
|
+
}));
|
|
306
314
|
return jsx("form", {
|
|
307
315
|
"data-testid": testIds.linkPicker,
|
|
308
316
|
css: rootContainerStyles,
|
|
@@ -353,12 +361,7 @@ function LinkPicker(_ref) {
|
|
|
353
361
|
testId: testIds.tabList,
|
|
354
362
|
selected: activeTab,
|
|
355
363
|
onChange: handleTabChange
|
|
356
|
-
}, jsx(
|
|
357
|
-
return jsx(Tab, {
|
|
358
|
-
key: tab.tabTitle,
|
|
359
|
-
testId: testIds.tabItem
|
|
360
|
-
}, tab.tabTitle);
|
|
361
|
-
}))), jsx(TrackTabViewed, {
|
|
364
|
+
}, featureFlags !== null && featureFlags !== void 0 && featureFlags.scrollingTabs ? jsx(ScrollingTabList, null, tabList) : tabList), jsx(TrackTabViewed, {
|
|
362
365
|
activeTab: activeTab
|
|
363
366
|
})), jsx("div", _extends({
|
|
364
367
|
css: flexColumnStyles
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
|
|
4
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
5
|
+
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
9
|
+
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
import React, { useRef, useMemo, useState, useCallback } from 'react';
|
|
12
|
+
import { jsx } from '@emotion/react';
|
|
13
|
+
import Button from '@atlaskit/button';
|
|
14
|
+
import ChevronLeftIcon from '@atlaskit/icon/glyph/chevron-left';
|
|
15
|
+
import ChevronRightIcon from '@atlaskit/icon/glyph/chevron-right';
|
|
16
|
+
import { scrollBack, scrollForward, calculateConditionalButtons, getTabList, createGhost } from './scrolling-tabs';
|
|
17
|
+
import { containerStyles, scrollingContainerStyles, nextButtonStyles, backButtonStyles } from './styles';
|
|
18
|
+
|
|
19
|
+
function isTouchDevice() {
|
|
20
|
+
return 'ontouchstart' in window || // eslint-disable-next-line compat/compat
|
|
21
|
+
navigator.maxTouchPoints > 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var initialConditionalButtonsState = {
|
|
25
|
+
back: false,
|
|
26
|
+
forward: false
|
|
27
|
+
};
|
|
28
|
+
export var ScrollingTabList = function ScrollingTabList(props) {
|
|
29
|
+
var ref = useRef(null);
|
|
30
|
+
|
|
31
|
+
var _useState = useState(initialConditionalButtonsState),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
conditionalButtons = _useState2[0],
|
|
34
|
+
setConditionalButtons = _useState2[1];
|
|
35
|
+
|
|
36
|
+
var ghost = useMemo(function () {
|
|
37
|
+
return createGhost();
|
|
38
|
+
}, []);
|
|
39
|
+
var onTabClick = useCallback(function (e) {
|
|
40
|
+
var target = e.currentTarget;
|
|
41
|
+
|
|
42
|
+
if (target) {
|
|
43
|
+
target.scrollIntoView({
|
|
44
|
+
behavior: 'smooth'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, []);
|
|
48
|
+
React.useLayoutEffect(function () {
|
|
49
|
+
var container = ref.current;
|
|
50
|
+
var scrollingContainer;
|
|
51
|
+
var tabs;
|
|
52
|
+
|
|
53
|
+
var handleConditionalButtonsChange = function handleConditionalButtonsChange() {
|
|
54
|
+
var buttons = calculateConditionalButtons(scrollingContainer, isTouchDevice());
|
|
55
|
+
setConditionalButtons(buttons);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var observerCallback = function observerCallback(mutationList) {
|
|
59
|
+
var tablist = getTabList(ref);
|
|
60
|
+
|
|
61
|
+
var _iterator = _createForOfIteratorHelper(mutationList),
|
|
62
|
+
_step;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
66
|
+
var mutation = _step.value;
|
|
67
|
+
|
|
68
|
+
if (mutation.type === 'childList') {
|
|
69
|
+
var addedNodes = Array.from(mutation.addedNodes);
|
|
70
|
+
var found = addedNodes.find(function (node) {
|
|
71
|
+
return node.getAttribute('role') === 'tab';
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (found && tablist) {
|
|
75
|
+
ghost.remove();
|
|
76
|
+
|
|
77
|
+
var _tabs = Array.from(tablist.children);
|
|
78
|
+
|
|
79
|
+
_tabs.forEach(function (tab) {
|
|
80
|
+
tab.removeEventListener('click', onTabClick);
|
|
81
|
+
tab.addEventListener('click', onTabClick);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
tablist.appendChild(ghost);
|
|
85
|
+
handleConditionalButtonsChange();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
_iterator.e(err);
|
|
91
|
+
} finally {
|
|
92
|
+
_iterator.f();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var observer = new MutationObserver(observerCallback);
|
|
97
|
+
|
|
98
|
+
if (container) {
|
|
99
|
+
var tablist = getTabList(ref);
|
|
100
|
+
scrollingContainer = tablist === null || tablist === void 0 ? void 0 : tablist.parentElement;
|
|
101
|
+
observer.observe(container, {
|
|
102
|
+
attributes: false,
|
|
103
|
+
childList: true,
|
|
104
|
+
subtree: true
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (scrollingContainer instanceof HTMLElement && tablist) {
|
|
108
|
+
tablist.appendChild(ghost);
|
|
109
|
+
tabs = Array.from(tablist.children);
|
|
110
|
+
tabs.forEach(function (tab) {
|
|
111
|
+
return tab.addEventListener('click', onTabClick);
|
|
112
|
+
});
|
|
113
|
+
handleConditionalButtonsChange();
|
|
114
|
+
scrollingContainer.addEventListener('scroll', handleConditionalButtonsChange);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return function () {
|
|
118
|
+
if (scrollingContainer) {
|
|
119
|
+
scrollingContainer.removeEventListener('scroll', handleConditionalButtonsChange);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (tabs.length) {
|
|
123
|
+
tabs.forEach(function (tab) {
|
|
124
|
+
return tab.removeEventListener('click', onTabClick);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}, [onTabClick, ghost, ref]);
|
|
130
|
+
var buttonProps = {
|
|
131
|
+
appearance: 'subtle',
|
|
132
|
+
spacing: 'none'
|
|
133
|
+
};
|
|
134
|
+
return jsx("div", {
|
|
135
|
+
css: containerStyles,
|
|
136
|
+
ref: ref,
|
|
137
|
+
"data-testid": "scrolling-tabs"
|
|
138
|
+
}, conditionalButtons.back && jsx("div", {
|
|
139
|
+
className: "back",
|
|
140
|
+
css: backButtonStyles
|
|
141
|
+
}, jsx(Button, _extends({
|
|
142
|
+
"data-test-id": "back"
|
|
143
|
+
}, buttonProps, {
|
|
144
|
+
iconBefore: jsx(ChevronLeftIcon, {
|
|
145
|
+
label: "back"
|
|
146
|
+
}),
|
|
147
|
+
onClick: function onClick() {
|
|
148
|
+
return scrollBack(ref);
|
|
149
|
+
}
|
|
150
|
+
}))), jsx("div", {
|
|
151
|
+
css: scrollingContainerStyles
|
|
152
|
+
}, props.children), conditionalButtons.forward && jsx("div", {
|
|
153
|
+
css: nextButtonStyles
|
|
154
|
+
}, jsx(Button, _extends({
|
|
155
|
+
"data-test-id": "forward"
|
|
156
|
+
}, buttonProps, {
|
|
157
|
+
iconBefore: jsx(ChevronRightIcon, {
|
|
158
|
+
label: "forward"
|
|
159
|
+
}),
|
|
160
|
+
onClick: function onClick() {
|
|
161
|
+
return scrollForward(ref);
|
|
162
|
+
}
|
|
163
|
+
}))));
|
|
164
|
+
};
|
|
165
|
+
export default ScrollingTabList;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
var BUTTON_SIZE = 24;
|
|
3
|
+
var GUTTER = 48;
|
|
4
|
+
var GHOST_WIDTH = 342 - GUTTER - 40;
|
|
5
|
+
export var scrollBack = function scrollBack(ref) {
|
|
6
|
+
moveTabsScroll(ref, findPrevious);
|
|
7
|
+
};
|
|
8
|
+
export var scrollForward = function scrollForward(ref) {
|
|
9
|
+
moveTabsScroll(ref, findNext);
|
|
10
|
+
};
|
|
11
|
+
export var calculateConditionalButtons = function calculateConditionalButtons(container, hideButtons) {
|
|
12
|
+
var initialState = {
|
|
13
|
+
back: false,
|
|
14
|
+
forward: false
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
if (!container || hideButtons) {
|
|
18
|
+
return initialState;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var maxScrollValue = container.scrollWidth - container.clientWidth;
|
|
22
|
+
return {
|
|
23
|
+
back: container.scrollLeft > 0,
|
|
24
|
+
forward: container.scrollLeft < maxScrollValue - GHOST_WIDTH
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export var createGhost = function createGhost() {
|
|
28
|
+
var ghost = document.createElement('div');
|
|
29
|
+
ghost.setAttribute('id', 'scrolling-tabs-ghost');
|
|
30
|
+
ghost.style.minWidth = "".concat(GHOST_WIDTH, "px");
|
|
31
|
+
ghost.style.pointerEvents = 'none';
|
|
32
|
+
return ghost;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var moveTabsScroll = function moveTabsScroll(ref, findFn) {
|
|
36
|
+
var container = getContainer(ref);
|
|
37
|
+
|
|
38
|
+
if (container) {
|
|
39
|
+
var tablist = container.children[0];
|
|
40
|
+
|
|
41
|
+
var _tabs = _toConsumableArray(tablist.children);
|
|
42
|
+
|
|
43
|
+
if (_tabs.length > 0) {
|
|
44
|
+
var target = findFn(container, _tabs);
|
|
45
|
+
|
|
46
|
+
if (target) {
|
|
47
|
+
var left = container.scrollLeft + target.getBoundingClientRect().left - container.getBoundingClientRect().left - BUTTON_SIZE;
|
|
48
|
+
scrollTo(container, left);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var scrollTo = function scrollTo(container, left) {
|
|
55
|
+
container.scrollTo({
|
|
56
|
+
left: left
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export var getTabList = function getTabList(ref) {
|
|
61
|
+
var _ref$current;
|
|
62
|
+
|
|
63
|
+
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector('[role="tablist"]');
|
|
64
|
+
};
|
|
65
|
+
export var getContainer = function getContainer(ref) {
|
|
66
|
+
var _getTabList;
|
|
67
|
+
|
|
68
|
+
return (_getTabList = getTabList(ref)) === null || _getTabList === void 0 ? void 0 : _getTabList.parentElement;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var findPrevious = function findPrevious(container, tabs) {
|
|
72
|
+
var previousTabs = tabs.filter(function (tab) {
|
|
73
|
+
var _ref = [container.getBoundingClientRect(), tab.getBoundingClientRect()],
|
|
74
|
+
containerRect = _ref[0],
|
|
75
|
+
tabRect = _ref[1];
|
|
76
|
+
var containerArea = containerRect.left + container.scrollLeft - GUTTER,
|
|
77
|
+
tabArea = container.scrollLeft + tabRect.left + tabRect.width;
|
|
78
|
+
return containerArea > tabArea;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (previousTabs.length < 3) {
|
|
82
|
+
return previousTabs[0];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return previousTabs[previousTabs.length - 1];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
var findNext = function findNext(container, tabs) {
|
|
89
|
+
var containerRect = container.getBoundingClientRect();
|
|
90
|
+
return tabs.find(function (tab) {
|
|
91
|
+
var tabRect = tab.getBoundingClientRect();
|
|
92
|
+
var containerArea = container.clientWidth + containerRect.left - GUTTER,
|
|
93
|
+
tabArea = tabRect.left + tabRect.width;
|
|
94
|
+
return containerArea < tabArea;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { css } from '@emotion/react';
|
|
2
|
+
import { token } from '@atlaskit/tokens';
|
|
3
|
+
import { N0, N30 } from '@atlaskit/theme/colors';
|
|
4
|
+
export var scrollingContainerStyles = css({
|
|
5
|
+
overflowX: 'auto',
|
|
6
|
+
scrollBehavior: 'smooth',
|
|
7
|
+
scrollPadding: '0 24px',
|
|
8
|
+
scrollbarWidth: 'none',
|
|
9
|
+
'&::-webkit-scrollbar': {
|
|
10
|
+
display: 'none'
|
|
11
|
+
},
|
|
12
|
+
'&::before': {
|
|
13
|
+
content: '""',
|
|
14
|
+
borderRadius: 2,
|
|
15
|
+
bottom: 0,
|
|
16
|
+
margin: 0,
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
width: 'inherit',
|
|
19
|
+
left: 8,
|
|
20
|
+
right: 8,
|
|
21
|
+
height: 2,
|
|
22
|
+
backgroundColor: token('color.border', N30)
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export var containerStyles = css({
|
|
26
|
+
position: 'relative',
|
|
27
|
+
'[role="tablist"]': {
|
|
28
|
+
'&::before': {
|
|
29
|
+
display: 'none'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
// Overrides Atlaskit tabs styles to stop overflowing with ellipsis
|
|
33
|
+
'[role="tab"]': {
|
|
34
|
+
overflow: 'unset !important',
|
|
35
|
+
textOverflow: 'unset !important'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export var buttonContainerStyles = css({
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
top: 4,
|
|
41
|
+
zIndex: 999,
|
|
42
|
+
backgroundColor: token('elevation.surface', N0)
|
|
43
|
+
});
|
|
44
|
+
export var backButtonStyles = css([buttonContainerStyles, {
|
|
45
|
+
left: 0
|
|
46
|
+
}]);
|
|
47
|
+
export var nextButtonStyles = css([buttonContainerStyles, {
|
|
48
|
+
right: 0
|
|
49
|
+
}]);
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export interface ConditionalButtons {
|
|
3
|
+
back: boolean;
|
|
4
|
+
forward: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const scrollBack: (ref: RefObject<HTMLDivElement>) => void;
|
|
7
|
+
export declare const scrollForward: (ref: RefObject<HTMLDivElement>) => void;
|
|
8
|
+
export declare const calculateConditionalButtons: (container: HTMLElement | null | undefined, hideButtons: boolean) => ConditionalButtons;
|
|
9
|
+
export declare const createGhost: () => HTMLDivElement;
|
|
10
|
+
export declare const getTabList: (ref: RefObject<HTMLDivElement>) => Element | null | undefined;
|
|
11
|
+
export declare const getContainer: (ref: RefObject<HTMLDivElement>) => HTMLElement | null | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SerializedStyles } from '@emotion/react';
|
|
2
|
+
export declare const scrollingContainerStyles: SerializedStyles;
|
|
3
|
+
export declare const containerStyles: SerializedStyles;
|
|
4
|
+
export declare const buttonContainerStyles: SerializedStyles;
|
|
5
|
+
export declare const backButtonStyles: SerializedStyles;
|
|
6
|
+
export declare const nextButtonStyles: SerializedStyles;
|
package/dist/types/ui/types.d.ts
CHANGED
|
@@ -53,5 +53,7 @@ export interface LinkPickerPlugin {
|
|
|
53
53
|
/** The data source that provides all results provided by the plugin */
|
|
54
54
|
source?: string;
|
|
55
55
|
};
|
|
56
|
+
/** Callback for plugin activation */
|
|
57
|
+
UNSAFE_onActivation?: () => void;
|
|
56
58
|
}
|
|
57
59
|
export declare type LinkPickerPluginErrorFallback = (error: unknown, retry: () => void) => ReactNode;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export interface ConditionalButtons {
|
|
3
|
+
back: boolean;
|
|
4
|
+
forward: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const scrollBack: (ref: RefObject<HTMLDivElement>) => void;
|
|
7
|
+
export declare const scrollForward: (ref: RefObject<HTMLDivElement>) => void;
|
|
8
|
+
export declare const calculateConditionalButtons: (container: HTMLElement | null | undefined, hideButtons: boolean) => ConditionalButtons;
|
|
9
|
+
export declare const createGhost: () => HTMLDivElement;
|
|
10
|
+
export declare const getTabList: (ref: RefObject<HTMLDivElement>) => Element | null | undefined;
|
|
11
|
+
export declare const getContainer: (ref: RefObject<HTMLDivElement>) => HTMLElement | null | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SerializedStyles } from '@emotion/react';
|
|
2
|
+
export declare const scrollingContainerStyles: SerializedStyles;
|
|
3
|
+
export declare const containerStyles: SerializedStyles;
|
|
4
|
+
export declare const buttonContainerStyles: SerializedStyles;
|
|
5
|
+
export declare const backButtonStyles: SerializedStyles;
|
|
6
|
+
export declare const nextButtonStyles: SerializedStyles;
|
|
@@ -53,5 +53,7 @@ export interface LinkPickerPlugin {
|
|
|
53
53
|
/** The data source that provides all results provided by the plugin */
|
|
54
54
|
source?: string;
|
|
55
55
|
};
|
|
56
|
+
/** Callback for plugin activation */
|
|
57
|
+
UNSAFE_onActivation?: () => void;
|
|
56
58
|
}
|
|
57
59
|
export declare type LinkPickerPluginErrorFallback = (error: unknown, retry: () => void) => ReactNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Standalone link picker",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@atlaskit/analytics-next": "^8.3.1",
|
|
43
|
-
"@atlaskit/button": "^16.
|
|
43
|
+
"@atlaskit/button": "^16.4.0",
|
|
44
44
|
"@atlaskit/empty-state": "^7.4.0",
|
|
45
|
-
"@atlaskit/form": "^8.
|
|
45
|
+
"@atlaskit/form": "^8.7.0",
|
|
46
46
|
"@atlaskit/frontend-utilities": "^2.0.0",
|
|
47
47
|
"@atlaskit/icon": "^21.11.0",
|
|
48
|
-
"@atlaskit/spinner": "^15.
|
|
48
|
+
"@atlaskit/spinner": "^15.2.0",
|
|
49
49
|
"@atlaskit/tabs": "^13.3.0",
|
|
50
50
|
"@atlaskit/textfield": "^5.3.0",
|
|
51
51
|
"@atlaskit/theme": "^12.2.0",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"@atlaskit/visual-regression": "*",
|
|
81
81
|
"@atlaskit/webdriver-runner": "*",
|
|
82
82
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
83
|
-
"@atlassian/link-picker-atlassian-plugin": "^
|
|
84
|
-
"@atlassian/link-picker-plugins": "^
|
|
83
|
+
"@atlassian/link-picker-atlassian-plugin": "^23.0.0",
|
|
84
|
+
"@atlassian/link-picker-plugins": "^11.0.0",
|
|
85
85
|
"@atlassian/recent-work-client": "^1.6.0",
|
|
86
86
|
"@atlassian/search-provider": "^2.3.0",
|
|
87
87
|
"@testing-library/dom": "^8.17.1",
|
package/report.api.md
CHANGED
|
@@ -41,6 +41,7 @@ export interface LinkPickerPlugin {
|
|
|
41
41
|
) => AsyncGenerator<ResolveResult, ResolveResult> | Promise<ResolveResult>;
|
|
42
42
|
tabKey?: string;
|
|
43
43
|
tabTitle?: string;
|
|
44
|
+
UNSAFE_onActivation?: () => void;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// @public (undocumented)
|
|
@@ -57,6 +58,8 @@ export interface LinkPickerProps {
|
|
|
57
58
|
}
|
|
58
59
|
>;
|
|
59
60
|
displayText?: null | string;
|
|
61
|
+
// (undocumented)
|
|
62
|
+
featureFlags?: Record<string, unknown>;
|
|
60
63
|
onCancel: () => void;
|
|
61
64
|
onContentResize?: () => void;
|
|
62
65
|
onSubmit: (
|