@bytebrand/fe-ui-core 4.2.120 → 4.2.122
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/package.json +1 -1
- package/source/components/FormattedNumber/FormattedNumber.tsx +3 -31
- package/source/components/OfferDetailedSection/partials/PanelConfig.tsx +0 -1
- package/source/components/Vehicle/VehicleFormattedPrice/VehicleFormattedPrice.tsx +20 -5
- package/source/components/VehicleDetailedSidebar/partials/PriceContent.styl +17 -0
- package/source/components/VehicleDetailedSidebar/partials/PriceContent.tsx +5 -2
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import styles from './FormattedNumber.styl';
|
|
3
3
|
|
|
4
4
|
import classnames from 'classnames';
|
|
5
|
-
import _uniqueId from 'lodash/uniqueId';
|
|
6
5
|
|
|
7
6
|
export interface IFormattedPriceProps {
|
|
8
7
|
value: number;
|
|
@@ -13,38 +12,11 @@ export interface IFormattedPriceProps {
|
|
|
13
12
|
className?: string;
|
|
14
13
|
afterCommaClassName?: string;
|
|
15
14
|
beforeCommaClassName?: string;
|
|
16
|
-
fontSize?:number;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
// const breakpointForRound = 10000;
|
|
20
18
|
const separatorCounter = 3;
|
|
21
|
-
const FormattedNumber: React.FunctionComponent<IFormattedPriceProps> = ({ className, value, disableFormatting, toRound, numbersAfterDot, beforeCommaClassName, afterCommaClassName
|
|
22
|
-
const textRef = useRef(null);
|
|
23
|
-
const uniqueId = _uniqueId(className);
|
|
24
|
-
|
|
25
|
-
const [newFontSize, setFontSize] = useState(fontSize);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const priceElement = document.getElementById(uniqueId);
|
|
28
|
-
const resizeFont = () => {
|
|
29
|
-
const textWidth = priceElement.getBoundingClientRect().width;
|
|
30
|
-
let parentWidth = fontSize === 40 ? 150 : 100;
|
|
31
|
-
if (window.innerWidth < 720) {
|
|
32
|
-
parentWidth = fontSize === 40 ? 200 : 150;
|
|
33
|
-
}
|
|
34
|
-
if (fontSize && textWidth > 120) {
|
|
35
|
-
textRef.current.parentNode.style.maxWidth = `${parentWidth}px`;
|
|
36
|
-
const newFont = Math.floor(newFontSize * parentWidth / textWidth);
|
|
37
|
-
priceElement.style.fontSize = `${newFont}px`;
|
|
38
|
-
priceElement.style.verticalAlign = 'top';
|
|
39
|
-
textRef.current.parentNode.style.fontSize = `${newFont}px`;
|
|
40
|
-
setFontSize(newFont);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
resizeFont();
|
|
44
|
-
window.addEventListener('resize', resizeFont);
|
|
45
|
-
return () => window.removeEventListener('resize', resizeFont);
|
|
46
|
-
}, [uniqueId, newFontSize]);
|
|
47
|
-
|
|
19
|
+
const FormattedNumber: React.FunctionComponent<IFormattedPriceProps> = ({ className, value, disableFormatting, toRound, numbersAfterDot, beforeCommaClassName, afterCommaClassName }) => {
|
|
48
20
|
function getFormattedNumber() {
|
|
49
21
|
// First we need to check if value is actual number;
|
|
50
22
|
|
|
@@ -99,7 +71,7 @@ const FormattedNumber: React.FunctionComponent<IFormattedPriceProps> = ({ classN
|
|
|
99
71
|
|
|
100
72
|
return (
|
|
101
73
|
<span className={classnames(styles.formattedNumber, className)}>
|
|
102
|
-
<span className={styles.value}
|
|
74
|
+
<span className={styles.value}>{val}</span>
|
|
103
75
|
</span>
|
|
104
76
|
);
|
|
105
77
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useEffect, useRef, useCallback } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import FormattedNumber from '../../FormattedNumber/FormattedNumber';
|
|
4
4
|
import styles from './VehicleFormattedPrice.styl';
|
|
@@ -23,7 +23,7 @@ export interface IVehiclePriceProps {
|
|
|
23
23
|
size?: 'small' | 'semimedium' | 'medium' | 'large';
|
|
24
24
|
disableStyles?: boolean;
|
|
25
25
|
disablePrice?: boolean;
|
|
26
|
-
|
|
26
|
+
isDynamicFontSize?:boolean;
|
|
27
27
|
|
|
28
28
|
// FormattedNumber props
|
|
29
29
|
toRound?: boolean;
|
|
@@ -35,6 +35,20 @@ export interface IVehiclePriceProps {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const VehicleFormattedPrice: React.FunctionComponent<IVehiclePriceProps> = (props) => {
|
|
38
|
+
const textRef = useRef(null);
|
|
39
|
+
|
|
40
|
+
const updateFontSize = useCallback(() => {
|
|
41
|
+
if (price && isDynamicFontSize && textRef.current) {
|
|
42
|
+
const priceLength = Math.round(price).toString().length;
|
|
43
|
+
const newSize = Math.min(60, 200 / priceLength);
|
|
44
|
+
textRef.current.style.fontSize = `${newSize}px`;
|
|
45
|
+
}
|
|
46
|
+
}, [props.price, props.isDynamicFontSize]);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
updateFontSize();
|
|
50
|
+
}, [updateFontSize]);
|
|
51
|
+
|
|
38
52
|
function renderUnit(): React.ReactNode {
|
|
39
53
|
const { postfix, unit, unitClassName } = props;
|
|
40
54
|
return (
|
|
@@ -79,7 +93,7 @@ const VehicleFormattedPrice: React.FunctionComponent<IVehiclePriceProps> = (prop
|
|
|
79
93
|
// FormattedNumber props
|
|
80
94
|
const {
|
|
81
95
|
unit, sub, numbersAfterDot, toRound, numberContainerClassName,
|
|
82
|
-
afterCommaClassName, beforeCommaClassName, disableFormatting, disablePrice,
|
|
96
|
+
afterCommaClassName, beforeCommaClassName, disableFormatting, disablePrice, isDynamicFontSize
|
|
83
97
|
} = props;
|
|
84
98
|
|
|
85
99
|
const decimalsClass = classnames(afterCommaClassName, styles.decimals);
|
|
@@ -95,7 +109,7 @@ const VehicleFormattedPrice: React.FunctionComponent<IVehiclePriceProps> = (prop
|
|
|
95
109
|
disableFormatting,
|
|
96
110
|
numbersAfterDot,
|
|
97
111
|
toRound,
|
|
98
|
-
|
|
112
|
+
isDynamicFontSize,
|
|
99
113
|
beforeCommaClassName,
|
|
100
114
|
value: price,
|
|
101
115
|
className: numberContainerClassName,
|
|
@@ -103,7 +117,7 @@ const VehicleFormattedPrice: React.FunctionComponent<IVehiclePriceProps> = (prop
|
|
|
103
117
|
};
|
|
104
118
|
|
|
105
119
|
return (
|
|
106
|
-
<span className={containerClass}>
|
|
120
|
+
<span className={containerClass} ref={textRef}>
|
|
107
121
|
{<FormattedNumber {...formattedNumberProps} />}
|
|
108
122
|
{(unit && !monthly) && renderUnit()}
|
|
109
123
|
{(monthly && unit) && renderUnitMonthly()}
|
|
@@ -127,6 +141,7 @@ VehicleFormattedPrice.defaultProps = {
|
|
|
127
141
|
unitClassName: '',
|
|
128
142
|
postfixClassName: '',
|
|
129
143
|
subClassName: '',
|
|
144
|
+
isDynamicFontSize: false,
|
|
130
145
|
sub: '',
|
|
131
146
|
// FormattedNumber props
|
|
132
147
|
toRound: false,
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
font-size: 45px!important;
|
|
26
26
|
margin-left: 3px;
|
|
27
27
|
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
28
31
|
.tabContentPadding
|
|
29
32
|
padding: 10px 10px 10px 10px;
|
|
30
33
|
flex-direction: row
|
|
@@ -112,3 +115,17 @@
|
|
|
112
115
|
.wrapper
|
|
113
116
|
+media-tablet-landscape-up()
|
|
114
117
|
padding-right: 15px;
|
|
118
|
+
|
|
119
|
+
.priceFontSizeSmall
|
|
120
|
+
.financingPriceItem
|
|
121
|
+
display: block;
|
|
122
|
+
.priceInfoLabel
|
|
123
|
+
margin-top:8px!important
|
|
124
|
+
.wrapper
|
|
125
|
+
+media-tablet-landscape-up()
|
|
126
|
+
padding-right: 0px;
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
.tabContentPaddingForBuy.priceFontSizeSmall
|
|
130
|
+
.financingPriceItem
|
|
131
|
+
display: flex;
|
|
@@ -7,6 +7,7 @@ import styles from './PriceContent.styl';
|
|
|
7
7
|
import VehicleFormattedPrice from '../../Vehicle/VehicleFormattedPrice/VehicleFormattedPrice';
|
|
8
8
|
import PriceRating from '../../PriceRating/PriceRating';
|
|
9
9
|
import RequestOffer from '../../_common/OfferRequestButtonWrapper/OfferRequestButtonWrapper';
|
|
10
|
+
import { getFormattedPrice } from '../../../../utils';
|
|
10
11
|
|
|
11
12
|
const PriceContent: React.FunctionComponent<IPriceContentProps> = ({
|
|
12
13
|
t,
|
|
@@ -45,10 +46,12 @@ const PriceContent: React.FunctionComponent<IPriceContentProps> = ({
|
|
|
45
46
|
isAdditionalOption: true,
|
|
46
47
|
onShowOfferDetails: offerBlockProps.onShowOfferDetails
|
|
47
48
|
};
|
|
49
|
+
const priceFontSize:string = monthlyInstallment ? (getFormattedPrice(monthlyInstallment)?.toString().match(/\d/g).length >= 4 ? 'small' :'large') :'';
|
|
48
50
|
|
|
49
51
|
const tabContentPaddingClassName = classnames(
|
|
50
52
|
styles.tabContentPadding,
|
|
51
|
-
{ [styles.tabContentPaddingForBuy]: isBuy }
|
|
53
|
+
{ [styles.tabContentPaddingForBuy]: isBuy },
|
|
54
|
+
{ [styles.priceFontSizeSmall]: priceFontSize === 'small' }
|
|
52
55
|
);
|
|
53
56
|
|
|
54
57
|
return (
|
|
@@ -91,7 +94,7 @@ const PriceContent: React.FunctionComponent<IPriceContentProps> = ({
|
|
|
91
94
|
postfix={postfix}
|
|
92
95
|
numbersAfterDot={0}
|
|
93
96
|
size='large'
|
|
94
|
-
|
|
97
|
+
isDynamicFontSize={tabContentPaddingClassName.includes('tabContentPaddingForBuy')? false : true}
|
|
95
98
|
/>
|
|
96
99
|
</div>
|
|
97
100
|
) : null}
|