@canutin/svelte-currency-input 0.8.0 → 0.9.1
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/CurrencyInput.svelte +3 -0
- package/CurrencyInput.svelte.d.ts +1 -0
- package/README.md +1 -0
- package/package.json +1 -1
package/CurrencyInput.svelte
CHANGED
|
@@ -19,6 +19,7 @@ export let placeholder = DEFAULT_VALUE;
|
|
|
19
19
|
export let isNegativeAllowed = true;
|
|
20
20
|
export let fractionDigits = DEFAULT_FRACTION_DIGITS;
|
|
21
21
|
export let inputClasses = null;
|
|
22
|
+
export let onValueChange = () => { };
|
|
22
23
|
// Formats value as: e.g. $1,523.00 | -$1,523.00
|
|
23
24
|
const formatCurrency = (value, maximumFractionDigits, minimumFractionDigits) => {
|
|
24
25
|
return new Intl.NumberFormat(locale, {
|
|
@@ -109,6 +110,8 @@ const setFormattedValue = () => {
|
|
|
109
110
|
setTimeout(() => {
|
|
110
111
|
inputTarget?.setSelectionRange(endCaretPosition, endCaretPosition);
|
|
111
112
|
}, 0.1);
|
|
113
|
+
// Run callback function when `value` changes
|
|
114
|
+
onValueChange(value);
|
|
112
115
|
};
|
|
113
116
|
let formattedValue = '';
|
|
114
117
|
let formattedPlaceholder = placeholder !== null ? formatCurrency(placeholder, fractionDigits, fractionDigits) : '';
|
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ This is more or less what `<CurrencyInput />` looks like under the hood:
|
|
|
70
70
|
| isNegativeAllowed | `boolean` | `true` | If `false`, forces formatting only to positive values and ignores `--positive` and `--negative` styling modifiers |
|
|
71
71
|
| fractionDigits | `number` | `2` | Sets `maximumFractionDigits` in [`Intl.NumberFormat()` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits) used for formatting the currency. Supported digits: `0` to `20` |
|
|
72
72
|
| inputClasses | `object` | [See below](#Styling) | Selectively overrides any class names passed |
|
|
73
|
+
| onValueChange | `Callback` | `undefined` | Runs a callback function after the value changes |
|
|
73
74
|
|
|
74
75
|
## Styling
|
|
75
76
|
|