@atlaskit/navigation-system 2.1.1 → 2.1.2

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,14 @@
1
1
  # @atlassian/navigation-system
2
2
 
3
+ ## 2.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e276abaa88f28`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e276abaa88f28) -
8
+ The `SideNavToggleButton`, `useExpandSideNav` and `useToggleSideNav` functions have been updated
9
+ to not throw an error if the side nav state is not initialised (for example, if the `SideNav` has
10
+ not mounted yet).
11
+
3
12
  ## 2.1.1
4
13
 
5
14
  ### Patch Changes
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.useExpandSideNav = useExpandSideNav;
8
7
  var _react = require("react");
9
- var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
10
8
  var _visibilityContext = require("./visibility-context");
11
9
  /**
12
10
  * __useExpandSideNav__
@@ -24,7 +22,11 @@ function useExpandSideNav() {
24
22
  matches = _window$matchMedia.matches;
25
23
  if (matches) {
26
24
  setSideNavState(function (currentState) {
27
- (0, _tinyInvariant.default)(currentState, 'Side nav state should not be null');
25
+ // No-op if the side nav state has not been initialised yet
26
+ // e.g. if the SideNav has not been mounted yet
27
+ if (!currentState) {
28
+ return null;
29
+ }
28
30
 
29
31
  // Skip the re-render if it's a no-op change
30
32
  if (currentState.desktop === 'expanded' && currentState.flyout === 'closed') {
@@ -38,7 +40,11 @@ function useExpandSideNav() {
38
40
  });
39
41
  } else {
40
42
  setSideNavState(function (currentState) {
41
- (0, _tinyInvariant.default)(currentState, 'Side nav state should not be null');
43
+ // No-op if the side nav state has not been initialised yet
44
+ // e.g. if the SideNav has not been mounted yet
45
+ if (!currentState) {
46
+ return null;
47
+ }
42
48
 
43
49
  // Skip the re-render if it's a no-op change
44
50
  if (currentState.mobile === 'expanded' && currentState.flyout === 'closed') {
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.useToggleSideNav = useToggleSideNav;
8
7
  var _react = require("react");
9
- var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
10
8
  var _visibilityContext = require("./visibility-context");
11
9
  /**
12
10
  * __useToggleSideNav__
@@ -24,7 +22,11 @@ function useToggleSideNav() {
24
22
  matches = _window$matchMedia.matches;
25
23
  if (matches) {
26
24
  setSideNavState(function (currentState) {
27
- (0, _tinyInvariant.default)(currentState, 'Side nav state should not be null');
25
+ // No-op if the side nav state has not been initialised yet
26
+ // e.g. if the SideNav has not been mounted yet
27
+ if (!currentState) {
28
+ return null;
29
+ }
28
30
  return {
29
31
  mobile: currentState.mobile,
30
32
  desktop: currentState.desktop === 'expanded' ? 'collapsed' : 'expanded',
@@ -33,7 +35,11 @@ function useToggleSideNav() {
33
35
  });
34
36
  } else {
35
37
  setSideNavState(function (currentState) {
36
- (0, _tinyInvariant.default)(currentState, 'Side nav state should not be null');
38
+ // No-op if the side nav state has not been initialised yet
39
+ // e.g. if the SideNav has not been mounted yet
40
+ if (!currentState) {
41
+ return null;
42
+ }
37
43
  return {
38
44
  desktop: currentState.desktop,
39
45
  mobile: currentState.mobile === 'expanded' ? 'collapsed' : 'expanded',
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useContext } from 'react';
2
- import invariant from 'tiny-invariant';
3
2
  import { SetSideNavVisibilityState } from './visibility-context';
4
3
  /**
5
4
  * __useExpandSideNav__
@@ -18,7 +17,11 @@ export function useExpandSideNav() {
18
17
  } = window.matchMedia('(min-width: 64rem)');
19
18
  if (matches) {
20
19
  setSideNavState(currentState => {
21
- invariant(currentState, 'Side nav state should not be null');
20
+ // No-op if the side nav state has not been initialised yet
21
+ // e.g. if the SideNav has not been mounted yet
22
+ if (!currentState) {
23
+ return null;
24
+ }
22
25
 
23
26
  // Skip the re-render if it's a no-op change
24
27
  if (currentState.desktop === 'expanded' && currentState.flyout === 'closed') {
@@ -32,7 +35,11 @@ export function useExpandSideNav() {
32
35
  });
33
36
  } else {
34
37
  setSideNavState(currentState => {
35
- invariant(currentState, 'Side nav state should not be null');
38
+ // No-op if the side nav state has not been initialised yet
39
+ // e.g. if the SideNav has not been mounted yet
40
+ if (!currentState) {
41
+ return null;
42
+ }
36
43
 
37
44
  // Skip the re-render if it's a no-op change
38
45
  if (currentState.mobile === 'expanded' && currentState.flyout === 'closed') {
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useContext } from 'react';
2
- import invariant from 'tiny-invariant';
3
2
  import { SetSideNavVisibilityState } from './visibility-context';
4
3
  /**
5
4
  * __useToggleSideNav__
@@ -18,7 +17,11 @@ export function useToggleSideNav() {
18
17
  } = window.matchMedia('(min-width: 64rem)');
19
18
  if (matches) {
20
19
  setSideNavState(currentState => {
21
- invariant(currentState, 'Side nav state should not be null');
20
+ // No-op if the side nav state has not been initialised yet
21
+ // e.g. if the SideNav has not been mounted yet
22
+ if (!currentState) {
23
+ return null;
24
+ }
22
25
  return {
23
26
  mobile: currentState.mobile,
24
27
  desktop: currentState.desktop === 'expanded' ? 'collapsed' : 'expanded',
@@ -27,7 +30,11 @@ export function useToggleSideNav() {
27
30
  });
28
31
  } else {
29
32
  setSideNavState(currentState => {
30
- invariant(currentState, 'Side nav state should not be null');
33
+ // No-op if the side nav state has not been initialised yet
34
+ // e.g. if the SideNav has not been mounted yet
35
+ if (!currentState) {
36
+ return null;
37
+ }
31
38
  return {
32
39
  desktop: currentState.desktop,
33
40
  mobile: currentState.mobile === 'expanded' ? 'collapsed' : 'expanded',
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useContext } from 'react';
2
- import invariant from 'tiny-invariant';
3
2
  import { SetSideNavVisibilityState } from './visibility-context';
4
3
  /**
5
4
  * __useExpandSideNav__
@@ -17,7 +16,11 @@ export function useExpandSideNav() {
17
16
  matches = _window$matchMedia.matches;
18
17
  if (matches) {
19
18
  setSideNavState(function (currentState) {
20
- invariant(currentState, 'Side nav state should not be null');
19
+ // No-op if the side nav state has not been initialised yet
20
+ // e.g. if the SideNav has not been mounted yet
21
+ if (!currentState) {
22
+ return null;
23
+ }
21
24
 
22
25
  // Skip the re-render if it's a no-op change
23
26
  if (currentState.desktop === 'expanded' && currentState.flyout === 'closed') {
@@ -31,7 +34,11 @@ export function useExpandSideNav() {
31
34
  });
32
35
  } else {
33
36
  setSideNavState(function (currentState) {
34
- invariant(currentState, 'Side nav state should not be null');
37
+ // No-op if the side nav state has not been initialised yet
38
+ // e.g. if the SideNav has not been mounted yet
39
+ if (!currentState) {
40
+ return null;
41
+ }
35
42
 
36
43
  // Skip the re-render if it's a no-op change
37
44
  if (currentState.mobile === 'expanded' && currentState.flyout === 'closed') {
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useContext } from 'react';
2
- import invariant from 'tiny-invariant';
3
2
  import { SetSideNavVisibilityState } from './visibility-context';
4
3
  /**
5
4
  * __useToggleSideNav__
@@ -17,7 +16,11 @@ export function useToggleSideNav() {
17
16
  matches = _window$matchMedia.matches;
18
17
  if (matches) {
19
18
  setSideNavState(function (currentState) {
20
- invariant(currentState, 'Side nav state should not be null');
19
+ // No-op if the side nav state has not been initialised yet
20
+ // e.g. if the SideNav has not been mounted yet
21
+ if (!currentState) {
22
+ return null;
23
+ }
21
24
  return {
22
25
  mobile: currentState.mobile,
23
26
  desktop: currentState.desktop === 'expanded' ? 'collapsed' : 'expanded',
@@ -26,7 +29,11 @@ export function useToggleSideNav() {
26
29
  });
27
30
  } else {
28
31
  setSideNavState(function (currentState) {
29
- invariant(currentState, 'Side nav state should not be null');
32
+ // No-op if the side nav state has not been initialised yet
33
+ // e.g. if the SideNav has not been mounted yet
34
+ if (!currentState) {
35
+ return null;
36
+ }
30
37
  return {
31
38
  desktop: currentState.desktop,
32
39
  mobile: currentState.mobile === 'expanded' ? 'collapsed' : 'expanded',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/navigation-system",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "The latest navigation system for Atlassian apps.",
5
5
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
6
6
  "author": "Atlassian Pty Ltd",