From 4e64b6c5d99fe563f3b4c4d397e368e51a9fa8ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LEGRELLE=2C=20F=C3=A9lix?= Date: Tue, 17 Dec 2024 10:39:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refacto=20price?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react/components/price/Price.tsx | 59 ++++++++----------- .../react/components/price/PriceHelpers.ts | 6 +- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/packages/react/components/price/Price.tsx b/packages/react/components/price/Price.tsx index ea603d9c..45f96a68 100644 --- a/packages/react/components/price/Price.tsx +++ b/packages/react/components/price/Price.tsx @@ -3,10 +3,11 @@ import clsx from 'clsx' import { PriceProps } from './PriceProps' import { has, is } from '@/services/classify' import { Text, TextMarkup } from '../text' -import { Alignable, TypographyBold, TypographyColor } from '@/objects' +import { Alignable } from '@/objects' import { checkCents } from './PriceHelpers' import { hashClass } from '@/helpers' import { useTrilogyContext } from '@/context' +import { PriceLevel } from './PriceEnum' /** * Price Component @@ -18,7 +19,6 @@ import { useTrilogyContext } from '@/context' * @param inverted {boolean} Inverted Price Color * @param children {React.ReactNode} * @param align {Alignable} Price alignement - * @param inline {boolean} Inline display Price * @param accessibilityLabel {string} Accessibility label * @param overline {string} Price overline * @param oldAmount {boolean} old Amount Price @@ -33,7 +33,7 @@ const Price = ({ mention, period, hideCents = false, - level, + level = PriceLevel.ONE, inverted, align, accessibilityLabel, @@ -52,52 +52,42 @@ const Price = ({ let amountComponent = null let oldAmountComponent = null - const tagAmountComponent = null - if (oldAmount) { - const isNegativeStrike = oldAmount && oldAmount < 0 - const absoluteAmountStrike = oldAmount && Math.abs(oldAmount) - const absoluteWholeStrike = absoluteAmountStrike && Math.floor(absoluteAmountStrike) - const wholeStrike = isNegativeStrike && absoluteWholeStrike ? -absoluteWholeStrike : absoluteWholeStrike - - let cents = checkCents(absoluteAmountStrike.toString().split(/[.,]/)[1]?.substring(0, 2) || '') - cents = (cents && cents.length === 1 && `${cents}0`) || cents - const centsDisplayed = (!hideCents && `€${cents}`) || '€' - - oldAmountComponent = ( -