currency-fomatter 1.3.2 → 1.4.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/README.md +558 -35
- package/dist/cjs/components/currency/hooks.d.ts +52 -0
- package/dist/cjs/components/currency/hooks.js +130 -0
- package/dist/cjs/components/currency/hooks.js.map +1 -0
- package/dist/cjs/components/currency/index.d.ts +44 -107
- package/dist/cjs/components/currency/index.js +509 -505
- package/dist/cjs/components/currency/index.js.map +1 -1
- package/dist/cjs/components/currency/locales.d.ts +55 -0
- package/dist/cjs/components/currency/locales.js +382 -0
- package/dist/cjs/components/currency/locales.js.map +1 -0
- package/dist/cjs/components/currency/utils.d.ts +108 -20
- package/dist/cjs/components/currency/utils.js +344 -70
- package/dist/cjs/components/currency/utils.js.map +1 -1
- package/dist/cjs/components/test/index.d.ts +3 -6
- package/dist/cjs/components/test/index.js +121 -15
- package/dist/cjs/components/test/index.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +19 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/currency/hooks.d.ts +52 -0
- package/dist/esm/components/currency/hooks.js +126 -0
- package/dist/esm/components/currency/hooks.js.map +1 -0
- package/dist/esm/components/currency/index.d.ts +44 -107
- package/dist/esm/components/currency/index.js +497 -508
- package/dist/esm/components/currency/index.js.map +1 -1
- package/dist/esm/components/currency/locales.d.ts +55 -0
- package/dist/esm/components/currency/locales.js +370 -0
- package/dist/esm/components/currency/locales.js.map +1 -0
- package/dist/esm/components/currency/utils.d.ts +108 -20
- package/dist/esm/components/currency/utils.js +338 -66
- package/dist/esm/components/currency/utils.js.map +1 -1
- package/dist/esm/components/test/index.d.ts +3 -6
- package/dist/esm/components/test/index.js +123 -16
- package/dist/esm/components/test/index.js.map +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +13 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -3
|
@@ -2,21 +2,127 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
5
|
+
var currency_1 = tslib_1.__importDefault(require("../currency"));
|
|
6
|
+
// Example 1: Basic Currency Format
|
|
7
|
+
var BasicCurrencyExample = function () {
|
|
8
|
+
var _a = (0, react_1.useState)("1234567.89"), value = _a[0], setValue = _a[1];
|
|
9
|
+
var handleValueChange = function (values) {
|
|
10
|
+
console.log("Basic:", values);
|
|
11
|
+
setValue(values.value);
|
|
10
12
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
14
|
+
react_1.default.createElement("h3", null, "1. Basic Currency Format"),
|
|
15
|
+
react_1.default.createElement(currency_1.default, { value: value, thousandSeparator: ",", decimalSeparator: ".", prefix: "$", decimalScale: 2, fixedDecimalScale: true, onValueChange: handleValueChange, placeholder: "Enter amount", style: { padding: 8, fontSize: 16 } }),
|
|
16
|
+
react_1.default.createElement("p", null,
|
|
17
|
+
"Value: ",
|
|
18
|
+
value)));
|
|
19
|
+
};
|
|
20
|
+
// Example 2: Phone Number Format
|
|
21
|
+
var PhoneNumberExample = function () {
|
|
22
|
+
var _a = (0, react_1.useState)(""), value = _a[0], setValue = _a[1];
|
|
23
|
+
var handleValueChange = function (values) {
|
|
24
|
+
console.log("Phone:", values);
|
|
25
|
+
setValue(values.value);
|
|
26
|
+
};
|
|
27
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
28
|
+
react_1.default.createElement("h3", null, "2. Phone Number Format"),
|
|
29
|
+
react_1.default.createElement(currency_1.default, { format: "+1 (###) ###-####", mask: "_", onValueChange: handleValueChange, placeholder: "+1 (___) ___-____", style: { padding: 8, fontSize: 16 } }),
|
|
30
|
+
react_1.default.createElement("p", null,
|
|
31
|
+
"Value: ",
|
|
32
|
+
value)));
|
|
33
|
+
};
|
|
34
|
+
// Example 3: Credit Card Format
|
|
35
|
+
var CreditCardExample = function () {
|
|
36
|
+
var _a = (0, react_1.useState)(""), value = _a[0], setValue = _a[1];
|
|
37
|
+
var handleValueChange = function (values) {
|
|
38
|
+
console.log("Card:", values);
|
|
39
|
+
setValue(values.value);
|
|
40
|
+
};
|
|
41
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
42
|
+
react_1.default.createElement("h3", null, "3. Credit Card Format"),
|
|
43
|
+
react_1.default.createElement(currency_1.default, { format: "#### #### #### ####", mask: "_", onValueChange: handleValueChange, placeholder: "____ ____ ____ ____", style: { padding: 8, fontSize: 16 } }),
|
|
44
|
+
react_1.default.createElement("p", null,
|
|
45
|
+
"Value: ",
|
|
46
|
+
value)));
|
|
47
|
+
};
|
|
48
|
+
// Example 4: Percentage Format
|
|
49
|
+
var PercentageExample = function () {
|
|
50
|
+
var _a = (0, react_1.useState)("75.5"), value = _a[0], setValue = _a[1];
|
|
51
|
+
var handleValueChange = function (values) {
|
|
52
|
+
console.log("Percentage:", values);
|
|
53
|
+
setValue(values.value);
|
|
54
|
+
};
|
|
55
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
56
|
+
react_1.default.createElement("h3", null, "4. Percentage Format"),
|
|
57
|
+
react_1.default.createElement(currency_1.default, { value: value, suffix: "%", decimalScale: 2, onValueChange: handleValueChange, isAllowed: function (values) {
|
|
58
|
+
var floatValue = values.floatValue;
|
|
59
|
+
return floatValue <= 100;
|
|
60
|
+
}, placeholder: "Enter percentage", style: { padding: 8, fontSize: 16 } }),
|
|
61
|
+
react_1.default.createElement("p", null,
|
|
62
|
+
"Value: ",
|
|
63
|
+
value,
|
|
64
|
+
"%")));
|
|
65
|
+
};
|
|
66
|
+
// Example 5: Indian Number System (Lakhs/Crores)
|
|
67
|
+
var IndianFormatExample = function () {
|
|
68
|
+
var _a = (0, react_1.useState)("1234567"), value = _a[0], setValue = _a[1];
|
|
69
|
+
var handleValueChange = function (values) {
|
|
70
|
+
console.log("Indian:", values);
|
|
71
|
+
setValue(values.value);
|
|
13
72
|
};
|
|
14
|
-
return (react_1.default.createElement("div",
|
|
15
|
-
react_1.default.createElement("
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
73
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
74
|
+
react_1.default.createElement("h3", null, "5. Indian Number System (12,34,567)"),
|
|
75
|
+
react_1.default.createElement(currency_1.default, { value: value, thousandSeparator: ",", thousandSpacing: "2s", prefix: "\u20B9", onValueChange: handleValueChange, style: { padding: 8, fontSize: 16 } }),
|
|
76
|
+
react_1.default.createElement("p", null,
|
|
77
|
+
"Value: ",
|
|
78
|
+
value)));
|
|
79
|
+
};
|
|
80
|
+
// Example 6: Display Type Text (Read-only)
|
|
81
|
+
var DisplayTextExample = function () {
|
|
82
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
83
|
+
react_1.default.createElement("h3", null, "6. Display Type Text (Read-only)"),
|
|
84
|
+
react_1.default.createElement(currency_1.default, { value: 9999.99, displayType: "text", thousandSeparator: ",", prefix: "$", decimalScale: 2, fixedDecimalScale: true })));
|
|
85
|
+
};
|
|
86
|
+
// Example 7: Custom Input Component
|
|
87
|
+
var CustomInputExample = function () {
|
|
88
|
+
var _a = (0, react_1.useState)("500"), value = _a[0], setValue = _a[1];
|
|
89
|
+
var CustomInput = function (props) { return (react_1.default.createElement("input", tslib_1.__assign({}, props, { style: {
|
|
90
|
+
padding: 12,
|
|
91
|
+
fontSize: 18,
|
|
92
|
+
border: "2px solid #007bff",
|
|
93
|
+
borderRadius: 8,
|
|
94
|
+
outline: "none",
|
|
95
|
+
} }))); };
|
|
96
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
97
|
+
react_1.default.createElement("h3", null, "7. Custom Input Component"),
|
|
98
|
+
react_1.default.createElement(currency_1.default, { value: value, customInput: CustomInput, thousandSeparator: ",", prefix: "$", onValueChange: function (values) { return setValue(values.value); } }),
|
|
99
|
+
react_1.default.createElement("p", null,
|
|
100
|
+
"Value: ",
|
|
101
|
+
value)));
|
|
102
|
+
};
|
|
103
|
+
// Example 8: Negative Numbers
|
|
104
|
+
var NegativeNumberExample = function () {
|
|
105
|
+
var _a = (0, react_1.useState)("-1234.56"), value = _a[0], setValue = _a[1];
|
|
106
|
+
return (react_1.default.createElement("div", { style: { marginBottom: 20 } },
|
|
107
|
+
react_1.default.createElement("h3", null, "8. Negative Numbers Allowed"),
|
|
108
|
+
react_1.default.createElement(currency_1.default, { value: value, thousandSeparator: ",", prefix: "$", allowNegative: true, decimalScale: 2, onValueChange: function (values) { return setValue(values.value); }, style: { padding: 8, fontSize: 16 } }),
|
|
109
|
+
react_1.default.createElement("p", null,
|
|
110
|
+
"Value: ",
|
|
111
|
+
value)));
|
|
112
|
+
};
|
|
113
|
+
// Main Example Component
|
|
114
|
+
var CurrencyFormatExamples = function () {
|
|
115
|
+
return (react_1.default.createElement("div", { style: { padding: 20, fontFamily: "Arial, sans-serif" } },
|
|
116
|
+
react_1.default.createElement("h1", null, "CurrencyFormat Component Examples"),
|
|
117
|
+
react_1.default.createElement("hr", null),
|
|
118
|
+
react_1.default.createElement(BasicCurrencyExample, null),
|
|
119
|
+
react_1.default.createElement(PhoneNumberExample, null),
|
|
120
|
+
react_1.default.createElement(CreditCardExample, null),
|
|
121
|
+
react_1.default.createElement(PercentageExample, null),
|
|
122
|
+
react_1.default.createElement(IndianFormatExample, null),
|
|
123
|
+
react_1.default.createElement(DisplayTextExample, null),
|
|
124
|
+
react_1.default.createElement(CustomInputExample, null),
|
|
125
|
+
react_1.default.createElement(NegativeNumberExample, null)));
|
|
126
|
+
};
|
|
127
|
+
exports.default = CurrencyFormatExamples;
|
|
22
128
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/test/index.tsx"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/test/index.tsx"],"names":[],"mappings":";;;AAAA,qDAAwC;AACxC,iEAA0D;AAE1D,mCAAmC;AACnC,IAAM,oBAAoB,GAAG;IACrB,IAAA,KAAoB,IAAA,gBAAQ,EAAC,YAAY,CAAC,EAAzC,KAAK,QAAA,EAAE,QAAQ,QAA0B,CAAC;IAEjD,IAAM,iBAAiB,GAAG,UAAC,MAAmB;QAC5C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC9B,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC;IAEF,OAAO,CACL,uCAAK,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;QAC9B,qEAAiC;QACjC,8BAAC,kBAAc,IACb,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAC,GAAG,EACrB,gBAAgB,EAAC,GAAG,EACpB,MAAM,EAAC,GAAG,EACV,YAAY,EAAE,CAAC,EACf,iBAAiB,QACjB,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAC,cAAc,EAC1B,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,GACnC;QACF;;YAAW,KAAK,CAAK,CACjB,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,iCAAiC;AACjC,IAAM,kBAAkB,GAAG;IACnB,IAAA,KAAoB,IAAA,gBAAQ,EAAC,EAAE,CAAC,EAA/B,KAAK,QAAA,EAAE,QAAQ,QAAgB,CAAC;IAEvC,IAAM,iBAAiB,GAAG,UAAC,MAAmB;QAC5C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC9B,QAAQ,CAAC,MAAM,CAAC,KAAK,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IAE/C,OAAO,CACL,uCAAK,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;QAC9B,wEAAoC;QACpC,8BAAC,kBAAc,IACb,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAC,GAAG,EACrB,MAAM,EAAC,GAAG,EACV,aAAa,EAAE,IAAI,EACnB,YAAY,EAAE,CAAC,EACf,aAAa,EAAE,UAAC,MAAM,IAAK,OAAA,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAtB,CAAsB,EACjD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,GACnC;QACF;;YAAW,KAAK,CAAK,CACjB,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,yBAAyB;AACzB,IAAM,sBAAsB,GAAG;IAC7B,OAAO,CACL,uCAAK,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,mBAAmB,EAAE;QAC1D,8EAA0C;QAC1C,yCAAM;QACN,8BAAC,oBAAoB,OAAG;QACxB,8BAAC,kBAAkB,OAAG;QACtB,8BAAC,iBAAiB,OAAG;QACrB,8BAAC,iBAAiB,OAAG;QACrB,8BAAC,mBAAmB,OAAG;QACvB,8BAAC,kBAAkB,OAAG;QACtB,8BAAC,kBAAkB,OAAG;QACtB,8BAAC,qBAAqB,OAAG,CACrB,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,sBAAsB,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import CurrencyFormat from
|
|
2
|
-
export { CurrencyFormat };
|
|
1
|
+
import CurrencyFormat, { formatCurrency, parseCurrency, formatCompact, parseCompact, defaultCompactDisplay, useCurrencyFormat, localePresets, getLocaleConfig, getFormatOptionsFromLocale, detectLocaleFormat, getCompactLabels, createLocaleConfig, getAutoLocaleConfig, formatWithIntl, registerLocale, unregisterLocale } from "./components/currency";
|
|
2
|
+
export { CurrencyFormat, formatCurrency, parseCurrency, formatCompact, parseCompact, defaultCompactDisplay, useCurrencyFormat, localePresets, getLocaleConfig, getFormatOptionsFromLocale, detectLocaleFormat, getCompactLabels, createLocaleConfig, getAutoLocaleConfig, formatWithIntl, registerLocale, unregisterLocale, };
|
|
3
|
+
export default CurrencyFormat;
|
|
4
|
+
export type { CurrencyFormatProps, ValueObject, ThousandSpacing, FormatFunction, RemoveFormattingFunction, IsAllowedFunction, OnValueChangeFunction, RenderTextFunction, FormatCurrencyOptions, ParseCurrencyOptions, CompactDisplayOptions, FormatCompactOptions, UseCurrencyFormatOptions, UseCurrencyFormatReturn, LocaleConfig, } from "./components/currency";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CurrencyFormat = void 0;
|
|
3
|
+
exports.unregisterLocale = exports.registerLocale = exports.formatWithIntl = exports.getAutoLocaleConfig = exports.createLocaleConfig = exports.getCompactLabels = exports.detectLocaleFormat = exports.getFormatOptionsFromLocale = exports.getLocaleConfig = exports.localePresets = exports.useCurrencyFormat = exports.defaultCompactDisplay = exports.parseCompact = exports.formatCompact = exports.parseCurrency = exports.formatCurrency = exports.CurrencyFormat = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var currency_1 = tslib_1.
|
|
5
|
+
var currency_1 = tslib_1.__importStar(require("./components/currency"));
|
|
6
6
|
exports.CurrencyFormat = currency_1.default;
|
|
7
|
+
Object.defineProperty(exports, "formatCurrency", { enumerable: true, get: function () { return currency_1.formatCurrency; } });
|
|
8
|
+
Object.defineProperty(exports, "parseCurrency", { enumerable: true, get: function () { return currency_1.parseCurrency; } });
|
|
9
|
+
Object.defineProperty(exports, "formatCompact", { enumerable: true, get: function () { return currency_1.formatCompact; } });
|
|
10
|
+
Object.defineProperty(exports, "parseCompact", { enumerable: true, get: function () { return currency_1.parseCompact; } });
|
|
11
|
+
Object.defineProperty(exports, "defaultCompactDisplay", { enumerable: true, get: function () { return currency_1.defaultCompactDisplay; } });
|
|
12
|
+
Object.defineProperty(exports, "useCurrencyFormat", { enumerable: true, get: function () { return currency_1.useCurrencyFormat; } });
|
|
13
|
+
Object.defineProperty(exports, "localePresets", { enumerable: true, get: function () { return currency_1.localePresets; } });
|
|
14
|
+
Object.defineProperty(exports, "getLocaleConfig", { enumerable: true, get: function () { return currency_1.getLocaleConfig; } });
|
|
15
|
+
Object.defineProperty(exports, "getFormatOptionsFromLocale", { enumerable: true, get: function () { return currency_1.getFormatOptionsFromLocale; } });
|
|
16
|
+
Object.defineProperty(exports, "detectLocaleFormat", { enumerable: true, get: function () { return currency_1.detectLocaleFormat; } });
|
|
17
|
+
Object.defineProperty(exports, "getCompactLabels", { enumerable: true, get: function () { return currency_1.getCompactLabels; } });
|
|
18
|
+
Object.defineProperty(exports, "createLocaleConfig", { enumerable: true, get: function () { return currency_1.createLocaleConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "getAutoLocaleConfig", { enumerable: true, get: function () { return currency_1.getAutoLocaleConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "formatWithIntl", { enumerable: true, get: function () { return currency_1.formatWithIntl; } });
|
|
21
|
+
Object.defineProperty(exports, "registerLocale", { enumerable: true, get: function () { return currency_1.registerLocale; } });
|
|
22
|
+
Object.defineProperty(exports, "unregisterLocale", { enumerable: true, get: function () { return currency_1.unregisterLocale; } });
|
|
23
|
+
exports.default = currency_1.default;
|
|
7
24
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;AAAA,wEAiB+B;AAG7B,yBApBK,kBAAc,CAoBL;AAEd,+FArBA,yBAAc,OAqBA;AACd,8FArBA,wBAAa,OAqBA;AACb,8FArBA,wBAAa,OAqBA;AACb,6FArBA,uBAAY,OAqBA;AACZ,sGArBA,gCAAqB,OAqBA;AAErB,kGAtBA,4BAAiB,OAsBA;AAEjB,8FAvBA,wBAAa,OAuBA;AACb,gGAvBA,0BAAe,OAuBA;AACf,2GAvBA,qCAA0B,OAuBA;AAE1B,mGAxBA,6BAAkB,OAwBA;AAClB,iGAxBA,2BAAgB,OAwBA;AAChB,mGAxBA,6BAAkB,OAwBA;AAClB,oGAxBA,8BAAmB,OAwBA;AACnB,+FAxBA,yBAAc,OAwBA;AAEd,+FAzBA,yBAAc,OAyBA;AACd,iGAzBA,2BAAgB,OAyBA;AAGlB,kBAAe,kBAAc,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FormatCurrencyOptions, ValueObject } from "./utils";
|
|
2
|
+
import { LocaleConfig } from "./locales";
|
|
3
|
+
export interface UseCurrencyFormatOptions extends FormatCurrencyOptions {
|
|
4
|
+
locale?: string;
|
|
5
|
+
initialValue?: number | string;
|
|
6
|
+
}
|
|
7
|
+
export interface UseCurrencyFormatReturn {
|
|
8
|
+
/** Raw numeric value as number */
|
|
9
|
+
value: number;
|
|
10
|
+
/** Raw numeric value as string (preserves precision) */
|
|
11
|
+
valueAsString: string;
|
|
12
|
+
/** Formatted display value */
|
|
13
|
+
formattedValue: string;
|
|
14
|
+
/** Set value from number or string */
|
|
15
|
+
setValue: (value: number | string) => void;
|
|
16
|
+
/** Set value from formatted string (parses it first) */
|
|
17
|
+
setFormattedValue: (formatted: string) => void;
|
|
18
|
+
/** Format options derived from locale or props */
|
|
19
|
+
formatOptions: FormatCurrencyOptions;
|
|
20
|
+
/** Props to spread on CurrencyFormat component */
|
|
21
|
+
inputProps: {
|
|
22
|
+
value: number | string;
|
|
23
|
+
onValueChange: (values: ValueObject) => void;
|
|
24
|
+
decimalSeparator: string;
|
|
25
|
+
thousandSeparator: string | boolean;
|
|
26
|
+
prefix: string;
|
|
27
|
+
suffix: string;
|
|
28
|
+
decimalScale?: number;
|
|
29
|
+
fixedDecimalScale?: boolean;
|
|
30
|
+
allowNegative?: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** Reset to initial value */
|
|
33
|
+
reset: () => void;
|
|
34
|
+
/** Clear value */
|
|
35
|
+
clear: () => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook for managing currency format state
|
|
39
|
+
* Makes it easy to use currency formatting in forms
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const { value, formattedValue, inputProps } = useCurrencyFormat({
|
|
44
|
+
* locale: "en-US",
|
|
45
|
+
* initialValue: 1000,
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* return <CurrencyFormat {...inputProps} />;
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function useCurrencyFormat(options?: UseCurrencyFormatOptions): UseCurrencyFormatReturn;
|
|
52
|
+
export type { LocaleConfig };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useState, useCallback, useMemo } from "react";
|
|
2
|
+
import { formatCurrency, parseCurrency, } from "./utils";
|
|
3
|
+
import { getFormatOptionsFromLocale } from "./locales";
|
|
4
|
+
/**
|
|
5
|
+
* Hook for managing currency format state
|
|
6
|
+
* Makes it easy to use currency formatting in forms
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { value, formattedValue, inputProps } = useCurrencyFormat({
|
|
11
|
+
* locale: "en-US",
|
|
12
|
+
* initialValue: 1000,
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* return <CurrencyFormat {...inputProps} />;
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function useCurrencyFormat(options) {
|
|
19
|
+
if (options === void 0) { options = {}; }
|
|
20
|
+
var locale = options.locale, _a = options.initialValue, initialValue = _a === void 0 ? 0 : _a, decimalSeparatorProp = options.decimalSeparator, thousandSeparatorProp = options.thousandSeparator, prefixProp = options.prefix, suffixProp = options.suffix, decimalScaleProp = options.decimalScale, fixedDecimalScaleProp = options.fixedDecimalScale, allowNegativeProp = options.allowNegative, thousandSpacingProp = options.thousandSpacing;
|
|
21
|
+
// Get locale config if locale is provided
|
|
22
|
+
var localeOptions = useMemo(function () { return (locale ? getFormatOptionsFromLocale(locale) : undefined); }, [locale]);
|
|
23
|
+
// Merge options: prop values override locale values
|
|
24
|
+
var formatOptions = useMemo(function () {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
26
|
+
var base = localeOptions || {};
|
|
27
|
+
return {
|
|
28
|
+
decimalSeparator: (_a = decimalSeparatorProp !== null && decimalSeparatorProp !== void 0 ? decimalSeparatorProp : base.decimalSeparator) !== null && _a !== void 0 ? _a : ".",
|
|
29
|
+
thousandSeparator: (_b = thousandSeparatorProp !== null && thousandSeparatorProp !== void 0 ? thousandSeparatorProp : base.thousandSeparator) !== null && _b !== void 0 ? _b : ",",
|
|
30
|
+
prefix: (_c = prefixProp !== null && prefixProp !== void 0 ? prefixProp : base.prefix) !== null && _c !== void 0 ? _c : "",
|
|
31
|
+
suffix: (_d = suffixProp !== null && suffixProp !== void 0 ? suffixProp : base.suffix) !== null && _d !== void 0 ? _d : "",
|
|
32
|
+
decimalScale: decimalScaleProp !== null && decimalScaleProp !== void 0 ? decimalScaleProp : base.decimalScale,
|
|
33
|
+
fixedDecimalScale: fixedDecimalScaleProp !== null && fixedDecimalScaleProp !== void 0 ? fixedDecimalScaleProp : base.fixedDecimalScale,
|
|
34
|
+
allowNegative: (_e = allowNegativeProp !== null && allowNegativeProp !== void 0 ? allowNegativeProp : base.allowNegative) !== null && _e !== void 0 ? _e : true,
|
|
35
|
+
thousandSpacing: (_f = thousandSpacingProp !== null && thousandSpacingProp !== void 0 ? thousandSpacingProp : base.thousandSpacing) !== null && _f !== void 0 ? _f : "3",
|
|
36
|
+
};
|
|
37
|
+
}, [
|
|
38
|
+
localeOptions,
|
|
39
|
+
decimalSeparatorProp,
|
|
40
|
+
thousandSeparatorProp,
|
|
41
|
+
prefixProp,
|
|
42
|
+
suffixProp,
|
|
43
|
+
decimalScaleProp,
|
|
44
|
+
fixedDecimalScaleProp,
|
|
45
|
+
allowNegativeProp,
|
|
46
|
+
thousandSpacingProp,
|
|
47
|
+
]);
|
|
48
|
+
// Parse initial value
|
|
49
|
+
var parseInitialValue = useCallback(function (val) {
|
|
50
|
+
if (typeof val === "number") {
|
|
51
|
+
return isNaN(val) ? "" : val.toString();
|
|
52
|
+
}
|
|
53
|
+
return val;
|
|
54
|
+
}, []);
|
|
55
|
+
// State
|
|
56
|
+
var _b = useState(function () {
|
|
57
|
+
return parseInitialValue(initialValue);
|
|
58
|
+
}), valueAsString = _b[0], setValueAsString = _b[1];
|
|
59
|
+
// Derived values
|
|
60
|
+
var value = useMemo(function () { return (valueAsString === "" ? NaN : parseFloat(valueAsString)); }, [valueAsString]);
|
|
61
|
+
var formattedValue = useMemo(function () { return formatCurrency(valueAsString, formatOptions); }, [valueAsString, formatOptions]);
|
|
62
|
+
// Setters
|
|
63
|
+
var setValue = useCallback(function (newValue) {
|
|
64
|
+
if (typeof newValue === "number") {
|
|
65
|
+
setValueAsString(isNaN(newValue) ? "" : newValue.toString());
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Parse if it looks formatted
|
|
69
|
+
var parseOptions = {
|
|
70
|
+
decimalSeparator: formatOptions.decimalSeparator,
|
|
71
|
+
thousandSeparator: formatOptions.thousandSeparator,
|
|
72
|
+
prefix: formatOptions.prefix,
|
|
73
|
+
suffix: formatOptions.suffix,
|
|
74
|
+
};
|
|
75
|
+
var parsed = parseCurrency(newValue, parseOptions);
|
|
76
|
+
setValueAsString(parsed.value);
|
|
77
|
+
}
|
|
78
|
+
}, [formatOptions]);
|
|
79
|
+
var setFormattedValue = useCallback(function (formatted) {
|
|
80
|
+
var parseOptions = {
|
|
81
|
+
decimalSeparator: formatOptions.decimalSeparator,
|
|
82
|
+
thousandSeparator: formatOptions.thousandSeparator,
|
|
83
|
+
prefix: formatOptions.prefix,
|
|
84
|
+
suffix: formatOptions.suffix,
|
|
85
|
+
};
|
|
86
|
+
var parsed = parseCurrency(formatted, parseOptions);
|
|
87
|
+
setValueAsString(parsed.value);
|
|
88
|
+
}, [formatOptions]);
|
|
89
|
+
var reset = useCallback(function () {
|
|
90
|
+
setValueAsString(parseInitialValue(initialValue));
|
|
91
|
+
}, [initialValue, parseInitialValue]);
|
|
92
|
+
var clear = useCallback(function () {
|
|
93
|
+
setValueAsString("");
|
|
94
|
+
}, []);
|
|
95
|
+
// Handle value change from CurrencyFormat component
|
|
96
|
+
var handleValueChange = useCallback(function (values) {
|
|
97
|
+
setValueAsString(values.value);
|
|
98
|
+
}, []);
|
|
99
|
+
// Props to spread on CurrencyFormat
|
|
100
|
+
var inputProps = useMemo(function () {
|
|
101
|
+
var _a;
|
|
102
|
+
return ({
|
|
103
|
+
value: valueAsString === "" ? "" : parseFloat(valueAsString),
|
|
104
|
+
onValueChange: handleValueChange,
|
|
105
|
+
decimalSeparator: formatOptions.decimalSeparator || ".",
|
|
106
|
+
thousandSeparator: (_a = formatOptions.thousandSeparator) !== null && _a !== void 0 ? _a : ",",
|
|
107
|
+
prefix: formatOptions.prefix || "",
|
|
108
|
+
suffix: formatOptions.suffix || "",
|
|
109
|
+
decimalScale: formatOptions.decimalScale,
|
|
110
|
+
fixedDecimalScale: formatOptions.fixedDecimalScale,
|
|
111
|
+
allowNegative: formatOptions.allowNegative,
|
|
112
|
+
});
|
|
113
|
+
}, [valueAsString, handleValueChange, formatOptions]);
|
|
114
|
+
return {
|
|
115
|
+
value: value,
|
|
116
|
+
valueAsString: valueAsString,
|
|
117
|
+
formattedValue: formattedValue,
|
|
118
|
+
setValue: setValue,
|
|
119
|
+
setFormattedValue: setFormattedValue,
|
|
120
|
+
formatOptions: formatOptions,
|
|
121
|
+
inputProps: inputProps,
|
|
122
|
+
reset: reset,
|
|
123
|
+
clear: clear,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../src/components/currency/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EACL,cAAc,EACd,aAAa,GAId,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,0BAA0B,EAAgB,MAAM,WAAW,CAAC;AAsCrE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAsC;IAAtC,wBAAA,EAAA,YAAsC;IAGpC,IAAA,MAAM,GAUJ,OAAO,OAVH,EACN,KASE,OAAO,aATO,EAAhB,YAAY,mBAAG,CAAC,KAAA,EACE,oBAAoB,GAQpC,OAAO,iBAR6B,EACnB,qBAAqB,GAOtC,OAAO,kBAP+B,EAChC,UAAU,GAMhB,OAAO,OANS,EACV,UAAU,GAKhB,OAAO,OALS,EACJ,gBAAgB,GAI5B,OAAO,aAJqB,EACX,qBAAqB,GAGtC,OAAO,kBAH+B,EACzB,iBAAiB,GAE9B,OAAO,cAFuB,EACf,mBAAmB,GAClC,OAAO,gBAD2B,CAC1B;IAEZ,0CAA0C;IAC1C,IAAM,aAAa,GAAG,OAAO,CAC3B,cAAM,OAAA,CAAC,MAAM,CAAC,CAAC,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAzD,CAAyD,EAC/D,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,oDAAoD;IACpD,IAAM,aAAa,GAAG,OAAO,CAAwB;;QACnD,IAAM,IAAI,GAAG,aAAa,IAAI,EAAE,CAAC;QACjC,OAAO;YACL,gBAAgB,EAAE,MAAA,oBAAoB,aAApB,oBAAoB,cAApB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EAAE,aAAa,CAAC,CAClD,CAAC;IAEF,OAAO;QACL,KAAK,OAAA;QACL,aAAa,eAAA;QACb,cAAc,gBAAA;QACd,QAAQ,UAAA;QACR,iBAAiB,mBAAA;QACjB,aAAa,eAAA;QACb,UAAU,YAAA;QACV,KAAK,OAAA;QACL,KAAK,OAAA;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -1,109 +1,46 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
getFloatString(num?: string): string;
|
|
45
|
-
getNumberRegex(g: boolean, ignoreDecimalSeparator?: boolean): RegExp;
|
|
46
|
-
getSeparators(): {
|
|
47
|
-
decimalSeparator: string;
|
|
48
|
-
thousandSeparator: string | false;
|
|
49
|
-
thousandSpacing: "2" | "2s" | "3" | "4";
|
|
50
|
-
};
|
|
51
|
-
getMaskAtIndex(index: number): string;
|
|
52
|
-
validateProps(): void;
|
|
53
|
-
splitDecimal(numStr: string): {
|
|
54
|
-
beforeDecimal: string;
|
|
55
|
-
afterDecimal: string;
|
|
56
|
-
hasNagation: boolean;
|
|
57
|
-
addNegation: boolean;
|
|
58
|
-
};
|
|
59
|
-
/** Misc methods end **/
|
|
60
|
-
/** caret specific methods **/
|
|
61
|
-
setPatchedCaretPosition(el: any, caretPos: number, currentValue: string): void;
|
|
62
|
-
correctCaretPosition(value: string, caretPos: number, direction?: string): any;
|
|
63
|
-
getCaretPosition(inputValue: string, formattedValue: string, caretPos: number): any;
|
|
64
|
-
/** caret specific methods ends **/
|
|
65
|
-
/** methods to remove formattting **/
|
|
66
|
-
removePrefixAndSuffix(val: string): string;
|
|
67
|
-
removePatternFormatting(val: string): string;
|
|
68
|
-
removeFormatting(val: string): string;
|
|
69
|
-
/** methods to remove formattting end **/
|
|
70
|
-
/*** format specific methods start ***/
|
|
71
|
-
/**
|
|
72
|
-
* Format when # based string is provided
|
|
73
|
-
* @param {string} numStr Numeric String
|
|
74
|
-
* @return {string} formatted Value
|
|
75
|
-
*/
|
|
76
|
-
formatWithPattern(numStr: string): string;
|
|
77
|
-
/**
|
|
78
|
-
* Format the given string according to thousand separator and thousand spacing
|
|
79
|
-
* @param {*} beforeDecimal
|
|
80
|
-
* @param {*} thousandSeparator
|
|
81
|
-
* @param {*} thousandSpacing
|
|
82
|
-
*/
|
|
83
|
-
formatThousand(beforeDecimal: any, thousandSeparator: string | boolean, thousandSpacing?: any): any;
|
|
84
|
-
/**
|
|
85
|
-
* @param {string} numStr Numeric string/floatString] It always have decimalSeparator as .
|
|
86
|
-
* @return {string} formatted Value
|
|
87
|
-
*/
|
|
88
|
-
formatAsNumber(numStr: string): string;
|
|
89
|
-
formatNumString(value?: string): string;
|
|
90
|
-
formatValueProp(): string;
|
|
91
|
-
formatNegation(value?: string): string;
|
|
92
|
-
formatInput(value?: string): string;
|
|
93
|
-
/*** format specific methods end ***/
|
|
94
|
-
isCharacterAFormat(caretPos: number, value: string): boolean;
|
|
95
|
-
checkIfFormatGotDeleted(start: number, end: number, value: string): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* This will check if any formatting got removed by the delete or backspace and reset the value
|
|
98
|
-
* It will also work as fallback if android chome keyDown handler does not work
|
|
99
|
-
**/
|
|
100
|
-
correctInputValue(caretPos: number, lastValue: string, value: string): string;
|
|
101
|
-
onChange(e: React.FormEvent<HTMLInputElement>): void;
|
|
102
|
-
onBlur(e: React.FormEvent<HTMLInputElement>): void;
|
|
103
|
-
onKeyDown(e: any): void;
|
|
104
|
-
/** required to handle the caret position when click anywhere within the input **/
|
|
105
|
-
onMouseUp(e: React.FormEvent<HTMLInputElement>): void;
|
|
106
|
-
onFocus(e: React.FormEvent<HTMLInputElement>): void;
|
|
107
|
-
render(): string | React.JSX.Element | null;
|
|
1
|
+
import React, { ComponentType, InputHTMLAttributes, FocusEvent, KeyboardEvent, ChangeEvent, MouseEvent, ReactNode } from "react";
|
|
2
|
+
import { ThousandSpacing, ValueObject } from "./utils";
|
|
3
|
+
export type { ThousandSpacing, ValueObject, FormatCurrencyOptions, ParseCurrencyOptions, CompactDisplayOptions, FormatCompactOptions, } from "./utils";
|
|
4
|
+
export { formatCurrency, parseCurrency, formatCompact, parseCompact, defaultCompactDisplay, } from "./utils";
|
|
5
|
+
export { useCurrencyFormat } from "./hooks";
|
|
6
|
+
export type { UseCurrencyFormatOptions, UseCurrencyFormatReturn } from "./hooks";
|
|
7
|
+
export { localePresets, getLocaleConfig, getFormatOptionsFromLocale, detectLocaleFormat, getCompactLabels, createLocaleConfig, getAutoLocaleConfig, formatWithIntl, registerLocale, unregisterLocale, } from "./locales";
|
|
8
|
+
export type { LocaleConfig } from "./locales";
|
|
9
|
+
export type FormatFunction = (value: string) => string;
|
|
10
|
+
export type RemoveFormattingFunction = (value: string) => string;
|
|
11
|
+
export type IsAllowedFunction = (values: ValueObject) => boolean;
|
|
12
|
+
export type OnValueChangeFunction = (values: ValueObject, sourceInfo?: {
|
|
13
|
+
event?: ChangeEvent<HTMLInputElement>;
|
|
14
|
+
source: "event" | "prop";
|
|
15
|
+
}) => void;
|
|
16
|
+
export type RenderTextFunction = (value: string, otherProps: Record<string, unknown>) => ReactNode;
|
|
17
|
+
export interface CurrencyFormatProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onKeyDown" | "onMouseUp" | "onFocus" | "onBlur"> {
|
|
18
|
+
value?: string | number;
|
|
19
|
+
name?: string;
|
|
20
|
+
format?: string | FormatFunction;
|
|
21
|
+
decimalScale?: number;
|
|
22
|
+
decimalSeparator?: string;
|
|
23
|
+
thousandSpacing?: ThousandSpacing;
|
|
24
|
+
thousandSeparator?: string | boolean;
|
|
25
|
+
mask?: string | string[];
|
|
26
|
+
allowNegative?: boolean;
|
|
27
|
+
prefix?: string;
|
|
28
|
+
suffix?: string;
|
|
29
|
+
removeFormatting?: RemoveFormattingFunction;
|
|
30
|
+
fixedDecimalScale?: boolean;
|
|
31
|
+
isNumericString?: boolean;
|
|
32
|
+
isAllowed?: IsAllowedFunction;
|
|
33
|
+
onValueChange?: OnValueChangeFunction;
|
|
34
|
+
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
35
|
+
onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
36
|
+
onMouseUp?: (e: MouseEvent<HTMLInputElement>) => void;
|
|
37
|
+
onFocus?: (e: FocusEvent<HTMLInputElement>) => void;
|
|
38
|
+
onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
|
|
39
|
+
type?: "text" | "tel";
|
|
40
|
+
displayType?: "input" | "text";
|
|
41
|
+
customInput?: ComponentType<InputHTMLAttributes<HTMLInputElement>>;
|
|
42
|
+
renderText?: RenderTextFunction;
|
|
43
|
+
getInputRef?: (el: HTMLInputElement | null) => void;
|
|
108
44
|
}
|
|
45
|
+
declare const CurrencyFormat: React.ForwardRefExoticComponent<CurrencyFormatProps & React.RefAttributes<HTMLInputElement>>;
|
|
109
46
|
export default CurrencyFormat;
|