@atlaskit/side-navigation 1.3.0 → 1.4.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/codemods/helpers/generic.tsx +10 -12
- package/dist/cjs/components/LoadingItems/index.js +13 -9
- package/dist/cjs/components/NavigationFooter/index.js +5 -5
- package/dist/cjs/components/NavigationHeader/index.js +8 -7
- package/dist/cjs/components/NestableNavigationContent/index.js +25 -15
- package/dist/cjs/components/NestingItem/index.js +19 -10
- package/dist/cjs/components/SideNavigation/index.js +13 -12
- package/dist/cjs/components/utils/hooks.js +48 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/LoadingItems/index.js +14 -10
- package/dist/es2019/components/NavigationFooter/index.js +6 -6
- package/dist/es2019/components/NavigationHeader/index.js +9 -8
- package/dist/es2019/components/NestableNavigationContent/index.js +24 -16
- package/dist/es2019/components/NestingItem/index.js +19 -12
- package/dist/es2019/components/SideNavigation/index.js +14 -13
- package/dist/es2019/components/utils/hooks.js +34 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/LoadingItems/index.js +14 -10
- package/dist/esm/components/NavigationFooter/index.js +6 -6
- package/dist/esm/components/NavigationHeader/index.js +9 -8
- package/dist/esm/components/NestableNavigationContent/index.js +25 -16
- package/dist/esm/components/NestingItem/index.js +19 -12
- package/dist/esm/components/SideNavigation/index.js +14 -13
- package/dist/esm/components/utils/hooks.js +34 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/NestableNavigationContent/context.d.ts +2 -1
- package/dist/types/components/NestableNavigationContent/index.d.ts +5 -0
- package/dist/types/components/utils/hooks.d.ts +5 -0
- package/package.json +6 -12
- package/report.api.md +92 -375
- package/dist/types-ts4.0/common/constants.d.ts +0 -2
- package/dist/types-ts4.0/common/styles.d.ts +0 -12
- package/dist/types-ts4.0/components/Footer/index.d.ts +0 -11
- package/dist/types-ts4.0/components/Header/index.d.ts +0 -50
- package/dist/types-ts4.0/components/Item/button-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/custom-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/go-back-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/index.d.ts +0 -10
- package/dist/types-ts4.0/components/Item/link-item.d.ts +0 -16
- package/dist/types-ts4.0/components/Item/skeleton-item.d.ts +0 -13
- package/dist/types-ts4.0/components/LoadingItems/index.d.ts +0 -35
- package/dist/types-ts4.0/components/NavigationContent/index.d.ts +0 -25
- package/dist/types-ts4.0/components/NavigationContent/styles.d.ts +0 -91
- package/dist/types-ts4.0/components/NavigationFooter/index.d.ts +0 -16
- package/dist/types-ts4.0/components/NavigationHeader/index.d.ts +0 -16
- package/dist/types-ts4.0/components/NestableNavigationContent/context.d.ts +0 -23
- package/dist/types-ts4.0/components/NestableNavigationContent/index.d.ts +0 -69
- package/dist/types-ts4.0/components/NestableNavigationContent/nesting-motion.d.ts +0 -22
- package/dist/types-ts4.0/components/NestingItem/hack-for-ert.d.ts +0 -2
- package/dist/types-ts4.0/components/NestingItem/index.d.ts +0 -91
- package/dist/types-ts4.0/components/NestingItem/styles.d.ts +0 -28
- package/dist/types-ts4.0/components/Section/heading-item.d.ts +0 -11
- package/dist/types-ts4.0/components/Section/index.d.ts +0 -6
- package/dist/types-ts4.0/components/Section/section.d.ts +0 -34
- package/dist/types-ts4.0/components/Section/skeleton-heading-item.d.ts +0 -12
- package/dist/types-ts4.0/components/SideNavigation/index.d.ts +0 -32
- package/dist/types-ts4.0/components/index.d.ts +0 -22
- package/dist/types-ts4.0/index.d.ts +0 -4
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import React, { Fragment, useCallback, useMemo, useState } from 'react';
|
|
5
|
-
import { jsx } from '@emotion/react';
|
|
5
|
+
import { css, jsx } from '@emotion/react';
|
|
6
6
|
import RightArrow from '@atlaskit/icon/glyph/arrow-right-circle';
|
|
7
7
|
import { N10 } from '@atlaskit/theme/colors';
|
|
8
8
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
@@ -10,13 +10,21 @@ import { overrideStyleFunction } from '../../common/styles';
|
|
|
10
10
|
import { ButtonItem, CustomItem, NavigationContent } from '../index';
|
|
11
11
|
import { ROOT_ID } from '../NestableNavigationContent';
|
|
12
12
|
import { NestedContext, useNestedContext } from '../NestableNavigationContent/context';
|
|
13
|
+
import { useChildIdsEffect } from '../utils/hooks';
|
|
13
14
|
import { nestingItemStyle } from './styles';
|
|
14
|
-
|
|
15
|
+
const nestingItemStyles = css({
|
|
16
|
+
marginRight: gridSize(),
|
|
17
|
+
marginLeft: gridSize(),
|
|
18
|
+
// This padding bottom needs to match the section margin inside @atlaskit/menu.
|
|
19
|
+
paddingTop: gridSize() * 0.75,
|
|
20
|
+
paddingBottom: gridSize() * 0.75
|
|
21
|
+
});
|
|
15
22
|
/**
|
|
16
23
|
* NestingItem will render itself differently depending in what context it is rendered in.
|
|
17
24
|
* When not open - it will render itself as an item.
|
|
18
25
|
* When open - it will render its children.
|
|
19
26
|
*/
|
|
27
|
+
|
|
20
28
|
const NestingItem = props => {
|
|
21
29
|
const {
|
|
22
30
|
children,
|
|
@@ -35,7 +43,8 @@ const NestingItem = props => {
|
|
|
35
43
|
onNest,
|
|
36
44
|
onUnNest,
|
|
37
45
|
backButton: contextualBackButton,
|
|
38
|
-
stack
|
|
46
|
+
stack,
|
|
47
|
+
childIds
|
|
39
48
|
} = useNestedContext();
|
|
40
49
|
const mergedStyles = overrideStyleFunction(nestingItemStyle, cssFn);
|
|
41
50
|
const [isInteracted, setIsInteracted] = useState(false);
|
|
@@ -49,8 +58,12 @@ const NestingItem = props => {
|
|
|
49
58
|
onNest,
|
|
50
59
|
onUnNest,
|
|
51
60
|
backButton,
|
|
52
|
-
parentId: id
|
|
53
|
-
|
|
61
|
+
parentId: id,
|
|
62
|
+
childIds
|
|
63
|
+
}), // childIds shouldn't change as it's a ref
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
[onNest, onUnNest, backButton, stack, id, currentStackId]);
|
|
66
|
+
useChildIdsEffect(childIds, id);
|
|
54
67
|
|
|
55
68
|
const isNormalClick = e => !(e.button || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
56
69
|
/**
|
|
@@ -79,13 +92,7 @@ const NestingItem = props => {
|
|
|
79
92
|
return jsx(NestedContext.Provider, {
|
|
80
93
|
value: context
|
|
81
94
|
}, stack.length >= 1 && jsx("div", {
|
|
82
|
-
css:
|
|
83
|
-
marginLeft: gridSize(),
|
|
84
|
-
marginRight: gridSize(),
|
|
85
|
-
// This padding bottom needs to match the section margin inside @atlaskit/menu.
|
|
86
|
-
paddingTop: gridSize() * 0.75,
|
|
87
|
-
paddingBottom: gridSize() * 0.75
|
|
88
|
-
}
|
|
95
|
+
css: nestingItemStyles
|
|
89
96
|
}, backButton), jsx(NavigationContent, {
|
|
90
97
|
testId: testId,
|
|
91
98
|
showTopScrollIndicator: stack.length >= 1
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
|
-
import { jsx } from '@emotion/react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
4
|
import { N10, N500 } from '@atlaskit/theme/colors';
|
|
5
5
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
6
|
-
|
|
6
|
+
const sideNavStyles = css({
|
|
7
|
+
display: 'flex',
|
|
8
|
+
width: '100%',
|
|
9
|
+
minWidth: gridSize() * 30,
|
|
10
|
+
height: '100%',
|
|
11
|
+
position: 'relative',
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
backgroundColor: `var(--ds-surface, ${N10})`,
|
|
14
|
+
color: `var(--ds-text-subtle, ${N500})`,
|
|
15
|
+
overflow: 'hidden'
|
|
16
|
+
});
|
|
7
17
|
/**
|
|
8
18
|
* __Side navigation__
|
|
9
19
|
*
|
|
@@ -13,6 +23,7 @@ import { gridSize } from '@atlaskit/theme/constants';
|
|
|
13
23
|
* - [Code](https://atlassian.design/components/side-navigation/code)
|
|
14
24
|
* - [Usage](https://atlassian.design/components/side-navigation/usage)
|
|
15
25
|
*/
|
|
26
|
+
|
|
16
27
|
const SideNavigation = /*#__PURE__*/forwardRef((props, ref) => {
|
|
17
28
|
const {
|
|
18
29
|
children,
|
|
@@ -23,17 +34,7 @@ const SideNavigation = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
23
34
|
ref: ref,
|
|
24
35
|
"data-testid": testId,
|
|
25
36
|
"aria-label": label,
|
|
26
|
-
css:
|
|
27
|
-
width: '100%',
|
|
28
|
-
height: '100%',
|
|
29
|
-
color: `var(--ds-text-subtle, ${N500})`,
|
|
30
|
-
minWidth: gridSize() * 30,
|
|
31
|
-
backgroundColor: `var(--ds-surface, ${N10})`,
|
|
32
|
-
position: 'relative',
|
|
33
|
-
display: 'flex',
|
|
34
|
-
flexDirection: 'column',
|
|
35
|
-
overflow: 'hidden'
|
|
36
|
-
}
|
|
37
|
+
css: sideNavStyles
|
|
37
38
|
}, children);
|
|
38
39
|
});
|
|
39
40
|
export default SideNavigation;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ROOT_ID } from '../NestableNavigationContent';
|
|
3
|
+
export const useChildIds = (currentStackId, committedStack, onUnknownNest) => {
|
|
4
|
+
const childIdsRef = useRef(new Set());
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
// we are holding navigation item IDs in childIdsRef
|
|
7
|
+
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
|
|
8
|
+
if (currentStackId === ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
onUnknownNest(committedStack || [currentStackId]);
|
|
13
|
+
}, [currentStackId, committedStack, onUnknownNest]);
|
|
14
|
+
return {
|
|
15
|
+
childIdsRef
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const useChildIdsEffect = (childIds, id) => {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!childIds || !childIds.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!childIds.current.has(id)) {
|
|
25
|
+
childIds.current.add(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
childIds.current.delete(id);
|
|
31
|
+
}; // childIds shouldn't change as it's a ref
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [id]);
|
|
34
|
+
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import { jsx } from '@emotion/react';
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
5
5
|
import { ExitingPersistence, FadeIn, mediumDurationMs } from '@atlaskit/motion';
|
|
6
6
|
import { useShouldNestedElementRender } from '../NestableNavigationContent/context';
|
|
7
|
-
|
|
7
|
+
var baseMotionStyles = css({
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
zIndex: 1,
|
|
10
|
+
top: 0,
|
|
11
|
+
right: 0,
|
|
12
|
+
left: 0
|
|
13
|
+
});
|
|
14
|
+
var enteringStyles = css({
|
|
15
|
+
position: 'static',
|
|
16
|
+
zIndex: 2
|
|
17
|
+
});
|
|
8
18
|
/**
|
|
9
19
|
* __Loading items__
|
|
10
20
|
*
|
|
11
21
|
* Loading items conditionally render based on the useShouldNestedElementRender() hook.
|
|
12
22
|
*/
|
|
23
|
+
|
|
13
24
|
var LoadingItems = function LoadingItems(_ref) {
|
|
14
25
|
var children = _ref.children,
|
|
15
26
|
isLoading = _ref.isLoading,
|
|
@@ -29,14 +40,7 @@ var LoadingItems = function LoadingItems(_ref) {
|
|
|
29
40
|
}, function (motion, state) {
|
|
30
41
|
return jsx("span", _extends({}, motion, {
|
|
31
42
|
"data-testid": testId && "".concat(testId, "--").concat(state),
|
|
32
|
-
css:
|
|
33
|
-
// Used to have the exiting section appear above the entering one.
|
|
34
|
-
position: state === 'entering' ? undefined : 'absolute',
|
|
35
|
-
zIndex: state === 'entering' ? 2 : 1,
|
|
36
|
-
top: 0,
|
|
37
|
-
left: 0,
|
|
38
|
-
right: 0
|
|
39
|
-
}
|
|
43
|
+
css: [baseMotionStyles, state === 'entering' && enteringStyles]
|
|
40
44
|
}), isLoading ? fallback : children);
|
|
41
45
|
}));
|
|
42
46
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react';
|
|
2
|
+
import { css, jsx } from '@emotion/react';
|
|
3
3
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
4
|
-
var
|
|
5
|
-
position: 'relative',
|
|
4
|
+
var footerStyles = css({
|
|
6
5
|
padding: gridSize(),
|
|
7
|
-
paddingBottom: gridSize() * 1.75
|
|
8
|
-
|
|
6
|
+
paddingBottom: gridSize() * 1.75,
|
|
7
|
+
position: 'relative'
|
|
8
|
+
});
|
|
9
9
|
/**
|
|
10
10
|
* __Navigation footer__
|
|
11
11
|
*
|
|
@@ -18,7 +18,7 @@ var footerCSS = {
|
|
|
18
18
|
var NavigationFooter = function NavigationFooter(_ref) {
|
|
19
19
|
var children = _ref.children;
|
|
20
20
|
return jsx("div", {
|
|
21
|
-
css:
|
|
21
|
+
css: footerStyles
|
|
22
22
|
}, children);
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react';
|
|
2
|
+
import { css, jsx } from '@emotion/react';
|
|
3
3
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
4
|
-
|
|
4
|
+
var navigationHeaderStyles = css({
|
|
5
|
+
paddingTop: gridSize() * 3,
|
|
6
|
+
paddingRight: gridSize(),
|
|
7
|
+
paddingBottom: gridSize(),
|
|
8
|
+
paddingLeft: gridSize()
|
|
9
|
+
});
|
|
5
10
|
/**
|
|
6
11
|
* __Navigation header__
|
|
7
12
|
*
|
|
@@ -10,16 +15,12 @@ import { gridSize } from '@atlaskit/theme/constants';
|
|
|
10
15
|
* - [Examples](https://atlassian.design/components/side-navigation/examples#header-and-footer)
|
|
11
16
|
* - [Code](https://atlassian.design/components/side-navigation/code)
|
|
12
17
|
*/
|
|
18
|
+
|
|
13
19
|
var NavigationHeader = function NavigationHeader(props) {
|
|
14
20
|
var children = props.children;
|
|
15
21
|
return jsx("div", {
|
|
16
22
|
"data-navheader": true,
|
|
17
|
-
css:
|
|
18
|
-
paddingTop: gridSize() * 3,
|
|
19
|
-
paddingBottom: gridSize(),
|
|
20
|
-
paddingLeft: gridSize(),
|
|
21
|
-
paddingRight: gridSize()
|
|
22
|
-
}
|
|
23
|
+
css: navigationHeaderStyles
|
|
23
24
|
}, children);
|
|
24
25
|
};
|
|
25
26
|
|
|
@@ -3,15 +3,27 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
|
|
4
4
|
/** @jsx jsx */
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
-
import { jsx } from '@emotion/react';
|
|
6
|
+
import { css, jsx } from '@emotion/react';
|
|
7
7
|
import { ExitingPersistence } from '@atlaskit/motion';
|
|
8
8
|
import { GoBackItem as GoBackButton } from '../Item';
|
|
9
9
|
import { default as NestingItem } from '../NestingItem';
|
|
10
|
+
import { useChildIds } from '../utils/hooks';
|
|
10
11
|
import { NestedContext } from './context';
|
|
11
12
|
import { NestingMotion } from './nesting-motion'; // Named so ERT doesn't pick up the override name as a type.
|
|
12
13
|
|
|
13
14
|
export var ROOT_ID = 'ATLASKIT_NESTED_ROOT';
|
|
14
|
-
|
|
15
|
+
var nestableNavigationContentStyles = css({
|
|
16
|
+
height: '100%',
|
|
17
|
+
position: 'relative',
|
|
18
|
+
outline: 'none'
|
|
19
|
+
});
|
|
20
|
+
var nestingRootStyles = css({
|
|
21
|
+
display: 'flex',
|
|
22
|
+
width: '100%',
|
|
23
|
+
height: '100%',
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
flexDirection: 'column'
|
|
26
|
+
});
|
|
15
27
|
/**
|
|
16
28
|
* __Nestable navigation content__
|
|
17
29
|
*
|
|
@@ -20,6 +32,7 @@ export var ROOT_ID = 'ATLASKIT_NESTED_ROOT';
|
|
|
20
32
|
* - [Examples](https://atlassian.design/components/side-navigation/examples#nested-navigation)
|
|
21
33
|
* - [Code](https://atlassian.design/components/side-navigation/code)
|
|
22
34
|
*/
|
|
35
|
+
|
|
23
36
|
var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
24
37
|
var containerRef = useRef(null);
|
|
25
38
|
var children = props.children,
|
|
@@ -27,6 +40,7 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
27
40
|
overrides = props.overrides,
|
|
28
41
|
initialStack = props.initialStack,
|
|
29
42
|
onChange = props.onChange,
|
|
43
|
+
onUnknownNest = props.onUnknownNest,
|
|
30
44
|
stack = props.stack;
|
|
31
45
|
|
|
32
46
|
var _useState = useState(stack || initialStack || []),
|
|
@@ -46,6 +60,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
46
60
|
var renderGoBackItem = overrides && overrides.GoBackItem && overrides.GoBackItem.render ? overrides.GoBackItem.render : function (props) {
|
|
47
61
|
return jsx(GoBackButton, props, "Go back");
|
|
48
62
|
};
|
|
63
|
+
|
|
64
|
+
var _useChildIds = useChildIds(currentStackId, committedStack, onUnknownNest),
|
|
65
|
+
childIdsRef = _useChildIds.childIdsRef;
|
|
66
|
+
|
|
49
67
|
var onNestHandler = useCallback(function (layerId) {
|
|
50
68
|
onChange && onChange(committedStack.concat(layerId));
|
|
51
69
|
|
|
@@ -119,9 +137,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
119
137
|
stack: committedStack,
|
|
120
138
|
onNest: onNestHandler,
|
|
121
139
|
onUnNest: onUnNestHandler,
|
|
122
|
-
parentId: ROOT_ID
|
|
140
|
+
parentId: ROOT_ID,
|
|
141
|
+
childIds: childIdsRef
|
|
123
142
|
};
|
|
124
|
-
}, [
|
|
143
|
+
}, [currentStackId, backButton, committedStack, onNestHandler, onUnNestHandler, childIdsRef]);
|
|
125
144
|
|
|
126
145
|
var manageFocus = function manageFocus(event) {
|
|
127
146
|
var triggeredByKeyboard = event.nativeEvent.detail === 0;
|
|
@@ -133,11 +152,7 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
133
152
|
|
|
134
153
|
return jsx("div", {
|
|
135
154
|
"data-testid": testId,
|
|
136
|
-
css:
|
|
137
|
-
position: 'relative',
|
|
138
|
-
height: '100%',
|
|
139
|
-
outline: 'none'
|
|
140
|
-
},
|
|
155
|
+
css: nestableNavigationContentStyles,
|
|
141
156
|
ref: containerRef,
|
|
142
157
|
tabIndex: -1,
|
|
143
158
|
onClick: manageFocus
|
|
@@ -150,13 +165,7 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
150
165
|
testId: testId && "".concat(testId, "-anim")
|
|
151
166
|
}, function (motion) {
|
|
152
167
|
return jsx("div", _extends({
|
|
153
|
-
css:
|
|
154
|
-
position: 'absolute',
|
|
155
|
-
width: '100%',
|
|
156
|
-
height: '100%',
|
|
157
|
-
display: 'flex',
|
|
158
|
-
flexDirection: 'column'
|
|
159
|
-
}
|
|
168
|
+
css: nestingRootStyles
|
|
160
169
|
}, motion), jsx(NestedContext.Provider, {
|
|
161
170
|
// This provider is inside the NestingMotion to ensure it keeps a stale
|
|
162
171
|
// reference to the previous value.
|
|
@@ -11,7 +11,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
|
|
12
12
|
/** @jsx jsx */
|
|
13
13
|
import React, { Fragment, useCallback, useMemo, useState } from 'react';
|
|
14
|
-
import { jsx } from '@emotion/react';
|
|
14
|
+
import { css, jsx } from '@emotion/react';
|
|
15
15
|
import RightArrow from '@atlaskit/icon/glyph/arrow-right-circle';
|
|
16
16
|
import { N10 } from '@atlaskit/theme/colors';
|
|
17
17
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
@@ -19,13 +19,21 @@ import { overrideStyleFunction } from '../../common/styles';
|
|
|
19
19
|
import { ButtonItem, CustomItem, NavigationContent } from '../index';
|
|
20
20
|
import { ROOT_ID } from '../NestableNavigationContent';
|
|
21
21
|
import { NestedContext, useNestedContext } from '../NestableNavigationContent/context';
|
|
22
|
+
import { useChildIdsEffect } from '../utils/hooks';
|
|
22
23
|
import { nestingItemStyle } from './styles';
|
|
23
|
-
|
|
24
|
+
var nestingItemStyles = css({
|
|
25
|
+
marginRight: gridSize(),
|
|
26
|
+
marginLeft: gridSize(),
|
|
27
|
+
// This padding bottom needs to match the section margin inside @atlaskit/menu.
|
|
28
|
+
paddingTop: gridSize() * 0.75,
|
|
29
|
+
paddingBottom: gridSize() * 0.75
|
|
30
|
+
});
|
|
24
31
|
/**
|
|
25
32
|
* NestingItem will render itself differently depending in what context it is rendered in.
|
|
26
33
|
* When not open - it will render itself as an item.
|
|
27
34
|
* When open - it will render its children.
|
|
28
35
|
*/
|
|
36
|
+
|
|
29
37
|
var NestingItem = function NestingItem(props) {
|
|
30
38
|
var children = props.children,
|
|
31
39
|
iconAfter = props.iconAfter,
|
|
@@ -43,7 +51,8 @@ var NestingItem = function NestingItem(props) {
|
|
|
43
51
|
onNest = _useNestedContext.onNest,
|
|
44
52
|
onUnNest = _useNestedContext.onUnNest,
|
|
45
53
|
contextualBackButton = _useNestedContext.backButton,
|
|
46
|
-
stack = _useNestedContext.stack
|
|
54
|
+
stack = _useNestedContext.stack,
|
|
55
|
+
childIds = _useNestedContext.childIds;
|
|
47
56
|
|
|
48
57
|
var mergedStyles = overrideStyleFunction(nestingItemStyle, cssFn);
|
|
49
58
|
|
|
@@ -63,9 +72,13 @@ var NestingItem = function NestingItem(props) {
|
|
|
63
72
|
onNest: onNest,
|
|
64
73
|
onUnNest: onUnNest,
|
|
65
74
|
backButton: backButton,
|
|
66
|
-
parentId: id
|
|
75
|
+
parentId: id,
|
|
76
|
+
childIds: childIds
|
|
67
77
|
};
|
|
68
|
-
},
|
|
78
|
+
}, // childIds shouldn't change as it's a ref
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
[onNest, onUnNest, backButton, stack, id, currentStackId]);
|
|
81
|
+
useChildIdsEffect(childIds, id);
|
|
69
82
|
|
|
70
83
|
var isNormalClick = function isNormalClick(e) {
|
|
71
84
|
return !(e.button || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
@@ -96,13 +109,7 @@ var NestingItem = function NestingItem(props) {
|
|
|
96
109
|
return jsx(NestedContext.Provider, {
|
|
97
110
|
value: context
|
|
98
111
|
}, stack.length >= 1 && jsx("div", {
|
|
99
|
-
css:
|
|
100
|
-
marginLeft: gridSize(),
|
|
101
|
-
marginRight: gridSize(),
|
|
102
|
-
// This padding bottom needs to match the section margin inside @atlaskit/menu.
|
|
103
|
-
paddingTop: gridSize() * 0.75,
|
|
104
|
-
paddingBottom: gridSize() * 0.75
|
|
105
|
-
}
|
|
112
|
+
css: nestingItemStyles
|
|
106
113
|
}, backButton), jsx(NavigationContent, {
|
|
107
114
|
testId: testId,
|
|
108
115
|
showTopScrollIndicator: stack.length >= 1
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
|
-
import { jsx } from '@emotion/react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
4
|
import { N10, N500 } from '@atlaskit/theme/colors';
|
|
5
5
|
import { gridSize } from '@atlaskit/theme/constants';
|
|
6
|
-
|
|
6
|
+
var sideNavStyles = css({
|
|
7
|
+
display: 'flex',
|
|
8
|
+
width: '100%',
|
|
9
|
+
minWidth: gridSize() * 30,
|
|
10
|
+
height: '100%',
|
|
11
|
+
position: 'relative',
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
backgroundColor: "var(--ds-surface, ".concat(N10, ")"),
|
|
14
|
+
color: "var(--ds-text-subtle, ".concat(N500, ")"),
|
|
15
|
+
overflow: 'hidden'
|
|
16
|
+
});
|
|
7
17
|
/**
|
|
8
18
|
* __Side navigation__
|
|
9
19
|
*
|
|
@@ -13,6 +23,7 @@ import { gridSize } from '@atlaskit/theme/constants';
|
|
|
13
23
|
* - [Code](https://atlassian.design/components/side-navigation/code)
|
|
14
24
|
* - [Usage](https://atlassian.design/components/side-navigation/usage)
|
|
15
25
|
*/
|
|
26
|
+
|
|
16
27
|
var SideNavigation = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
17
28
|
var children = props.children,
|
|
18
29
|
testId = props.testId,
|
|
@@ -21,17 +32,7 @@ var SideNavigation = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
21
32
|
ref: ref,
|
|
22
33
|
"data-testid": testId,
|
|
23
34
|
"aria-label": label,
|
|
24
|
-
css:
|
|
25
|
-
width: '100%',
|
|
26
|
-
height: '100%',
|
|
27
|
-
color: "var(--ds-text-subtle, ".concat(N500, ")"),
|
|
28
|
-
minWidth: gridSize() * 30,
|
|
29
|
-
backgroundColor: "var(--ds-surface, ".concat(N10, ")"),
|
|
30
|
-
position: 'relative',
|
|
31
|
-
display: 'flex',
|
|
32
|
-
flexDirection: 'column',
|
|
33
|
-
overflow: 'hidden'
|
|
34
|
-
}
|
|
35
|
+
css: sideNavStyles
|
|
35
36
|
}, children);
|
|
36
37
|
});
|
|
37
38
|
export default SideNavigation;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ROOT_ID } from '../NestableNavigationContent';
|
|
3
|
+
export var useChildIds = function useChildIds(currentStackId, committedStack, onUnknownNest) {
|
|
4
|
+
var childIdsRef = useRef(new Set());
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
// we are holding navigation item IDs in childIdsRef
|
|
7
|
+
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
|
|
8
|
+
if (currentStackId === ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
onUnknownNest(committedStack || [currentStackId]);
|
|
13
|
+
}, [currentStackId, committedStack, onUnknownNest]);
|
|
14
|
+
return {
|
|
15
|
+
childIdsRef: childIdsRef
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export var useChildIdsEffect = function useChildIdsEffect(childIds, id) {
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (!childIds || !childIds.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!childIds.current.has(id)) {
|
|
25
|
+
childIds.current.add(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return function () {
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
childIds.current.delete(id);
|
|
31
|
+
}; // childIds shouldn't change as it's a ref
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [id]);
|
|
34
|
+
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
2
|
interface NestedContext {
|
|
3
3
|
currentStackId: string;
|
|
4
4
|
onNest: (id: string) => void;
|
|
@@ -6,6 +6,7 @@ interface NestedContext {
|
|
|
6
6
|
stack: string[];
|
|
7
7
|
parentId: string;
|
|
8
8
|
backButton?: React.ReactNode;
|
|
9
|
+
childIds: MutableRefObject<Set<string>>;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* @internal
|
|
@@ -38,6 +38,11 @@ export interface NestableNavigationContentProps {
|
|
|
38
38
|
* This prop should be used with the `stack` prop for controlled behavior.
|
|
39
39
|
*/
|
|
40
40
|
onChange?: (stack: string[]) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Called when a nesting id that does not exist among `<NestingItem>`s is pushed to the stack. Use this callback to be notified when there is an undefined nesting state.
|
|
43
|
+
* Provides you with the stack which led to the undefined state, with the top of the stack (last item in array) being the invalid item.
|
|
44
|
+
*/
|
|
45
|
+
onUnknownNest?: (stack: string[]) => void;
|
|
41
46
|
/**
|
|
42
47
|
* Custom overrides for the composed components.
|
|
43
48
|
*
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
export declare const useChildIds: (currentStackId: string, committedStack: string[], onUnknownNest?: ((stack: string[]) => void) | undefined) => {
|
|
3
|
+
childIdsRef: MutableRefObject<Set<string>>;
|
|
4
|
+
};
|
|
5
|
+
export declare const useChildIdsEffect: (childIds: MutableRefObject<Set<string>>, id: string) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/side-navigation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A highly composable side navigation component that supports nested views.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,16 +12,10 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"module:es2019": "dist/es2019/index.js",
|
|
14
14
|
"types": "dist/types/index.d.ts",
|
|
15
|
-
"typesVersions": {
|
|
16
|
-
">=4.0 <4.5": {
|
|
17
|
-
"*": [
|
|
18
|
-
"dist/types-ts4.0/*"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
15
|
"sideEffects": false,
|
|
23
16
|
"atlaskit:src": "src/index.tsx",
|
|
24
17
|
"atlassian": {
|
|
18
|
+
"disableProductCI": true,
|
|
25
19
|
"team": "Design System Team",
|
|
26
20
|
"deprecatedAutoEntryPoints": true,
|
|
27
21
|
"releaseModel": "scheduled",
|
|
@@ -33,8 +27,8 @@
|
|
|
33
27
|
"dependencies": {
|
|
34
28
|
"@atlaskit/ds-lib": "^2.1.0",
|
|
35
29
|
"@atlaskit/icon": "^21.11.0",
|
|
36
|
-
"@atlaskit/menu": "^1.
|
|
37
|
-
"@atlaskit/motion": "^1.
|
|
30
|
+
"@atlaskit/menu": "^1.4.0",
|
|
31
|
+
"@atlaskit/motion": "^1.3.0",
|
|
38
32
|
"@atlaskit/theme": "^12.2.0",
|
|
39
33
|
"@atlaskit/tokens": "^0.10.0",
|
|
40
34
|
"@babel/runtime": "^7.0.0",
|
|
@@ -44,8 +38,8 @@
|
|
|
44
38
|
"react": "^16.8.0"
|
|
45
39
|
},
|
|
46
40
|
"devDependencies": {
|
|
47
|
-
"@atlaskit/atlassian-navigation": "^2.
|
|
48
|
-
"@atlaskit/button": "^16.
|
|
41
|
+
"@atlaskit/atlassian-navigation": "^2.3.0",
|
|
42
|
+
"@atlaskit/button": "^16.4.0",
|
|
49
43
|
"@atlaskit/docs": "*",
|
|
50
44
|
"@atlaskit/logo": "^13.10.0",
|
|
51
45
|
"@atlaskit/onboarding": "^10.6.0",
|