@automattic/jetpack-components 0.72.5 → 0.73.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
@@ -2,6 +2,22 @@
2
2
 
3
3
  ### This is a list detailing changes for the Jetpack RNA Components package releases.
4
4
 
5
+ ## [0.73.0] - 2025-05-12
6
+ ### Changed
7
+ - Use `formatCurrency()` and `getCurrencyObject()` functions from the `@automattic/number-formatters` package. [#42796]
8
+
9
+ ### Removed
10
+ - Remove the `numberFormat()` function. This is a breaking change; use the `@automattic/number-formatters` package instead. [#42864]
11
+
12
+ ## [0.72.6] - 2025-05-05
13
+ ### Changed
14
+ - Update package dependencies. [#43320] [#43326]
15
+
16
+ ### Fixed
17
+ - JS Packages: Decrease CSS priority of global styles to prevent them from applying within the editor. [#43035]
18
+ - Linting: Address final rules in WordPress Stylelint config. [#43296]
19
+ - Linting: Do additional stylesheet cleanup. [#43247]
20
+
5
21
  ## [0.72.5] - 2025-04-28
6
22
  ### Changed
7
23
  - Connection: Mark external links as external. [#43152]
@@ -1376,6 +1392,8 @@
1376
1392
  ### Changed
1377
1393
  - Update node version requirement to 14.16.1
1378
1394
 
1395
+ [0.73.0]: https://github.com/Automattic/jetpack-components/compare/0.72.6...0.73.0
1396
+ [0.72.6]: https://github.com/Automattic/jetpack-components/compare/0.72.5...0.72.6
1379
1397
  [0.72.5]: https://github.com/Automattic/jetpack-components/compare/0.72.4...0.72.5
1380
1398
  [0.72.4]: https://github.com/Automattic/jetpack-components/compare/0.72.3...0.72.4
1381
1399
  [0.72.3]: https://github.com/Automattic/jetpack-components/compare/0.72.2...0.72.3
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { formatNumber } from '@automattic/number-formatters';
2
3
  import { __ } from '@wordpress/i18n';
3
4
  import { useMemo, useRef, useCallback } from 'react';
4
5
  import uPlot from 'uplot';
5
6
  import UplotReact from 'uplot-react';
6
7
  import { getUserLocale } from "../../lib/locale/index.js";
7
- import numberFormat from "../number-format/index.js";
8
8
  import { annotationsPlugin } from "./annotations-plugin.js";
9
9
  import { dayHighlightPlugin } from "./day-highlight-plugin.js";
10
10
  import getDateFormat from "./get-date-format.js";
@@ -45,7 +45,7 @@ function createSerieInfo(label, score) {
45
45
  if (!rawValue) {
46
46
  return '-';
47
47
  }
48
- return numberFormat(rawValue);
48
+ return formatNumber(rawValue);
49
49
  },
50
50
  };
51
51
  }
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { getCurrencyObject } from '@automattic/format-currency';
2
+ import { getCurrencyObject } from '@automattic/number-formatters';
3
3
  import { Button } from '@wordpress/components';
4
4
  import { sprintf, __ } from '@wordpress/i18n';
5
5
  import { LoadingPlaceholder } from '@automattic/jetpack-components';
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { getCurrencyObject } from '@automattic/format-currency';
2
+ import { getCurrencyObject } from '@automattic/number-formatters';
3
3
  import clsx from 'clsx';
4
4
  import Text from "../text/index.js";
5
5
  import styles from './style.module.scss';
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { formatNumber } from '@automattic/number-formatters';
2
3
  import { __ } from '@wordpress/i18n';
3
4
  import clsx from 'clsx';
4
5
  import { useMemo } from 'react';
5
- import numberFormat from "../number-format/index.js";
6
6
  import './style.scss';
7
7
  /**
8
8
  * Generate Record Meter bar
@@ -31,7 +31,7 @@ const RecordMeterBar = ({ totalCount, items = [], showLegendLabelBeforeCount = f
31
31
  const widthPercent = ((count / total) * 100).toPrecision(2);
32
32
  return (_jsx("div", { style: { backgroundColor, flexBasis: `${widthPercent}%` } }, label));
33
33
  }) }), _jsxs("div", { className: "record-meter-bar__legend", "aria-hidden": "true", children: [legendTitle && _jsx("div", { className: "record-meter-bar__legend--title", children: legendTitle }), _jsx("ul", { className: "record-meter-bar__legend--items", children: itemsToRender.map(({ count, label, backgroundColor }) => {
34
- const formattedCount = numberFormat(count);
34
+ const formattedCount = formatNumber(count);
35
35
  return (_jsxs("li", { className: "record-meter-bar__legend--item", children: [_jsx("div", { className: "record-meter-bar__legend--item-circle", style: { backgroundColor } }), !showLegendLabelBeforeCount && (_jsxs("span", { children: [_jsx("span", { className: "record-meter-bar__legend--item-count", children: formattedCount }), _jsx("span", { className: "record-meter-bar__legend--item-label", children: label })] })), showLegendLabelBeforeCount && (_jsxs("span", { children: [_jsx("span", { className: "record-meter-bar__legend--item-label record-meter-bar__legend--item-label-first", children: label }), _jsxs("span", { className: "record-meter-bar__legend--item-count", children: ["(", formattedCount, ")"] })] }))] }, label));
36
36
  }) })] }), _jsxs("table", { className: "screen-reader-text", children: [_jsx("caption", { children: tableCaption || __('Summary of the records', 'jetpack-components') }), _jsxs("tbody", { children: [_jsxs("tr", { children: [_jsx("th", { scope: "col", children: recordTypeLabel || __('Record type', 'jetpack-components') }), _jsx("th", { scope: "col", children: recordCountLabel || __('Record count', 'jetpack-components') })] }), itemsToRender.map(({ label, count }) => {
37
37
  return (_jsxs("tr", { children: [_jsx("td", { children: label }), _jsx("td", { children: count })] }, label));
@@ -2,12 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * External dependencies
4
4
  */
5
+ import { formatNumber, formatNumberCompact } from '@automattic/number-formatters';
5
6
  import { Tooltip } from '@wordpress/components';
6
7
  import clsx from 'clsx';
7
8
  /**
8
9
  * Internal dependencies
9
10
  */
10
- import numberFormat from "../number-format/index.js";
11
11
  import Text from "../text/index.js";
12
12
  import styles from './style.module.scss';
13
13
  /**
@@ -17,11 +17,8 @@ import styles from './style.module.scss';
17
17
  * @return {React.ReactNode} - StatCard react component.
18
18
  */
19
19
  const StatCard = ({ className, hideValue, icon, label, value, variant = 'square', }) => {
20
- const formattedValue = numberFormat(value);
21
- const compactValue = numberFormat(value, {
22
- notation: 'compact',
23
- compactDisplay: 'short',
24
- });
20
+ const formattedValue = formatNumber(value);
21
+ const compactValue = formatNumberCompact(value);
25
22
  return (_jsxs("div", { className: clsx(className, styles.wrapper, styles[variant]), children: [_jsx("div", { className: clsx(styles.icon), children: icon }), _jsxs("div", { className: clsx(styles.info), children: [_jsx(Text, { className: styles.label, children: label }), variant === 'square' ? (_jsx(Tooltip, { text: formattedValue, placement: "top", children: _jsx(Text, { variant: "headline-small", className: clsx(styles.value), children: hideValue ? '-' : compactValue }) })) : (_jsx(Text, { variant: "title-medium-semi-bold", className: clsx(styles.value), children: hideValue ? '-' : formattedValue }))] })] }));
26
23
  };
27
24
  export default StatCard;
package/build/index.d.ts CHANGED
@@ -31,7 +31,6 @@ export { default as ThemeProvider } from './components/theme-provider/index.tsx'
31
31
  export { default as Text, H2, H3, Title } from './components/text/index.tsx';
32
32
  export { default as ToggleControl } from './components/toggle-control/index.tsx';
33
33
  export { default as NumberControl } from './components/number-control/index.jsx';
34
- export { default as numberFormat } from './components/number-format/index.ts';
35
34
  export { default as QRCode } from './components/qr-code/index.tsx';
36
35
  export { default as Button } from './components/button/index.tsx';
37
36
  export type { ButtonProps } from './components/button/types.ts';
package/build/index.js CHANGED
@@ -46,7 +46,6 @@ export { default as ThemeProvider } from "./components/theme-provider/index.js";
46
46
  export { default as Text, H2, H3, Title } from "./components/text/index.js";
47
47
  export { default as ToggleControl } from "./components/toggle-control/index.js";
48
48
  export { default as NumberControl } from './components/number-control/index.jsx';
49
- export { default as numberFormat } from "./components/number-format/index.js";
50
49
  export { default as QRCode } from "./components/qr-code/index.js";
51
50
  export { default as Button } from "./components/button/index.js";
52
51
  export { default as LoadingPlaceholder } from "./components/loading-placeholder/index.js";
@@ -43,6 +43,7 @@ $white: #fff;
43
43
  &__date {
44
44
  font-size: 1em;
45
45
  font-weight: 600;
46
+ // stylelint-disable-next-line declaration-property-unit-allowed-list -- this should be changed to a unitless value: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/#values
46
47
  line-height: 1.6em;
47
48
  }
48
49
 
@@ -69,4 +70,4 @@ $white: #fff;
69
70
  left: 50%;
70
71
  transform: translateX(-50%);
71
72
  }
72
- }
73
+ }
@@ -1,9 +1,9 @@
1
+ import { formatNumber } from '@automattic/number-formatters';
1
2
  import { __ } from '@wordpress/i18n';
2
3
  import React, { useMemo, useRef, useCallback } from 'react';
3
4
  import uPlot from 'uplot';
4
5
  import UplotReact from 'uplot-react';
5
6
  import { getUserLocale } from '../../lib/locale/index.ts';
6
- import numberFormat from '../number-format/index.ts';
7
7
  import { annotationsPlugin } from './annotations-plugin.ts';
8
8
  import { dayHighlightPlugin } from './day-highlight-plugin.ts';
9
9
  import getDateFormat from './get-date-format.ts';
@@ -68,7 +68,7 @@ function createSerieInfo( label: string, score ) {
68
68
  return '-';
69
69
  }
70
70
 
71
- return numberFormat( rawValue );
71
+ return formatNumber( rawValue );
72
72
  },
73
73
  };
74
74
  }
@@ -53,7 +53,7 @@
53
53
  }
54
54
 
55
55
  // With Spinner
56
- & > :global(.components-spinner) {
56
+ > :global(.components-spinner) {
57
57
  height: 20px;
58
58
  }
59
59
  }
@@ -197,12 +197,12 @@
197
197
  justify-content: center;
198
198
  }
199
199
 
200
- & > *:not(:global(.components-spinner)) {
200
+ > *:not(:global(.components-spinner)) {
201
201
  visibility: hidden;
202
202
  }
203
203
 
204
204
  // Spinner
205
- & > :global(.components-spinner) {
205
+ > :global(.components-spinner) {
206
206
  margin: 0;
207
207
  position: absolute;
208
208
  }
@@ -35,11 +35,11 @@
35
35
  &:focus-within,
36
36
  &:hover {
37
37
 
38
- & .icon {
38
+ .icon {
39
39
  transform: translateX( calc( var( --spacing-base ) * 2 ) );
40
40
  }
41
41
 
42
- & .cta {
42
+ .cta {
43
43
  text-decoration: underline;
44
44
  text-decoration-thickness: 2px;
45
45
  }
@@ -74,4 +74,4 @@
74
74
 
75
75
  .description {
76
76
  display: inline;
77
- }
77
+ }
@@ -33,19 +33,19 @@
33
33
  flex-grow: 1;
34
34
  overflow-x: visible;
35
35
 
36
- & div,
37
- & del,
38
- & ins {
36
+ div,
37
+ del,
38
+ ins {
39
39
  padding: 0 var( --spacing-base ); // 0px | 8px
40
40
  text-decoration: none;
41
41
  }
42
42
 
43
- & del {
43
+ del {
44
44
  background-color: var( --jp-red-0 );
45
45
  color: var( --jp-red-60 );
46
46
  }
47
47
 
48
- & ins {
48
+ ins {
49
49
  background-color: var( --jp-green-5 );
50
50
  color: var( --jp-green-60 );
51
51
  }
@@ -50,6 +50,11 @@
50
50
 
51
51
  .dot-pager__control-choose-page {
52
52
  cursor: pointer;
53
+ border-radius: 50%;
54
+ width: 6px;
55
+ height: 6px;
56
+ padding: 0;
57
+ background-color: var(--jp-white-off);
53
58
 
54
59
  &:disabled {
55
60
  cursor: default;
@@ -58,14 +63,6 @@
58
63
  &:focus-visible {
59
64
  box-shadow: 0 0 0 2px var(--jp-gray-90);
60
65
  }
61
- }
62
-
63
- .dot-pager__control-choose-page {
64
- border-radius: 50%;
65
- width: 6px;
66
- height: 6px;
67
- padding: 0;
68
- background-color: var(--jp-white-off);
69
66
 
70
67
  &:hover {
71
68
  background-color: var(--jp-gray-20);
@@ -76,9 +73,6 @@
76
73
  }
77
74
  }
78
75
 
79
- .dot-pager {
80
-
81
- &__button {
82
- margin-right: 10px;
83
- }
76
+ .dot-pager__button {
77
+ margin-right: 10px;
84
78
  }
@@ -9,6 +9,14 @@ $arrow-color: var( --jp-gray );
9
9
 
10
10
  // Namespace to avoid overriding global styles
11
11
  .icon-tooltip-helper {
12
+ // POPOVER_HELPER_WIDTH
13
+ width: 124px;
14
+ height: 18px;
15
+ position: absolute;
16
+ top: 0;
17
+ // -( POPOVER_HELPER_WIDTH / 2 - iconSize / 2 ) + 'px'
18
+ left: -53px;
19
+ pointer-events: none;
12
20
 
13
21
  /*
14
22
  * Fix arrow placement - section start
@@ -71,17 +79,6 @@ $arrow-color: var( --jp-gray );
71
79
  }
72
80
  }
73
81
 
74
- .icon-tooltip-helper {
75
- // POPOVER_HELPER_WIDTH
76
- width: 124px;
77
- height: 18px;
78
- position: absolute;
79
- top: 0;
80
- // -( POPOVER_HELPER_WIDTH / 2 - iconSize / 2 ) + 'px'
81
- left: -53px;
82
- pointer-events: none;
83
- }
84
-
85
82
  .icon-tooltip-container {
86
83
  // Recover events
87
84
  pointer-events: all;
@@ -24,10 +24,6 @@
24
24
  }
25
25
  }
26
26
 
27
- &.instagram {
28
- fill: var( --color-instagram );
29
- }
30
-
31
27
  &.twitter {
32
28
  fill: var( --color-twitter );
33
29
  }
@@ -19,7 +19,8 @@
19
19
 
20
20
  &__body p {
21
21
  font-weight: 400;
22
+ // stylelint-disable-next-line declaration-property-unit-allowed-list -- this should be changed to a unitless value: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/#values
22
23
  line-height: 1.6em;
23
24
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
24
25
  }
25
- }
26
+ }
@@ -1,10 +1,10 @@
1
- import { getCurrencyObject } from '@automattic/format-currency';
1
+ import { getCurrencyObject } from '@automattic/number-formatters';
2
2
  import { Button } from '@wordpress/components';
3
3
  import { sprintf, __ } from '@wordpress/i18n';
4
4
  import { LoadingPlaceholder } from '@automattic/jetpack-components';
5
5
  import TermsOfService from '../terms-of-service/index.tsx';
6
6
  import type { PricingCardProps } from './types.ts';
7
- import type { CurrencyObject } from '@automattic/format-currency/src/types.js';
7
+ import type { CurrencyObject } from '@automattic/number-formatters';
8
8
  import type React from 'react';
9
9
 
10
10
  import './style.scss';
@@ -1,4 +1,4 @@
1
- import { getCurrencyObject } from '@automattic/format-currency';
1
+ import { getCurrencyObject } from '@automattic/number-formatters';
2
2
  import clsx from 'clsx';
3
3
  import Text from '../text/index.tsx';
4
4
  import styles from './style.module.scss';
@@ -1,7 +1,7 @@
1
+ import { formatNumber } from '@automattic/number-formatters';
1
2
  import { __ } from '@wordpress/i18n';
2
3
  import clsx from 'clsx';
3
4
  import React, { useMemo } from 'react';
4
- import numberFormat from '../number-format/index.ts';
5
5
 
6
6
  import './style.scss';
7
7
 
@@ -110,7 +110,7 @@ const RecordMeterBar: React.FC< RecordMeterBarProps > = ( {
110
110
  { legendTitle && <div className="record-meter-bar__legend--title">{ legendTitle }</div> }
111
111
  <ul className="record-meter-bar__legend--items">
112
112
  { itemsToRender.map( ( { count, label, backgroundColor } ) => {
113
- const formattedCount = numberFormat( count );
113
+ const formattedCount = formatNumber( count );
114
114
  return (
115
115
  <li key={ label } className="record-meter-bar__legend--item">
116
116
  <div
@@ -9,11 +9,11 @@
9
9
  height: 100%;
10
10
  }
11
11
 
12
- & > .button:first-child {
12
+ > .button:first-child {
13
13
  border-radius: var(--jp-border-radius) 0 0 var(--jp-border-radius);
14
14
  }
15
15
 
16
- & > :global(.components-dropdown) > .button {
16
+ > :global(.components-dropdown) > .button {
17
17
  border-radius: 0 var(--jp-border-radius) var(--jp-border-radius) 0;
18
18
  }
19
19
  }
@@ -23,4 +23,4 @@
23
23
  border-radius: var(--jp-border-radius);
24
24
  height: var(--actions-size);
25
25
  line-height: var(--actions-size);
26
- }
26
+ }
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ import { formatNumber, formatNumberCompact } from '@automattic/number-formatters';
4
5
  import { Tooltip } from '@wordpress/components';
5
6
  import clsx from 'clsx';
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
- import numberFormat from '../number-format/index.ts';
10
10
  import Text from '../text/index.tsx';
11
11
  import styles from './style.module.scss';
12
12
  import { StatCardProps } from './types.ts';
@@ -26,11 +26,8 @@ const StatCard = ( {
26
26
  value,
27
27
  variant = 'square',
28
28
  }: StatCardProps ) => {
29
- const formattedValue = numberFormat( value );
30
- const compactValue = numberFormat( value, {
31
- notation: 'compact',
32
- compactDisplay: 'short',
33
- } );
29
+ const formattedValue = formatNumber( value );
30
+ const compactValue = formatNumberCompact( value );
34
31
 
35
32
  return (
36
33
  <div className={ clsx( className, styles.wrapper, styles[ variant ] ) }>
@@ -1,7 +1,7 @@
1
1
  /* DO NOT USE THIS TO OVERRIDE STYLES */
2
2
  .global {
3
3
 
4
- & * {
4
+ :where(&) * {
5
5
  box-sizing: border-box;
6
6
  }
7
7
  }
package/index.ts CHANGED
@@ -47,7 +47,6 @@ export { default as ThemeProvider } from './components/theme-provider/index.tsx'
47
47
  export { default as Text, H2, H3, Title } from './components/text/index.tsx';
48
48
  export { default as ToggleControl } from './components/toggle-control/index.tsx';
49
49
  export { default as NumberControl } from './components/number-control/index.jsx';
50
- export { default as numberFormat } from './components/number-format/index.ts';
51
50
  export { default as QRCode } from './components/qr-code/index.tsx';
52
51
  export { default as Button } from './components/button/index.tsx';
53
52
  export type { ButtonProps } from './components/button/types.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-components",
3
- "version": "0.72.5",
3
+ "version": "0.73.0",
4
4
  "description": "Jetpack Components Package",
5
5
  "author": "Automattic",
6
6
  "license": "GPL-2.0-or-later",
@@ -15,32 +15,33 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@automattic/format-currency": "1.0.1",
18
- "@automattic/jetpack-boost-score-api": "^0.1.63",
19
- "@automattic/jetpack-api": "^0.20.1",
18
+ "@automattic/jetpack-boost-score-api": "^0.1.64",
19
+ "@automattic/jetpack-api": "^0.20.2",
20
20
  "@automattic/jetpack-script-data": "^0.4.1",
21
+ "@automattic/number-formatters": "^1.0.1",
21
22
  "@babel/runtime": "^7",
22
- "@wordpress/browserslist-config": "6.21.0",
23
- "@wordpress/components": "29.7.0",
24
- "@wordpress/compose": "7.21.0",
25
- "@wordpress/data": "10.21.0",
26
- "@wordpress/date": "5.21.0",
27
- "@wordpress/element": "6.21.0",
28
- "@wordpress/i18n": "5.21.0",
29
- "@wordpress/icons": "10.21.0",
30
- "@wordpress/notices": "5.21.0",
23
+ "@wordpress/browserslist-config": "6.22.0",
24
+ "@wordpress/components": "29.8.0",
25
+ "@wordpress/compose": "7.22.0",
26
+ "@wordpress/data": "10.22.0",
27
+ "@wordpress/date": "5.22.0",
28
+ "@wordpress/element": "6.22.0",
29
+ "@wordpress/i18n": "5.22.0",
30
+ "@wordpress/icons": "10.22.0",
31
+ "@wordpress/notices": "5.22.0",
31
32
  "clsx": "2.1.1",
32
33
  "prop-types": "^15.7.2",
33
34
  "qrcode.react": "4.2.0",
34
35
  "react-slider": "2.0.5",
35
- "social-logos": "^3.1.21",
36
+ "social-logos": "^3.2.0",
36
37
  "uplot": "1.6.31",
37
38
  "uplot-react": "1.1.4"
38
39
  },
39
40
  "devDependencies": {
40
- "@automattic/jetpack-base-styles": "^0.7.2",
41
+ "@automattic/jetpack-base-styles": "^0.7.4",
41
42
  "@babel/core": "7.26.10",
42
43
  "@babel/preset-react": "7.26.3",
43
- "@jest/globals": "29.4.3",
44
+ "@jest/globals": "29.7.0",
44
45
  "@storybook/addon-actions": "8.6.7",
45
46
  "@storybook/blocks": "8.6.7",
46
47
  "@storybook/react": "8.6.7",
@@ -1,9 +0,0 @@
1
- /**
2
- * Format a number using the locale in use by the user viewing the page.
3
- *
4
- * @param {number} number - The number to format.
5
- * @param {Intl.NumberFormatOptions} options - The format options
6
- * @return {string} Formatted number.
7
- */
8
- declare const numberFormat: (number: number, options?: Intl.NumberFormatOptions) => string;
9
- export default numberFormat;
@@ -1,13 +0,0 @@
1
- import { getUserLocale } from "../../lib/locale/index.js";
2
- /**
3
- * Format a number using the locale in use by the user viewing the page.
4
- *
5
- * @param {number} number - The number to format.
6
- * @param {Intl.NumberFormatOptions} options - The format options
7
- * @return {string} Formatted number.
8
- */
9
- const numberFormat = (number, options = {}) => {
10
- const locale = getUserLocale();
11
- return new Intl.NumberFormat(locale, options).format(number);
12
- };
13
- export default numberFormat;
@@ -1,25 +0,0 @@
1
- numberFormat
2
- =========
3
-
4
- This utility function can be used to format numbers so they are displayed in the format expected for a specific locale.
5
-
6
- For example, a large number such as `123456` would be displayed as `123,456` in US English, and as `123 456` in FR French.
7
-
8
- The function relies on `Intl.NumberFormat` to format the numbers, based on the locale information available in WordPress, or based on the browser locale as a fallback.
9
-
10
- ## General Usage:
11
-
12
- ```js
13
- import { numberFormat } from '@automattic/jetpack-components';
14
-
15
- render() {
16
- const number = '123456';
17
- const options = {
18
- notation: 'compact',
19
- compactDisplay: 'short',
20
- };
21
- return (
22
- <>{ numberFormat( number ) }</> // 123K
23
- );
24
- }
25
- ```
@@ -1,16 +0,0 @@
1
- import { getUserLocale } from '../../lib/locale/index.ts';
2
-
3
- /**
4
- * Format a number using the locale in use by the user viewing the page.
5
- *
6
- * @param {number} number - The number to format.
7
- * @param {Intl.NumberFormatOptions} options - The format options
8
- * @return {string} Formatted number.
9
- */
10
- const numberFormat = ( number: number, options: Intl.NumberFormatOptions = {} ): string => {
11
- const locale = getUserLocale();
12
-
13
- return new Intl.NumberFormat( locale, options ).format( number );
14
- };
15
-
16
- export default numberFormat;