@fiscozen/input 0.1.5 → 0.1.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/input",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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.21",
12
+ "@fiscozen/composables": "^0.1.24",
13
13
  "@fiscozen/icons": "^0.1.9"
14
14
  },
15
15
  "devDependencies": {
@@ -1,24 +1,21 @@
1
1
  <template>
2
- <FzInput
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 'vue'
11
- import FzInput from './FzInput.vue'
12
- import {FzCurrencyInputProps} from './types'
13
- import {useCurrency} from '@fiscozen/composables'
6
+ import { onMounted, ref } from "vue";
7
+ import FzInput from "./FzInput.vue";
8
+ import { FzCurrencyInputProps } from "./types";
9
+ import { useCurrency } from "@fiscozen/composables";
14
10
 
15
11
  const fzInputRef = ref();
16
12
  const props = defineProps<FzCurrencyInputProps>();
17
- const {inputRef} = useCurrency();
13
+ const { inputRef } = useCurrency();
18
14
 
19
- onMounted(() => {
20
- inputRef.value = fzInputRef.value.inputRef
21
- })
22
- const model = defineModel()
15
+ defineEmits(["update:amount"]);
23
16
 
24
- </script>
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(['input', 'focus']);
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>
@@ -3,35 +3,38 @@ import { mount } from "@vue/test-utils";
3
3
  import { FzCurrencyInput } from "..";
4
4
 
5
5
  describe.concurrent("FzCurrencyInput", () => {
6
- it('renders floating numbers as currency', async () => {
7
- const val = 1234.56
6
+ it("renders floating numbers as currency", async () => {
7
+ const wrapper = mount(FzCurrencyInput, {
8
+ props: {
9
+ label: "Label",
10
+ amount: 1234.56,
11
+ "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
12
+ },
13
+ });
8
14
 
9
- const wrapper = mount(FzCurrencyInput, {
10
- props: {
11
- label: "Label",
12
- modelValue: val,
13
- 'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e})
14
- },
15
- });
15
+ const inputElement = wrapper.find("input");
16
+ await inputElement.trigger("blur");
17
+ // flushPromises doesn't seem to be enoughsince the implementation
18
+ // of the composable uses setTimeout itself
19
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
20
+ expect(inputElement.element.value).toBe("1234,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
+ amount: "",
27
+ "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
28
+ },
29
+ });
16
30
 
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
- });
29
-
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
- })
31
+ const inputElement = wrapper.find("input");
32
+ await inputElement.setValue("as12.3");
33
+ await inputElement.trigger("input");
34
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
35
+ expect(inputElement.element.value).toBe("12.3");
36
+ await inputElement.trigger("blur");
37
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
38
+ expect(inputElement.element.value).toBe("12,30");
39
+ });
37
40
  });
package/src/types.ts CHANGED
@@ -62,10 +62,10 @@ type FzInputProps = {
62
62
  * native readonly input value
63
63
  */
64
64
  readonly?: boolean;
65
-
66
65
  };
67
66
 
68
- interface FzCurrencyInputProps extends Omit<FzInputProps, 'type'> {
67
+ interface FzCurrencyInputProps
68
+ extends Omit<FzInputProps, "type" | "modelValue"> {
69
69
  /**
70
70
  * Is set to true, an empty string will be casted to null
71
71
  */