@m4l/components 9.1.75 → 9.1.76
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/components/DataGrid/formatters/ColumnPriceFormatter/index.js +1 -1
- package/components/formatters/PriceFormatter/PriceFormatter.d.ts +43 -0
- package/components/formatters/PriceFormatter/PriceFormatter.js +69 -0
- package/components/formatters/PriceFormatter/PriceFormatter.styles.d.ts +2 -0
- package/components/formatters/PriceFormatter/PriceFormatter.styles.js +11 -0
- package/components/formatters/PriceFormatter/constants.d.ts +1 -0
- package/components/formatters/PriceFormatter/constants.js +4 -0
- package/components/formatters/PriceFormatter/slots/PriceFormatterEnum.d.ts +3 -0
- package/components/formatters/PriceFormatter/slots/PriceFormatterEnum.js +7 -0
- package/components/formatters/PriceFormatter/slots/PriceFormatterSlots.d.ts +1 -0
- package/components/formatters/PriceFormatter/slots/PriceFormatterSlots.js +12 -0
- package/components/formatters/PriceFormatter/tests/PriceFormatter.test.d.ts +1 -0
- package/components/formatters/PriceFormatter/types.d.ts +21 -1
- package/components/formatters/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/components/formatters/PriceFormatter/index.d.ts +0 -9
- package/components/formatters/PriceFormatter/index.js +0 -35
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { P as PriceFormatter } from "../../../formatters/PriceFormatter/
|
|
2
|
+
import { P as PriceFormatter } from "../../../formatters/PriceFormatter/PriceFormatter.js";
|
|
3
3
|
function ColumnPriceFormatter(props) {
|
|
4
4
|
return (obProps) => {
|
|
5
5
|
return /* @__PURE__ */ jsx(PriceFormatter, { obProps, ...props });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { PriceFormatterProps } from './types';
|
|
3
|
+
import { PriceFormatterRootStyled } from './slots/PriceFormatterSlots';
|
|
4
|
+
/**
|
|
5
|
+
* Formatea un valor numérico como un precio en una moneda específica.
|
|
6
|
+
* @param {any} obProps - El objeto que contiene las propiedades.
|
|
7
|
+
* @param {string} fieldValue - El nombre de la propiedad dentro de obProps que contiene el valor a formatear.
|
|
8
|
+
* @param {string} currency - El código de la moneda (por ejemplo, 'USD' para dólares estadounidenses).
|
|
9
|
+
* @param {number} decimalDigits - La cantidad de dígitos decimales a mostrar.
|
|
10
|
+
* @returns {string} - El valor formateado como un precio en la moneda especificada.
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* const obProps = { price: '1234.56' };
|
|
14
|
+
* const formattedPrice = getFormatPrice(obProps, 'price', 'USD', 2);
|
|
15
|
+
* console.log(formattedPrice); // "$1,234.56" (suponiendo que el idioma del navegador es 'en-US')
|
|
16
|
+
*
|
|
17
|
+
* const formattedPriceEUR = getFormatPrice(obProps, 'price', 'EUR', 2);
|
|
18
|
+
* console.log(formattedPriceEUR); // "1.234,56 €" (suponiendo que el idioma del navegador es 'es-ES')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFormatPrice(obProps: any, fieldValue: string, currency: string, decimalDigits: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* El `PriceFormatter` es un componente de presentación diseñado para mostrar valores monetarios en el formato correcto según la configuración del sistema.
|
|
24
|
+
* Este componente asegura que los valores se representen en la divisa esperada, respetando las configuraciones de idioma, número de decimales y estilo visual definidos.
|
|
25
|
+
* @param {PriceFormatterProps} props - Las propiedades del componente.
|
|
26
|
+
* @returns {JSX.Element} - El componente `PriceFormatter` renderizado.
|
|
27
|
+
* @example
|
|
28
|
+
* ```
|
|
29
|
+
* import React from 'react';
|
|
30
|
+
* import { PriceFormatter } from './PriceFormatter';
|
|
31
|
+
*
|
|
32
|
+
* const obProps = { price: '1234.56' };
|
|
33
|
+
*
|
|
34
|
+
* function App() {
|
|
35
|
+
* return (
|
|
36
|
+
* <PriceFormatter obProps={obProps} fieldValue="price" size="medium" variant="body" />
|
|
37
|
+
* );
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* export default App;
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function PriceFormatter<T extends React.ElementType = typeof PriceFormatterRootStyled>(props: PriceFormatterProps): JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { clsx } from "clsx";
|
|
4
|
+
import { getPropertyByString } from "@m4l/core";
|
|
5
|
+
import { useFormatter } from "@m4l/graphics";
|
|
6
|
+
import { a as getComponentSlotRoot } from "../../../utils/getComponentSlotRoot.js";
|
|
7
|
+
import { g as getPropDataTestId } from "../../../test/getNameDataTestId.js";
|
|
8
|
+
import { P as PriceFormatterRootStyled } from "./slots/PriceFormatterSlots.js";
|
|
9
|
+
import { P as PRICE_FORMATTER_KEY_COMPONENT } from "./constants.js";
|
|
10
|
+
import { P as PriceFormatterSlots } from "./slots/PriceFormatterEnum.js";
|
|
11
|
+
import { u as useComponentSize } from "../../../hooks/useComponentSize/useComponentSize.js";
|
|
12
|
+
function getFormatPrice(obProps, fieldValue, currency, decimalDigits) {
|
|
13
|
+
let result = "";
|
|
14
|
+
const value = getPropertyByString(obProps, fieldValue);
|
|
15
|
+
if (isNaN(Number(value))) {
|
|
16
|
+
return Number("").toLocaleString(navigator.language, {
|
|
17
|
+
currency,
|
|
18
|
+
style: "currency",
|
|
19
|
+
currencyDisplay: "symbol",
|
|
20
|
+
useGrouping: true,
|
|
21
|
+
maximumFractionDigits: decimalDigits
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
result = Number(value).toLocaleString(navigator.language, {
|
|
26
|
+
currency,
|
|
27
|
+
style: "currency",
|
|
28
|
+
currencyDisplay: "symbol",
|
|
29
|
+
useGrouping: true,
|
|
30
|
+
maximumFractionDigits: decimalDigits
|
|
31
|
+
}) || "";
|
|
32
|
+
} catch (_e) {
|
|
33
|
+
result = Number(value).toLocaleString("en-US", {
|
|
34
|
+
style: "currency",
|
|
35
|
+
currency: "USD",
|
|
36
|
+
currencyDisplay: "symbol",
|
|
37
|
+
useGrouping: true,
|
|
38
|
+
maximumFractionDigits: decimalDigits
|
|
39
|
+
}) || "";
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function PriceFormatter(props) {
|
|
44
|
+
const { obProps, fieldValue, Component = PriceFormatterRootStyled, size = "medium", color, dataTestid, className } = props;
|
|
45
|
+
const { currentSize } = useComponentSize(size);
|
|
46
|
+
const { currencyFormatter } = useFormatter();
|
|
47
|
+
const formatterPrice = useMemo(
|
|
48
|
+
() => getFormatPrice(obProps, fieldValue, currencyFormatter.code, currencyFormatter.decimalDigits),
|
|
49
|
+
[obProps, fieldValue, currencyFormatter.code, currencyFormatter.decimalDigits]
|
|
50
|
+
);
|
|
51
|
+
if (Component === React.Fragment) {
|
|
52
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatterPrice });
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
Component,
|
|
56
|
+
{
|
|
57
|
+
variant: "body",
|
|
58
|
+
size: currentSize,
|
|
59
|
+
color,
|
|
60
|
+
className: clsx(getComponentSlotRoot(PRICE_FORMATTER_KEY_COMPONENT), className),
|
|
61
|
+
...getPropDataTestId(PRICE_FORMATTER_KEY_COMPONENT, PriceFormatterSlots.root, dataTestid),
|
|
62
|
+
children: formatterPrice
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
PriceFormatter as P,
|
|
68
|
+
getFormatPrice as g
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PRICE_FORMATTER_KEY_COMPONENT = "M4LPriceFormatter";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PriceFormatterRootStyled: import('@emotion/styled').StyledComponent<Pick<import('../../../mui_extended/Typography/types').TypographyProps, keyof import('../../../mui_extended/Typography/types').TypographyProps> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { styled } from "@mui/material";
|
|
2
|
+
import { P as PRICE_FORMATTER_KEY_COMPONENT } from "../constants.js";
|
|
3
|
+
import { p as priceFormatterStyles } from "../PriceFormatter.styles.js";
|
|
4
|
+
import { P as PriceFormatterSlots } from "./PriceFormatterEnum.js";
|
|
5
|
+
import { T as Typography } from "../../../mui_extended/Typography/Typography.js";
|
|
6
|
+
const PriceFormatterRootStyled = styled(Typography, {
|
|
7
|
+
name: PRICE_FORMATTER_KEY_COMPONENT,
|
|
8
|
+
slot: PriceFormatterSlots.root
|
|
9
|
+
})(priceFormatterStyles?.root);
|
|
10
|
+
export {
|
|
11
|
+
PriceFormatterRootStyled as P
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { Theme } from '@mui/material';
|
|
2
|
+
import { Sizes } from '@m4l/styles';
|
|
3
|
+
import { M4LOverridesStyleRules } from 'src/@types/augmentations';
|
|
4
|
+
import { TypographyProps } from '../../mui_extended/Typography/types';
|
|
5
|
+
import { PriceFormatterSlots } from './slots/PriceFormatterEnum';
|
|
6
|
+
import { PRICE_FORMATTER_KEY_COMPONENT } from './constants';
|
|
7
|
+
export interface PriceFormatterProps extends Pick<TypographyProps, 'color' | 'dataTestid' | 'className'> {
|
|
8
|
+
/**
|
|
9
|
+
* Componente personalizado que puede dar la presentación del formatter.
|
|
10
|
+
*/
|
|
2
11
|
Component?: React.ElementType;
|
|
12
|
+
/**
|
|
13
|
+
*Objeto de información que contine los valores que se van a utilizar en la propiedad price.
|
|
14
|
+
*/
|
|
3
15
|
obProps: any;
|
|
16
|
+
/**
|
|
17
|
+
* Valor del campo que debe ser expresado en notación de cadena.
|
|
18
|
+
*/
|
|
4
19
|
fieldValue: string;
|
|
20
|
+
/**
|
|
21
|
+
* Tamaño del componente.
|
|
22
|
+
*/
|
|
23
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
5
24
|
}
|
|
25
|
+
export type PriceFormatterStyles = M4LOverridesStyleRules<keyof typeof PriceFormatterSlots, typeof PRICE_FORMATTER_KEY_COMPONENT, Theme>;
|
|
@@ -4,6 +4,6 @@ export { UncertaintyFormatter, getUncertaintyFormat } from './UncertaintyFormatt
|
|
|
4
4
|
export { PointsFormatter, getFormatPoints } from './PointsFormatter/PointsFormatter';
|
|
5
5
|
export { getFormatConcatenated, ConcatenatedFormatter } from './ConcatenatedFormatter/ConcatenatedFormatter';
|
|
6
6
|
export { useFormatPeriod, PeriodFormatter } from './PeriodFormatter/PeriodFormatter';
|
|
7
|
-
export { PriceFormatter, getFormatPrice } from './PriceFormatter';
|
|
7
|
+
export { PriceFormatter, getFormatPrice } from './PriceFormatter/PriceFormatter';
|
|
8
8
|
export * from './DistanceToNowFormatter';
|
|
9
9
|
export type { UncertaintyRange } from './UncertaintyFormatter/types';
|
package/index.js
CHANGED
|
@@ -47,7 +47,7 @@ import { U, g as g7 } from "./components/formatters/UncertaintyFormatter/index.j
|
|
|
47
47
|
import { P as P2, g as g8 } from "./components/formatters/PointsFormatter/PointsFormatter.js";
|
|
48
48
|
import { C, g as g9 } from "./components/formatters/ConcatenatedFormatter/ConcatenatedFormatter.js";
|
|
49
49
|
import { P as P3, u as u5 } from "./components/formatters/PeriodFormatter/PeriodFormatter.js";
|
|
50
|
-
import { P as P4, g as g10 } from "./components/formatters/PriceFormatter/
|
|
50
|
+
import { P as P4, g as g10 } from "./components/formatters/PriceFormatter/PriceFormatter.js";
|
|
51
51
|
import { g as g11 } from "./components/formatters/DistanceToNowFormatter/dictionary.js";
|
|
52
52
|
import { D as D3 } from "./components/formatters/DistanceToNowFormatter/DistanceToNowFormatter.js";
|
|
53
53
|
import { g as g12 } from "./components/formatters/dictionary.js";
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PriceFormatterProps } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* TODO: Documentar
|
|
4
|
-
*/
|
|
5
|
-
export declare function getFormatPrice(obProps: any, fieldValue: string, currency: string, decimalDigits: number): string;
|
|
6
|
-
/**
|
|
7
|
-
* TODO: Documentar
|
|
8
|
-
*/
|
|
9
|
-
export declare function PriceFormatter(props: PriceFormatterProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getPropertyByString } from "@m4l/core";
|
|
3
|
-
import { useFormatter } from "@m4l/graphics";
|
|
4
|
-
import { W as WrapperComponent } from "../../WrapperComponent/index.js";
|
|
5
|
-
function getFormatPrice(obProps, fieldValue, currency, decimalDigits) {
|
|
6
|
-
let result = "";
|
|
7
|
-
const value = getPropertyByString(obProps, fieldValue);
|
|
8
|
-
try {
|
|
9
|
-
result = Number(value).toLocaleString(navigator.language, {
|
|
10
|
-
currency,
|
|
11
|
-
style: "currency",
|
|
12
|
-
currencyDisplay: "symbol",
|
|
13
|
-
useGrouping: true,
|
|
14
|
-
maximumFractionDigits: decimalDigits
|
|
15
|
-
}) || "";
|
|
16
|
-
} catch (_e) {
|
|
17
|
-
result = Number(value).toLocaleString("en-US", {
|
|
18
|
-
style: "currency",
|
|
19
|
-
currency: "USD",
|
|
20
|
-
currencyDisplay: "symbol",
|
|
21
|
-
useGrouping: true,
|
|
22
|
-
maximumFractionDigits: decimalDigits
|
|
23
|
-
}) || "";
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
function PriceFormatter(props) {
|
|
28
|
-
const { obProps, fieldValue, Component = WrapperComponent } = props;
|
|
29
|
-
const { currencyFormatter } = useFormatter();
|
|
30
|
-
return /* @__PURE__ */ jsx(Component, { children: getFormatPrice(obProps, fieldValue, currencyFormatter.code, currencyFormatter.decimalDigits) });
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
PriceFormatter as P,
|
|
34
|
-
getFormatPrice as g
|
|
35
|
-
};
|