@fiscozen/input 0.1.4 → 0.1.5-beta.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/package.json +4 -4
- package/src/FzCurrencyInput.vue +13 -16
- package/src/FzInput.vue +3 -3
- package/src/__tests__/FzCurrencyInput.spec.ts +34 -29
- package/src/types.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/input",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5-beta.1",
|
|
4
4
|
"description": "Design System Input component",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"tailwindcss": "^3.4.1",
|
|
11
11
|
"vue": "^3.4.13",
|
|
12
|
-
"@fiscozen/composables": "^0.1.
|
|
12
|
+
"@fiscozen/composables": "^0.1.20-beta.1",
|
|
13
13
|
"@fiscozen/icons": "^0.1.9"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"vite-plugin-dts": "^3.8.3",
|
|
29
29
|
"vitest": "^1.2.0",
|
|
30
30
|
"vue-tsc": "^1.8.25",
|
|
31
|
-
"@fiscozen/
|
|
31
|
+
"@fiscozen/eslint-config": "^0.1.0",
|
|
32
32
|
"@fiscozen/prettier-config": "^0.1.0",
|
|
33
|
-
"@fiscozen/
|
|
33
|
+
"@fiscozen/tsconfig": "^0.1.0"
|
|
34
34
|
},
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"scripts": {
|
package/src/FzCurrencyInput.vue
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
ref="fzInputRef"
|
|
4
|
-
v-bind="props"
|
|
5
|
-
:model-value="model"
|
|
6
|
-
></FzInput>
|
|
2
|
+
<FzInput ref="fzInputRef" v-bind="props" type="text"></FzInput>
|
|
7
3
|
</template>
|
|
8
4
|
|
|
9
5
|
<script setup lang="ts">
|
|
10
|
-
import {onMounted, ref} from
|
|
11
|
-
import FzInput from
|
|
12
|
-
import {FzInputProps} from
|
|
13
|
-
import {useCurrency} from
|
|
6
|
+
import { onMounted, ref } from "vue";
|
|
7
|
+
import FzInput from "./FzInput.vue";
|
|
8
|
+
import { FzInputProps } from "./types";
|
|
9
|
+
import { useCurrency } from "@fiscozen/composables";
|
|
14
10
|
|
|
15
11
|
const fzInputRef = ref();
|
|
16
|
-
const props = defineProps<Omit<FzInputProps,
|
|
17
|
-
const {inputRef} = useCurrency();
|
|
12
|
+
const props = defineProps<Omit<FzInputProps, "type" | "modelValue">>();
|
|
13
|
+
const { inputRef } = useCurrency();
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
inputRef.value = fzInputRef.value.inputRef
|
|
21
|
-
})
|
|
22
|
-
const model = defineModel()
|
|
15
|
+
defineEmits(["update:amount"]);
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
inputRef.value = fzInputRef.value.inputRef;
|
|
19
|
+
});
|
|
20
|
+
const model = defineModel("amount");
|
|
21
|
+
</script>
|
package/src/FzInput.vue
CHANGED
|
@@ -92,11 +92,11 @@ const {
|
|
|
92
92
|
containerWidth,
|
|
93
93
|
} = useInputStyle(props, containerRef);
|
|
94
94
|
|
|
95
|
-
const emit = defineEmits([
|
|
95
|
+
const emit = defineEmits(["input", "focus"]);
|
|
96
96
|
defineExpose({
|
|
97
97
|
inputRef,
|
|
98
|
-
containerRef
|
|
99
|
-
})
|
|
98
|
+
containerRef,
|
|
99
|
+
});
|
|
100
100
|
</script>
|
|
101
101
|
|
|
102
102
|
<style scoped></style>
|
|
@@ -1,37 +1,42 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { flushPromises, mount } from "@vue/test-utils";
|
|
3
3
|
import { FzCurrencyInput } from "..";
|
|
4
|
+
import {ref} from 'vue'
|
|
4
5
|
|
|
5
6
|
describe.concurrent("FzCurrencyInput", () => {
|
|
6
|
-
|
|
7
|
-
const val = 1234.56
|
|
7
|
+
it("renders floating numbers as currency", async () => {
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const wrapper = mount(FzCurrencyInput, {
|
|
10
|
+
props: {
|
|
11
|
+
label: "Label",
|
|
12
|
+
amount: 1234.56,
|
|
13
|
+
"onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const inputElement = wrapper.find("input");
|
|
18
|
+
await inputElement.trigger("blur");
|
|
19
|
+
// flushPromises doesn't seem to be enoughsince the implementation
|
|
20
|
+
// of the composable uses setTimeout itself
|
|
21
|
+
await new Promise((resolve) => window.setTimeout(resolve, 100));
|
|
22
|
+
expect(inputElement.element.value).toBe("1234,56");
|
|
23
|
+
});
|
|
24
|
+
it("should not allow inputs other than digits and separators", async () => {
|
|
25
|
+
const wrapper = mount(FzCurrencyInput, {
|
|
26
|
+
props: {
|
|
27
|
+
label: "Label",
|
|
28
|
+
amount: '',
|
|
29
|
+
"onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const inputElement = wrapper.find("input");
|
|
34
|
+
await inputElement.setValue("as12.3");
|
|
35
|
+
await inputElement.trigger("input");
|
|
36
|
+
await new Promise((resolve) => window.setTimeout(resolve, 100));
|
|
37
|
+
expect(inputElement.element.value).toBe("12.3");
|
|
38
|
+
await inputElement.trigger("blur");
|
|
39
|
+
await new Promise((resolve) => window.setTimeout(resolve, 100));
|
|
40
|
+
expect(inputElement.element.value).toBe("12,30");
|
|
41
|
+
});
|
|
37
42
|
});
|
package/src/types.ts
CHANGED
|
@@ -62,9 +62,8 @@ type FzInputProps = {
|
|
|
62
62
|
* native readonly input value
|
|
63
63
|
*/
|
|
64
64
|
readonly?: boolean;
|
|
65
|
-
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
type FzCurrencyInputProps = Omit<FzInputProps,
|
|
67
|
+
type FzCurrencyInputProps = Omit<FzInputProps, "type">;
|
|
69
68
|
|
|
70
69
|
export { FzInputProps, FzCurrencyInputProps };
|