@canutin/svelte-currency-input 0.11.5 → 0.13.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 +3 -2
- package/dist/CurrencyInput.svelte +4 -1
- package/dist/CurrencyInput.svelte.d.ts +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -64,8 +64,9 @@ value | `number` | `undefined` | Initial value. If left `unde
|
|
|
64
64
|
locale | `string` | `en-US` | Overrides default locale. [Examples](https://gist.github.com/ncreated/9934896) |
|
|
65
65
|
currency | `string` | `USD` | Overrides default currency. [Examples](https://www.xe.com/symbols/) |
|
|
66
66
|
name | `string` | `total` | Applies the name to the [input fields](#how-it-works) for _unformatted_ (e.g `[name=total]`) and _formatted_ (e.g. `[name=formatted-total]`) values |
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
id | `string` | `undefined` | Sets the `id` attribute on the input |
|
|
68
|
+
required | `boolean` | `false` | Marks the input as required |
|
|
69
|
+
disabled | `boolean` | `false` | Marks the input as disabled |
|
|
69
70
|
placeholder | `string` `number` `null` | `0` | A `string` will override the default placeholder. A `number` will override it by formatting it to the set currency. Setting it to `null` will not show a placeholder |
|
|
70
71
|
isZeroNullish | `boolean` | `false` | If `true` and when the value is `0`, it will override the default placeholder and render the formatted value in the field like any other value. _Note: this option might become the default in future versions_ |
|
|
71
72
|
autocomplete | `string` | `undefined` | Sets the autocomplete attribute. Accepts any valid HTML [autocomplete attribute values](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values) |
|
|
@@ -17,6 +17,7 @@ export let locale = DEFAULT_LOCALE;
|
|
|
17
17
|
export let currency = DEFAULT_CURRENCY;
|
|
18
18
|
export let fractionDigits = DEFAULT_FRACTION_DIGITS;
|
|
19
19
|
export let name = DEFAULT_NAME;
|
|
20
|
+
export let id = void 0;
|
|
20
21
|
export let required = false;
|
|
21
22
|
export let disabled = false;
|
|
22
23
|
export let placeholder = DEFAULT_VALUE;
|
|
@@ -49,6 +50,7 @@ function handleKeyDown(event) {
|
|
|
49
50
|
const isModifier = event.metaKey || event.altKey || event.ctrlKey;
|
|
50
51
|
const isArrowKey = event.key === "ArrowLeft" || event.key === "ArrowRight";
|
|
51
52
|
const isTab = event.key === "Tab";
|
|
53
|
+
const isEnter = event.key === "Enter";
|
|
52
54
|
const isInvalidCharacter = !/^\d|,|\.|-$/g.test(event.key);
|
|
53
55
|
function isPunctuationDuplicated() {
|
|
54
56
|
if (event.key !== "," && event.key !== ".") return false;
|
|
@@ -56,7 +58,7 @@ function handleKeyDown(event) {
|
|
|
56
58
|
if (!isDecimalComma) return formattedValue.split(".").length >= 2;
|
|
57
59
|
return false;
|
|
58
60
|
}
|
|
59
|
-
if (isPunctuationDuplicated() || !isDeletion && !isModifier && !isArrowKey && isInvalidCharacter && !isTab)
|
|
61
|
+
if (isPunctuationDuplicated() || !isDeletion && !isModifier && !isArrowKey && isInvalidCharacter && !isTab && !isEnter)
|
|
60
62
|
event.preventDefault();
|
|
61
63
|
}
|
|
62
64
|
function handlePlaceholder(placeholder2) {
|
|
@@ -142,6 +144,7 @@ function setFormattedValue() {
|
|
|
142
144
|
placeholder={handlePlaceholder(placeholder)}
|
|
143
145
|
{autocomplete}
|
|
144
146
|
{disabled}
|
|
147
|
+
{id}
|
|
145
148
|
bind:this={inputElement}
|
|
146
149
|
bind:value={formattedValue}
|
|
147
150
|
on:keydown={handleKeyDown}
|
|
@@ -7,6 +7,7 @@ declare const __propDef: {
|
|
|
7
7
|
currency?: string | undefined;
|
|
8
8
|
fractionDigits?: number | undefined;
|
|
9
9
|
name?: string | undefined;
|
|
10
|
+
id?: string | undefined;
|
|
10
11
|
required?: boolean | undefined;
|
|
11
12
|
disabled?: boolean | undefined;
|
|
12
13
|
placeholder?: string | number | null | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canutin/svelte-currency-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@playwright/test": "^1.39.0",
|
|
28
|
-
"@sveltejs/adapter-auto": "^3.2.
|
|
29
|
-
"@sveltejs/adapter-cloudflare": "^4.
|
|
30
|
-
"@sveltejs/kit": "^2.
|
|
28
|
+
"@sveltejs/adapter-auto": "^3.2.5",
|
|
29
|
+
"@sveltejs/adapter-cloudflare": "^4.7.3",
|
|
30
|
+
"@sveltejs/kit": "^2.7.1",
|
|
31
31
|
"@sveltejs/package": "^2.2.2",
|
|
32
32
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
33
33
|
"@types/node": "^20.8.7",
|