@atlaskit/side-nav-items 1.0.1 → 1.2.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/side-nav-items
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d06bf7b1c35dd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d06bf7b1c35dd) -
8
+ Added back event firing analytics for flyout menu opening, and flyout menu closing upon trigger
9
+ click. Added back tests for flyout menu open and close analytics.
10
+
11
+ ## 1.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`4b1149e96b0e1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4b1149e96b0e1) -
16
+ Add five new entry points (/command, /command-creator, /singleton, /client-types, /bridge-api) to
17
+ enable granular imports for better tree-shaking and performance. Existing barrel imports continue
18
+ to work; this is a foundational change that enables future debarreling work.
19
+
3
20
  ## 1.0.1
4
21
 
5
22
  ### Patch Changes
@@ -13,8 +13,10 @@ var React = _react;
13
13
  var _runtime = require("@compiled/react/runtime");
14
14
  var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
15
15
  var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
16
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
17
  var _experimental = require("@atlaskit/popup/experimental");
17
18
  var _menuItem = require("../menu-item");
19
+ var _flyoutMenuItemContext = require("./flyout-menu-item-context");
18
20
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
19
21
  var elemAfterStyles = {
20
22
  root: "_18zr12x7 _1tz3r0mg"
@@ -36,6 +38,18 @@ var FlyoutMenuItemTrigger = exports.FlyoutMenuItemTrigger = /*#__PURE__*/(0, _re
36
38
  isDragging = _ref.isDragging,
37
39
  hasDragIndicator = _ref.hasDragIndicator,
38
40
  dropIndicator = _ref.dropIndicator;
41
+ var isOpen = (0, _react.useContext)(_flyoutMenuItemContext.IsOpenContext);
42
+ var onCloseRef = (0, _react.useContext)(_flyoutMenuItemContext.OnCloseContext);
43
+ var handleClick = (0, _react.useCallback)(function (event, analyticsEvent) {
44
+ // If the flyout is open and the trigger is clicked, close the flyout and call the onClick
45
+ // handler with the source information set to 'outside-click'.
46
+ if ((0, _platformFeatureFlags.fg)('platform_dst_nav4_flyout_menu_slots_close_button')) {
47
+ if (isOpen && onCloseRef.current) {
48
+ onCloseRef.current(event, 'outside-click');
49
+ }
50
+ }
51
+ onClick === null || onClick === void 0 || onClick(event, analyticsEvent);
52
+ }, [isOpen, onCloseRef, onClick]);
39
53
  return /*#__PURE__*/React.createElement(_experimental.PopupTrigger, null, function (_ref2) {
40
54
  var ref = _ref2.ref,
41
55
  ariaControls = _ref2['aria-controls'],
@@ -53,7 +67,7 @@ var FlyoutMenuItemTrigger = exports.FlyoutMenuItemTrigger = /*#__PURE__*/(0, _re
53
67
  color: "currentColor",
54
68
  size: "small"
55
69
  })),
56
- onClick: onClick,
70
+ onClick: handleClick,
57
71
  ariaControls: ariaControls,
58
72
  ariaExpanded: ariaExpanded,
59
73
  ariaHasPopup: ariaHasPopup,
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.FlyoutMenuItem = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = _interopRequireWildcard(require("react"));
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
11
12
  var _useControlled3 = _interopRequireDefault(require("@atlaskit/ds-lib/use-controlled"));
12
13
  var _usePreviousValue = _interopRequireDefault(require("@atlaskit/ds-lib/use-previous-value"));
13
14
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -49,6 +50,9 @@ var FlyoutMenuItem = exports.FlyoutMenuItem = /*#__PURE__*/(0, _react.forwardRef
49
50
  isOpen = _useControlled2[0],
50
51
  setIsOpen = _useControlled2[1];
51
52
  var previousIsOpen = (0, _usePreviousValue.default)(isOpen);
53
+ var onCloseRef = (0, _react.useRef)(null);
54
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
55
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
52
56
  (0, _react.useEffect)(function () {
53
57
  if (previousIsOpen === undefined || previousIsOpen === isOpen) {
54
58
  /**
@@ -60,17 +64,31 @@ var FlyoutMenuItem = exports.FlyoutMenuItem = /*#__PURE__*/(0, _react.forwardRef
60
64
  */
61
65
  return;
62
66
  }
67
+
68
+ // When flyout menu is opened, fire analytics event
69
+ if (isOpen && previousIsOpen === false) {
70
+ if ((0, _platformFeatureFlags.fg)('platform_dst_nav4_flyout_menu_slots_close_button')) {
71
+ var navigationAnalyticsEvent = createAnalyticsEvent({
72
+ source: 'sideNav',
73
+ actionSubject: 'flyoutMenu',
74
+ action: 'opened'
75
+ });
76
+ navigationAnalyticsEvent.fire('navigation');
77
+ }
78
+ }
63
79
  onOpenChange === null || onOpenChange === void 0 || onOpenChange(isOpen);
64
- }, [isOpen, onOpenChange, previousIsOpen]);
80
+ }, [isOpen, onOpenChange, previousIsOpen, createAnalyticsEvent]);
65
81
  return /*#__PURE__*/_react.default.createElement(_flyoutMenuItemContext.IsOpenContext.Provider, {
66
82
  value: isOpen
67
83
  }, /*#__PURE__*/_react.default.createElement(_flyoutMenuItemContext.SetIsOpenContext.Provider, {
68
84
  value: setIsOpen
85
+ }, /*#__PURE__*/_react.default.createElement(_flyoutMenuItemContext.OnCloseContext.Provider, {
86
+ value: onCloseRef
69
87
  }, /*#__PURE__*/_react.default.createElement(_menuListItem.MenuListItem, {
70
88
  ref: forwardedRef
71
89
  }, /*#__PURE__*/_react.default.createElement(_experimental.Popup, {
72
90
  id: id,
73
91
  isOpen: isOpen,
74
92
  role: (0, _platformFeatureFlags.fg)('platform_dst_nav4_flyout_menu_slots_close_button') ? 'dialog' : undefined
75
- }, children))));
93
+ }, children)))));
76
94
  });
@@ -2,11 +2,13 @@
2
2
  import "./flyout-menu-item-trigger.compiled.css";
3
3
  import * as React from 'react';
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
- import { forwardRef } from 'react';
5
+ import { forwardRef, useCallback, useContext } from 'react';
6
6
  import mergeRefs from '@atlaskit/ds-lib/merge-refs';
7
7
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { PopupTrigger } from '@atlaskit/popup/experimental';
9
10
  import { MenuItemBase } from '../menu-item';
11
+ import { IsOpenContext, OnCloseContext } from './flyout-menu-item-context';
10
12
  const elemAfterStyles = {
11
13
  root: "_18zr12x7 _1tz3r0mg"
12
14
  };
@@ -27,31 +29,45 @@ export const FlyoutMenuItemTrigger = /*#__PURE__*/forwardRef(({
27
29
  isDragging,
28
30
  hasDragIndicator,
29
31
  dropIndicator
30
- }, forwardedRef) => /*#__PURE__*/React.createElement(PopupTrigger, null, ({
31
- ref,
32
- 'aria-controls': ariaControls,
33
- 'aria-expanded': ariaExpanded,
34
- 'aria-haspopup': ariaHasPopup
35
- }) => /*#__PURE__*/React.createElement(MenuItemBase, {
36
- testId: testId,
37
- ref: mergeRefs([ref, forwardedRef]),
38
- visualContentRef: visualContentRef,
39
- elemBefore: elemBefore,
40
- elemAfter: /*#__PURE__*/React.createElement("div", {
41
- className: ax([elemAfterStyles.root])
42
- }, /*#__PURE__*/React.createElement(ChevronRightIcon, {
43
- label: "",
44
- color: "currentColor",
45
- size: "small"
46
- })),
47
- onClick: onClick,
48
- ariaControls: ariaControls,
49
- ariaExpanded: ariaExpanded,
50
- ariaHasPopup: ariaHasPopup,
51
- interactionName: interactionName,
52
- isContentTooltipDisabled: isContentTooltipDisabled,
53
- isSelected: isSelected,
54
- isDragging: isDragging,
55
- hasDragIndicator: hasDragIndicator,
56
- dropIndicator: dropIndicator
57
- }, children)));
32
+ }, forwardedRef) => {
33
+ const isOpen = useContext(IsOpenContext);
34
+ const onCloseRef = useContext(OnCloseContext);
35
+ const handleClick = useCallback((event, analyticsEvent) => {
36
+ // If the flyout is open and the trigger is clicked, close the flyout and call the onClick
37
+ // handler with the source information set to 'outside-click'.
38
+ if (fg('platform_dst_nav4_flyout_menu_slots_close_button')) {
39
+ if (isOpen && onCloseRef.current) {
40
+ onCloseRef.current(event, 'outside-click');
41
+ }
42
+ }
43
+ onClick === null || onClick === void 0 ? void 0 : onClick(event, analyticsEvent);
44
+ }, [isOpen, onCloseRef, onClick]);
45
+ return /*#__PURE__*/React.createElement(PopupTrigger, null, ({
46
+ ref,
47
+ 'aria-controls': ariaControls,
48
+ 'aria-expanded': ariaExpanded,
49
+ 'aria-haspopup': ariaHasPopup
50
+ }) => /*#__PURE__*/React.createElement(MenuItemBase, {
51
+ testId: testId,
52
+ ref: mergeRefs([ref, forwardedRef]),
53
+ visualContentRef: visualContentRef,
54
+ elemBefore: elemBefore,
55
+ elemAfter: /*#__PURE__*/React.createElement("div", {
56
+ className: ax([elemAfterStyles.root])
57
+ }, /*#__PURE__*/React.createElement(ChevronRightIcon, {
58
+ label: "",
59
+ color: "currentColor",
60
+ size: "small"
61
+ })),
62
+ onClick: handleClick,
63
+ ariaControls: ariaControls,
64
+ ariaExpanded: ariaExpanded,
65
+ ariaHasPopup: ariaHasPopup,
66
+ interactionName: interactionName,
67
+ isContentTooltipDisabled: isContentTooltipDisabled,
68
+ isSelected: isSelected,
69
+ isDragging: isDragging,
70
+ hasDragIndicator: hasDragIndicator,
71
+ dropIndicator: dropIndicator
72
+ }, children));
73
+ });
@@ -1,10 +1,11 @@
1
- import React, { forwardRef, useEffect } from 'react';
1
+ import React, { forwardRef, useEffect, useRef } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
2
3
  import useControlled from '@atlaskit/ds-lib/use-controlled';
3
4
  import usePreviousValue from '@atlaskit/ds-lib/use-previous-value';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { Popup } from '@atlaskit/popup/experimental';
6
7
  import { MenuListItem } from '../menu-list-item';
7
- import { IsOpenContext, SetIsOpenContext } from './flyout-menu-item-context';
8
+ import { IsOpenContext, OnCloseContext, SetIsOpenContext } from './flyout-menu-item-context';
8
9
  /**
9
10
  * __FlyoutMenuItem__
10
11
  *
@@ -34,6 +35,10 @@ export const FlyoutMenuItem = /*#__PURE__*/forwardRef(({
34
35
  }, forwardedRef) => {
35
36
  const [isOpen, setIsOpen] = useControlled(isOpenControlled, () => isDefaultOpen);
36
37
  const previousIsOpen = usePreviousValue(isOpen);
38
+ const onCloseRef = useRef(null);
39
+ const {
40
+ createAnalyticsEvent
41
+ } = useAnalyticsEvents();
37
42
  useEffect(() => {
38
43
  if (previousIsOpen === undefined || previousIsOpen === isOpen) {
39
44
  /**
@@ -45,17 +50,31 @@ export const FlyoutMenuItem = /*#__PURE__*/forwardRef(({
45
50
  */
46
51
  return;
47
52
  }
53
+
54
+ // When flyout menu is opened, fire analytics event
55
+ if (isOpen && previousIsOpen === false) {
56
+ if (fg('platform_dst_nav4_flyout_menu_slots_close_button')) {
57
+ const navigationAnalyticsEvent = createAnalyticsEvent({
58
+ source: 'sideNav',
59
+ actionSubject: 'flyoutMenu',
60
+ action: 'opened'
61
+ });
62
+ navigationAnalyticsEvent.fire('navigation');
63
+ }
64
+ }
48
65
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(isOpen);
49
- }, [isOpen, onOpenChange, previousIsOpen]);
66
+ }, [isOpen, onOpenChange, previousIsOpen, createAnalyticsEvent]);
50
67
  return /*#__PURE__*/React.createElement(IsOpenContext.Provider, {
51
68
  value: isOpen
52
69
  }, /*#__PURE__*/React.createElement(SetIsOpenContext.Provider, {
53
70
  value: setIsOpen
71
+ }, /*#__PURE__*/React.createElement(OnCloseContext.Provider, {
72
+ value: onCloseRef
54
73
  }, /*#__PURE__*/React.createElement(MenuListItem, {
55
74
  ref: forwardedRef
56
75
  }, /*#__PURE__*/React.createElement(Popup, {
57
76
  id: id,
58
77
  isOpen: isOpen,
59
78
  role: fg('platform_dst_nav4_flyout_menu_slots_close_button') ? 'dialog' : undefined
60
- }, children))));
79
+ }, children)))));
61
80
  });
@@ -2,11 +2,13 @@
2
2
  import "./flyout-menu-item-trigger.compiled.css";
3
3
  import * as React from 'react';
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
- import { forwardRef } from 'react';
5
+ import { forwardRef, useCallback, useContext } from 'react';
6
6
  import mergeRefs from '@atlaskit/ds-lib/merge-refs';
7
7
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { PopupTrigger } from '@atlaskit/popup/experimental';
9
10
  import { MenuItemBase } from '../menu-item';
11
+ import { IsOpenContext, OnCloseContext } from './flyout-menu-item-context';
10
12
  var elemAfterStyles = {
11
13
  root: "_18zr12x7 _1tz3r0mg"
12
14
  };
@@ -27,6 +29,18 @@ export var FlyoutMenuItemTrigger = /*#__PURE__*/forwardRef(function (_ref, forwa
27
29
  isDragging = _ref.isDragging,
28
30
  hasDragIndicator = _ref.hasDragIndicator,
29
31
  dropIndicator = _ref.dropIndicator;
32
+ var isOpen = useContext(IsOpenContext);
33
+ var onCloseRef = useContext(OnCloseContext);
34
+ var handleClick = useCallback(function (event, analyticsEvent) {
35
+ // If the flyout is open and the trigger is clicked, close the flyout and call the onClick
36
+ // handler with the source information set to 'outside-click'.
37
+ if (fg('platform_dst_nav4_flyout_menu_slots_close_button')) {
38
+ if (isOpen && onCloseRef.current) {
39
+ onCloseRef.current(event, 'outside-click');
40
+ }
41
+ }
42
+ onClick === null || onClick === void 0 || onClick(event, analyticsEvent);
43
+ }, [isOpen, onCloseRef, onClick]);
30
44
  return /*#__PURE__*/React.createElement(PopupTrigger, null, function (_ref2) {
31
45
  var ref = _ref2.ref,
32
46
  ariaControls = _ref2['aria-controls'],
@@ -44,7 +58,7 @@ export var FlyoutMenuItemTrigger = /*#__PURE__*/forwardRef(function (_ref, forwa
44
58
  color: "currentColor",
45
59
  size: "small"
46
60
  })),
47
- onClick: onClick,
61
+ onClick: handleClick,
48
62
  ariaControls: ariaControls,
49
63
  ariaExpanded: ariaExpanded,
50
64
  ariaHasPopup: ariaHasPopup,
@@ -1,11 +1,12 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { forwardRef, useEffect } from 'react';
2
+ import React, { forwardRef, useEffect, useRef } from 'react';
3
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
4
  import useControlled from '@atlaskit/ds-lib/use-controlled';
4
5
  import usePreviousValue from '@atlaskit/ds-lib/use-previous-value';
5
6
  import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { Popup } from '@atlaskit/popup/experimental';
7
8
  import { MenuListItem } from '../menu-list-item';
8
- import { IsOpenContext, SetIsOpenContext } from './flyout-menu-item-context';
9
+ import { IsOpenContext, OnCloseContext, SetIsOpenContext } from './flyout-menu-item-context';
9
10
  /**
10
11
  * __FlyoutMenuItem__
11
12
  *
@@ -40,6 +41,9 @@ export var FlyoutMenuItem = /*#__PURE__*/forwardRef(function (_ref, forwardedRef
40
41
  isOpen = _useControlled2[0],
41
42
  setIsOpen = _useControlled2[1];
42
43
  var previousIsOpen = usePreviousValue(isOpen);
44
+ var onCloseRef = useRef(null);
45
+ var _useAnalyticsEvents = useAnalyticsEvents(),
46
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
43
47
  useEffect(function () {
44
48
  if (previousIsOpen === undefined || previousIsOpen === isOpen) {
45
49
  /**
@@ -51,17 +55,31 @@ export var FlyoutMenuItem = /*#__PURE__*/forwardRef(function (_ref, forwardedRef
51
55
  */
52
56
  return;
53
57
  }
58
+
59
+ // When flyout menu is opened, fire analytics event
60
+ if (isOpen && previousIsOpen === false) {
61
+ if (fg('platform_dst_nav4_flyout_menu_slots_close_button')) {
62
+ var navigationAnalyticsEvent = createAnalyticsEvent({
63
+ source: 'sideNav',
64
+ actionSubject: 'flyoutMenu',
65
+ action: 'opened'
66
+ });
67
+ navigationAnalyticsEvent.fire('navigation');
68
+ }
69
+ }
54
70
  onOpenChange === null || onOpenChange === void 0 || onOpenChange(isOpen);
55
- }, [isOpen, onOpenChange, previousIsOpen]);
71
+ }, [isOpen, onOpenChange, previousIsOpen, createAnalyticsEvent]);
56
72
  return /*#__PURE__*/React.createElement(IsOpenContext.Provider, {
57
73
  value: isOpen
58
74
  }, /*#__PURE__*/React.createElement(SetIsOpenContext.Provider, {
59
75
  value: setIsOpen
76
+ }, /*#__PURE__*/React.createElement(OnCloseContext.Provider, {
77
+ value: onCloseRef
60
78
  }, /*#__PURE__*/React.createElement(MenuListItem, {
61
79
  ref: forwardedRef
62
80
  }, /*#__PURE__*/React.createElement(Popup, {
63
81
  id: id,
64
82
  isOpen: isOpen,
65
83
  role: fg('platform_dst_nav4_flyout_menu_slots_close_button') ? 'dialog' : undefined
66
- }, children))));
84
+ }, children)))));
67
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/side-nav-items",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Menu items and elements for the navigation side nav area.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",