@fiscozen/input 0.1.12 → 0.1.14

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.12",
3
+ "version": "0.1.14",
4
4
  "description": "Design System Input component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -9,8 +9,8 @@
9
9
  "peerDependencies": {
10
10
  "tailwindcss": "^3.4.1",
11
11
  "vue": "^3.4.13",
12
- "@fiscozen/icons": "^0.1.14",
13
- "@fiscozen/composables": "^0.1.33"
12
+ "@fiscozen/icons": "^0.1.22",
13
+ "@fiscozen/composables": "^0.1.36"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@rushstack/eslint-patch": "^1.3.3",
@@ -29,8 +29,8 @@
29
29
  "vitest": "^1.2.0",
30
30
  "vue-tsc": "^1.8.25",
31
31
  "@fiscozen/eslint-config": "^0.1.0",
32
- "@fiscozen/tsconfig": "^0.1.0",
33
- "@fiscozen/prettier-config": "^0.1.0"
32
+ "@fiscozen/prettier-config": "^0.1.0",
33
+ "@fiscozen/tsconfig": "^0.1.0"
34
34
  },
35
35
  "license": "MIT",
36
36
  "scripts": {
@@ -5,14 +5,32 @@
5
5
  :modelValue="fzInputModel"
6
6
  type="text"
7
7
  @paste="onPaste"
8
- ></FzInput>
8
+ >
9
+ <template #right-icon v-if="step">
10
+ <div class="flex flex-col justify-between items-center">
11
+ <FzIcon
12
+ name="angle-up"
13
+ size="xs"
14
+ class="fz__currencyinput__arrowup cursor-pointer"
15
+ @click="stepUpDown(step)"
16
+ ></FzIcon>
17
+ <FzIcon
18
+ name="angle-down"
19
+ size="xs"
20
+ class="fz__currencyinput__arrowdown cursor-pointer"
21
+ @click="stepUpDown(-step)"
22
+ ></FzIcon>
23
+ </div>
24
+ </template>
25
+ </FzInput>
9
26
  </template>
10
27
 
11
28
  <script setup lang="ts">
12
29
  import { computed, nextTick, onMounted, ref, watch } from "vue";
13
30
  import FzInput from "./FzInput.vue";
14
31
  import { FzCurrencyInputProps } from "./types";
15
- import { useCurrency } from "@fiscozen/composables";
32
+ import { roundTo, useCurrency } from "@fiscozen/composables";
33
+ import { FzIcon } from "@fiscozen/icons";
16
34
 
17
35
  const fzInputRef = ref<InstanceType<typeof FzInput>>();
18
36
  const fzInputModel = ref();
@@ -31,6 +49,9 @@ const {
31
49
  } = useCurrency({
32
50
  minimumFractionDigits: props.minimumFractionDigits,
33
51
  maximumFractionDigits: props.maximumFractionDigits,
52
+ min: props.min,
53
+ max: props.max,
54
+ step: props.step,
34
55
  });
35
56
 
36
57
  defineEmits(["update:amount"]);
@@ -107,10 +128,22 @@ onMounted(() => {
107
128
  fzInputModel.value = inputRef.value?.value;
108
129
  });
109
130
  });
110
- const model = defineModel("amount");
131
+ const model = defineModel<number>("amount");
132
+
133
+ const stepUpDown = (amount: number) => {
134
+ if (!props.step) {
135
+ return;
136
+ }
137
+ const value = model.value || 0;
138
+ let stepVal = props.forceStep ? roundTo(props.step, value) : value;
139
+ stepVal += amount;
140
+ const safeText = format(stepVal);
141
+ setValue(safeText);
142
+ emitAmount(stepVal);
143
+ };
111
144
 
112
145
  watch(model, (newVal) => {
113
- fzInputModel.value = newVal as string;
146
+ fzInputModel.value = newVal;
114
147
  });
115
148
 
116
149
  defineExpose({
package/src/FzInput.vue CHANGED
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="fz-input w-full flex flex-col gap-8">
3
- <label :class="['text-sm', computedLabelClass]" :for="uniqueId">
3
+ <label :class="['text-sm', computedLabelClass]" :for="uniqueId" v-if="label">
4
4
  {{ label }}{{ required ? " *" : "" }}
5
5
  </label>
6
6
  <div
@@ -23,7 +23,7 @@ describe.concurrent("FzCurrencyInput", () => {
23
23
  const wrapper = mount(FzCurrencyInput, {
24
24
  props: {
25
25
  label: "Label",
26
- amount: "",
26
+ amount: 0,
27
27
  "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
28
28
  },
29
29
  });
@@ -126,4 +126,79 @@ describe.concurrent("FzCurrencyInput", () => {
126
126
  await new Promise((resolve) => window.setTimeout(resolve, 100));
127
127
  expect(inputElement.element.value).toBe("1,23");
128
128
  });
129
+
130
+ it("should limit value according to min/max setting", async () => {
131
+ const wrapper = mount(FzCurrencyInput, {
132
+ props: {
133
+ label: "Label",
134
+ amount: 10,
135
+ "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
136
+ min: 2,
137
+ max: 20,
138
+ },
139
+ });
140
+
141
+ const inputElement = wrapper.find("input");
142
+ await inputElement.trigger("blur");
143
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
144
+ expect(inputElement.element.value).toBe("10,00");
145
+ await wrapper.setProps({ amount: 1 });
146
+ await inputElement.trigger("blur");
147
+ expect(inputElement.element.value).toBe("2,00");
148
+ await wrapper.setProps({ amount: 23 });
149
+ await inputElement.trigger("blur");
150
+ expect(inputElement.element.value).toBe("20,00");
151
+ });
152
+
153
+ it("should step correctly when using quantization via the 'step' prop", async () => {
154
+ const wrapper = mount(FzCurrencyInput, {
155
+ props: {
156
+ label: "Label",
157
+ amount: 1,
158
+ "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
159
+ step: 4,
160
+ },
161
+ });
162
+
163
+ const inputElement = wrapper.find("input");
164
+ const arrowUp = wrapper.find(".fz__currencyinput__arrowup");
165
+ const arrowDown = wrapper.find(".fz__currencyinput__arrowdown");
166
+
167
+ await inputElement.trigger("blur");
168
+ expect(inputElement.element.value).toBe("1,00");
169
+ await arrowUp.trigger("click");
170
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
171
+ expect(inputElement.element.value).toBe("5,00");
172
+ await arrowDown.trigger("click");
173
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
174
+ expect(inputElement.element.value).toBe("1,00");
175
+ await arrowDown.trigger("click");
176
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
177
+ expect(inputElement.element.value).toBe("-3,00");
178
+ });
179
+
180
+ it("should enforce quantization via the 'forcedStep' prop", async () => {
181
+ const wrapper = mount(FzCurrencyInput, {
182
+ props: {
183
+ label: "Label",
184
+ amount: 8,
185
+ "onUpdate:amount": (e) => wrapper.setProps({ amount: e }),
186
+ step: 4,
187
+ forceStep: true,
188
+ },
189
+ });
190
+
191
+ const inputElement = wrapper.find("input");
192
+ await inputElement.trigger("blur");
193
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
194
+ expect(inputElement.element.value).toBe("8,00");
195
+ await wrapper.setProps({ amount: 5 });
196
+ await inputElement.trigger("blur");
197
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
198
+ expect(inputElement.element.value).toBe("4,00");
199
+ await wrapper.setProps({ amount: -7 });
200
+ await inputElement.trigger("blur");
201
+ await new Promise((resolve) => window.setTimeout(resolve, 100));
202
+ expect(inputElement.element.value).toBe("-8,00");
203
+ });
129
204
  });
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ type FzInputProps = {
4
4
  /**
5
5
  * The label displayed on top of the input
6
6
  */
7
- label: string;
7
+ label?: string;
8
8
  /**
9
9
  * The size of the input
10
10
  */
@@ -97,6 +97,22 @@ interface FzCurrencyInputProps
97
97
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#digit_options
98
98
  */
99
99
  maximumFractionDigits?: number;
100
+ /**
101
+ * Minimum number value
102
+ */
103
+ min?: number;
104
+ /**
105
+ * Maximum number value
106
+ */
107
+ max?: number;
108
+ /**
109
+ * Quantized step
110
+ */
111
+ step?: number;
112
+ /**
113
+ * Allow only mutiples of step
114
+ */
115
+ forceStep?: boolean;
100
116
  }
101
117
 
102
118
  export { FzInputProps, FzCurrencyInputProps };