@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.
@@ -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) : '';
@@ -18,6 +18,7 @@ declare const __propDef: {
18
18
  formattedNegative?: string | undefined;
19
19
  formattedZero?: string | undefined;
20
20
  } | null | undefined;
21
+ onValueChange?: ((value: number) => any) | undefined;
21
22
  };
22
23
  events: {
23
24
  [evt: string]: CustomEvent<any>;
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canutin/svelte-currency-input",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "exports": {
5
5
  "./package.json": "./package.json",
6
6
  ".": "./index.js",