@fiscozen/input 0.1.5-beta.1 → 0.1.5-currencynullonempty.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/input",
3
- "version": "0.1.5-beta.1",
3
+ "version": "0.1.5-currencynullonempty.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.20-beta.1",
12
+ "@fiscozen/composables": "^0.1.20",
13
13
  "@fiscozen/icons": "^0.1.9"
14
14
  },
15
15
  "devDependencies": {
@@ -1,21 +1,24 @@
1
1
  <template>
2
- <FzInput ref="fzInputRef" v-bind="props" type="text"></FzInput>
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 { onMounted, ref } from "vue";
7
- import FzInput from "./FzInput.vue";
8
- import { FzInputProps } from "./types";
9
- import { useCurrency } from "@fiscozen/composables";
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<Omit<FzInputProps, "type" | "modelValue">>();
13
- const { inputRef } = useCurrency();
14
-
15
- defineEmits(["update:amount"]);
16
+ const props = defineProps<FzCurrencyInputProps>();
17
+ const {inputRef} = useCurrency();
16
18
 
17
19
  onMounted(() => {
18
- inputRef.value = fzInputRef.value.inputRef;
19
- });
20
- const model = defineModel("amount");
21
- </script>
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(["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>
@@ -1,42 +1,37 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { flushPromises, mount } from "@vue/test-utils";
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
- it("renders floating numbers as currency", async () => {
6
+ it('renders floating numbers as currency', async () => {
7
+ const val = 1234.56
8
8
 
9
- const wrapper = mount(FzCurrencyInput, {
10
- props: {
11
- label: "Label",
12
- amount: 1234.56,
13
- "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
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
- 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
- });
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
- 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
- });
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
- type FzCurrencyInputProps = Omit<FzInputProps, "type">;
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 };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './src/index'