@m4l/components 9.1.76 → 9.1.77
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/ColumnUncertaintyFormatter/index.js +1 -1
- package/components/formatters/UncertaintyFormatter/UncertaintyFormatter.d.ts +53 -0
- package/components/formatters/UncertaintyFormatter/UncertaintyFormatter.js +54 -0
- package/components/formatters/UncertaintyFormatter/UncertaintyFormatter.styles.d.ts +2 -0
- package/components/formatters/UncertaintyFormatter/UncertaintyFormatter.styles.js +11 -0
- package/components/formatters/UncertaintyFormatter/constants.d.ts +1 -0
- package/components/formatters/UncertaintyFormatter/constants.js +4 -0
- package/components/formatters/UncertaintyFormatter/slots/UncertaintyFormatterEnum.d.ts +3 -0
- package/components/formatters/UncertaintyFormatter/slots/UncertaintyFormatterEnum.js +7 -0
- package/components/formatters/UncertaintyFormatter/slots/UncertaintyFormatterSlots.d.ts +1 -0
- package/components/formatters/UncertaintyFormatter/slots/UncertaintyFormatterSlots.js +12 -0
- package/components/formatters/UncertaintyFormatter/tests/UncertaintyFormatter.test.d.ts +1 -0
- package/components/formatters/UncertaintyFormatter/types.d.ts +45 -1
- package/components/formatters/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/components/formatters/UncertaintyFormatter/index.d.ts +0 -9
- package/components/formatters/UncertaintyFormatter/index.js +0 -29
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { U as UncertaintyFormatter } from "../../../formatters/UncertaintyFormatter/
|
|
2
|
+
import { U as UncertaintyFormatter } from "../../../formatters/UncertaintyFormatter/UncertaintyFormatter.js";
|
|
3
3
|
function ColumnUncertaintyFormatter(props) {
|
|
4
4
|
return (obProps) => {
|
|
5
5
|
return /* @__PURE__ */ jsx(UncertaintyFormatter, { obProps, ...props });
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { UncertaintyFormatterProps } from './types';
|
|
3
|
+
import { UncertaintyFormatterRootStyled } from './slots/UncertaintyFormatterSlots';
|
|
4
|
+
/**
|
|
5
|
+
* Formatea un conjunto de rangos de incertidumbre en una cadena legible.
|
|
6
|
+
* @param obProps - Objeto que contiene las propiedades de los rangos de incertidumbre.
|
|
7
|
+
* @param fieldValue - Nombre del campo que contiene los valores de los rangos.
|
|
8
|
+
* @param fieldSymbol - Nombre del campo que contiene el símbolo a utilizar.
|
|
9
|
+
* @param fieldUnit - Nombre del campo que contiene la unidad de medida.
|
|
10
|
+
* @returns Una cadena que representa los rangos de incertidumbre formateados.
|
|
11
|
+
* @example
|
|
12
|
+
* const obProps = {
|
|
13
|
+
* ranges: [
|
|
14
|
+
* { cmc_min: -20, cmc_max: 0.0, cmc_min_closed: true, cmc_max_closed: false, cmc_uncertainty: 0.5 },
|
|
15
|
+
* ],
|
|
16
|
+
* symbol: 'T',
|
|
17
|
+
* unit: '°C'
|
|
18
|
+
* };
|
|
19
|
+
* const result = getUncertaintyFormat(obProps, 'ranges', 'symbol', 'unit');
|
|
20
|
+
* console.log(result); // "[-20°C ≤ T < 0°C ± 0.5]"
|
|
21
|
+
*/
|
|
22
|
+
export declare function getUncertaintyFormat(obProps: any, fieldValue: string, fieldSymbol: string, fieldUnit: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Formatea y muestra valores de incertidumbre con estilo opcional.
|
|
25
|
+
* @param props - Las propiedades para el componente UncertaintyFormatter.
|
|
26
|
+
* @returns El valor de incertidumbre formateado envuelto en el componente especificado.
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
*
|
|
30
|
+
* const ObjFormatter = {
|
|
31
|
+
* ranges: [
|
|
32
|
+
* { cmc_min: -20,
|
|
33
|
+
* cmc_max: 0.0,
|
|
34
|
+
* cmc_min_closed: true,
|
|
35
|
+
* cmc_max_closed: false,
|
|
36
|
+
* cmc_uncertainty: 0.5 },
|
|
37
|
+
* ],
|
|
38
|
+
* symbol: 'T',
|
|
39
|
+
* unit: '°C',
|
|
40
|
+
* },
|
|
41
|
+
*
|
|
42
|
+
* <UncertaintyFormatter
|
|
43
|
+
* obProps = {ObjFormatter}
|
|
44
|
+
* fieldValue='ranges'
|
|
45
|
+
* fieldSymbol='symbol'
|
|
46
|
+
* fieldUnit='unit'
|
|
47
|
+
* color='text.primary'
|
|
48
|
+
* size='medium'
|
|
49
|
+
* variant='body'
|
|
50
|
+
* />
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function UncertaintyFormatter<T extends React.ElementType = typeof UncertaintyFormatterRootStyled>(props: UncertaintyFormatterProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { U as UncertaintyFormatterRootStyled } from "./slots/UncertaintyFormatterSlots.js";
|
|
6
|
+
import { g as getPropDataTestId } from "../../../test/getNameDataTestId.js";
|
|
7
|
+
import { a as getComponentSlotRoot } from "../../../utils/getComponentSlotRoot.js";
|
|
8
|
+
import { U as UNCERTAINTY_FORMATTER_KEY_COMPONENT } from "./constants.js";
|
|
9
|
+
import { U as UncertaintyFormatterSlots } from "./slots/UncertaintyFormatterEnum.js";
|
|
10
|
+
import { u as useComponentSize } from "../../../hooks/useComponentSize/useComponentSize.js";
|
|
11
|
+
function getUncertaintyFormat(obProps, fieldValue, fieldSymbol, fieldUnit) {
|
|
12
|
+
let result = "";
|
|
13
|
+
const ranges = getPropertyByString(obProps, fieldValue);
|
|
14
|
+
const symbol = getPropertyByString(obProps, fieldSymbol);
|
|
15
|
+
const unit = getPropertyByString(obProps, fieldUnit);
|
|
16
|
+
if (ranges === void 0 || ranges === null || !Array.isArray(ranges) || typeof symbol !== "string" || typeof unit !== "string") {
|
|
17
|
+
return "[]";
|
|
18
|
+
}
|
|
19
|
+
ranges.map((obj, idx) => {
|
|
20
|
+
const cmc_min_closed = obj.cmc_min_closed !== true ? "<" : "≤";
|
|
21
|
+
const cmc_max_closed = obj.cmc_max_closed !== true ? "<" : "≤";
|
|
22
|
+
result = result.concat(
|
|
23
|
+
`${idx > 0 ? " " : ""}`,
|
|
24
|
+
obj.cmc_min !== obj.cmc_max ? `[${obj.cmc_min}${unit} ${cmc_min_closed} ${symbol} ${cmc_max_closed} ${obj.cmc_max}${unit} ± ${obj.cmc_uncertainty}]` : `[${obj.cmc_min}${unit} ± ${obj.cmc_uncertainty}]`
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function UncertaintyFormatter(props) {
|
|
30
|
+
const { obProps, fieldValue, fieldSymbol, fieldUnit, Component = UncertaintyFormatterRootStyled, size = "medium", color, dataTestid, className } = props;
|
|
31
|
+
const { currentSize } = useComponentSize(size);
|
|
32
|
+
const formatterUncertainty = useMemo(
|
|
33
|
+
() => getUncertaintyFormat(obProps, fieldValue, fieldSymbol, fieldUnit),
|
|
34
|
+
[obProps, fieldValue, fieldSymbol, fieldUnit]
|
|
35
|
+
);
|
|
36
|
+
if (Component === React.Fragment) {
|
|
37
|
+
return /* @__PURE__ */ jsx(Fragment, { children: formatterUncertainty });
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ jsx(
|
|
40
|
+
Component,
|
|
41
|
+
{
|
|
42
|
+
size: currentSize,
|
|
43
|
+
variant: "body",
|
|
44
|
+
color,
|
|
45
|
+
className: clsx(getComponentSlotRoot(UNCERTAINTY_FORMATTER_KEY_COMPONENT), className),
|
|
46
|
+
...getPropDataTestId(UNCERTAINTY_FORMATTER_KEY_COMPONENT, UncertaintyFormatterSlots.root, dataTestid),
|
|
47
|
+
children: formatterUncertainty
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
UncertaintyFormatter as U,
|
|
53
|
+
getUncertaintyFormat as g
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UNCERTAINTY_FORMATTER_KEY_COMPONENT = "M4LUncertaintyFormatter";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UncertaintyFormatterRootStyled: 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/styles').Theme> & Record<string, unknown>, {}, {}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { styled } from "@mui/material/styles";
|
|
2
|
+
import { U as UNCERTAINTY_FORMATTER_KEY_COMPONENT } from "../constants.js";
|
|
3
|
+
import { u as uncertaintyFormatterStyles } from "../UncertaintyFormatter.styles.js";
|
|
4
|
+
import { U as UncertaintyFormatterSlots } from "./UncertaintyFormatterEnum.js";
|
|
5
|
+
import { T as Typography } from "../../../mui_extended/Typography/Typography.js";
|
|
6
|
+
const UncertaintyFormatterRootStyled = styled(Typography, {
|
|
7
|
+
name: UNCERTAINTY_FORMATTER_KEY_COMPONENT,
|
|
8
|
+
slot: UncertaintyFormatterSlots.root
|
|
9
|
+
})(uncertaintyFormatterStyles.root);
|
|
10
|
+
export {
|
|
11
|
+
UncertaintyFormatterRootStyled as U
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,58 @@
|
|
|
1
|
+
import { Sizes } from '@m4l/styles';
|
|
2
|
+
import { Theme } from '@mui/material';
|
|
3
|
+
import { M4LOverridesStyleRules } from 'src/@types/augmentations';
|
|
4
|
+
import { TypographyProps } from '../../mui_extended/Typography/types';
|
|
5
|
+
import { UncertaintyFormatterSlots as Slots } from './slots/UncertaintyFormatterEnum';
|
|
6
|
+
import { UNCERTAINTY_FORMATTER_KEY_COMPONENT } from './constants';
|
|
7
|
+
/**
|
|
8
|
+
* Representa un rango de incertidumbre con límites y una incertidumbre asociada.
|
|
9
|
+
*/
|
|
1
10
|
export interface UncertaintyRange {
|
|
11
|
+
/**
|
|
12
|
+
* Indica si el límite inferior está cerrado (≤) o abierto (<).
|
|
13
|
+
*/
|
|
2
14
|
cmc_min_closed: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Valor mínimo del rango.
|
|
17
|
+
*/
|
|
3
18
|
cmc_min: number;
|
|
19
|
+
/**
|
|
20
|
+
* Indica si el límite superior está cerrado (≤) o abierto (<).
|
|
21
|
+
*/
|
|
4
22
|
cmc_max_closed: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Valor máximo del rango.
|
|
25
|
+
*/
|
|
5
26
|
cmc_max: number;
|
|
27
|
+
/**
|
|
28
|
+
* Incertidumbre asociada al rango.
|
|
29
|
+
*/
|
|
6
30
|
cmc_uncertainty: number;
|
|
7
31
|
}
|
|
8
|
-
export interface UncertaintyFormatterProps {
|
|
32
|
+
export interface UncertaintyFormatterProps extends Pick<TypographyProps, 'color' | 'dataTestid' | 'className'> {
|
|
33
|
+
/**
|
|
34
|
+
* Componente personalizado que puede dar la presentación del formatter.
|
|
35
|
+
*/
|
|
9
36
|
Component?: React.ElementType;
|
|
37
|
+
/**
|
|
38
|
+
* Objeto de información que contine los valores que se van a utilizar en las propiedades fieldUnit y fieldValue.
|
|
39
|
+
*/
|
|
10
40
|
obProps: any;
|
|
41
|
+
/**
|
|
42
|
+
* Valor del campo que debe ser expresado en notación de cadena.
|
|
43
|
+
*/
|
|
11
44
|
fieldValue: string;
|
|
45
|
+
/**
|
|
46
|
+
* Valor del simbolo que debe ser expresado en notación de cadena.
|
|
47
|
+
*/
|
|
12
48
|
fieldSymbol: string;
|
|
49
|
+
/**
|
|
50
|
+
* Valor de la unidad de medida que debe ser expresado en notación de cadena.
|
|
51
|
+
*/
|
|
13
52
|
fieldUnit: string;
|
|
53
|
+
/**
|
|
54
|
+
* Tamaño del componente.
|
|
55
|
+
*/
|
|
56
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
14
57
|
}
|
|
58
|
+
export type UncertaintyFormatterStyles = M4LOverridesStyleRules<keyof typeof Slots, typeof UNCERTAINTY_FORMATTER_KEY_COMPONENT, Theme>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { BooleanFormatter } from './BooleanFormatter/BooleanFormatter';
|
|
2
2
|
export { useFormatDate as getFormatDate, DateFormatter } from './DateFormatter/DateFormatter';
|
|
3
|
-
export { UncertaintyFormatter, getUncertaintyFormat } from './UncertaintyFormatter';
|
|
3
|
+
export { UncertaintyFormatter, getUncertaintyFormat } from './UncertaintyFormatter/UncertaintyFormatter';
|
|
4
4
|
export { PointsFormatter, getFormatPoints } from './PointsFormatter/PointsFormatter';
|
|
5
5
|
export { getFormatConcatenated, ConcatenatedFormatter } from './ConcatenatedFormatter/ConcatenatedFormatter';
|
|
6
6
|
export { useFormatPeriod, PeriodFormatter } from './PeriodFormatter/PeriodFormatter';
|
package/index.js
CHANGED
|
@@ -43,7 +43,7 @@ import { R as R12 } from "./components/hook-form/RHFTextFieldPassword/RHFTextFie
|
|
|
43
43
|
import { R as R13 } from "./components/hook-form/RHFUpload/RHFUploadImage/RHFUploadImage.js";
|
|
44
44
|
import { B } from "./components/formatters/BooleanFormatter/BooleanFormatter.js";
|
|
45
45
|
import { D as D2, u as u4 } from "./components/formatters/DateFormatter/DateFormatter.js";
|
|
46
|
-
import { U, g as g7 } from "./components/formatters/UncertaintyFormatter/
|
|
46
|
+
import { U, g as g7 } from "./components/formatters/UncertaintyFormatter/UncertaintyFormatter.js";
|
|
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";
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { UncertaintyFormatterProps } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* TODO: Documentar
|
|
4
|
-
*/
|
|
5
|
-
export declare function getUncertaintyFormat(obProps: any, fieldValue: string, fieldSymbol: string, fieldUnit: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* TODO: Documentar
|
|
8
|
-
*/
|
|
9
|
-
export declare function UncertaintyFormatter(props: UncertaintyFormatterProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getPropertyByString } from "@m4l/core";
|
|
3
|
-
import { W as WrapperComponent } from "../../WrapperComponent/index.js";
|
|
4
|
-
function getUncertaintyFormat(obProps, fieldValue, fieldSymbol, fieldUnit) {
|
|
5
|
-
let result = "";
|
|
6
|
-
const ranges = getPropertyByString(obProps, fieldValue);
|
|
7
|
-
const symbol = getPropertyByString(obProps, fieldSymbol);
|
|
8
|
-
const unit = getPropertyByString(obProps, fieldUnit);
|
|
9
|
-
if (ranges === void 0 || ranges === null || !Array.isArray(ranges) || typeof symbol !== "string" || typeof unit !== "string") {
|
|
10
|
-
return "[]";
|
|
11
|
-
}
|
|
12
|
-
ranges.map((obj, idx) => {
|
|
13
|
-
const cmc_min_closed = obj.cmc_min_closed !== true ? "<" : "≤";
|
|
14
|
-
const cmc_max_closed = obj.cmc_max_closed !== true ? "<" : "≤";
|
|
15
|
-
result = result.concat(
|
|
16
|
-
`${idx > 0 ? " " : ""}`,
|
|
17
|
-
obj.cmc_min !== obj.cmc_max ? `[${obj.cmc_min}${unit} ${cmc_min_closed} ${symbol} ${cmc_max_closed} ${obj.cmc_max}${unit} ± ${obj.cmc_uncertainty}]` : `[${obj.cmc_min}${unit} ± ${obj.cmc_uncertainty}]`
|
|
18
|
-
);
|
|
19
|
-
});
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
function UncertaintyFormatter(props) {
|
|
23
|
-
const { obProps, fieldValue, fieldSymbol, fieldUnit, Component = WrapperComponent } = props;
|
|
24
|
-
return /* @__PURE__ */ jsx(Component, { children: getUncertaintyFormat(obProps, fieldValue, fieldSymbol, fieldUnit) });
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
UncertaintyFormatter as U,
|
|
28
|
-
getUncertaintyFormat as g
|
|
29
|
-
};
|