@hortiview/shared-components 0.0.10589 → 0.0.11114
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/README.md +59 -0
- package/dist/assets/formNumber.css +1 -0
- package/dist/components/Filter/Filter.js +3 -2
- package/dist/components/FormComponents/FormNumber/CustomTextField.d.ts +34 -0
- package/dist/components/FormComponents/FormNumber/CustomTextField.js +40 -0
- package/dist/components/FormComponents/FormNumber/FormNumber.d.ts +98 -0
- package/dist/components/FormComponents/FormNumber/FormNumber.js +63 -0
- package/dist/components/FormComponents/FormNumber/FormNumber.test.d.ts +1 -0
- package/dist/components/FormComponents/FormNumber/FormNumber.test.js +51 -0
- package/dist/components/FormattedNumberDisplay/FormattedNumberDisplay.d.ts +57 -0
- package/dist/components/FormattedNumberDisplay/FormattedNumberDisplay.js +29 -0
- package/dist/components/GenericTable/GenericTable.js +3 -2
- package/dist/formNumber.module-BA05Gi6_.js +7 -0
- package/dist/main.d.ts +5 -1
- package/dist/main.js +61 -54
- package/dist/react-number-format.es-BeIT_PM7.js +561 -0
- package/dist/services/NumberService.d.ts +10 -0
- package/dist/services/NumberService.js +17 -0
- package/dist/services/UtilService.d.ts +12 -0
- package/dist/services/UtilService.js +18 -11
- package/dist/types/Languages.d.ts +3 -0
- package/dist/types/Languages.js +7 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -33,9 +33,11 @@ Additionally the library provides form components using [react-hook-form](https:
|
|
|
33
33
|
1. [Disclaimer](#disclaimer)
|
|
34
34
|
1. [EmptyView](#emptyview)
|
|
35
35
|
1. [Filter](#filter)
|
|
36
|
+
1. [FormattedNumberDisplay] (#formattednumberdisplay)
|
|
36
37
|
1. [FormComponents](#formcomponents)
|
|
37
38
|
1. [FormCheckBox](#formcheckbox)
|
|
38
39
|
1. [FormDatePicker](#formdatepicker)
|
|
40
|
+
1. [FormNumber] (#formnumber)
|
|
39
41
|
1. [FormRadio](#formradio)
|
|
40
42
|
1. [FormSelect](#formselect)
|
|
41
43
|
1. [FormSlider](#formslider)
|
|
@@ -296,6 +298,22 @@ const MyComponent = () => {
|
|
|
296
298
|
export default MyComponent;
|
|
297
299
|
```
|
|
298
300
|
|
|
301
|
+
### FormattedNumberDisplay
|
|
302
|
+
|
|
303
|
+
A component to display a formatted number based on the given language code, wrapped in a given typography component to style it as needed.
|
|
304
|
+
|
|
305
|
+
The typography component that is passed to the FormattedNumberDisplay needs the "children" property to which the formatted number will be added.
|
|
306
|
+
|
|
307
|
+
```jsx
|
|
308
|
+
import { FormattedNumberDisplay } from '@hortiview/shared-components';
|
|
309
|
+
|
|
310
|
+
const TypoDisplay3 = (props: { children: React.ReactNode }) => {
|
|
311
|
+
return <TypoDisplay level={3}>{props.children}</TypoDisplay>;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
<FormattedNumberDisplay typographyComponent={TypoDisplay3} languageCode="en-MX" value={12345.67} />;
|
|
315
|
+
```
|
|
316
|
+
|
|
299
317
|
### FormComponents
|
|
300
318
|
|
|
301
319
|
The library provides some form components based on [react-hook-form](https://react-hook-form.com/). The components can only be use within a form provided by react-hook-form.
|
|
@@ -362,6 +380,36 @@ const { handleSubmit } = formMethods;
|
|
|
362
380
|
</FormProvider>;
|
|
363
381
|
```
|
|
364
382
|
|
|
383
|
+
#### FormNumber
|
|
384
|
+
|
|
385
|
+
Number input field that formats the users input depending on the user language. The component automatically sets the language specific thousand separators and only allows the language specific decimal separators.
|
|
386
|
+
|
|
387
|
+
```jsx
|
|
388
|
+
import { FormNumber } from '@hortiview/shared-components';
|
|
389
|
+
import { FormProvider, SubmitHandler, useForm } from 'react-hook-form';
|
|
390
|
+
|
|
391
|
+
const formMethods = useForm<{ birthday: string }>({
|
|
392
|
+
mode: 'onSubmit',
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const { handleSubmit } = formMethods;
|
|
396
|
+
|
|
397
|
+
<FormProvider {...formMethods}>
|
|
398
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
399
|
+
<FormNumber<{ price: number }>
|
|
400
|
+
propertyName='price'
|
|
401
|
+
label='module.price'
|
|
402
|
+
languageCode="es-MX"
|
|
403
|
+
decimalScale={5}
|
|
404
|
+
fixedDecimalScale={true}
|
|
405
|
+
allowNegative={false}
|
|
406
|
+
allowLeadingZeros={false}
|
|
407
|
+
prefix=" €"
|
|
408
|
+
/>
|
|
409
|
+
</form>
|
|
410
|
+
</FormProvider>;
|
|
411
|
+
```
|
|
412
|
+
|
|
365
413
|
#### FormRadio
|
|
366
414
|
|
|
367
415
|
Provides a radio button form component
|
|
@@ -918,3 +966,14 @@ https://github.com/microsoft/TypeScript/issues/15300
|
|
|
918
966
|
```typescript
|
|
919
967
|
const trimmedData = trimLeadingAndTrailingSpaces({ ...data });
|
|
920
968
|
```
|
|
969
|
+
|
|
970
|
+
### getNumberAsLocaleString
|
|
971
|
+
|
|
972
|
+
Receives a number and returns the value as a locale string.
|
|
973
|
+
Note: Should only be used for displaying numbers, not for calculations or values that are supposed to be send to the backend.
|
|
974
|
+
|
|
975
|
+
```typescript
|
|
976
|
+
const userLocale = 'es-MX';
|
|
977
|
+
|
|
978
|
+
const overlineTitle = `${getNumberAsLocaleString(userLocale, totalArea, 5)} ${t('squaremeter-unit')}`;
|
|
979
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._invalid_1dsbr_1+*[class*=mdc-text-field-helper-line] *[class*=mdc-text-field-helper-text]{color:var(--lmnt-theme-danger)!important}
|
|
@@ -33,10 +33,11 @@ import "../../loadingSpinner.module-CLtqSMWA.js";
|
|
|
33
33
|
import "../Scrollbar/Scrollbar.js";
|
|
34
34
|
import "react-hook-form";
|
|
35
35
|
import "../../formDatePicker.module-BV3ma_7y.js";
|
|
36
|
+
import "../../formNumber.module-BA05Gi6_.js";
|
|
36
37
|
import "../../formSelect.module-PUiLDSD4.js";
|
|
37
38
|
import "../../formText.module-C0by6_DK.js";
|
|
38
39
|
import "../../isPlainObject-BlCDf1Kc.js";
|
|
39
|
-
const
|
|
40
|
+
const bt = ({
|
|
40
41
|
clearFilterText: f,
|
|
41
42
|
closeCallback: m,
|
|
42
43
|
currentFilter: i,
|
|
@@ -180,5 +181,5 @@ const Nt = ({
|
|
|
180
181
|
);
|
|
181
182
|
};
|
|
182
183
|
export {
|
|
183
|
-
|
|
184
|
+
bt as Filter
|
|
184
185
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TextfieldProps } from '@element/react-components';
|
|
2
|
+
import { ControllerRenderProps, FieldValues, Path } from 'react-hook-form';
|
|
3
|
+
import { InputAttributes, NumericFormatProps } from 'react-number-format';
|
|
4
|
+
type CustomTextFieldProps<T extends FieldValues> = Pick<TextfieldProps, 'className' | 'disabled' | 'fullWidth' | 'helperText' | 'helperTextPersistent' | 'helperTextValidation' | 'label' | 'leadingIcon' | 'placeholder' | 'trailingIcon' | 'variant'> & {
|
|
5
|
+
/**
|
|
6
|
+
* the path to the property
|
|
7
|
+
* @example address.addressLine1
|
|
8
|
+
*/
|
|
9
|
+
propertyName: Path<T>;
|
|
10
|
+
/** a suffix to be shown before the number */
|
|
11
|
+
suffix?: string;
|
|
12
|
+
/** a prefix to be shown after the number */
|
|
13
|
+
prefix?: string;
|
|
14
|
+
/**
|
|
15
|
+
* the trigger to validate the field
|
|
16
|
+
* @default 'none'
|
|
17
|
+
* @value 'onBlur' | 'onChange' | 'none'
|
|
18
|
+
*/
|
|
19
|
+
additionalTrigger?: 'onBlur' | 'onChange' | 'none';
|
|
20
|
+
/** value to be used as default when no value is provided */
|
|
21
|
+
defaultValue?: string;
|
|
22
|
+
/**
|
|
23
|
+
* React Hook Form properties
|
|
24
|
+
*/
|
|
25
|
+
formOnBlur: ControllerRenderProps<T>['onBlur'];
|
|
26
|
+
/**
|
|
27
|
+
* React Number Format properties
|
|
28
|
+
*/
|
|
29
|
+
value: NumericFormatProps['value'];
|
|
30
|
+
onBlur?: InputAttributes['onBlur'];
|
|
31
|
+
onChange?: NumericFormatProps['onChange'];
|
|
32
|
+
};
|
|
33
|
+
export declare const CustomTextField: <T extends FieldValues>({ ...props }: CustomTextFieldProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { Textfield as u } from "@element/react-components";
|
|
3
|
+
import { get as d } from "lodash";
|
|
4
|
+
import { useMemo as f } from "react";
|
|
5
|
+
import { useFormContext as g } from "react-hook-form";
|
|
6
|
+
import { s as v } from "../../../formNumber.module-BA05Gi6_.js";
|
|
7
|
+
const s = ({ ...e }) => {
|
|
8
|
+
const {
|
|
9
|
+
getFieldState: r,
|
|
10
|
+
formState: { errors: n },
|
|
11
|
+
trigger: i,
|
|
12
|
+
watch: o
|
|
13
|
+
} = g(), a = o(e.propertyName), l = f(() => {
|
|
14
|
+
if (!(!a || e.value === null))
|
|
15
|
+
return e.value;
|
|
16
|
+
}, [a, e.value]);
|
|
17
|
+
return /* @__PURE__ */ m(
|
|
18
|
+
u,
|
|
19
|
+
{
|
|
20
|
+
...e,
|
|
21
|
+
value: l,
|
|
22
|
+
"data-testid": `numeric-field-${e.propertyName}`,
|
|
23
|
+
fullWidth: !0,
|
|
24
|
+
inputMode: "decimal",
|
|
25
|
+
variant: "outlined",
|
|
26
|
+
onBlur: (t) => {
|
|
27
|
+
e.onBlur?.(t), e.formOnBlur(), e.additionalTrigger === "onBlur" && i(e.propertyName);
|
|
28
|
+
},
|
|
29
|
+
onChange: (t) => {
|
|
30
|
+
e.onChange?.(t), e.additionalTrigger === "onChange" && i(e.propertyName);
|
|
31
|
+
},
|
|
32
|
+
valid: !r(e.propertyName).invalid,
|
|
33
|
+
helperTextPersistent: d(n, e.propertyName) !== void 0 || e.helperTextPersistent,
|
|
34
|
+
className: r(e.propertyName).invalid ? v.invalid : ""
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
s as CustomTextField
|
|
40
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TextfieldProps } from '@element/react-components';
|
|
2
|
+
import { FieldValues, Path } from 'react-hook-form';
|
|
3
|
+
import { NumericFormatProps } from 'react-number-format';
|
|
4
|
+
import { LANGUAGE_COUNTRY_CODES } from '../../../types/Languages';
|
|
5
|
+
export type FormNumberProps<T extends FieldValues> = {
|
|
6
|
+
/**
|
|
7
|
+
* the language code to use for formatting the number
|
|
8
|
+
*/
|
|
9
|
+
languageCode: LANGUAGE_COUNTRY_CODES;
|
|
10
|
+
/**
|
|
11
|
+
* the path to the property for React Hook Form
|
|
12
|
+
* @example address.addressLine1
|
|
13
|
+
*/
|
|
14
|
+
propertyName: Path<T>;
|
|
15
|
+
/**
|
|
16
|
+
* an additional trigger to validate the field
|
|
17
|
+
* @default 'likeForm'
|
|
18
|
+
* @value 'onBlur' | 'onChange' | 'likeForm'
|
|
19
|
+
*/
|
|
20
|
+
additionalTrigger?: 'onBlur' | 'onChange' | 'none';
|
|
21
|
+
/**
|
|
22
|
+
* the maximal allowed number input
|
|
23
|
+
*/
|
|
24
|
+
maxValue?: number;
|
|
25
|
+
} & Pick<TextfieldProps, 'className' | 'disabled' | 'helperText' | 'helperTextPersistent' | 'helperTextValidation' | 'label' | 'leadingIcon' | 'trailingIcon'> & Partial<Pick<NumericFormatProps,
|
|
26
|
+
/**
|
|
27
|
+
* limits the number of digits after the decimal point
|
|
28
|
+
*/
|
|
29
|
+
'decimalScale'
|
|
30
|
+
/**
|
|
31
|
+
* @default false
|
|
32
|
+
* if true it adds 0s after the decimal separator to match given decimalScale
|
|
33
|
+
*/
|
|
34
|
+
| 'fixedDecimalScale'
|
|
35
|
+
/**
|
|
36
|
+
* @default true
|
|
37
|
+
* if false negative numbers are not allowed
|
|
38
|
+
*/
|
|
39
|
+
| 'allowNegative'
|
|
40
|
+
/**
|
|
41
|
+
* @default false
|
|
42
|
+
* By default, on blur of an input, leading zeros are removed
|
|
43
|
+
*/
|
|
44
|
+
| 'allowLeadingZeros'
|
|
45
|
+
/**
|
|
46
|
+
* A checker function to validate the input value.
|
|
47
|
+
* If this function returns false, the onChange method will not get triggered
|
|
48
|
+
* and the input value will not change.
|
|
49
|
+
* @example
|
|
50
|
+
* <NumericFormat
|
|
51
|
+
* value={11}
|
|
52
|
+
* isAllowed={(values) => {
|
|
53
|
+
* const { floatValue } = values;
|
|
54
|
+
* return floatValue < MAX_LIMIT;
|
|
55
|
+
* }}
|
|
56
|
+
* />;
|
|
57
|
+
*/
|
|
58
|
+
| 'isAllowed'
|
|
59
|
+
/** a suffix to be shown before the number */
|
|
60
|
+
| 'suffix'
|
|
61
|
+
/** a prefix to be shown after the number */
|
|
62
|
+
| 'prefix'>>;
|
|
63
|
+
/**
|
|
64
|
+
* Number input field that formats the user input depending on the user language
|
|
65
|
+
* the input automatically sets the language specific thousand separators
|
|
66
|
+
* and only allows the language specific decimal separators.
|
|
67
|
+
* Note: This component is supposed to be used with react-hook-form.
|
|
68
|
+
*
|
|
69
|
+
* @param languageCode The language code for formatting the number. Supported values are 'de-DE', 'es-MX', 'fr-FR', 'en-US', 'de-CH'. Default is 'es-MX'.
|
|
70
|
+
* @param propertyName The path to the property for React Hook Form.
|
|
71
|
+
* @param additionalTrigger An additional trigger to validate the field. Supported values are 'onBlur', 'onChange', 'none'. Default is 'none'.
|
|
72
|
+
* @param maxValue The maximal allowed number input.
|
|
73
|
+
* @param decimalScale Limits the number of digits after the decimal point.
|
|
74
|
+
* @param allowNegative If false, negative numbers are not allowed. Default is true.
|
|
75
|
+
* @param fixedDecimalScale If true, it adds 0s after the decimal separator to match the given decimalScale. Default is false.
|
|
76
|
+
* @param allowLeadingZeros If true, leading zeros are allowed. Default is false.
|
|
77
|
+
* @param isAllowed A checker function to validate the input value. If this function returns false, the onChange method will not get triggered and the input value will not change.
|
|
78
|
+
* @example
|
|
79
|
+
* <NumericFormat
|
|
80
|
+
* value={11}
|
|
81
|
+
* isAllowed={(values) => {
|
|
82
|
+
* const { floatValue } = values;
|
|
83
|
+
* return floatValue < MAX_LIMIT;
|
|
84
|
+
* }}
|
|
85
|
+
* @param suffix A suffix to be shown after the number.
|
|
86
|
+
* @param prefix A prefix to be shown before the number.
|
|
87
|
+
* @param className The class name for the component.
|
|
88
|
+
* @param disabled If true, the input will be disabled.
|
|
89
|
+
* @param helperText The helper text for the input.
|
|
90
|
+
* @param helperTextValidation The validation helper text for the input.
|
|
91
|
+
* @param helperTextPersistent If true, the helper text will persist. Default is true.
|
|
92
|
+
* @param label The label for the input.
|
|
93
|
+
* @param leadingIcon The leading icon for the input.
|
|
94
|
+
* @param placeholder The placeholder text for the input.
|
|
95
|
+
* @param trailingIcon The trailing icon for the input.
|
|
96
|
+
* @returns a JSX element that renders a number input field
|
|
97
|
+
*/
|
|
98
|
+
export declare const FormNumber: <T extends FieldValues>({ decimalScale, helperTextPersistent, languageCode, additionalTrigger, ...props }: FormNumberProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import { g as p } from "../../../get-BJn2Enx7.js";
|
|
3
|
+
import { useMemo as h } from "react";
|
|
4
|
+
import { useFormContext as S, Controller as T } from "react-hook-form";
|
|
5
|
+
import { N as g } from "../../../react-number-format.es-BeIT_PM7.js";
|
|
6
|
+
import { useDecimalSeparator as y, useThousandSeparator as F } from "../../../services/NumberService.js";
|
|
7
|
+
import { CustomTextField as V } from "./CustomTextField.js";
|
|
8
|
+
const B = ({
|
|
9
|
+
/**numeric format props */
|
|
10
|
+
decimalScale: l = 2,
|
|
11
|
+
/** TextField props */
|
|
12
|
+
helperTextPersistent: i = !0,
|
|
13
|
+
/** custom props */
|
|
14
|
+
languageCode: m = "es-MX",
|
|
15
|
+
additionalTrigger: s = "none",
|
|
16
|
+
...e
|
|
17
|
+
}) => {
|
|
18
|
+
const {
|
|
19
|
+
control: f,
|
|
20
|
+
formState: { errors: a }
|
|
21
|
+
} = S(), c = h(() => {
|
|
22
|
+
const o = p(a, e.propertyName);
|
|
23
|
+
if (o) {
|
|
24
|
+
const r = o.message;
|
|
25
|
+
return r || "Invalid input";
|
|
26
|
+
}
|
|
27
|
+
return e.helperText;
|
|
28
|
+
}, [a, e.propertyName, e.helperText]), d = y(m), x = F(m);
|
|
29
|
+
return /* @__PURE__ */ u(
|
|
30
|
+
T,
|
|
31
|
+
{
|
|
32
|
+
name: e.propertyName,
|
|
33
|
+
control: f,
|
|
34
|
+
render: ({ field: { value: o, onChange: r, onBlur: N } }) => /* @__PURE__ */ u(
|
|
35
|
+
g,
|
|
36
|
+
{
|
|
37
|
+
"data-testid": `form-number-${e.propertyName}`,
|
|
38
|
+
...e,
|
|
39
|
+
valueIsNumericString: !0,
|
|
40
|
+
value: o,
|
|
41
|
+
onValueChange: (t) => {
|
|
42
|
+
t.value === "" ? r(null) : r(Number(t.value));
|
|
43
|
+
},
|
|
44
|
+
decimalSeparator: d,
|
|
45
|
+
thousandSeparator: x,
|
|
46
|
+
decimalScale: l,
|
|
47
|
+
customInput: V,
|
|
48
|
+
isAllowed: (t) => {
|
|
49
|
+
const { floatValue: n } = t;
|
|
50
|
+
return n ? e.maxValue && n > e.maxValue ? !1 : e.isAllowed?.(t) ?? !0 : !0;
|
|
51
|
+
},
|
|
52
|
+
formOnBlur: N,
|
|
53
|
+
additionalTrigger: s,
|
|
54
|
+
helperText: c,
|
|
55
|
+
helperTextPersistent: i
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
B as FormNumber
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { a, s as n } from "../../../react.esm-CHvVvf3L.js";
|
|
3
|
+
import { FormNumber as s } from "./FormNumber.js";
|
|
4
|
+
import { v as e, d as m, t as f, g as r } from "../../../vi.JYQecGiw-BpOAB4v6.js";
|
|
5
|
+
const l = e.fn();
|
|
6
|
+
e.mock("react-hook-form", () => ({
|
|
7
|
+
...e.importActual("react-hook-form"),
|
|
8
|
+
Controller: ({
|
|
9
|
+
render: t
|
|
10
|
+
}) => t({
|
|
11
|
+
field: {
|
|
12
|
+
ref: void 0,
|
|
13
|
+
onChange: l,
|
|
14
|
+
value: 12345
|
|
15
|
+
},
|
|
16
|
+
formState: { defaultValue: { "de-DE": 234 } }
|
|
17
|
+
}),
|
|
18
|
+
useFormContext: () => ({
|
|
19
|
+
watch: e.fn(),
|
|
20
|
+
control: {
|
|
21
|
+
register: e.fn(),
|
|
22
|
+
unregister: e.fn(),
|
|
23
|
+
getFieldState: e.fn(),
|
|
24
|
+
_names: {
|
|
25
|
+
array: new Set("test"),
|
|
26
|
+
mount: new Set("test"),
|
|
27
|
+
unMount: new Set("test"),
|
|
28
|
+
watch: new Set("test"),
|
|
29
|
+
focus: "test",
|
|
30
|
+
watchAll: !1
|
|
31
|
+
},
|
|
32
|
+
_subjects: {
|
|
33
|
+
watch: e.fn(),
|
|
34
|
+
array: e.fn(),
|
|
35
|
+
state: e.fn()
|
|
36
|
+
},
|
|
37
|
+
_getWatch: e.fn(),
|
|
38
|
+
_formValues: ["test"],
|
|
39
|
+
_defaultValues: ["test"]
|
|
40
|
+
},
|
|
41
|
+
formState: { errors: {} },
|
|
42
|
+
getFieldState: () => ({ invalid: !1 })
|
|
43
|
+
})
|
|
44
|
+
}));
|
|
45
|
+
m("FormNumber Test", () => {
|
|
46
|
+
f("render FormNumber with correct properties", () => {
|
|
47
|
+
a(/* @__PURE__ */ o(s, { languageCode: "de-DE", propertyName: "de-DE" }));
|
|
48
|
+
const t = n.getByRole("textbox");
|
|
49
|
+
r(t).toBeInTheDocument(), r(t).toHaveAttribute("type", "text"), r(t).toHaveAttribute("inputmode", "decimal");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { NumericFormatProps } from 'react-number-format';
|
|
3
|
+
import { LANGUAGE_COUNTRY_CODES } from '../../types/Languages';
|
|
4
|
+
export type FormattedNumberDisplayProps = {
|
|
5
|
+
/**
|
|
6
|
+
* the number to format
|
|
7
|
+
*/
|
|
8
|
+
value: number;
|
|
9
|
+
/**
|
|
10
|
+
* the language code to use for formatting the number
|
|
11
|
+
*/
|
|
12
|
+
languageCode: LANGUAGE_COUNTRY_CODES;
|
|
13
|
+
/**
|
|
14
|
+
* the component that wraps the formatted number
|
|
15
|
+
* it should be used to apply styles to the number
|
|
16
|
+
*/
|
|
17
|
+
typographyComponent: React.ComponentType<PropsWithChildren>;
|
|
18
|
+
} & Pick<NumericFormatProps,
|
|
19
|
+
/**
|
|
20
|
+
* limits the number of digits after the decimal point
|
|
21
|
+
*/
|
|
22
|
+
'decimalScale'
|
|
23
|
+
/**
|
|
24
|
+
* @default false
|
|
25
|
+
* if true it adds 0s after the decimal separator to match given decimalScale
|
|
26
|
+
*/
|
|
27
|
+
| 'fixedDecimalScale'
|
|
28
|
+
/** a suffix to be shown before the number */
|
|
29
|
+
| 'suffix'
|
|
30
|
+
/** a prefix to be shown after the number */
|
|
31
|
+
| 'prefix'
|
|
32
|
+
/**
|
|
33
|
+
* @default true
|
|
34
|
+
* if false negative numbers are not allowed
|
|
35
|
+
*/
|
|
36
|
+
| 'allowNegative'
|
|
37
|
+
/**
|
|
38
|
+
* @default false
|
|
39
|
+
* By default, on blur of an input, leading zeros are removed
|
|
40
|
+
*/
|
|
41
|
+
| 'allowLeadingZeros'>;
|
|
42
|
+
/**
|
|
43
|
+
* A component to display a formatted number based on the given language code,
|
|
44
|
+
* wrapped in a given typography component to style it as needed.
|
|
45
|
+
*
|
|
46
|
+
* @param languageCode - The language code to use for formatting the number.
|
|
47
|
+
* @param typographyComponent - The component that wraps the formatted number. It should be used to apply styles to the number.
|
|
48
|
+
* It has to be a component with child since the formatted number will be passed as a child.
|
|
49
|
+
* @param decimalScale - Limits the number of digits after the decimal point.
|
|
50
|
+
* @param fixedDecimalScale - If true, it adds 0s after the decimal separator to match the given decimalScale. Default is false.
|
|
51
|
+
* @param suffix - A suffix to be shown before the number.
|
|
52
|
+
* @param prefix - A prefix to be shown after the number.
|
|
53
|
+
* @param allowNegative If false, negative numbers are not allowed. Default is true.
|
|
54
|
+
* @param allowLeadingZeros If true, leading zeros are allowed. Default is false.
|
|
55
|
+
* @returns A formatted number wrapped in the specified typography component.
|
|
56
|
+
*/
|
|
57
|
+
export declare const FormattedNumberDisplay: ({ typographyComponent: TypographyComponent, decimalScale, languageCode, ...props }: FormattedNumberDisplayProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { N as i } from "../../react-number-format.es-BeIT_PM7.js";
|
|
3
|
+
import { useDecimalSeparator as d, useThousandSeparator as n } from "../../services/NumberService.js";
|
|
4
|
+
const y = ({
|
|
5
|
+
typographyComponent: a,
|
|
6
|
+
/**numeric format props */
|
|
7
|
+
decimalScale: o = 2,
|
|
8
|
+
/** custom props */
|
|
9
|
+
languageCode: r = "es-MX",
|
|
10
|
+
...t
|
|
11
|
+
}) => {
|
|
12
|
+
const m = d(r), p = n(r);
|
|
13
|
+
return /* @__PURE__ */ e(
|
|
14
|
+
i,
|
|
15
|
+
{
|
|
16
|
+
"data-testid": "formatted-number-display",
|
|
17
|
+
...t,
|
|
18
|
+
value: t.value,
|
|
19
|
+
displayType: "text",
|
|
20
|
+
renderText: (s) => /* @__PURE__ */ e(a, { children: s }),
|
|
21
|
+
decimalSeparator: m,
|
|
22
|
+
thousandSeparator: p,
|
|
23
|
+
decimalScale: o
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
y as FormattedNumberDisplay
|
|
29
|
+
};
|
|
@@ -31,12 +31,13 @@ import "../../loadingSpinner.module-CLtqSMWA.js";
|
|
|
31
31
|
import "../Scrollbar/Scrollbar.js";
|
|
32
32
|
import "react-hook-form";
|
|
33
33
|
import "../../formDatePicker.module-BV3ma_7y.js";
|
|
34
|
+
import "../../formNumber.module-BA05Gi6_.js";
|
|
34
35
|
import "../../formSelect.module-PUiLDSD4.js";
|
|
35
36
|
import "../../formText.module-C0by6_DK.js";
|
|
36
37
|
import "../../isPlainObject-BlCDf1Kc.js";
|
|
37
38
|
import { useGenerateColumns as x, useGenerateTableData as _ } from "./GenericTableService.js";
|
|
38
39
|
import { GenericCardList as A } from "./Mobile/GenericCardList.js";
|
|
39
|
-
const
|
|
40
|
+
const br = ({
|
|
40
41
|
data: p = [],
|
|
41
42
|
hiddenColumns: l = [],
|
|
42
43
|
order: f = [],
|
|
@@ -119,5 +120,5 @@ const yr = ({
|
|
|
119
120
|
) });
|
|
120
121
|
};
|
|
121
122
|
export {
|
|
122
|
-
|
|
123
|
+
br as GenericTable
|
|
123
124
|
};
|
package/dist/main.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { DeleteModal } from './components/DeleteModal/DeleteModal';
|
|
|
8
8
|
export { Disclaimer } from './components/Disclaimer/Disclaimer';
|
|
9
9
|
export { EmptyView } from './components/EmptyView/EmptyView';
|
|
10
10
|
export { Filter } from './components/Filter/Filter';
|
|
11
|
+
export { FormattedNumberDisplay } from './components/FormattedNumberDisplay/FormattedNumberDisplay';
|
|
11
12
|
export { GenericTable } from './components/GenericTable/GenericTable';
|
|
12
13
|
export { HashTabView } from './components/HashTabView/HashTabView';
|
|
13
14
|
export { HeaderFilter } from './components/HeaderFilter/HeaderFilter';
|
|
@@ -23,6 +24,7 @@ export { SearchBar } from './components/SearchBar/SearchBar';
|
|
|
23
24
|
export { VerticalDivider } from './components/VerticalDivider/VerticalDivider';
|
|
24
25
|
export { FormCheckBox } from './components/FormComponents/FormCheckBox/FormCheckBox';
|
|
25
26
|
export { FormDatePicker } from './components/FormComponents/FormDatePicker/FormDatePicker';
|
|
27
|
+
export { FormNumber } from './components/FormComponents/FormNumber/FormNumber';
|
|
26
28
|
export { FormRadio } from './components/FormComponents/FormRadio/FormRadio';
|
|
27
29
|
export { FormSelect } from './components/FormComponents/FormSelect/FormSelect';
|
|
28
30
|
export { FormSlider } from './components/FormComponents/FormSlider/FormSlider';
|
|
@@ -30,7 +32,7 @@ export { FormText } from './components/FormComponents/FormText/FormText';
|
|
|
30
32
|
export { AvailableCustomIcons } from './enums/AvailableCustomIcons';
|
|
31
33
|
export { ThemeColor } from './enums/ThemeColor';
|
|
32
34
|
export { useBreakpoints } from './hooks/useBreakpoints';
|
|
33
|
-
export { capitalizeFirstLetters, trimLeadingAndTrailingSpaces } from './services/UtilService';
|
|
35
|
+
export { capitalizeFirstLetters, getNumberAsLocaleString, trimLeadingAndTrailingSpaces, } from './services/UtilService';
|
|
34
36
|
export type { ActionProps } from './components/ContextMenu/ContextMenu';
|
|
35
37
|
export type { FormSelectOption } from './components/FormComponents/FormSelect/FormSelect';
|
|
36
38
|
export type { FormTextProps } from './components/FormComponents/FormText/FormText';
|
|
@@ -39,3 +41,5 @@ export type { FilterData, FilterOption, FilterSelection } from './types/Filter';
|
|
|
39
41
|
export type { CellTemplate, CellTemplateProps, TableLayoutProps } from './types/GenericTable';
|
|
40
42
|
export type { HashTab } from './types/HashTab';
|
|
41
43
|
export type { BaseListElement, ListElement } from './types/ListElement';
|
|
44
|
+
export { LANGUAGE_CODES_MAPPER } from './types/Languages';
|
|
45
|
+
export type { LANGUAGE_CODES, LANGUAGE_COUNTRY_CODES } from './types/Languages';
|