@atlaskit/badge 17.2.0 → 18.1.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,32 @@
1
1
  # @atlaskit/badge
2
2
 
3
+ ## 18.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#117557](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/117557)
8
+ [`c76a9ef9c9363`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c76a9ef9c9363) -
9
+ [ux] Add Support for showing negative numbers in Badge Component for Custom Number fields with max
10
+ prop supported
11
+
12
+ ## 18.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - [#117363](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/117363)
17
+ [`10a0f7f6c2027`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/10a0f7f6c2027) -
18
+ This package's `peerDependencies` have been adjusted for `react` and/or `react-dom` to reflect the
19
+ status of only supporting React 18 going forward. No explicit breaking change to React support has
20
+ been made in this release, but this is to signify going forward, breaking changes for React 16 or
21
+ React 17 may come via non-major semver releases.
22
+
23
+ Please refer this community post for more details:
24
+ https://community.developer.atlassian.com/t/rfc-78-dropping-support-for-react-16-and-rendering-in-a-react-18-concurrent-root-in-jira-and-confluence/87026
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies
29
+
3
30
  ## 17.2.0
4
31
 
5
32
  ### Minor Changes
package/dist/cjs/badge.js CHANGED
@@ -45,6 +45,14 @@ var styles = {
45
45
  primaryInverted: "_bfhkvuon _syaz1e6v",
46
46
  removed: "_bfhk1gly _syaz1fxt"
47
47
  };
48
+ var badgeValueWithNegativeNumberSupported = function badgeValueWithNegativeNumberSupported(children, max) {
49
+ // Use this flag for allowing negative values(numbers) in badge component when custom number field is used
50
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
51
+ if ((0, _platformFeatureFlags.fg)('platform_ken_2029_negative_numbers_badge')) {
52
+ return typeof children === 'number' && typeof max === 'number' ? (0, _utils.formatValueWithNegativeSupport)(children, max) : children;
53
+ }
54
+ return typeof children === 'number' && max ? (0, _utils.formatValue)(children, max) : children;
55
+ };
48
56
 
49
57
  /**
50
58
  * __Badge__
@@ -77,7 +85,7 @@ var Badge = /*#__PURE__*/(0, _react.memo)(function Badge(_ref) {
77
85
  size: "small",
78
86
  align: "center",
79
87
  color: "inherit"
80
- }, typeof children === 'number' && max ? (0, _utils.formatValue)(children, max) : children));
88
+ }, badgeValueWithNegativeNumberSupported(children, max)));
81
89
  }
82
90
  return /*#__PURE__*/React.createElement("span", {
83
91
  "data-testid": testId,
@@ -90,7 +98,7 @@ var Badge = /*#__PURE__*/(0, _react.memo)(function Badge(_ref) {
90
98
  size: "UNSAFE_small",
91
99
  align: "center",
92
100
  color: style !== null && style !== void 0 && style.color ? 'inherit' : textColors[appearance]
93
- }, typeof children === 'number' && max ? (0, _utils.formatValue)(children, max) : children));
101
+ }, badgeValueWithNegativeNumberSupported(children, max)));
94
102
  });
95
103
  Badge.displayName = 'Badge';
96
104
  var _default = exports.default = Badge;
@@ -4,6 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.formatValue = formatValue;
7
+ exports.formatValueWithNegativeSupport = formatValueWithNegativeSupport;
8
+ function getSafeValueWithNegativeSupport() {
9
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
10
+ var numericValue = +value;
11
+ // NOTE: Changing below code as this causes custom fields -ve number to show up as zero in activity timeline.
12
+ // This will ensure it renders correctly if it is a number otherwise renders 0
13
+ // If the value is NaN, return it as is (assuming it's a non-numeric string)
14
+ if (isNaN(numericValue)) {
15
+ return value;
16
+ }
17
+ // Return the numeric value, allowing negative numbers
18
+ return numericValue;
19
+ }
20
+ function formatValueWithNegativeSupport(value, max) {
21
+ var safeValue = getSafeValueWithNegativeSupport(value);
22
+ var safeMax = getSafeValueWithNegativeSupport(max);
23
+ var hasSafeMaxValue = false;
24
+ if (max !== undefined) {
25
+ hasSafeMaxValue = true;
26
+ }
27
+ if (safeMax === Infinity && safeValue === Infinity) {
28
+ return '∞';
29
+ }
30
+ if (hasSafeMaxValue && safeMax < safeValue) {
31
+ return "".concat(safeMax, "+");
32
+ }
33
+ if (safeValue === Infinity) {
34
+ return '∞';
35
+ }
36
+ return safeValue.toString();
37
+ }
7
38
  function getSafeValue() {
8
39
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
9
40
  var numericValue = +value;
@@ -5,7 +5,7 @@ import { ax, ix } from "@compiled/react/runtime";
5
5
  import { memo } from 'react';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { Text } from '@atlaskit/primitives';
8
- import { formatValue } from './internal/utils';
8
+ import { formatValue, formatValueWithNegativeSupport } from './internal/utils';
9
9
  const boxStyles = {
10
10
  root: "_2rkopd34 _18zr12x7 _1e0c116y _1o9zidpf _1kz6184x",
11
11
  added: "_bfhk1bay",
@@ -36,6 +36,14 @@ const styles = {
36
36
  primaryInverted: "_bfhkvuon _syaz1e6v",
37
37
  removed: "_bfhk1gly _syaz1fxt"
38
38
  };
39
+ const badgeValueWithNegativeNumberSupported = (children, max) => {
40
+ // Use this flag for allowing negative values(numbers) in badge component when custom number field is used
41
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
42
+ if (fg('platform_ken_2029_negative_numbers_badge')) {
43
+ return typeof children === 'number' && typeof max === 'number' ? formatValueWithNegativeSupport(children, max) : children;
44
+ }
45
+ return typeof children === 'number' && max ? formatValue(children, max) : children;
46
+ };
39
47
 
40
48
  /**
41
49
  * __Badge__
@@ -66,7 +74,7 @@ const Badge = /*#__PURE__*/memo(function Badge({
66
74
  size: "small",
67
75
  align: "center",
68
76
  color: "inherit"
69
- }, typeof children === 'number' && max ? formatValue(children, max) : children));
77
+ }, badgeValueWithNegativeNumberSupported(children, max)));
70
78
  }
71
79
  return /*#__PURE__*/React.createElement("span", {
72
80
  "data-testid": testId,
@@ -79,7 +87,7 @@ const Badge = /*#__PURE__*/memo(function Badge({
79
87
  size: "UNSAFE_small",
80
88
  align: "center",
81
89
  color: style !== null && style !== void 0 && style.color ? 'inherit' : textColors[appearance]
82
- }, typeof children === 'number' && max ? formatValue(children, max) : children));
90
+ }, badgeValueWithNegativeNumberSupported(children, max)));
83
91
  });
84
92
  Badge.displayName = 'Badge';
85
93
  export default Badge;
@@ -1,3 +1,32 @@
1
+ function getSafeValueWithNegativeSupport(value = 0) {
2
+ const numericValue = +value;
3
+ // NOTE: Changing below code as this causes custom fields -ve number to show up as zero in activity timeline.
4
+ // This will ensure it renders correctly if it is a number otherwise renders 0
5
+ // If the value is NaN, return it as is (assuming it's a non-numeric string)
6
+ if (isNaN(numericValue)) {
7
+ return value;
8
+ }
9
+ // Return the numeric value, allowing negative numbers
10
+ return numericValue;
11
+ }
12
+ export function formatValueWithNegativeSupport(value, max) {
13
+ const safeValue = getSafeValueWithNegativeSupport(value);
14
+ const safeMax = getSafeValueWithNegativeSupport(max);
15
+ let hasSafeMaxValue = false;
16
+ if (max !== undefined) {
17
+ hasSafeMaxValue = true;
18
+ }
19
+ if (safeMax === Infinity && safeValue === Infinity) {
20
+ return '∞';
21
+ }
22
+ if (hasSafeMaxValue && safeMax < safeValue) {
23
+ return `${safeMax}+`;
24
+ }
25
+ if (safeValue === Infinity) {
26
+ return '∞';
27
+ }
28
+ return safeValue.toString();
29
+ }
1
30
  function getSafeValue(value = 0) {
2
31
  const numericValue = +value;
3
32
  if (numericValue < 0) {
package/dist/esm/badge.js CHANGED
@@ -5,7 +5,7 @@ import { ax, ix } from "@compiled/react/runtime";
5
5
  import { memo } from 'react';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { Text } from '@atlaskit/primitives';
8
- import { formatValue } from './internal/utils';
8
+ import { formatValue, formatValueWithNegativeSupport } from './internal/utils';
9
9
  var boxStyles = {
10
10
  root: "_2rkopd34 _18zr12x7 _1e0c116y _1o9zidpf _1kz6184x",
11
11
  added: "_bfhk1bay",
@@ -36,6 +36,14 @@ var styles = {
36
36
  primaryInverted: "_bfhkvuon _syaz1e6v",
37
37
  removed: "_bfhk1gly _syaz1fxt"
38
38
  };
39
+ var badgeValueWithNegativeNumberSupported = function badgeValueWithNegativeNumberSupported(children, max) {
40
+ // Use this flag for allowing negative values(numbers) in badge component when custom number field is used
41
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
42
+ if (fg('platform_ken_2029_negative_numbers_badge')) {
43
+ return typeof children === 'number' && typeof max === 'number' ? formatValueWithNegativeSupport(children, max) : children;
44
+ }
45
+ return typeof children === 'number' && max ? formatValue(children, max) : children;
46
+ };
39
47
 
40
48
  /**
41
49
  * __Badge__
@@ -68,7 +76,7 @@ var Badge = /*#__PURE__*/memo(function Badge(_ref) {
68
76
  size: "small",
69
77
  align: "center",
70
78
  color: "inherit"
71
- }, typeof children === 'number' && max ? formatValue(children, max) : children));
79
+ }, badgeValueWithNegativeNumberSupported(children, max)));
72
80
  }
73
81
  return /*#__PURE__*/React.createElement("span", {
74
82
  "data-testid": testId,
@@ -81,7 +89,7 @@ var Badge = /*#__PURE__*/memo(function Badge(_ref) {
81
89
  size: "UNSAFE_small",
82
90
  align: "center",
83
91
  color: style !== null && style !== void 0 && style.color ? 'inherit' : textColors[appearance]
84
- }, typeof children === 'number' && max ? formatValue(children, max) : children));
92
+ }, badgeValueWithNegativeNumberSupported(children, max)));
85
93
  });
86
94
  Badge.displayName = 'Badge';
87
95
  export default Badge;
@@ -1,3 +1,33 @@
1
+ function getSafeValueWithNegativeSupport() {
2
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
3
+ var numericValue = +value;
4
+ // NOTE: Changing below code as this causes custom fields -ve number to show up as zero in activity timeline.
5
+ // This will ensure it renders correctly if it is a number otherwise renders 0
6
+ // If the value is NaN, return it as is (assuming it's a non-numeric string)
7
+ if (isNaN(numericValue)) {
8
+ return value;
9
+ }
10
+ // Return the numeric value, allowing negative numbers
11
+ return numericValue;
12
+ }
13
+ export function formatValueWithNegativeSupport(value, max) {
14
+ var safeValue = getSafeValueWithNegativeSupport(value);
15
+ var safeMax = getSafeValueWithNegativeSupport(max);
16
+ var hasSafeMaxValue = false;
17
+ if (max !== undefined) {
18
+ hasSafeMaxValue = true;
19
+ }
20
+ if (safeMax === Infinity && safeValue === Infinity) {
21
+ return '∞';
22
+ }
23
+ if (hasSafeMaxValue && safeMax < safeValue) {
24
+ return "".concat(safeMax, "+");
25
+ }
26
+ if (safeValue === Infinity) {
27
+ return '∞';
28
+ }
29
+ return safeValue.toString();
30
+ }
1
31
  function getSafeValue() {
2
32
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
3
33
  var numericValue = +value;
@@ -1 +1,2 @@
1
+ export declare function formatValueWithNegativeSupport(value?: string | number, max?: number): string;
1
2
  export declare function formatValue(value?: string | number, max?: number): string;
@@ -1 +1,2 @@
1
+ export declare function formatValueWithNegativeSupport(value?: string | number, max?: number): string;
1
2
  export declare function formatValue(value?: string | number, max?: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/badge",
3
- "version": "17.2.0",
3
+ "version": "18.1.0",
4
4
  "description": "A badge is a visual indicator for numeric values such as tallies and scores.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -39,24 +39,24 @@
39
39
  "dependencies": {
40
40
  "@atlaskit/codemod-utils": "^4.2.0",
41
41
  "@atlaskit/platform-feature-flags": "^1.1.0",
42
- "@atlaskit/primitives": "^13.6.0",
43
- "@atlaskit/tokens": "^3.3.0",
42
+ "@atlaskit/primitives": "^14.1.0",
43
+ "@atlaskit/tokens": "^4.3.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@compiled/react": "^0.18.2"
46
46
  },
47
47
  "peerDependencies": {
48
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
48
+ "react": "^18.2.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@af/accessibility-testing": "*",
52
52
  "@af/integration-testing": "*",
53
53
  "@af/visual-regression": "*",
54
54
  "@atlaskit/docs": "*",
55
- "@atlaskit/ds-lib": "^3.5.0",
55
+ "@atlaskit/ds-lib": "^4.0.0",
56
56
  "@atlaskit/link": "*",
57
57
  "@atlaskit/section-message": "*",
58
58
  "@atlaskit/ssr": "*",
59
- "@atlaskit/theme": "^16.0.0",
59
+ "@atlaskit/theme": "^17.0.0",
60
60
  "@atlassian/feature-flags-test-utils": "*",
61
61
  "@testing-library/react": "^13.4.0",
62
62
  "react-dom": "^18.2.0",
@@ -90,6 +90,9 @@
90
90
  "platform-feature-flags": {
91
91
  "platform-component-visual-refresh": {
92
92
  "type": "boolean"
93
+ },
94
+ "platform_ken_2029_negative_numbers_badge": {
95
+ "type": "boolean"
93
96
  }
94
97
  }
95
98
  }