@proximus/lavender-price-native 0.1.0-alpha.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/dist/PxPrice.d.ts +19 -0
- package/dist/PxPrice.d.ts.map +1 -0
- package/dist/PxPrice.js +90 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/package.json +19 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, TextStyle } from 'react-native';
|
|
3
|
+
export declare function useParsedPrice(amount: number): string[];
|
|
4
|
+
export declare function usePriceColor(status: PriceStatus, inverted?: boolean): {
|
|
5
|
+
price: string;
|
|
6
|
+
prefix: string;
|
|
7
|
+
};
|
|
8
|
+
export interface PxPriceProps {
|
|
9
|
+
amount: number;
|
|
10
|
+
prefix?: string;
|
|
11
|
+
suffix?: string;
|
|
12
|
+
status?: PriceStatus;
|
|
13
|
+
inverted?: boolean;
|
|
14
|
+
testID?: string;
|
|
15
|
+
containerStyle?: StyleProp<TextStyle>;
|
|
16
|
+
}
|
|
17
|
+
export type PriceStatus = 'Default' | 'Promo' | 'Neutral' | 'Error' | 'Disabled';
|
|
18
|
+
export declare function PxPrice({ amount, prefix, suffix, status, inverted, testID, containerStyle, }: PxPriceProps): React.JSX.Element;
|
|
19
|
+
//# sourceMappingURL=PxPrice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PxPrice.d.ts","sourceRoot":"","sources":["../src/PxPrice.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAQ,SAAS,EAAE,MAAM,cAAc,CAAC;AAG1D,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,YAY5C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,UAAQ;;;EA0ClE;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACvC;AAED,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,OAAO,GACP,SAAS,GACT,OAAO,GACP,UAAU,CAAC;AAEf,wBAAgB,OAAO,CAAC,EACtB,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAkB,EAClB,QAAQ,EACR,MAAM,EACN,cAAc,GACf,EAAE,YAAY,qBAmDd"}
|
package/dist/PxPrice.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Body, Header } from '@proximus/lavender-texts-native';
|
|
3
|
+
import { useTheme } from '@proximus/lavender-styling-native';
|
|
4
|
+
import { Text } from 'react-native';
|
|
5
|
+
import { e2eID } from '@proximus/lavender-common-native';
|
|
6
|
+
export function useParsedPrice(amount) {
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
try {
|
|
9
|
+
// To floor round the parsed value to 2 decimal places (truncating instead of rounding up),
|
|
10
|
+
// we multiply the number by 1000 (not 100 to keep the first two decimals untouched),
|
|
11
|
+
// use Math.floor to remove the remaining decimals, and then divide back by 1000.
|
|
12
|
+
const parsed = parseFloat((Math.floor(amount * 1000) / 1000));
|
|
13
|
+
return parsed.toFixed(2).split('.');
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
return ['0', '00'];
|
|
17
|
+
}
|
|
18
|
+
}, [amount]);
|
|
19
|
+
}
|
|
20
|
+
export function usePriceColor(status, inverted = false) {
|
|
21
|
+
const { theme } = useTheme();
|
|
22
|
+
const suffix = useMemo(() => (inverted ? 'Inverted' : 'Default'), [inverted]);
|
|
23
|
+
const colors = useMemo(() => ({
|
|
24
|
+
prefix: theme.t(`ColorTextNeutral${suffix}`),
|
|
25
|
+
}), [theme, suffix]);
|
|
26
|
+
return useMemo(() => {
|
|
27
|
+
switch (status) {
|
|
28
|
+
case 'Promo':
|
|
29
|
+
return {
|
|
30
|
+
...colors,
|
|
31
|
+
price: theme.t(`ColorTextPurposePromo${suffix}`),
|
|
32
|
+
};
|
|
33
|
+
case 'Neutral':
|
|
34
|
+
return {
|
|
35
|
+
...colors,
|
|
36
|
+
price: theme.t(`ColorTextNeutral${suffix}`),
|
|
37
|
+
};
|
|
38
|
+
case 'Error':
|
|
39
|
+
return {
|
|
40
|
+
...colors,
|
|
41
|
+
price: theme.t(`ColorTextPurposeError${suffix}`),
|
|
42
|
+
};
|
|
43
|
+
case 'Disabled':
|
|
44
|
+
return {
|
|
45
|
+
prefix: theme.t(`ColorTextStateDisabled${suffix}`),
|
|
46
|
+
price: theme.t(`ColorTextStateDisabled${suffix}`),
|
|
47
|
+
};
|
|
48
|
+
case 'Default':
|
|
49
|
+
default:
|
|
50
|
+
return {
|
|
51
|
+
...colors,
|
|
52
|
+
price: theme.t(`ColorTextBrand${suffix}`),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, [status, theme, suffix, colors]);
|
|
56
|
+
}
|
|
57
|
+
export function PxPrice({ amount, prefix, suffix, status = 'Default', inverted, testID, containerStyle, }) {
|
|
58
|
+
const [num, decimal] = useParsedPrice(amount);
|
|
59
|
+
const colors = usePriceColor(status, inverted);
|
|
60
|
+
const { theme } = useTheme();
|
|
61
|
+
// 1.5 factor because of this android issue: https://github.com/facebook/react-native/issues/29507
|
|
62
|
+
const lineHeight = theme.t('TextSizeBodyMMobile').number * 1.5;
|
|
63
|
+
return (React.createElement(Body, { style: [
|
|
64
|
+
containerStyle,
|
|
65
|
+
{
|
|
66
|
+
fontSize: theme.t('TextSizeBodyMMobile').number,
|
|
67
|
+
color: colors.prefix,
|
|
68
|
+
lineHeight,
|
|
69
|
+
},
|
|
70
|
+
], ...e2eID(testID) },
|
|
71
|
+
React.createElement(Text, null, prefix && prefix + ' '),
|
|
72
|
+
React.createElement(Header, { style: {
|
|
73
|
+
fontSize: theme.t('PriceSizeSignMMobile').number,
|
|
74
|
+
color: colors.price,
|
|
75
|
+
lineHeight,
|
|
76
|
+
} }, "\u20AC"),
|
|
77
|
+
React.createElement(Header, { style: {
|
|
78
|
+
fontSize: theme.t('PriceSizeUnitMMobile').number,
|
|
79
|
+
color: colors.price,
|
|
80
|
+
lineHeight,
|
|
81
|
+
} }, num),
|
|
82
|
+
React.createElement(Header, { style: {
|
|
83
|
+
fontSize: theme.t('PriceSizeDecimalMMobile').number,
|
|
84
|
+
color: colors.price,
|
|
85
|
+
lineHeight,
|
|
86
|
+
} },
|
|
87
|
+
".",
|
|
88
|
+
decimal),
|
|
89
|
+
React.createElement(Text, null, suffix)));
|
|
90
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PxPrice';
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@proximus/lavender-price-native",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Lavender native price component",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@proximus/lavender-common-native": "*",
|
|
13
|
+
"@proximus/lavender-styling-native": "*",
|
|
14
|
+
"@proximus/lavender-texts-native": "*"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
}
|
|
19
|
+
}
|