@fiscozen/input 0.1.5-beta.1 → 0.1.5
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 +2 -2
- package/src/FzCurrencyInput.vue +16 -13
- package/src/FzInput.vue +3 -3
- package/src/__tests__/FzCurrencyInput.spec.ts +29 -34
- package/src/types.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/input",
|
|
3
|
-
"version": "0.1.5
|
|
3
|
+
"version": "0.1.5",
|
|
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.21",
|
|
13
13
|
"@fiscozen/icons": "^0.1.9"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
package/src/FzCurrencyInput.vue
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
2
|
+
<FzInput
|
|
3
|
+
ref="fzInputRef"
|
|
4
|
+
v-bind="props"
|
|
5
|
+
:model-value="model"
|
|
6
|
+
></FzInput>
|
|
3
7
|
</template>
|
|
4
8
|
|
|
5
9
|
<script setup lang="ts">
|
|
6
|
-
import {
|
|
7
|
-
import FzInput from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import {onMounted, ref} from 'vue'
|
|
11
|
+
import FzInput from './FzInput.vue'
|
|
12
|
+
import {FzCurrencyInputProps} from './types'
|
|
13
|
+
import {useCurrency} from '@fiscozen/composables'
|
|
10
14
|
|
|
11
15
|
const fzInputRef = ref();
|
|
12
|
-
const props = defineProps<
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
defineEmits(["update:amount"]);
|
|
16
|
+
const props = defineProps<FzCurrencyInputProps>();
|
|
17
|
+
const {inputRef} = useCurrency();
|
|
16
18
|
|
|
17
19
|
onMounted(() => {
|
|
18
|
-
|
|
19
|
-
})
|
|
20
|
-
const model = defineModel(
|
|
21
|
-
|
|
20
|
+
inputRef.value = fzInputRef.value.inputRef
|
|
21
|
+
})
|
|
22
|
+
const model = defineModel()
|
|
23
|
+
|
|
24
|
+
</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,42 +1,37 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { mount } from "@vue/test-utils";
|
|
3
3
|
import { FzCurrencyInput } from "..";
|
|
4
|
-
import {ref} from 'vue'
|
|
5
4
|
|
|
6
5
|
describe.concurrent("FzCurrencyInput", () => {
|
|
7
|
-
|
|
6
|
+
it('renders floating numbers as currency', async () => {
|
|
7
|
+
const val = 1234.56
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const wrapper = mount(FzCurrencyInput, {
|
|
10
|
+
props: {
|
|
11
|
+
label: "Label",
|
|
12
|
+
modelValue: val,
|
|
13
|
+
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e})
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
|
|
30
|
-
},
|
|
31
|
-
});
|
|
17
|
+
const inputElement = wrapper.find('input')
|
|
18
|
+
await inputElement.setValue(val)
|
|
19
|
+
await inputElement.trigger('blur')
|
|
20
|
+
expect(inputElement.element.value).toBe('1.234,56')
|
|
21
|
+
})
|
|
22
|
+
it('should not allow inputs other than digits and separators', async () => {
|
|
23
|
+
const wrapper = mount(FzCurrencyInput, {
|
|
24
|
+
props: {
|
|
25
|
+
label: "Label",
|
|
26
|
+
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e})
|
|
27
|
+
},
|
|
28
|
+
});
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
expect(inputElement.element.value).toBe("12,30");
|
|
41
|
-
});
|
|
30
|
+
const inputElement = wrapper.find('input')
|
|
31
|
+
await inputElement.setValue('as12.3')
|
|
32
|
+
await inputElement.trigger('input')
|
|
33
|
+
expect(inputElement.element.value).toBe('12.3')
|
|
34
|
+
await inputElement.trigger('blur')
|
|
35
|
+
expect(inputElement.element.value).toBe('12,30')
|
|
36
|
+
})
|
|
42
37
|
});
|
package/src/types.ts
CHANGED
|
@@ -62,8 +62,14 @@ type FzInputProps = {
|
|
|
62
62
|
* native readonly input value
|
|
63
63
|
*/
|
|
64
64
|
readonly?: boolean;
|
|
65
|
+
|
|
65
66
|
};
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
interface FzCurrencyInputProps extends Omit<FzInputProps, 'type'> {
|
|
69
|
+
/**
|
|
70
|
+
* Is set to true, an empty string will be casted to null
|
|
71
|
+
*/
|
|
72
|
+
nullOnEmpty?: boolean;
|
|
73
|
+
}
|
|
68
74
|
|
|
69
75
|
export { FzInputProps, FzCurrencyInputProps };
|