@antify/ui 2.5.1 → 2.5.3

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.
@@ -4,6 +4,7 @@ import {
4
4
  } from 'vue';
5
5
  import AntField from '../forms/AntField.vue';
6
6
  import AntBaseInput from './Elements/AntBaseInput.vue';
7
+ import AntButton from '../buttons/AntButton.vue';
7
8
  import AntIcon from '../AntIcon.vue';
8
9
  import {
9
10
  Size,
@@ -12,7 +13,7 @@ import {
12
13
  useVModel,
13
14
  } from '@vueuse/core';
14
15
  import {
15
- InputState,
16
+ Grouped, InputState, State,
16
17
  } from '../../enums';
17
18
  import {
18
19
  BaseInputType,
@@ -24,7 +25,7 @@ import {
24
25
  AntDateInputTypes,
25
26
  } from './__types/AntDateInput.types';
26
27
  import {
27
- faCalendar, faClock,
28
+ faCalendar, faClock, faMultiply,
28
29
  } from '@fortawesome/free-solid-svg-icons';
29
30
  import {
30
31
  IconSize,
@@ -47,6 +48,7 @@ const props = withDefaults(defineProps<{
47
48
  messages?: string[];
48
49
  min?: string;
49
50
  max?: string;
51
+ nullable?: boolean;
50
52
  }>(), {
51
53
  state: InputState.base,
52
54
  type: AntDateInputTypes.date,
@@ -55,6 +57,7 @@ const props = withDefaults(defineProps<{
55
57
  skeleton: false,
56
58
  size: Size.md,
57
59
  messages: () => [],
60
+ nullable: false,
58
61
  });
59
62
  const emit = defineEmits([
60
63
  'update:modelValue',
@@ -78,6 +81,7 @@ const iconColor = computed(() => {
78
81
  });
79
82
  const iconSize = computed(() => props.size === Size.xs || props.size === Size.xs2 ? IconSize.xs : IconSize.sm);
80
83
  const _icon = computed(() => props.type === AntDateInputTypes.time ? faClock : faCalendar);
84
+ const _nullable = computed(() => props.nullable && props.modelValue);
81
85
 
82
86
  onMounted(() => {
83
87
  handleEnumValidation(props.state, InputState, 'state');
@@ -102,30 +106,42 @@ function onClickCalendar() {
102
106
  :state="state"
103
107
  :messages="messages"
104
108
  >
105
- <AntBaseInput
106
- v-model="_modelValue"
107
- v-model:input-ref="inputRef"
108
- :type="type as unknown as BaseInputType"
109
- :state="state"
110
- :size="size"
111
- :skeleton="skeleton"
112
- :disabled="disabled"
113
- :readonly="readonly"
114
- :show-icon="false"
115
- :min="min"
116
- :max="max"
117
- v-bind="$attrs"
118
- @validate="val => $emit('validate', val)"
119
- >
120
- <template #icon-right>
121
- <AntIcon
122
- :icon="_icon"
123
- :color="iconColor"
124
- :size="iconSize"
125
- :class="{'cursor-pointer': !disabled && !readonly, 'opacity-50': disabled}"
126
- @click="onClickCalendar"
127
- />
128
- </template>
129
- </AntBaseInput>
109
+ <div class="flex">
110
+ <AntBaseInput
111
+ v-model="_modelValue"
112
+ v-model:input-ref="inputRef"
113
+ :type="type as unknown as BaseInputType"
114
+ :state="state"
115
+ :size="size"
116
+ :skeleton="skeleton"
117
+ :disabled="disabled"
118
+ :readonly="readonly"
119
+ :show-icon="false"
120
+ :min="min"
121
+ :max="max"
122
+ :grouped="_nullable ? Grouped.left : Grouped.none"
123
+ v-bind="$attrs"
124
+ @validate="val => $emit('validate', val)"
125
+ >
126
+ <template #icon-right>
127
+ <AntIcon
128
+ :icon="_icon"
129
+ :color="iconColor"
130
+ :size="iconSize"
131
+ :class="{'cursor-pointer': !disabled && !readonly, 'opacity-50': disabled}"
132
+ @click="onClickCalendar"
133
+ />
134
+ </template>
135
+ </AntBaseInput>
136
+
137
+ <AntButton
138
+ v-if="_nullable"
139
+ :icon-left="faMultiply"
140
+ :grouped="Grouped.right"
141
+ :state="state as unknown as State"
142
+ :size="size"
143
+ @click="_modelValue = null"
144
+ />
145
+ </div>
130
146
  </AntField>
131
147
  </template>
@@ -9,17 +9,14 @@ import {
9
9
  Size,
10
10
  } from '../../enums/Size.enum';
11
11
  import {
12
- faPlus, faMinus,
12
+ faMinus, faPlus,
13
13
  } from '@fortawesome/free-solid-svg-icons';
14
14
  import {
15
- State, InputState,
15
+ InputState, State,
16
16
  } from '../../enums/State.enum';
17
17
  import {
18
18
  handleEnumValidation,
19
19
  } from '../../handler';
20
- import {
21
- useVModel,
22
- } from '@vueuse/core';
23
20
  import {
24
21
  Grouped,
25
22
  } from '../../enums/Grouped.enum';
@@ -27,6 +24,10 @@ import {
27
24
  BaseInputType,
28
25
  } from './Elements/__types';
29
26
  import Big from 'big.js';
27
+ import {
28
+ getDecimalPlaces,
29
+ } from '../../utils';
30
+
30
31
  Big.RM = Big.roundHalfEven;
31
32
 
32
33
  defineOptions({
@@ -38,7 +39,7 @@ defineOptions({
38
39
  * Additionally, the initial value (if none is given) gets set to "0" with the same amount of decimals as used in the steps.
39
40
  */
40
41
  const props = withDefaults(defineProps<{
41
- modelValue: string | null;
42
+ modelValue: number | null;
42
43
  label?: string;
43
44
  placeholder?: string;
44
45
  description?: string;
@@ -68,7 +69,23 @@ const emit = defineEmits([
68
69
  'update:modelValue',
69
70
  'validate',
70
71
  ]);
71
- const _modelValue = useVModel(props, 'modelValue', emit);
72
+
73
+ const _modelValue = computed({
74
+ get: () => {
75
+ if(!props.modelValue) {
76
+ return props.modelValue;
77
+ }
78
+
79
+ const modelDecimalPlaces = getDecimalPlaces(props.modelValue || 0);
80
+ const stepDecimalPlaces = getDecimalPlaces(props.steps);
81
+ const decimalPlaces = Math.max(modelDecimalPlaces, stepDecimalPlaces);
82
+
83
+ return String(new Big(props.modelValue).toFixed(decimalPlaces));
84
+ },
85
+ set: (val: string) => {
86
+ emit('update:modelValue', Number(val));
87
+ },
88
+ });
72
89
 
73
90
  const isPrevButtonDisabled = computed(() => {
74
91
  if (props.disabled) {
@@ -98,19 +115,6 @@ onMounted(() => {
98
115
  handleEnumValidation(props.state, InputState, 'state');
99
116
  });
100
117
 
101
- /**
102
- * Returns the amount of decimal places of the given value.
103
- * @param value Number to get decimal places from.
104
- */
105
- function getDecimalPlaces(value: number | string) {
106
- const strValue = String(value);
107
- const decimalIndex = strValue.indexOf('.');
108
-
109
- if (decimalIndex === -1) return 0;
110
-
111
- return strValue.length - decimalIndex - 1;
112
- }
113
-
114
118
  function subtract() {
115
119
  const modelDecimalPlaces = getDecimalPlaces(_modelValue.value || 0);
116
120
  const stepDecimalPlaces = getDecimalPlaces(props.steps);
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import {
3
- onMounted,
3
+ computed, onMounted,
4
4
  } from 'vue';
5
5
  import AntButton from '../buttons/AntButton.vue';
6
6
  import AntField from '../forms/AntField.vue';
@@ -12,10 +12,7 @@ import {
12
12
  type IconDefinition,
13
13
  } from '@fortawesome/free-solid-svg-icons';
14
14
  import {
15
- useVModel,
16
- } from '@vueuse/core';
17
- import {
18
- State, InputState,
15
+ InputState, State,
19
16
  } from '../../enums';
20
17
  import {
21
18
  Grouped,
@@ -26,6 +23,7 @@ import {
26
23
  import {
27
24
  handleEnumValidation,
28
25
  } from '../../handler';
26
+ import Big from 'big.js';
29
27
 
30
28
  defineOptions({
31
29
  inheritAttrs: false,
@@ -47,6 +45,7 @@ const props = withDefaults(defineProps<{
47
45
  skeleton?: boolean;
48
46
  wrapperClass?: string | Record<string, boolean>;
49
47
  messages?: string[];
48
+ decimalPlaces?: number;
50
49
  }>(), {
51
50
  state: InputState.base,
52
51
  disabled: false,
@@ -55,12 +54,25 @@ const props = withDefaults(defineProps<{
55
54
  size: Size.md,
56
55
  limiter: false,
57
56
  messages: () => [],
57
+ decimalPlaces: 2,
58
58
  });
59
59
  const emit = defineEmits([
60
60
  'update:modelValue',
61
61
  'validate',
62
62
  ]);
63
- const _modelValue = useVModel(props, 'modelValue', emit);
63
+
64
+ const _modelValue = computed({
65
+ get: () => {
66
+ if(!props.modelValue) {
67
+ return props.modelValue;
68
+ }
69
+
70
+ return String(new Big(props.modelValue).toFixed(Math.max(0, props.decimalPlaces)));
71
+ },
72
+ set: (val: string) => {
73
+ emit('update:modelValue', Number(val));
74
+ },
75
+ });
64
76
 
65
77
  onMounted(() => {
66
78
  handleEnumValidation(props.state, InputState, 'state');
@@ -76,7 +88,7 @@ onMounted(() => {
76
88
  :description="description"
77
89
  :state="state"
78
90
  :limiter-max-value="limiter && max !== undefined ? max : undefined"
79
- :limiter-value="limiter && _modelValue !== undefined && _modelValue !== null ? _modelValue : undefined"
91
+ :limiter-value="limiter && _modelValue !== undefined && _modelValue !== null ? Number(_modelValue) : undefined"
80
92
  :messages="messages"
81
93
  >
82
94
  <div
@@ -86,7 +98,7 @@ onMounted(() => {
86
98
  v-model="_modelValue"
87
99
  :type="BaseInputType.number"
88
100
  :grouped="Grouped.left"
89
- wrapper-class="grow"
101
+ wrapper-class="flex-grow"
90
102
  :state="state"
91
103
  :size="size"
92
104
  :min="min"
@@ -1,4 +1,4 @@
1
- import { type Meta, type StoryObj } from '@storybook/vue3';
1
+ import type { Meta, StoryObj } from '@storybook/vue3';
2
2
  import AntDateInput from '../AntDateInput.vue';
3
3
  declare const meta: Meta<typeof AntDateInput>;
4
4
  export default meta;
@@ -165,6 +165,41 @@ const Summary = exports.Summary = {
165
165
  />
166
166
  </AntFormGroup>
167
167
 
168
+ <AntFormGroupLabel>
169
+ Nullable
170
+ </AntFormGroupLabel>
171
+ <AntFormGroup :direction="Direction.row">
172
+ <AntDateInput
173
+ v-bind="args"
174
+ model-value="2025-01-01"
175
+ nullable
176
+ />
177
+ <AntDateInput
178
+ v-bind="args"
179
+ model-value="2025-01-01"
180
+ :state="InputState.info"
181
+ nullable
182
+ />
183
+ <AntDateInput
184
+ v-bind="args"
185
+ model-value="2025-01-01"
186
+ :state="InputState.success"
187
+ nullable
188
+ />
189
+ <AntDateInput
190
+ v-bind="args"
191
+ model-value="2025-01-01"
192
+ :state="InputState.warning"
193
+ nullable
194
+ />
195
+ <AntDateInput
196
+ v-bind="args"
197
+ model-value="2025-01-01"
198
+ :state="InputState.danger"
199
+ nullable
200
+ />
201
+ </AntFormGroup>
202
+
168
203
  <AntFormGroupLabel>
169
204
  Type
170
205
  </AntFormGroupLabel>
@@ -166,6 +166,41 @@ export const Summary = {
166
166
  />
167
167
  </AntFormGroup>
168
168
 
169
+ <AntFormGroupLabel>
170
+ Nullable
171
+ </AntFormGroupLabel>
172
+ <AntFormGroup :direction="Direction.row">
173
+ <AntDateInput
174
+ v-bind="args"
175
+ model-value="2025-01-01"
176
+ nullable
177
+ />
178
+ <AntDateInput
179
+ v-bind="args"
180
+ model-value="2025-01-01"
181
+ :state="InputState.info"
182
+ nullable
183
+ />
184
+ <AntDateInput
185
+ v-bind="args"
186
+ model-value="2025-01-01"
187
+ :state="InputState.success"
188
+ nullable
189
+ />
190
+ <AntDateInput
191
+ v-bind="args"
192
+ model-value="2025-01-01"
193
+ :state="InputState.warning"
194
+ nullable
195
+ />
196
+ <AntDateInput
197
+ v-bind="args"
198
+ model-value="2025-01-01"
199
+ :state="InputState.danger"
200
+ nullable
201
+ />
202
+ </AntFormGroup>
203
+
169
204
  <AntFormGroupLabel>
170
205
  Type
171
206
  </AntFormGroupLabel>
package/dist/utils.d.ts CHANGED
@@ -18,3 +18,8 @@ export declare function enumToPlainText(value: object, className: string): strin
18
18
  * To get a slot in your component, call $slots['slotName'] or useSlots()['slotName'].
19
19
  */
20
20
  export declare function hasSlotContent(slot: Slot<any> | undefined): boolean;
21
+ /**
22
+ * Returns the amount of decimal places of the given value.
23
+ * @param value Number to get decimal places from.
24
+ */
25
+ export declare function getDecimalPlaces(value: number | string): number;
package/dist/utils.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.classesToObjectSyntax = classesToObjectSyntax;
7
7
  exports.enumToPlainText = enumToPlainText;
8
+ exports.getDecimalPlaces = getDecimalPlaces;
8
9
  exports.hasSlotContent = hasSlotContent;
9
10
  var _vue = require("vue");
10
11
  function classesToObjectSyntax(classes) {
@@ -46,4 +47,12 @@ function hasSlotContent(slot) {
46
47
  });
47
48
  };
48
49
  return !isVnodeEmpty(slot());
50
+ }
51
+ function getDecimalPlaces(value) {
52
+ const strValue = String(value);
53
+ const decimalIndex = strValue.indexOf(".");
54
+ if (decimalIndex === -1) {
55
+ return 0;
56
+ }
57
+ return strValue.length - decimalIndex - 1;
49
58
  }
package/dist/utils.mjs CHANGED
@@ -41,3 +41,11 @@ export function hasSlotContent(slot) {
41
41
  };
42
42
  return !isVnodeEmpty(slot());
43
43
  }
44
+ export function getDecimalPlaces(value) {
45
+ const strValue = String(value);
46
+ const decimalIndex = strValue.indexOf(".");
47
+ if (decimalIndex === -1) {
48
+ return 0;
49
+ }
50
+ return strValue.length - decimalIndex - 1;
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antify/ui",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {