@antify/ui 2.5.0 → 2.5.2

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.
@@ -234,12 +234,14 @@ input[type="checkbox"]::before {
234
234
  width: 100%;
235
235
  height: 100%;
236
236
  transform: scale(0);
237
- transition: 120ms transform;
237
+ transition: 120ms all;
238
238
  background: currentColor;
239
239
  border-radius: inherit;
240
+ opacity: 0;
240
241
  }
241
242
 
242
243
  input[type="checkbox"]:checked::before {
243
244
  transform: scale(1);
245
+ opacity: 1;
244
246
  }
245
247
  </style>
@@ -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"
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.0",
3
+ "version": "2.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {