@megha-ui/react 1.2.134 → 1.2.136
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.
|
@@ -604,7 +604,7 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
|
|
|
604
604
|
? "#2377ba"
|
|
605
605
|
: "#000",
|
|
606
606
|
} }), dropdownVisible === column.key &&
|
|
607
|
-
(column.uniqueDrop ? ((0, jsx_runtime_1.jsx)(gridFilterDropdown_1.default, { columnType: (_b = column.dataType) !== null && _b !== void 0 ? _b : "string", columnIndex: colIndex, searchable: (column === null || column === void 0 ? void 0 : column.search) || false, headerDropdownIndex: headerDropdownIndex, searchOptions: searchOptions.filter((item) => column.dataType === "number"
|
|
607
|
+
(column.uniqueDrop ? ((0, jsx_runtime_1.jsx)(gridFilterDropdown_1.default, { locale: locale, formatOptions: formatOptions, columnType: (_b = column.dataType) !== null && _b !== void 0 ? _b : "string", columnIndex: colIndex, searchable: (column === null || column === void 0 ? void 0 : column.search) || false, headerDropdownIndex: headerDropdownIndex, searchOptions: searchOptions.filter((item) => column.dataType === "number"
|
|
608
608
|
? numberTypeSearch.includes(item.value)
|
|
609
609
|
: column.dataType === "date"
|
|
610
610
|
? dateTypeSearch.includes(item.value)
|
|
@@ -107,10 +107,56 @@ const formatDate = (date, locale = "sv-SE", options) => {
|
|
|
107
107
|
const formatter = new Intl.DateTimeFormat(locale, options);
|
|
108
108
|
return formatter.format(date);
|
|
109
109
|
};
|
|
110
|
-
//
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
// Helpers for currency formatting
|
|
111
|
+
const isValidCurrencyCode = (code) => typeof code === "string" && /^[A-Z]{3}$/.test(code);
|
|
112
|
+
const buildCurrencyOptions = (currency, options) => {
|
|
113
|
+
const { currencyDisplay, currencySign, notation, compactDisplay, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigits, useGrouping, roundingMode, roundingIncrement, } = options !== null && options !== void 0 ? options : {};
|
|
114
|
+
return {
|
|
115
|
+
style: "currency",
|
|
116
|
+
currency,
|
|
117
|
+
currencyDisplay,
|
|
118
|
+
currencySign,
|
|
119
|
+
notation,
|
|
120
|
+
compactDisplay,
|
|
121
|
+
minimumFractionDigits,
|
|
122
|
+
maximumFractionDigits,
|
|
123
|
+
minimumSignificantDigits,
|
|
124
|
+
maximumSignificantDigits,
|
|
125
|
+
useGrouping,
|
|
126
|
+
// The following are newer options; some engines ignore them, some may throw.
|
|
127
|
+
// We'll include them here, but handle failures via try/catch and fallback.
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
roundingMode,
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
roundingIncrement,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
// Function to format currency with robust fallbacks
|
|
135
|
+
const formatCurrency = (value, locale = "sv-SE", currency = "SEK", options) => {
|
|
136
|
+
const code = isValidCurrencyCode(currency) ? currency : "SEK";
|
|
137
|
+
// 1) Try as requested
|
|
138
|
+
try {
|
|
139
|
+
const fmt = new Intl.NumberFormat(locale, buildCurrencyOptions(code, options));
|
|
140
|
+
return fmt.format(value);
|
|
141
|
+
}
|
|
142
|
+
catch (_) {
|
|
143
|
+
// 2) Fallback if currencyDisplay: 'name' is problematic or other options unsupported
|
|
144
|
+
try {
|
|
145
|
+
const safe = Object.assign({}, (options !== null && options !== void 0 ? options : {}));
|
|
146
|
+
if (safe.currencyDisplay === "name")
|
|
147
|
+
safe.currencyDisplay = "code";
|
|
148
|
+
// Drop less-supported options that may throw
|
|
149
|
+
delete safe.roundingMode;
|
|
150
|
+
delete safe.roundingIncrement;
|
|
151
|
+
const fmt = new Intl.NumberFormat(locale, buildCurrencyOptions(code, safe));
|
|
152
|
+
return fmt.format(value);
|
|
153
|
+
}
|
|
154
|
+
catch (_a) {
|
|
155
|
+
// 3) Final fallback: minimal currency formatting
|
|
156
|
+
const fmt = new Intl.NumberFormat(locale, { style: "currency", currency: code });
|
|
157
|
+
return fmt.format(value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
114
160
|
};
|
|
115
161
|
// Dynamic formatter function
|
|
116
162
|
const formatValue = (value, type = "number", locale = "sv-SE", options) => {
|
|
@@ -157,20 +203,8 @@ const formatValue = (value, type = "number", locale = "sv-SE", options) => {
|
|
|
157
203
|
}
|
|
158
204
|
else if (type === "currency") {
|
|
159
205
|
const num = parseFloat(value.toString());
|
|
160
|
-
const { currency
|
|
161
|
-
return formatCurrency(num, locale, currency,
|
|
162
|
-
currencyDisplay,
|
|
163
|
-
currencySign,
|
|
164
|
-
notation,
|
|
165
|
-
compactDisplay,
|
|
166
|
-
minimumFractionDigits,
|
|
167
|
-
maximumFractionDigits,
|
|
168
|
-
minimumSignificantDigits,
|
|
169
|
-
maximumSignificantDigits,
|
|
170
|
-
useGrouping,
|
|
171
|
-
roundingMode,
|
|
172
|
-
roundingIncrement,
|
|
173
|
-
});
|
|
206
|
+
const { currency } = options !== null && options !== void 0 ? options : {};
|
|
207
|
+
return formatCurrency(num, locale, currency, options);
|
|
174
208
|
}
|
|
175
209
|
else {
|
|
176
210
|
return value.toString();
|
package/package.json
CHANGED