From 95f2e82dbbe44b4db7cb20433fc73b1851437e5c Mon Sep 17 00:00:00 2001 From: dobri1408 <50819975+dobri1408@users.noreply.github.com> Date: Tue, 25 Jul 2023 17:38:47 +0300 Subject: [PATCH] feat: Use the new @eeacms/countup library refs - #254634 --- package.json | 6 +---- src/StatisticBlock/View.jsx | 44 ++++++++++++-------------------- src/StatisticBlock/View.test.jsx | 6 ++++- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index b102770..dc32044 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,8 @@ "url": "git@github.com:eea/volto-statistic-block.git" }, "addons": [], - "resolutions": { - "react-countup/countup.js": "2.5.0" - }, "dependencies": { - "react-countup": "6.3.1", - "react-visibility-sensor": "5.1.1" + "@eeacms/countup": "*" }, "devDependencies": { "@cypress/code-coverage": "^3.10.0", diff --git a/src/StatisticBlock/View.jsx b/src/StatisticBlock/View.jsx index 4ea39c9..2d18fa4 100644 --- a/src/StatisticBlock/View.jsx +++ b/src/StatisticBlock/View.jsx @@ -2,8 +2,7 @@ import React from 'react'; import isNumber from 'lodash/isNumber'; import isNaN from 'lodash/isNaN'; import cx from 'classnames'; -import CountUp from 'react-countup'; -import VisibilitySensor from 'react-visibility-sensor'; +import { CountUp } from '@eeacms/countup'; import { Statistic } from 'semantic-ui-react'; import { UniversalLink } from '@plone/volto/components'; import { @@ -18,25 +17,6 @@ import { import './styles.less'; -const CountUpWrapper = ({ countUpRef, start }) => { - const [visible, setVisible] = React.useState(false); - - return ( - { - start(); - if (isVisible && !visible) { - setVisible(true); - } - }} - active={!visible} - delayedCall - > - - - ); -}; - const View = ({ data, mode }) => { const { horizontal = false, @@ -93,13 +73,21 @@ const View = ({ data, mode }) => { {animation.enabled && isNumber(valueNo) && !isNaN(valueNo) ? ( 0 ? animation.duration : 2} - decimals={animation.decimals > 0 ? animation.decimals : 0} - prefix={animation.prefix || ''} - suffix={animation.suffix || ''} - > - {(props) => } - + isCounting + duration={parseInt( + animation.duration > 0 ? animation.duration : 2, + )} + decimalPlaces={ + animation.decimals > 0 ? animation.decimals : 0 + } + formatter={(value) => { + let prefix = animation.prefix || ''; + let suffix = animation.suffix || ''; + return ( + prefix + value.toFixed(animation.decimals) + suffix + ); + }} + /> ) : ( _serializeNodes(valueNodes) )} diff --git a/src/StatisticBlock/View.test.jsx b/src/StatisticBlock/View.test.jsx index c7bbc51..d35be4b 100644 --- a/src/StatisticBlock/View.test.jsx +++ b/src/StatisticBlock/View.test.jsx @@ -7,7 +7,11 @@ import '@testing-library/jest-dom/extend-expect'; jest.mock('lodash/isNumber', () => jest.fn(() => true)); jest.mock('lodash/isNaN', () => jest.fn(() => false)); -jest.mock('react-countup', () => () =>
Mocked CountUp
); +jest.mock('@eeacms/countup', () => ({ + CountUp: () => { + return
Mocked CountUp
; + }, +})); jest.mock('@plone/volto/components', () => ({ UniversalLink: ({ children }) =>
{children}
,